Commit in lcsim/src/org/lcsim/digisim on MAIN
DigiSimDriver.java+55-91.15 -> 1.16
TJ: Commit changes to Digisim made during workshop to maek reading non-default steering file easier

lcsim/src/org/lcsim/digisim
DigiSimDriver.java 1.15 -> 1.16
diff -u -r1.15 -r1.16
--- DigiSimDriver.java	17 Jan 2006 18:00:02 -0000	1.15
+++ DigiSimDriver.java	17 Jan 2006 19:24:43 -0000	1.16
@@ -1,8 +1,10 @@
 package org.lcsim.digisim;
 
-import java.io.File;
 import java.util.Vector;
 import java.util.Map;
+import org.lcsim.conditions.CachedConditions;
+import org.lcsim.conditions.ConditionsEvent;
+import org.lcsim.conditions.ConditionsListener;
 import java.util.HashMap;
 
 import org.lcsim.util.Driver;
@@ -14,17 +16,18 @@
  * both parameters and events from the framework.
  *
  * @author Guilherme Lima
- * @version $Id: DigiSimDriver.java,v 1.15 2006/01/17 18:00:02 lima Exp $
+ * @version $Id: DigiSimDriver.java,v 1.16 2006/01/17 19:24:43 tonyj Exp $
  */
-public class DigiSimDriver extends Driver {
+public class DigiSimDriver extends Driver implements ConditionsListener {
 
     /**
      * Basic constructor
      * @param name A unique name, typically contains the corresponding
      * subdetector name as a substring.
+
      */
     public DigiSimDriver(String name) {
-      _name = new String("");
+      _name = "";
       _digitizers = new Vector<Digitizer>();
 
       // open released config file from lcsim.jar
@@ -37,7 +40,8 @@
     /** By default, takes the steering file from the ConditionsManager */
     public DigiSimDriver() {
       // _name will store detector name at first process(evt) call
-      _name = new String("");
+      _name = "";
+
       _digitizers = new Vector<Digitizer>();
       _useConditions = true;
       getConditionsManager().registerConditionsConverter(new DigiSimConditionsConverter());
@@ -48,11 +52,33 @@
      * digitizers.  Digitizers to be used, and their configuration
      * information, are stored in the same configuration file
      */
-    public void init() {
+    private void init() {
+	// FIXME: This should be using conditions system
+  	System.out.println("DigiSimDriver.init(): _name=<"+_name+">");
+        System.out.println("DigiSimDriver.init(): _file=<"+_file+">");
 	if(_name.equals("")) return;
-
+        if (_file != null)
+        {
+            // open released config file from lcsim.jar
+            ConfigReader reader = new ConfigReader(_file);
+            DigiSimSetup setup = reader.digiSimParse();
+            calculateDerivedConditions(setup);
+        }
+        else
+        {
+            _cachedConditions = getConditionsManager().getCachedConditions(DigiSimSetup.class,"digisim/digisim.steer");
+            // read config file
+	    calculateDerivedConditions(_cachedConditions.getCachedData());
+            _cachedConditions.addConditionsListener(this);
+        }
+    }
+    public void conditionsChanged(ConditionsEvent event)
+    {
+        if (_file != null) calculateDerivedConditions(_cachedConditions.getCachedData());
+    }
+    private void calculateDerivedConditions(DigiSimSetup setup)
+    {
 	// read config file
-	DigiSimSetup setup = null;
 	if(_useConditions) {
 	    // use conditions system
 	    setup = getConditionsManager().getCachedConditions(DigiSimSetup.class, "digisim/digisim.steer").getCachedData();
@@ -76,6 +102,7 @@
 	  }
 	}
 
+        _digitizers.clear();
 	// Instantiate subdetector digitizers.  All active names will
 	// be called, but only the ones compatible with being a
 	// digitizer will be actually used
@@ -101,7 +128,7 @@
 	// set debuggin state in digitizers, as per user request
 	setDigitizersDebugState();
     }
-
+    
     /** Called for every event - the event loop */
     protected void process( EventHeader event ) {
 
@@ -144,6 +171,21 @@
 	}
       }
     }
+    /** Set the name of the steering file to use. This should be the full path
+     * to the steering file. If set to null (the default) the steering file will
+     * be read from the conditions system based on the current detector.
+     */
+    public void setSteeringFile(String name)
+    {
+       _file = name;
+       // Fixme: I am not sure if calling init more than once will work.
+       init();
+    }
+    
+    public String getSteeringFile()
+    {
+       return _file;
+    }
 
     // *** FIELDS ***
 
@@ -151,8 +193,12 @@
     private int _nEvt ;
     /** Name of this DigiSimDriver object */
     private String _name;
+    /** Name of steering file to read (null means use conditions manager) */
+    private String _file;
     /** modifiers */
     private Vector<Digitizer> _digitizers;
+    
+    private CachedConditions<DigiSimSetup> _cachedConditions;
 //     private String _digisimURL = "http://nicadd.niu.edu/digisim/config/";
     private Map<String,Integer> _debugMap = new HashMap<String,Integer>();
 
CVSspam 0.2.8