Print

Print


Commit in lcio on MAIN
bin/lcio+1-11.6 -> 1.7
config/lcio.properties+3-31.68 -> 1.69
src/java/hep/lcio/util/MergeCommandHandler.java+270-2621.10 -> 1.11
                      /MergeFileParameters.java+146-1141.1 -> 1.2
                      /MergeUtil.java+530-5261.8 -> 1.9
tools/commons-math-1.2.jar[binary]added 1.1
+950-906
1 added + 5 modified, total 6 files
Add support for poisson distribution to merge facility

lcio/bin
lcio 1.6 -> 1.7
diff -u -r1.6 -r1.7
--- lcio	8 May 2009 23:27:38 -0000	1.6
+++ lcio	22 May 2009 20:18:59 -0000	1.7
@@ -33,7 +33,7 @@
 
 LOCALCLASSPATH=$LCIO/lib/lcio.jar:$LCIO/tools/sio.jar:$LCIO/tools/jdom.jar:$LCIO/tools/saxpath.jar
 LOCALCLASSPATH=$LOCALCLASSPATH:$LCIO/tools/jaxen-jdom.jar:$LCIO/tools/jaxen-core.jar:$LCIO/tools/jel.jar
-LOCALCLASSPATH=$LOCALCLASSPATH:$LCIO/tools/commons-cli-1.0.jar:$LCIO/tools/commons-lang-2.1.jar
+LOCALCLASSPATH=$LOCALCLASSPATH:$LCIO/tools/commons-cli-1.0.jar:$LCIO/tools/commons-lang-2.1.jar:$LCIO/tools/commons-math-1.2.jar
 #LOCALCLASSPATH=$LOCALCLASSPATH:$LCIO/tools/freehep-hep.jar:$LCIO/tools/freehep-physics.jar:$LCIO/tools/freehep-base.jar
 LOCALCLASSPATH=$LOCALCLASSPATH:$LCIO/tools/freehep-mcfio-2.0.1.jar:$LCIO/tools/freehep-stdhep-2.0.2.jar:$LCIO/tools/freehep-sio-2.0.jar:$LCIO/tools/freehep-xdr-2.0.3.jar:$LCIO/tools/freehep-physics-2.1.jar
 

lcio/config
lcio.properties 1.68 -> 1.69
diff -u -r1.68 -r1.69
--- lcio.properties	13 Dec 2008 13:13:50 -0000	1.68
+++ lcio.properties	22 May 2009 20:18:59 -0000	1.69
@@ -1,7 +1,7 @@
 # ANT property file for LCIO
 #
 # Author: Mark Donszelmann
-# Version: $Id: lcio.properties,v 1.68 2008/12/13 13:13:50 gaede Exp $
+# Version: $Id: lcio.properties,v 1.69 2009/05/22 20:18:59 cassell Exp $
 #
 debug=true
 
@@ -22,10 +22,10 @@
 # test properties --JM
 test.output=./reports
 test.html=./reports/html
-test.classpath=lib/lcio.jar;tools/sio.jar;tools/commons-cli-1.0.jar;tools/commons-lang-2.1.jar
+test.classpath=lib/lcio.jar;tools/sio.jar;tools/commons-cli-1.0.jar;tools/commons-lang-2.1.jar;tools/commons-math-1.2.jar
 test.format=frames
 
-classpath=src/java;tools/saxpath.jar;tools/jel.jar;tools/jdom.jar;tools/jaxen-core.jar;tools/jaxen-jdom.jar;tools/commons-cli-1.0.jar;tools/commons-lang-2.1.jar;tools/freehep-physics-2.1.jar;tools/freehep-mcfio-2.0.1.jar;tools/freehep-sio-2.0.jar;tools/freehep-stdhep-2.0.2.jar;tools/freehep-xdr-2.0.3.jar
+classpath=src/java;tools/saxpath.jar;tools/jel.jar;tools/jdom.jar;tools/jaxen-core.jar;tools/jaxen-jdom.jar;tools/commons-cli-1.0.jar;tools/commons-lang-2.1.jar;tools/freehep-physics-2.1.jar;tools/freehep-mcfio-2.0.1.jar;tools/freehep-sio-2.0.jar;tools/freehep-stdhep-2.0.2.jar;tools/freehep-xdr-2.0.3.jar;tools/commons-math-1.2.jar
 
 srcpath=src/java
 exp.srcpath=

lcio/src/java/hep/lcio/util
MergeCommandHandler.java 1.10 -> 1.11
diff -u -r1.10 -r1.11
--- MergeCommandHandler.java	1 Feb 2007 19:33:24 -0000	1.10
+++ MergeCommandHandler.java	22 May 2009 20:18:59 -0000	1.11
@@ -1,262 +1,270 @@
-package hep.lcio.util;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-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;
-
-/**
- * This is the CommandHandler for the merge utility.
- *
- * It parses 'lcio merge' command-line options and
- * passes the results to a method from MergeUtil.
- *
- * @author jeremym
- * @version $Id: MergeCommandHandler.java,v 1.10 2007/02/01 19:33:24 jeremy Exp $
- */
-public class MergeCommandHandler extends CommandHandler
-{
-	File outfile;
-	File[] infiles;
-	int maxevents = Integer.MAX_VALUE;
-	List mergeFiles;
-	float def_dt = 0;
-	float def_startt = 0;
-	int def_ntoread = 1;
-
-	/**
-	 * MergeCommandHandler ctor.
-	 */
-	MergeCommandHandler()
-	{
-		// Call CommandHandler ctor.
-		super("merge", "Merge LCIO events together.");
-
-		// Setup merge command options.
-		options = createMergeOptions();
-	}
-
-	/**
-	 * Creates the CLI options for the merge command.
-	 * @return Options for the merge command.
-	 */
-	private static Options createMergeOptions()
-	{
-		Options options = new Options();
-		
-		Option opt = new Option("h", false, "Print merge usage.");
-		options.addOption(opt);
-		
-		opt = new Option("o", false, "Set the output file.");
-		opt.setArgs(1);
-		options.addOption(opt);
-				
-		opt = new Option("f", false, "Add an input file.");
-		opt.setArgs(1);
-		options.addOption(opt);
-
-		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);
-
-		opt = new Option("n", true, "Set maximum number of output events.");
-		opt.setArgs(1);
-		options.addOption(opt);
-
-		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("i", 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 -f 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.
-	 */
-	public void parse(String[] argv) throws Exception
-	{
-		CommandLine cl = parser.parse(options, argv);
-
-		if ( cl.hasOption("h") )
-		{
-			printUsage(true);
-		}
-		
-		// Must have at least one of -i or -f.
-		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.
-		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("i"))
-		{
-			mergeFiles = createMergeFiles(FileUtil.loadFile(cl.getOptionValue("i")));
-		}
-
-		// Add input files one-by-one.
-		if (cl.hasOption("f"))
-		{
-			// Create input file array.
-			infiles = FileUtil.createFiles(cl.getOptionValues("f"));
-
-			// Create default merge files.
-			mergeFiles = createDefaultMergeFiles(infiles);
-		}
-		
-		// Output file.
-		if (cl.hasOption("o"))
-		{
-			outfile = new File(cl.getOptionValue("o"));
-		}
-		else {
-			outfile = new File("merged_events.slcio");
-		}
-
-		System.err.println("Set output file: " + outfile.getAbsolutePath());
-
-		// Set the default time delta.
-		if (cl.hasOption("t"))
-		{
-			def_dt = Float.parseFloat(cl.getOptionValue("t"));
-		}
-
-		// Set the default start time.
-		if (cl.hasOption("T"))
-		{
-			def_startt = Float.parseFloat(cl.getOptionValue("T"));
-		}
-
-		// Set the maximum number of merged events.
-		if (cl.hasOption("n"))
-		{
-			maxevents = Integer.parseInt(cl.getOptionValue("n"));
-		}
-		
-		// Set the maximum number of merged events.
-		if (cl.hasOption("e"))
-		{
-			def_ntoread = Integer.parseInt(cl.getOptionValue("n"));
-		}
-	}
-
-	/**
-	 * Execute the merge command with current arguments.
-	 */
-	public void execute() throws Exception
-	{
-		System.out.println("maxevents="+maxevents);
-		MergeUtil.mergeFiles(outfile, mergeFiles, maxevents);
-	}
-
-	/**
-	 * 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 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.
-			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]);
-
-				// 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.
-	 * @return A List of MergeFileParameters.
-	 */
-	public List createDefaultMergeFiles(File[] files) throws IOException
-	{
-		List m = new ArrayList();
-		if (files != null)
-		{
-			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.
-	 */
-	public void printUsage(boolean doExit)
-	{
-		HelpFormatter help = new HelpFormatter();
-
-		help.printHelp("LCIO Merge command", "merge command", options, "");
-
-		if (doExit)
-		{
-			System.exit(0);
-		}
-	}
-}
+package hep.lcio.util;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+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;
+
+/**
+ * This is the CommandHandler for the merge utility.
+ *
+ * It parses 'lcio merge' command-line options and
+ * passes the results to a method from MergeUtil.
+ *
+ * @author jeremym
+ * @version $Id: MergeCommandHandler.java,v 1.11 2009/05/22 20:18:59 cassell Exp $
+ */
+public class MergeCommandHandler extends CommandHandler
+{
+	File outfile;
+	File[] infiles;
+	int maxevents = Integer.MAX_VALUE;
+	List mergeFiles;
+	float def_dt = 0;
+	float def_startt = 0;
+	int def_ntoread = 1;
+	double def_mreads = 0.;
+
+	/**
+	 * MergeCommandHandler ctor.
+	 */
+	MergeCommandHandler()
+	{
+		// Call CommandHandler ctor.
+		super("merge", "Merge LCIO events together.");
+
+		// Setup merge command options.
+		options = createMergeOptions();
+	}
+
+	/**
+	 * Creates the CLI options for the merge command.
+	 * @return Options for the merge command.
+	 */
+	private static Options createMergeOptions()
+	{
+		Options options = new Options();
+		
+		Option opt = new Option("h", false, "Print merge usage.");
+		options.addOption(opt);
+		
+		opt = new Option("o", false, "Set the output file.");
+		opt.setArgs(1);
+		options.addOption(opt);
+				
+		opt = new Option("f", false, "Add an input file.");
+		opt.setArgs(1);
+		options.addOption(opt);
+
+		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);
+
+		opt = new Option("n", true, "Set maximum number of output events.");
+		opt.setArgs(1);
+		options.addOption(opt);
+
+		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("i", true, "Set input file list with format:\n[file_name],[n_reads_per_event],[start_time],[delta_time],[<reads> poisson]\n" +
+				"This option is not usable with the -f 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.
+	 */
+	public void parse(String[] argv) throws Exception
+	{
+		CommandLine cl = parser.parse(options, argv);
+
+		if ( cl.hasOption("h") )
+		{
+			printUsage(true);
+		}
+		
+		// Must have at least one of -i or -f.
+		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.
+		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("i"))
+		{
+			mergeFiles = createMergeFiles(FileUtil.loadFile(cl.getOptionValue("i")));
+		}
+
+		// Add input files one-by-one.
+		if (cl.hasOption("f"))
+		{
+			// Create input file array.
+			infiles = FileUtil.createFiles(cl.getOptionValues("f"));
+
+			// Create default merge files.
+			mergeFiles = createDefaultMergeFiles(infiles);
+		}
+		
+		// Output file.
+		if (cl.hasOption("o"))
+		{
+			outfile = new File(cl.getOptionValue("o"));
+		}
+		else {
+			outfile = new File("merged_events.slcio");
+		}
+
+		System.err.println("Set output file: " + outfile.getAbsolutePath());
+
+		// Set the default time delta.
+		if (cl.hasOption("t"))
+		{
+			def_dt = Float.parseFloat(cl.getOptionValue("t"));
+		}
+
+		// Set the default start time.
+		if (cl.hasOption("T"))
+		{
+			def_startt = Float.parseFloat(cl.getOptionValue("T"));
+		}
+
+		// Set the maximum number of merged events.
+		if (cl.hasOption("n"))
+		{
+			maxevents = Integer.parseInt(cl.getOptionValue("n"));
+		}
+		
+		// Set the maximum number of merged events.
+		if (cl.hasOption("e"))
+		{
+			def_ntoread = Integer.parseInt(cl.getOptionValue("n"));
+		}
+	}
+
+	/**
+	 * Execute the merge command with current arguments.
+	 */
+	public void execute() throws Exception
+	{
+		System.out.println("maxevents="+maxevents);
+		MergeUtil.mergeFiles(outfile, mergeFiles, maxevents);
+	}
+
+	/**
+	 * 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 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.
+			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]);
+
+				// Get the mean of a poisson distribution
+				double mreads = def_mreads;
+				if (fields.length > 4)
+					mreads = Double.parseDouble(fields[4]);
+
+				// Create the input file.
+				File f = new File(fname);
+
+				// Create the merge file object.
+				MergeFileParameters fopt;
+                                if(mreads > 0.)fopt = new MergeFileParameters(f, mreads, startt, dt);
+                                else 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.
+	 * @return A List of MergeFileParameters.
+	 */
+	public List createDefaultMergeFiles(File[] files) throws IOException
+	{
+		List m = new ArrayList();
+		if (files != null)
+		{
+			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.
+	 */
+	public void printUsage(boolean doExit)
+	{
+		HelpFormatter help = new HelpFormatter();
+
+		help.printHelp("LCIO Merge command", "merge command", options, "");
+
+		if (doExit)
+		{
+			System.exit(0);
+		}
+	}
+}

lcio/src/java/hep/lcio/util
MergeFileParameters.java 1.1 -> 1.2
diff -u -r1.1 -r1.2
--- MergeFileParameters.java	26 Apr 2006 19:37:05 -0000	1.1
+++ MergeFileParameters.java	22 May 2009 20:18:59 -0000	1.2
@@ -1,115 +1,147 @@
-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();
-	}
+package hep.lcio.util;
+
+import hep.lcio.event.LCEvent;
+import hep.lcio.implementation.io.LCFactory;
+import hep.lcio.io.LCReader;
+import org.apache.commons.math.distribution.DistributionFactory;
+import org.apache.commons.math.distribution.PoissonDistribution;
+import java.util.Random;
+
+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.2 2009/05/22 20:18:59 cassell Exp $
+ */
+public final class MergeFileParameters
+{		
+	int nreads = 1;
+        double mreads = 0.;
+	float startt = 0;
+	float dt = 0;
+	File f;		
+        PoissonDistribution _poisson;
+	LCReader reader = LCFactory.getInstance().createLCReader();
+	DistributionFactory df = DistributionFactory.newInstance();
+        Random ran;
+	
+	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, double mreads, float startt, float dt) throws IOException
+	{
+		this.f = f;
+		this.mreads = mreads;
+		this.startt = startt;
+		this.dt = dt;
+	        _poisson = df.createPoissonDistribution( mreads );
+                ran = new Random();
+		
+		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()
+	{
+                if(mreads > 0.)
+                {
+                   int n = 0;
+                   try
+                   {
+                      n = _poisson.inverseCumulativeProbability(ran.nextDouble()) + 1;
+                   }
+                   catch(Exception e)
+                   {
+                      System.out.println("Poisson error: "+e.toString());
+                   }
+                   return n;
+                }
+		else 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
MergeUtil.java 1.8 -> 1.9
diff -u -r1.8 -r1.9
--- MergeUtil.java	1 Feb 2007 20:50:11 -0000	1.8
+++ MergeUtil.java	22 May 2009 20:18:59 -0000	1.9
@@ -1,526 +1,530 @@
-package hep.lcio.util;
-
-import hep.lcio.event.LCCollection;
-import hep.lcio.event.LCEvent;
-import hep.lcio.event.LCIO;
-import hep.lcio.event.SimCalorimeterHit;
-import hep.lcio.implementation.event.ILCCollection;
-import hep.lcio.implementation.event.ILCEvent;
-import hep.lcio.implementation.event.IMCParticle;
-import hep.lcio.implementation.event.ISimCalorimeterHit;
-import hep.lcio.implementation.event.ISimTrackerHit;
-import hep.lcio.implementation.io.LCFactory;
-import hep.lcio.io.LCReader;
-import hep.lcio.io.LCWriter;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.Iterator;
-import java.util.List;
-
-/**
- * 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.8 2007/02/01 20:50:11 jeremy Exp $
- */
-abstract public class MergeUtil
-{
-	/** 
-	 * 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.
-		writer.open(outfile.getCanonicalPath(), LCIO.WRITE_NEW);
-
-		// Count of total merged events that were created.
-		int nevents = 0;
-		
-		boolean done=false;
-
-		// File read loop.
-		for (;;)
-		{			
-			// Check if max output events is reached.
-			if (nevents >= maxEvents)
-				break;
-			
-			System.out.println("merge - processing event <"+(nevents+1)+">");
-
-			// Create the new output event.
-			ILCEvent targetEvent = new ILCEvent();
-
-			// 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 files.
-			int totmerged = 0;
-
-			// 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 the starting time.
-				float startt = mfile.startt();
-
-				// 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(targetEvent, reader, ntoread, setEventHeader, startt, dt);
-				
-				// Check if the input file ran out of events.
-				if (nmerged==0) {
-				
-					System.out.println("EOF on <"+mfile.file().getCanonicalPath()+">.  This merge event will be discarded.");
-				
-					// Invalidate this event.
-					totmerged=0;
-					
-					// Stop processing this event.
-					break;
-				}
-
-				// Increment total merged.
-				totmerged += nmerged;
-
-				// Next time, don't need to set the header.
-				setEventHeader = false;
-			}
-
-			// Write out the combined event if it is valid.
-			// The totmerged counter will be reset if any
-			// of the input events runs out of events.
-			if (totmerged > 0)
-			{
-				writer.writeEvent(targetEvent);
-				nevents++;
-			}
-			else
-			{
-				// Done!
-				break;
-			}
-		} // file read loop
-
-		System.out.println("Created " + nevents + " merged events.");
-
-		// Close the writer.
-		writer.close();
-
-		// Close the readers.
-		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 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
-	{
-		// Read the next event from the reader.
-		LCEvent nextEvent = overlayEvents.readNextEvent(LCIO.UPDATE);
-
-		// Return 0 if reader is exhausted.
-		if (nextEvent == null)
-		{
-			return 0;
-		}
-
-		// Set the event header from the first event if setEventHeader flag is true.
-		if (setEventHeader)
-		{
-			ILCEvent itargetEvent = (ILCEvent) targetEvent;
-			itargetEvent.setDetectorName(nextEvent.getDetectorName());
-			itargetEvent.setEventNumber(nextEvent.getEventNumber());
-			itargetEvent.setRunNumber(nextEvent.getRunNumber());
-			itargetEvent.setTimeStamp(nextEvent.getTimeStamp());
-		}
-
-		// Number of events merged in.
-		int nevt = 0;
-
-		// Set starting time.
-		float time = startt;
-
-		// Read loop.
-		while (nextEvent != null)
-		{
-			// 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(LCIO.UPDATE);
-
-			// Increment the time for next event.
-			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.
-	 * @param overlayEvent An event to be overlayed onto targetEvent.
-	 * @param dt A delta time to apply to sim types.
-	 */
-	public static void mergeSingleEvent(ILCEvent targetEvent, LCEvent overlayEvent, float dt)
-	{
-		//System.out.println("mergeSingleEvent");
-		
-		if (overlayEvent.getCollectionNames().length == 0)
-		{
-			// Empty event, nothing to do.
-			return;
-		}
-
-		// Get names of collections already existing in target.
-		String[] tcolls = targetEvent.getCollectionNames();
-
-		// Get names of collections to be merged in.
-		String[] ocolls = overlayEvent.getCollectionNames();
-
-		// Iterate over the overlay collections that will be merged into target.
-		for (int i = 0; i < ocolls.length; i++)
-		{
-			// Get the name of this overlay collection.
-			String collname = ocolls[i];
-			
-			//System.out.println("collname="+ocolls[i]);
-
-			// Get this overlay collection.
-			LCCollection ocoll = overlayEvent.getCollection(collname);
-
-			// Declare the target collection reference,
-			// which will be either a new collection or
-			// an existing one from the target.
-			LCCollection tcoll = null;
-
-			// Find the index of this overlay collection in the target.
-			int tidx = getCollectionIdx(tcolls, collname);
-
-			// 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.
-				tcoll = copy(overlayEvent.getCollection(collname));
-
-				// Add the new collection to the target event.
-				targetEvent.addCollection(tcoll, collname);
-			}
-			else
-			{
-				// Get the existing target collection.
-				tcoll = targetEvent.getCollection(collname);
-			}		
-			
-			//System.out.println("merging " + tcolls[i] + " and " + ocolls[i]);
-
-			// Overlay overlay collection into target collection.
-			mergeCollection(tcoll, ocoll, dt);
-		}
-
-		return;
-	}
-
-	/**
-	 * 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.
-	 */
-	public static void mergeCollection(LCCollection targetColl, LCCollection overlayColl, float dt)
-	{
-		//System.out.println("mergeCollection");
-				
-		String colltype = targetColl.getTypeName();
-		
-		//System.out.println("colltype="+colltype);
-
-		// Handle a SimTrackerHit collection.
-		if (colltype.compareTo(LCIO.SIMTRACKERHIT) == 0)
-		{
-			mergeSimTrackerHitCollection(targetColl, overlayColl, dt);
-		}
-		// Handle a SimCalorimeterHit collection.
-		else if (colltype.compareTo(LCIO.SIMCALORIMETERHIT) == 0)
-		{
-			mergeSimCalorimeterHitCollection(targetColl, overlayColl, dt);
-		}
-		// Handle an MCParticle collection.
-		else if (colltype.compareTo(LCIO.MCPARTICLE) == 0)
-		{
-			mergeMCParticleCollection(targetColl, overlayColl, dt);
-		}
-		// Handle a default collection.
-		else
-		{
-			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)
-			{
-				//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.
-	 * @param Collection of type SIMCALORIMETERHIT.
-	 * @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++)
-		{
-			ISimCalorimeterHit checkhit = (ISimCalorimeterHit) coll.getElementAt(i);
-			if ((checkhit.getCellID0() == hit.getCellID0() && checkhit.getCellID1() == hit.getCellID1()) || checkhit == hit)
-			{
-				match = checkhit;
-				break;
-			}
-		}
-
-		return match;
-	}
-
-	/** 
-	 * Find the given name in collnames.
-	 * @return The index of name in collnames or -1 if not found.
-	 * @param collnames A list of collection names.
-	 * @param name A collection name to find in collnames. 
-	 */
-	public static int getCollectionIdx(String[] collnames, String name)
-	{
-		int idx = -1;
-		for (int i = 0; i < collnames.length; i++)
-		{
-			if (collnames[i].compareTo(name) == 0)
-			{
-				idx = i;
-				break;
-			}
-		}
-		return idx;
-	}
-
-	/** 
-	 * Add MCParticle contributions from an overlay hit to a target hit. 
-	 * @param target Hit that receives MCParticle contributions.
-	 * @param hit Hit containing MCParticle contributions to be copied.
-	 * @param dt Delta time to apply to contributions.
-	 */
-	public static void addMCParticleContributions(ISimCalorimeterHit targetHit, SimCalorimeterHit hit, float dt)
-	{
-		// Get the hit energy.
-		float e = targetHit.getEnergy();
-
-		for (int j = 0; j < hit.getNMCContributions(); j++)
-		{
-			// PDGID might not be set.
-			int pdgid = 0;
-			try
-			{
-				pdgid = targetHit.getPDGCont(j);
-			}
-			catch (Exception x)
-			{
-			}
-
-			// Add this MCParticle contribution.
-			targetHit.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.
-		targetHit.setEnergy(e);
-	}
-
-	/** 
-	 * Shallow copy a SimCalorimeterHit.  
-	 * Do not copy MCParticle contributions.
-	 * @return A copy of hit. 
-	 * @param hit The hit to be copied.
-	 */
-	private static ISimCalorimeterHit copy(SimCalorimeterHit hit)
-	{
-		ISimCalorimeterHit newhit = new ISimCalorimeterHit();
-		newhit.setCellID0(hit.getCellID0());
-		newhit.setCellID1(hit.getCellID1());
-		newhit.setPosition(hit.getPosition());
-		return newhit;
-	}
-
-	/** 
-	 * Shallow copy an LCCollection.  
-	 * Does not copy LCObject members.
-	 * @return A copy of collection. 
-	 * @param coll The LCCollection to be copied.
-	 */
-	private static ILCCollection copy(LCCollection coll)
-	{
-		ILCCollection newcoll = new ILCCollection(coll.getTypeName());
-		newcoll.setDefault(coll.isDefault());
-		newcoll.setFlag(coll.getFlag());
-		newcoll.setParameters(coll.getParameters());
-		newcoll.setSubset(coll.isSubset());
-		newcoll.setTransient(coll.isTransient());
-
-		return newcoll;
-	}
-}
\ No newline at end of file
+package hep.lcio.util;
+
+import hep.lcio.event.LCCollection;
+import hep.lcio.event.LCEvent;
+import hep.lcio.event.LCIO;
+import hep.lcio.event.SimCalorimeterHit;
+import hep.lcio.implementation.event.ILCCollection;
+import hep.lcio.implementation.event.ILCEvent;
+import hep.lcio.implementation.event.IMCParticle;
+import hep.lcio.implementation.event.ISimCalorimeterHit;
+import hep.lcio.implementation.event.ISimTrackerHit;
+import hep.lcio.implementation.io.LCFactory;
+import hep.lcio.io.LCReader;
+import hep.lcio.io.LCWriter;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * 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.9 2009/05/22 20:18:59 cassell Exp $
+ */
+abstract public class MergeUtil
+{
+	/** 
+	 * 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.
+		writer.open(outfile.getCanonicalPath(), LCIO.WRITE_NEW);
+
+		// Count of total merged events that were created.
+		int nevents = 0;
+		
+		boolean done=false;
+
+		// File read loop.
+		for (;;)
+		{			
+			// Check if max output events is reached.
+			if (nevents >= maxEvents)
+				break;
+			
+			System.out.println("merge - processing event <"+(nevents+1)+">");
+
+			// Create the new output event.
+			ILCEvent targetEvent = new ILCEvent();
+
+			// 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 files.
+			int totmerged = 0;
+
+			// 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 the starting time.
+				float startt = mfile.startt();
+
+				// 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 = 0;
+                                if(ntoread > 0)
+                                {
+				nmerged = MergeUtil.mergeEvents(targetEvent, reader, ntoread, setEventHeader, startt, dt);
+				
+				// Check if the input file ran out of events.
+				if (nmerged==0) {
+				
+					System.out.println("EOF on <"+mfile.file().getCanonicalPath()+">.  This merge event will be discarded.");
+				
+					// Invalidate this event.
+					totmerged=0;
+					
+					// Stop processing this event.
+					break;
+				}
+                                }
+
+				// Increment total merged.
+				totmerged += nmerged;
+
+				// Next time, don't need to set the header.
+				setEventHeader = false;
+			}
+
+			// Write out the combined event if it is valid.
+			// The totmerged counter will be reset if any
+			// of the input events runs out of events.
+			if (totmerged > 0)
+			{
+				writer.writeEvent(targetEvent);
+				nevents++;
+			}
+			else
+			{
+				// Done!
+				break;
+			}
+		} // file read loop
+
+		System.out.println("Created " + nevents + " merged events.");
+
+		// Close the writer.
+		writer.close();
+
+		// Close the readers.
+		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 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
+	{
+		// Read the next event from the reader.
+		LCEvent nextEvent = overlayEvents.readNextEvent(LCIO.UPDATE);
+
+		// Return 0 if reader is exhausted.
+		if (nextEvent == null)
+		{
+			return 0;
+		}
+
+		// Set the event header from the first event if setEventHeader flag is true.
+		if (setEventHeader)
+		{
+			ILCEvent itargetEvent = (ILCEvent) targetEvent;
+			itargetEvent.setDetectorName(nextEvent.getDetectorName());
+			itargetEvent.setEventNumber(nextEvent.getEventNumber());
+			itargetEvent.setRunNumber(nextEvent.getRunNumber());
+			itargetEvent.setTimeStamp(nextEvent.getTimeStamp());
+		}
+
+		// Number of events merged in.
+		int nevt = 0;
+
+		// Set starting time.
+		float time = startt;
+
+		// Read loop.
+		while (nextEvent != null)
+		{
+			// 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(LCIO.UPDATE);
+
+			// Increment the time for next event.
+			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.
+	 * @param overlayEvent An event to be overlayed onto targetEvent.
+	 * @param dt A delta time to apply to sim types.
+	 */
+	public static void mergeSingleEvent(ILCEvent targetEvent, LCEvent overlayEvent, float dt)
+	{
+		//System.out.println("mergeSingleEvent");
+		
+		if (overlayEvent.getCollectionNames().length == 0)
+		{
+			// Empty event, nothing to do.
+			return;
+		}
+
+		// Get names of collections already existing in target.
+		String[] tcolls = targetEvent.getCollectionNames();
+
+		// Get names of collections to be merged in.
+		String[] ocolls = overlayEvent.getCollectionNames();
+
+		// Iterate over the overlay collections that will be merged into target.
+		for (int i = 0; i < ocolls.length; i++)
+		{
+			// Get the name of this overlay collection.
+			String collname = ocolls[i];
+			
+			//System.out.println("collname="+ocolls[i]);
+
+			// Get this overlay collection.
+			LCCollection ocoll = overlayEvent.getCollection(collname);
+
+			// Declare the target collection reference,
+			// which will be either a new collection or
+			// an existing one from the target.
+			LCCollection tcoll = null;
+
+			// Find the index of this overlay collection in the target.
+			int tidx = getCollectionIdx(tcolls, collname);
+
+			// 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.
+				tcoll = copy(overlayEvent.getCollection(collname));
+
+				// Add the new collection to the target event.
+				targetEvent.addCollection(tcoll, collname);
+			}
+			else
+			{
+				// Get the existing target collection.
+				tcoll = targetEvent.getCollection(collname);
+			}		
+			
+			//System.out.println("merging " + tcolls[i] + " and " + ocolls[i]);
+
+			// Overlay overlay collection into target collection.
+			mergeCollection(tcoll, ocoll, dt);
+		}
+
+		return;
+	}
+
+	/**
+	 * 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.
+	 */
+	public static void mergeCollection(LCCollection targetColl, LCCollection overlayColl, float dt)
+	{
+		//System.out.println("mergeCollection");
+				
+		String colltype = targetColl.getTypeName();
+		
+		//System.out.println("colltype="+colltype);
+
+		// Handle a SimTrackerHit collection.
+		if (colltype.compareTo(LCIO.SIMTRACKERHIT) == 0)
+		{
+			mergeSimTrackerHitCollection(targetColl, overlayColl, dt);
+		}
+		// Handle a SimCalorimeterHit collection.
+		else if (colltype.compareTo(LCIO.SIMCALORIMETERHIT) == 0)
+		{
+			mergeSimCalorimeterHitCollection(targetColl, overlayColl, dt);
+		}
+		// Handle an MCParticle collection.
+		else if (colltype.compareTo(LCIO.MCPARTICLE) == 0)
+		{
+			mergeMCParticleCollection(targetColl, overlayColl, dt);
+		}
+		// Handle a default collection.
+		else
+		{
+			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)
+			{
+				//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.
+	 * @param Collection of type SIMCALORIMETERHIT.
+	 * @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++)
+		{
+			ISimCalorimeterHit checkhit = (ISimCalorimeterHit) coll.getElementAt(i);
+			if ((checkhit.getCellID0() == hit.getCellID0() && checkhit.getCellID1() == hit.getCellID1()) || checkhit == hit)
+			{
+				match = checkhit;
+				break;
+			}
+		}
+
+		return match;
+	}
+
+	/** 
+	 * Find the given name in collnames.
+	 * @return The index of name in collnames or -1 if not found.
+	 * @param collnames A list of collection names.
+	 * @param name A collection name to find in collnames. 
+	 */
+	public static int getCollectionIdx(String[] collnames, String name)
+	{
+		int idx = -1;
+		for (int i = 0; i < collnames.length; i++)
+		{
+			if (collnames[i].compareTo(name) == 0)
+			{
+				idx = i;
+				break;
+			}
+		}
+		return idx;
+	}
+
+	/** 
+	 * Add MCParticle contributions from an overlay hit to a target hit. 
+	 * @param target Hit that receives MCParticle contributions.
+	 * @param hit Hit containing MCParticle contributions to be copied.
+	 * @param dt Delta time to apply to contributions.
+	 */
[truncated at 1000 lines; 61 more skipped]
CVSspam 0.2.8