Print

Print


Commit in lcsim on MAIN
resources/org/lcsim/schemas/lcsim/1.0/lcsim.xsd+181.10 -> 1.11
src/org/lcsim/job/ConditionsCheckDriver.java+59added 1.1
                 /JobControlManager.java+143-551.58 -> 1.59
+220-55
1 added + 2 modified, total 3 files
add command line option for adding input LCIO files; add optional conditions element in .lcsim files for prechecking for detectors and conditions before job begins

lcsim/resources/org/lcsim/schemas/lcsim/1.0
lcsim.xsd 1.10 -> 1.11
diff -u -r1.10 -r1.11
--- lcsim.xsd	8 Apr 2012 23:45:31 -0000	1.10
+++ lcsim.xsd	17 May 2012 00:14:05 -0000	1.11
@@ -4,6 +4,23 @@
            elementFormDefault="unqualified"
            version="1.0"
            xmlns:xs="http://www.w3.org/2001/XMLSchema">
+           
+    <xs:element name="conditions">
+        <xs:complexType>
+            <xs:sequence>
+                <xs:element name="detectors" type="xs:string" minOccurs="0" maxOccurs="1"/>
+                <xs:element name="condition" minOccurs="0" maxOccurs="unbounded">
+                    <xs:complexType>
+                        <xs:simpleContent>
+                            <xs:extension base="xs:string" >                        
+                                <xs:attribute name="required" type="xs:boolean" use="optional" default="true"/>
+                            </xs:extension>
+                        </xs:simpleContent>
+                    </xs:complexType>
+                </xs:element>
+            </xs:sequence>
+        </xs:complexType>
+    </xs:element>           
                                
     <xs:element name="inputFiles">
         <xs:complexType>
@@ -110,6 +127,7 @@
     <xs:element name="lcsim">
         <xs:complexType>
             <xs:all>
+                <xs:element ref="conditions" minOccurs="0" maxOccurs="1"/>
                 <xs:element ref="inputFiles" minOccurs="0" maxOccurs="1"/>
                 <xs:element ref="control" minOccurs="0" maxOccurs="1"/>
                 <xs:element ref="classpath" minOccurs="0" maxOccurs="1"/>

lcsim/src/org/lcsim/job
ConditionsCheckDriver.java added at 1.1
diff -N ConditionsCheckDriver.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ ConditionsCheckDriver.java	17 May 2012 00:14:05 -0000	1.1
@@ -0,0 +1,59 @@
+package org.lcsim.job;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.lcsim.conditions.ConditionsManager;
+import org.lcsim.geometry.Detector;
+import org.lcsim.util.Driver;
+
+/**
+ * This Driver checks that a list of required conditions are present.
+ * @author Jeremy McCormick <[log in to unmask]>
+ * @version $Id: ConditionsCheckDriver.java,v 1.1 2012/05/17 00:14:05 jeremy Exp $
+ */
+public class ConditionsCheckDriver extends Driver {
+    
+    List<String> requiredConditions = new ArrayList<String>();
+    List<String> detectors = new ArrayList<String>();
+    boolean checkConditions = true;
+    boolean checkDetector = true;
+    
+    ConditionsCheckDriver() {}
+    
+    public void detectorChanged(Detector detector) {
+        if (checkDetector) {
+            if (detectors.size() > 0) {
+                if (!detectors.contains(detector.getDetectorName())) {
+                    throw new RuntimeException("The detector " + detector.getDetectorName() + " is not in the list of valid detectors.");
+                }
+            }
+        }
+        if (checkConditions) {
+            ConditionsManager mgr = ConditionsManager.defaultInstance();
+            for (String condition : requiredConditions) {
+                try {
+                    mgr.getRawConditions(condition);
+                } catch (ConditionsManager.ConditionsSetNotFoundException e) {
+                    throw new RuntimeException(e);
+                }
+            }
+        }
+    }
+    
+    public void setCondition(String c) {
+        requiredConditions.add(c);
+    }
+    
+    public void setDetector(String d) {
+        detectors.add(d);
+    }
+    
+    public void setCheckConditions(boolean b) {
+        this.checkConditions = b;
+    }
+    
+    public void setCheckDetector(boolean b) {
+        this.checkDetector = b;
+    }
+}

lcsim/src/org/lcsim/job
JobControlManager.java 1.58 -> 1.59
diff -u -r1.58 -r1.59
--- JobControlManager.java	30 Apr 2012 22:56:26 -0000	1.58
+++ JobControlManager.java	17 May 2012 00:14:05 -0000	1.59
@@ -35,6 +35,7 @@
 import org.freehep.record.loop.LoopSourceExhaustedException;
 import org.freehep.record.loop.event.RecordSuppliedEvent;
 import org.jdom.Attribute;
+import org.jdom.DataConversionException;
 import org.jdom.Document;
 import org.jdom.Element;
 import org.jdom.Text;
@@ -42,6 +43,8 @@
 import org.jdom.output.Format;
 import org.jdom.output.XMLOutputter;
 import org.lcsim.LCSimVersion;
+import org.lcsim.conditions.ConditionsManager;
+import org.lcsim.conditions.ConditionsManager.ConditionsSetNotFoundException;
 import org.lcsim.event.EventHeader;
 import org.lcsim.units.Constants;
 import org.lcsim.util.Driver;
@@ -80,10 +83,11 @@
  * which it should be discarded.  If the {@link #run()} method is called twice on 
  * the same manager, a fatal exception will be thrown.
  *   
- * @version $Id: JobControlManager.java,v 1.58 2012/04/30 22:56:26 jeremy Exp $
+ * @version $Id: JobControlManager.java,v 1.59 2012/05/17 00:14:05 jeremy Exp $
  * @author Jeremy McCormick
  */
-// TODO Allow no input files when only Driver list is needed.
+// TODO: Do proper logging using Java Logger class.
+// TODO: Add command line option for including input files as paths or URLs.
 public class JobControlManager
 {
     // The LCIO record loop.
@@ -179,26 +183,16 @@
 	 */
 	private static Options createCommandLineOptions()
 	{
-	    Options options = new Options();
-	    
-	    Option propOpt = new Option("p", true, "Load a properties file containing variable definitions");
-	    Option defOpt = new Option("D", true, "Define a variable with form [name]=[value]");
-	    Option rewriteOpt = new Option("w", true, "Rewrite the XML file with variables resolved");
-	    Option verbOpt = new Option("v", false, "Turn on verbose mode");
-	    Option skipOpt = new Option("s", true, "Set the number of events to skip.");
-	    Option evtOpt = new Option("n", true, "Set the max number of events to process.");
-	    Option dryOpt = new Option("x", false, "Perform a dry run which does not process events");
-	    Option quietOpt = new Option("q", false, "Turn on quiet mode.");
-	    
-	    options.addOption(propOpt);
-	    options.addOption(defOpt);
-	    options.addOption(rewriteOpt);
-	    options.addOption(verbOpt);
-	    options.addOption(skipOpt);
-	    options.addOption(evtOpt);
-	    options.addOption(dryOpt);
-	    options.addOption(quietOpt);
-
+	    Options options = new Options();	 	  
+	    options.addOption(new Option("p", true, "Load a properties file containing variable definitions"));
+	    options.addOption(new Option("D", true, "Define a variable with form [name]=[value]"));
+	    options.addOption(new Option("w", true, "Rewrite the XML file with variables resolved"));
+	    options.addOption(new Option("v", false, "Turn on verbose mode"));
+	    options.addOption(new Option("s", true, "Set the number of events to skip."));
+	    options.addOption(new Option("n", true, "Set the max number of events to process."));
+	    options.addOption(new Option("x", false, "Perform a dry run which does not process events"));
+	    options.addOption(new Option("q", false, "Turn on quiet mode."));
+	    options.addOption(new Option("i", true, "Add an LCIO input file to process."));
 	    return options;
 	}
 	
@@ -312,6 +306,18 @@
         if (!xmlRunControlFile.exists()) {
             throw new RuntimeException("The steering file " + args[0] + " does not exist!");
         }
+        
+        // Local LCIO files to process.
+        if (cl.hasOption("i")) {
+            String[] files = cl.getOptionValues("i");
+            for (String fileName : files) {
+                File file = new File(fileName);
+                if (!file.exists()) {
+                    throw new RuntimeException("File given as command line option does not exist: " + fileName);
+                }
+                inputFiles.add(new File(fileName));
+            }
+        }
 	    
 	    // Setup job parameters from XML now that CL options are all processed.
 	    setup(xmlRunControlFile);
@@ -346,7 +352,6 @@
 	{
 	    // If setup was not called first, then abort the job.
 		if (!wasSetup) {
-			//throw new RuntimeException("Aborting job!  The method JobManager.setup(File) was never called.");
 			logStream.println("Aborting job!  Setup was never called.");
 		    return false;
 		}
@@ -355,22 +360,26 @@
 			(new LCSimVersion()).printOut(logStream);			
 			logStream.println();
 		}
-				
-		// Need to make sure loop is setup before running.
+		
+        // Dry run selected.  No events will be processed here.
+		if (performDryRun) {		    
+		    logStream.println("Executed dry run.  No events processed!");
+		    return false;
+		}
+						
+		// Setup lcsim loop before running.
 		getLCSimLoop();
 		
-		try {
-			// Add the LCIO files to the loop.
-			loop.setLCIORecordSource(new LCIOEventSource(this.getClass().getSimpleName(), inputFiles));
-			
-			// Driver statistics printout.
-			PrintStream statsStream = null;			
-			if (printDriverStatistics) {
-				statsStream = logStream;
-			}
-			
-			// Execute the entire job if not a dry run.
-			if (!performDryRun) {
+		try {								    
+			    // Add the LCIO files to the loop.
+	            loop.setLCIORecordSource(new LCIOEventSource(this.getClass().getSimpleName(), inputFiles));
+	            
+	            // Driver statistics printout.
+	            PrintStream statsStream = null;         
+	            if (printDriverStatistics) {
+	                statsStream = logStream;
+	            }
+			    
 				if (verbose) {
 					logStream.println("Start time: " + (new Date()));
 					logStream.println();
@@ -389,16 +398,9 @@
 				if (verbose) {
 					logStream.println();
 					logStream.println("End time: " + (new Date()));
-				}
-			}
-			// A dry run does not process any events.  
-			else {
-			    // Always print this info msg.
-				logStream.println("Executed dry run.  No events processed!");
-			}
+				}			
 		} 
-		// Record source was exhausted before max events was hit.  This is probably fine,
-		// but print message in case more were expected.
+		// Record source was exhausted before max events was hit.
 		catch (LoopSourceExhaustedException x) {
 		    logStream.println(x.getMessage());
 		}
@@ -408,7 +410,7 @@
 			throw new RuntimeException(e);
 		}
 		
-		// Cleanup.
+		// Cleanup the loop.
 		loop.dispose();
 		loop = null;
 		
@@ -525,15 +527,18 @@
         if (printSystemProperties) {
             printSystemProperties(logStream);
         }
-        
+                
         // Setup the class loader.
         setupClassLoader();
-    
+            
         // Setup units.
         setupUnits();
         
         // Process the variable definitions.
-        processConstants();     
+        processConstants();
+        
+        // Check for required conditions.
+        checkConditions();
                 
         // Setup drivers with parameters and execution order.
         setupDrivers();
@@ -543,6 +548,12 @@
 
         // Setup the input files.
         setupInputFiles();
+        
+        // Check if a dry run should be performed when no input files are present.
+        if (inputFiles.size() == 0) {
+            performDryRun = true;
+            logStream.println("No input files provided by XML or command line.  Dry run will be enabled.");
+        }
 
         // Flag JobManager as setup.
         wasSetup = true;
@@ -752,7 +763,7 @@
                 }
                 // No method found.  The parameter name is probably invalid.  
                 else if (methodCandidates.size() == 0) {
-                    throw new RuntimeException("No set method found for parameter: " + pname);
+                    throw new RuntimeException("Set method was not found: " + driverClass.getSimpleName() + "." + pname);
                 }
                 
                 // No setter method found.
@@ -792,7 +803,7 @@
         if (printDriversDetailed) {
             logStream.println("--- End Drivers ---");
         }
-
+        
         // Make a list of Drivers to be executed.
         List<Element> exec = root.getChild("execute").getChildren("driver");
         for (Element execDriver : exec) {
@@ -893,9 +904,9 @@
 	@SuppressWarnings("unchecked")
     private void setupInputFiles()
 	{
-	    if (root.getChild("inputFiles") == null) {
-	        logStream.println("No input files in XML file.  Dry run will be peformed.");
-	        this.performDryRun = true;
+	    if (root.getChild("inputFiles") == null) { 
+	        logStream.println("No input files in XML file.");
+	        //this.performDryRun = true;
 	        return;
 	    }
 	    
@@ -1397,4 +1408,81 @@
     public void setPerformDryRun(boolean d) {
         this.performDryRun = d;
     }
+    
+    private void checkConditions() {
+        
+        // Get conditions element if it is there; otherwise return.
+        Element conditionsElement = root.getChild("conditions");        
+        if (conditionsElement == null)
+            return;
+        
+        // Get the list of valid detectors for this steering file.
+        Element detectorsElement = conditionsElement.getChild("detectors");
+        
+        if (detectorsElement != null) {
+            String detectors = detectorsElement.getTextNormalize();
+                       
+            String[] detectorNames = detectors.split(" ");
+
+            // Loop over detector names and check for required conditions in each.
+            for (String detector : detectorNames) {               
+                logStream.println("Looking up required conditions for " + detector + " ...");                
+                ConditionsManager mgr = ConditionsManager.defaultInstance();
+                try {
+                    mgr.setDetector(detector, 0);
+                } catch (ConditionsManager.ConditionsNotFoundException e) {
+                    throw new RuntimeException(e);
+                }
+                for (Object condition : conditionsElement.getChildren()) {
+                    Element conditionElement = (Element) condition;
+                    boolean required = true;
+                    try {
+                        required = conditionElement.getAttribute("required").getBooleanValue();
+                    } catch (DataConversionException e) {
+                    } catch (NullPointerException e) {                        
+                    }
+                    try {
+                        mgr.getRawConditions(conditionElement.getTextTrim());
+                        logStream.println(conditionElement.getTextTrim() + " - OKAY");
+                    } catch (ConditionsSetNotFoundException e) {
+                        logStream.println(conditionElement.getTextTrim() + " - NOT FOUND");
+                        if (required)
+                            throw new RuntimeException("Required conditions " + conditionElement.getTextTrim() + " are missing from detector " + detector + ".");
+                    }                        
+                }
+            }
+        }
+        
+        logStream.println("Adding ConditionsCheckDriver to front of Driver exec list.");
+        ConditionsCheckDriver d = createConditionsCheckDriver();        
+        if (detectorsElement == null) {
+            // No detector names provided, so individual detectors will have all conditions checked.   
+            d.setCheckDetector(false);
+            d.setCheckConditions(true);
+        } else {
+            // Detectors already checked by name so just check that detector names in the job are okay.
+            d.setCheckConditions(false);
+            d.setCheckDetector(true);
+        }
+        if (d != null)
+            driverExec.add(d);
+    }
+    
+    private ConditionsCheckDriver createConditionsCheckDriver() {
+        ConditionsCheckDriver driver = new ConditionsCheckDriver();
+        Element conditionsElement = root.getChild("conditions");
+        if (conditionsElement == null)
+            return null;
+        for (Object condition : conditionsElement.getChildren()) {
+            Element conditionElement = (Element) condition;
+            driver.setCondition(conditionElement.getTextTrim());
+        }
+        if (conditionsElement.getChild("detectors") != null) {                   
+            String[] detectorNames = conditionsElement.getChild("detectors").getText().split(" +");
+            for (String detector : detectorNames) {
+                driver.setDetector(detector);
+            }
+        }
+        return driver;
+    }
 }
\ No newline at end of file
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