View Javadoc

1   package org.lcsim.recon.tracking.gtrbase;
2   
3   /**
4    *
5    *     This class defines methods that can construct a unique ID for any
6    *     detector element. In order for two different subdetectors to have 
7    *     unique ids but allow each subdetector to implement its own numbering 
8    *     scheme , the ID ( 32 bits long integer ) reserves the last 8 bits. 
9    *     It uses them to identify each particular subdetector. The rest 
10   *     ( 24 bits ) are free for use by subdetectors. Each subdetector should 
11   *     implement its own numbering scheme . The ID is constructed using that 
12   *     subdetector ID . This way, the interperetation of subdetector ID is 
13   *     left to the discretion of each subdetector.
14   *
15   *     It is in no way guaranteed that convention remains the same. The
16   *     reserved 8 bits can be upper or lower or any other. It is required
17   *     that subdetector ID should be no longer than 24 bits though.
18   *     If subdetector follows that rule its subdetector id will be
19   *     always packed and unpacked correctly.
20   *
21   *
22   *@author Norman A. Graf
23   *@version 1.0
24   *
25   */
26  public class DetectorID
27  {
28      protected int _detid;
29  
30      /**
31       *Construct an instance for detector type dettyp and subdetector id subdetid.
32       *
33       * @param   dettyp The detector type.
34       * @param   subdetid The subdetector type.
35       */
36      public DetectorID( int dettyp , int subdetid )
37      {
38          if ( dettyp == 0 ) throw new IllegalArgumentException("dettyp 0 not allowed");
39          int subid = subdetid;
40          if ( (subid  <<  8 >> 8) != subdetid )throw new IllegalArgumentException("Only 8 bits allowed for detector type");
41          //  Assert.assert ( subid.intValue()  <<  8 >> 8 == subdetid );
42          int  type = dettyp;
43          if ( (type << 24 >> 24) != dettyp )throw new IllegalArgumentException("Only 24 bits allowed for subdetector ID");
44          
45          //  Assert.assert ( (type.intValue() << 24 >> 24) != 0);
46          _detid = ((type << 24) | subid) ;
47      }
48      
49      /**
50       *Construct a default instance.
51       *
52       */
53      public DetectorID( )
54      {
55      }
56      
57      /**
58       * Construct an instance from a detector ID.
59       *
60       * @param   detid The detector ID.
61       */
62      public DetectorID( int detid )
63      {
64          // basic sanity check
65          if(detid<0) throw new IllegalArgumentException("detid must be an unsigned int");
66          _detid = detid;
67      }
68      
69      /**
70       * Construct an instance replicating the DetectorID (copy constructor).
71       *
72       * @param   detid The DetectorID to replicate.
73       */
74      public DetectorID(   DetectorID detid )
75      {
76          _detid = detid._detid;
77      }
78         
79      
80      /**
81       * Return the subdetector type.
82       *
83       * @return The subdetector type.
84       */
85      public int subdetectorType( )
86      {
87          return _detid >> 24 ;
88      }
89      
90      /**
91       *Return subdetector ID from detector id detid.
92       *
93       * @return The subdetector id.
94       */
95      public int subdetectorId( )
96      {
97          return _detid << 8 >> 8;
98      }
99      
100     /**
101      *Return the detector ID.
102      *
103      * @return The detector ID.
104      */
105     public int detectorId( )
106     {
107         return _detid;
108     }
109     
110     /**
111      *output stream
112      *
113      * @return A String representation of this instance.
114      */
115     public String toString()
116     {
117         StringBuffer sb = new StringBuffer("DetectorID ");
118         sb.append( _detid );
119         return sb.toString();
120     }
121     
122     
123     /**
124      * Test equality.
125      *
126      * @param   detid The DetectorID to test.
127      * @return true if the DetectorIDs are equal.
128      */
129     public boolean equals(DetectorID detid)
130     {
131         return _detid==detid._detid;
132     }
133     
134     
135     /**
136      * Test inequality.
137      *
138      * @param   detid The DetectorID to test.
139      * @return true if the DetectorIDs are not equal.
140      */
141     public boolean notEquals(DetectorID detid)
142     {
143         return !equals( detid );
144     }
145     
146     
147     /**
148      * Test ordering.
149      *
150      * @param   detid  The DetectorID to test.
151      * @return true if detid is larger.
152      */
153     public boolean lessThan(DetectorID detid)
154     {
155         return _detid<detid._detid;
156     }
157     
158 }