Commit in lcsim/sandbox/RobKutschke/TKNHits on MAIN
ReadTKNRawHitsDriverV1.java+25-181.3 -> 1.4
Move all treatment of the index cache into the detectorChanged() method.

lcsim/sandbox/RobKutschke/TKNHits
ReadTKNRawHitsDriverV1.java 1.3 -> 1.4
diff -u -r1.3 -r1.4
--- ReadTKNRawHitsDriverV1.java	5 Nov 2007 23:19:34 -0000	1.3
+++ ReadTKNRawHitsDriverV1.java	6 Nov 2007 00:11:46 -0000	1.4
@@ -15,6 +15,7 @@
 import org.lcsim.event.base.BaseRawTrackerHit;
 
 import org.lcsim.geometry.Detector;
+import org.lcsim.geometry.compact.Subdetector;
 import org.lcsim.detector.IDetectorElement;
 import org.lcsim.detector.IGeometryInfo;
 import org.lcsim.detector.IRotation3D;
@@ -44,9 +45,9 @@
  * This version also contains tests to compared measured and generated positions.
  *
  *@author $Author: kutschke $
- *@version $Id: ReadTKNRawHitsDriverV1.java,v 1.3 2007/11/05 23:19:34 kutschke Exp $
+ *@version $Id: ReadTKNRawHitsDriverV1.java,v 1.4 2007/11/06 00:11:46 kutschke Exp $
  *
- * Date $Date: 2007/11/05 23:19:34 $
+ * Date $Date: 2007/11/06 00:11:46 $
  * 
  * Notes:
  *
@@ -56,10 +57,7 @@
  *    -90 degrees.  This file uses the detector description: SiTrackerBarrelTest00 .
  *
  * 1) There are a few magic numbers that I need to look up in a dictionary and I only
- *    want to do this when the dictionary changes.  Ideally all of the code should be
- *    within detectorChanged() but I don't yet know how to do that.  So the cache is 
- *    invalidated when the detector changes and recomputed on the first event following
- *    a detector change.
+ *    want to do this when the dictionary changes. 
  * 
  * 2) I am not aware of anything in the event model that informs the user that correct 
  *    argument to the getElectrodes() method is HOLES, not ELECTRONS.  This is just something
@@ -116,9 +114,9 @@
      */
     public void detectorChanged( Detector detector) {
 
-	// Invalidate the cached indices.  See note 1.
-	index = null;
-
+	// Initialize the index cache.
+	Subdetector tracker = findSubdetector( detector, "SiTrackerBarrel");
+	index = new TrackerIdentifierIndexCache( tracker, true );
     }
    
     /**
@@ -134,15 +132,6 @@
 	List<RawTrackerHit> rawhits = header.get(RawTrackerHit.class, raw[0] );
 	aida.cloud1D("Number of RawTrackerHits per event").fill(rawhits.size());
 
-	// Make sure cached indices are valid. See note 1.
-	if ( index == null ){
-	    if ( rawhits.size() > 0 ){
-		index = new TrackerIdentifierIndexCache( rawhits.get(0), true );
-	    } else{
-		return;
-	    }
-	}
-
 	// Header for the tabluar printout.
 	if ( ++nprint == 1 ){ 
 	    System.out.printf ( "Event System Layer Module Sensor Side Strip Time   ADC NSim\n");
@@ -347,5 +336,23 @@
 
     }
 
+    /**
+     * Find a named subdector object within the detector.
+     *
+     * @return Subdetector object that is specified by the second argument.
+     *
+     *
+     */
+    private Subdetector findSubdetector( Detector detector, String sub ){
+	Map<String, Subdetector> subDetMap = detector.getSubdetectors();
+	Subdetector tracker = subDetMap.get(sub);
+	if ( tracker == null ){
+	    System.out.println ("Cannot find subdetector: "  + sub
+				+ " in detector " + detector.getName() );
+	    System.out.println ("Aborting now.");
+	    System.exit(-1);
+	}
+	return tracker;
+    }
 
 } 
CVSspam 0.2.8