Print

Print


Author: [log in to unmask]
Date: Thu Jan 15 17:06:40 2015
New Revision: 1941

Log:
Inject the SvtSensorSetup Driver if it is not present in the job.  This is a temporary fix while HPS-263 is unresolved.

Modified:
    java/trunk/record-util/src/main/java/org/hps/job/JobManager.java

Modified: java/trunk/record-util/src/main/java/org/hps/job/JobManager.java
 =============================================================================
--- java/trunk/record-util/src/main/java/org/hps/job/JobManager.java	(original)
+++ java/trunk/record-util/src/main/java/org/hps/job/JobManager.java	Thu Jan 15 17:06:40 2015
@@ -25,9 +25,19 @@
      */
     @Override
     public boolean run() {
+        
+        // Inject the SvtSensorSetup Driver required for most recon jobs.
+        addSvtSetupDriver();
+        
+        // Setup the conditions if there is a ConditionsDriver present.
         setupConditions();
+        
+        // Run the job.
         boolean result = super.run();
+        
+        // Close the conditions database connection if it is open.        
         DatabaseConditionsManager.getInstance().closeConnection();
+               
         return result;
     }
 
@@ -48,4 +58,33 @@
             conditionsDriver.initialize();
         }
     }
+    
+    static String driverClassName = "org.hps.recon.tracking.SvtSensorSetup";
+    private void addSvtSetupDriver() {        
+        Class<?> driverClass = null;        
+        try {
+            driverClass = Class.forName(driverClassName);
+        } catch (ClassNotFoundException e) {
+            throw new RuntimeException("SvtSensorSetup class is not accessible.", e);
+        }
+        
+        boolean hasSetupDriver = false;
+        for (Driver driver : this.getDriverAdapter().getDriver().drivers()) {
+            if (driver.getClass().getCanonicalName().equals(driverClassName)) {
+                hasSetupDriver = true;
+                break;
+            }
+        }
+
+        if (!hasSetupDriver) {
+            Driver setupDriver;
+            try {
+                setupDriver = (Driver) driverClass.newInstance();
+            } catch (InstantiationException | IllegalAccessException e) {
+                throw new RuntimeException("Error creating new SvtSensorSetup Driver.", e);
+            }
+            this.getDriverAdapter().getDriver().drivers().add(0, setupDriver);
+            logStream.println("added SvtSensorSetup to beginning of Driver list");
+        }
+    }
 }