LCIO  "2.7.4"
 All Classes Namespaces Functions Variables Typedefs Friends Pages
CellIDDecoder.h
1 #ifndef CellIDDecoder_h
2 #define CellIDDecoder_h 1
3 
4 //#include <vector>
5 //#include "EVENT/LCObject.h"
6 #include "EVENT/LCCollection.h"
7 //#include "EVENT/SimTrackerHit.h"
8 #include "UTIL/BitField64.h"
9 #include "lcio.h"
10 #include <string>
11 
12 // fixes problem in gcc 4.0.3
13 #include "EVENT/LCParameters.h"
14 
15 //#include <sstream>
16 //#include <typeinfo>
17 
18 using namespace lcio ;
19 
20 namespace UTIL{
21 
22 
29  template <class T>
30  class CellIDDecoder {
31 
32  public:
33 
36  CellIDDecoder( const std::string& encoder_str ) : _oldHit(0) {
37 
38  if( encoder_str.length() == 0 ){
39  throw( lcio::Exception( "CellIDDecoder : string of length zero provided as encoder string" ) ) ;
40  }
41  _b = new BitField64( encoder_str ) ;
42 
43  }
44 
47  CellIDDecoder( const EVENT::LCCollection* col ) : _oldHit(0) {
48 
49  std::string initString("") ;
50 
51  if( col !=0 )
52  initString = col->getParameters().getStringVal( lcio::LCIO::CellIDEncoding ) ;
53 
54  if( initString.size() == 0 ) {
55 
56  initString = *_defaultEncoding ;
57 
58  std::cout << " ----------------------------------------- " << std::endl
59  << " WARNING: CellIDDecoder - no CellIDEncoding parameter in collection ! "
60  << std::endl
61  << " -> using default : \"" << initString << "\""
62  << std::endl
63  << " ------------------------------------------ "
64  << std::endl ;
65  }
66 
67  _b = new BitField64( initString ) ;
68  }
69 
70  ~CellIDDecoder(){
71 
72  delete _b ;
73  }
74 
75 
80  inline const BitField64 & operator()( const T* hit ){
81 
82  if( hit != _oldHit && hit ) {
83 
84 
85  lcio::long64 val = lcio::long64( hit->getCellID0() & 0xffffffff )
86  | ( lcio::long64( hit->getCellID1() ) << 32 ) ;
87 
88  _b->setValue( val ) ;
89 
90  _oldHit = hit ;
91  }
92 
93  return *_b ;
94  }
95 
96 
100  static void setDefaultEncoding(const std::string& defaultEncoding ) {
101 
102  delete _defaultEncoding ;
103 
104  _defaultEncoding = new std::string( defaultEncoding ) ;
105  }
106 
107  protected:
108  BitField64* _b ;
109  const T* _oldHit ;
110 
111  static std::string* _defaultEncoding ;
112  } ;
113 
114  template <class T>
116  = new std::string("byte0:8,byte1:8,byte2:8,byte3:8,byte4:8,byte5:8,byte6:8,byte7:8") ;
117 
118 
119 
120 // /** Provides access to the bit fields, e.g. <br>
121 // * int layer = myCellIDEncoding( hit )[ "layer" ] ;
122 // * Specialization for SimTrackerHits that have only one cellID.
123 // */
124 // template<>
125 // inline const BitField64 & CellIDDecoder<SimTrackerHit>::operator()(const SimTrackerHit* hit ){
126 //
127 // if( hit != _oldHit && hit ) {
128 //
129 // long64 val = long64( hit->getCellID() & 0xffffffff ) ;
130 //
131 // _b->setValue( val ) ;
132 //
133 // _oldHit = hit ;
134 // }
135 //
136 // return *_b ;
137 // }
138 //
139 //
140 // template <>
141 // std::string* CellIDDecoder<SimTrackerHit>::_defaultEncoding ;
142 
143 } // namespace
144 #endif
145 
146 
Base exception class for LCIO - all other exceptions extend this.
Definition: Exceptions.h:21
CellIDDecoder(const std::string &encoder_str)
Constructor takes encoding string as argument.
Definition: CellIDDecoder.h:36
A bit field of 64bits that allows convenient declaration and manipulation of sub fields of various wi...
Definition: BitField64.h:132
const BitField64 & operator()(const T *hit)
Provides access to the bit fields, e.g.
Definition: CellIDDecoder.h:80
long long long64
64 bit signed integer,e.g.to be used for timestamps
Definition: LCIOTypes.h:14
Convenient class for decoding cellIDs from collection parameter LCIO::CellIDEncoding.
Definition: CellIDDecoder.h:30
static void setDefaultEncoding(const std::string &defaultEncoding)
This can be used to set the default encoding that is used if no CellIDEncoding parameter is set in th...
Definition: CellIDDecoder.h:100
The generic collection used in LCIO.
Definition: LCCollection.h:29
CellIDDecoder(const EVENT::LCCollection *col)
Constructor reads encoding string from collection parameter LCIO::CellIDEncoding. ...
Definition: CellIDDecoder.h:47
virtual const std::string & getStringVal(const std::string &key) const =0
Returns the first string value for the given key.
virtual const LCParameters & getParameters() const =0
Parameters defined for this collection.