GeomConverter/src/org/lcsim/detector
diff -N DetectorIdHelper.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ DetectorIdHelper.java 6 Sep 2007 18:14:45 -0000 1.1
@@ -0,0 +1,893 @@
+package org.lcsim.detector;
+
+import java.util.HashMap;
+
+import org.lcsim.detector.identifier.ExpandedIdentifier;
+import org.lcsim.detector.identifier.IExpandedIdentifier;
+import org.lcsim.detector.identifier.IIdentifier;
+import org.lcsim.detector.identifier.IIdentifierDictionary;
+import org.lcsim.detector.identifier.IdentifierHelper;
+import org.lcsim.detector.identifier.IIdentifierDictionary.FieldNotFoundException;
+import org.lcsim.detector.identifier.IIdentifierDictionary.InvalidIndexException;
+import org.lcsim.geometry.Detector;
+import org.lcsim.geometry.compact.Subdetector;
+import org.lcsim.geometry.subdetector.PolyconeSupport;
+
+/**
+ * <p>
+ * An {@link org.lcsim.detector.identifier.IIdentifierHelper} for decoding {@link org.lcsim.detector.identifier.IIdentifier}s
+ * from the top-level of the detector description.
+ * </p>
+ *
+ * <p>
+ * The identifier fields used by this class.
+ * <ul>
+ * <li><code>system</code> - The system number that uniquely identifies a subdetector.</li>
+ * <li><code>barrel</code> - The flag that indicates whether a subdetector is a barrel, endcap positive, or endcap negative.</li>
+ * <li><code>layer</code> - The layer number of a subcomponent. (Field is optional.)</li>
+ * </ul>
+ * </p>
+ *
+ * <p>
+ * The system numbers can be set from a {@see SysteMap} which is simply a map of
+ * strings to integer values for system. These could be read from a compact description.
+ * </p>
+ *
+ * <p>
+ * The basic method signatures are as follows.
+ * <ul>
+ * <li><code>int getSomeSubdetectorValue()</code> - Get the system value of SomeSubdetector.
+ * <li><code>isSomething(IIdentifier i)</code> - Check if the id is of some subdetector type or it it has matching barrel flag.
+ * <li><code>IIdentifier getSomeSubdetectorId()</code> - Get the id for SomeSubdetector.
+ * <li><code>int getSomeField(IIdentifier i)</code> - Get a specific field value from an id.
+ * <li><code>boolean someFieldEquals(IIdentifier i, int x)</code> - Check if field from identifier equals the argument.
+ * </ul>
+ * </p>
+ *
+ * @author Jeremy McCormick <[log in to unmask]>
+ */
+public class DetectorIdHelper
+extends IdentifierHelper
+{
+ // Invalid index.
+ public static final int invalidIndex=-1;
+
+ // Index of system field in the IdentifierDictionary. REQUIRED.
+ int systemIndex=invalidIndex;
+
+ // Index of barrel field in the IdentifierDictionary. REQUIRED.
+ int barrelIndex=invalidIndex;
+
+ // Index of layer field in the IdentifierDictionary. OPTIONAL.
+ int layerIndex=invalidIndex;
+
+ // Barrel or endcap flag.
+ // These values are fixed according to an established LCSim convention.
+ private final static int barrelValue=0;
+ private final static int endcapPositiveValue=1;
+ private final static int endcapNegativeValue=2;
+
+ // Subsystem id values.
+ // These are set via a SystemMap, to allow the values to be read
+ // from a compact detector description. The default SystemMap is
+ // created if none is supplied.
+ private static int invalidSystemValue = -1;
+ private static int unknownValue = invalidSystemValue;
+ private static int vtxBarrelValue = invalidSystemValue;
+ private static int vtxEndcapValue = invalidSystemValue;
+ private static int sitBarrelValue = invalidSystemValue;
+ private static int sitEndcapValue = invalidSystemValue;
+ private static int sitForwardValue = invalidSystemValue;
+ private static int tpcValue = invalidSystemValue;
+ private static int ecalBarrelValue = invalidSystemValue;
+ private static int ecalEndcapValue = invalidSystemValue;
+ private static int hcalBarrelValue = invalidSystemValue;
+ private static int hcalEndcapValue = invalidSystemValue;
+ private static int muonBarrelValue = invalidSystemValue;
+ private static int muonEndcapValue = invalidSystemValue;
+ private static int ecalForwardValue = invalidSystemValue;
+ private static int lumiValue = invalidSystemValue;
+
+ // Barrel or endcap ids.
+ IIdentifier barrelId;
+ IIdentifier endcapPositiveId;
+ IIdentifier endcapNegativeId;
+
+ // Vertex detector ids.
+ IIdentifier vtxBarrelId;
+ IIdentifier vtxEndcapId;
+ IIdentifier vtxEndcapPositiveId;
+ IIdentifier vtxEndcapNegativeId;
+
+ // Silicon tracker ids.
+ IIdentifier sitBarrelId;
+ IIdentifier sitEndcapId;
+ IIdentifier sitEndcapPositiveId;
+ IIdentifier sitEndcapNegativeId;
+
+ // Forward silicon tracking.
+ IIdentifier sitForwardId;
+ IIdentifier sitForwardEndcapPositiveId;
+ IIdentifier sitForwardEndcapNegativeId;
+
+ // NOTE
+ // LDC si tracking...
+ // inner = sit
+ // outer = set
+ // ftc = forward tracking chamber
+
+ // TPC id.
+ IIdentifier tpcId;
+
+ // Ecal ids.
+ IIdentifier ecalBarrelId;
+ IIdentifier ecalEndcapId;
+ IIdentifier ecalEndcapPositiveId;
+ IIdentifier ecalEndcapNegativeId;
+
+ // Hcal ids.
+ IIdentifier hcalBarrelId;
+ IIdentifier hcalEndcapId;
+ IIdentifier hcalEndcapPositiveId;
+ IIdentifier hcalEndcapNegativeId;
+
+ // Muon ids.
+ IIdentifier muonBarrelId;
+ IIdentifier muonEndcapId;
+ IIdentifier muonEndcapPositiveId;
+ IIdentifier muonEndcapNegativeId;
+
+ // Ecal forward ids.
+ IIdentifier ecalForwardId;
+ IIdentifier ecalForwardEndcapPositiveId;
+ IIdentifier ecalForwardEndcapNegativeId;
+
+ // Luminosity monitor ids.
+ IIdentifier lumiId;
+ IIdentifier lumiEndcapPositiveId;
+ IIdentifier lumiEndcapNegativeId;
+
+ // FIXME: Add an hcalForward subsystem.
+
+ public static class SystemMap
+ extends HashMap<String,Integer>
+ {
+ public Integer put(String key, Integer value)
+ {
+ if (containsKey(key))
+ {
+ System.err.println("The field " + key + " was already set to " + value + " ! Ignored.");
+ return -1;
+ }
+ else {
+ return super.put(key, value);
+ }
+ }
+ }
+
+ private static SystemMap defaultSystemMap;
+
+ private SystemMap makeDefaultSystemMap()
+ {
+ if (defaultSystemMap == null)
+ {
+ defaultSystemMap = new SystemMap();
+
+ SystemMap s = defaultSystemMap;
+
+ s.put("unknown",0);
+ s.put("vtxBarrel",1);
+ s.put("vtxEndcap",2);
+ s.put("sitBarrel",3);
+ s.put("sitEndcap",4);
+ s.put("sitForward", 5);
+ s.put("tpc",6);
+ s.put("ecalBarrel",7);
+ s.put("ecalEndcap",8);
+ s.put("hcalBarrel",9);
+ s.put("hcalEndcap",10);
+ s.put("muonBarrel",11);
+ s.put("muonEndcap",12);
+ s.put("ecalForward",13);
+ s.put("lumi",14);
+ }
+ return defaultSystemMap;
+ }
+
+ private void setSystemValues(SystemMap s)
+ {
+ if (s != null)
+ {
+ if (s.containsKey("unknown"))
+ unknownValue = s.get("unknown");
+
+ if (s.containsKey("vtxBarrel"))
+ vtxBarrelValue = s.get("vtxBarrel");
+
+ if (s.containsKey("vtxEndcap"))
+ vtxEndcapValue = s.get("vtxEndcap");
+
+ if (s.containsKey("sitBarrel"))
+ sitBarrelValue = s.get("sitBarrel");
+
+ if (s.containsKey("sitEndcap"))
+ sitEndcapValue = s.get("sitEndcap");
+
+ if (s.containsKey("sitForward"))
+ sitForwardValue = s.get("sitForward");
+
+ if (s.containsKey("tpc"))
+ tpcValue = s.get("tpc");
+
+ if (s.containsKey("ecalBarrel"))
+ ecalBarrelValue = s.get("ecalBarrel");
+
+ if (s.containsKey("ecalEndcap"))
+ ecalEndcapValue = s.get("ecalEndcap");
+
+ if (s.containsKey("hcalBarrel"))
+ hcalBarrelValue = s.get("hcalBarrel");
+
+ if (s.containsKey("hcalEndcap"))
+ hcalEndcapValue = s.get("hcalEndcap");
+
+ if (s.containsKey("muonBarrel"))
+ muonBarrelValue = s.get("muonBarrel");
+
+ if (s.containsKey("muonEndcap"))
+ muonEndcapValue = s.get("muonEndcap");
+
+ if (s.containsKey("ecalForward"))
+ ecalForwardValue = s.get("ecalForward");
+
+ if (s.containsKey("lumi"))
+ lumiValue = s.get("lumi");
+ }
+ }
+
+ private void setup(IIdentifierDictionary dict, SystemMap systemMap) throws InvalidIndexException, FieldNotFoundException
+ {
+ if (systemMap == null)
+ systemMap = makeDefaultSystemMap();
+
+ setSystemValues(systemMap);
+
+ systemIndex = dict.getFieldIndex("system");
+ barrelIndex = dict.getFieldIndex("barrel");
+
+ // Optional layer field.
+ if (dict.hasField("layer"))
+ layerIndex = dict.getFieldIndex("layer");
+
+ barrelId = makeBarrelId(barrelValue);
+ endcapPositiveId = makeBarrelId(endcapPositiveValue);
+ endcapNegativeId = makeBarrelId(endcapNegativeValue);
+
+ vtxBarrelId = makeSubsysId(vtxBarrelValue,barrelValue);
+ vtxEndcapPositiveId = makeSubsysId(vtxEndcapValue,endcapPositiveValue);
+ vtxEndcapNegativeId = makeSubsysId(vtxEndcapValue,endcapNegativeValue);
+
+ sitBarrelId = makeSubsysId(sitBarrelValue,barrelValue);
+ sitEndcapPositiveId = makeSubsysId(sitEndcapValue,endcapPositiveValue);
+ sitEndcapNegativeId = makeSubsysId(sitEndcapValue,endcapNegativeValue);
+
+ sitForwardId = makeSubsysId(sitForwardValue);
+ sitForwardEndcapPositiveId = makeSubsysId(sitForwardValue,endcapPositiveValue);
+ sitForwardEndcapNegativeId = makeSubsysId(sitForwardValue,endcapNegativeValue);
+
+ tpcId = makeSubsysId(tpcValue);
+
+ ecalBarrelId = makeSubsysId(ecalBarrelValue,barrelValue);
+ ecalEndcapPositiveId = makeSubsysId(ecalEndcapValue,endcapPositiveValue);
+ ecalEndcapNegativeId = makeSubsysId(ecalEndcapValue,endcapNegativeValue);
+
+ hcalBarrelId = makeSubsysId(hcalBarrelValue,barrelValue);
+ hcalEndcapPositiveId = makeSubsysId(hcalEndcapValue,endcapPositiveValue);
+ hcalEndcapNegativeId = makeSubsysId(hcalEndcapValue,endcapNegativeValue);
+
+ muonBarrelId = makeSubsysId(muonBarrelValue,barrelValue);
+ muonEndcapPositiveId = makeSubsysId(muonEndcapValue,endcapPositiveValue);
+ muonEndcapNegativeId = makeSubsysId(muonEndcapValue,endcapNegativeValue);
+
+ ecalForwardId = makeSubsysId(ecalForwardValue);
+ ecalForwardEndcapPositiveId = makeSubsysId(ecalForwardValue, endcapPositiveValue);
+ ecalForwardEndcapNegativeId = makeSubsysId(ecalForwardValue, endcapNegativeValue);
+
+ lumiId = makeSubsysId(lumiValue);
+ lumiEndcapPositiveId = makeSubsysId(lumiValue,endcapPositiveValue);
+ lumiEndcapNegativeId = makeSubsysId(lumiValue,endcapNegativeValue);
+ }
+
+ // For subclasses only.
+ //protected DetectorIdHelper(IIdentifierDictionary dict)
+ //{
+ // super(dict);
+ //}
+
+ // Public ctor.
+ public DetectorIdHelper(IIdentifierDictionary dict, SystemMap systemMap) throws FieldNotFoundException, InvalidIndexException
+ {
+ super(dict);
+ setup(dict,systemMap);
+ }
+
+ private IIdentifier makeSubsysId(int system) throws InvalidIndexException
+ {
+ IExpandedIdentifier expid =
+ new ExpandedIdentifier(getIdentifierDictionary().getNumberOfFields());
+ expid.setValue(systemIndex, system);
+ IIdentifier id = pack(expid);
+ return id;
+ }
+
+ private IIdentifier makeSubsysId(int system, int barrel) throws InvalidIndexException
+ {
+ IExpandedIdentifier expid =
+ new ExpandedIdentifier(getIdentifierDictionary().getNumberOfFields());
+ expid.setValue(systemIndex, system);
+ expid.setValue(barrelIndex, barrel);
+ IIdentifier id = pack(expid);
+ return id;
+ }
+ private IIdentifier makeBarrelId(int barrel) throws InvalidIndexException
+ {
+ IExpandedIdentifier expid =
+ new ExpandedIdentifier(getIdentifierDictionary().getNumberOfFields());
+ expid.setValue(barrelIndex, barrel);
+ IIdentifier id = pack(expid);
+ return id;
+ }
+
+ private boolean compareSystem(IIdentifier id, int system)
+ {
+ try {
+ return unpack(id).getValue(systemIndex) == system;
+ }
+ catch (InvalidIndexException x)
+ {
+ throw new RuntimeException(x);
+ }
+ }
+
+ public int getBarrelValue()
+ {
+ return barrelValue;
+ }
+
+ public int getEndcapPositiveValue()
+ {
+ return endcapPositiveValue;
+ }
+
+ public int getEndcapNegativeValue()
+ {
+ return endcapNegativeValue;
+ }
+
+ public int getUnknownValue()
+ {
+ return unknownValue;
+ }
+
+ public int getVtxBarrelValue()
+ {
+ return vtxBarrelValue;
+ }
+ public int getVtxEndcapValue()
+ {
+ return vtxEndcapValue;
+ }
+
+ public int getSitForwardValue()
+ {
+ return sitForwardValue;
+ }
+
+ public int getSitBarrelValue()
+ {
+ return sitBarrelValue;
+ }
+ public int getSitEndcapValue()
+ {
+ return sitEndcapValue;
+ }
+
+ public int getEcalBarrelValue()
+ {
+ return ecalBarrelValue;
+ }
+ public int getEcalEndcapValue()
+ {
+ return ecalEndcapValue;
+ }
+
+ public IIdentifier getBarrelId()
+ {
+ return barrelId;
+ }
+
+ public IIdentifier getEndcapPositiveId()
+ {
+ return endcapPositiveId;
+ }
+
+ public IIdentifier getEndcapNegativeId()
+ {
+ return endcapNegativeId;
+ }
+
+ public IIdentifier getVtxBarrelId()
+ {
+ return vtxBarrelId;
+ }
+
+ public IIdentifier getVtxEndcapId()
+ {
+ return vtxEndcapId;
+ }
+ public IIdentifier getVtxEndcapPositiveId()
+ {
+ return vtxEndcapPositiveId;
+ }
+
+ public IIdentifier getVtxEndcapNegativeId()
+ {
+ return vtxEndcapNegativeId;
+ }
+
+ public IIdentifier getSitEndcapId()
+ {
+ return sitEndcapId;
+ }
+ public IIdentifier getSitBarrelId()
+ {
+ return sitBarrelId;
+ }
+
+ public IIdentifier getSitEndcapPositiveId()
+ {
+ return sitEndcapPositiveId;
+ }
+
+ public IIdentifier getSitEndcapNegativeId()
+ {
+ return sitEndcapNegativeId;
+ }
+
+ public IIdentifier getSitForwardId()
+ {
+ return sitForwardId;
+ }
+
+ public IIdentifier getSitForwardEndcapPositiveId()
+ {
+ return sitForwardEndcapPositiveId;
+ }
+
+ public IIdentifier getSitForwardEndcapNegativeId()
+ {
+ return sitForwardEndcapNegativeId;
+ }
+
+ public IIdentifier getTpcId()
+ {
+ return tpcId;
+ }
+
+ public IIdentifier getEcalEndcapId()
+ {
+ return ecalEndcapId;
+ }
+
+ public IIdentifier getEcalBarrelId()
+ {
+ return ecalBarrelId;
+ }
+
+ public IIdentifier getEcalEndcapNegativeId()
+ {
+ return ecalEndcapNegativeId;
+ }
+
+ public IIdentifier getEcalEndcapPositiveId()
+ {
+ return ecalEndcapPositiveId;
+ }
+
+ public IIdentifier getHcalBarrelId()
+ {
+ return hcalBarrelId;
+ }
+
+ public IIdentifier getHcalEndcapNegativeId()
+ {
+ return hcalEndcapNegativeId;
+ }
+
+ public IIdentifier getHcalEndcapPositiveId()
+ {
+ return hcalEndcapPositiveId;
+ }
+
+ public IIdentifier getMuonBarrelId()
+ {
+ return muonBarrelId;
+ }
+ public IIdentifier getMuonEndcapId()
+ {
+ return muonEndcapId;
+ }
+ public IIdentifier getMuonEndcapNegativeId()
+ {
+ return muonEndcapNegativeId;
+ }
+
+ public IIdentifier getMuonEndcapPositiveId()
+ {
+ return muonEndcapPositiveId;
+ }
+
+ public IIdentifier getEcalForwardId()
+ {
+ return ecalForwardId;
+ }
+
+ public IIdentifier getEcalForwardEndcapPositiveId()
+ {
+ return ecalForwardEndcapPositiveId;
+ }
+
+ public IIdentifier getEcalForwardEndcapNegativeId()
+ {
+ return ecalForwardEndcapNegativeId;
+ }
+
+ public IIdentifier getLumiId()
+ {
+ return lumiId;
+ }
+
+ public IIdentifier getLumiEndcapPositiveId()
+ {
+ return lumiEndcapPositiveId;
+ }
+
+ public IIdentifier getLumiEndcapNegativeId()
+ {
+ return lumiEndcapNegativeId;
+ }
+
+ public boolean isBarrel(IIdentifier i)
+ {
+ try {
+ return unpack(i).getValue(barrelIndex) == barrelValue;
+ }
+ catch (InvalidIndexException x)
+ {
+ throw new RuntimeException(x);
+ }
+ }
+
+ public boolean isEndcap(IIdentifier i)
+ {
+ return isEndcapPositive(i) || isEndcapNegative(i);
+ }
+
+ public boolean isEndcapPositive(IIdentifier i)
+ {
+ try {
+ return unpack(i).getValue(barrelIndex) == endcapPositiveValue;
+ }
+ catch (InvalidIndexException x)
+ {
+ throw new RuntimeException(x);
+ }
+ }
+
+ public boolean isEndcapNegative(IIdentifier i)
+ {
+ try {
+ return unpack(i).getValue(barrelIndex) == endcapNegativeValue;
+ }
+ catch (InvalidIndexException x)
+ {
+ throw new RuntimeException(x);
+ }
+ }
+
+ public boolean isTracker(IIdentifier i)
+ {
+ return isVtx(i) || isTpc(i) || isSit(i) || isSitForward(i);
+ }
+
+ public boolean isTrackerBarrel(IIdentifier i)
+ {
+ return isTracker(i) && isBarrel(i);
+ }
+
+ public boolean isTrackerEndcap(IIdentifier i)
+ {
+ return isTracker(i) && isEndcap(i);
+ }
+
+ public boolean isTrackerEndcapPositive(IIdentifier i)
+ {
+ return isTracker(i) && isEndcapPositive(i);
+ }
+
+ public boolean isTrackerEndcapNegative(IIdentifier i)
+ {
+ return isTracker(i) && isEndcapNegative(i);
+ }
+
+ public boolean isCalorimeter(IIdentifier i)
+ {
+ return isEcal(i) || isHcal(i) || isMuon(i) || isEcalForward(i) || isLumi(i);
+ }
+
+ public boolean isCalorimeterBarrel(IIdentifier i)
+ {
+ return isCalorimeter(i) && isBarrel(i);
+ }
+
+ public boolean isCalorimeterEndcap(IIdentifier i)
+ {
+ return isCalorimeter(i) && isEndcap(i);
+ }
+
+ public boolean isCalorimeterEndcapPositive(IIdentifier i)
+ {
+ return isCalorimeter(i) && isEndcapPositive(i);
+ }
+
+ public boolean isCalorimeterEndcapNegative(IIdentifier i)
+ {
+ return isCalorimeter(i) && isEndcapNegative(i);
+ }
+
+ public boolean isVtx(IIdentifier i)
+ {
+ return compareSystem(i,vtxBarrelValue) || compareSystem(i,vtxEndcapValue);
+ }
+
+ public boolean isVtxBarrel(IIdentifier i)
+ {
+ return isVtx(i) && isBarrel(i);
+ }
+
+ public boolean isVtxEndcap(IIdentifier i)
+ {
+ return compareSystem(i,vtxEndcapValue) && isEndcap(i);
+ }
+
+ public boolean isVtxEndcapPositive(IIdentifier i)
+ {
+ return isVtx(i) && isEndcapPositive(i);
+ }
+
+ public boolean isVtxEndcapNegative(IIdentifier i)
+ {
+ return isVtx(i) && isEndcapNegative(i);
+ }
+
+ public boolean isSit(IIdentifier i)
+ {
+ return compareSystem(i,sitBarrelValue) || compareSystem(i,sitEndcapValue);
+ }
+
+ public boolean isSitBarrel(IIdentifier i)
+ {
+ return isSit(i) && isBarrel(i);
+ }
+
+ public boolean isSitEndcap(IIdentifier i)
+ {
+ return isSit(i) && isEndcap(i);
+ }
+
+ public boolean isSitEndcapPositive(IIdentifier i)
+ {
+ return isSit(i) && isEndcapPositive(i);
+ }
+
+ public boolean isSitEndcapNegative(IIdentifier i)
+ {
+ return isSit(i) && isEndcapNegative(i);
+ }
+
+ public boolean isSitForward(IIdentifier i)
+ {
+ return compareSystem(i,sitForwardValue);
+ }
+
+ public boolean isSitForwardEndcapNegative(IIdentifier i)
+ {
+ return isSitForward(i) && isEndcapNegative(i);
+ }
+
+ public boolean isSitForwardEndcapPositive(IIdentifier i)
+ {
+ return isSitForward(i) && isEndcapPositive(i);
+ }
+
+ public boolean isTpc(IIdentifier i)
+ {
+ return compareSystem(i,tpcValue);
+ }
+
+ public boolean isEcal(IIdentifier i)
+ {
+ return compareSystem(i,ecalBarrelValue) || compareSystem(i,ecalEndcapValue);
+ }
+
+ public boolean isEcalBarrel(IIdentifier i)
+ {
+ return isEcal(i) && isBarrel(i);
+ }
+
+ public boolean isEcalEndcap(IIdentifier i)
+ {
+ return isEcal(i) && isEndcap(i);
+ }
+
+ public boolean isEcalEndcapPositive(IIdentifier i)
+ {
+ return isEcal(i) && isEndcapPositive(i);
+ }
+
+ public boolean isEcalEndcapNegative(IIdentifier i)
+ {
+ return isEcal(i) && isEndcapNegative(i);
+ }
+
+ public boolean isHcal(IIdentifier i)
+ {
+ return compareSystem(i,hcalBarrelValue) || compareSystem(i,hcalEndcapValue);
+ }
+
+ public boolean isHcalBarrel(IIdentifier i)
+ {
+ return isHcal(i) && isBarrel(i);
+ }
+
+ public boolean isHcalEndcap(IIdentifier i)
+ {
+ return isHcal(i) && isEndcap(i);
+ }
+
+ public boolean isHcalEndcapPositive(IIdentifier i)
+ {
+ return isHcal(i) && isEndcapPositive(i);
+ }
+
+ public boolean isHcalEndcapNegative(IIdentifier i)
+ {
+ return isHcal(i) && isEndcapNegative(i);
+ }
+
+ public boolean isMuon(IIdentifier i)
+ {
+ return compareSystem(i,muonBarrelValue) || compareSystem(i,muonEndcapValue);
+ }
+
+ public boolean isMuonBarrel(IIdentifier i)
+ {
+ return isMuon(i) && isBarrel(i);
+ }
+
+ public boolean isMuonEndcap(IIdentifier i)
+ {
+ return isMuon(i) && isEndcap(i);
+ }
+
+ public boolean isMuonEndcapPositive(IIdentifier i)
+ {
+ return isMuon(i) && isEndcapPositive(i);
+ }
+
+ public boolean isMuonEndcapNegative(IIdentifier i)
+ {
+ return isMuon(i) && isEndcapNegative(i);
+ }
+
+ public boolean isEcalForward(IIdentifier i)
+ {
+ return compareSystem(i,ecalForwardValue);
+ }
+
+ public boolean isEcalForwardEndcapPositive(IIdentifier i)
+ {
+ return isEcalForward(i) && isEndcapPositive(i);
+ }
+
+ public boolean isEcalForwardEndcapNegative(IIdentifier i)
+ {
+ return isEcalForward(i) && isEndcapNegative(i);
+ }
+
+ public boolean isLumi(IIdentifier i)
+ {
+ return compareSystem(i,lumiValue);
+ }
+
+ public boolean isLumiEndcapPositive(IIdentifier i)
+ {
+ return isLumi(i) && isEndcapPositive(i);
+ }
+
+ public boolean isLumiEndcapNegative(IIdentifier i)
+ {
+ return isLumi(i) && isEndcapNegative(i);
+ }
+
+ public int getSystem(IIdentifier i)
+ {
+ try {
+ return unpack(i).getValue(systemIndex);
+ }
+ catch (InvalidIndexException x)
+ {
+ throw new RuntimeException(x);
+ }
+ }
+
+ public int getBarrel(IIdentifier i)
+ {
+ try {
+ return unpack(i).getValue(barrelIndex);
+ }
+ catch (InvalidIndexException x)
+ {
+ throw new RuntimeException(x);
+ }
+ }
+
+ public int getLayer(IIdentifier i)
+ {
+ if (layerIndex == invalidIndex)
+ throw new RuntimeException("The layer number is not available, because " + getIdentifierDictionary().getName() + " does not have a layer field!");
+ try
+ {
+ return unpack(i).getValue(layerIndex);
+ }
+ catch (InvalidIndexException x)
+ {
+ throw new RuntimeException(x);
+ }
+ }
+
+ public boolean layerEquals(IIdentifier i, int layer)
+ {
+ return getLayer(i) == layer;
+ }
+
+ public boolean systemEquals(IIdentifier i, int system)
+ {
+ return getSystem(i) == system;
+ }
+
+ public boolean barrelEquals(IIdentifier i, int barrel)
+ {
+ return getBarrel(i) == barrel;
+ }
+
+ public int getSystemIndex()
+ {
+ return systemIndex;
+ }
+
+ public int getLayerIndex()
+ {
+ return layerIndex;
+ }
+
+ public int getBarrelIndex()
+ {
+ return barrelIndex;
+ }
+
+ public int getInvalidIndex()
+ {
+ return invalidIndex;
+ }
+}
GeomConverter/src/org/lcsim/detector/converter/compact
diff -u -r1.20 -r1.21
--- DetectorConverter.java 28 Aug 2007 22:26:34 -0000 1.20
+++ DetectorConverter.java 6 Sep 2007 18:14:46 -0000 1.21
@@ -8,6 +8,7 @@
import org.jdom.Element;
import org.jdom.JDOMException;
import org.lcsim.detector.DetectorElement;
+import org.lcsim.detector.DetectorIdHelper;
import org.lcsim.detector.IDetectorElement;
import org.lcsim.detector.ILogicalVolume;
import org.lcsim.detector.IPhysicalVolume;
@@ -15,9 +16,13 @@
import org.lcsim.detector.ParametersStore;
import org.lcsim.detector.PhysicalVolume;
import org.lcsim.detector.PhysicalVolumeNavigatorStore;
+import org.lcsim.detector.DetectorIdHelper.SystemMap;
import org.lcsim.detector.converter.lcdd.MaterialElementConverter;
import org.lcsim.detector.converter.lcdd.MaterialMixtureConverter;
import org.lcsim.detector.converter.lcdd.MaterialsConverter;
+import org.lcsim.detector.identifier.ExpandedIdentifier;
+import org.lcsim.detector.identifier.IExpandedIdentifier;
+import org.lcsim.detector.identifier.IIdentifier;
import org.lcsim.detector.identifier.IIdentifierDictionary;
import org.lcsim.detector.identifier.IIdentifierField;
import org.lcsim.detector.identifier.IdentifierDictionary;
@@ -25,6 +30,8 @@
import org.lcsim.detector.identifier.IdentifierField;
import org.lcsim.detector.identifier.IdentifierHelper;
import org.lcsim.detector.identifier.IIdentifierDictionary.DuplicateFieldException;
+import org.lcsim.detector.identifier.IIdentifierDictionary.FieldNotFoundException;
+import org.lcsim.detector.identifier.IIdentifierDictionary.InvalidIndexException;
import org.lcsim.detector.material.IMaterial;
import org.lcsim.detector.material.MaterialStore;
import org.lcsim.detector.solids.Box;
@@ -33,86 +40,111 @@
import org.lcsim.geometry.Readout;
import org.lcsim.geometry.compact.Constant;
import org.lcsim.geometry.compact.Subdetector;
+import org.lcsim.geometry.subdetector.PolyconeSupport;
import org.lcsim.geometry.util.IDDescriptor;
public class DetectorConverter implements IDetectorConverter
{
Map<Class,ISubdetectorConverter> subdetectorConverters =
new HashMap<Class,ISubdetectorConverter>();
-
+
+ SystemMap systemMap = null;
+ int systemIndex = -1;
+ int systemLength = -1;
+ int systemOffset = -1;
+ int systemOrder = -1;
+ int barrelIndex = -1;
+ int barrelLength = -1;
+ int barrelOffset = -1;
+ int barrelOrder = -1;
+
+ boolean useSingleDetectorIdHelper = false;
+
+ public IPhysicalVolume convert(Detector detector, Document doc) throws JDOMException, IOException
+ {
+ //System.out.println("Converting " + detector.getName() + " to detailed description ...");
+
+ // Construct the world volume.
+ IPhysicalVolume pvWorld = buildWorldVolume(detector);
+
+ // Create the default navigator.
+ PhysicalVolumeNavigatorStore.getInstance().reset();
+ PhysicalVolumeNavigatorStore.getInstance().createDefault(pvWorld);
+
+ // Set the Detector's associated DetectorElement.
+ IDetectorElement deDet = new DeDetector(detector);
+ detector.setDetectorElement(deDet);
+
+ // Construct the tracking volume.
+ buildTrackingVolume(pvWorld.getLogicalVolume(), detector);
+
+ // Set the world volume.
+ detector.setWorldVolume(pvWorld);
+
+ // Convert materials.
+ convertMaterials("/org/lcsim/material/elements.xml");
+ convertMaterials("/org/lcsim/material/materials.xml");
+ convertMaterials(doc);
+
+ // Make a system map of subdetector types to system id.
+ systemMap = makeSystemMap(detector);
+
+ // Convert Subdetectors including creation of IdentifierHelpers.
+ convertSubdetectors(detector);
+
+ // Create the top level IdentifierHelper for the detector if possible.
+ if (useSingleDetectorIdHelper)
+ makeDetectorIdHelper(detector);
+
+ //System.out.println("Done converting " + detector.getName() + " !");
+
+ // Return the world volume.
+ return pvWorld;
+ }
+
+
public DetectorConverter()
{
addSubdetectorConverter( new CylindricalBarrelCalorimeterConverter() );
- addSubdetectorConverter( new CylindricalEndcapCalorimeterConverter() );
- addSubdetectorConverter( new MultiLayerTrackerConverter() );
- addSubdetectorConverter( new DiskTrackerConverter() );
- addSubdetectorConverter( new SiTrackerBarrelConverter() );
+ addSubdetectorConverter( new CylindricalEndcapCalorimeterConverter() );
+ addSubdetectorConverter( new MultiLayerTrackerConverter() );
+ addSubdetectorConverter( new DiskTrackerConverter() );
+ addSubdetectorConverter( new SiTrackerBarrelConverter() );
}
-
+
private void addSubdetectorConverter(ISubdetectorConverter s)
{
if ( subdetectorConverters.get(s.getSubdetectorType() ) != null )
{
throw new IllegalArgumentException("Already have converter for <" + s.getSubdetectorType().getCanonicalName() + "> !");
}
-
+
subdetectorConverters.put(s.getSubdetectorType(), s);
}
-
+
private ISubdetectorConverter getSubdetectorConverter(Class klass)
{
return subdetectorConverters.get(klass);
}
-
- public IPhysicalVolume convert(Detector detector, String resource) throws JDOMException, IOException
- {
- return convert( detector, CompactDocumentBuilder.build(resource) );
- }
-
- public IPhysicalVolume convert(Detector detector, Document doc) throws JDOMException, IOException
- {
- // Construct the world volume.
- IPhysicalVolume pvWorld = buildWorldVolume(detector);
-
- // Create the default navigator.
- PhysicalVolumeNavigatorStore.getInstance().reset();
- PhysicalVolumeNavigatorStore.getInstance().createDefault(pvWorld);
-
- // Set the Detector's DetectorElement.
- IDetectorElement deDet = new DeDetector(detector);
- detector.setDetectorElement( deDet );
-
- // Construct the tracking volume.
- buildTrackingVolume( pvWorld.getLogicalVolume(), detector );
-
- // Set the world volume.
- detector.setWorldVolume( pvWorld );
-
- // Convert materials.
- convertMaterials( "/org/lcsim/material/elements.xml" );
- convertMaterials( "/org/lcsim/material/materials.xml" );
- convertMaterials( doc );
-
- // Convert Subdetectors.
- convertSubdetectors( detector );
-
- // Return the world volume.
- return pvWorld;
- }
-
+
+ public IPhysicalVolume convert(Detector detector, String resource) throws JDOMException, IOException
+ {
+ return convert( detector, CompactDocumentBuilder.build(resource) );
+ }
+
+
private void convertMaterials(Document doc) throws JDOMException
{
( new MaterialsConverter() ).convert( doc );
}
-
+
private void convertMaterials(String resource) throws JDOMException, IOException
{
Document doc = CompactDocumentBuilder.build(resource);
- //convertMaterials( doc );
-
+
MaterialElementConverter elemCnv = new MaterialElementConverter();
MaterialMixtureConverter matCnv = new MaterialMixtureConverter();
-
+
for ( Object obj : doc.getRootElement().getChildren())
{
Element e = (Element)obj;
@@ -126,147 +158,257 @@
}
}
}
-
+
private void convertSubdetectors(Detector detector)
- {
- ParametersConverter paramCnv = new ParametersConverter();
-
- // Loop over all compact Subdetectors in the Detector.
- for ( Map.Entry<String,Subdetector> entry : detector.getSubdetectors().entrySet())
- {
- Subdetector subdet = entry.getValue();
-
- // Lookup a registered converter for this Subdetector class.
- ISubdetectorConverter cnv = getSubdetectorConverter( subdet.getClass() );
-
- // Convert to detailed description if a suitable converter exists.
- if ( cnv != null && subdet.getReadout() != null )
- {
- // Build the IdentifierDictionary for this Subdetector.
- // Subdetector converters may need this to be done first.
- IIdentifierDictionary iddict = createIdentifierDictionary( subdet );
-
- // Converter parameters.
- try {
- paramCnv.convert(subdet.getNode());
- }
- catch ( JDOMException x )
- {
- throw new RuntimeException(x);
- }
-
- // Convert from a compact type to the generic detector description
- // using a registered converter.
+ {
+ // Create a new parameters converter.
+ ParametersConverter paramCnv = new ParametersConverter();
+
+ // Loop over all Subdetectors in the Detector.
+ for ( Subdetector subdet : detector.getSubdetectors().values())
+ {
+ //System.out.println("converting subdet " + subdet.getName());
+
+ // Lookup a registered converter for this Subdetector class.
+ ISubdetectorConverter cnv = getSubdetectorConverter(subdet.getClass());
+
+ // Build the IdentifierDictionary for this Subdetector.
+ // Subdetector converters may need this to be done first.
+ // An IdentifierDictionary is created for all Subdetectors,
+ // not only those converted to the detailed description.
+ IIdentifierDictionary iddict = createIdentifierDictionary(subdet);
+
+ checkIdDict(iddict);
+
+ // Convert to detailed description if a suitable converter exists.
+ if ( cnv != null && iddict != null )
+ {
+ //System.out.println(subdet.getName() + " will be converted to detailed descr");
+
+ // Convert parameters.
+ try {
+ paramCnv.convert(subdet.getNode());
+ }
+ catch ( JDOMException x )
+ {
+ throw new RuntimeException(x);
+ }
+
+ // Convert from a compact type to the generic detector description
+ // using a registered converter.
cnv.convert(subdet, detector);
-
+
// If this subdetector was converted, it should have a DetectorElement.
- if ( subdet.getDetectorElement() != null )
- {
- // Set the IdentifierHelper.
- ((DetectorElement)subdet.getDetectorElement()).setIdentifierHelper( new IdentifierHelper( iddict ) );
-
- // Set the Parameters.
- ((DetectorElement)subdet.getDetectorElement()).setParameters(ParametersStore.getInstance().get(subdet.getName()));
- }
- }
+ if ( subdet.getDetectorElement() != null )
+ {
+ // Set the IdentifierHelper.
+ ((DetectorElement)subdet.getDetectorElement()).setIdentifierHelper( new IdentifierHelper( iddict ) );
+
+ // Set the Parameters.
+ ((DetectorElement)subdet.getDetectorElement()).setParameters(ParametersStore.getInstance().get(subdet.getName()));
+
+ if (iddict != null)
+ {
+ // Setup the IdentifierHelper for this subdetector.
+ DetectorIdHelper idhelper = null;
+ boolean useDetectorIdHelper=true;
+ try {
+ idhelper = new DetectorIdHelper(iddict, systemMap);
+ }
+ catch (InvalidIndexException x)
+ {
+ useDetectorIdHelper=false;
+ }
+ catch (FieldNotFoundException x)
+ {
+
+ useDetectorIdHelper=false;
+ }
+
+ if (useDetectorIdHelper)
+ {
+ ((DetectorElement)subdet.getDetectorElement()).setIdentifierHelper(idhelper);
+
+ // Create identifiers for the Subdetector and (possibly) its top-level subcomponents.
+ makeIdentifiers(subdet);
+ }
+ }
+
+ //System.out.println("done converting " + subdet.getName());
+ }
+ }
+ /*
+ else
+ {
+ System.out.print("skipping " + subdet.getName() + " - ");
+ if (cnv == null)
+ System.out.println("cnv is null");
+ if (iddict == null)
+ System.out.println("iddict is null");
+ }
+ */
}
}
-
- /**
- * Creates an {@link IIdentifierDictionary} from an existing
- * {@link org.lcsim.geometry.compact.Subdetector}'s
- * {@link org.lcsim.geometry.IDDecoder}.
- *
- * @param subdet The compact Subdetector.
- */
- protected static IIdentifierDictionary createIdentifierDictionary(Subdetector subdet)
- {
- Readout ro = subdet.getReadout();
- IIdentifierDictionary iddict=null;
- if ( ro != null )
- {
- iddict = new IdentifierDictionary(ro.getName());
- IdentifierDictionaryManager.getInstance().addIdentifierDictionary( iddict );
-
- IDDescriptor desc = ro.getIDDescriptor();
- for ( int i=0; i<desc.fieldCount(); i++ )
- {
- int nbits = Math.abs(desc.fieldLength(i));
- int start = desc.fieldStart(i);
- boolean signed = desc.isSigned(i);
- String name = desc.fieldName(i);
-
- IIdentifierField field = new IdentifierField(name,nbits,start,signed,i);
- try {
- iddict.addField(field);
- }
- catch (DuplicateFieldException x)
- {
- throw new RuntimeException(x);
- }
- }
- }
- return iddict;
- }
-
- private void buildTrackingVolume(ILogicalVolume world, Detector detector)
- {
- Map<String,Constant> constants = detector.getConstants();
-
- if ( constants.get("tracking_region_zmax") == null ||
- constants.get("tracking_region_radius") == null)
- {
- throw new RuntimeException("Missing parameters for defining tracking region!");
- }
-
- double zmax = constants.get("tracking_region_zmax").getValue();
- double radius = constants.get("tracking_region_radius").getValue();
-
- Tube trackingTube =
- new Tube("tracking_region_tube", 0, radius, zmax);
-
- LogicalVolume trackingLV =
- new LogicalVolume(
- "tracking_region",
- trackingTube,
- MaterialStore.getInstance().get("Air"));
-
- new PhysicalVolume(
- null,
- "tracking_region",
- trackingLV,
- world,
- 0);
- }
-
+
+ private static void makeIdentifiers(Subdetector subdet)
+ {
+ DetectorIdHelper idhelper = (DetectorIdHelper)subdet.getDetectorElement().getIdentifierHelper();
+
+ int sys = subdet.getSystemID();
+ int sysIndex = idhelper.getSystemIndex();
+ int barrelIndex = idhelper.getBarrelIndex();
+
+ IExpandedIdentifier expid = new ExpandedIdentifier(idhelper.getIdentifierDictionary().getNumberOfFields());
+
+ expid.setValue(sysIndex, sys);
+
+ // Barrel.
+ if (subdet.isBarrel())
+ {
+ expid.setValue(barrelIndex, idhelper.getBarrelValue());
+ try {
+ IIdentifier barrelId = idhelper.pack(expid);
+ subdet.getDetectorElement().setIdentifier(barrelId);
+ }
+ catch (InvalidIndexException x)
+ {
+ throw new RuntimeException(x);
+ }
+ }
+ // Deal with endcaps.
+ else
+ {
+ try {
+ // Id for the endcap container DetectorElement.
+ IIdentifier endcapId = idhelper.pack(expid);
+ subdet.getDetectorElement().setIdentifier(endcapId);
+ }
+ catch (InvalidIndexException x)
+ {
+ throw new RuntimeException(x);
+ }
+
+ // Ids for the positive and negative endcaps.
+ for (IDetectorElement endcap : subdet.getDetectorElement().getChildren())
+ {
+ // Positive endcap.
+ if (endcap.getName().contains("positive"))
+ {
+ expid.setValue(barrelIndex, idhelper.getEndcapPositiveValue());
+ }
+ // Negative endcap.
+ else if (endcap.getName().contains("negative"))
+ {
+ expid.setValue(barrelIndex, idhelper.getEndcapNegativeValue());
+ }
+
+ try {
+ IIdentifier endcapSubId = idhelper.pack(expid);
+ endcap.setIdentifier(endcapSubId);
+ }
+ catch (InvalidIndexException x)
+ {
+ throw new RuntimeException(x);
+ }
+ }
+ }
+ }
+
+ /**
+ * Creates an {@link IIdentifierDictionary} from an existing
+ * {@link org.lcsim.geometry.compact.Subdetector}'s
+ * {@link org.lcsim.geometry.IDDecoder}.
+ *
+ * @param subdet The compact Subdetector.
+ */
+ protected static IIdentifierDictionary createIdentifierDictionary(Subdetector subdet)
+ {
+ Readout ro = subdet.getReadout();
+ IIdentifierDictionary iddict = null;
+ if ( ro != null )
+ {
+ iddict = new IdentifierDictionary(ro.getName());
+ IdentifierDictionaryManager.getInstance().addIdentifierDictionary( iddict );
+
+ IDDescriptor desc = ro.getIDDescriptor();
+ for ( int i=0; i<desc.fieldCount(); i++ )
+ {
+ int nbits = Math.abs(desc.fieldLength(i));
+ int start = desc.fieldStart(i);
+ boolean signed = desc.isSigned(i);
+ String name = desc.fieldName(i);
+
+ IIdentifierField field = new IdentifierField(name,nbits,start,signed,i);
+ try {
+ iddict.addField(field);
+ }
+ catch (DuplicateFieldException x)
+ {
+ throw new RuntimeException(x);
+ }
+ }
+ }
+ return iddict;
+ }
+
+ private void buildTrackingVolume(ILogicalVolume world, Detector detector)
+ {
+ Map<String,Constant> constants = detector.getConstants();
+
+ if ( constants.get("tracking_region_zmax") == null ||
+ constants.get("tracking_region_radius") == null)
+ {
+ throw new RuntimeException("Missing parameters for defining tracking region!");
+ }
+
+ double zmax = constants.get("tracking_region_zmax").getValue();
+ double radius = constants.get("tracking_region_radius").getValue();
+
+ Tube trackingTube =
+ new Tube("tracking_region_tube", 0, radius, zmax);
+
+ LogicalVolume trackingLV =
+ new LogicalVolume(
+ "tracking_region",
+ trackingTube,
+ MaterialStore.getInstance().get("Air"));
+
+ new PhysicalVolume(
+ null,
+ "tracking_region",
+ trackingLV,
+ world,
+ 0);
+ }
+
private IPhysicalVolume buildWorldVolume(Detector detector)
{
Map<String,Constant> constants = detector.getConstants();
-
+
if ( constants.get("world_x") == null ||
- constants.get("world_y") == null ||
- constants.get("world_z") == null ) {
+ constants.get("world_y") == null ||
+ constants.get("world_z") == null ) {
throw new RuntimeException("Missing world_x, world_y, or world_z!");
}
-
+
double x = constants.get("world_x").getValue();
double y = constants.get("world_y").getValue();
double z = constants.get("world_z").getValue();
-
+
IMaterial air = MaterialStore.getInstance().get("Air");
-
+
Box boxWorld = new Box(
"world_box",
x,
y,
z);
-
+
LogicalVolume lvWorld =
new LogicalVolume(
"world",
boxWorld,
air);
-
+
PhysicalVolume pvWorld =
new PhysicalVolume(
null,
@@ -274,7 +416,173 @@
lvWorld,
null,
0);
-
+
return pvWorld;
}
-}
\ No newline at end of file
+
+ // Put here instead of org.lcsim.detector.DetectorIdHelper
+ // to avoid a dependence on Detector.
+ public static final SystemMap makeSystemMap(Detector d)
+ {
+ SystemMap m = new SystemMap();
+
+ for (Subdetector subdet : d.getSubdetectors().values())
+ {
+ String name = subdet.getName();
+
+ int sys = subdet.getSystemID();
+
+ if (!name.contains("Support") && !(subdet instanceof PolyconeSupport))
+ {
+ if (name.contains("VertexBarrel"))
+ {
+ m.put("vtxBarrel", sys);
+ }
+ else if (name.contains("VertexEndcap"))
+ {
+ m.put("vtxEndcap", sys);
+ }
+ else if (name.contains("TrackerBarrel"))
+ {
+ m.put("sitBarrel", sys);
+ }
+ else if (name.contains("TrackerEndcap"))
+ {
+ m.put("sitEndcap", sys);
+ }
+ else if (name.contains("TrackerForward"))
+ {
+ m.put("sitForward", sys);
+ }
+ else if (name.contains("TPC"))
+ {
+ m.put("tpc", sys);
+ }
+ else if (name.contains("EMBarrel"))
+ {
+ m.put("ecalBarrel", sys);
+ }
+ else if (name.contains("EMEndcap") && !name.contains("Forward"))
+ {
+ m.put("ecalEndcap", sys);
+ }
+ else if (name.contains("HADBarrel"))
+ {
+ m.put("hcalBarrel", sys);
+ }
+ else if (name.contains("HADEndcap"))
+ {
+ m.put("hcalEndcap", sys);
+ }
+ else if (name.contains("MuonBarrel"))
+ {
+ m.put("muonBarrel", sys);
+ }
+ else if (name.contains("MuonEndcap"))
+ {
+ m.put("muonEndcap", sys);
+ }
+ else if (name.contains("LuminosityMonitor"))
+ {
+ m.put("lumi", sys);
+ }
+ else if (name.contains("ForwardEMEndcap"))
+ {
+ m.put("ecalForward", sys);
+ }
+ }
+ }
+
+ return m;
+ }
+
+ private void makeDetectorIdHelper(Detector detector)
+ {
+ // If systemIndex was never set, then it is assumed that the compact description
+ // did not have any readouts or at least not any with a system field. This is
+ // possible, e.g. for tests and the like. In this case, the Detector's IdentifierHelper
+ // is left null.
+ if (systemIndex != -1)
+ {
+ IdentifierDictionary iddict = new IdentifierDictionary(detector.getName());
+ try {
+ iddict.addField(new IdentifierField("system",systemLength, systemOffset, false, systemOrder));
+
+ if (barrelIndex != -1)
+ iddict.addField(new IdentifierField("barrel",barrelLength, barrelOffset, false, barrelOrder));
+ else
+ throw new RuntimeException("Missing required field barrel for the top level IdentifierHelper!");
+ }
+ catch (DuplicateFieldException x)
+ {
+ throw new RuntimeException(x);
+ }
+ ((DetectorElement)detector.getDetectorElement()).setIdentifierHelper(new IdentifierHelper(iddict));
+ }
+ }
+
+ private void checkIdDict(IIdentifierDictionary iddict)
+ {
+ // Sanity checks on the system and barrel fields for all Subdetectors.
+ // All system and barrel fields in the same compact description must
+ // result in identical IdentifierFields.
+ if (iddict != null)
+ {
+ if (iddict.hasField("system"))
+ {
+ try {
+ IIdentifierField systemField = iddict.getField("system");
+
+ if (systemIndex == -1)
+ {
+ systemIndex = iddict.getFieldIndex("system");
+ systemLength = systemField.getNumberOfBits();
+ systemOffset = systemField.getOffset();
+ systemOrder = systemField.getOrder();
+ }
+ else
+ {
+ if (iddict.getFieldIndex("system") != systemIndex)
+ throw new RuntimeException("Different indices for system field in same compact description!");
+ if (systemField.getNumberOfBits() != systemLength)
+ throw new RuntimeException("Different lengths for system field in same compact description!");
+ if (systemField.getOrder() != systemOrder)
+ throw new RuntimeException("Different order for system field in same compact description!");
+ if (systemField.isSigned())
+ throw new RuntimeException("The system field is not supposed to be signed!");
+ }
+
+ if (!iddict.hasField("barrel"))
+ throw new RuntimeException(iddict.getName() + " is missing the barrel field!");
+
+ IIdentifierField barrelField = iddict.getField("barrel");
+
+ if (barrelIndex == -1)
+ {
+ barrelIndex = iddict.getFieldIndex("barrel");
+ barrelLength = barrelField.getNumberOfBits();
+ barrelOffset = barrelField.getOffset();
+ barrelOrder = barrelField.getOrder();
+ }
+ else
+ {
+ if (iddict.getFieldIndex("barrel") != barrelIndex)
+ throw new RuntimeException("Different indices for barrel in same compact description!");
+ if (barrelField.getNumberOfBits() != barrelLength)
+ throw new RuntimeException("Different lengths for barrel field in same compact description!");
+ if (barrelField.getOrder() != barrelOrder)
+ throw new RuntimeException("Different order for barrel field in same compact description!");
+ if (barrelField.isSigned())
+ throw new RuntimeException("The barrel field is not supposed to be signed!");
+ }
+
+ useSingleDetectorIdHelper = true;
+ }
+ catch (Exception x)
+ {
+ throw new RuntimeException(x);
+ }
+ }
+ }
+ }
+}