CMS 3D CMS Logo

FedDescriptions.cc
Go to the documentation of this file.
1 
6 
7 using namespace std;
8 using namespace sistrip;
9 
10 // -----------------------------------------------------------------------------
11 //
13  // Check
14  if ((!dbParams_.usingDbCache() && !deviceFactory(__func__)) ||
15  (dbParams_.usingDbCache() && !databaseCache(__func__))) {
16  return feds_.emptyRange();
17  }
18 
19  try {
20  if (!dbParams_.usingDbCache()) {
21  SiStripDbParams::SiStripPartitions::const_iterator iter = dbParams_.partitions().begin();
22  SiStripDbParams::SiStripPartitions::const_iterator jter = dbParams_.partitions().end();
23  for (; iter != jter; ++iter) {
24  if (partition.empty() || partition == iter->second.partitionName()) {
25  if (iter->second.partitionName() == SiStripPartition::defaultPartitionName_) {
26  continue;
27  }
28 
29  FedDescriptionsRange range = feds_.find(iter->second.partitionName());
30  if (range == feds_.emptyRange()) {
31  // Extract versions
32  deviceFactory(__func__)->setUsingStrips(usingStrips_);
33  int16_t major = iter->second.fedVersion().first;
34  int16_t minor = iter->second.fedVersion().second;
35  if (iter->second.fedVersion().first == 0 && iter->second.fedVersion().second == 0) {
36  major = -1; //@@ "current state" for fed factory!
37  minor = -1; //@@ "current state" for fed factory!
38  }
39 
40  // Retrive FED descriptions
41  FedDescriptionsV tmp1;
42  tmp1 = *(deviceFactory(__func__)->getFed9UDescriptions(iter->second.partitionName(), major, minor));
43 
44  // Make local copy
45  FedDescriptionsV tmp2;
46  Fed9U::Fed9UDeviceFactory::vectorCopy(tmp2, tmp1);
47 
48  // Add to cache
49  feds_.loadNext(iter->second.partitionName(), tmp2);
50 
51  // Some debug
52  FedDescriptionsRange feds = feds_.find(iter->second.partitionName());
53  std::stringstream ss;
54  ss << "[SiStripConfigDb::" << __func__ << "]"
55  << " Downloaded " << feds.size() << " FED descriptions to local cache for partition \""
56  << iter->second.partitionName() << "\"" << std::endl;
57  ss << "[SiStripConfigDb::" << __func__ << "]"
58  << " Cache holds FED descriptions for " << feds_.size() << " partitions.";
59  LogTrace(mlConfigDb_) << ss.str();
60  }
61  }
62  }
63 
64  } else { // Using database cache
65 
66  FedDescriptionsV* tmp1 = databaseCache(__func__)->getFed9UDescriptions();
67 
68  if (tmp1) {
69  // Make local copy
70  FedDescriptionsV tmp2;
71  Fed9U::Fed9UDeviceFactory::vectorCopy(tmp2, *tmp1);
72 
73  // Add to cache
74  feds_.loadNext(SiStripPartition::defaultPartitionName_, tmp2);
75 
76  } else {
77  edm::LogWarning(mlConfigDb_) << "[SiStripConfigDb::" << __func__ << "]"
78  << " NULL pointer to FED descriptions vector!";
79  }
80  }
81 
82  } catch (...) {
83  handleException(__func__);
84  }
85 
86  // Create range object
87  uint16_t np = 0;
88  uint16_t nc = 0;
90  if (!partition.empty()) {
91  feds = feds_.find(partition);
92  np = 1;
93  nc = feds.size();
94  } else {
95  if (!feds_.empty()) {
96  feds = FedDescriptionsRange(feds_.find(dbParams_.partitions().begin()->second.partitionName()).begin(),
97  feds_.find((--(dbParams_.partitions().end()))->second.partitionName()).end());
98  } else {
99  feds = feds_.emptyRange();
100  }
101  np = feds_.size();
102  nc = feds.size();
103  }
104 
105  stringstream ss;
106  ss << "[SiStripConfigDb::" << __func__ << "]"
107  << " Found " << nc << " FED descriptions";
108  if (!dbParams_.usingDb()) {
109  ss << " in " << dbParams_.inputFedXmlFiles().size() << " 'fed.xml' file(s)";
110  } else {
111  if (!dbParams_.usingDbCache()) {
112  ss << " in " << np << " database partition(s)";
113  } else {
114  ss << " from shared memory name '" << dbParams_.sharedMemory() << "'";
115  }
116  }
117  if (feds_.empty()) {
118  edm::LogWarning(mlConfigDb_) << ss.str();
119  } else {
120  LogTrace(mlConfigDb_) << ss.str();
121  }
122 
123  return feds;
124 }
125 
126 // -----------------------------------------------------------------------------
127 //
129  if (!deviceFactory(__func__)) {
130  return;
131  }
132 
133  if (partition.empty()) {
134  stringstream ss;
135  ss << "[SiStripConfigDb::" << __func__ << "]"
136  << " Partition string is empty,"
137  << " therefore cannot add FED descriptions to local cache!";
138  edm::LogWarning(mlConfigDb_) << ss.str();
139  return;
140  }
141 
142  if (feds.empty()) {
143  stringstream ss;
144  ss << "[SiStripConfigDb::" << __func__ << "]"
145  << " Vector of FED descriptions is empty,"
146  << " therefore cannot add FED descriptions to local cache!";
147  edm::LogWarning(mlConfigDb_) << ss.str();
148  return;
149  }
150 
151  SiStripDbParams::SiStripPartitions::const_iterator iter = dbParams_.partitions().begin();
152  SiStripDbParams::SiStripPartitions::const_iterator jter = dbParams_.partitions().end();
153  for (; iter != jter; ++iter) {
154  if (partition == iter->second.partitionName()) {
155  break;
156  }
157  }
158  if (iter == dbParams_.partitions().end()) {
159  stringstream ss;
160  ss << "[SiStripConfigDb::" << __func__ << "]"
161  << " Partition \"" << partition << "\" not found in partition list, "
162  << " therefore cannot add FED descriptions!";
163  edm::LogWarning(mlConfigDb_) << ss.str();
164  return;
165  }
166 
167  FedDescriptionsRange range = feds_.find(partition);
168  if (range == feds_.emptyRange()) {
169  // Make local copy
171  Fed9U::Fed9UDeviceFactory::vectorCopy(tmp, feds);
172 
173  // Add to local cache
174  feds_.loadNext(partition, tmp);
175 
176  // Some debug
177  std::stringstream ss;
178  ss << "[SiStripConfigDb::" << __func__ << "]"
179  << " Added " << feds.size() << " FED descriptions to local cache for partition \""
180  << iter->second.partitionName() << "\"" << std::endl;
181  ss << "[SiStripConfigDb::" << __func__ << "]"
182  << " Cache holds FED descriptions for " << feds_.size() << " partitions.";
183  LogTrace(mlConfigDb_) << ss.str();
184 
185  } else {
186  stringstream ss;
187  ss << "[SiStripConfigDb::" << __func__ << "]"
188  << " Partition \"" << partition << "\" already found in local cache, "
189  << " therefore cannot add new FED descriptions!";
190  edm::LogWarning(mlConfigDb_) << ss.str();
191  return;
192  }
193 }
194 
195 // -----------------------------------------------------------------------------
196 //
198  if (dbParams_.usingDbCache()) {
199  edm::LogWarning(mlConfigDb_) << "[SiStripConfigDb::" << __func__ << "]"
200  << " Using database cache! No uploads allowed!";
201  return;
202  }
203 
204  if (!deviceFactory(__func__)) {
205  return;
206  }
207 
208  if (feds_.empty()) {
209  stringstream ss;
210  ss << "[SiStripConfigDb::" << __func__ << "]"
211  << " Found no cached FED descriptions, therefore no upload!";
212  edm::LogWarning(mlConfigDb_) << ss.str();
213  return;
214  }
215 
216  try {
217  SiStripDbParams::SiStripPartitions::const_iterator iter = dbParams_.partitions().begin();
218  SiStripDbParams::SiStripPartitions::const_iterator jter = dbParams_.partitions().end();
219  for (; iter != jter; ++iter) {
220  if (partition.empty() || partition == iter->second.partitionName()) {
221  FedDescriptionsRange range = feds_.find(iter->second.partitionName());
222  if (range != feds_.emptyRange()) {
223  FedDescriptionsV feds(range.begin(), range.end());
224 
225  SiStripPartition::Versions fedVersion = iter->second.fedVersion();
226  deviceFactory(__func__)->setFed9UDescriptions(feds,
227  iter->second.partitionName(),
228  (uint16_t*)(&(fedVersion.first)),
229  (uint16_t*)(&(fedVersion.second)),
230  1); // new major version
231 
232  // Some debug
233  std::stringstream ss;
234  ss << "[SiStripConfigDb::" << __func__ << "]"
235  << " Uploaded " << feds.size() << " FED descriptions to database for partition \""
236  << iter->second.partitionName() << "\"";
237  LogTrace(mlConfigDb_) << ss.str();
238 
239  } else {
240  stringstream ss;
241  ss << "[SiStripConfigDb::" << __func__ << "]"
242  << " Vector of FED descriptions is empty for partition \"" << iter->second.partitionName()
243  << "\", therefore aborting upload for this partition!";
244  edm::LogWarning(mlConfigDb_) << ss.str();
245  continue;
246  }
247 
248  } else {
249  // stringstream ss;
250  // ss << "[SiStripConfigDb::" << __func__ << "]"
251  // << " Cannot find partition \"" << partition
252  // << "\" in cached partitions list: \""
253  // << dbParams_.partitionNames( dbParams_.partitionNames() )
254  // << "\", therefore aborting upload for this partition!";
255  // edm::LogWarning(mlConfigDb_) << ss.str();
256  }
257  }
258 
259  } catch (...) {
260  handleException(__func__);
261  }
262 
263  allowCalibUpload_ = true;
264 }
265 
266 // -----------------------------------------------------------------------------
267 //
269  LogTrace(mlConfigDb_) << "[SiStripConfigDb::" << __func__ << "]";
270 
271  if (feds_.empty()) {
272  stringstream ss;
273  ss << "[SiStripConfigDb::" << __func__ << "]"
274  << " Found no cached FED descriptions!";
275  //edm::LogWarning(mlConfigDb_) << ss.str();
276  return;
277  }
278 
279  // Reproduce temporary cache for "all partitions except specified one" (or clear all if none specified)
280  FedDescriptions temporary_cache;
281  if (partition.empty()) {
282  temporary_cache = FedDescriptions();
283  } else {
284  SiStripDbParams::SiStripPartitions::const_iterator iter = dbParams_.partitions().begin();
285  SiStripDbParams::SiStripPartitions::const_iterator jter = dbParams_.partitions().end();
286  for (; iter != jter; ++iter) {
287  if (partition != iter->second.partitionName()) {
288  FedDescriptionsRange range = feds_.find(iter->second.partitionName());
289  if (range != feds_.emptyRange()) {
290  temporary_cache.loadNext(partition, FedDescriptionsV(range.begin(), range.end()));
291  }
292  } else {
293  FedDescriptionsRange range = feds_.find(iter->second.partitionName());
294  if (range != feds_.emptyRange()) {
295  LogTrace(mlConfigDb_) << "[SiStripConfigDb::" << __func__ << "]"
296  << " Deleting FED descriptions for partition \"" << iter->second.partitionName()
297  << "\" from local cache...";
298  }
299  }
300  }
301  }
302 
303  // Delete objects in local cache for specified partition (or all if not specified)
305  if (partition.empty()) {
306  if (!feds_.empty()) {
307  feds = FedDescriptionsRange(feds_.find(dbParams_.partitions().begin()->second.partitionName()).begin(),
308  feds_.find((--(dbParams_.partitions().end()))->second.partitionName()).end());
309  } else {
310  feds = feds_.emptyRange();
311  }
312  } else {
313  SiStripDbParams::SiStripPartitions::const_iterator iter = dbParams_.partitions().begin();
314  SiStripDbParams::SiStripPartitions::const_iterator jter = dbParams_.partitions().end();
315  for (; iter != jter; ++iter) {
316  if (partition == iter->second.partitionName()) {
317  break;
318  }
319  }
320  feds = feds_.find(iter->second.partitionName());
321  }
322 
323  if (feds != feds_.emptyRange()) {
324  FedDescriptionsV::const_iterator ifed = feds.begin();
325  FedDescriptionsV::const_iterator jfed = feds.end();
326  for (; ifed != jfed; ++ifed) {
327  if (*ifed) {
328  delete *ifed;
329  }
330  }
331  } else {
332  stringstream ss;
333  ss << "[SiStripConfigDb::" << __func__ << "]";
334  if (partition.empty()) {
335  ss << " Found no FED descriptions in local cache!";
336  } else {
337  ss << " Found no FED descriptions in local cache for partition \"" << partition << "\"!";
338  }
339  edm::LogWarning(mlConfigDb_) << ss.str();
340  }
341 
342  // Overwrite local cache with temporary cache
343  feds_ = temporary_cache;
344 }
345 
346 // -----------------------------------------------------------------------------
347 //
349  std::stringstream ss;
350  ss << "[SiStripConfigDb::" << __func__ << "]"
351  << " Contents of FedDescriptions container:" << std::endl;
352  ss << " Number of partitions: " << feds_.size() << std::endl;
353 
354  // Loop through partitions
355  uint16_t cntr = 0;
356  FedDescriptions::const_iterator iconn = feds_.begin();
357  FedDescriptions::const_iterator jconn = feds_.end();
358  for (; iconn != jconn; ++iconn) {
359  cntr++;
360  if (partition.empty() || partition == iconn->first) {
361  ss << " Partition number : " << cntr << " (out of " << feds_.size() << ")" << std::endl;
362  ss << " Partition name : \"" << iconn->first << "\"" << std::endl;
363  ss << " Num of FED ids : " << iconn->second.size() << std::endl;
364 
365  // Extract FED crates and ids
366  std::map<uint16_t, vector<uint16_t> > feds;
367  FedDescriptionsV::const_iterator iter = iconn->second.begin();
368  FedDescriptionsV::const_iterator jter = iconn->second.end();
369  for (; iter != jter; ++iter) {
370  if (*iter) {
371  uint16_t key = (*iter)->getCrateNumber();
372  uint16_t data = (*iter)->getFedId();
373  if (find(feds[key].begin(), feds[key].end(), data) == feds[key].end()) {
374  feds[key].push_back(data);
375  }
376  }
377  }
378 
379  // Sort contents
380  std::map<uint16_t, std::vector<uint16_t> > tmp;
381  std::map<uint16_t, std::vector<uint16_t> >::const_iterator ii = feds.begin();
382  std::map<uint16_t, std::vector<uint16_t> >::const_iterator jj = feds.end();
383  for (; ii != jj; ++ii) {
384  std::vector<uint16_t> temp = ii->second;
385  std::sort(temp.begin(), temp.end());
386  std::vector<uint16_t>::const_iterator iii = temp.begin();
387  std::vector<uint16_t>::const_iterator jjj = temp.end();
388  for (; iii != jjj; ++iii) {
389  tmp[ii->first].push_back(*iii);
390  }
391  }
392  feds.clear();
393  feds = tmp;
394 
395  // Print FED crates and ids
396  std::map<uint16_t, std::vector<uint16_t> >::const_iterator ifed = feds.begin();
397  std::map<uint16_t, std::vector<uint16_t> >::const_iterator jfed = feds.end();
398  for (; ifed != jfed; ++ifed) {
399  ss << " Found " << std::setw(2) << ifed->second.size() << " FED ids for crate number " << std::setw(2)
400  << ifed->first << " : ";
401  if (!ifed->second.empty()) {
402  uint16_t first = ifed->second.front();
403  uint16_t last = ifed->second.front();
404  std::vector<uint16_t>::const_iterator icrate = ifed->second.begin();
405  std::vector<uint16_t>::const_iterator jcrate = ifed->second.end();
406  for (; icrate != jcrate; ++icrate) {
407  if (icrate != ifed->second.begin()) {
408  if (*icrate != last + 1) {
409  ss << std::setw(2) << first << "->" << std::setw(2) << last << ", ";
410  if (icrate != ifed->second.end()) {
411  first = *(icrate + 1);
412  }
413  }
414  }
415  last = *icrate;
416  }
417  if (first != last) {
418  ss << std::setw(2) << first << "->" << std::setw(2) << last;
419  }
420  ss << std::endl;
421  }
422  }
423  }
424  }
425 
426  LogTrace(mlConfigDb_) << ss.str();
427 }
428 
429 // -----------------------------------------------------------------------------
432  fedIds_.clear();
433 
434  if ((!dbParams_.usingDbCache() && !deviceFactory(__func__)) ||
435  (dbParams_.usingDbCache() && !databaseCache(__func__))) {
436  return FedIdsRange(fedIds_.end(), fedIds_.end());
437  }
438 
439  try {
440  // Inhibit download of strip info
441  bool using_strips = usingStrips_;
442  if (factory_) {
443  factory_->setUsingStrips(false);
444  }
445  FedDescriptionsRange feds = getFedDescriptions(partition);
446  if (factory_) {
447  factory_->setUsingStrips(using_strips);
448  }
449 
450  if (!feds.empty()) {
451  FedDescriptionsV::const_iterator ifed = feds.begin();
452  FedDescriptionsV::const_iterator jfed = feds.end();
453  for (; ifed != jfed; ++ifed) {
454  if (*ifed) {
455  fedIds_.push_back((*ifed)->getFedId());
456  } else {
457  edm::LogError(mlCabling_) << "[SiStripConfigDb::" << __func__ << "]"
458  << " NULL pointer to FedDescription!";
459  continue;
460  }
461  }
462  }
463 
464  } catch (...) {
465  handleException(__func__);
466  }
467 
468  if (fedIds_.empty()) {
469  edm::LogWarning(mlConfigDb_) << "[SiStripConfigDb::" << __func__ << "]"
470  << " No FED ids found!";
471  }
472 
473  return FedIdsRange(fedIds_.begin(), fedIds_.end());
474 }
l1tstage2emulator_dqm_sourceclient-live_cfg.feds
feds
Definition: l1tstage2emulator_dqm_sourceclient-live_cfg.py:153
FastTimerService_cff.range
range
Definition: FastTimerService_cff.py:34
MessageLogger.h
SiStripConfigDb::getFedDescriptions
FedDescriptionsRange getFedDescriptions(std::string partition="")
Definition: FedDescriptions.cc:12
SiStripConfigDb::uploadFedDescriptions
void uploadFedDescriptions(std::string partition="")
Definition: FedDescriptions.cc:197
np
int np
Definition: AMPTWrapper.h:43
SiStripFedCabling.h
SiStripConfigDb::printFedDescriptions
void printFedDescriptions(std::string partition="")
Definition: FedDescriptions.cc:348
SiStripConfigDb::addFedDescriptions
void addFedDescriptions(std::string partition, FedDescriptionsV &)
Definition: FedDescriptions.cc:128
spr::find
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
createJobs.tmp
tmp
align.sh
Definition: createJobs.py:716
groupFilesInBlocks.temp
list temp
Definition: groupFilesInBlocks.py:142
edm::LogWarning
Log< level::Warning, false > LogWarning
Definition: MessageLogger.h:122
SiStripConfigDb::FedDescriptionsV
std::vector< FedDescription * > FedDescriptionsV
Definition: SiStripConfigDb.h:117
SiStripConfigDb::clearFedDescriptions
void clearFedDescriptions(std::string partition="")
Definition: FedDescriptions.cc:268
sistrip::mlConfigDb_
static const char mlConfigDb_[]
Definition: ConstantsForLogger.h:16
contentValuesCheck.ss
ss
Definition: contentValuesCheck.py:33
SiStripConfigDb::FedDescriptionsRange
FedDescriptions::range FedDescriptionsRange
Definition: SiStripConfigDb.h:116
dqmdumpme.last
last
Definition: dqmdumpme.py:56
mps_fire.end
end
Definition: mps_fire.py:242
edm::MapOfVectors::loadNext
void loadNext(K const &k, std::vector< T > const &v)
Definition: MapOfVectors.h:87
first
auto first
Definition: CAHitNtupletGeneratorKernelsImpl.h:125
SiStripPartition::Versions
std::pair< uint32_t, uint32_t > Versions
Definition: SiStripPartition.h:42
sistrip::mlCabling_
static const char mlCabling_[]
Definition: ConstantsForLogger.h:14
jetUpdater_cfi.sort
sort
Definition: jetUpdater_cfi.py:29
SiStripConfigDb::FedIdsRange
boost::iterator_range< FedIds::const_iterator > FedIdsRange
Definition: SiStripConfigDb.h:121
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
SiStripConfigDb.h
std
Definition: JetResolutionObject.h:76
FedChannelConnection.h
SiStripConfigDb::getFedIds
FedIdsRange getFedIds(std::string partition="")
Definition: FedDescriptions.cc:431
findQualityFiles.jj
string jj
Definition: findQualityFiles.py:188
edm::MapOfVectors< std::string, FedDescription * >
data
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
LogTrace
#define LogTrace(id)
Definition: MessageLogger.h:234
sistrip
sistrip classes
Definition: EnsembleCalibrationLA.cc:10
SiStripPartition::defaultPartitionName_
static const std::string defaultPartitionName_
Definition: SiStripPartition.h:40
crabWrapper.key
key
Definition: crabWrapper.py:19
cuy.ii
ii
Definition: cuy.py:589
edm::MapOfVectors< std::string, FedDescription * >::const_iterator
Iter const_iterator
Definition: MapOfVectors.h:69