Print

Print


Commit in hps-java/src/main/java/org/lcsim/hps/users/meeg on MAIN
FilterMCBunches.java+42-341.4 -> 1.5
read multiple input files

hps-java/src/main/java/org/lcsim/hps/users/meeg
FilterMCBunches.java 1.4 -> 1.5
diff -u -r1.4 -r1.5
--- FilterMCBunches.java	30 Jul 2012 23:31:45 -0000	1.4
+++ FilterMCBunches.java	9 Aug 2012 22:25:27 -0000	1.5
@@ -20,9 +20,10 @@
 /**
  * Selects LCIO events passing a cut; spaces out these events with blank events.
  * Intended use is to clean up a photon-run MC file before running trigger and readout sim.
+ * Can also be used to chain multiple LCIO files together.
  *
  * @author Sho Uemura <[log in to unmask]>
- * @version $Id: FilterMCBunches.java,v 1.4 2012/07/30 23:31:45 meeg Exp $
+ * @version $Id: FilterMCBunches.java,v 1.5 2012/08/09 22:25:27 meeg Exp $
  */
 public class FilterMCBunches {
 
@@ -41,18 +42,11 @@
         return options;
     }
 
-    /**
-     * This method will execute the EVIO to LCIO conversion and perform an
-     * intermediate LCSim job. Then the resultant LCIO events will be written to
-     * disk.
-     *
-     * @param args The command line arguments.
-     */
     public static void main(String[] args) {
         // Set up command line parsing.
         Options options = createCommandLineOptions();
         if (args.length == 0) {
-            System.out.println("FilterMCBunches <input file> <output file>");
+            System.out.println("FilterMCBunches <input files> <output file>");
             HelpFormatter help = new HelpFormatter();
             help.printHelp(" ", options);
             System.exit(1);
@@ -68,14 +62,7 @@
         }
 
         String[] parsedArgs = cl.getArgs();
-        String inFileName = parsedArgs[0];
-        String outFileName = parsedArgs[1];
-        LCIOReader reader = null;
-        try {
-            reader = new LCIOReader(new File(inFileName));
-        } catch (IOException e) {
-            throw new RuntimeException(e);
-        }
+        String outFileName = parsedArgs[parsedArgs.length - 1];
 
         LCIOWriter writer = null;
         try {
@@ -97,40 +84,61 @@
         int writtenEvents = 0;
 
         String detectorName = null;
-        while (nEvents == -1 || readEvents < nEvents) {
-            EventHeader event;
+
+        fileLoop:
+        for (int fileNumber = 0; fileNumber < parsedArgs.length - 1; fileNumber++) {
+            LCIOReader reader = null;
+            String inFileName = parsedArgs[fileNumber];
             try {
-                event = reader.read();
+                reader = new LCIOReader(new File(inFileName));
+                System.out.println("Opened input file " + inFileName);
             } catch (IOException e) {
-                break;
-            }
-            readEvents++;
-
-            if (detectorName == null) {
-                detectorName = event.getDetectorName();
+                throw new RuntimeException(e);
             }
 
-            if (cl.hasOption("a") || goodEvent(event)) {
-                writtenEvents++;
+            eventLoop:
+            while (true) {
+                if (nEvents != -1 && readEvents == nEvents) {
+                    break fileLoop;
+                }
+                EventHeader event;
                 try {
-                    writer.write(event);
+                    event = reader.read();
                 } catch (IOException e) {
-                    break;
+                    break eventLoop;
                 }
+                readEvents++;
 
-                for (int i = 1; i < nEmpty; i++) {
+                if (detectorName == null) {
+                    detectorName = event.getDetectorName();
+                }
+
+                if (cl.hasOption("a") || goodEvent(event)) {
+                    writtenEvents++;
                     try {
-                        writer.write(new BaseLCSimEvent(event.getRunNumber(), event.getEventNumber(), detectorName));
+                        writer.write(event);
                     } catch (IOException e) {
-                        break;
+                        throw new RuntimeException(e);
+                    }
+
+                    for (int i = 1; i < nEmpty; i++) {
+                        try {
+                            writer.write(new BaseLCSimEvent(event.getRunNumber(), event.getEventNumber(), detectorName));
+                        } catch (IOException e) {
+                            throw new RuntimeException(e);
+                        }
                     }
                 }
             }
+            try {
+                reader.close();
+            } catch (IOException e) {
+                throw new RuntimeException(e);
+            }
         }
 
         System.out.format("Read %d events, wrote %d of them\n", readEvents, writtenEvents);
         try {
-            reader.close();
             writer.close();
         } catch (IOException e) {
             throw new RuntimeException(e);
CVSspam 0.2.12


Use REPLY-ALL to reply to list

To unsubscribe from the LCD-CVS list, click the following link:
https://listserv.slac.stanford.edu/cgi-bin/wa?SUBED1=LCD-CVS&A=1