Go to the documentation of this file.00001
00002
00003 #include "DataFormats/SiStripCommon/interface/SiStripDetKey.h"
00004 #include "DataFormats/SiStripCommon/interface/Constants.h"
00005 #include "DataFormats/SiStripCommon/interface/SiStripEnumsAndStrings.h"
00006 #include <iomanip>
00007
00008
00009
00010 SiStripDetKey::SiStripDetKey( const uint16_t& partition ) :
00011 SiStripKey(),
00012 partition_(partition),
00013 apvPairNumber_(sistrip::invalid_),
00014 apvWithinPair_(sistrip::invalid_)
00015 {
00016
00017 initFromValue();
00018 initFromKey();
00019 initFromPath();
00020 initGranularity();
00021 }
00022
00023
00024
00025 SiStripDetKey::SiStripDetKey( const DetId& det_id,
00026 const uint16_t& apv_pair_number,
00027 const uint16_t& apv_within_pair ) :
00028 SiStripKey(),
00029 partition_(sistrip::invalid_),
00030 apvPairNumber_(apv_pair_number),
00031 apvWithinPair_(apv_within_pair)
00032 {
00033
00034 initFromValue();
00035 initFromKey();
00036 initFromPath();
00037 initGranularity();
00038 }
00039
00040
00041
00042 SiStripDetKey::SiStripDetKey( const SiStripDetId& det_id ) :
00043 SiStripKey(),
00044 partition_(sistrip::invalid_),
00045 apvPairNumber_(sistrip::invalid_),
00046 apvWithinPair_(sistrip::invalid_)
00047 {
00048
00049 initFromValue();
00050 initFromKey();
00051 initFromPath();
00052 initGranularity();
00053 }
00054
00055
00056
00057 SiStripDetKey::SiStripDetKey( const uint32_t& det_key ) :
00058 SiStripKey(det_key),
00059 partition_(sistrip::invalid_),
00060 apvPairNumber_(sistrip::invalid_),
00061 apvWithinPair_(sistrip::invalid_)
00062 {
00063
00064 initFromKey();
00065 initFromValue();
00066 initFromPath();
00067 initGranularity();
00068 }
00069
00070
00071
00072 SiStripDetKey::SiStripDetKey( const std::string& path ) :
00073 SiStripKey(path),
00074 partition_(sistrip::invalid_),
00075 apvPairNumber_(sistrip::invalid_),
00076 apvWithinPair_(sistrip::invalid_)
00077 {
00078
00079 initFromPath();
00080 initFromValue();
00081 initFromKey();
00082 initGranularity();
00083 }
00084
00085
00086
00087 SiStripDetKey::SiStripDetKey( const SiStripDetKey& input ) :
00088 SiStripKey(),
00089 partition_(input.partition()),
00090 apvPairNumber_(input.apvPairNumber()),
00091 apvWithinPair_(input.apvWithinPair())
00092 {
00093 key(input.key());
00094 path(input.path());
00095 granularity(input.granularity());
00096 }
00097
00098
00099
00100 SiStripDetKey::SiStripDetKey( const SiStripKey& input ) :
00101 SiStripKey(),
00102 partition_(sistrip::invalid_),
00103 apvPairNumber_(sistrip::invalid_),
00104 apvWithinPair_(sistrip::invalid_)
00105 {
00106 const SiStripDetKey& det_key = dynamic_cast<const SiStripDetKey&>(input);
00107 if ( (&det_key) ) {
00108 key(det_key.key());
00109 path(det_key.path());
00110 granularity(det_key.granularity());
00111 partition_ = det_key.partition();
00112 apvPairNumber_ = det_key.apvPairNumber();
00113 apvWithinPair_ = det_key.apvWithinPair();
00114 }
00115 }
00116
00117
00118
00119 SiStripDetKey::SiStripDetKey( const SiStripKey& input,
00120 const sistrip::Granularity& gran ) :
00121 SiStripKey(),
00122 partition_(0),
00123 apvPairNumber_(0),
00124 apvWithinPair_(0)
00125 {
00126 const SiStripDetKey& det_key = dynamic_cast<const SiStripDetKey&>(input);
00127 if ( (&det_key) ) {
00128
00129 if ( gran == sistrip::PARTITION ) {
00130 partition_ = det_key.partition();
00131 }
00132
00133 initFromValue();
00134 initFromKey();
00135 initFromPath();
00136 initGranularity();
00137
00138 }
00139
00140 }
00141
00142
00143
00144 SiStripDetKey::SiStripDetKey() :
00145 SiStripKey(),
00146 partition_(sistrip::invalid_),
00147 apvPairNumber_(sistrip::invalid_),
00148 apvWithinPair_(sistrip::invalid_)
00149 {;}
00150
00151
00152
00153 bool SiStripDetKey::isEqual( const SiStripKey& key ) const {
00154 const SiStripDetKey& input = dynamic_cast<const SiStripDetKey&>(key);
00155 if ( !(&input) ) { return false; }
00156 if ( partition_ == input.partition() &&
00157 apvPairNumber_ == input.apvPairNumber() &&
00158 apvWithinPair_ == input.apvWithinPair() ) {
00159 return true;
00160 } else { return false; }
00161 }
00162
00163
00164
00165 bool SiStripDetKey::isConsistent( const SiStripKey& key ) const {
00166 const SiStripDetKey& input = dynamic_cast<const SiStripDetKey&>(key);
00167 if ( !(&input) ) { return false; }
00168 if ( isEqual(input) ) { return false; }
00169 else if ( ( partition_ == 0 || input.partition() == 0 ) &&
00170 ( apvPairNumber_ == 0 || input.apvPairNumber() == 0 ) &&
00171 ( apvWithinPair_ == 0 || input.apvWithinPair() == 0 ) ) {
00172 return true;
00173 } else { return false; }
00174 }
00175
00176
00177
00178 bool SiStripDetKey::isValid() const {
00179 return isValid(sistrip::APV);
00180 }
00181
00182
00183
00184 bool SiStripDetKey::isValid( const sistrip::Granularity& gran ) const {
00185 if ( gran == sistrip::TRACKER ) { return true; }
00186 else if ( gran == sistrip::UNDEFINED_GRAN ||
00187 gran == sistrip::UNKNOWN_GRAN ) { return false; }
00188
00189 if ( partition_ != sistrip::invalid_ ) {
00190 if ( gran == sistrip::PARTITION ) { return true; }
00191 }
00192 return false;
00193 }
00194
00195
00196
00197 bool SiStripDetKey::isInvalid() const {
00198 return isInvalid(sistrip::APV);
00199 }
00200
00201
00202
00203 bool SiStripDetKey::isInvalid( const sistrip::Granularity& gran ) const {
00204 if ( gran == sistrip::TRACKER ) { return false; }
00205 else if ( gran == sistrip::UNDEFINED_GRAN ||
00206 gran == sistrip::UNKNOWN_GRAN ) { return false; }
00207
00208 if ( partition_ == sistrip::invalid_ ) {
00209 if ( gran == sistrip::PARTITION ) { return true; }
00210 }
00211 return false;
00212 }
00213
00214
00215
00216 void SiStripDetKey::initFromValue() {
00217
00218
00219 if ( partition_ >= 1 &&
00220 partition_ <= 4 ) {
00221 partition_ = partition_;
00222 } else if ( partition_ == 0 ) {
00223 partition_ = 0;
00224 } else { partition_ = sistrip::invalid_; }
00225
00226 }
00227
00228
00229
00230 void SiStripDetKey::initFromKey() {
00231
00232 if ( key() == sistrip::invalid32_ ) {
00233
00234
00235
00236
00237 key(0);
00238
00239
00240 if ( partition_ >= 1 &&
00241 partition_ <= 4 ) {
00242 key( key() | (partition_<<partitionOffset_) );
00243 } else if ( partition_ == 0 ) {
00244 key( key() | (partition_<<partitionOffset_) );
00245 } else {
00246 key( key() | (partitionMask_<<partitionOffset_) );
00247 }
00248
00249 } else {
00250
00251
00252
00253 partition_ = ( key()>>partitionOffset_ ) & partitionMask_;
00254
00255 if ( partition_ == partitionMask_ ) { partition_ = sistrip::invalid_; }
00256
00257 }
00258
00259 }
00260
00261
00262
00263 void SiStripDetKey::initFromPath() {
00264
00265 if ( path() == sistrip::null_ ) {
00266
00267
00268
00269 std::stringstream dir;
00270
00271 dir << sistrip::root_ << sistrip::dir_
00272 << sistrip::detectorView_ << sistrip::dir_;
00273
00274
00275 if ( partition_ ) {
00276 dir << sistrip::partition_ << partition_ << sistrip::dir_;
00277 }
00278
00279 std::string temp( dir.str() );
00280 path( temp );
00281
00282 } else {
00283
00284
00285
00286 partition_ = 0;
00287
00288
00289 if ( path().find( sistrip::root_ ) == std::string::npos ) {
00290 std::string temp = path();
00291 path( std::string(sistrip::root_) + sistrip::dir_ + temp );
00292 }
00293
00294 size_t curr = 0;
00295 size_t next = 0;
00296 next = path().find( sistrip::detectorView_, curr );
00297
00298
00299 curr = next;
00300 if ( curr != std::string::npos ) {
00301 next = path().find( sistrip::partition_, curr );
00302 std::string detector_view( path(),
00303 curr+(sizeof(sistrip::detectorView_) - 1),
00304 next-(sizeof(sistrip::dir_) - 1)-curr );
00305
00306 curr = next;
00307 if ( curr != std::string::npos ) {
00308 next = std::string::npos;
00309 std::string partition( path(),
00310 curr+(sizeof(sistrip::partition_) - 1),
00311 next-(sizeof(sistrip::dir_) - 1)-curr );
00312 partition_ = std::atoi( partition.c_str() );
00313 }
00314 } else {
00315 std::stringstream ss;
00316 ss << sistrip::root_ << sistrip::dir_;
00317
00318
00319 std::string temp( ss.str() );
00320 path( temp );
00321 }
00322
00323 }
00324
00325 }
00326
00327
00328
00329 void SiStripDetKey::initGranularity() {
00330
00331 granularity( sistrip::TRACKER );
00332 channel(0);
00333 if ( partition_ && partition_ != sistrip::invalid_ ) {
00334 granularity( sistrip::PARTITION );
00335 channel(partition_);
00336 } else if ( partition_ == sistrip::invalid_ ) {
00337 granularity( sistrip::UNKNOWN_GRAN );
00338 channel(sistrip::invalid_);
00339 }
00340
00341 }
00342
00343
00344
00345 void SiStripDetKey::terse( std::stringstream& ss ) const {
00346 ss << "DET:partition= "
00347 << partition();
00348 }
00349
00350
00351
00352 void SiStripDetKey::print( std::stringstream& ss ) const {
00353 ss << " [SiStripDetKey::print]" << std::endl
00354 << std::hex
00355 << " 32-bit Det key : 0x"
00356 << std::setfill('0')
00357 << std::setw(8) << key() << std::endl
00358 << std::setfill(' ')
00359 << std::dec
00360 << " Partition : " << partition() << std::endl
00361 << " Directory : " << path() << std::endl
00362 << " Granularity : "
00363 << SiStripEnumsAndStrings::granularity( granularity() ) << std::endl
00364 << " Channel : " << channel() << std::endl
00365 << " isValid : " << isValid();
00366 }
00367
00368
00369
00370 std::ostream& operator<< ( std::ostream& os, const SiStripDetKey& input ) {
00371 std::stringstream ss;
00372 input.print(ss);
00373 os << ss.str();
00374 return os;
00375 }