LCIO  02.17
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
CellIDDecoder.h
Go to the documentation of this file.
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 #include "LCIODeprecated.h"
15 
16 //#include <sstream>
17 //#include <typeinfo>
18 
19 namespace UTIL{
20 
21 
28  template <class T>
29  class CellIDDecoder {
30 
31  public:
32 
33  CellIDDecoder() = default ;
34  CellIDDecoder(const CellIDDecoder& ) = delete ;
35  CellIDDecoder& operator=(const CellIDDecoder& ) = delete ;
36 
37 
40  CellIDDecoder( const std::string& encoder_str ) : _oldHit(0) {
41 
42  if( encoder_str.length() == 0 ){
43  throw( lcio::Exception( "CellIDDecoder : string of length zero provided as encoder string" ) ) ;
44  }
45  _b = new BitField64( encoder_str ) ;
46 
47  }
48 
52 
53  std::string initString("") ;
54 
55  if( col !=0 )
56  initString = col->getParameters().getStringVal( lcio::LCIO::CellIDEncoding ) ;
57 
58  if( initString.size() == 0 ) {
59 
60  initString = _defaultEncoding ;
61 
62  std::cout << " ----------------------------------------- " << std::endl
63  << " WARNING: CellIDDecoder - no CellIDEncoding parameter in collection ! "
64  << std::endl
65  << " -> using default : \"" << initString << "\""
66  << std::endl
67  << " ------------------------------------------ "
68  << std::endl ;
69  }
70 
71  _b = new BitField64( initString ) ;
72  }
73 
75 
76  delete _b ;
77  }
78 
79 
84  inline const BitField64 & operator()( const T* hit ){
85 
86  if( hit != _oldHit && hit ) {
87 
88 
89  lcio::long64 val = lcio::long64( hit->getCellID0() & 0xffffffff )
90  | ( lcio::long64( hit->getCellID1() ) << 32 ) ;
91 
92  _b->setValue( val ) ;
93 
94  _oldHit = hit ;
95  }
96 
97  return *_b ;
98  }
99 
100 
104  LCIO_DEPRECATED( "No longer supported for thread safety issues" ,
105  static void setDefaultEncoding(const std::string& defaultEncoding ) ) ;
106 
107  protected:
109  const T* _oldHit{NULL} ;
110 
112  } ;
113 
114  template <class T>
115  inline void CellIDDecoder<T>::setDefaultEncoding(const std::string& /*defaultEncoding*/ ) {
116  std::cout << "=================== WARNING ===================" << std::endl;
117  std::cout << "static method CellIDDecoder::setDefaultEncoding" << std::endl;
118  std::cout << "does nothing anymore. Use the constructor to " << std::endl;
119  std::cout << "specify your encoding string !!" << std::endl;
120  std::cout << "===============================================" << std::endl;
121  }
122 
123  template <class T>
124  const std::string CellIDDecoder<T>::_defaultEncoding
125  = std::string("M:3,S-1:3,I:9,J:9,K-1:6") ;
126 
127 
128 } // namespace
129 #endif
130 
131 
CellIDDecoder(const std::string &encoder_str)
Constructor takes encoding string as argument.
Definition: CellIDDecoder.h:40
CellIDDecoder & operator=(const CellIDDecoder &)=delete
T endl(T...args)
A bit field of 64bits that allows convenient declaration and manipulation of sub fields of various wi...
Definition: BitField64.h:132
static const std::string _defaultEncoding
const BitField64 & operator()(const T *hit)
Provides access to the bit fields, e.g.
Definition: CellIDDecoder.h:84
STL class.
Convenient class for decoding cellIDs from collection parameter LCIO::CellIDEncoding.
Definition: CellIDDecoder.h:29
CellIDDecoder()=default
void setValue(lcio::long64 value)
Set a new 64bit value.
Definition: BitField64.h:172
T length(T...args)
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:51
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.
EVENT::long64 long64
Definition: LCReader.cc:27
LCIO_DEPRECATED("No longer supported for thread safety issues", 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...