Author: [log in to unmask]
Date: Thu Mar 5 21:16:27 2015
New Revision: 2293
Log:
Add class that maps between EcalCrystal and EcalChannel objects.
Added:
java/trunk/conditions/src/main/java/org/hps/conditions/ecal/EcalCrystalChannelMap.java
Added: java/trunk/conditions/src/main/java/org/hps/conditions/ecal/EcalCrystalChannelMap.java
=============================================================================
--- java/trunk/conditions/src/main/java/org/hps/conditions/ecal/EcalCrystalChannelMap.java (added)
+++ java/trunk/conditions/src/main/java/org/hps/conditions/ecal/EcalCrystalChannelMap.java Thu Mar 5 21:16:27 2015
@@ -0,0 +1,45 @@
+package org.hps.conditions.ecal;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.hps.conditions.ecal.EcalChannel.EcalChannelCollection;
+import org.lcsim.detector.converter.compact.EcalCrystal;
+import org.lcsim.detector.converter.compact.HPSEcalAPI;
+
+/**
+ * This is a convenience utility for associating the geometric crystal
+ * objects with the conditions system channel information.
+ *
+ * @author Jeremy McCormick <[log in to unmask]>
+ */
+final class EcalCrystalChannelMap {
+
+ Map<EcalCrystal, EcalChannel> crystalMap = new HashMap<EcalCrystal, EcalChannel>();
+
+ /**
+ * Creates the map between crystals and channels.
+ * @param api The ECAL API.
+ * @param channels The list of channels.
+ */
+ EcalCrystalChannelMap(HPSEcalAPI api, EcalChannelCollection channels) {
+ List<EcalCrystal> crystals = api.getCrystals();
+ for (EcalCrystal crystal : crystals) {
+ EcalChannel channel = channels.findGeometric(crystal.getIdentifier().getValue());
+ if (channel == null) {
+ throw new RuntimeException("ECAL channel was not found for ID: " + crystal.getExpandedIdentifier());
+ }
+ crystalMap.put(crystal, channel);
+ }
+ }
+
+ /**
+ * Get a channel from a crystal.
+ * @param crystal The geometry object.
+ * @return The channel information or null if does not exist.
+ */
+ EcalChannel getEcalChannel(EcalCrystal crystal) {
+ return crystalMap.get(crystal);
+ }
+}
|