CMS 3D CMS Logo

SiStripCondObjBuilderFromDb.cc
Go to the documentation of this file.
1 
19 
20 #include <cstdlib>
21 #include <iostream>
22 #include <sstream>
23 #include <iomanip>
24 #include "Fed9UUtils.hh"
25 
26 using namespace std;
27 using namespace sistrip;
28 
29 // -----------------------------------------------------------------------------
32  : m_skippedDevices(pset.getUntrackedParameter<edm::VParameterSet>("SkippedDevices", edm::VParameterSet())),
33  m_whitelistedDevices(pset.getUntrackedParameter<edm::VParameterSet>("WhitelistedDevices", edm::VParameterSet())),
34  m_tickmarkThreshold(static_cast<float>(pset.getUntrackedParameter<double>("TickmarkThreshold", 50.))),
35  m_gaincalibrationfactor(static_cast<float>(pset.getUntrackedParameter<double>("GainNormalizationFactor", 640.))),
36  m_defaultpedestalvalue(static_cast<float>(pset.getUntrackedParameter<double>("DefaultPedestal", 0.))),
37  m_defaultnoisevalue(static_cast<float>(pset.getUntrackedParameter<double>("DefaultNoise", 0.))),
38  m_defaultthresholdhighvalue(static_cast<float>(pset.getUntrackedParameter<double>("DefaultThresholdHigh", 0.))),
39  m_defaultthresholdlowvalue(static_cast<float>(pset.getUntrackedParameter<double>("DefaultThresholdLow", 0.))),
40  m_defaultapvmodevalue(static_cast<uint16_t>(pset.getUntrackedParameter<uint32_t>("DefaultAPVMode", 37))),
41  m_defaultapvlatencyvalue(static_cast<uint16_t>(pset.getUntrackedParameter<uint32_t>("DefaultAPVLatency", 142))),
42  m_defaulttickheightvalue(static_cast<float>(pset.getUntrackedParameter<double>("DefaultTickHeight", 690.))),
43  m_useanalysis(static_cast<bool>(pset.getUntrackedParameter<bool>("UseAnalysis", false))),
44  m_usefed(static_cast<bool>(pset.getUntrackedParameter<bool>("UseFED", false))),
45  m_usefec(static_cast<bool>(pset.getUntrackedParameter<bool>("UseFEC", false))),
46  m_debug(static_cast<bool>(pset.getUntrackedParameter<bool>("DebugMode", false))),
47  m_detInfo(SiStripDetInfoFileReader::read(pset.getParameter<edm::FileInPath>("SiStripDetInfoFile").fullPath())),
48  tTopo(buildTrackerTopology()) {
49  LogTrace(mlESSources_) << "[SiStripCondObjBuilderFromDb::" << __func__ << "]"
50  << " Constructing object...";
51  for (const auto& pset : m_skippedDevices) {
52  skippedDevices.emplace_back(pset);
53  }
54  for (const auto& pset : m_whitelistedDevices) {
55  whitelistedDevices.emplace_back(pset);
56  }
57 }
58 
59 // -----------------------------------------------------------------------------
62  LogTrace(mlESSources_) << "[SiStripCondObjBuilderFromDb::" << __func__ << "]"
63  << " Constructing object...";
64 }
65 
66 // -----------------------------------------------------------------------------
69  LogTrace(mlESSources_) << "[SiStripCondObjBuilderFromDb::" << __func__ << "]"
70  << " Destructing object...";
71  delete tTopo;
72 }
73 
74 // -----------------------------------------------------------------------------
75 
78  if (!(dbParams_ == dbParams())) {
79  dbParams_ = dbParams();
80  buildCondObj();
81  }
82 }
83 // -----------------------------------------------------------------------------
91 
92  pxbVals_.layerStartBit_ = 16;
93  pxbVals_.ladderStartBit_ = 8;
94  pxbVals_.moduleStartBit_ = 2;
95  pxbVals_.layerMask_ = 0xF;
96  pxbVals_.ladderMask_ = 0xFF;
97  pxbVals_.moduleMask_ = 0x3F;
98  pxfVals_.sideStartBit_ = 23;
99  pxfVals_.diskStartBit_ = 16;
100  pxfVals_.bladeStartBit_ = 10;
101  pxfVals_.panelStartBit_ = 8;
102  pxfVals_.moduleStartBit_ = 2;
103  pxfVals_.sideMask_ = 0x3;
104  pxfVals_.diskMask_ = 0xF;
105  pxfVals_.bladeMask_ = 0x3F;
106  pxfVals_.panelMask_ = 0x3;
107  pxfVals_.moduleMask_ = 0x3F;
108  tecVals_.sideStartBit_ = 18;
109  tecVals_.wheelStartBit_ = 14;
110  tecVals_.petal_fw_bwStartBit_ = 12;
111  tecVals_.petalStartBit_ = 8;
112  tecVals_.ringStartBit_ = 5;
113  tecVals_.moduleStartBit_ = 2;
114  tecVals_.sterStartBit_ = 0;
115  tecVals_.sideMask_ = 0x3;
116  tecVals_.wheelMask_ = 0xF;
117  tecVals_.petal_fw_bwMask_ = 0x3;
118  tecVals_.petalMask_ = 0xF;
119  tecVals_.ringMask_ = 0x7;
120  tecVals_.moduleMask_ = 0x7;
121  tecVals_.sterMask_ = 0x3;
122  tibVals_.layerStartBit_ = 14;
123  tibVals_.str_fw_bwStartBit_ = 12;
124  tibVals_.str_int_extStartBit_ = 10;
125  tibVals_.strStartBit_ = 4;
126  tibVals_.moduleStartBit_ = 2;
127  tibVals_.sterStartBit_ = 0;
128  tibVals_.layerMask_ = 0x7;
129  tibVals_.str_fw_bwMask_ = 0x3;
130  tibVals_.str_int_extMask_ = 0x3;
131  tibVals_.strMask_ = 0x3F;
132  tibVals_.moduleMask_ = 0x3;
133  tibVals_.sterMask_ = 0x3;
134  tidVals_.sideStartBit_ = 13;
135  tidVals_.wheelStartBit_ = 11;
136  tidVals_.ringStartBit_ = 9;
137  tidVals_.module_fw_bwStartBit_ = 7;
138  tidVals_.moduleStartBit_ = 2;
139  tidVals_.sterStartBit_ = 0;
140  tidVals_.sideMask_ = 0x3;
141  tidVals_.wheelMask_ = 0x3;
142  tidVals_.ringMask_ = 0x3;
143  tidVals_.module_fw_bwMask_ = 0x3;
144  tidVals_.moduleMask_ = 0x1F;
145  tidVals_.sterMask_ = 0x3;
146  tobVals_.layerStartBit_ = 14;
147  tobVals_.rod_fw_bwStartBit_ = 12;
148  tobVals_.rodStartBit_ = 5;
149  tobVals_.moduleStartBit_ = 2;
150  tobVals_.sterStartBit_ = 0;
151  tobVals_.layerMask_ = 0x7;
152  tobVals_.rod_fw_bwMask_ = 0x3;
153  tobVals_.rodMask_ = 0x7F;
154  tobVals_.moduleMask_ = 0x7;
155  tobVals_.sterMask_ = 0x3;
156 
157  return new TrackerTopology(pxbVals_, pxfVals_, tecVals_, tibVals_, tidVals_, tobVals_);
158 }
159 // -----------------------------------------------------------------------------
162  std::stringstream& output,
163  std::string& label) {
164  // DEPRECATED. Superseded by SiStripCondObjBuilderFromDb::getConfigString(const std::type_info& typeInfo).
165 
166  //get current config DB parameter
167 
169 
170  SiStripDbParams::SiStripPartitions::const_iterator ipart = partitionsRange.begin();
171  SiStripDbParams::SiStripPartitions::const_iterator ipartEnd = partitionsRange.end();
172  for (; ipart != ipartEnd; ++ipart) {
173  SiStripPartition partition = ipart->second;
174  output << "@ "
175  << " Partition " << partition.partitionName();
176  if (label != "Cabling" && label != "ApvLatency")
177  output << " FedVer " << partition.fedVersion().first << "." << partition.fedVersion().second;
178  if (label == "Cabling")
179  output << " CabVer " << partition.cabVersion().first << "." << partition.cabVersion().second << " MaskVer "
180  << partition.maskVersion().first << "." << partition.maskVersion().second;
181  if (label == "ApvTiming")
182  output << " ApvTimingVer " << partition.apvTimingVersion().first << "." << partition.apvTimingVersion().second;
183  if (label == "ApvLatency")
184  output << " FecVersion " << partition.fecVersion().first << "." << partition.fecVersion().second;
185  }
186 
187  if (!strcmp(output.str().c_str(), input.str().c_str()))
188  return false;
189 
190  return true;
191 }
192 // -----------------------------------------------------------------------------
195  // create config line used by fast O2O
196 
197  std::stringstream output;
198 
200  SiStripDbParams::SiStripPartitions::const_iterator ipart = partitionsRange.begin();
201  SiStripDbParams::SiStripPartitions::const_iterator ipartEnd = partitionsRange.end();
202  for (; ipart != ipartEnd; ++ipart) {
203  SiStripPartition partition = ipart->second;
204  output << "%%"
205  << "Partition: " << partition.partitionName();
206 
207  // Make everything depend on cabVersion and maskVersion!
208  output << " CablingVersion: " << partition.cabVersion().first << "." << partition.cabVersion().second;
209  output << " MaskVersion: " << partition.maskVersion().first << "." << partition.maskVersion().second;
210 
211  if (typeInfo == typeid(SiStripFedCabling)) {
212  // Do nothing. FedCabling only depends on cabVersion and maskVersion.
213  } else if (typeInfo == typeid(SiStripLatency)) {
214  // Latency is FEC related, add fecVersion.
215  output << " FecVersion: " << partition.fecVersion().first << "." << partition.fecVersion().second;
216  } else {
217  // BadStrip, Noises, Pedestals and Thresholds are FED related, add fecVersion.
218  output << " FedVersion: " << partition.fedVersion().first << "." << partition.fedVersion().second;
219  if (typeInfo == typeid(SiStripApvGain)) {
220  // Not used in O2O.
221  output << " ApvTimingVersion: " << partition.apvTimingVersion().first << "."
222  << partition.apvTimingVersion().second;
223  }
224  }
225  }
226 
227  return output.str();
228 }
229 // -----------------------------------------------------------------------------
232  LogTrace(mlESSources_) << "[SiStripCondObjBuilderFromDb::" << __func__ << "]";
233 
234  // Check if DB connection is made
235  if (db_) {
236  // Check if DB connection is made
237  if (db_->deviceFactory() || db_->databaseCache()) {
238  // Build FEC cabling object
239  SiStripFecCabling fec_cabling;
240 
243 
245  SiStripDetCabling det_cabling(*fed_cabling_, tTopo);
246  buildStripRelatedObjects(&*db_, det_cabling);
247 
248  if (m_useanalysis)
250  if (m_usefed)
252  if (m_usefec)
254 
255  } else {
256  edm::LogWarning(mlESSources_) << "[SiStripCondObjBuilderFromDb::" << __func__ << "]"
257  << " NULL pointer to DeviceFactory returned by SiStripConfigDb!"
258  << " Cannot build Pedestals object!";
259  }
260  } else {
261  edm::LogWarning(mlESSources_) << "[SiStripCondObjBuilderFromDb::" << __func__ << "]"
262  << " NULL pointer to SiStripConfigDb returned by DB \"service\"!"
263  << " Cannot build Pedestals object!";
264  }
265 }
266 
267 // -----------------------------------------------------------------------------
269 //Retrieve FedDescriptions from configuration database
271  SiStripConfigDb::FedDescriptionsRange descriptions = db->getFedDescriptions();
272  if (descriptions.empty()) {
273  edm::LogWarning(mlESSources_) << "SiStripCondObjBuilderFromDb::" << __func__ << "]"
274  << " No FED descriptions found!";
275 
276  return false;
277  }
278  return true;
279 }
280 
281 // -----------------------------------------------------------------------------
283 // Retrieve gain from configuration database
286  db->getAnalysisDescriptions(CommissioningAnalysisDescription::T_ANALYSIS_TIMING);
287  if (anal_descriptions.empty()) {
288  edm::LogWarning(mlESSources_) << "SiStripCondObjBuilderFromDb::" << __func__ << "]"
289  << " Unable to build SiStripApvGain object!"
290  << " No timing-scan analysis descriptions found!";
291  return false;
292  }
293  return true;
294 }
295 
296 // -----------------------------------------------------------------------------
298 // Retrieve list of active DetIds
300  vector<uint32_t> det_ids;
301  det_cabling.addActiveDetectorsRawIds(det_ids);
302  if (det_ids.empty()) {
303  edm::LogWarning(mlESSources_) << "SiStripCondObjBuilderFromDb::" << __func__ << "]"
304  << " Unable to build Pedestals object!"
305  << " No DetIds found!";
306  return det_ids;
307  }
308  LogTrace(mlESSources_) << "\n\nSiStripCondObjBuilderFromDb::" << __func__ << "]"
309  << " Found " << det_ids.size() << " active DetIds";
310  return det_ids;
311 }
312 
313 // -----------------------------------------------------------------------------
315 //build connections per DetId
316 vector<const FedChannelConnection*> SiStripCondObjBuilderFromDb::buildConnections(const SiStripDetCabling& det_cabling,
317  uint32_t det_id) {
318  vector<const FedChannelConnection*> conns = det_cabling.getConnections(det_id);
319  if (conns.empty()) {
320  edm::LogWarning(mlESSources_) << "SiStripCondObjBuilderFromDb::" << __func__ << "]"
321  << " Unable to build condition object!"
322  << " No FED channel connections found for detid " << det_id;
323  }
324  return conns;
325 }
326 
327 // -----------------------------------------------------------------------------
329 //retrieve number of APV pairs per detid
331  uint16_t nApvPairs;
332  nApvPairs = m_detInfo.getNumberOfApvsAndStripLength(det_id).first / 2;
333  return nApvPairs;
334 }
335 
336 // -----------------------------------------------------------------------------
338 //set default values for Cabling Objects Peds, Noise, thresh, Quality
340  uint16_t istrip = apvPair * sistrip::STRIPS_PER_FEDCH;
341  std::cout << "Found disabled FedConnection! APVPair: " << apvPair << " Strips: " << sistrip::STRIPS_PER_FEDCH
342  << std::endl;
344  for (; istrip < (apvPair + 1) * sistrip::STRIPS_PER_FEDCH; ++istrip) {
348  }
349 }
350 
351 // -----------------------------------------------------------------------------
353 void SiStripCondObjBuilderFromDb::setDefaultValuesApvTiming(uint32_t detid, uint32_t apvPair) {
355 
356  if (gain_last_) {
357  auto range = gain_last_->getRange(detid);
358  if (apvPair * 2 < range.second - range.first) {
359  height = gain_last_->getApvGain(apvPair * 2, range);
360  edm::LogWarning(mlESSources_) << "[SiStripCondObjBuilderFromDb::" << __func__ << "]"
361  << " [ApvGain] Read gain value from last IOV for DetId: " << detid
362  << " ApvPair: " << apvPair << ", value=" << height;
363  } else {
364  edm::LogWarning(mlESSources_) << "[SiStripCondObjBuilderFromDb::" << __func__ << "]"
365  << " [ApvGain] Unable to read gain value from last IOV for DetId: " << detid
366  << " ApvPair: " << apvPair << ", use dummy value=" << height;
367  }
368  } else {
369  edm::LogWarning(mlESSources_) << "[SiStripCondObjBuilderFromDb::" << __func__ << "]"
370  << " [ApvGain] NULL pointer for last stored gain object in DB!!! "
371  << "Will use dummy value=" << height << " for DetId: " << detid
372  << " ApvPair: " << apvPair;
373  }
374 
375  inputApvGain.push_back(height); // APV0
376  inputApvGain.push_back(height); // APV1
377 }
378 
379 // -----------------------------------------------------------------------------
382  const FedChannelConnection& ipair,
383  uint32_t detid,
384  uint16_t apvnr) {
385  std::cout << "[SiStripCondObjBuilderFromDb::" << __func__ << "]: Set Default Latency for Detid: " << detid
386  << " ApvNr: " << apvnr << std::endl;
388  std::cout << "[SiStripCondObjBuilderFromDb::" << __func__ << "]: Unable to fill Latency for Detid: " << detid
389  << " ApvNr: " << apvnr << std::endl;
390  }
392  std::cout << "[SiStripCondObjBuilderFromDb::" << __func__ << "]: Unable to fill Latency for Detid: " << detid
393  << " ApvNr: " << apvnr << std::endl;
394  }
395 }
396 
397 // -----------------------------------------------------------------------------
401  db->getAnalysisDescriptions(CommissioningAnalysisDescription::T_ANALYSIS_TIMING);
402  SiStripConfigDb::AnalysisDescriptionsV::const_iterator iii = anal_descriptions.begin();
403  SiStripConfigDb::AnalysisDescriptionsV::const_iterator jjj = anal_descriptions.end();
404 
405  while (iii != jjj) {
406  CommissioningAnalysisDescription* tmp = *iii;
407  uint16_t fed_id = tmp->getFedId();
408  uint16_t fed_ch = SiStripFedKey::fedCh(tmp->getFeUnit(), tmp->getFeChan());
409  if (fed_id == ipair.fedId() && fed_ch == ipair.fedCh()) {
410  break;
411  }
412  iii++;
413  }
414 
415  TimingAnalysisDescription* anal = nullptr;
416  if (iii != jjj) {
417  anal = dynamic_cast<TimingAnalysisDescription*>(*iii);
418  }
419  if (!anal) {
420  edm::LogWarning(mlESSources_) << "[SiStripCondObjBuilderFromDb::" << __func__ << "]"
421  << " [ApvGain] Unable to find Timing Analysis Description from DB for DetId: "
422  << ipair.detId() << " ApvPair:" << ipair.apvPairNumber();
423  return false;
424  }
425 
426  bool is_whitelist = false;
427  for (const auto& desc : whitelistedDevices) {
428  if (desc.isConsistent(ipair)) {
429  is_whitelist = true;
430  if (std::find(whitelistedDetIds.begin(), whitelistedDetIds.end(), ipair.detId()) == whitelistedDetIds.end()) {
431  whitelistedDetIds.push_back(ipair.detId());
432  }
433  break;
434  }
435  }
436 
437  if (!is_whitelist) {
438  // check if this should be skipped only if it is not in the whitelist
439  for (const auto& desc : skippedDevices) {
440  if (desc.isConsistent(ipair)) {
441  edm::LogInfo(mlESSources_) << "[SiStripCondObjBuilderFromDb::" << __func__ << "]"
442  << " [ApvGain] Skip module with DetId:" << ipair.detId()
443  << " ApvPair:" << ipair.apvPairNumber() << " according to \n"
444  << desc.dump();
445  if (std::find(skippedDetIds.begin(), skippedDetIds.end(), ipair.detId()) == skippedDetIds.end()) {
446  skippedDetIds.push_back(ipair.detId());
447  }
448  return false;
449  }
450  }
451  }
452 
453  if (anal->getHeight() > m_tickmarkThreshold) {
454  float tick_height = (anal->getHeight() / m_gaincalibrationfactor);
455  inputApvGain.push_back(tick_height); // APV0
456  inputApvGain.push_back(tick_height); // APV1
457  } else {
458  edm::LogWarning(mlESSources_) << "[SiStripCondObjBuilderFromDb::" << __func__ << "]"
459  << " [ApvGain] Low tickmark height for DetId:" << ipair.detId()
460  << " ApvPair:" << ipair.apvPairNumber() << ", height=" << anal->getHeight();
461  return false;
462  }
463 
464  return true;
465 }
466 
467 // -----------------------------------------------------------------------------
470  SiStripConfigDb* const db,
471  FedChannelConnection& ipair,
472  uint32_t detid,
473  uint16_t apvnr,
476 
477  SiStripConfigDb::DeviceDescriptionsV::const_iterator iapv = apvs.begin();
478  SiStripConfigDb::DeviceDescriptionsV::const_iterator japv = apvs.end();
479  if (iapv == japv)
480  return false;
481  for (; iapv != japv; ++iapv) {
482  apvDescription* apv = dynamic_cast<apvDescription*>(*iapv);
483  if (!apv) {
484  continue;
485  }
486  if ((apv->getCrateId()) != (ipair.fecCrate()))
487  continue;
488  if ((apv->getFecSlot()) != (ipair.fecSlot()))
489  continue;
490  if ((apv->getRingSlot()) != (ipair.fecRing()))
491  continue;
492  if ((apv->getCcuAddress()) != (ipair.ccuAddr()))
493  continue;
494  if ((apv->getChannel()) != (ipair.ccuChan()))
495  continue;
496  // Insert latency values into latency object
497  if ((apv->getAddress()) == (ipair.i2cAddr(0))) {
498  if (!latency_.put(
499  detid, apvnr, static_cast<uint16_t>(apv->getLatency()), static_cast<uint16_t>(apv->getApvMode()))) {
500  std::cout << "UNABLE APVLatency Put: Detid " << dec << detid << " APVNr.: " << apvnr
501  << " Latency Value: " << dec << static_cast<uint16_t>(apv->getLatency()) << " APV Mode: " << dec
502  << static_cast<uint16_t>(apv->getApvMode()) << std::endl;
503  return false;
504  } else {
505  ++apvnr;
506  }
507  }
508  if ((apv->getAddress()) == (ipair.i2cAddr(1))) {
509  if (!latency_.put(
510  detid, apvnr, static_cast<uint16_t>(apv->getLatency()), static_cast<uint16_t>(apv->getApvMode()))) {
511  std::cout << "UNABLE APVLatency Put: Detid " << dec << detid << " APVNr.: " << apvnr
512  << " Latency Value: " << dec << static_cast<uint16_t>(apv->getLatency()) << " APV Mode: " << dec
513  << static_cast<uint16_t>(apv->getApvMode()) << std::endl;
514  continue;
515  return false;
516  } else {
517  ++apvnr;
518  }
519  }
520  }
521  return true;
522 }
523 
524 // -----------------------------------------------------------------------------
526 //bool SiStripCondObjBuilderFromDb::setValuesCabling(SiStripConfigDb* const db, FedChannelConnection &ipair, uint32_t detid){
528  FedChannelConnection& ipair,
529  uint32_t detid) {
530  //SiStripConfigDb::FedDescriptionsRange descriptions = db->getFedDescriptions();
531  SiStripConfigDb::FedDescriptionsV::const_iterator description = descriptions.begin();
532  while (description != descriptions.end()) {
533  if ((*description)->getFedId() == ipair.fedId()) {
534  break;
535  }
536  description++;
537  }
538  if (description == descriptions.end()) {
539  return false;
540  }
541  // Retrieve Fed9UStrips object from FED description
542  const Fed9U::Fed9UStrips& strips = (*description)->getFedStrips();
543 
544  // Retrieve StripDescriptions for each APV
545  uint16_t jstrip = ipair.apvPairNumber() * sistrip::STRIPS_PER_FEDCH;
546  for (uint16_t iapv = 2 * ipair.fedCh(); iapv < 2 * ipair.fedCh() + 2; iapv++) {
547  // Get StripDescriptions for the given APV
548  Fed9U::Fed9UAddress addr;
549  addr.setFedApv(iapv);
550  vector<Fed9U::Fed9UStripDescription> strip = strips.getApvStrips(addr);
551 
552  vector<Fed9U::Fed9UStripDescription>::const_iterator istrip = strip.begin();
553 
554  for (; istrip != strip.end(); istrip++) {
555  pedestals_->setData(istrip->getPedestal(), inputPedestals);
556  noises_->setData(istrip->getNoise(), inputNoises);
557  threshold_->setData(jstrip, istrip->getLowThresholdFactor(), istrip->getHighThresholdFactor(), inputThreshold);
558  if (istrip->getDisable()) {
559  std::cout << "Found disabled strip! Detid: " << detid << " APVNr: " << iapv << " Strips: " << jstrip
560  << std::endl;
561 
562  inputQuality.push_back(quality_->encode(jstrip, 1));
563  }
564  jstrip++;
565  }
566  }
567  return true;
568 }
569 
570 // -----------------------------------------------------------------------------
572 //store objects
574  if (!pedestals_->put(det_id, inputPedestals)) {
575  std::cout << "[SiStripCondObjBuilderFromDb::" << __func__ << "]"
576  << " Unable to insert values into SiStripPedestals object!"
577  << " DetId already exists!" << std::endl;
578  }
579  inputPedestals.clear();
580 }
581 
582 // -----------------------------------------------------------------------------
585  // Insert noise values into Noises object
586 
587  if (!noises_->put(det_id, inputNoises)) {
588  std::cout << "[SiStripCondObjBuilderFromDb::" << __func__ << "]"
589  << " Unable to insert values into SiStripNoises object!"
590  << " DetId already exists!" << std::endl;
591  }
592  inputNoises.clear();
593 }
594 
595 // -----------------------------------------------------------------------------
598  // Insert threshold values into Threshold object
599  if (!threshold_->put(det_id, inputThreshold)) {
600  std::cout << "[SiStripCondObjBuilderFromDb::" << __func__ << "]"
601  << " Unable to insert values into SiStripThreshold object!"
602  << " DetId already exists!" << std::endl;
603  }
604  inputThreshold.clear();
605 }
606 
607 // -----------------------------------------------------------------------------
610  // Insert quality values into Quality object
611  if (!inputQuality.empty()) {
612  quality_->compact(det_id, inputQuality);
613  if (!quality_->put(det_id, inputQuality)) {
614  std::cout << "[SiStripCondObjBuilderFromDb::" << __func__ << "]"
615  << " Unable to insert values into SiStripQuality object!"
616  << " DetId already exists!" << std::endl;
617  }
618  }
619  inputQuality.clear();
620 }
621 
622 // -----------------------------------------------------------------------------
625  // Insert tick height values into Gain object
627  if (!gain_->put(det_id, range)) {
628  edm::LogWarning(mlESSources_) << "[SiStripCondObjBuilderFromDb::" << __func__ << "]"
629  << " [ApvGain] Unable to insert values into SiStripApvGain object!"
630  << " DetId already exists!";
631  }
632  inputApvGain.clear();
633 }
634 
635 // -----------------------------------------------------------------------------
638  const SiStripDetCabling& det_cabling) {
639  //variables needed in this function
640  uint16_t nApvPairs;
641  vector<uint32_t>::const_iterator det_id;
642  vector<uint32_t> det_ids;
643 
644  edm::LogInfo(mlESSources_) << "\n[SiStripCondObjBuilderFromDb::" << __func__ << "] first call to this method";
645 
646  //Check if FedDescriptions exist, if not return
647  if (!retrieveFedDescriptions(db)) {
648  std::cout << "Found no FedDescription!" << std::endl;
649  return;
650  }
651  // Retrieve list of active DetIds
652  det_cabling.addActiveDetectorsRawIds(det_ids);
653  if (det_ids.empty()) {
654  std::cout << "SiStripCondObjBuilderFromDb::" << __func__ << "]"
655  << " Unable to build Pedestals object!"
656  << " No DetIds found!" << std::endl;
657  return;
658  }
659  std::cout << "\n\nSiStripCondObjBuilderFromDb::" << __func__ << "]"
660  << " Found " << det_ids.size() << " active DetIds";
661 
662  // Loop Active DetIds
663  det_id = det_ids.begin();
664  for (; det_id != det_ids.end(); det_id++) {
665  std::stringstream ssMessage;
666 
667  // Ignore NULL DetIds
668  if (!(*det_id)) {
669  continue;
670  }
671  if (*det_id == sistrip::invalid32_) {
672  continue;
673  }
674 
675  //build connections per DetId
676  const vector<const FedChannelConnection*>& conns = buildConnections(det_cabling, *det_id);
677 
678  vector<const FedChannelConnection*>::const_iterator ipair = conns.begin();
679  if (conns.empty())
680  continue;
681 
682  //retrieve number of APV pairs per detid
683  nApvPairs = retrieveNumberAPVPairs(*det_id);
684 
685  //loop connections and check if APVPair is connected
686  vector<vector<const FedChannelConnection*>::const_iterator> listConns(nApvPairs, conns.end());
687 
688  for (; ipair != conns.end(); ++ipair) {
689  // Check if the ApvPair is connected
690  if (!(*ipair))
691  continue;
692  if ((*ipair)->fedId() != sistrip::invalid_ && (*ipair)->apvPairNumber() < 3) {
693  // (*ipair)->print(ssMessage);
694  // ssMessage<< std::endl;
695  listConns[ipair - conns.begin()] = ipair;
696  } else {
697  std::cout << "\n impossible to assign connection position in listConns " << std::endl;
698  // (*ipair)->print(ssMessage);
699  // ssMessage << std::endl;
700  }
701  }
702 
703  // get data
704  // vector< vector<const FedChannelConnection *>::const_iterator >::const_iterator ilistConns=listConns.begin();
705  for (uint16_t apvPair = 0; apvPair < listConns.size(); ++apvPair) {
706  ipair = listConns[apvPair];
707  if (ipair == conns.end()) {
708  // Fill object with default values
709  std::cout << "\n "
710  << " Unable to find FED connection for detid : " << std::dec << *det_id << " APV pair number "
711  << apvPair << " Writing default values" << std::endl;
712  // (*ipair)->print(ssMessage); // this will crash!
713  //If no connection was found, add 100 to apvpair
714  apvPair += 100;
715  std::cout << " Put apvPair+100:" << apvPair << " into vector!" << std::endl;
716  // use dummy FedChannelConnection since it's not used in this case
718  p_apvpcon = std::make_pair(apvPair, dummy);
719  v_apvpcon.push_back(p_apvpcon);
720  apvPair = apvPair - 100;
721  continue;
722  }
723  p_apvpcon = std::make_pair(apvPair, **ipair);
724  v_apvpcon.push_back(p_apvpcon);
725  } //conns loop
726  p_detcon = std::make_pair(*det_id, v_apvpcon);
727  v_trackercon.push_back(p_detcon);
728  v_apvpcon.clear();
729  } // det id loop
730 }
731 
732 // -----------------------------------------------------------------------------
735  trackercon tc = _tc;
736  std::cout << "Entering [SiStripCondObjBuilderFromDb::" << __func__ << "]" << std::endl;
737  //data container
738  gain_ = new SiStripApvGain();
739 
740  //check if Timing analysis description is found, otherwise quit
742  edm::LogWarning(mlESSources_) << "[SiStripCondObjBuilderFromDb::" << __func__ << "]"
743  << " NULL pointer to AnalysisDescriptions returned by SiStripConfigDb!"
744  << " Cannot build Analysis object! QUIT";
745  throw cms::Exception("Cannot build Analysis object!");
746  }
747 
748  // Get all detIds from the ideal geometry to build the payload
749  for (const auto& it : m_detInfo.getAllData()) {
750  // check if det id is correct and if it is actually cabled in the detector
751  if (it.first == 0 || it.first == sistrip::invalid32_) {
752  edm::LogError("DetIdNotGood") << "@SUB=analyze"
753  << "Invalid detid: " << it.first << " ... neglecting!" << std::endl;
754  continue;
755  }
756 
757  uint32_t detid = it.first;
758  bool update_ = true;
759  i_trackercon det_iter =
760  std::find_if(tc.begin(), tc.end(), [detid](const pair_detcon& p) { return p.first == detid; });
761  if (det_iter == tc.end()) {
762  update_ = false; // do not update if it is not connected in cabling
763  }
764 
765  if (update_) {
766  //loop connections
767  for (i_apvpairconn connections = det_iter->second.begin(); connections != det_iter->second.end(); connections++) {
768  uint32_t apvPair = (*connections).first;
769  FedChannelConnection ipair = (*connections).second;
770 
771  //no connection for apvPair found
772  if (apvPair >= 100) {
773  setDefaultValuesApvTiming(detid, apvPair - 100);
774  continue;
775  }
776 
777  //fill data
778  if (!setValuesApvTiming(db, ipair)) {
779  // either not found in analysis table or low tickmark height
780  setDefaultValuesApvTiming(detid, apvPair);
781  }
782  } //connections
783 
784  } else {
785  uint32_t nApvPairs = it.second.nApvs / 2;
786  for (uint32_t apvPair = 0; apvPair < nApvPairs; ++apvPair) {
787  setDefaultValuesApvTiming(detid, apvPair);
788  }
789  }
790 
791  storeTiming(detid);
792 
793  } // end loop detids
794 
795  //print out skipped modules
796  std::stringstream ss;
797  for (const auto& id : whitelistedDetIds) {
798  ss << "\n" << id;
799  }
800  edm::LogInfo(mlESSources_) << "[SiStripCondObjBuilderFromDb::" << __func__ << "]"
801  << " [ApvGainSummary] " << whitelistedDetIds.size()
802  << " modules are in the whitelist, updates will be ensured: " << ss.str();
803 
804  ss.str(""); // clear it!
805  for (const auto& skip : skippedDetIds) {
806  ss << "\n" << skip;
807  }
808  edm::LogInfo(mlESSources_) << "[SiStripCondObjBuilderFromDb::" << __func__ << "]"
809  << " [ApvGainSummary] Skipped " << skippedDetIds.size() << " modules: " << ss.str();
810 }
811 
812 // -----------------------------------------------------------------------------
815  trackercon tc = _tc;
816  std::cout << "Entering [SiStripCondObjBuilderFromDb::" << __func__ << "]" << std::endl;
817  //data container
818  latency_ = new SiStripLatency();
819 
820  i_trackercon detids_end = tc.end();
821 
822  // get APV DeviceDescriptions
823  SiStripConfigDb::DeviceDescriptionsRange apvs = db->getDeviceDescriptions(APV25);
824  ;
825 
826  //loop detids
827  for (i_trackercon detids = tc.begin(); detids != detids_end; detids++) {
828  uint32_t detid = (*detids).first;
829  uint16_t apvnr = 1;
830  i_apvpairconn connections_end = ((*detids).second).end();
831 
832  //loop connections
833  for (i_apvpairconn connections = ((*detids).second).begin(); connections != connections_end; connections++) {
834  uint32_t apvPair = (*connections).first;
835  FedChannelConnection ipair = (*connections).second;
836 
837  //no connection for apvPair found
838  if (apvPair >= 100) {
839  //setDefaultValuesApvLatency((*latency_),ipair, detid, apvnr);
840  std::cout << "[SiStripCondObjBuilderFromDb::" << __func__ << "] No FEDConnection for DetId " << detid
841  << " ApvPair " << apvPair - 100 << " found, skipping Latency Insertion!" << std::endl;
842  continue;
843  }
844 
845  //fill data
846  if (!setValuesApvLatency((*latency_), db, ipair, detid, apvnr, apvs)) {
847  std::cout << "\n "
848  << " Unable to find FEC Description"
849  << " Skipping Insertion for DetId: " << detid << std::endl;
850  //setDefaultValuesApvLatency((*latency_),ipair, detid, apvnr);
851  }
852  apvnr += 2;
853  } //connections
854  // compact Latency Object
855 
856  } //detids
857  latency_->compress();
858  std::stringstream ss;
859  // latency debug output
862  std::cout << ss.str() << std::endl;
863 }
864 
865 // -----------------------------------------------------------------------------
868  trackercon tc = _tc;
869  std::cout << "Entering [SiStripCondObjBuilderFromDb::" << __func__ << "]" << std::endl;
870 
871  //data containers
873  noises_ = new SiStripNoises();
876 
877  i_trackercon detids_end = tc.end();
878 
879  //Build FED Descriptions out of db object
880  SiStripConfigDb::FedDescriptionsRange descriptions = db->getFedDescriptions();
881 
882  //loop detids
883  for (i_trackercon detids = tc.begin(); detids != detids_end; detids++) {
884  uint32_t detid = (*detids).first;
885  i_apvpairconn connections_end = ((*detids).second).end();
886 
887  //loop connections
888  for (i_apvpairconn connections = ((*detids).second).begin(); connections != connections_end; connections++) {
889  uint32_t apvPair = (*connections).first;
890  FedChannelConnection ipair = (*connections).second;
891 
892  //no connection for apvPair found
893  if (apvPair >= 100) {
894  std::cout << "[SiStripCondObjBuilderFromDb::" << __func__ << "]"
895  << " Unable to find FED description for FED id: " << ipair.fedId() << " detid : " << detid
896  << " APV pair number " << apvPair << " Writing default values" << std::endl;
897  setDefaultValuesCabling((apvPair - 100));
898  continue;
899  }
900  // if(!setValuesCabling(db, ipair, detid)){
901  if (!setValuesCabling(descriptions, ipair, detid)) {
902  std::cout << "[SiStripCondObjBuilderFromDb::" << __func__ << "]"
903  << " Unable to find FED description for FED id: " << ipair.fedId() << " detid : " << detid
904  << " APV pair number " << apvPair << " Writing default values" << std::endl;
905  setDefaultValuesCabling(apvPair);
906  }
907  } //connections
908  storePedestals(detid);
909  storeNoise(detid);
910  storeThreshold(detid);
911  storeQuality(detid);
912  } //detids
913 }
914 
916  : fec_(sistrip::invalid_), fed_(sistrip::invalid_), detid_(sistrip::invalid32_) {}
917 
919  : fec_(pset.getUntrackedParameter<uint32_t>("fecCrate", sistrip::invalid_),
920  pset.getUntrackedParameter<uint32_t>("fecSlot", sistrip::invalid_),
921  pset.getUntrackedParameter<uint32_t>("fecRing", sistrip::invalid_),
922  pset.getUntrackedParameter<uint32_t>("ccuAddr", sistrip::invalid_),
923  pset.getUntrackedParameter<uint32_t>("ccuChan", sistrip::invalid_),
924  pset.getUntrackedParameter<uint32_t>("lldChan", sistrip::invalid_),
925  pset.getUntrackedParameter<uint32_t>("i2cAddr", sistrip::invalid_)),
926  fed_(pset.getUntrackedParameter<uint32_t>("fedId", sistrip::invalid_),
927  pset.getUntrackedParameter<uint32_t>("feUnit", sistrip::invalid_),
928  pset.getUntrackedParameter<uint32_t>("feChan", sistrip::invalid_),
929  pset.getUntrackedParameter<uint32_t>("fedApv", sistrip::invalid_)),
930  detid_(pset.getUntrackedParameter<uint32_t>("detid", sistrip::invalid32_)) {
931  if (!fec_.isValid() && !fed_.isValid() && detid_ == sistrip::invalid32_) {
932  throw cms::Exception("InvalidPSet") << "None of FEC coordinates/FED coordinates/detids are valid in this PSet!\n"
933  << pset.dump(2);
934  }
935 }
936 
938  auto comp = [](uint16_t desc, uint16_t device) { return desc == 0 || desc == device; };
939 
940  // use FEC coordinates first if provided
941  if (fec_.isValid()) {
942  return comp(fec_.fecCrate(), fc.fecCrate()) && comp(fec_.fecSlot(), fc.fecSlot()) &&
943  comp(fec_.fecRing(), fc.fecRing()) && comp(fec_.ccuAddr(), fc.ccuAddr()) &&
944  comp(fec_.ccuChan(), fc.ccuChan()) && comp(fec_.lldChan(), fc.lldChannel()) &&
945  (comp(fec_.i2cAddr(), fc.i2cAddr(0)) ||
946  comp(fec_.i2cAddr(), fc.i2cAddr(1))); // do not distinguish between APV1 and APV2
947  }
948 
949  // then try FED coordinates
950  if (fed_.isValid()) {
951  return comp(fed_.fedId(), fc.fedId()) && comp(fed_.feUnit(), SiStripFedKey::feUnit(fc.fedCh())) &&
952  comp(fed_.feChan(), SiStripFedKey::feChan(fc.fedCh()));
953  // no fedApv in FedChannelConnection -- and we do not distinguish between APV1 and APV2
954  }
955 
956  // last try detids (will skip all APVs on the module)
957  if (detid_ != sistrip::invalid32_) {
958  return detid_ == fc.detId();
959  }
960 
961  return false;
962 }
963 
965  std::stringstream ss;
966  fec_.terse(ss);
967  ss << "\n";
968  fed_.terse(ss);
969  ss << "\n";
970  ss << "detid=" << detid_;
971  return ss.str();
972 }
bool put(const uint32_t &detID, const InputVector &vect)
const uint16_t & fecCrate() const
vector< uint32_t > retrieveActiveDetIds(const SiStripDetCabling &det_cabling)
SiStripPedestals::InputVector inputPedestals
const uint16_t & ccuAddr() const
bool put(const uint32_t detId, const uint16_t apv, const uint16_t latency, const uint16_t mode)
const uint16_t & feChan() const
const std::vector< const FedChannelConnection * > & getConnections(uint32_t det_id) const
const uint16_t & feUnit() const
void buildAnalysisRelatedObjects(SiStripConfigDb *const db, const trackercon &tc)
static const uint32_t invalid32_
Definition: Constants.h:15
SiStripQuality::InputVector inputQuality
DbClient *const databaseCache(std::string method_name="") const
std::vector< ParameterSet > VParameterSet
Definition: ParameterSet.h:34
void printDebug(std::stringstream &ss, const TrackerTopology *trackerTopo) const
Prints the full list of all ranges and corresponding values of latency and mode.
std::pair< uint32_t, v_apvpairconn > pair_detcon
FedDescriptions::range FedDescriptionsRange
const uint16_t & i2cAddr(const uint16_t &apv0_or_1) const
const uint16_t & fecSlot() const
SiStripThreshold::InputVector inputThreshold
Log< level::Error, false > LogError
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
std::vector< SkipDeviceDescription > whitelistedDevices
const_iterator_range partitions() const
sistrip classes
#define LogTrace(id)
bool isConsistent(const FedChannelConnection &fc) const
void setDefaultValuesCabling(uint16_t apvPair)
static std::string const input
Definition: EdmProvDump.cc:50
edm::Service< SiStripConfigDb > db_
bool put(const uint32_t &detID, Range input)
void buildFECRelatedObjects(SiStripConfigDb *const db, const trackercon &tc)
bool setValuesApvLatency(SiStripLatency &latency_, SiStripConfigDb *const db, FedChannelConnection &ipair, uint32_t detid, uint16_t apvnr, SiStripConfigDb::DeviceDescriptionsRange apvs)
char const * label
bool retrieveFedDescriptions(SiStripConfigDb *const db)
void buildStripRelatedObjects(SiStripConfigDb *const db, const SiStripDetCabling &det_cabling)
bool checkForCompatibility(std::stringstream &input, std::stringstream &output, std::string &label)
std::shared_ptr< SiStripApvGain > gain_last_
static void buildFecCabling(SiStripConfigDb *const, SiStripFecCabling &, const sistrip::CablingSource &)
Class containning control, module, detector and connection information, at the level of a FED channel...
DeviceDescriptions::range DeviceDescriptionsRange
const uint16_t & ccuChan() const
void compact(uint32_t detid, std::vector< unsigned int > &)
const uint16_t & fedId() const
An interface class to the DeviceFactory.
void buildFEDRelatedObjects(SiStripConfigDb *const db, const trackercon &tc)
std::pair< ContainerIterator, ContainerIterator > Range
const SiStripDbParams & dbParams() const
uint16_t retrieveNumberAPVPairs(uint32_t det_id)
std::vector< pair_detcon > trackercon
Container class for database partition parameters.
const uint16_t & fecRing() const
vector< const FedChannelConnection * > buildConnections(const SiStripDetCabling &det_cabling, uint32_t det_id)
SiStripNoises::InputVector inputNoises
bool put(const uint32_t &detID, const InputVector &input)
const uint32_t & detId() const
Log< level::Info, false > LogInfo
bool setValuesCabling(SiStripConfigDb::FedDescriptionsRange &descriptions, FedChannelConnection &ipair, uint32_t detid)
static void getFedCabling(const SiStripFecCabling &in, SiStripFedCabling &out)
static const uint16_t STRIPS_PER_FEDCH
bool isValid() const override
bool put(const uint32_t &detID, InputVector &input)
const std::pair< unsigned short, double > getNumberOfApvsAndStripLength(uint32_t detId) const
bool retrieveTimingAnalysisDescriptions(SiStripConfigDb *const db)
AnalysisDescriptions::range AnalysisDescriptionsRange
unsigned int module_fw_bwStartBit_
static const uint16_t invalid_
Definition: Constants.h:16
std::string getConfigString(const std::type_info &typeInfo)
void setDefaultValuesApvLatency(SiStripLatency &latency_, const FedChannelConnection &ipair, uint32_t detid, uint16_t apvnr)
void setData(const uint16_t &strip, const float &lTh, const float &hTh, Container &vthr)
uint16_t apvPairNumber() const
Contains cabling info at the device level, including DetId, APV pair numbers, hardware addresses...
boost::iterator_range< SiStripPartitions::const_iterator > const_iterator_range
SiStripApvGain::InputVector inputApvGain
void setData(float ped, InputVector &vped)
HLT enums.
const std::map< uint32_t, DetInfo > & getAllData() const noexcept
std::vector< uint32_t > whitelistedDetIds
void printSummary(std::stringstream &ss, const TrackerTopology *trackerTopo) const
Prints the number of ranges as well as the value of singleLatency and singleMode. ...
strips
#turn off noise in all subdetectors simHcalUnsuppressedDigis.doNoise = False mix.digitizers.hcal.doNoise = False simEcalUnsuppressedDigis.doNoise = False mix.digitizers.ecal.doNoise = False simEcalUnsuppressedDigis.doESNoise = False simSiPixelDigis.AddNoise = False mix.digitizers.pixel.AddNoise = False simSiStripDigis.Noise = False mix.digitizers.strip.AddNoise = False
Definition: DigiDM_cff.py:32
void setDefaultValuesApvTiming(uint32_t detid, uint32_t apvPair)
static uint16_t fedCh(const uint16_t &fe_unit, const uint16_t &fe_chan)
Log< level::Warning, false > LogWarning
static const char mlESSources_[]
std::vector< SkipDeviceDescription > skippedDevices
const uint16_t & fedCh() const
bool put(const uint32_t &detID, const InputVector &vect)
std::vector< pair_detcon >::iterator i_trackercon
tmp
align.sh
Definition: createJobs.py:716
std::vector< pair_apvpairconn >::iterator i_apvpairconn
unsigned int encode(const unsigned short &first, const unsigned short &NconsecutiveBadStrips, const unsigned short &flag=0)
void setData(float noise_, InputVector &vped)
bool setValuesApvTiming(SiStripConfigDb *const db, FedChannelConnection &ipair)
DeviceFactory *const deviceFactory(std::string method_name="") const
void addActiveDetectorsRawIds(std::vector< uint32_t > &) const
bool isValid() const override