File indexing completed on 2023-10-25 09:57:39
0001
0002 #include "OnlineDB/SiStripConfigDb/interface/SiStripConfigDb.h"
0003 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0004
0005 using namespace std;
0006 using namespace sistrip;
0007
0008
0009
0010 SiStripConfigDb::DcuDetIdsRange SiStripConfigDb::getDcuDetIds(std::string partition) {
0011
0012 if ((!dbParams_.usingDbCache() && !deviceFactory(__func__)) ||
0013 (dbParams_.usingDbCache() && !databaseCache(__func__))) {
0014 return dcuDetIds_.emptyRange();
0015 }
0016
0017 try {
0018 if (!dbParams_.usingDbCache()) {
0019 SiStripDbParams::SiStripPartitions::const_iterator iter = dbParams_.partitions().begin();
0020 SiStripDbParams::SiStripPartitions::const_iterator jter = dbParams_.partitions().end();
0021 for (; iter != jter; ++iter) {
0022 if (partition.empty() || partition == iter->second.partitionName()) {
0023 if (iter->second.partitionName() == SiStripPartition::defaultPartitionName_) {
0024 continue;
0025 }
0026
0027 DcuDetIdsRange range = dcuDetIds_.find(iter->second.partitionName());
0028 if (range == dcuDetIds_.emptyRange()) {
0029 deviceFactory(__func__)->addDetIdPartition(
0030 iter->second.partitionName(), iter->second.dcuVersion().first, iter->second.dcuVersion().second);
0031
0032
0033 DcuDetIdMap src = deviceFactory(__func__)->getInfos();
0034
0035
0036 DcuDetIdsV dst;
0037 clone(src, dst);
0038
0039
0040 dcuDetIds_.loadNext(iter->second.partitionName(), dst);
0041 }
0042 }
0043 }
0044
0045 } else {
0046
0047
0048 DcuDetIdMap* src = databaseCache(__func__)->getInfos();
0049
0050 if (src) {
0051
0052 DcuDetIdsV dst;
0053 clone(*src, dst);
0054
0055
0056 dcuDetIds_.loadNext(SiStripPartition::defaultPartitionName_, dst);
0057
0058 } else {
0059 edm::LogWarning(mlConfigDb_) << "[SiStripConfigDb::" << __func__ << "]"
0060 << " NULL pointer to Dcu-DetId map!";
0061 }
0062 }
0063
0064 } catch (...) {
0065 handleException(__func__);
0066 }
0067
0068
0069 uint16_t np = 0;
0070 uint16_t nc = 0;
0071 DcuDetIdsRange range;
0072 if (!partition.empty()) {
0073 range = dcuDetIds_.find(partition);
0074 np = 1;
0075 nc = range.size();
0076 } else {
0077 if (!dcuDetIds_.empty()) {
0078 range = DcuDetIdsRange(dcuDetIds_.find(dbParams_.partitions().begin()->second.partitionName()).begin(),
0079 dcuDetIds_.find((--(dbParams_.partitions().end()))->second.partitionName()).end());
0080 } else {
0081 range = dcuDetIds_.emptyRange();
0082 }
0083 np = dcuDetIds_.size();
0084 nc = range.size();
0085 }
0086
0087 stringstream ss;
0088 ss << "[SiStripConfigDb::" << __func__ << "]"
0089 << " Found " << nc << " entries in DCU-DetId map";
0090 if (!dbParams_.usingDb()) {
0091 ss << " in " << dbParams_.inputDcuInfoXmlFiles().size() << " 'module.xml' file(s)";
0092 } else {
0093 if (!dbParams_.usingDbCache()) {
0094 ss << " in " << np << " database partition(s)";
0095 } else {
0096 ss << " from shared memory name '" << dbParams_.sharedMemory() << "'";
0097 }
0098 }
0099 if (dcuDetIds_.empty()) {
0100 edm::LogWarning(mlConfigDb_) << ss.str();
0101 } else {
0102 LogTrace(mlConfigDb_) << ss.str();
0103 }
0104
0105 return range;
0106 }
0107
0108
0109
0110 void SiStripConfigDb::addDcuDetIds(std::string partition, DcuDetIdsV& dcus) {
0111 stringstream ss;
0112 ss << "[SiStripConfigDb::" << __func__ << "]"
0113 << " Cannot add to local cache! This functionality not allowed!";
0114 edm::LogWarning(mlConfigDb_) << ss.str();
0115
0116
0117
0118
0119
0120
0121
0122
0123
0124
0125
0126
0127
0128
0129
0130
0131
0132
0133
0134
0135
0136
0137
0138
0139
0140
0141
0142
0143
0144
0145
0146
0147
0148
0149
0150
0151
0152
0153
0154
0155
0156
0157
0158
0159
0160
0161
0162
0163
0164
0165
0166
0167
0168
0169
0170
0171
0172
0173
0174
0175
0176
0177
0178
0179 }
0180
0181
0182
0183 void SiStripConfigDb::uploadDcuDetIds(std::string partition) {
0184 stringstream ss;
0185 ss << "[SiStripConfigDb::" << __func__ << "]"
0186 << " Cannot upload to database! This functionality not allowed!";
0187 edm::LogWarning(mlConfigDb_) << ss.str();
0188
0189
0190
0191
0192
0193
0194
0195
0196
0197
0198
0199
0200
0201
0202
0203
0204
0205
0206
0207
0208
0209
0210
0211
0212
0213
0214
0215
0216
0217
0218
0219
0220
0221
0222
0223
0224
0225
0226
0227
0228
0229
0230
0231
0232
0233
0234
0235
0236
0237
0238
0239
0240
0241
0242
0243
0244
0245
0246
0247
0248
0249
0250
0251
0252
0253
0254
0255
0256
0257
0258
0259
0260
0261
0262
0263
0264
0265
0266 }
0267
0268
0269
0270 void SiStripConfigDb::clearDcuDetIds(std::string partition) {
0271 LogTrace(mlConfigDb_) << "[SiStripConfigDb::" << __func__ << "]";
0272
0273 if (dcuDetIds_.empty()) {
0274 stringstream ss;
0275 ss << "[SiStripConfigDb::" << __func__ << "]"
0276 << " Found no cached DCU-DetId map!";
0277
0278 return;
0279 }
0280
0281
0282 DcuDetIds temporary_cache;
0283 if (partition.empty()) {
0284 temporary_cache = DcuDetIds();
0285 } else {
0286 SiStripDbParams::SiStripPartitions::const_iterator iter = dbParams_.partitions().begin();
0287 SiStripDbParams::SiStripPartitions::const_iterator jter = dbParams_.partitions().end();
0288 for (; iter != jter; ++iter) {
0289 if (partition != iter->second.partitionName()) {
0290 DcuDetIdsRange range = dcuDetIds_.find(iter->second.partitionName());
0291 if (range != dcuDetIds_.emptyRange()) {
0292 temporary_cache.loadNext(partition, DcuDetIdsV(range.begin(), range.end()));
0293 } else {
0294
0295
0296
0297
0298
0299 }
0300 }
0301 }
0302 }
0303
0304
0305 DcuDetIdsRange dcus;
0306 if (partition.empty()) {
0307 if (!dcuDetIds_.empty()) {
0308 dcus = DcuDetIdsRange(dcuDetIds_.find(dbParams_.partitions().begin()->second.partitionName()).begin(),
0309 dcuDetIds_.find((--(dbParams_.partitions().end()))->second.partitionName()).end());
0310 } else {
0311 dcus = dcuDetIds_.emptyRange();
0312 }
0313 } else {
0314 SiStripDbParams::SiStripPartitions::const_iterator iter = dbParams_.partitions().begin();
0315 SiStripDbParams::SiStripPartitions::const_iterator jter = dbParams_.partitions().end();
0316 for (; iter != jter; ++iter) {
0317 if (partition == iter->second.partitionName()) {
0318 break;
0319 }
0320 }
0321 dcus = dcuDetIds_.find(iter->second.partitionName());
0322 }
0323
0324 if (dcus != dcuDetIds_.emptyRange()) {
0325 DcuDetIdsV::const_iterator ifed = dcus.begin();
0326 DcuDetIdsV::const_iterator jfed = dcus.end();
0327 for (; ifed != jfed; ++ifed) {
0328 if (ifed->second) {
0329 delete ifed->second;
0330 }
0331 }
0332 } else {
0333 stringstream ss;
0334 ss << "[SiStripConfigDb::" << __func__ << "]";
0335 if (partition.empty()) {
0336 ss << " Found no DCU-DetId map in local cache!";
0337 } else {
0338 ss << " Found no DCU-DetId map in local cache for partition \"" << partition << "\"!";
0339 }
0340 edm::LogWarning(mlConfigDb_) << ss.str();
0341 }
0342
0343
0344 dcuDetIds_ = temporary_cache;
0345 }
0346
0347
0348
0349 void SiStripConfigDb::printDcuDetIds(std::string partition) {
0350 std::stringstream ss;
0351 ss << "[SiStripConfigDb::" << __func__ << "]"
0352 << " Contents of DcuDetIds container:" << std::endl;
0353 ss << " Number of partitions: " << dcuDetIds_.size() << std::endl;
0354
0355
0356 uint16_t cntr = 0;
0357 DcuDetIds::const_iterator idcu = dcuDetIds_.begin();
0358 DcuDetIds::const_iterator jdcu = dcuDetIds_.end();
0359 for (; idcu != jdcu; ++idcu) {
0360 cntr++;
0361 if (partition.empty() || partition == idcu->first) {
0362 ss << " Partition number : " << cntr << " (out of " << dcuDetIds_.size() << ")" << std::endl;
0363 ss << " Partition name : \"" << idcu->first << "\"" << std::endl;
0364 ss << " Size of DCU-DetId map : " << idcu->second.size() << std::endl;
0365 }
0366 }
0367
0368 LogTrace(mlConfigDb_) << ss.str();
0369 }
0370
0371
0372
0373 void SiStripConfigDb::clone(const DcuDetIdMap& input, DcuDetIdsV& output) const {
0374 output.clear();
0375 DcuDetIdMap::const_iterator ii = input.begin();
0376 DcuDetIdMap::const_iterator jj = input.end();
0377 for (; ii != jj; ++ii) {
0378 if (ii->second) {
0379 output.push_back(std::make_pair(ii->first, new TkDcuInfo(*(ii->second))));
0380 }
0381 }
0382 }
0383
0384
0385
0386 void SiStripConfigDb::clone(const DcuDetIdsV& input, DcuDetIdMap& output) const {
0387 output.clear();
0388 DcuDetIdsV::const_iterator ii = input.begin();
0389 DcuDetIdsV::const_iterator jj = input.end();
0390 for (; ii != jj; ++ii) {
0391 if (ii->second) {
0392 output[ii->first] = new TkDcuInfo(*(ii->second));
0393 }
0394 }
0395 }
0396
0397
0398
0399 void SiStripConfigDb::clone(const DcuDetIdsV& input, DcuDetIdsV& output) const {
0400 output.clear();
0401 DcuDetIdsV::const_iterator ii = input.begin();
0402 DcuDetIdsV::const_iterator jj = input.end();
0403 for (; ii != jj; ++ii) {
0404 if (ii->second) {
0405 output.push_back(std::make_pair(ii->first, new TkDcuInfo(*(ii->second))));
0406 }
0407 }
0408 }
0409
0410
0411
0412 SiStripConfigDb::DcuDetIdsV::const_iterator SiStripConfigDb::findDcuDetId(DcuDetIdsV::const_iterator begin,
0413 DcuDetIdsV::const_iterator end,
0414 uint32_t dcu_id) {
0415 DcuDetIdsV::const_iterator iter = begin;
0416 DcuDetIdsV::const_iterator jter = end;
0417 for (; iter != jter; ++iter) {
0418 if (iter->second && iter->second->getDcuHardId() == dcu_id) {
0419 return iter;
0420 }
0421 }
0422 return end;
0423 }
0424
0425
0426
0427 SiStripConfigDb::DcuDetIdsV::iterator SiStripConfigDb::findDcuDetId(DcuDetIdsV::iterator begin,
0428 DcuDetIdsV::iterator end,
0429 uint32_t dcu_id) {
0430 DcuDetIdsV::iterator iter = begin;
0431 DcuDetIdsV::iterator jter = end;
0432 for (; iter != jter; ++iter) {
0433 if (iter->second && iter->second->getDcuHardId() == dcu_id) {
0434 return iter;
0435 }
0436 }
0437 return end;
0438 }