00001
00002
00003 #include "OnlineDB/SiStripConfigDb/interface/SiStripConfigDb.h"
00004 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00005
00006 using namespace std;
00007 using namespace sistrip;
00008
00009
00010
00011 SiStripConfigDb::DcuDetIdsRange SiStripConfigDb::getDcuDetIds( std::string partition ) {
00012
00013
00014 if ( ( !dbParams_.usingDbCache() && !deviceFactory(__func__) ) ||
00015 ( dbParams_.usingDbCache() && !databaseCache(__func__) ) ) {
00016 return dcuDetIds_.emptyRange();
00017 }
00018
00019 try {
00020
00021 if ( !dbParams_.usingDbCache() ) {
00022
00023 SiStripDbParams::SiStripPartitions::const_iterator iter = dbParams_.partitions().begin();
00024 SiStripDbParams::SiStripPartitions::const_iterator jter = dbParams_.partitions().end();
00025 for ( ; iter != jter; ++iter ) {
00026
00027 if ( partition == "" || partition == iter->second.partitionName() ) {
00028
00029 if ( iter->second.partitionName() == SiStripPartition::defaultPartitionName_ ) { continue; }
00030
00031 DcuDetIdsRange range = dcuDetIds_.find( iter->second.partitionName() );
00032 if ( range == dcuDetIds_.emptyRange() ) {
00033
00034 #ifdef USING_NEW_DATABASE_MODEL
00035 deviceFactory(__func__)->addDetIdPartition( iter->second.partitionName(),
00036 iter->second.dcuVersion().first,
00037 iter->second.dcuVersion().second );
00038 #else
00039 deviceFactory(__func__)->addDetIdPartition( iter->second.partitionName() );
00040 #endif
00041
00042
00043 DcuDetIdMap src = deviceFactory(__func__)->getInfos();
00044
00045
00046 DcuDetIdsV dst;
00047 clone( src, dst );
00048
00049
00050 dcuDetIds_.loadNext( iter->second.partitionName(), dst );
00051
00052 }
00053
00054 }
00055
00056 }
00057
00058 } else {
00059
00060 #ifdef USING_NEW_DATABASE_MODEL
00061
00062
00063 DcuDetIdMap* src = databaseCache(__func__)->getInfos();
00064
00065 if ( src ) {
00066
00067
00068 DcuDetIdsV dst;
00069 clone( *src, dst );
00070
00071
00072 dcuDetIds_.loadNext( SiStripPartition::defaultPartitionName_, dst );
00073
00074 } else {
00075 edm::LogWarning(mlConfigDb_)
00076 << "[SiStripConfigDb::" << __func__ << "]"
00077 << " NULL pointer to Dcu-DetId map!";
00078 }
00079 #endif
00080
00081 }
00082
00083 } catch (... ) { handleException( __func__ ); }
00084
00085
00086 uint16_t np = 0;
00087 uint16_t nc = 0;
00088 DcuDetIdsRange range;
00089 if ( partition != "" ) {
00090 range = dcuDetIds_.find( partition );
00091 np = 1;
00092 nc = range.size();
00093 } else {
00094 if ( !dcuDetIds_.empty() ) {
00095 range = DcuDetIdsRange( dcuDetIds_.find( dbParams_.partitions().begin()->second.partitionName() ).begin(),
00096 dcuDetIds_.find( (--(dbParams_.partitions().end()))->second.partitionName() ).end() );
00097 } else { range = dcuDetIds_.emptyRange(); }
00098 np = dcuDetIds_.size();
00099 nc = range.size();
00100 }
00101
00102 stringstream ss;
00103 ss << "[SiStripConfigDb::" << __func__ << "]"
00104 << " Found " << nc << " entries in DCU-DetId map";
00105 if ( !dbParams_.usingDb() ) { ss << " in " << dbParams_.inputDcuInfoXmlFiles().size() << " 'module.xml' file(s)"; }
00106 else { if ( !dbParams_.usingDbCache() ) { ss << " in " << np << " database partition(s)"; }
00107 else { ss << " from shared memory name '" << dbParams_.sharedMemory() << "'"; } }
00108 if ( dcuDetIds_.empty() ) { edm::LogWarning(mlConfigDb_) << ss.str(); }
00109 else { LogTrace(mlConfigDb_) << ss.str(); }
00110
00111 return range;
00112 }
00113
00114
00115
00116 void SiStripConfigDb::addDcuDetIds( std::string partition, DcuDetIdsV& dcus ) {
00117
00118 stringstream ss;
00119 ss << "[SiStripConfigDb::" << __func__ << "]"
00120 << " Cannot add to local cache! This functionality not allowed!";
00121 edm::LogWarning(mlConfigDb_) << ss.str();
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191 }
00192
00193
00194
00195 void SiStripConfigDb::uploadDcuDetIds( std::string partition ) {
00196
00197 stringstream ss;
00198 ss << "[SiStripConfigDb::" << __func__ << "]"
00199 << " Cannot upload to database! This functionality not allowed!";
00200 edm::LogWarning(mlConfigDb_) << ss.str();
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280 }
00281
00282
00283
00284 void SiStripConfigDb::clearDcuDetIds( std::string partition ) {
00285 LogTrace(mlConfigDb_) << "[SiStripConfigDb::" << __func__ << "]";
00286
00287 if ( dcuDetIds_.empty() ) {
00288 stringstream ss;
00289 ss << "[SiStripConfigDb::" << __func__ << "]"
00290 << " Found no cached DCU-DetId map!";
00291
00292 return;
00293 }
00294
00295
00296 DcuDetIds temporary_cache;
00297 if ( partition == "" ) { temporary_cache = DcuDetIds(); }
00298 else {
00299 SiStripDbParams::SiStripPartitions::const_iterator iter = dbParams_.partitions().begin();
00300 SiStripDbParams::SiStripPartitions::const_iterator jter = dbParams_.partitions().end();
00301 for ( ; iter != jter; ++iter ) {
00302 if ( partition != iter->second.partitionName() ) {
00303 DcuDetIdsRange range = dcuDetIds_.find( iter->second.partitionName() );
00304 if ( range != dcuDetIds_.emptyRange() ) {
00305 temporary_cache.loadNext( partition, DcuDetIdsV( range.begin(), range.end() ) );
00306 } else {
00307
00308
00309
00310
00311
00312 }
00313 }
00314 }
00315 }
00316
00317
00318 DcuDetIdsRange dcus;
00319 if ( partition == "" ) {
00320 if ( !dcuDetIds_.empty() ) {
00321 dcus = DcuDetIdsRange( dcuDetIds_.find( dbParams_.partitions().begin()->second.partitionName() ).begin(),
00322 dcuDetIds_.find( (--(dbParams_.partitions().end()))->second.partitionName() ).end() );
00323 } else { dcus = dcuDetIds_.emptyRange(); }
00324 } else {
00325 SiStripDbParams::SiStripPartitions::const_iterator iter = dbParams_.partitions().begin();
00326 SiStripDbParams::SiStripPartitions::const_iterator jter = dbParams_.partitions().end();
00327 for ( ; iter != jter; ++iter ) { if ( partition == iter->second.partitionName() ) { break; } }
00328 dcus = dcuDetIds_.find( iter->second.partitionName() );
00329 }
00330
00331 if ( dcus != dcuDetIds_.emptyRange() ) {
00332
00333 #ifdef USING_NEW_DATABASE_MODEL
00334 DcuDetIdsV::const_iterator ifed = dcus.begin();
00335 DcuDetIdsV::const_iterator jfed = dcus.end();
00336 for ( ; ifed != jfed; ++ifed ) { if ( ifed->second ) { delete ifed->second; } }
00337 #endif
00338
00339 } else {
00340 stringstream ss;
00341 ss << "[SiStripConfigDb::" << __func__ << "]";
00342 if ( partition == "" ) { ss << " Found no DCU-DetId map in local cache!"; }
00343 else { ss << " Found no DCU-DetId map in local cache for partition \"" << partition << "\"!"; }
00344 edm::LogWarning(mlConfigDb_) << ss.str();
00345 }
00346
00347
00348 dcuDetIds_ = temporary_cache;
00349
00350 }
00351
00352
00353
00354 void SiStripConfigDb::printDcuDetIds( std::string partition ) {
00355
00356 std::stringstream ss;
00357 ss << "[SiStripConfigDb::" << __func__ << "]"
00358 << " Contents of DcuDetIds container:" << std::endl;
00359 ss << " Number of partitions: " << dcuDetIds_.size() << std::endl;
00360
00361
00362 uint16_t cntr = 0;
00363 DcuDetIds::const_iterator idcu = dcuDetIds_.begin();
00364 DcuDetIds::const_iterator jdcu = dcuDetIds_.end();
00365 for ( ; idcu != jdcu; ++idcu ) {
00366
00367 cntr++;
00368 if ( partition == "" || partition == idcu->first ) {
00369
00370 ss << " Partition number : " << cntr << " (out of " << dcuDetIds_.size() << ")" << std::endl;
00371 ss << " Partition name : \"" << idcu->first << "\"" << std::endl;
00372 ss << " Size of DCU-DetId map : " << idcu->second.size() << std::endl;
00373
00374 }
00375
00376 }
00377
00378 LogTrace(mlConfigDb_) << ss.str();
00379
00380 }
00381
00382
00383
00384 void SiStripConfigDb::clone( const DcuDetIdMap& input, DcuDetIdsV& output ) const {
00385 output.clear();
00386 DcuDetIdMap::const_iterator ii = input.begin();
00387 DcuDetIdMap::const_iterator jj = input.end();
00388 for ( ; ii != jj; ++ii ) { if ( ii->second ) { output.push_back( std::make_pair( ii->first, new TkDcuInfo( *(ii->second) ) ) ); } }
00389 }
00390
00391
00392
00393 void SiStripConfigDb::clone( const DcuDetIdsV& input, DcuDetIdMap& output ) const {
00394 output.clear();
00395 DcuDetIdsV::const_iterator ii = input.begin();
00396 DcuDetIdsV::const_iterator jj = input.end();
00397 for ( ; ii != jj; ++ii ) { if ( ii->second ) { output[ii->first] = new TkDcuInfo( *(ii->second) ); } }
00398 }
00399
00400
00401
00402 void SiStripConfigDb::clone( const DcuDetIdsV& input, DcuDetIdsV& output ) const {
00403 output.clear();
00404 DcuDetIdsV::const_iterator ii = input.begin();
00405 DcuDetIdsV::const_iterator jj = input.end();
00406 for ( ; ii != jj; ++ii ) { if ( ii->second ) { output.push_back( std::make_pair( ii->first, new TkDcuInfo( *(ii->second) ) ) ); } }
00407 }
00408
00409
00410
00411 SiStripConfigDb::DcuDetIdsV::const_iterator SiStripConfigDb::findDcuDetId( DcuDetIdsV::const_iterator begin,
00412 DcuDetIdsV::const_iterator end,
00413 uint32_t dcu_id ) {
00414 DcuDetIdsV::const_iterator iter = begin;
00415 DcuDetIdsV::const_iterator jter = end;
00416 for ( ; iter != jter; ++iter ) {
00417 if ( iter->second && iter->second->getDcuHardId() == dcu_id ) { return iter; }
00418 }
00419 return end;
00420 }
00421
00422
00423
00424 SiStripConfigDb::DcuDetIdsV::iterator SiStripConfigDb::findDcuDetId( DcuDetIdsV::iterator begin,
00425 DcuDetIdsV::iterator end,
00426 uint32_t dcu_id ) {
00427 DcuDetIdsV::iterator iter = begin;
00428 DcuDetIdsV::iterator jter = end;
00429 for ( ; iter != jter; ++iter ) {
00430 if ( iter->second && iter->second->getDcuHardId() == dcu_id ) { return iter; }
00431 }
00432 return end;
00433 }