Author: [log in to unmask]
Date: Mon Feb 23 14:39:33 2015
New Revision: 3550
Log:
Correctly handle missing barrel field for subdetector when setting up ID.
Modified:
projects/lcsim/trunk/detector-framework/src/main/java/org/lcsim/detector/converter/compact/AbstractSubdetectorConverter.java
Modified: projects/lcsim/trunk/detector-framework/src/main/java/org/lcsim/detector/converter/compact/AbstractSubdetectorConverter.java
=============================================================================
--- projects/lcsim/trunk/detector-framework/src/main/java/org/lcsim/detector/converter/compact/AbstractSubdetectorConverter.java (original)
+++ projects/lcsim/trunk/detector-framework/src/main/java/org/lcsim/detector/converter/compact/AbstractSubdetectorConverter.java Mon Feb 23 14:39:33 2015
@@ -22,23 +22,15 @@
import org.lcsim.geometry.util.IDDescriptor;
/**
- * An abstract implementation of {@link ISubdetectorConverter} that provides some utilities and default method
- * implementations for Subdetector conversion.
- *
+ * An abstract implementation of {@link ISubdetectorConverter} that provides some utilities
+ * and default method implementations for Subdetector conversion.
* @author Jeremy McCormick
* @version $Id: AbstractSubdetectorConverter.java,v 1.9 2011/02/25 03:09:38 jeremy Exp $
*/
+public abstract class AbstractSubdetectorConverter implements ISubdetectorConverter {
-public abstract class AbstractSubdetectorConverter implements ISubdetectorConverter
-{
- /*
- * public void makeIdentifierContext( Subdetector subdet ) { // Default is a no-op. }
- */
-
- public IDetectorElement makeSubdetectorDetectorElement(Detector detector, Subdetector subdetector)
- {
- IDetectorElement subdetectorDE =
- new SubdetectorDetectorElement(subdetector.getName(), detector.getDetectorElement());
+ public IDetectorElement makeSubdetectorDetectorElement(Detector detector, Subdetector subdetector) {
+ IDetectorElement subdetectorDE = new SubdetectorDetectorElement(subdetector.getName(), detector.getDetectorElement());
subdetector.setDetectorElement(subdetectorDE);
return subdetectorDE;
}
@@ -51,19 +43,17 @@
/**
* Sub-classes must implement this.
*/
- public abstract Class getSubdetectorType();
+ public abstract Class<? extends Subdetector> getSubdetectorType();
/**
- * Creates a concrete {@link org.lcsim.detector.identifier.IIdentifierHelper} for this Subdetector. Concrete
- * converter types should override this if they want to use a different type of helper.
+ * Creates a concrete {@link org.lcsim.detector.identifier.IIdentifierHelper} for this Subdetector.
+ * Concrete converter types should override this if they want to use a different type of helper.
*
* @return An IIdentifierHelper for this Subdetector.
*/
- public IIdentifierHelper makeIdentifierHelper(Subdetector subdetector, SystemMap systemMap)
- {
+ public IIdentifierHelper makeIdentifierHelper(Subdetector subdetector, SystemMap systemMap) {
// Do not create helper if there is no Readout.
- if (subdetector.getReadout() == null)
- {
+ if (subdetector.getReadout() == null) {
return null;
}
@@ -72,12 +62,9 @@
IIdentifierHelper helper = null;
- if (iddict.hasField("system") && iddict.hasField("barrel"))
- {
+ if (iddict.hasField("system") && iddict.hasField("barrel")) {
helper = new DetectorIdentifierHelper(subdetector.getDetectorElement(), iddict, systemMap);
- }
- else
- {
+ } else {
// Make a generic IdentifierHelper if standard fields are not present.
helper = new IdentifierHelper(iddict);
}
@@ -86,27 +73,23 @@
}
/**
- * Utility method for creating an {@link org.lcsim.detector.identifier.IIdentifierDictionary} for a
- * {@link org.lcsim.geometry.Subdetector} by using its {@link org.lcsim.geometry.IDDecoder}.
+ * Utility method for creating an {@link org.lcsim.detector.identifier.IIdentifierDictionary}
+ * for a {@link org.lcsim.geometry.Subdetector} by using its {@link org.lcsim.geometry.IDDecoder}.
*
* @param subdet The Subdetector.
* @return A IdentifierDictionary.
*/
- static IIdentifierDictionary makeIdentifierDictionary(Subdetector subdet)
- {
+ static IIdentifierDictionary makeIdentifierDictionary(Subdetector subdet) {
Readout ro = subdet.getReadout();
IIdentifierDictionary iddict = null;
- if (ro != null)
- {
+ if (ro != null) {
IDDescriptor desc = ro.getIDDescriptor();
List<IIdentifierField> fields = new ArrayList<IIdentifierField>();
- for (int i = 0; i < desc.fieldCount(); i++ )
- {
+ 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);
fields.add(field);
}
@@ -117,67 +100,50 @@
return iddict;
}
- public void makeIdentifiers(Subdetector subdet)
- {
+ public void makeIdentifiers(Subdetector subdet) {
+
+ // FIXME: Should this throw an Exception?
if (subdet.getDetectorElement() == null)
return;
+ // FIXME: Should this throw an Exception?
if (subdet.getDetectorElement().getIdentifierHelper() == null)
return;
- IIdentifierHelper idhelper = subdet.getDetectorElement().getIdentifierHelper();
+ IIdentifierHelper helper = subdet.getDetectorElement().getIdentifierHelper();
+ IIdentifierDictionary iddict = helper.getIdentifierDictionary();
- IIdentifierDictionary iddict = idhelper.getIdentifierDictionary();
+ // Create a new ID.
+ IExpandedIdentifier expId = new ExpandedIdentifier(helper.getIdentifierDictionary().getNumberOfFields());
- int sys = subdet.getSystemID();
- int sysIndex, barrelIndex;
-
- try
- {
- sysIndex = iddict.getFieldIndex("system");
- barrelIndex = iddict.getFieldIndex("barrel");
- }
- catch (Exception x)
- {
- // Missing some required fields. Just ignore.
- return;
+ // Set the system ID.
+ int system = subdet.getSystemID();
+ if (iddict.hasField("system")) {
+ int systemIndex = iddict.getFieldIndex("system");
+ expId.setValue(systemIndex, system);
}
- IExpandedIdentifier expid = new ExpandedIdentifier(idhelper.getIdentifierDictionary().getNumberOfFields());
+ // Set the ID on the primary subdetector container.
+ IIdentifier id = helper.pack(expId);
+ subdet.getDetectorElement().setIdentifier(id);
- expid.setValue(sysIndex, sys);
-
- // Barrel.
- if (subdet.isBarrel())
- {
- expid.setValue(barrelIndex, 0);
- IIdentifier barrelId = idhelper.pack(expid);
- subdet.getDetectorElement().setIdentifier(barrelId);
- }
- // Deal with endcaps.
- else
- {
- // Id for the endcap container DetectorElement.
- IIdentifier endcapId = idhelper.pack(expid);
- subdet.getDetectorElement().setIdentifier(endcapId);
-
- // Ids for the positive and negative endcaps.
- for (IDetectorElement endcap : subdet.getDetectorElement().getChildren())
- {
- // Positive endcap.
- if (endcap.getName().contains("positive"))
- {
- expid.setValue(barrelIndex, 1);
+ // Set the endcap IDs if applicable.
+ if (subdet.isEndcap()) {
+ if (iddict.hasField("barrel")) {
+ int barrelIndex = iddict.getFieldIndex("barrel");
+ // Create IDs for the positive and negative endcaps.
+ for (IDetectorElement endcap : subdet.getDetectorElement().getChildren()) {
+ // This is an endcap in the positive Z direction.
+ if (endcap.getName().contains("positive")) {
+ expId.setValue(barrelIndex, 1);
+ }
+ // This is an endcap in the negative Z direction.
+ else if (endcap.getName().contains("negative")) {
+ expId.setValue(barrelIndex, 2);
+ }
+ IIdentifier endcapId = helper.pack(expId);
+ endcap.setIdentifier(endcapId);
}
- // Negative endcap.
- else if (endcap.getName().contains("negative"))
- {
- expid.setValue(barrelIndex, 2);
- }
-
- IIdentifier endcapSubId = idhelper.pack(expid);
-
- endcap.setIdentifier(endcapSubId);
}
}
}
########################################################################
Use REPLY-ALL to reply to list
To unsubscribe from the LCDET-SVN list, click the following link:
https://listserv.slac.stanford.edu/cgi-bin/wa?SUBED1=LCDET-SVN&A=1
|