View Javadoc

1   package org.lcsim.geometry.compact;
2   
3   import java.util.HashMap;
4   import java.util.Map;
5   
6   /**
7    * A map of system ID to Subdetectors, used by
8    * org.lcsim.geometry.compact.Detector.
9    * 
10   * @author jeremym
11   */
12  class SystemIDMap
13  {
14      private Map<Integer, Subdetector> _subdetectors = new HashMap<Integer, Subdetector>();
15  
16      /**
17       * Add an entry mapping system id to a Subdetector.
18       * 
19       * @param sysid
20       *            System ID which must be > 0
21       * @param subdetector
22       *            Subdetector with this sysid
23       */
24      protected void add(int sysid, Subdetector subdetector)
25      {
26          if (sysid > 0)
27          {
28              if (_subdetectors.containsKey(sysid))
29              {
30                  throw new RuntimeException("The System ID " + sysid + " of " + subdetector.getName()
31                          + " is already used by " + _subdetectors.get(sysid).getName());
32              }
33              else
34              {
35                  _subdetectors.put(sysid, subdetector);                
36              }
37          }
38  //        else
39  //        {
40  //            System.err.println("WARNING: The system id <" + sysid + "> of Subdetector <" + subdetector.getName()
41  //                    + "> was ignored, because it is not greater than zero.");
42  //        }
43      }
44  
45      /** Retrieve a Subdetector by system ID. */
46      protected Subdetector get(int sysid)
47      {
48          return _subdetectors.get(sysid);
49      }
50  }