lcio/src/java/hep/lcio/util
diff -u -r1.1 -r1.2
--- Split.java 28 Apr 2006 21:33:51 -0000 1.1
+++ Split.java 15 Jun 2007 23:14:57 -0000 1.2
@@ -21,7 +21,7 @@
* chunks of given size.
*
* @author Jeremy McCormick
- * @version $Id: Split.java,v 1.1 2006/04/28 21:33:51 jeremy Exp $
+ * @version $Id: Split.java,v 1.2 2007/06/15 23:14:57 jeremy Exp $
*/
public class Split
{
@@ -31,10 +31,10 @@
* @param nevents The number of events in each new output file.
* @throws Exception
*/
- public static List split(File infile, int nevents) throws Exception
+ public static List split(File infile, int nevents, int maxevents) throws Exception
{
// List of files created.
- List outfilelist = new ArrayList();
+ List<File> outfilelist = new ArrayList<File>();
// Base name from input file name.
String basename = infile.getAbsolutePath().replace(".slcio", "");
@@ -67,6 +67,7 @@
// file loop
String outfile;
+ int totalevents=0;
for (;;)
{
// Next output file name.
@@ -120,6 +121,7 @@
{
// Increment number of events.
++neventsread;
+ ++totalevents;
}
// Increment number of records.
@@ -130,6 +132,11 @@
throw new RuntimeException("Error writing record " + (nevents - 1), x);
}
}
+
+ if (maxevents != -1 && totalevents == maxevents)
+ {
+ done = true;
+ }
if (neventsread == nevents || done)
{
@@ -178,8 +185,11 @@
}
// Delete the last file as it doesn't have any events.
- outfilelist.remove(outfilelist.size() - 1);
- (new File(outfile)).delete();
+ if (neventsread == 0)
+ {
+ outfilelist.remove(outfilelist.size() - 1);
+ (new File(outfile)).delete();
+ }
// Return a list of files created.
return outfilelist;
lcio/src/java/hep/lcio/util
diff -u -r1.4 -r1.5
--- SplitCommandHandler.java 7 Dec 2006 00:47:33 -0000 1.4
+++ SplitCommandHandler.java 15 Jun 2007 23:14:57 -0000 1.5
@@ -13,12 +13,13 @@
* Command-line handler for the split utility.
*
* @author Jeremy McCormick
- * @version $Id: SplitCommandHandler.java,v 1.4 2006/12/07 00:47:33 jeremy Exp $
+ * @version $Id: SplitCommandHandler.java,v 1.5 2007/06/15 23:14:57 jeremy Exp $
*/
public class SplitCommandHandler extends CommandHandler
{
File infile;
int nevents;
+ int maxevents=-1;
SplitCommandHandler()
{
@@ -46,6 +47,10 @@
opt = new Option("n", true, "The number of events to split.");
opt.setArgs(1);
options.addOption(opt);
+
+ opt = new Option("m", false, "The maximum number of events to read.");
+ opt.setArgs(1);
+ options.addOption(opt);
return options;
}
@@ -80,6 +85,11 @@
{
nevents = Integer.parseInt(cl.getOptionValue("n"));
}
+
+ if (cl.hasOption("m"))
+ {
+ maxevents = Integer.parseInt(cl.getOptionValue("m"));
+ }
}
/**
@@ -87,7 +97,7 @@
*/
public void execute() throws Exception
{
- List flist = Split.split(infile, nevents);
+ List flist = Split.split(infile, nevents, maxevents);
Split.printSplitSummary(flist, System.out);
}
}