00001 #ifndef LCTrackerConf_h
00002 #define LCTrackerConf_h 1
00003
00004 #include <string>
00005 #include "UTIL/BitField64.h"
00006
00007 namespace UTIL {
00008
00009
00023 class LCTrackerCellID{
00024
00025
00026 enum {
00027 subdetID = 0 ,
00028 sideID = 1 ,
00029 layerID = 2 ,
00030 moduleID = 3 ,
00031 sensorID = 4 ,
00032 } ;
00033
00034
00035 public:
00036
00037 static LCTrackerCellID& instance() {
00038 static LCTrackerCellID _me ;
00039 return _me ;
00040 }
00041
00043 static unsigned subdet() { return subdetID ; }
00044
00046 static unsigned side() { return sideID ; }
00047
00049 static unsigned layer() { return layerID ; }
00050
00052 static unsigned module() { return moduleID ; }
00053
00055 static unsigned sensor() { return sensorID ; }
00056
00057
00059 LCTrackerCellID() : _encoding("subdet:5,side:-2,layer:9,module:8,sensor:8" ),
00060 _accessed(false) {}
00061
00062
00063 static const std::string& encoding_string() {
00064 instance()._accessed = true;
00065 return instance()._encoding ;
00066 }
00067
00069 static std::string valueString( unsigned val ){
00070 instance().setAccessed();
00071 UTIL::BitField64 encoder( instance().encoding_string() ) ;
00072 encoder.setValue( val ) ;
00073 return encoder.valueString() ;
00074 }
00075
00077 void set_encoding_string( const std::string& encodingString ) {
00078 if( _accessed ) throw std::logic_error( "The encoding string was already accessed! Changing it now will lead to inconsistencies! Fix your code!" );
00079
00080 bool isValid = true ;
00081
00082 unsigned long long subdetPos = encodingString.find( "subdet" );
00083 unsigned long long systemPos = encodingString.find( "system" );
00084 unsigned long long sidePos = encodingString.find( "side" ) ;
00085 unsigned long long layerPos = encodingString.find( "layer" ) ;
00086 unsigned long long modulePos = encodingString.find( "module" ) ;
00087 unsigned long long sensorPos = encodingString.find( "sensor" ) ;
00088
00089 isValid = ( (subdetPos != std::string::npos || systemPos != std::string::npos) &&
00090 sidePos != std::string::npos &&
00091 layerPos != std::string::npos &&
00092 modulePos != std::string::npos &&
00093 sensorPos != std::string::npos &&
00094 (
00095 (( subdetPos < sidePos ) || (systemPos < sidePos ) ) &&
00096 ( sidePos < layerPos ) &&
00097 ( layerPos < modulePos ) &&
00098 ( modulePos < sensorPos)
00099 )
00100 );
00101
00102 if( ! isValid ) throw std::runtime_error(" LCTrackerCellID::set_encoding_string(): string needs to contain"
00103 " \"subdet:A,side:B,layer:C,module:D,sensor:E\" " ) ;
00104
00105 _encoding = encodingString;
00106 }
00107
00109 void setAccessed() {
00110 _accessed = true;
00111 }
00112
00113
00114 protected:
00115 std::string _encoding ;
00116 bool _accessed;
00117 } ;
00118
00119 }
00120
00121 #endif