lcio/src/java/hep/lcio/util
diff -u -r1.2 -r1.3
--- CommandLineTool.java 26 Apr 2006 00:56:53 -0000 1.2
+++ CommandLineTool.java 26 Apr 2006 19:37:05 -0000 1.3
@@ -6,11 +6,10 @@
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.HelpFormatter;
+import org.apache.commons.cli.Option;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.Parser;
import org.apache.commons.cli.PosixParser;
-//import org.apache.commons.cli.Parser;
-//import org.apache.commons.cli.PosixParser;
/**
* CommandLineTool provides a command-line interface
@@ -27,8 +26,10 @@
* @see hep.lcio.util.SioDump siodump
* @see hep.lcio.util.Split split
*
+ * FIXME: Implement all of the above commands.
+ *
* @author jeremym
- * @version $Id: CommandLineTool.java,v 1.2 2006/04/26 00:56:53 jeremy Exp $
+ * @version $Id: CommandLineTool.java,v 1.3 2006/04/26 19:37:05 jeremy Exp $
*/
public class CommandLineTool
{
@@ -39,41 +40,48 @@
private CommandLine cl;
private static CommandLineTool instance = new CommandLineTool();
+ /**
+ * Get an instance of CommandLineTool.
+ * @return A globall unique instance of CommandLineTool.
+ */
public static CommandLineTool instance()
{
return instance;
}
+ /**
+ * The private ctor.
+ */
private CommandLineTool()
{
- //System.out.println("CommandLineTool");
-
registerOptions();
registerHandlers();
}
+ /**
+ * Get the global options.
+ * @return A CommandLine object representing the global options,
+ * e.g. the options in front of the command.
+ */
public CommandLine getGlobalOptions()
{
return cl;
}
- // main entry point.
- public static void main(String[] args) throws Exception
+ /**
+ * The default main method for the CommandLineTool.
+ * @param argv The raw input arguments from the CL.
+ * @throws Exception
+ */
+ public static void main(String[] argv) throws Exception
{
- //System.err.println("main");
-
CommandLineTool cl = CommandLineTool.instance();
-
- // try {
- cl.parse(args);
- // }
- // catch (Exception e)
- // {
- // throw new RuntimeException("Problem parsing args.",e);
- // }
+ cl.parse(argv);
}
- // Register the default CommandHandlers.
+ /**
+ * Register default command handlers with the CommandLineTool.
+ */
private void registerHandlers()
{
// addCommandHandler("compare", Compare)
@@ -85,65 +93,83 @@
// addCommandHandler("split", Split);
}
- // Register global options. Sub-commands have their own option set.
+ /**
+ * Register the CommandLineTool's global options.
+ */
private void registerOptions()
{
-// Option opt = new Option("h", false, "print lcio command-line tool usage");
-// options.addOption(opt);
+ Option opt = new Option("h", false, "Print lcio command-line tool usage.");
+ options.addOption(opt);
-// opt = new Option("v", false, "set the verbosity");
-// opt.setArgs(1);
-// options.addOption(opt);
+ opt = new Option("v", false, "Set the verbosity.");
+ opt.setArgs(1);
+ options.addOption(opt);
}
- // Set the name of the active sub-command.
- public void setCommand(String command)
+ /**
+ * Set the name of the active command.
+ * @param command String of the command.
+ */
+ private void setCommand(String command)
{
this.command = command;
}
- // Get the name of the active sub-command.
+ /**
+ * Get the name of the currently active command.
+ * @return String of the currently active command.
+ */
public String getCommand()
{
return this.command;
}
- // Parse the command line for global options.
- // Then find and execute the appropriate CommandHandler.
- public void parse(String[] args) throws Exception
+ /**
+ * Parse the argv for global options.
+ * Lookup the appropriate CommandHandler.
+ * Pass command options to @see CommandHandler.parse method.
+ * Execute the CommandHandler's execute method.
+ * @param argv The raw input arguments from CL.
+ * @throws Exception
+ */
+ // FIXME: Method needs to handle quoting properly.
+ // FreeHep's argv package can handle this.
+ public void parse(String[] argv) throws Exception
{
- int icmd = scanForCommand(args);
+ // Get the index of a command.
+ int icmd = scanForCommand(argv);
if (icmd == -1)
{
+ // No command was found, so print usage and exit.
printUsage(true);
}
// Set the command to execute.
- setCommand(args[icmd]);
+ setCommand(argv[icmd]);
- System.out.println("command: " + getCommand());
+ System.out.println("Executing command: " + getCommand());
// Get a command handler for this command string.
CommandHandler handler = getCommandHandler(getCommand());
// Global arguments.
- int nglob = icmd - 1;
+ int nglob = icmd;
String[] globargv = new String[0];
if (nglob > 0)
{
globargv = new String[nglob];
- System.arraycopy(args, 0, globargv, 0, nglob);
+ System.arraycopy(argv, 0, globargv, 0, nglob);
for (int i = 0; i < globargv.length; i++)
{
System.out.println("globargv[" + i + "]=" + globargv[i]);
}
}
- // Arguments are passed verbatim to the subcommand.
- int ncmd = args.length - (icmd + 1);
+ // Arguments are passed verbatim to the command.
+ int ncmd = argv.length - (icmd + 1);
String[] cmdargv = new String[ncmd];
- System.arraycopy(args, icmd + 1, cmdargv, 0, ncmd);
+ System.arraycopy(argv, icmd + 1, cmdargv, 0, ncmd);
for (int i = 0; i < cmdargv.length; i++)
{
System.out.println("cmdargv[" + i + "]=" + cmdargv[i]);
@@ -152,7 +178,7 @@
// Parse global options.
cl = parser.parse(options, globargv);
- // Pass the subcommand the command line options
+ // Pass the command the command line options
// with globals stripped out.
handler.parse(cmdargv);
@@ -160,33 +186,32 @@
handler.execute();
}
- // Add a class to handle a command string.
+ /**
+ * Add a @see CommandHandler to the CommandLineTool.
+ * The @see CommandHandler.getName method is the command
+ * that will be handled by this @see CommandHandler.
+ * @param handler The CommandHandler.
+ */
public void addCommandHandler(CommandHandler handler)
{
handlers.put(handler.getName(), handler);
}
- // Get a CommandHandler from the command string.
+ /**
+ * Get a CommandHandler for the command.
+ * @param command A String of the command to lookup.
+ * @return A CommandHandler for this command.
+ * @throws Exception
+ */
public CommandHandler getCommandHandler(String command) throws Exception
{
return (CommandHandler) handlers.get(command);
}
- // Scan the argv for an input command string, e.g. "merge", etc.
- private int scanForCommand(String[] argv)
- {
- for (int i = 0; i < argv.length; i++)
- {
- if (handlers.get(argv[i]) != null)
- {
- //System.err.println("found " + argv[i] + " @ idx " + i);
- return i;
- }
- }
- return -1;
- }
-
- // Print usage using CLI.
+ /**
+ * Print the lcio command usage.
+ * @param doExit Boolean that specifies whether to exit or not.
+ */
public void printUsage(boolean doExit)
{
HelpFormatter help = new HelpFormatter();
@@ -206,4 +231,22 @@
System.exit(0);
}
}
+
+ /**
+ * Return the index of a command string in argv.
+ * @param argv The raw input arguments from CL.
+ * @return The index of the first command string in argv or -1 if not found.
+ */
+ private int scanForCommand(String[] argv)
+ {
+ for (int i = 0; i < argv.length; i++)
+ {
+ if (handlers.get(argv[i]) != null)
+ {
+ //System.err.println("found " + argv[i] + " @ idx " + i);
+ return i;
+ }
+ }
+ return -1;
+ }
}
\ No newline at end of file
lcio/src/java/hep/lcio/util
diff -u -r1.3 -r1.4
--- MergeUtil.java 26 Apr 2006 00:56:53 -0000 1.3
+++ MergeUtil.java 26 Apr 2006 19:37:05 -0000 1.4
@@ -22,81 +22,73 @@
import java.util.Map;
/**
- * Utility methods for merging LCIO files, events, and collections,
- * with optional application of a time delta per event.
+ * Utility methods for merging together LCIO
+ * files, events, and collections, with optional
+ * application of a delta time.
*
* @author jeremym
- * @version $Id: MergeUtil.java,v 1.3 2006/04/26 00:56:53 jeremy Exp $
+ * @version $Id: MergeUtil.java,v 1.4 2006/04/26 19:37:05 jeremy Exp $
*/
abstract public class MergeUtil
-{
+{
/**
- * Merge nEventsToRead events from each File in infiles into a single event in outfile,
- * until records in infiles are exhausted or maxevents are created.
- * @return The number of combined events created.
- * @param outfile Output target file containing the merged events.
- * @param fileMap Map of File to Integer, specifying number of events to read from that file per merge.
- * @param maxEventsToWrite Set the maximum number of merged events that this method will create.
- * @param dt The time delta.
- */
- public static int mergeFiles(
- File outfile,
- List mergeFiles,
- int maxEventsToWrite) throws IOException
- {
- // Create the writer.
+ * Merge events from mergeFiles into a single event in outfile,
+ * until all the files in mergeFiles are exhausted, or maxevents
+ * are created.
+ * @return The number of merged events that were created.
+ * @param outfile Target file that will contain the merged events.
+ * @param A list of @see MergeFileOptions objects.
+ * @param maxEvents Set the maximum number of merged events.
+ */
+ public static int mergeFiles(File outfile, List mergeFiles, int maxEvents) throws IOException
+ {
+ // Create the writer for the merged events.
LCWriter writer = LCFactory.getInstance().createLCWriter();
-
- // Open the writer for the new file containing the merged events.
+
+ // Open the writer.
writer.open(outfile.getCanonicalPath(), LCIO.WRITE_NEW);
-
- // Count of total output events.
+
+ // Count of total merged events that were created.
int nevents = 0;
// File read loop.
for (;;)
- {
+ {
// Check if max output events is reached.
- if (nevents >= maxEventsToWrite)
+ if (nevents >= maxEvents)
break;
// Create the new output event.
- ILCEvent target = new ILCEvent();
+ ILCEvent targetEvent = new ILCEvent();
- // First time, the event header needs to
- // be set from the first LCEvent read.
+ // On the first time through, the event header needs to
+ // be set from the first LCEvent that is read.
boolean setEventHeader = true;
- // Total events merged in from all sources in this pass.
+ // Total events merged in from all files.
int totmerged = 0;
- // Loop over the readers.
- for (Iterator iter = mergeFiles.iterator(); iter.hasNext(); )
- {
- // Get the next reader.
- MergeFileOptions mfile = (MergeFileOptions)iter.next();
-
- // Get number of events to read.
- int nEventsToRead = mfile.nreads();
+ // Loop over the files to be merged in.
+ for (Iterator iter = mergeFiles.iterator(); iter.hasNext();)
+ {
+ // Get the next set of merge file parameters.
+ MergeFileParameters mfile = (MergeFileParameters) iter.next();
+
+ // Get the number of events to read.
+ int ntoread = mfile.nreads();
// Get the reader.
LCReader reader = mfile.reader();
- // Get starting time.
+ // Get the starting time.
float startt = mfile.startt();
-
- // Get delta time.
+
+ // Get the delta time.
float dt = mfile.dt();
-
+
// Merge ntoread events from this reader into target,
// using starting time of startt, delta time of dt.
- int nmerged = MergeUtil.mergeEvents(
- target,
- reader,
- nEventsToRead,
- setEventHeader,
- startt,
- dt);
+ int nmerged = MergeUtil.mergeEvents(targetEvent, reader, ntoread, setEventHeader, startt, dt);
// Increment total merged.
totmerged += nmerged;
@@ -107,8 +99,8 @@
// Write out the combined event if something got merged in.
if (totmerged > 0)
- {
- writer.writeEvent(target);
+ {
+ writer.writeEvent(targetEvent);
nevents++;
}
else
@@ -119,37 +111,50 @@
} // file read loop
System.out.println("Created " + nevents + " merged events.");
-
+
// Close the writer.
writer.close();
// Close the readers.
//closeReaders(readers);
- for (Iterator iter = mergeFiles.iterator(); iter.hasNext(); )
- {
- try { ((MergeFileOptions)iter.next()).close(); } catch (Exception x) {}
+ for (Iterator iter = mergeFiles.iterator(); iter.hasNext();)
+ {
+ try
+ {
+ ((MergeFileParameters) iter.next()).close();
+ }
+ catch (Exception x)
+ {
+ }
}
-
+
// Return number of events created.
return nevents;
}
-
+
+ /**
+ * Merge nEventsToRead events from each File in mergeFiles into a single event in outfile,
+ * until records in mergeFiles are exhausted.
+ * @return The number of merged events that were created.
+ * @param outfile Output Target file containing the merged events.
+ * @param A list of @see MergeFileOptions objects.
+ */
+ public static int mergeFiles(File outfile, List mergeFiles) throws IOException
+ {
+ return mergeFiles(outfile, mergeFiles, Integer.MAX_VALUE);
+ }
+
/**
- * Merge n events read from a reader into a single target event.
+ * Merge ntoread events from a reader into a single target event, applying time
+ * delta dt with starting time of startt.
* @return Number of events overlayed from overlayEvents reader.
* @param targetEvent target LCEvent to merge events into
* @param overlayEvents LCReader with overlay events to read
* @param ntoread number of events to overlay from overlayEvents
* @param dt delta time to be applied to the sim types
*/
- public static int mergeEvents(
- LCEvent targetEvent,
- LCReader overlayEvents,
- int ntoread,
- boolean setEventHeader,
- float startt,
- float dt) throws IOException
- {
+ public static int mergeEvents(LCEvent targetEvent, LCReader overlayEvents, int ntoread, boolean setEventHeader, float startt, float dt) throws IOException
+ {
// Read the next event from the reader.
LCEvent nextEvent = overlayEvents.readNextEvent();
@@ -159,7 +164,7 @@
return 0;
}
- // Set the event header from first event if setEventHeader flag is true.
+ // Set the event header from the first event if setEventHeader flag is true.
if (setEventHeader)
{
ILCEvent itargetEvent = (ILCEvent) targetEvent;
@@ -171,34 +176,34 @@
// Number of events merged in.
int nevt = 0;
-
+
// Set starting time.
float time = startt;
-
+
// Read loop.
while (nextEvent != null)
- {
- // Merge single overlay event onto targetEvent.
- mergeSingleEvent((ILCEvent) targetEvent, nextEvent, dt);
-
+ {
+ // Merge single overlay event into targetEvent.
+ mergeSingleEvent((ILCEvent) targetEvent, nextEvent, dt);
+
// Increment number of events read.
nevt++;
-
+
// Break if read max num events.
if (nevt >= ntoread)
break;
-
+
// Get next event to merge in. (could be null)
nextEvent = overlayEvents.readNextEvent();
-
+
// Increment the time for next event.
- time += dt;
+ time += dt;
}
// Return the number of events that were overlayed.
return nevt;
}
-
+
/**
* Overlay the overlay event onto target event, applying time delta.
* @param targetEvent The event that will be overlayed onto from overlayEvent.
@@ -228,7 +233,7 @@
// Iterate over the overlay collections that will be merged into target.
for (int i = 0; i < ocolls.length; i++)
{
- // Get name of this overlay collection.
+ // Get the name of this overlay collection.
String collname = ocolls[i];
// Get this overlay collection.
@@ -245,7 +250,8 @@
// If index is -1, there is no existing collection in the target.
if (tidx == -1)
{
- // Create an empty target collection with the overlay collection's settings.
+ // Create an empty target collection with the overlay
+ // collection's settings.
tcoll = copy(overlayEvent.getCollection(collname));
// Add the new collection to the target event.
@@ -257,15 +263,16 @@
tcoll = targetEvent.getCollection(collname);
}
- // Handle overlay for each pair of target-overlay collections.
+ // Overlay overlay collection into target collection.
mergeCollection(tcoll, ocoll, dt);
}
return;
}
-
+
/**
- * overlayCollection overlays the overlayColl onto the targetColl applying dt.
+ * overlayCollection overlays the overlayColl onto the targetColl applying
+ * the delta time, dt.
* @param targetColl The target collection to be modified.
* @param overlayColl The overlay collection containing objects to merge into targetColl.
* @param dt A delta time parameter applied to sim types of overlayColl before merge-in.
@@ -277,73 +284,118 @@
// Handle a SimTrackerHit collection.
if (colltype.compareTo(LCIO.SIMTRACKERHIT) == 0)
{
- // Loop over hits to merge in.
- for (int ii = 0; ii < overlayColl.size(); ii++)
- {
- // Get the hit from the overlay collection.
- ISimTrackerHit hit = (ISimTrackerHit) overlayColl.getElementAt(ii);
-
- // Adjust time.
- hit.setTime(hit.getTime() + dt);
-
- // Add the hit to the target collection.
- targetColl.add(hit);
- }
+ mergeSimTrackerHitCollection(targetColl, overlayColl, dt);
}
// Handle a SimCalorimeterHit collection.
else if (colltype.compareTo(LCIO.SIMCALORIMETERHIT) == 0)
{
- // Loop over the overlay hits.
- for (int ii = 0; ii < overlayColl.size(); ii++)
- {
- // Get an overlay hit.
- ISimCalorimeterHit ohit = (ISimCalorimeterHit) overlayColl.getElementAt(ii);
-
- // Find a matching hit in target collection.
- ISimCalorimeterHit thit = findMatching(targetColl, ohit);
-
- // No matching hits?
- if (thit == null)
- {
- //System.out.println("new hit");
-
- // Copy the overlay hit without MCParticle contributions.
- thit = copy(ohit);
-
- // Add the hit to the target collection.
- targetColl.addElement(thit);
- }
-
- // Apply MCParticle contributions from overlay to target.
- addMCParticleContributions(thit, ohit, dt);
- }
+ mergeSimCalorimeterHitCollection(targetColl, overlayColl, dt);
}
// Handle an MCParticle collection.
else if (colltype.compareTo(LCIO.MCPARTICLE) == 0)
- {
- for (int ii = 0; ii < overlayColl.size(); ii++)
- {
- // Get the next MCParticle to add in.
- IMCParticle p = (IMCParticle) overlayColl.getElementAt(ii);
-
- // Apply dt to particle time.
- p.setTime(p.getTime() + dt);
-
- // Add to target collection.
- targetColl.add(p);
- }
+ {
+ mergeMCParticleCollection(targetColl, overlayColl, dt);
}
// Handle a default collection.
else
{
- for (int ii = 0; ii < overlayColl.size(); ii++)
+ mergeDefaultCollection(targetColl, overlayColl);
+ }
+
+ }
+
+ /**
+ * Merge overlayColl into targetColl without applying a delta time.
+ * This is used to merge non-simulator collections.
+ * @param targetColl The target collection to be modified.
+ * @param overlayColl The overlay collection containing objects to merge into targetColl.
+ */
+ public static void mergeDefaultCollection(LCCollection targetColl, LCCollection overlayColl)
+ {
+ for (int ii = 0; ii < overlayColl.size(); ii++)
+ {
+ targetColl.add(overlayColl.getElementAt(ii));
+ }
+ }
+
+ /**
+ * Merge MCParticle collection overlayColl into targetColl.
+ * @param targetColl The target collection to be modified.
+ * @param overlayColl The overlay collection containing objects to merge into targetColl.
+ * @param dt A delta time parameter added to the particle's production time.
+ */
+ public static void mergeMCParticleCollection(LCCollection targetColl, LCCollection overlayColl, float dt)
+ {
+ for (int ii = 0; ii < overlayColl.size(); ii++)
+ {
+ // Get the next MCParticle to add in.
+ IMCParticle p = (IMCParticle) overlayColl.getElementAt(ii);
+
+ // Apply dt to particle time.
+ p.setTime(p.getTime() + dt);
+
+ // Add to target collection.
+ targetColl.add(p);
+ }
+ }
+
+ /**
+ * Merge SimCalorimeterHit collection overlayColl into targetColl.
+ * Hits with matching cell ID's are combined.
+ * @param targetColl The target collection to be modified.
+ * @param overlayColl The overlay collection containing objects to merge into targetColl.
+ * @param dt A delta time parameter added to MCParticle contributions from overlayColl's hits.
+ */
+ public static void mergeSimCalorimeterHitCollection(LCCollection targetColl, LCCollection overlayColl, float dt)
+ {
+ // Loop over the overlay hits.
+ for (int ii = 0; ii < overlayColl.size(); ii++)
+ {
+ // Get an overlay hit.
+ ISimCalorimeterHit ohit = (ISimCalorimeterHit) overlayColl.getElementAt(ii);
+
+ // Find a matching hit in target collection.
+ ISimCalorimeterHit thit = findMatching(targetColl, ohit);
+
+ // No matching hits?
+ if (thit == null)
{
- targetColl.add(overlayColl.getElementAt(ii));
+ //System.out.println("new hit");
+
+ // Copy the overlay hit without MCParticle contributions.
+ thit = copy(ohit);
+
+ // Add the hit to the target collection.
+ targetColl.addElement(thit);
}
+
+ // Apply MCParticle contributions from overlay to target.
+ addMCParticleContributions(thit, ohit, dt);
}
+ }
+ /**
+ * Merge SimTrackerHit collection overlayColl into targetColl.
+ * @param targetColl The target collection to be modified.
+ * @param overlayColl The overlay collection containing objects to merge into targetColl.
+ * @param dt A delta time parameter added to the time of hits from overlayColl.
+ */
+ public static void mergeSimTrackerHitCollection(LCCollection targetColl, LCCollection overlayColl, float dt)
+ {
+ // Loop over hits to merge in.
+ for (int ii = 0; ii < overlayColl.size(); ii++)
+ {
+ // Get the hit from the overlay collection.
+ ISimTrackerHit hit = (ISimTrackerHit) overlayColl.getElementAt(ii);
+
+ // Adjust time.
+ hit.setTime(hit.getTime() + dt);
+
+ // Add the hit to the target collection.
+ targetColl.add(hit);
+ }
}
-
+
/**
* Find a SimCalorimeterHit in coll with matching cellId0, cellId1.
* @return The first match of hit in coll.
@@ -351,7 +403,7 @@
* @param hit Matching hit to be searched for in coll.
*/
public static ISimCalorimeterHit findMatching(LCCollection coll, SimCalorimeterHit hit)
- {
+ {
ISimCalorimeterHit match = null;
for (int i = 0; i < coll.size(); i++)
@@ -363,7 +415,7 @@
break;
}
}
-
+
return match;
}
@@ -397,7 +449,7 @@
{
// Get the hit energy.
float e = hit.getEnergy();
-
+
for (int j = 0; j < hit.getNMCContributions(); j++)
{
// PDGID might not be set.
@@ -407,19 +459,16 @@
pdgid = target.getPDGCont(j);
}
catch (Exception x)
- {}
+ {
+ }
// Add this MCParticle contribution.
- target.addMCParticleContribution(
- hit.getParticleCont(j),
- hit.getEnergyCont(j),
- hit.getTimeCont(j) + dt,
- pdgid);
-
+ target.addMCParticleContribution(hit.getParticleCont(j), hit.getEnergyCont(j), hit.getTimeCont(j) + dt, pdgid);
+
// Increment the energy by this particle contribution.
e += hit.getEnergyCont(j);
}
-
+
// Set the energy in the new hit.
target.setEnergy(e);
}
@@ -456,27 +505,7 @@
return newcoll;
}
-
- /**
- * Create an array of LCReaders to be read in parallel.
- * @return Array of open LCReaders.
- * @param Array of input files.
- */
- public static LCReader[] createReaders(File[] infiles) throws IOException
- {
- // Make a reader for each input event.
- LCReader[] readers = new LCReader[infiles.length];
- for (int i = 0; i < infiles.length; i++)
- {
- // Create a new reader.
- readers[i] = LCFactory.getInstance().createLCReader();
- // Open the reader for this file.
- readers[i].open(((File) infiles[i]).getCanonicalPath());
- }
- return readers;
- }
-
/**
* Create a Map of LCReader to Integer from a Map of File to Integer.
* @param fileMap Input map of File to Integer.
@@ -487,140 +516,24 @@
{
Map readMap = new HashMap();
- for (Iterator iter=fileMap.keySet().iterator(); iter.hasNext();)
+ for (Iterator iter = fileMap.keySet().iterator(); iter.hasNext();)
{
// Create a new reader.
LCReader reader = LCFactory.getInstance().createLCReader();
// Get the next file.
- File f = (File)iter.next();
+ File f = (File) iter.next();
// Open the reader.
reader.open(f.getCanonicalPath());
-
+
// Get number of events to read per merge.
- Integer nreads = (Integer)fileMap.get(f);
-
+ Integer nreads = (Integer) fileMap.get(f);
+
// Map the reader to number of reads.
- readMap.put(reader, (Object)nreads);
+ readMap.put(reader, (Object) nreads);
}
-
- return readMap;
- }
- /**
- * Close all of the readers.
- * @param readers Array of LCReaders to be closed.
- */
- public static void closeReaders(LCReader[] readers) throws IOException
- {
- for (int i = 0; i < readers.length; i++)
- {
- try
- {
- readers[i].close();
- }
- catch (Throwable t)
- {
- // Ignore errors on close.
- }
- }
+ return readMap;
}
-
-
-}
-
-/**
- * Merge nEventsToRead events from each File in infiles into a single event in outfile,
- * until records in infiles are exhausted or maxevents are created.
- * @return The number of combined events created.
- * @param outfile Output target file.
- * @param infiles Input events to merge in.
- * @param nEventsToRead Number of events to read at once into one output event.
- * @param maxEventsToWrite Maximum number of output events to create.
- * @param dt The time delta.
- */
-/*
-public static int mergeFiles(
- File outfile,
- File[] infiles,
- int nEventsToRead,
- int maxEventsToWrite,
- float dt,
- boolean incrTime) throws IOException
-{
- // Create the writer.
- LCWriter writer = LCFactory.getInstance().createLCWriter();
-
- // Open the writer for the new file containing the merged events.
- writer.open(outfile.getCanonicalPath(), LCIO.WRITE_NEW);
-
- // Create the array of LCReaders.
- LCReader[] readers = createReaders(infiles);
-
- // Count of total output events.
- int nevents = 0;
-
- // File read loop.
- for (;;)
- {
- System.err.println("nevents: " + nevents);
-
- // Check if max output events is reached.
- if (nevents >= maxEventsToWrite)
- break;
-
- // Create the new output event.
- ILCEvent target = new ILCEvent();
-
- // First time, the event header needs to
- // be set from the first LCEvent read.
- boolean setEventHeader = true;
-
- // Total events merged in from all sources in this pass.
- int totmerged = 0;
-
- // Loop over the readers.
- for (int i = 0; i < readers.length; i++)
- {
- // Get the next reader.
- LCReader reader = readers[i];
-
- // Merge ntoread events from this reader into target with delta time of dt.
- int nmerged = MergeUtil.mergeEvents(target, reader, nEventsToRead, setEventHeader, dt, incrTime);
-
- // DEBUG
- System.err.println("nmerged: " + nmerged);
-
- // Increment total merged.
- totmerged += nmerged;
-
- // Next time, don't need to set the header.
- setEventHeader = false;
- }
-
- // Write out the combined event if something got merged in.
- if (totmerged > 0)
- {
- //System.err.println("totmerged: " + totmerged);
-
- writer.writeEvent(target);
- nevents++;
- }
- else
- {
- // Done!
- break;
- }
- } // file read loop
-
- // Close the writer.
- writer.close();
-
- // Close the readers.
- closeReaders(readers);
-
- // Return number of events created.
- return nevents;
-}
-*/
+}
\ No newline at end of file