LISTSERV mailing list manager LISTSERV 16.5

Help for HPS-SVN Archives


HPS-SVN Archives

HPS-SVN Archives


HPS-SVN@LISTSERV.SLAC.STANFORD.EDU


View:

Message:

[

First

|

Previous

|

Next

|

Last

]

By Topic:

[

First

|

Previous

|

Next

|

Last

]

By Author:

[

First

|

Previous

|

Next

|

Last

]

Font:

Proportional Font

LISTSERV Archives

LISTSERV Archives

HPS-SVN Home

HPS-SVN Home

HPS-SVN  December 2014

HPS-SVN December 2014

Subject:

r1607 - /java/trunk/evio/src/main/java/org/hps/evio/EvioToLcio.java

From:

[log in to unmask]

Reply-To:

Notification of commits to the hps svn repository <[log in to unmask]>

Date:

Mon, 1 Dec 2014 21:26:51 -0000

Content-Type:

text/plain

Parts/Attachments:

Parts/Attachments

text/plain (313 lines)

Author: [log in to unmask]
Date: Mon Dec  1 13:26:47 2014
New Revision: 1607

Log:
Remove error suppression option for now.  (Might add back later if needed.)

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	Mon Dec  1 13:26:47 2014
@@ -30,9 +30,7 @@
 
 /**
  * <p>
- * This class converts EVIO to LCIO, performing an LCSim job in the same
- * session. The processed events are then (optionally) written to disk using an
- * LCIOWriter.
+ * This class converts EVIO to LCIO, performing an LCSim job in the same session. The processed events are then (optionally) written to disk using an LCIOWriter.
  * <p>
  * To run this class from the command line:<br>
  * java -cp hps-distribution-bin.jar EvioToLcio [options] [evioFiles]
@@ -42,19 +40,13 @@
  * <p>
  * Extra arguments are treated as paths to EVIO files.
  * <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! 
+ * 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!
  *
  * @author Jeremy McCormick <[log in to unmask]>
  */
-// TODO: Add run number override argument.  This should cause EVIO run numbers to be ignored.
+// TODO: Add run number override argument. This should cause EVIO run numbers to be ignored.
 public class EvioToLcio {
-
-    // Events with run numbers greater than this will use the new LCSimEngRunEventBuilder.
-    private static final int TEST_RUN_END_RUN = 1365;
 
     // The default Test Run detector.
     private static final String DEFAULT_TEST_RUN_DETECTOR = "HPS-TestRun-v8-5";
@@ -71,9 +63,9 @@
 
     // The class's logger.
     Logger logger = LogUtil.create(EvioToLcio.class);
-    
+
     LCSimEventBuilder eventBuilder = null;
-    
+
     String detectorName;
 
     /**
@@ -89,14 +81,14 @@
         options.addOption(new Option("n", true, "Maximum number of events to process"));
         options.addOption(new Option("D", true, "Pass a variable to the steering file with format -Dname=value"));
         options.addOption(new Option("r", false, "Interpret steering from -x argument as a resource instead of a file"));
-        options.addOption(new Option("e", false, "Continue if errors occur during event processing"));
+        // options.addOption(new Option("e", false, "Continue if errors occur during event processing"));
         options.addOption(new Option("L", true, "Set the log level"));
         options.addOption(new Option("b", false, "Enable headless mode which will not show any plots"));
         logger.setLevel(Level.FINE);
     }
 
     /**
-     * Run the EVIO to LCIO converter from the command line.     
+     * Run the EVIO to LCIO converter from the command line. 
      * @param args The command line arguments.
      */
     public static void main(String[] args) {
@@ -105,9 +97,7 @@
     }
 
     /**
-     * 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. 
+     * 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 void run(String[] args) {
@@ -126,8 +116,7 @@
         try {
             cl = parser.parse(options, args);
         } catch (ParseException e) {
-            throw new RuntimeException("Problem parsing command line options.",
-                    e);
+            throw new RuntimeException("Problem parsing command line options.", e);
         }
 
         // Is the extra argument list empty?
@@ -185,13 +174,6 @@
             logger.config("set max events to " + maxEvents);
         }
 
-        // Whether to continue on errors or stop.
-        boolean continueOnErrors = false;
-        if (cl.hasOption("e")) {
-            continueOnErrors = true;
-            logger.config("continue on errors enabled");
-        }
-
         // LCIO writer.
         if (lcioFileName != null) {
             try {
@@ -232,18 +214,18 @@
             detectorName = cl.getOptionValue("d");
             logger.config("user set detector to " + detectorName);
         }
-        
+
         Integer runNumber = null;
         if (cl.hasOption("R")) {
             runNumber = Integer.parseInt(cl.getOptionValue("R"));
         }
-        
+
         DatabaseConditionsManager conditionsManager = DatabaseConditionsManager.getInstance();
-        
+
         // Is there a user specified run number?
         if (runNumber != null) {
             logger.config("user specified to use run number " + runNumber);
-            
+
             // Setup the event builder at the beginning of the job with the run number and detector name.
             this.setupEventBuilder(detectorName, runNumber);
             try {
@@ -251,11 +233,11 @@
                 conditionsManager.setDetector(detectorName, runNumber);
             } catch (ConditionsNotFoundException e) {
                 throw new RuntimeException();
-            }            
+            }
             // Freeze the conditions manager so run numbers from data are ignored.
             conditionsManager.freeze();
         }
-               
+
         for (String evioFileName : cl.getArgs()) {
             // EVIO input file.
             File evioFile = new File(evioFileName);
@@ -285,32 +267,23 @@
                         if (evioEvent == null) {
                             break fileLoop;
                         }
-                        try {
-                            reader.parseEvent(evioEvent);
-                        } catch (Exception e) {
-                            Logger.getLogger(EvioToLcio.class.getName()).log(Level.SEVERE, "Error reading EVIO event.", e);
-                            if (!continueOnErrors) {
-                                throw new RuntimeException(e);
-                            } else {
-                                continue eventLoop;
-                            }
-                        }
+                        reader.parseEvent(evioEvent);
                     }
 
                     // Handlers for different event types.
                     if (EvioEventUtilities.isPreStartEvent(evioEvent)) {
-                                                
+
                         // Get the pre start event's int data bank.
                         int[] data = EvioEventUtilities.getControlEventData(evioEvent);
-                        
+
                         // Does the int data bank actually exist?
                         if (data != null) {
-                                                
+
                             // int seconds = data[0];
                             int preStartRunNumber = data[1];
-                        
+
                             logger.info("EVIO pre start event with run #" + preStartRunNumber);
-                                                                       
+
                             // Is the event builder uninitialized?
                             if (eventBuilder == null) {
                                 // Initialize the event builder.
@@ -318,13 +291,17 @@
                             }
                         } else {
                             // Okay, this is a bank of banks structure that we don't know how to handle yet!
-                            logger.warning("pre start int data was null so no run number was read");                            
+                            logger.warning("pre start int data was null so no run number was read");
                             // FIXME: Here need to get run number from "bank of banks" structure.
-                        }                        
+                        }
                     }
 
                     // Setup state in the LCSimEventBuilder based on the EVIO event.
-                    eventBuilder.readEvioEvent(evioEvent);
+                    if (eventBuilder != null) {
+                        eventBuilder.readEvioEvent(evioEvent);
+                    } else {
+                        throw new RuntimeException("The event builder was never setup.  Try manually setting a run number using the -R switch.");
+                    }
 
                     if (EvioEventUtilities.isEndEvent(evioEvent)) {
                         int[] data = EvioEventUtilities.getControlEventData(evioEvent);
@@ -338,7 +315,7 @@
                         // Is the event builder initialized?
                         if (eventBuilder == null) {
                             // This can happen if there are no pre-start events in the EVIO file and no run number was explicitly given on the command line.
-                            throw new RuntimeException( "The LCSimEventBuilder was never setup.  You may need to manually specify a run number using the -R switch.");
+                            throw new RuntimeException("The LCSimEventBuilder was never setup.  You may need to manually specify a run number using the -R switch.");
                         }
 
                         EventHeader lcioEvent = eventBuilder.makeLCSimEvent(evioEvent);
@@ -359,30 +336,25 @@
                             writer.flush();
                             logger.finest("wrote LCIO event #" + lcioEvent.getEventNumber());
                         }
-                        
+
                         nEvents++;
                     }
 
                 } catch (Exception e) {
                     logger.log(Level.SEVERE, "Error in LCIO event processing.", e);
-                    if (!continueOnErrors) {
-                        throw new RuntimeException(e);
-                    } else {
-                        continue;
-                    }
-                }                
-            }
-            logger.info("Last physics event time: " + time / 1000 + " - " + new Date(time));
-            try {
-                logger.fine("closing reader");
-                reader.close();
-                logger.fine("reader closed");
-            } catch (IOException e) {
-                logger.log(Level.SEVERE, "An IO error occurred.", e);
-                if (!continueOnErrors) {
                     throw new RuntimeException(e);
                 }
             }
+            logger.info("Last physics event time: " + time / 1000 + " - " + new Date(time));
+            // try {
+            logger.fine("closing EVIO reader");
+            try {
+                reader.close();
+            } catch (IOException e) {
+                logger.warning(e.getMessage());
+                e.printStackTrace();
+            }
+            logger.fine("EVIO reader closed");
         }
         logger.info("no more data");
 
@@ -395,11 +367,12 @@
             try {
                 writer.close();
             } catch (IOException e) {
-                throw new RuntimeException(e);
-            }
-            logger.info("closed LCIO writer");
-        }
-        
+                logger.warning(e.getMessage());
+                e.printStackTrace();
+            }
+            logger.info("LCIO writer closed");
+        }
+
         logger.info("job finished successfully");
     }
 
@@ -414,14 +387,14 @@
     }
 
     /**
-     * Setup and return the LCSimEventBuilder.
+     * Setup and return the LCSimEventBuilder. 
      * @param detectorName The detector name to be assigned to the event builder.
      * @param runNumber The run number which determines which event builder to use.
      * @return The LCSimEventBuilder for the Test Run or Engineering Run.
      */
-    private void setupEventBuilder(String detectorName, int runNumber) {         
-        // Is this run number not part of the Test Run?
-        if (runNumber > 0 && runNumber <= EvioToLcio.TEST_RUN_END_RUN) {
+    private void setupEventBuilder(String detectorName, int runNumber) {
+        // Is this run number from the Test Run?
+        if (DatabaseConditionsManager.isTestRun(runNumber)) {
             // This looks like a Test Run file.
             logger.info("using LCSimTestRunEventBuilder");
             eventBuilder = new LCSimTestRunEventBuilder();
@@ -429,6 +402,7 @@
                 this.detectorName = DEFAULT_TEST_RUN_DETECTOR;
             }
         } else {
+            // Use the default event builder.
             logger.info("using LCSimEngRunEventBuilder");
             eventBuilder = new LCSimEngRunEventBuilder();
             if (detectorName == null) {
@@ -438,5 +412,5 @@
         eventBuilder.setDetectorName(this.detectorName);
         ConditionsManager.defaultInstance().addConditionsListener(eventBuilder);
         logger.config("initialized " + eventBuilder.getClass().getCanonicalName() + " with detector " + this.detectorName + " and run number " + runNumber);
-    }    
+    }
 }

Top of Message | Previous Page | Permalink

Advanced Options


Options

Log In

Log In

Get Password

Get Password


Search Archives

Search Archives


Subscribe or Unsubscribe

Subscribe or Unsubscribe


Archives

November 2017
August 2017
July 2017
January 2017
December 2016
November 2016
October 2016
September 2016
August 2016
July 2016
June 2016
May 2016
April 2016
March 2016
February 2016
January 2016
December 2015
November 2015
October 2015
September 2015
August 2015
July 2015
June 2015
May 2015
April 2015
March 2015
February 2015
January 2015
December 2014
November 2014
October 2014
September 2014
August 2014
July 2014
June 2014
May 2014
April 2014
March 2014
February 2014
January 2014
December 2013
November 2013

ATOM RSS1 RSS2



LISTSERV.SLAC.STANFORD.EDU

Secured by F-Secure Anti-Virus CataList Email List Search Powered by the LISTSERV Email List Manager

Privacy Notice, Security Notice and Terms of Use