LCIO  02.17
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
CellIDEncoder.h
Go to the documentation of this file.
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 
104  CellIDEncoder( const CellIDEncoder&) = delete ;
105  CellIDEncoder& operator=(const CellIDEncoder&) = delete ;
106 
109  CellIDEncoder( const std::string& cellIDEncoding , EVENT::LCCollection* col) :
110 
111  BitField64( cellIDEncoding ),
112 
113  _col( col ) {
114 
115  _col->parameters().setValue( EVENT::LCIO::CellIDEncoding , cellIDEncoding ) ;
116 
117  setCellIDFlag() ;
118  }
119 
120  inline void setCellID( T* hit) {
121 
122  CellIDEncoder_setCellID( hit , lowWord() , highWord() ) ;
123  }
124 
127  void setCellIDFlag() {
128 
129  int bit = CellIDEncoder_cellID1Bit<typename T::lcobject_type>() ;
130 
131  if( bit >= 0 ) {
132 
133  IMPL::LCFlagImpl f( _col->getFlag() ) ;
134 
135  if( highestBit() > 31 ) {
136 
137  // std::cout << " setting bit " << bit << std::endl ;
138  f.setBit( bit ) ;
139 
140  } else {
141  // std::cout << " unsetting bit " << bit << std::endl ;
142  f.unsetBit( bit ) ;
143  }
144 
145  _col->setFlag( f.getFlag() ) ;
146  }
147  }
148 
149  protected:
150 
151  // int cellID1Bit() { return -1 ; }
152 
153 
155  // T* _oldHit ;
156  } ;
157 
158 
159 
160 
161 } // namespace
162 #endif
163 
164 
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...
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.
STL class.
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
void setCellID(T *hit)
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.
EVENT::LCCollection * _col
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
CellIDEncoder & operator=(const CellIDEncoder &)=delete
virtual void setBit(int bit)
Sets bit to 1.
Definition: LCFlagImpl.cc:18
CellIDEncoder(const CellIDEncoder &)=delete
void setCellIDFlag()
Helper method that sets/unsets the proper bit for storing a second cellid word.