00001 #ifndef CellIDDecoder_h
00002 #define CellIDDecoder_h 1
00003
00004
00005
00006 #include "EVENT/LCCollection.h"
00007
00008 #include "UTIL/BitField64.h"
00009 #include "lcio.h"
00010 #include <string>
00011
00012
00013 #include "EVENT/LCParameters.h"
00014
00015
00016
00017
00018 namespace UTIL{
00019
00020
00027 template <class T>
00028 class CellIDDecoder {
00029
00030 public:
00031
00032 CellIDDecoder() = default ;
00033 CellIDDecoder(const CellIDDecoder& ) = delete ;
00034 CellIDDecoder& operator=(const CellIDDecoder& ) = delete ;
00035
00036
00039 CellIDDecoder( const std::string& encoder_str ) : _oldHit(0) {
00040
00041 if( encoder_str.length() == 0 ){
00042 throw( lcio::Exception( "CellIDDecoder : string of length zero provided as encoder string" ) ) ;
00043 }
00044 _b = new BitField64( encoder_str ) ;
00045
00046 }
00047
00050 CellIDDecoder( const EVENT::LCCollection* col ) : _oldHit(0) {
00051
00052 std::string initString("") ;
00053
00054 if( col !=0 )
00055 initString = col->getParameters().getStringVal( lcio::LCIO::CellIDEncoding ) ;
00056
00057 if( initString.size() == 0 ) {
00058
00059 initString = _defaultEncoding ;
00060
00061 std::cout << " ----------------------------------------- " << std::endl
00062 << " WARNING: CellIDDecoder - no CellIDEncoding parameter in collection ! "
00063 << std::endl
00064 << " -> using default : \"" << initString << "\""
00065 << std::endl
00066 << " ------------------------------------------ "
00067 << std::endl ;
00068 }
00069
00070 _b = new BitField64( initString ) ;
00071 }
00072
00073 ~CellIDDecoder(){
00074
00075 delete _b ;
00076 }
00077
00078
00083 inline const BitField64 & operator()( const T* hit ){
00084
00085 if( hit != _oldHit && hit ) {
00086
00087
00088 lcio::long64 val = lcio::long64( hit->getCellID0() & 0xffffffff )
00089 | ( lcio::long64( hit->getCellID1() ) << 32 ) ;
00090
00091 _b->setValue( val ) ;
00092
00093 _oldHit = hit ;
00094 }
00095
00096 return *_b ;
00097 }
00098
00099
00103 static void setDefaultEncoding(const std::string& defaultEncoding ) {
00104
00105 _defaultEncoding = std::string( defaultEncoding ) ;
00106 }
00107
00108 protected:
00109 BitField64* _b{} ;
00110 const T* _oldHit{NULL} ;
00111
00112 static std::string _defaultEncoding;
00113 } ;
00114
00115 template <class T>
00116 std::string CellIDDecoder<T>::_defaultEncoding
00117 = std::string("byte0:8,byte1:8,byte2:8,byte3:8,byte4:8,byte5:8,byte6:8,byte7:8") ;
00118
00119
00120 }
00121 #endif
00122
00123