Commit in lcio/src/java/hep/lcio/util on MAIN
MergeFileParameters.java+115added 1.1
CommandLineTool.java+99-561.2 -> 1.3
FileUtil.java+5-41.1 -> 1.2
MergeCommandHandler.java+8-111.2 -> 1.3
MergeUtil.java+200-2871.3 -> 1.4
MergeFileOptions.java-741.1 removed
+427-432
1 added + 1 removed + 4 modified, total 6 files
JM: Cleanup merge code and add javadoc.

lcio/src/java/hep/lcio/util
MergeFileParameters.java added at 1.1
diff -N MergeFileParameters.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ MergeFileParameters.java	26 Apr 2006 19:37:05 -0000	1.1
@@ -0,0 +1,115 @@
+package hep.lcio.util;
+
+import hep.lcio.event.LCEvent;
+import hep.lcio.implementation.io.LCFactory;
+import hep.lcio.io.LCReader;
+
+import java.io.File;
+import java.io.IOException;
+
+/**
+ * Encapsulates parameters for events to be merged.
+ * The settings are input file, number of reads per event,
+ * start time, and delta time.
+ * 
+ * @author jeremym
+ * @version $Id: MergeFileParameters.java,v 1.1 2006/04/26 19:37:05 jeremy Exp $
+ */
+public final class MergeFileParameters
+{		
+	int nreads = 1;
+	float startt = 0;
+	float dt = 0;
+	File f;		
+	LCReader reader = LCFactory.getInstance().createLCReader();
+	
+	MergeFileParameters(File f, int nreads, float startt, float dt) throws IOException
+	{
+		this.f = f;
+		this.nreads = nreads;
+		this.startt = startt;
+		this.dt = dt;
+		
+		open();
+	}
+	
+	MergeFileParameters(File f) throws IOException
+	{
+		this.f = f;
+		
+		open();
+	}
+	
+	/**
+	 * Get the number of reads per event.
+	 * @return The number of reads to do per output event.
+	 */
+	public int nreads()
+	{
+		return nreads;	
+	}
+	
+	/**
+	 * Get the starting time in ns.
+	 * @return Start time in ns.
+	 */
+	public float startt()
+	{
+		return startt;
+	}
+	
+	/**
+	 * Get the delta time in ns.
+	 * @return Delta time in ns.
+	 */
+	public float dt()
+	{
+		return dt;
+	}
+	
+	/**
+	 * Get a file object for these input events.
+	 * @return The file corresponding to these input events.
+	 */
+	public File file()
+	{
+		return f;
+	}
+
+	/**
+	 * Get the LCReader associated with these input events.
+	 * @return The LCReader from this input file.
+	 */
+	public LCReader reader()
+	{
+		return reader;
+	}
+	
+	/**
+	 * Open the LCReader.
+	 * @throws IOException
+	 */
+	public void open() throws IOException
+	{
+		reader.open(file().getAbsolutePath());
+	}
+	
+	/**
+	 * Close the LCReader.
+	 * @throws IOException
+	 */
+	public void close() throws IOException
+	{
+		reader.close();
+	}
+	
+	/**
+	 * Get the next event.
+	 * @return @see LCReader.readNextEvent
+	 * @throws IOException
+	 */
+	public LCEvent nextEvent() throws IOException
+	{
+		return reader.readNextEvent();
+	}
+}
\ No newline at end of file

lcio/src/java/hep/lcio/util
CommandLineTool.java 1.2 -> 1.3
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
FileUtil.java 1.1 -> 1.2
diff -u -r1.1 -r1.2
--- FileUtil.java	26 Apr 2006 00:56:53 -0000	1.1
+++ FileUtil.java	26 Apr 2006 19:37:05 -0000	1.2
@@ -10,14 +10,15 @@
 /**
  * Miscellaneous java file utilities.
  * @author jeremym
- * @version $Id: FileUtil.java,v 1.1 2006/04/26 00:56:53 jeremy Exp $
+ * @version $Id: FileUtil.java,v 1.2 2006/04/26 19:37:05 jeremy Exp $
  */
 public abstract class FileUtil
 {
 	/**
-	 * Reads a file into an ArrayList.
+	 * Reads the lines of file at path fileName into 
+	 * an ArrayList.
 	 * @param fileName Name of the input file.
-	 * @return A List with one line String per entry.
+	 * @return A List with one String file line per entry.
 	 */
 	public static List loadFile(String fileName)
 	{
@@ -49,7 +50,7 @@
 	}
 	
 	/**
-	 * Return an array of files from an array of file paths.
+	 * Return an array of @see File objects from an array of paths.
 	 * @param fstr Array of file paths.
 	 * @return Array of File objects.
 	 */

lcio/src/java/hep/lcio/util
MergeCommandHandler.java 1.2 -> 1.3
diff -u -r1.2 -r1.3
--- MergeCommandHandler.java	26 Apr 2006 00:56:53 -0000	1.2
+++ MergeCommandHandler.java	26 Apr 2006 19:37:05 -0000	1.3
@@ -20,7 +20,7 @@
  * passes the results to a method from MergeUtil.
  * 
  * @author jeremym
- * @version $Id: MergeCommandHandler.java,v 1.2 2006/04/26 00:56:53 jeremy Exp $
+ * @version $Id: MergeCommandHandler.java,v 1.3 2006/04/26 19:37:05 jeremy Exp $
  */
 public class MergeCommandHandler extends CommandHandler
 {
@@ -28,12 +28,8 @@
 	Options options = new Options();
 	File outfile;
 	File[] infiles;
-	//float dt = 0;
 	int maxevents = Integer.MAX_VALUE;
-	//int ntoread = 1;
-	//boolean incrTime = false;
 	List mergeFiles;
-
 	float def_dt = 0;
 	float def_startt = 0;
 	int def_ntoread = 1;
@@ -165,9 +161,10 @@
 	}
 	
 	/**
-	 * Create a map of input files to number of reads to do per output (merged) event.
+	 * Create a list of @see MergeFileParameters objects from the
+	 * input file specified with -f.
 	 * @param lines File lines read from input file list (-f option).
-	 * @return Map of File to number of reads per merged event.
+	 * @return List of MergeFileParameters objects.
 	 */
 	public List createMergeFiles(List lines) throws IOException
 	{	
@@ -205,7 +202,7 @@
 				File f = new File(fname);
 				
 				// Create the merge file object.
-				MergeFileOptions fopt = new MergeFileOptions(f, nreads, startt, dt);
+				MergeFileParameters fopt = new MergeFileParameters(f, nreads, startt, dt);
 				
 				// Add this file with options to merge files list.
 				mfiles.add(fopt);
@@ -216,8 +213,8 @@
 	
 	/**
 	 * Create the default merge options, which is one event from the file per merged output event.
-	 * @param files An array of input Files.
-	 * @return A Map of File to Integer specifiying number of reads to do from that file per merged output event.
+	 * @param files An array of input File objects.
+	 * @return A List of MergeFileParameters.
 	 */
 	public List createDefaultMergeFiles(File[] files) throws IOException
 	{
@@ -226,7 +223,7 @@
 		{
 			for (int i=0; i<files.length;i++)
 			{
-				m.add(new MergeFileOptions(files[i], def_ntoread, def_startt, def_dt));
+				m.add(new MergeFileParameters(files[i], def_ntoread, def_startt, def_dt));
 			}			
 		}
 		return m;

lcio/src/java/hep/lcio/util
MergeUtil.java 1.3 -> 1.4
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

lcio/src/java/hep/lcio/util
MergeFileOptions.java removed after 1.1
diff -N MergeFileOptions.java
--- MergeFileOptions.java	26 Apr 2006 00:56:53 -0000	1.1
+++ /dev/null	1 Jan 1970 00:00:00 -0000
@@ -1,74 +0,0 @@
-package hep.lcio.util;
-
-import hep.lcio.event.LCEvent;
-import hep.lcio.implementation.io.LCFactory;
-import hep.lcio.io.LCReader;
-
-import java.io.File;
-import java.io.IOException;
-
-public final class MergeFileOptions
-{		
-	int nreads = 1;
-	float startt = 0;
-	float dt = 0;
-	File f;		
-	LCReader reader = LCFactory.getInstance().createLCReader();
-	
-	MergeFileOptions(File f, int nreads, float startt, float dt) throws IOException
-	{
-		this.f = f;
-		this.nreads = nreads;
-		this.startt = startt;
-		this.dt = dt;
-		
-		open();
-	}
-	
-	MergeFileOptions(File f) throws IOException
-	{
-		this.f = f;
-		
-		open();
-	}
-	
-	public int nreads()
-	{
-		return nreads;	
-	}
-	
-	public float startt()
-	{
-		return startt;
-	}
-	
-	public float dt()
-	{
-		return dt;
-	}
-	
-	public File file()
-	{
-		return f;
-	}
-	
-	public LCReader reader()
-	{
-		return reader;
-	}
-	
-	public void open() throws IOException
-	{
-		reader.open(file().getAbsolutePath());
-	}
-	
-	public void close() throws IOException
-	{
-		reader.close();
-	}
-	
-	public LCEvent nextEvent() throws IOException
-	{
-		return reader.readNextEvent();
-	}
-}
\ No newline at end of file
CVSspam 0.2.8