Go to the documentation of this file.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 deviceFactory(__func__)->addDetIdPartition( iter->second.partitionName(),
00035 iter->second.dcuVersion().first,
00036 iter->second.dcuVersion().second );
00037
00038
00039 DcuDetIdMap src = deviceFactory(__func__)->getInfos();
00040
00041
00042 DcuDetIdsV dst;
00043 clone( src, dst );
00044
00045
00046 dcuDetIds_.loadNext( iter->second.partitionName(), dst );
00047
00048 }
00049
00050 }
00051
00052 }
00053
00054 } else {
00055
00056
00057 DcuDetIdMap* src = databaseCache(__func__)->getInfos();
00058
00059 if ( src ) {
00060
00061
00062 DcuDetIdsV dst;
00063 clone( *src, dst );
00064
00065
00066 dcuDetIds_.loadNext( SiStripPartition::defaultPartitionName_, dst );
00067
00068 } else {
00069 edm::LogWarning(mlConfigDb_)
00070 << "[SiStripConfigDb::" << __func__ << "]"
00071 << " NULL pointer to Dcu-DetId map!";
00072 }
00073
00074 }
00075
00076 } catch (... ) { handleException( __func__ ); }
00077
00078
00079 uint16_t np = 0;
00080 uint16_t nc = 0;
00081 DcuDetIdsRange range;
00082 if ( partition != "" ) {
00083 range = dcuDetIds_.find( partition );
00084 np = 1;
00085 nc = range.size();
00086 } else {
00087 if ( !dcuDetIds_.empty() ) {
00088 range = DcuDetIdsRange( dcuDetIds_.find( dbParams_.partitions().begin()->second.partitionName() ).begin(),
00089 dcuDetIds_.find( (--(dbParams_.partitions().end()))->second.partitionName() ).end() );
00090 } else { range = dcuDetIds_.emptyRange(); }
00091 np = dcuDetIds_.size();
00092 nc = range.size();
00093 }
00094
00095 stringstream ss;
00096 ss << "[SiStripConfigDb::" << __func__ << "]"
00097 << " Found " << nc << " entries in DCU-DetId map";
00098 if ( !dbParams_.usingDb() ) { ss << " in " << dbParams_.inputDcuInfoXmlFiles().size() << " 'module.xml' file(s)"; }
00099 else { if ( !dbParams_.usingDbCache() ) { ss << " in " << np << " database partition(s)"; }
00100 else { ss << " from shared memory name '" << dbParams_.sharedMemory() << "'"; } }
00101 if ( dcuDetIds_.empty() ) { edm::LogWarning(mlConfigDb_) << ss.str(); }
00102 else { LogTrace(mlConfigDb_) << ss.str(); }
00103
00104 return range;
00105 }
00106
00107
00108
00109 void SiStripConfigDb::addDcuDetIds( std::string partition, DcuDetIdsV& dcus ) {
00110
00111 stringstream ss;
00112 ss << "[SiStripConfigDb::" << __func__ << "]"
00113 << " Cannot add to local cache! This functionality not allowed!";
00114 edm::LogWarning(mlConfigDb_) << ss.str();
00115
00116
00117
00118
00119
00120
00121
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 void SiStripConfigDb::uploadDcuDetIds( std::string partition ) {
00185
00186 stringstream ss;
00187 ss << "[SiStripConfigDb::" << __func__ << "]"
00188 << " Cannot upload to database! This functionality not allowed!";
00189 edm::LogWarning(mlConfigDb_) << ss.str();
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
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 void SiStripConfigDb::clearDcuDetIds( std::string partition ) {
00274 LogTrace(mlConfigDb_) << "[SiStripConfigDb::" << __func__ << "]";
00275
00276 if ( dcuDetIds_.empty() ) {
00277 stringstream ss;
00278 ss << "[SiStripConfigDb::" << __func__ << "]"
00279 << " Found no cached DCU-DetId map!";
00280
00281 return;
00282 }
00283
00284
00285 DcuDetIds temporary_cache;
00286 if ( partition == "" ) { temporary_cache = DcuDetIds(); }
00287 else {
00288 SiStripDbParams::SiStripPartitions::const_iterator iter = dbParams_.partitions().begin();
00289 SiStripDbParams::SiStripPartitions::const_iterator jter = dbParams_.partitions().end();
00290 for ( ; iter != jter; ++iter ) {
00291 if ( partition != iter->second.partitionName() ) {
00292 DcuDetIdsRange range = dcuDetIds_.find( iter->second.partitionName() );
00293 if ( range != dcuDetIds_.emptyRange() ) {
00294 temporary_cache.loadNext( partition, DcuDetIdsV( range.begin(), range.end() ) );
00295 } else {
00296
00297
00298
00299
00300
00301 }
00302 }
00303 }
00304 }
00305
00306
00307 DcuDetIdsRange dcus;
00308 if ( partition == "" ) {
00309 if ( !dcuDetIds_.empty() ) {
00310 dcus = DcuDetIdsRange( dcuDetIds_.find( dbParams_.partitions().begin()->second.partitionName() ).begin(),
00311 dcuDetIds_.find( (--(dbParams_.partitions().end()))->second.partitionName() ).end() );
00312 } else { dcus = dcuDetIds_.emptyRange(); }
00313 } else {
00314 SiStripDbParams::SiStripPartitions::const_iterator iter = dbParams_.partitions().begin();
00315 SiStripDbParams::SiStripPartitions::const_iterator jter = dbParams_.partitions().end();
00316 for ( ; iter != jter; ++iter ) { if ( partition == iter->second.partitionName() ) { break; } }
00317 dcus = dcuDetIds_.find( iter->second.partitionName() );
00318 }
00319
00320 if ( dcus != dcuDetIds_.emptyRange() ) {
00321 DcuDetIdsV::const_iterator ifed = dcus.begin();
00322 DcuDetIdsV::const_iterator jfed = dcus.end();
00323 for ( ; ifed != jfed; ++ifed ) { if ( ifed->second ) { delete ifed->second; } }
00324 } else {
00325 stringstream ss;
00326 ss << "[SiStripConfigDb::" << __func__ << "]";
00327 if ( partition == "" ) { ss << " Found no DCU-DetId map in local cache!"; }
00328 else { ss << " Found no DCU-DetId map in local cache for partition \"" << partition << "\"!"; }
00329 edm::LogWarning(mlConfigDb_) << ss.str();
00330 }
00331
00332
00333 dcuDetIds_ = temporary_cache;
00334
00335 }
00336
00337
00338
00339 void SiStripConfigDb::printDcuDetIds( std::string partition ) {
00340
00341 std::stringstream ss;
00342 ss << "[SiStripConfigDb::" << __func__ << "]"
00343 << " Contents of DcuDetIds container:" << std::endl;
00344 ss << " Number of partitions: " << dcuDetIds_.size() << std::endl;
00345
00346
00347 uint16_t cntr = 0;
00348 DcuDetIds::const_iterator idcu = dcuDetIds_.begin();
00349 DcuDetIds::const_iterator jdcu = dcuDetIds_.end();
00350 for ( ; idcu != jdcu; ++idcu ) {
00351
00352 cntr++;
00353 if ( partition == "" || partition == idcu->first ) {
00354
00355 ss << " Partition number : " << cntr << " (out of " << dcuDetIds_.size() << ")" << std::endl;
00356 ss << " Partition name : \"" << idcu->first << "\"" << std::endl;
00357 ss << " Size of DCU-DetId map : " << idcu->second.size() << std::endl;
00358
00359 }
00360
00361 }
00362
00363 LogTrace(mlConfigDb_) << ss.str();
00364
00365 }
00366
00367
00368
00369 void SiStripConfigDb::clone( const DcuDetIdMap& input, DcuDetIdsV& output ) const {
00370 output.clear();
00371 DcuDetIdMap::const_iterator ii = input.begin();
00372 DcuDetIdMap::const_iterator jj = input.end();
00373 for ( ; ii != jj; ++ii ) { if ( ii->second ) { output.push_back( std::make_pair( ii->first, new TkDcuInfo( *(ii->second) ) ) ); } }
00374 }
00375
00376
00377
00378 void SiStripConfigDb::clone( const DcuDetIdsV& input, DcuDetIdMap& output ) const {
00379 output.clear();
00380 DcuDetIdsV::const_iterator ii = input.begin();
00381 DcuDetIdsV::const_iterator jj = input.end();
00382 for ( ; ii != jj; ++ii ) { if ( ii->second ) { output[ii->first] = new TkDcuInfo( *(ii->second) ); } }
00383 }
00384
00385
00386
00387 void SiStripConfigDb::clone( const DcuDetIdsV& input, DcuDetIdsV& output ) const {
00388 output.clear();
00389 DcuDetIdsV::const_iterator ii = input.begin();
00390 DcuDetIdsV::const_iterator jj = input.end();
00391 for ( ; ii != jj; ++ii ) { if ( ii->second ) { output.push_back( std::make_pair( ii->first, new TkDcuInfo( *(ii->second) ) ) ); } }
00392 }
00393
00394
00395
00396 SiStripConfigDb::DcuDetIdsV::const_iterator SiStripConfigDb::findDcuDetId( DcuDetIdsV::const_iterator begin,
00397 DcuDetIdsV::const_iterator end,
00398 uint32_t dcu_id ) {
00399 DcuDetIdsV::const_iterator iter = begin;
00400 DcuDetIdsV::const_iterator jter = end;
00401 for ( ; iter != jter; ++iter ) {
00402 if ( iter->second && iter->second->getDcuHardId() == dcu_id ) { return iter; }
00403 }
00404 return end;
00405 }
00406
00407
00408
00409 SiStripConfigDb::DcuDetIdsV::iterator SiStripConfigDb::findDcuDetId( DcuDetIdsV::iterator begin,
00410 DcuDetIdsV::iterator end,
00411 uint32_t dcu_id ) {
00412 DcuDetIdsV::iterator iter = begin;
00413 DcuDetIdsV::iterator jter = end;
00414 for ( ; iter != jter; ++iter ) {
00415 if ( iter->second && iter->second->getDcuHardId() == dcu_id ) { return iter; }
00416 }
00417 return end;
00418 }