LCIO  "2.7.4"
 All Classes Namespaces Functions Variables Typedefs Friends Pages
CellIDEncoder.h
1 #ifndef CellIDEncoder_h
2 #define CellIDEncoder_h 1
3 
4 #include "EVENT/LCCollection.h"
5 #include "UTIL/BitField64.h"
6 #include "IMPL/LCFlagImpl.h"
7 
8 #include <string>
9 
10 //using namespace lcio ;
11 
12 //forward declarations for template specializations
13 namespace EVENT{
14  class SimCalorimeterHit ;
15  class RawCalorimeterHit ;
16  class CalorimeterHit ;
17  class TrackerData ;
18  class TrackerPulse ;
19  class TrackerRawData ;
20  class SimTrackerHit ;
21  class TrackerHit ;
22  class TrackerHitPlane ;
23  class TrackerHitZCylinder ;
24 }
25 
26 namespace UTIL{
27 
28 
32  template <class T>
33  int CellIDEncoder_cellID1Bit() { return -1 ; }
34 
36  template<> int CellIDEncoder_cellID1Bit<EVENT::SimCalorimeterHit>() ;
37 
39  template<> int CellIDEncoder_cellID1Bit<EVENT::RawCalorimeterHit>() ;
40 
42  template<> int CellIDEncoder_cellID1Bit<EVENT::CalorimeterHit>() ;
43 
45  template<> int CellIDEncoder_cellID1Bit<EVENT::TrackerData>() ;
46 
48  template<> int CellIDEncoder_cellID1Bit<EVENT::TrackerPulse>() ;
49 
51  template<> int CellIDEncoder_cellID1Bit<EVENT::TrackerRawData>() ;
52 
54  template<> int CellIDEncoder_cellID1Bit<EVENT::TrackerHit>() ;
55 
57  template<> int CellIDEncoder_cellID1Bit<EVENT::TrackerHitPlane>() ;
58 
60  template<> int CellIDEncoder_cellID1Bit<EVENT::TrackerHitZCylinder>() ;
61 
63  template<> int CellIDEncoder_cellID1Bit<EVENT::SimTrackerHit>() ;
64 
65 
68  template <class T>
69  void CellIDEncoder_setCellID(T* hit, int low, int high) {
70 
71  hit->setCellID0( low ) ;
72  hit->setCellID1( high ) ;
73  }
74 
75 // /** Specialization for SimTrackerHits that have only one cellID */
76 // template<>
77 // void CellIDEncoder_setCellID<IMPL::SimTrackerHitImpl>( IMPL::SimTrackerHitImpl* hit,
78 // int low, int high);
79 //
80 
81 
99  template <class T>
100  class CellIDEncoder : public BitField64 {
101 
102  public:
103 
106  CellIDEncoder( const std::string& cellIDEncoding , EVENT::LCCollection* col) :
107 
108  BitField64( cellIDEncoding ),
109 
110  _col( col ) {
111 
112  _col->parameters().setValue( EVENT::LCIO::CellIDEncoding , cellIDEncoding ) ;
113 
114  setCellIDFlag() ;
115  }
116 
117  inline void setCellID( T* hit) {
118 
119  CellIDEncoder_setCellID( hit , lowWord() , highWord() ) ;
120  }
121 
124  void setCellIDFlag() {
125 
126  int bit = CellIDEncoder_cellID1Bit<typename T::lcobject_type>() ;
127 
128  if( bit >= 0 ) {
129 
130  IMPL::LCFlagImpl f( _col->getFlag() ) ;
131 
132  if( highestBit() > 31 ) {
133 
134  // std::cout << " setting bit " << bit << std::endl ;
135  f.setBit( bit ) ;
136 
137  } else {
138  // std::cout << " unsetting bit " << bit << std::endl ;
139  f.unsetBit( bit ) ;
140  }
141 
142  _col->setFlag( f.getFlag() ) ;
143  }
144  }
145 
146  protected:
147 
148  // int cellID1Bit() { return -1 ; }
149 
150 
151  EVENT::LCCollection* _col ;
152  // T* _oldHit ;
153  } ;
154 
155 
156 
157 
158 } // namespace
159 #endif
160 
161 
unsigned highestBit() const
Highest bit used in fields [0-63].
Definition: BitField64.cc:109
CellIDEncoder(const std::string &cellIDEncoding, EVENT::LCCollection *col)
Constructor, sets collection parameter LCIO::CellIDEncoding to the given encoding string...
Definition: CellIDEncoder.h:106
A bit field of 64bits that allows convenient declaration and manipulation of sub fields of various wi...
Definition: BitField64.h:132
virtual void setFlag(int flag)=0
Set the flag word.
virtual int getFlag() const =0
Returns flag word for collection.
virtual LCParameters & parameters()=0
Parameters defined for this collection.
void CellIDEncoder_setCellID(T *hit, int low, int high)
Helper function that sets cellid1 and cellid2.
Definition: CellIDEncoder.h:69
unsigned highWord() const
The high word, bits 32-63.
Definition: BitField64.h:221
Implementation of helper class to create and interpret the 32-bit flag word in LCCollections.
Definition: LCFlagImpl.h:15
virtual void setValue(const std::string &key, int value)=0
Set integer value for the given key.
Specialization for SimTrackerHits that have only one cellID.
Definition: CellIDEncoder.h:100
unsigned lowWord() const
The low word, bits 0-31.
Definition: BitField64.h:217
The generic collection used in LCIO.
Definition: LCCollection.h:29
int CellIDEncoder_cellID1Bit()
Helper function that returns the bit for cellid1 through template specialization or -1 if no cellid1 ...
Definition: CellIDEncoder.h:33
virtual void setBit(int bit)
Sets bit to 1.
Definition: LCFlagImpl.cc:18
void setCellIDFlag()
Helper method that sets/unsets the proper bit for storing a second cellid word.
Definition: CellIDEncoder.h:124