CMS 3D CMS Logo

AnalysisDescriptions.cc
Go to the documentation of this file.
1 
5 
6 using namespace std;
7 using namespace sistrip;
8 
9 // -----------------------------------------------------------------------------
22  // Check
23  if ((!dbParams_.usingDbCache() && !deviceFactory(__func__)) ||
24  (dbParams_.usingDbCache() && !databaseCache(__func__))) {
25  return analyses_.emptyRange();
26  }
27 
28  try {
29  if (!dbParams_.usingDbCache()) {
30  SiStripDbParams::SiStripPartitions::const_iterator iter = dbParams_.partitions().begin();
31  SiStripDbParams::SiStripPartitions::const_iterator jter = dbParams_.partitions().end();
32  for (; iter != jter; ++iter) {
33  if (partition.empty() || partition == iter->second.partitionName()) {
34  if (iter->second.partitionName() == SiStripPartition::defaultPartitionName_) {
35  continue;
36  }
37 
38  AnalysisDescriptionsRange range = analyses_.find(iter->second.partitionName());
39  if (range == analyses_.emptyRange()) {
41  if (analysis_type == AnalysisDescription::T_ANALYSIS_FASTFEDCABLING) {
42  tmp1 = deviceFactory(__func__)->getAnalysisHistory(iter->second.partitionName(),
43  iter->second.fastCablingVersion().first,
44  iter->second.fastCablingVersion().second,
45  analysis_type);
46  } else if (analysis_type == AnalysisDescription::T_ANALYSIS_TIMING) {
47  tmp1 = deviceFactory(__func__)->getAnalysisHistory(iter->second.partitionName(),
48  iter->second.apvTimingVersion().first,
49  iter->second.apvTimingVersion().second,
50  analysis_type);
51  } else if (analysis_type == AnalysisDescription::T_ANALYSIS_OPTOSCAN) {
52  tmp1 = deviceFactory(__func__)->getAnalysisHistory(iter->second.partitionName(),
53  iter->second.optoScanVersion().first,
54  iter->second.optoScanVersion().second,
55  analysis_type);
56  } else if (analysis_type == AnalysisDescription::T_ANALYSIS_VPSPSCAN) {
57  tmp1 = deviceFactory(__func__)->getAnalysisHistory(iter->second.partitionName(),
58  iter->second.vpspScanVersion().first,
59  iter->second.vpspScanVersion().second,
60  analysis_type);
61  } else if (analysis_type == AnalysisDescription::T_ANALYSIS_CALIBRATION) {
62  tmp1 = deviceFactory(__func__)->getAnalysisHistory(iter->second.partitionName(),
63  iter->second.apvCalibVersion().first,
64  iter->second.apvCalibVersion().second,
65  analysis_type);
66  } else if (analysis_type == AnalysisDescription::T_ANALYSIS_PEDESTALS) {
67  tmp1 = deviceFactory(__func__)->getAnalysisHistory(iter->second.partitionName(),
68  iter->second.pedestalsVersion().first,
69  iter->second.pedestalsVersion().second,
70  analysis_type);
71  } else if (analysis_type == AnalysisDescription::T_ANALYSIS_PEDSFULLNOISE) {
72  tmp1 = deviceFactory(__func__)->getAnalysisHistory(iter->second.partitionName(),
73  iter->second.pedestalsVersion().first,
74  iter->second.pedestalsVersion().second,
75  analysis_type);
76  } else if (analysis_type == AnalysisDescription::T_ANALYSIS_APVLATENCY) {
77  tmp1 = deviceFactory(__func__)->getAnalysisHistory(iter->second.partitionName(),
78  iter->second.apvLatencyVersion().first,
79  iter->second.apvLatencyVersion().second,
80  analysis_type);
81  } else if (analysis_type == AnalysisDescription::T_ANALYSIS_FINEDELAY) {
82  tmp1 = deviceFactory(__func__)->getAnalysisHistory(iter->second.partitionName(),
83  iter->second.fineDelayVersion().first,
84  iter->second.fineDelayVersion().second,
85  analysis_type);
86  } else {
87  std::stringstream ss;
88  ss << "[SiStripConfigDb::" << __func__ << "]"
89  << " Unexpected analysis type \"" << analysisType(analysis_type) << "\"! Aborting download...";
90  edm::LogWarning(mlConfigDb_) << ss.str();
91  return analyses_.emptyRange();
92  }
93 
94  // Make local copy
96  CommissioningAnalysisFactory::vectorCopy(tmp1, tmp2);
97 
98  // Add to cache
99  analyses_.loadNext(iter->second.partitionName(), tmp2);
100 
101  // Some debug
102  AnalysisDescriptionsRange anals = analyses_.find(iter->second.partitionName());
103  std::stringstream ss;
104  ss << "[SiStripConfigDb::" << __func__ << "]"
105  << " Downloaded " << anals.size() << " analysis descriptions of type \"" << analysisType(analysis_type)
106  << "\" to local cache for partition \"" << iter->second.partitionName() << "\"" << std::endl;
107  ss << "[SiStripConfigDb::" << __func__ << "]"
108  << " Cache holds analysis descriptions for " << analyses_.size() << " partitions.";
109  LogTrace(mlConfigDb_) << ss.str();
110  }
111  }
112  }
113 
114  } else { // Use database cache
115  std::stringstream ss;
116  ss << "[SiStripConfigDb::" << __func__ << "]"
117  << " No database cache for analysis objects!";
118  edm::LogWarning(mlConfigDb_) << ss.str();
119  }
120 
121  } catch (...) {
122  handleException(__func__);
123  }
124 
125  // Create range object
126  uint16_t np = 0;
127  uint16_t nc = 0;
128  AnalysisDescriptionsRange anals = analyses_.emptyRange();
129  if (!partition.empty()) {
130  anals = analyses_.find(partition);
131  np = 1;
132  nc = anals.size();
133  } else {
134  if (!analyses_.empty()) {
135  anals =
136  AnalysisDescriptionsRange(analyses_.find(dbParams_.partitions().begin()->second.partitionName()).begin(),
137  analyses_.find((--(dbParams_.partitions().end()))->second.partitionName()).end());
138  } else {
139  anals = analyses_.emptyRange();
140  }
141  np = analyses_.size();
142  nc = anals.size();
143  }
144 
145  stringstream ss;
146  ss << "[SiStripConfigDb::" << __func__ << "]"
147  << " Found " << nc << " analysis descriptions";
148  if (!dbParams_.usingDbCache()) {
149  ss << " in " << np << " database partition(s)";
150  } else {
151  ss << " from shared memory name '" << dbParams_.sharedMemory() << "'";
152  }
153  if (analyses_.empty()) {
154  edm::LogWarning(mlConfigDb_) << ss.str();
155  } else {
156  LogTrace(mlConfigDb_) << ss.str();
157  }
158 
159  return anals;
160 }
161 
162 // -----------------------------------------------------------------------------
163 //
165  if (!deviceFactory(__func__)) {
166  return;
167  }
168 
169  if (partition.empty()) {
170  stringstream ss;
171  ss << "[SiStripConfigDb::" << __func__ << "]"
172  << " Partition string is empty,"
173  << " therefore cannot add analysis descriptions to local cache!";
174  edm::LogWarning(mlConfigDb_) << ss.str();
175  return;
176  }
177 
178  if (anals.empty()) {
179  stringstream ss;
180  ss << "[SiStripConfigDb::" << __func__ << "]"
181  << " Vector of analysis descriptions is empty,"
182  << " therefore cannot add analysis descriptions to local cache!";
183  edm::LogWarning(mlConfigDb_) << ss.str();
184  return;
185  }
186 
187  SiStripDbParams::SiStripPartitions::const_iterator iter = dbParams_.partitions().begin();
188  SiStripDbParams::SiStripPartitions::const_iterator jter = dbParams_.partitions().end();
189  for (; iter != jter; ++iter) {
190  if (partition == iter->second.partitionName()) {
191  break;
192  }
193  }
194  if (iter == dbParams_.partitions().end()) {
195  stringstream ss;
196  ss << "[SiStripConfigDb::" << __func__ << "]"
197  << " Partition \"" << partition << "\" not found in partition list, "
198  << " therefore cannot add analysis descriptions!";
199  edm::LogWarning(mlConfigDb_) << ss.str();
200  return;
201  }
202 
203  AnalysisDescriptionsRange range = analyses_.find(partition);
204  if (range == analyses_.emptyRange()) {
205  // Make local copy
207  CommissioningAnalysisFactory::vectorCopy(anals, tmp);
208 
209  // Add to local cache
210  analyses_.loadNext(partition, tmp);
211 
212  // Some debug
213  std::stringstream ss;
214  ss << "[SiStripConfigDb::" << __func__ << "]"
215  << " Added " << anals.size() << " analysis descriptions to local cache for partition \"" << partition << "\"."
216  << " (Cache holds analysis descriptions for " << analyses_.size() << " partitions.)";
217  LogTrace(mlConfigDb_) << ss.str();
218  } else {
219  stringstream ss;
220  ss << "[SiStripConfigDb::" << __func__ << "]"
221  << " Partition \"" << partition << "\" already found in local cache, "
222  << " therefore cannot add analysis descriptions!";
223  edm::LogWarning(mlConfigDb_) << ss.str();
224  return;
225  }
226 }
227 
228 // -----------------------------------------------------------------------------
229 //
231  if (dbParams_.usingDbCache()) {
232  edm::LogWarning(mlConfigDb_) << "[SiStripConfigDb::" << __func__ << "]"
233  << " Using database cache! No uploads allowed!";
234  return;
235  }
236 
237  if (!deviceFactory(__func__)) {
238  return;
239  }
240 
241  if (analyses_.empty()) {
242  edm::LogWarning(mlConfigDb_) << "[SiStripConfigDb::" << __func__ << "]"
243  << " Found no cached analysis descriptions, therefore no upload!";
244  return;
245  }
246 
247  if (calibration_for_physics && !allowCalibUpload_) {
248  edm::LogWarning(mlConfigDb_) << "[SiStripConfigDb::" << __func__ << "]"
249  << " Attempting to upload calibration constants"
250  << " without uploading any hardware descriptions!"
251  << " Aborting upload...";
252  return;
253  } else {
254  allowCalibUpload_ = false;
255  }
256 
257  try {
258  SiStripDbParams::SiStripPartitions::const_iterator iter = dbParams_.partitions().begin();
259  SiStripDbParams::SiStripPartitions::const_iterator jter = dbParams_.partitions().end();
260  for (; iter != jter; ++iter) {
261  if (partition.empty() || partition == iter->second.partitionName()) {
262  AnalysisDescriptionsRange range = analyses_.find(iter->second.partitionName());
263  if (range != analyses_.emptyRange()) {
264  AnalysisDescriptionsV anals(range.begin(), range.end());
265 
266  vector<AnalysisType>
267  analysis_type; // check how many different analysis type we have --> more than one analysis table could be uploaded in the same job
268  for (auto element : anals) {
269  if (std::find(analysis_type.begin(), analysis_type.end(), element->getType()) == analysis_type.end() and
270  element->getType() != AnalysisDescription::T_UNKNOWN) {
271  analysis_type.push_back(element->getType());
272  } else if (element->getType() == AnalysisDescription::T_UNKNOWN) {
273  edm::LogWarning(mlConfigDb_) << "[SiStripConfigDb::" << __func__ << "]"
274  << " Analysis type is UNKNOWN. Aborting upload!";
275  return;
276  }
277  }
278 
279  vector<AnalysisDescriptionsV> analysisToUpload; // in case there are more than one analysis type to be uploaded
280  for (auto type : analysis_type) {
281  AnalysisDescriptionsV ana_temp;
282  for (auto element : anals) {
283  if (element->getType() == type)
284  ana_temp.push_back(element);
285  }
286  analysisToUpload.push_back(ana_temp);
287  }
288 
289  // perform the upload
290  for (auto analysis : analysisToUpload) {
291  uint32_t version = deviceFactory(__func__)->uploadAnalysis(iter->second.runNumber(),
292  iter->second.partitionName(),
293  analysis.front()->getType(),
294  analysis,
295  calibration_for_physics);
296  // Update current state with analysis descriptions
297  if (calibration_for_physics) {
298  deviceFactory(__func__)->uploadAnalysisState(version);
299  }
300  }
301 
302  // Some debug
303  std::stringstream ss;
304  ss << "[SiStripConfigDb::" << __func__ << "]"
305  << " Uploaded " << anals.size() << " device descriptions to database for partition \""
306  << iter->second.partitionName() << "\".";
307  LogTrace(mlConfigDb_) << ss.str();
308 
309  } else {
310  stringstream ss;
311  ss << "[SiStripConfigDb::" << __func__ << "]"
312  << " Vector of device descriptions is empty for partition \"" << iter->second.partitionName()
313  << "\", therefore aborting upload for this partition!";
314  edm::LogWarning(mlConfigDb_) << ss.str();
315  continue;
316  }
317 
318  } else {
319  // stringstream ss;
320  // ss << "[SiStripConfigDb::" << __func__ << "]"
321  // << " Cannot find partition \"" << partition
322  // << "\" in cached partitions list: \""
323  // << dbParams_.partitionNames( dbParams_.partitionNames() )
324  // << "\", therefore aborting upload for this partition!";
325  // edm::LogWarning(mlConfigDb_) << ss.str();
326  }
327  }
328  } catch (...) {
329  handleException(__func__);
330  }
331 
332  allowCalibUpload_ = true;
333 }
334 
335 // -----------------------------------------------------------------------------
336 //
338  LogTrace(mlConfigDb_) << "[SiStripConfigDb::" << __func__ << "]";
339 
340  if (analyses_.empty()) {
341  stringstream ss;
342  ss << "[SiStripConfigDb::" << __func__ << "]"
343  << " Found no cached analysis descriptions!";
344  //edm::LogWarning(mlConfigDb_) << ss.str();
345  return;
346  }
347 
348  // Reproduce temporary cache for "all partitions except specified one" (or clear all if none specified)
349  AnalysisDescriptions temporary_cache;
350  if (partition.empty()) {
351  temporary_cache = AnalysisDescriptions();
352  } else {
353  SiStripDbParams::SiStripPartitions::const_iterator iter = dbParams_.partitions().begin();
354  SiStripDbParams::SiStripPartitions::const_iterator jter = dbParams_.partitions().end();
355  for (; iter != jter; ++iter) {
356  if (partition != iter->second.partitionName()) {
357  AnalysisDescriptionsRange range = analyses_.find(iter->second.partitionName());
358  if (range != analyses_.emptyRange()) {
359  temporary_cache.loadNext(partition, AnalysisDescriptionsV(range.begin(), range.end()));
360  } else {
361  // stringstream ss;
362  // ss << "[SiStripConfigDb::" << __func__ << "]"
363  // << " Cannot find partition \"" << iter->second.partitionName()
364  // << "\" in local cache!";
365  // edm::LogWarning(mlConfigDb_) << ss.str();
366  }
367  }
368  }
369  }
370 
371  // Delete objects in local cache for specified partition (or all if not specified)
372  AnalysisDescriptionsRange anals = analyses_.emptyRange();
373  if (partition.empty()) {
374  if (!analyses_.empty()) {
375  anals =
376  AnalysisDescriptionsRange(analyses_.find(dbParams_.partitions().begin()->second.partitionName()).begin(),
377  analyses_.find((--(dbParams_.partitions().end()))->second.partitionName()).end());
378  } else {
379  anals = analyses_.emptyRange();
380  }
381  } else {
382  SiStripDbParams::SiStripPartitions::const_iterator iter = dbParams_.partitions().begin();
383  SiStripDbParams::SiStripPartitions::const_iterator jter = dbParams_.partitions().end();
384  for (; iter != jter; ++iter) {
385  if (partition == iter->second.partitionName()) {
386  break;
387  }
388  }
389  anals = analyses_.find(iter->second.partitionName());
390  }
391 
392  if (anals != analyses_.emptyRange()) {
393  AnalysisDescriptionsV::const_iterator ianal = anals.begin();
394  AnalysisDescriptionsV::const_iterator janal = anals.end();
395  for (; ianal != janal; ++ianal) {
396  if (*ianal) {
397  delete *ianal;
398  }
399  }
400  } else {
401  stringstream ss;
402  ss << "[SiStripConfigDb::" << __func__ << "]";
403  if (partition.empty()) {
404  ss << " Found no analysis descriptions in local cache!";
405  } else {
406  ss << " Found no analysis descriptions in local cache for partition \"" << partition << "\"!";
407  }
408  edm::LogWarning(mlConfigDb_) << ss.str();
409  }
410 
411  // Overwrite local cache with temporary cache
412  analyses_ = temporary_cache;
413 }
414 
415 // -----------------------------------------------------------------------------
416 //
418  std::stringstream ss;
419  ss << "[SiStripConfigDb::" << __func__ << "]"
420  << " Contents of AnalysisDescriptions container:" << std::endl;
421  ss << " Number of partitions: " << analyses_.size() << std::endl;
422 
423  // Loop through partitions
424  uint16_t cntr = 0;
425  AnalysisDescriptions::const_iterator ianal = analyses_.begin();
426  AnalysisDescriptions::const_iterator janal = analyses_.end();
427  for (; ianal != janal; ++ianal) {
428  cntr++;
429  if (partition.empty() || partition == ianal->first) {
430  ss << " Partition number : " << cntr << " (out of " << analyses_.size() << ")" << std::endl;
431  ss << " Partition name : \"" << ianal->first << "\"" << std::endl;
432  ss << " Num of analyses : " << ianal->second.size() << std::endl;
433 
434  // Extract FEC crate, slot, etc
435  std::map<uint32_t, vector<uint32_t> > analyses;
436  AnalysisDescriptionsV::const_iterator iter = ianal->second.begin();
437  AnalysisDescriptionsV::const_iterator jter = ianal->second.end();
438  for (; iter != jter; ++iter) {
439  if (*iter) {
440  DeviceAddress addr = deviceAddress(**iter);
441  uint32_t key = SiStripFecKey(addr.fecCrate_, addr.fecSlot_, addr.fecRing_, 0, 0, 0, 0).key();
442  uint32_t data = SiStripFecKey(addr.fecCrate_,
443  addr.fecSlot_,
444  addr.fecRing_,
445  addr.ccuAddr_,
446  addr.ccuChan_,
447  addr.lldChan_,
448  addr.i2cAddr_)
449  .key();
450  if (find(analyses[key].begin(), analyses[key].end(), data) == analyses[key].end()) {
451  analyses[key].push_back(data);
452  }
453  }
454  }
455 
456  // Sort contents
457  std::map<uint32_t, std::vector<uint32_t> > tmp;
458  std::map<uint32_t, std::vector<uint32_t> >::const_iterator ii = analyses.begin();
459  std::map<uint32_t, std::vector<uint32_t> >::const_iterator jj = analyses.end();
460  for (; ii != jj; ++ii) {
461  std::vector<uint32_t> temp = ii->second;
462  std::sort(temp.begin(), temp.end());
463  std::vector<uint32_t>::const_iterator iii = temp.begin();
464  std::vector<uint32_t>::const_iterator jjj = temp.end();
465  for (; iii != jjj; ++iii) {
466  tmp[ii->first].push_back(*iii);
467  }
468  }
469  analyses.clear();
470  analyses = tmp;
471 
472  // Print FEC crate, slot, etc...
473  std::map<uint32_t, std::vector<uint32_t> >::const_iterator ianal = analyses.begin();
474  std::map<uint32_t, std::vector<uint32_t> >::const_iterator janal = analyses.end();
475  for (; ianal != janal; ++ianal) {
476  SiStripFecKey key(ianal->first);
477  ss << " Found " << std::setw(3) << ianal->second.size() << " analyses for FEC crate/slot/ring "
478  << key.fecCrate() << "/" << key.fecSlot() << "/" << key.fecRing();
479  //<< " (ccu/module/lld/i2c): ";
480  // if ( !ianal->second.empty() ) {
481  // uint16_t first = ianal->second.front();
482  // uint16_t last = ianal->second.front();
483  // std::vector<uint32_t>::const_iterator chan = ianal->second.begin();
484  // for ( ; chan != ianal->second.end(); chan++ ) {
485  // if ( chan != ianal->second.begin() ) {
486  // if ( *chan != last+1 ) {
487  // ss << std::setw(2) << first << "->" << std::setw(2) << last << ", ";
488  // if ( chan != ianal->second.end() ) { first = *(chan+1); }
489  // }
490  // }
491  // last = *chan;
492  // }
493  // if ( first != last ) { ss << std::setw(2) << first << "->" << std::setw(2) << last; }
494  ss << std::endl;
495  }
496  }
497  }
498 
499  LogTrace(mlConfigDb_) << ss.str();
500 }
501 
502 // -----------------------------------------------------------------------------
503 //
506  try {
507  addr.fecCrate_ = static_cast<uint16_t>(desc.getCrate() + sistrip::FEC_CRATE_OFFSET);
508  addr.fecSlot_ = static_cast<uint16_t>(desc.getSlot());
509  addr.fecRing_ = static_cast<uint16_t>(desc.getRing() + sistrip::FEC_RING_OFFSET);
510  addr.ccuAddr_ = static_cast<uint16_t>(desc.getCcuAdr());
511  addr.ccuChan_ = static_cast<uint16_t>(desc.getCcuChan());
512  addr.lldChan_ = static_cast<uint16_t>(SiStripFecKey::lldChan(desc.getI2cAddr()));
513  addr.i2cAddr_ = static_cast<uint16_t>(desc.getI2cAddr());
514  addr.fedId_ = static_cast<uint16_t>(desc.getFedId()); //@@ offset required? crate/slot needed?
515  addr.feUnit_ = static_cast<uint16_t>(desc.getFeUnit());
516  addr.feChan_ = static_cast<uint16_t>(desc.getFeChan());
517  } catch (...) {
518  handleException(__func__);
519  }
520 
521  return addr;
522 }
523 
524 // -----------------------------------------------------------------------------
525 //
527  if (analysis_type == AnalysisDescription::T_ANALYSIS_FASTFEDCABLING) {
528  return "FAST_CABLING";
529  } else if (analysis_type == AnalysisDescription::T_ANALYSIS_TIMING) {
530  return "APV_TIMING";
531  } else if (analysis_type == AnalysisDescription::T_ANALYSIS_OPTOSCAN) {
532  return "OPTO_SCAN";
533  } else if (analysis_type == AnalysisDescription::T_ANALYSIS_PEDESTALS) {
534  return "PEDESTALS";
535  } else if (analysis_type == AnalysisDescription::T_ANALYSIS_PEDSFULLNOISE) {
536  return "PEDSFULLNOISE";
537  } else if (analysis_type == AnalysisDescription::T_ANALYSIS_APVLATENCY) {
538  return "APV_LATENCY";
539  } else if (analysis_type == AnalysisDescription::T_ANALYSIS_FINEDELAY) {
540  return "FINE_DELAY";
541  } else if (analysis_type == AnalysisDescription::T_ANALYSIS_CALIBRATION) {
542  return "CALIBRATION";
543  } else if (analysis_type == AnalysisDescription::T_UNKNOWN) {
544  return "UNKNOWN ANALYSIS TYPE";
545  } else {
546  return "UNDEFINED ANALYSIS TYPE";
547  }
548 }
static const std::string defaultPartitionName_
void loadNext(K const &k, std::vector< T > const &v)
Definition: MapOfVectors.h:87
void uploadAnalysisDescriptions(bool calibration_for_physics=false, std::string partition="")
void addAnalysisDescriptions(std::string partition, AnalysisDescriptionsV &)
static const uint16_t FEC_RING_OFFSET
const uint16_t & lldChan() const
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
sistrip classes
#define LogTrace(id)
static const char mlConfigDb_[]
Utility class that identifies a position within the strip tracker control structure, down to the level of an APV25.
Definition: SiStripFecKey.h:45
int np
Definition: AMPTWrapper.h:43
CommissioningAnalysisDescription AnalysisDescription
void clearAnalysisDescriptions(std::string partition="")
const uint32_t & key() const
Definition: SiStripKey.h:120
DeviceAddress deviceAddress(const deviceDescription &)
AnalysisDescriptionsRange getAnalysisDescriptions(AnalysisType, std::string partition="")
ii
Definition: cuy.py:589
std::string analysisType(AnalysisType) const
AnalysisDescriptions::range AnalysisDescriptionsRange
CommissioningAnalysisDescription::commissioningType AnalysisType
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
std::vector< AnalysisDescription * > AnalysisDescriptionsV
static const uint16_t FEC_CRATE_OFFSET
void printAnalysisDescriptions(std::string partition="")
Log< level::Warning, false > LogWarning
tmp
align.sh
Definition: createJobs.py:716