Print

Print


Author: [log in to unmask]
Date: Tue Dec 16 15:30:36 2014
New Revision: 1763

Log:
Okay fix maxEvents so it actually does work correctly.

Modified:
    java/trunk/evio/src/main/java/org/hps/evio/EvioToLcio.java

Modified: java/trunk/evio/src/main/java/org/hps/evio/EvioToLcio.java
 =============================================================================
--- java/trunk/evio/src/main/java/org/hps/evio/EvioToLcio.java	(original)
+++ java/trunk/evio/src/main/java/org/hps/evio/EvioToLcio.java	Tue Dec 16 15:30:36 2014
@@ -49,14 +49,14 @@
  * <p>
  * This class attempts to automatically configure itself for Test Run or Engineering Run 
  * based on the run numbers in the EVIO file. It will use an appropriate default detector 
- * unless one is given on the command line, and it will also use the correct event builder. 
- * However, it will NOT correctly handle a mixed list of EVIO files from both runs, so
- * don't do this!
+ * unless one is given on the command line, and it will also use the correct event builder.
+ * It will not handle jobs correctly with files from both the Test and Engineering Run
+ * so don't do this!
  *
  * @author Jeremy McCormick <[log in to unmask]>
+ * @author Sho Uemura <[log in to unmask]>
  */
 public class EvioToLcio {
-
 
     // The default steering resource, which basically does nothing except print event numbers.
     private static final String DEFAULT_STEERING_RESOURCE = "/org/hps/steering/EventMarker.lcsim";
@@ -107,7 +107,7 @@
      */
     public void run(String[] args) {
 
-        int maxEvents = 0;
+        int maxEvents = -1;
         int nEvents = 0;
 
         // Set up command line parsing.
@@ -201,8 +201,11 @@
         }
 
         // Get the max number of events to process.
-        if (cl.hasOption("n")) {
+        if (cl.hasOption("n")) {            
             maxEvents = Integer.valueOf(cl.getOptionValue("n"));
+            if (maxEvents <= 0) {
+                throw new IllegalArgumentException("Value of -n option is invalid: " + maxEvents);
+            }
             logger.config("set max events to " + maxEvents);
         }
 
@@ -308,7 +311,7 @@
             long time = 0; // in ms
 
             // Loop over EVIO events, build LCSim events, process them, and then write events to disk.
-            readLoop: while (maxEvents == 0 || nEvents < maxEvents) {
+            readLoop: while (maxEvents == -1 || nEvents < maxEvents) {
                 EvioEvent evioEvent = null;
                 try {
                     while (evioEvent == null) {
@@ -406,8 +409,8 @@
                 e.printStackTrace();
             }
             
-            if (nEvents >= maxEvents) {
-                logger.info("user maxEvents " + maxEvents + " was reached");
+            if (maxEvents != -1 && nEvents < maxEvents) {
+                logger.info("maxEvents " + maxEvents + " was reached");
                 break fileLoop;
             }
         }