lcio/src/java/hep/lcio/util
diff -u -r1.6 -r1.7
--- MergeCommandHandler.java 2 Jun 2006 00:22:57 -0000 1.6
+++ MergeCommandHandler.java 3 Nov 2006 08:41:26 -0000 1.7
@@ -15,12 +15,12 @@
/**
* This is the CommandHandler for the merge utility.
- *
- * It parses 'lcio merge' command-line options and
+ *
+ * It parses 'lcio merge' command-line options and
* passes the results to a method from MergeUtil.
- *
+ *
* @author jeremym
- * @version $Id: MergeCommandHandler.java,v 1.6 2006/06/02 00:22:57 jeremy Exp $
+ * @version $Id: MergeCommandHandler.java,v 1.7 2006/11/03 08:41:26 jeremy Exp $
*/
public class MergeCommandHandler extends CommandHandler
{
@@ -31,15 +31,15 @@
float def_dt = 0;
float def_startt = 0;
int def_ntoread = 1;
-
- /**
- * MergeCommandHandler ctor.
+
+ /**
+ * MergeCommandHandler ctor.
*/
MergeCommandHandler()
{
// Call CommandHandler ctor.
super("merge", "Merge LCIO events together.");
-
+
// Setup merge command options.
options = createMergeOptions();
}
@@ -63,7 +63,7 @@
opt = new Option("t", true, "Set delta time (ns).");
opt.setArgs(1);
options.addOption(opt);
-
+
opt = new Option("T", true, "Set the starting time (ns).");
opt.setArgs(1);
options.addOption(opt);
@@ -75,18 +75,18 @@
opt = new Option("e", true, "Set number of events to merge in from each input file per merged event. (Default is 1)");
opt.setArgs(1);
options.addOption(opt);
-
- opt = new Option("f", true, "Set input file list with format: [file_name],[n_reads_per_event],[start_time],[delta_time]" +
+
+ opt = new Option("f", true, "Set input file list with format:\n[file_name],[n_reads_per_event],[start_time],[delta_time]\n" +
"This option is not usable with the -i argument.");
opt.setArgs(1);
options.addOption(opt);
-
+
return options;
}
- /**
+ /**
* Parse the command line options for the merge command using apache CLI.
- * @param argv The input arguments for the merge command.
+ * @param argv The input arguments for the merge command.
*/
public void parse(String[] argv) throws Exception
{
@@ -96,26 +96,28 @@
if (!cl.hasOption("i") && !cl.hasOption("f"))
{
System.err.println("The merge command requires one of the -i or -f options.");
+ printUsage(true);
}
+
// Cannot have both -i and -f.
- else if (cl.hasOption("i") && cl.hasOption("f"))
+ if (cl.hasOption("i") && cl.hasOption("f"))
{
System.err.println("The -i and -f options cannot be used together.");
printUsage(true);
}
-
+
// Read a file containing comma-delimited list of fname and nreads.
if (cl.hasOption("f"))
{
mergeFiles = createMergeFiles(FileUtil.loadFile(cl.getOptionValue("f")));
}
-
+
// Add input files one-by-one.
if (cl.hasOption("i"))
- {
+ {
// Create input file array.
infiles = FileUtil.createFiles(cl.getOptionValues("i"));
-
+
// Create default merge files.
mergeFiles = createDefaultMergeFiles(infiles);
}
@@ -128,7 +130,7 @@
else {
outfile = new File("merged_events.slcio");
}
-
+
System.err.println("Set output file: " + outfile.getAbsolutePath());
// Set the default time delta.
@@ -150,14 +152,14 @@
}
}
- /**
- * Execute the merge command with current arguments.
+ /**
+ * Execute the merge command with current arguments.
*/
public void execute() throws Exception
{
MergeUtil.mergeFiles(outfile, mergeFiles, maxevents);
}
-
+
/**
* Create a list of @see MergeFileParameters objects from the
* input file specified with -f.
@@ -165,50 +167,50 @@
* @return List of MergeFileParameters objects.
*/
public List createMergeFiles(List lines) throws IOException
- {
+ {
List mfiles = new ArrayList();
-
+
for (Iterator iter = lines.iterator(); iter.hasNext();)
{
- // Get the next line.
+ // Get the next line.
String line = (String)iter.next();
-
+
// Split into fields on comma.
String[] fields = line.split(",");
-
+
if (fields.length != 0)
{
// Get file name.
String fname = fields[0];
-
+
// Get number of reads per event for this file.
int nreads = def_ntoread;
if (fields.length > 1)
nreads = Integer.parseInt(fields[1]);
-
+
// Get start time.
float startt = def_startt;
if (fields.length > 2)
startt = Float.parseFloat(fields[2]);
-
+
// Get delta time.
float dt = def_dt;
if (fields.length > 3)
- dt = Float.parseFloat(fields[3]);
-
+ dt = Float.parseFloat(fields[3]);
+
// Create the input file.
File f = new File(fname);
-
+
// Create the merge file object.
MergeFileParameters fopt = new MergeFileParameters(f, nreads, startt, dt);
-
+
// Add this file with options to merge files list.
mfiles.add(fopt);
}
}
return mfiles;
}
-
+
/**
* Create the default merge options, which is one event from the file per merged output event.
* @param files An array of input File objects.
@@ -222,11 +224,11 @@
for (int i=0; i<files.length;i++)
{
m.add(new MergeFileParameters(files[i], def_ntoread, def_startt, def_dt));
- }
+ }
}
return m;
}
-
+
/**
* Print usage and (optionally) exit the program.
* @param doExit Whether or not to exit after printing usage.
@@ -242,4 +244,4 @@
System.exit(0);
}
}
-}
\ No newline at end of file
+}