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