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