CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
SiStripFedCablingBuilderFromDb.cc
Go to the documentation of this file.
1 // Last commit: $Id: SiStripFedCablingBuilderFromDb.cc,v 1.57 2009/04/06 17:08:39 lowette Exp $
2 
12 #include <cstdlib>
13 #include <iostream>
14 #include <sstream>
15 #include <iomanip>
16 
17 using namespace std;
18 using namespace sistrip;
19 
20 // -----------------------------------------------------------------------------
24  db_(0),
25  source_(sistrip::UNDEFINED_CABLING_SOURCE)
26 {
27  findingRecord<SiStripFedCablingRcd>();
28 
30  << "[SiStripFedCablingBuilderFromDb::" << __func__ << "]"
31  << " Constructing object...";
32 
33  // Defined cabling "source" (connections, devices, detids)
34  string source = pset.getUntrackedParameter<string>( "CablingSource", "UNDEFINED" );
36 
38  << "[SiStripFedCablingBuilderFromDb::" << __func__ << "]"
39  << " CablingSource configurable set to \"" << source << "\""
40  << ". CablingSource member data set to: \""
41  << SiStripEnumsAndStrings::cablingSource( source_ ) << "\"";
42 }
43 
44 // -----------------------------------------------------------------------------
48  << "[SiStripFedCablingBuilderFromDb::" << __func__ << "]"
49  << " Destructing object...";
50 }
51 
52 // -----------------------------------------------------------------------------
56  << "[SiStripFedCablingBuilderFromDb::" << __func__ << "]"
57  << " Constructing FED cabling...";
58 
59  // Create FED cabling object
60  SiStripFedCabling* fed_cabling = new SiStripFedCabling();
61 
62  // Build and retrieve SiStripConfigDb object using service
64 
65  // Check pointer
66  if ( db_ ) {
68  << "[SiStripFedCablingBuilderFromDb::" << __func__ << "]"
69  << " Pointer to SiStripConfigDb: 0x"
70  << std::setw(8) << std::setfill('0')
71  << std::hex << db_ << std::dec;
72  } else {
74  << "[SiStripFedCablingBuilderFromDb::" << __func__ << "]"
75  << " NULL pointer to SiStripConfigDb returned by DB \"service\"!"
76  << " Cannot build FED cabling object!";
77  return fed_cabling;
78  }
79 
80  // Check if DB connection is made
81  if ( db_->deviceFactory() ||
82  db_->databaseCache() ) {
83 
84  // Build FEC cabling object
85  SiStripFecCabling fec_cabling;
86  buildFecCabling( db_, fec_cabling, source_ );
87 
88  // Populate FED cabling object
89  getFedCabling( fec_cabling, *fed_cabling );
90 
91  // Call virtual method that writes FED cabling object to conditions DB
92  writeFedCablingToCondDb( *fed_cabling );
93 
94  // Prints FED cabling
95  //stringstream ss;
96  //ss << "[SiStripFedCablingBuilderFromDb::" << __func__ << "]"
97  //<< " Printing cabling map..." << endl
98  //<< *fed_cabling;
99  //LogTrace(mlCabling_) << ss.str();
100 
101  } else {
103  << "[SiStripFedCablingBuilderFromDb::" << __func__ << "]"
104  << " NULL pointers to DeviceFactory and DatabaseCache returned by SiStripConfigDb!"
105  << " Cannot build FED cabling object!";
106  }
107 
108  return fed_cabling;
109 
110 }
111 
112 // -----------------------------------------------------------------------------
115  SiStripFecCabling& fec_cabling,
116  const sistrip::CablingSource& source ) {
117 
118  if ( source == sistrip::CABLING_FROM_CONNS ) { buildFecCablingFromFedConnections( db, fec_cabling ); }
119  else if ( source == sistrip::CABLING_FROM_DEVICES ) { buildFecCablingFromDevices( db, fec_cabling ); }
120  else if ( source == sistrip::CABLING_FROM_DETIDS ) { buildFecCablingFromDetIds( db, fec_cabling ); }
121  else if ( source == sistrip::UNDEFINED_CABLING_SOURCE ) {
122 
124  << "[SiStripFedCablingBuilderFromDb::" << __func__ << "]"
125  << " Unexpected value for CablingSource: \""
127  << "\" Querying DB in order to build cabling from one of connections, devices or DetIds...";
128  buildFecCabling( db, fec_cabling );
129  return;
130 
131  } else {
132 
134  << "[SiStripFedCablingBuilderFromDb::" << __func__ << "]"
135  << " Cannot build SiStripFecCabling object!"
136  << " sistrip::CablingSource has value: "
138  return;
139 
140  }
141 
142  // Debug
143  const NumberOfDevices& devs = fec_cabling.countDevices();
144  std::stringstream ss;
145  ss << "[SiStripFedCablingBuilderFromDb::" << __func__ << "]"
146  << " Built SiStripFecCabling object with following devices:"
147  << endl << devs;
148  edm::LogVerbatim(mlCabling_) << ss.str() << endl;
149 
150 }
151 
152 // -----------------------------------------------------------------------------
155  SiStripFecCabling& fec_cabling ) {
157  << "[SiStripFedCablingBuilderFromDb::" << __func__ << "]"
158  << " Building cabling object...";
159 
160  if ( !db->getFedConnections().empty() ) { buildFecCablingFromFedConnections( db, fec_cabling ); }
161  else if ( !db->getDeviceDescriptions().empty() ) { buildFecCablingFromDevices( db, fec_cabling ); }
162  else if ( !db->getDcuDetIds().empty() ) { buildFecCablingFromDetIds( db, fec_cabling ); }
163  else {
164 
166  << "[SiStripFedCablingBuilderFromDb::" << __func__ << "]"
167  << " Cannot build SiStripFecCabling object!"
168  << " FedConnections, DeviceDescriptions and DcuDetIds vectors are all empty!";
169  return;
170 
171  }
172 
173  // Debug
174  const NumberOfDevices& devices = fec_cabling.countDevices();
175  std::stringstream ss;
176  ss << "[SiStripFedCablingBuilderFromDb::" << __func__ << "]"
177  << " Built SiStripFecCabling object with following devices:"
178  << std::endl << devices;
179  edm::LogVerbatim(mlCabling_) << ss.str() << endl;
180 
181 }
182 
183 // -----------------------------------------------------------------------------
220  SiStripFecCabling& fec_cabling ) {
222  << "[SiStripFedCablingBuilderFromDb::" << __func__ << "]"
223  << " Building FEC cabling from FED connections descriptions...";
224 
225  // ---------- Some initialization ----------
226 
227  //fec_cabling.clear(); //@@ Need to add method to "clear" FecCabling?
228 
229  // ---------- Retrieve connection descriptions from database ----------
230 
232  if ( conns.empty() ) {
234  << "[SiStripFedCablingBuilderFromDb::" << __func__ << "]"
235  << " Unable to build FEC cabling!"
236  << " No entries in FedConnections vector!";
237  return;
238  }
239 
240  // ---------- Retrieve DCU-DetId vector from database ----------
241 
243  << "[SiStripFedCablingBuilderFromDb::" << __func__ << "]"
244  << " Retrieving DCU-DetId vector from database...";
246  const SiStripConfigDb::DcuDetIdsV dcu_detid_vector( range.begin(), range.end() );
247  if ( !dcu_detid_vector.empty() ) {
249  << "[SiStripFedCablingBuilderFromDb::" << __func__ << "]"
250  << " Found " << dcu_detid_vector.size()
251  << " entries in DCU-DetId vector retrieved from database!";
252  } else {
254  << "[SiStripFedCablingBuilderFromDb::" << __func__ << "]"
255  << " No entries in DCU-DetId vector retrieved from database!";
256  }
257 
258  // ---------- Populate FEC cabling object with retrieved info ----------
259 
260  SiStripConfigDb::FedConnectionsV::const_iterator ifed = conns.begin();
261  SiStripConfigDb::FedConnectionsV::const_iterator jfed = conns.end();
262  for ( ; ifed != jfed; ++ifed ) {
263 
264  if ( !(*ifed) ) {
266  << "[SiStripFedCablingBuilderFromDb::" << __func__ << "]"
267  << " NULL pointer to FedConnection!";
268  continue;
269  }
270 
271  //uint16_t fec_id = static_cast<uint16_t>( (*ifed)->getFecHardwareId() );
272  uint16_t fec_crate = static_cast<uint16_t>( (*ifed)->getFecCrateId() + sistrip::FEC_CRATE_OFFSET ); //@@ temporary offset!
273  uint16_t fec_slot = static_cast<uint16_t>( (*ifed)->getFecSlot() );
274  uint16_t fec_ring = static_cast<uint16_t>( (*ifed)->getRingSlot() + sistrip::FEC_RING_OFFSET ); //@@ temporary offset!
275  uint16_t ccu_addr = static_cast<uint16_t>( (*ifed)->getCcuAddress() );
276  uint16_t ccu_chan = static_cast<uint16_t>( (*ifed)->getI2cChannel() );
277  uint16_t apv0 = static_cast<uint16_t>( (*ifed)->getApvAddress() );
278  uint16_t apv1 = apv0 + 1; //@@ needs implementing!
279  uint32_t dcu_id = static_cast<uint32_t>( (*ifed)->getDcuHardId() );
280  uint32_t det_id = 0; //@@ static_cast<uint32_t>( (*ifed)->getDetId() );
281  uint16_t npairs = 0; //@@ static_cast<uint16_t>( (*ifed)->getApvPairs() );
282  uint16_t fed_id = static_cast<uint16_t>( (*ifed)->getFedId() );
283  uint16_t fed_ch = static_cast<uint16_t>( (*ifed)->getFedChannel() );
284  uint16_t length = 0; //@@ static_cast<uint16_t>( (*ifed)->getFiberLength() );
285 
286  FedChannelConnection conn( fec_crate, fec_slot, fec_ring, ccu_addr, ccu_chan,
287  apv0, apv1,
288  dcu_id, det_id, npairs,
289  fed_id, fed_ch,
290  length );
291 
292  uint16_t fed_crate = sistrip::invalid_;
293  uint16_t fed_slot = sistrip::invalid_;
294  fed_crate = static_cast<uint16_t>( (*ifed)->getFedCrateId() );
295  fed_slot = static_cast<uint16_t>( (*ifed)->getFedSlot() );
296  conn.fedCrate( fed_crate );
297  conn.fedSlot( fed_slot );
298 
299  fec_cabling.addDevices( conn );
300 
301  }
302 
303  // ---------- Assign DCU and DetIds and then FED cabling ----------
304 
305  assignDcuAndDetIds( fec_cabling, dcu_detid_vector );
306 
307 }
308 
309 // -----------------------------------------------------------------------------
353  SiStripFecCabling& fec_cabling ) {
355  << "[SiStripFedCablingBuilderFromDb::" << __func__ << "]"
356  << " Building FEC cabling object from device descriptions...";
357 
358  // ---------- Some initialization ----------
359 
360  // fec_cabling.clear(); //@@ Need to add method to "clear" FecCabling?
361 
362  // ---------- Retrieve APV descriptions from database ----------
363 
365  << "[SiStripFedCablingBuilderFromDb::" << __func__ << "]"
366  << " Retrieving APV descriptions from database...";
368  if ( !apv_desc.empty() ) {
370  << "[SiStripFedCablingBuilderFromDb::" << __func__ << "]"
371  << " Retrieved " << apv_desc.size()
372  << " APV descriptions from database!";
373  } else {
375  << "[SiStripFedCablingBuilderFromDb::" << __func__ << "]"
376  << " Unable to build FEC cabling!"
377  << " No APV descriptions found!";
378  return;
379  }
380 
381  // ---------- Retrieve DCU descriptions from database ----------
382 
384  << "[SiStripFedCablingBuilderFromDb::" << __func__ << "]"
385  << " Retrieving DCU descriptions from database...";
387 
388  if ( !dcu_desc.empty() ) {
389 
390  uint16_t feh = 0;
391  uint16_t ccu = 0;
392  SiStripConfigDb::DeviceDescriptionsV::const_iterator idcu;
393  for ( idcu = dcu_desc.begin(); idcu != dcu_desc.end(); idcu++ ) {
394  dcuDescription* dcu = dynamic_cast<dcuDescription*>( *idcu );
395  if ( !dcu ) { continue; }
396  if ( dcu->getDcuType() == "FEH" ) { feh++; }
397  else { ccu++; }
398  }
399 
401  << "[SiStripFedCablingBuilderFromDb::" << __func__ << "]"
402  << " Retrieved " << feh
403  << " DCU-FEH descriptions from database!"
404  << " (and a further " << ccu << " DCUs for CCU modules, etc...)";
405 
406  } else {
408  << "[SiStripFedCablingBuilderFromDb::" << __func__ << "]"
409  << " No DCU descriptions found!";
410  }
411 
412  // ---------- Retrieve DCU-DetId vector from database ----------
413 
414 
416  << "[SiStripFedCablingBuilderFromDb::" << __func__ << "]"
417  << " Retrieving DCU-DetId vector from database...";
419  const SiStripConfigDb::DcuDetIdsV dcu_detid_vector( range.begin(), range.end() );
420  if ( !dcu_detid_vector.empty() ) {
422  << "[SiStripFedCablingBuilderFromDb::" << __func__ << "]"
423  << " Found " << dcu_detid_vector.size()
424  << " entries in DCU-DetId vector retrieved from database!";
425  } else {
427  << "[SiStripFedCablingBuilderFromDb::" << __func__ << "]"
428  << " No entries in DCU-DetId vector retrieved from database!";
429  }
430 
431  // ---------- Retrieve FED ids from database ----------
432 
434  << "[SiStripFedCablingBuilderFromDb::" << __func__ << "]"
435  << " Retrieving FED ids from database...";
436  SiStripConfigDb::FedIdsRange fed_ids = db->getFedIds();
437 
438  if ( !fed_ids.empty() ) {
440  << "[SiStripFedCablingBuilderFromDb::" << __func__ << "]"
441  << " Retrieved " << fed_ids.size()
442  << " FED ids from database!";
443  } else {
445  << "[SiStripFedCablingBuilderFromDb::" << __func__ << "]"
446  << " No FED ids found!";
447  }
448 
449  // ---------- Populate FEC cabling object with retrieved info ----------
450 
452  << "[SiStripFedCablingBuilderFromDb::" << __func__ << "]"
453  << " Building FEC cabling object from APV and DCU descriptions...";
454 
455  SiStripConfigDb::DeviceDescriptionsV::const_iterator iapv;
456  for ( iapv = apv_desc.begin(); iapv != apv_desc.end(); iapv++ ) {
457 
458  if ( !(*iapv) ) {
460  << "[SiStripFedCablingBuilderFromDb::" << __func__ << "]"
461  << " NULL pointer to DeviceDescription (of type APV25)!";
462  continue;
463  }
464 
467  addr.fecSlot_,
468  addr.fecRing_ + sistrip::FEC_RING_OFFSET, //@@ temp
469  addr.ccuAddr_,
470  addr.ccuChan_,
471  addr.i2cAddr_ );
472  fec_cabling.addDevices( conn );
473 
474  }
475 
476  SiStripConfigDb::DeviceDescriptionsV::const_iterator idcu;
477  for ( idcu = dcu_desc.begin(); idcu != dcu_desc.end(); idcu++ ) {
478 
479  if ( !(*idcu) ) {
481  << "[SiStripFedCablingBuilderFromDb::" << __func__ << "]"
482  << " NULL pointer to DeviceDescription (of type DCU)!";
483  continue;
484  }
485 
487  dcuDescription* dcu = dynamic_cast<dcuDescription*>( *idcu );
488  if ( !dcu ) { continue; }
489  if ( dcu->getDcuType() != "FEH" ) { continue; }
491  addr.fecSlot_,
492  addr.fecRing_ + sistrip::FEC_RING_OFFSET, //@@ temp,
493  addr.ccuAddr_,
494  addr.ccuChan_,
495  0, 0, // APV I2C addresses not used
496  dcu->getDcuHardId() );
497  fec_cabling.dcuId( conn );
498 
499  }
500 
502  << "[SiStripFedCablingBuilderFromDb::" << __func__ << "]"
503  << " Finished building FEC cabling object from APV and DCU descriptions!";
504 
505  NumberOfDevices devs1 = fec_cabling.countDevices();
506  std::stringstream ss1;
507  ss1 << "[SiStripFedCablingBuilderFromDb::" << __func__ << "]"
508  << " Number of devices in FEC cabling object:" << std::endl;
509  devs1.print(ss1);
510  LogTrace(mlCabling_) << ss1.str();
511 
512  // ---------- Counters used in assigning "dummy" FED ids and channels ----------
513 
514  std::vector<uint16_t>::const_iterator ifed = fed_ids.begin();
515  uint16_t fed_ch = 0;
516 
517  // ---------- Assign "dummy" FED crates/slots/ids/chans to constructed modules ----------
518 
519  std::vector<uint32_t> used_keys;
520 
522  << "[SiStripFedCablingBuilderFromDb::" << __func__ << "]"
523  << " Randomly assigning FED ids/channels to APV pairs in front-end modules...";
524 
525  if ( fed_ids.empty() ) {
527  << "[SiStripFedCablingBuilderFromDb::" << __func__ << "]"
528  << " No FED ids retrieved from database! Unable to cable system!";
529  } else {
530 
531  bool complete = false;
532  std::vector<SiStripFecCrate>::const_iterator icrate = fec_cabling.crates().begin();
533  std::vector<SiStripFecCrate>::const_iterator jcrate = fec_cabling.crates().end();
534  while ( !complete && icrate != jcrate ) {
535  std::vector<SiStripFec>::const_iterator ifec = icrate->fecs().begin();
536  std::vector<SiStripFec>::const_iterator jfec = icrate->fecs().end();
537  while ( !complete && ifec != jfec ) {
538  std::vector<SiStripRing>::const_iterator iring = ifec->rings().begin();
539  std::vector<SiStripRing>::const_iterator jring = ifec->rings().end();
540  while ( !complete && iring != jring ) {
541  std::vector<SiStripCcu>::const_iterator iccu = iring->ccus().begin();
542  std::vector<SiStripCcu>::const_iterator jccu = iring->ccus().end();
543  while ( !complete && iccu != jccu ) {
544  std::vector<SiStripModule>::const_iterator imod = iccu->modules().begin();
545  std::vector<SiStripModule>::const_iterator jmod = iccu->modules().end();
546  while ( !complete && imod != jmod ) {
547 
548  // Set number of APV pairs based on devices found
549  const_cast<SiStripModule&>(*imod).nApvPairs(0);
550 
551  used_keys.push_back( SiStripFecKey( imod->fecCrate(),
552  imod->fecSlot(),
553  imod->fecRing(),
554  imod->ccuAddr(),
555  imod->ccuChan() ).key() );
556 
557 // // Add middle LLD channel if missing (to guarantee all FED channels are cabled!)
558 // if ( imod->nApvPairs() == 2 ) {
559 // const_cast<SiStripModule&>(*imod).nApvPairs(3);
560 // FedChannelConnection temp( imod->fecCrate(),
561 // imod->fecSlot(),
562 // imod->fecRing(),
563 // imod->ccuAddr(),
564 // imod->ccuChan(),
565 // SiStripFecKey::i2cAddr(2,true),
566 // SiStripFecKey::i2cAddr(2,false) );
567 // const_cast<SiStripModule&>(*imod).addDevices( temp );
568 // }
569 // const_cast<SiStripModule&>(*imod).nApvPairs(0);
570 
571  // Iterate through APV pairs
572  for ( uint16_t ipair = 0; ipair < imod->nApvPairs(); ipair++ ) {
573 
574  // Check FED id and channel
575  if ( ifed == fed_ids.end() ) { fed_ch++; ifed = fed_ids.begin(); }
576  if ( fed_ch == 96 ) {
578  << "[SiStripFedCablingBuilderFromDb::" << __func__ << "]"
579  << " Insufficient FED channels to cable all devices in control system!";
580  complete = true;
581  break;
582  }
583 
584  // Set "dummy" FED id and channel
585  pair<uint16_t,uint16_t> addr = imod->activeApvPair( imod->lldChannel(ipair) );
586  SiStripModule::FedChannel fed_channel( (*ifed)/16+1, // 16 FEDs per crate, numbering starts from 1
587  (*ifed)%16+2, // FED slot starts from 2
588  *ifed,
589  fed_ch );
590  const_cast<SiStripModule&>(*imod).fedCh( addr.first, fed_channel );
591  ifed++;
592 
593  }
594 
595  imod++;
596  }
597  iccu++;
598  }
599  iring++;
600  }
601  ifec++;
602  }
603  icrate++;
604  }
605 
606  }
607 
608  std::sort( used_keys.begin(), used_keys.end() );
609 
610  NumberOfDevices devs2 = fec_cabling.countDevices();
611  std::stringstream ss2;
612  ss2 << "[SiStripFedCablingBuilderFromDb::" << __func__ << "]"
613  << " Number of devices in FEC cabling object:" << std::endl;
614  devs2.print(ss2);
615  LogTrace(mlCabling_) << ss2.str();
616 
618  << "[SiStripFedCablingBuilderFromDb::" << __func__ << "]"
619  << " Finished randomly assigning FED ids/channels to APV pairs in front-end modules...";
620 
621  // ---------- Assign "dummy" devices to remaining FED ids/chans ----------
622 
624  << "[SiStripFedCablingBuilderFromDb::" << __func__ << "]"
625  << " Assigning APV pairs in dummy front-end modules to any remaining \"uncabled\" FED ids/channels...";
626 
627  if ( fed_ids.empty() ) {
629  << "[SiStripFedCablingBuilderFromDb::" << __func__ << "]"
630  << " No FED ids retrieved from database! Unable to cable system!";
631  } else {
632 
633  uint16_t module = 0;
634  bool complete = false;
635  while ( !complete ) {
636  for ( uint16_t lld = sistrip::LLD_CHAN_MIN; lld < sistrip::LLD_CHAN_MAX+1; lld++ ) {
637 
638  // Check FED id and channel
639  if ( ifed == fed_ids.end() ) { fed_ch++; ifed = fed_ids.begin(); }
640  if ( fed_ch == 96 ) {
642  << "[SiStripFedCablingBuilderFromDb::" << __func__ << "]"
643  << " All FED channels are now cabled!";
644  complete = true;
645  break;
646  }
647 
648  // commented because key is not used
649  //uint32_t key = SiStripFecKey( fecCrate( module ),
650  // fecSlot( module ),
651  // fecRing( module ),
652  // ccuAddr( module ),
653  // ccuChan( module ) ).key();
654 
655  //if ( std::find( used_keys.begin(), used_keys.end(), key ) != used_keys.end() ) { break; }
656 
657  FedChannelConnection temp( fecCrate( module ),
658  fecSlot( module ),
659  fecRing( module ),
660  ccuAddr( module ),
661  ccuChan( module ),
662  SiStripFecKey::i2cAddr(lld,true),
663  SiStripFecKey::i2cAddr(lld,false),
666  3, // npairs
667  *ifed,
668  fed_ch );
669  uint16_t fed_crate = (*ifed)/16+1; // 16 FEDs per crate, numbering starts from 1
670  uint16_t fed_slot = (*ifed)%16+2; // FED slot starts from 2
671  temp.fedCrate( fed_crate );
672  temp.fedSlot( fed_slot );
673  fec_cabling.addDevices( temp );
674  ifed++;
675 
676  }
677  module++;
678  }
679 
680  }
681 
683  << "[SiStripFedCablingBuilderFromDb::" << __func__ << "]"
684  << " Finished assigning APV pairs in dummy front-end modules to any remaining \"uncabled\" FED ids/channels...";
685 
686  NumberOfDevices devs3 = fec_cabling.countDevices();
687  std::stringstream ss3;
688  ss3 << "[SiStripFedCablingBuilderFromDb::" << __func__ << "]"
689  << " Number of devices in FEC cabling object:" << std::endl;
690  devs3.print(ss3);
691  LogTrace(mlCabling_) << ss3.str();
692 
693  // ---------- Assign DCU and DetIds and then FED cabling ----------
694 
695  assignDcuAndDetIds( fec_cabling, dcu_detid_vector );
696 
697 }
698 
699 // -----------------------------------------------------------------------------
738  SiStripFecCabling& fec_cabling ) {
740  << "[SiStripFedCablingBuilderFromDb::" << __func__ << "]"
741  << " Building FEC cabling object from DetIds...";
742 
743  // ---------- Some initialization ----------
744 
745  // fec_cabling.clear();
746 
747  // chans_per_ring = chans_per_ccu * ccus_per_ring = 100 (TOB gives lower limit of 60)
748  uint32_t chans_per_ccu = 10;
749  uint32_t ccus_per_ring = 10;
750  uint32_t rings_per_fec = 8;
751  uint32_t fecs_per_crate = 11;
752 
753  // ---------- Retrieve necessary descriptions from database ----------
754 
755 
757  << "[SiStripFedCablingBuilderFromDb::" << __func__ << "]"
758  << " Retrieving DCU-DetId vector from database...";
760  const SiStripConfigDb::DcuDetIdsV dcu_detid_vector( range.begin(), range.end() );
761  if ( !dcu_detid_vector.empty() ) {
763  << "[SiStripFedCablingBuilderFromDb::" << __func__ << "]"
764  << " Found " << dcu_detid_vector.size()
765  << " entries in DCU-DetId vector retrieved from database!";
766  } else {
768  << "[SiStripFedCablingBuilderFromDb::" << __func__ << "]"
769  << " No entries in DCU-DetId vector retrieved from database!"
770  << " Unable to build FEC cabling!";
771  return;
772  }
773 
774  // ---------- Populate FEC cabling object with DCU, DetId and "dummy" control info ----------
775 
776  uint32_t imodule = 0;
777  SiStripConfigDb::DcuDetIdsV::const_iterator iter;
778  for ( iter = dcu_detid_vector.begin(); iter != dcu_detid_vector.end(); iter++ ) {
779 
780  if ( !(iter->second) ) {
782  << "[SiStripFedCablingBuilderFromDb::" << __func__ << "]"
783  << " NULL pointer to TkDcuInfo!";
784  continue;
785  }
786 
787  uint16_t fec_crate = ( imodule / ( chans_per_ccu * ccus_per_ring * rings_per_fec * fecs_per_crate ) ) + 1;
788  uint16_t fec_slot = ( imodule / ( chans_per_ccu * ccus_per_ring * rings_per_fec ) ) % fecs_per_crate + 2;
789  uint16_t fec_ring = ( imodule / ( chans_per_ccu * ccus_per_ring ) ) % rings_per_fec + 1;
790  uint16_t ccu_addr = ( imodule / ( chans_per_ccu) ) % ccus_per_ring + 1;
791  uint16_t ccu_chan = ( imodule ) % chans_per_ccu + 16;
792 
793  uint32_t dcu_id = iter->second->getDcuHardId(); //
794  uint32_t det_id = iter->second->getDetId();
795  uint16_t npairs = iter->second->getApvNumber()/2;
796  uint16_t length = (uint16_t) iter->second->getFibreLength(); //@@ should be double!
797 
798  // --- Check if DCU, DetId and nApvPairs are null ---
799 
800  if ( !dcu_id ) {
801  dcu_id = SiStripFecKey( fec_crate,
802  fec_slot,
803  fec_ring,
804  ccu_addr,
805  ccu_chan ).key();
806  }
807  if ( !det_id ) { det_id = 0xFFFF + imodule; }
808  if ( !npairs ) { npairs = rand()/2 ? 2 : 3; }
809 
810  // --- Construct FedChannelConnection objects ---
811 
812  for ( uint16_t ipair = 0; ipair < npairs; ipair++ ) {
813  uint16_t iapv = ( ipair == 1 && npairs == 2 ? 36 : 32 + 2 * ipair ) ;
814  FedChannelConnection conn( fec_crate,
815  fec_slot,
816  fec_ring,
817  ccu_addr,
818  ccu_chan,
819  iapv, iapv+1,
820  dcu_id, det_id, npairs,
821  0, 0, // FED id and channel
822  length,
823  true, true, true, true );
824  fec_cabling.addDevices( conn );
825  }
826 
827  imodule++;
828  }
829 
830  // ---------- Assign "dummy" FED ids/chans to Modules of FEC cabling object ----------
831 
832  uint32_t fed_id = 50;
833  uint32_t fed_ch = 0;
834  for ( vector<SiStripFecCrate>::const_iterator icrate = fec_cabling.crates().begin(); icrate != fec_cabling.crates().end(); icrate++ ) {
835  for ( vector<SiStripFec>::const_iterator ifec = icrate->fecs().begin(); ifec != icrate->fecs().end(); ifec++ ) {
836  for ( vector<SiStripRing>::const_iterator iring = ifec->rings().begin(); iring != ifec->rings().end(); iring++ ) {
837  for ( vector<SiStripCcu>::const_iterator iccu = iring->ccus().begin(); iccu != iring->ccus().end(); iccu++ ) {
838  for ( vector<SiStripModule>::const_iterator imod = iccu->modules().begin(); imod != iccu->modules().end(); imod++ ) {
839  if ( 96-fed_ch < imod->nApvPairs() ) { fed_id++; fed_ch = 0; } // move to next FED
840  for ( uint16_t ipair = 0; ipair < imod->nApvPairs(); ipair++ ) {
841  pair<uint16_t,uint16_t> addr = imod->activeApvPair( (*imod).lldChannel(ipair) );
842  SiStripModule::FedChannel fed_channel( (fed_id-50)/16+1, // 16 FEDs per crate, numbering starts from 1
843  (fed_id-50)%16+2, // FED slot starts from 2
844  fed_id,
845  fed_ch );
846  const_cast<SiStripModule&>(*imod).fedCh( addr.first, fed_channel );
847  fed_ch++;
848  }
849  }
850  }
851  }
852  }
853  }
854 
855 }
856 
857 // -----------------------------------------------------------------------------
860  std::vector< std::pair<uint32_t,TkDcuInfo*> > in ) {
861 
862  // ---------- Check if entries found in DCU-DetId vector ----------
863 
864  if ( in.empty() ) {
866  << "[SiStripFedCablingBuilderFromDb::" << __func__ << "]"
867  << " No entries in DCU-DetId vector!";
868  }
869 
870  // ---------- Assign DCU and DetId to Modules in FEC cabling object ----------
871 
873  << "[SiStripFedCablingBuilderFromDb::" << __func__ << "]"
874  << " Assigning DCU ids and DetIds to constructed modules...";
875 
876  uint16_t channels = 0;
877  uint16_t six = 0;
878  uint16_t four = 0;
879  uint16_t unknown = 0;
880  uint16_t missing = 0;
881 
882  for ( vector<SiStripFecCrate>::const_iterator icrate = fec_cabling.crates().begin(); icrate != fec_cabling.crates().end(); icrate++ ) {
883  for ( vector<SiStripFec>::const_iterator ifec = icrate->fecs().begin(); ifec != icrate->fecs().end(); ifec++ ) {
884  for ( vector<SiStripRing>::const_iterator iring = ifec->rings().begin(); iring != ifec->rings().end(); iring++ ) {
885  for ( vector<SiStripCcu>::const_iterator iccu = iring->ccus().begin(); iccu != iring->ccus().end(); iccu++ ) {
886  for ( vector<SiStripModule>::const_iterator imod = iccu->modules().begin(); imod != iccu->modules().end(); imod++ ) {
887  SiStripModule& module = const_cast<SiStripModule&>(*imod);
888 
889  //@@ TEMP FIX UNTIL LAURENT DEBUGS FedChannelConnectionDescription CLASS
890  module.nApvPairs(0);
891 
892  // --- Check for null DCU ---
893 
894  if ( !module.dcuId() ) {
895  SiStripFecKey path( icrate->fecCrate(),
896  ifec->fecSlot(),
897  iring->fecRing(),
898  iccu->ccuAddr(),
899  imod->ccuChan() );
900  uint32_t module_key = path.key();
901  module.dcuId( module_key ); // Assign DCU id equal to control key
902  stringstream ss;
903  ss << "[SiStripFedCablingBuilderFromDb::" << __func__ << "]"
904  << " Found NULL DcuId! Setting 'dummy' value based control key 0x"
905  << hex << setw(8) << setfill('0') << module_key << dec;
906  edm::LogWarning(mlCabling_) << ss.str();
907  }
908 
909  // --- Check for null DetId ---
910 
911  if ( !module.detId() ) {
912 
913  // --- Search for DcuId in map ---
914 
915  SiStripConfigDb::DcuDetIdsV::iterator iter = in.end();
916  iter = SiStripConfigDb::findDcuDetId( in.begin(), in.end(), module.dcuId() );
917  if ( iter != in.end() ) {
918 
919  if ( !(iter->second) ) {
921  << "[SiStripFedCablingBuilderFromDb::" << __func__ << "]"
922  << " NULL pointer to TkDcuInfo!";
923  continue;
924  }
925 
926  // --- Assign DetId and set nApvPairs based on APVs found in given Module ---
927 
928  module.detId( iter->second->getDetId() );
929  module.nApvPairs(0);
930 
931  // count expected channels
932  uint16_t pairs = iter->second->getApvNumber()/2;
933  channels += pairs;
934  if ( pairs == 2 ) { four++; }
935  else if ( pairs == 3 ) { six++; }
936  else { unknown++; }
937 
938  // --- Check number of APV pairs is valid and consistent with cached map ---
939 
940  if ( module.nApvPairs() != 2 && module.nApvPairs() != 3 ) {
941 
942  missing += ( iter->second->getApvNumber()/2 - module.nApvPairs() );
943  stringstream ss1;
944  ss1 << "[SiStripFedCablingBuilderFromDb::" << __func__ << "]" << std::endl
945  << " Module with DCU id 0x"
946  << hex << setw(8) << setfill('0') << module.dcuId() << dec
947  << " and DetId 0x"
948  << hex << setw(8) << setfill('0') << module.detId() << dec
949  << " has unexpected number of APV pairs ("
950  << module.nApvPairs() << ")." << std::endl
951  << " Some APV pairs may have not been detected by the FEC scan." << std::endl
952  << " Setting to value found in static map ("
953  << iter->second->getApvNumber()/2 << ")...";
954  edm::LogWarning(mlCabling_) << ss1.str();
955  module.nApvPairs( iter->second->getApvNumber()/2 );
956 
957  } else if ( module.nApvPairs() < iter->second->getApvNumber()/2 ) {
958 
959  missing += ( iter->second->getApvNumber()/2 - module.nApvPairs() );
960  stringstream ss2;
961  ss2 << "[SiStripFedCablingBuilderFromDb::" << __func__ << "]" << std::endl
962  << " Module with DCU id 0x"
963  << hex << setw(8) << setfill('0') << module.dcuId() << dec
964  << " and DetId 0x"
965  << hex << setw(8) << setfill('0') << module.detId() << dec
966  << " has number of APV pairs ("
967  << module.nApvPairs()
968  << ") that does not match value found in DCU-DetId vector ("
969  << iter->second->getApvNumber()/2 << ")." << std::endl
970  << " Some APV pairs may have not been detected by"
971  << " the FEC scan or the DCU-DetId vector may be incorrect." << std::endl
972  << " Setting to value found in static map ("
973  << iter->second->getApvNumber()/2 << ")...";
974  edm::LogWarning(mlCabling_) << ss2.str();
975  module.nApvPairs( iter->second->getApvNumber()/2 );
976 
977  }
978 
979  // --- Check for null fibre length ---
980 
981  if ( !module.length() ) {
982  module.length( static_cast<uint16_t>( iter->second->getFibreLength() ) );
983  }
984 
985  // --- Remove TkDcuInfo object from cached map ---
986 
987  in.erase( iter );
988 
989  } // Set for DCU in static table
990  } // Check for null DetId
991 
992  } // Module loop
993  } // CCU loop
994  } // FEC ring loop
995  } // FEC loop
996  } // FEC crate loop
997 
998  std::stringstream sss;
999  sss << "[SiStripFedCablingBuilderFromDb::" << __func__ << "]" << std::endl
1000  << " Connections in DCU-DetId map : " << channels << std::endl
1001  << " 4-APV modules : " << four << std::endl
1002  << " 6-APV modules : " << six << std::endl
1003  << " Unknown number of APV pairs : " << unknown << std::endl
1004  << " Total found APV pairs : " << ( channels - missing ) << std::endl
1005  << " Total missing APV pairs : " << missing << std::endl;
1006  edm::LogVerbatim(mlCabling_) << sss.str();
1007 
1009  << "[SiStripFedCablingBuilderFromDb::" << __func__ << "]"
1010  << " Finished assigning DCU ids and DetIds to constructed modules...";
1011 
1012  // ---------- "Randomly" assign DetIds to Modules with DCU ids not found in static table ----------
1013 
1015  << "[SiStripFedCablingBuilderFromDb::" << __func__ << "]"
1016  << " Assigning \"random\" DetIds to modules with DCU ids not found in static table...";
1017 
1018  uint32_t detid = 0x10000; // Incremented "dummy" DetId
1019  for ( vector<SiStripFecCrate>::const_iterator icrate = fec_cabling.crates().begin(); icrate != fec_cabling.crates().end(); icrate++ ) {
1020  for ( vector<SiStripFec>::const_iterator ifec = icrate->fecs().begin(); ifec != icrate->fecs().end(); ifec++ ) {
1021  for ( vector<SiStripRing>::const_iterator iring = ifec->rings().begin(); iring != ifec->rings().end(); iring++ ) {
1022  for ( vector<SiStripCcu>::const_iterator iccu = iring->ccus().begin(); iccu != iring->ccus().end(); iccu++ ) {
1023  for ( vector<SiStripModule>::const_iterator imod = iccu->modules().begin(); imod != iccu->modules().end(); imod++ ) {
1024  SiStripModule& module = const_cast<SiStripModule&>(*imod);
1025 
1026  // --- Check for null DetId and search for DCU in cached map ---
1027 
1028  if ( !module.detId() ) {
1029 
1030  SiStripConfigDb::DcuDetIdsV::iterator iter = in.end();
1031  iter = SiStripConfigDb::findDcuDetId( in.begin(), in.end(), module.dcuId() );
1032  if ( iter != in.end() ) {
1033 
1034  // --- Search for "random" module with consistent number of APV pairs ---
1035 
1036  SiStripConfigDb::DcuDetIdsV::iterator idcu;
1037  if ( in.empty() ) { idcu = in.end(); }
1038  else {
1039  idcu = in.begin();
1040  while ( idcu != in.end() ) {
1041  if ( idcu->second ) {
1042  if ( static_cast<uint32_t>(idcu->second->getApvNumber()) ==
1043  static_cast<uint32_t>(2*module.nApvPairs()) ) { break; }
1044  }
1045  idcu++;
1046  }
1047  }
1048 
1049  // --- Assign "random" DetId if number of APV pairs is consistent ---
1050 
1051  if ( idcu != in.end() ) {
1052 
1053  if ( !(idcu->second) ) {
1055  << "[SiStripFedCablingBuilderFromDb::" << __func__ << "]"
1056  << " NULL pointer to TkDcuInfo!";
1057  continue;
1058  }
1059 
1060  module.detId( idcu->second->getDetId() );
1061  in.erase( idcu );
1062 
1063  stringstream ss;
1064  ss << "[SiStripFedCablingBuilderFromDb::" << __func__ << "]"
1065  << " Did not find module with DCU id 0x"
1066  << hex << setw(8) << setfill('0') << module.dcuId() << dec
1067  << " in DCU-DetId vector!" << endl
1068  << " Assigned 'random' DetId 0x"
1069  << hex << setw(8) << setfill('0') << module.detId() << dec;
1070  edm::LogWarning(mlCabling_) << ss.str();
1071 
1072  } else { // --- Else, assign "dummy" DetId based on counter ---
1073 
1074  // If no match found, then assign DetId using incremented counter
1075  module.detId( detid );
1076  detid++;
1077 
1078  stringstream ss;
1079  if ( in.empty() ) {
1080  ss << "[SiStripFedCablingBuilderFromDb::" << __func__ << "]"
1081  << " Did not find module with DCU id 0x"
1082  << hex << setw(8) << setfill('0') << module.dcuId() << dec
1083  << " in DCU-DetId vector!"
1084  << " Could not assign 'random' DetId as DCU-DetID map is empty!"
1085  << " Assigned DetId based on incremented counter, with value 0x"
1086  << hex << setw(8) << setfill('0') << module.detId() << dec;
1087  } else {
1088  ss << "[SiStripFedCablingBuilderFromDb::" << __func__ << "]"
1089  << " Did not find module with DCU id 0x"
1090  << hex << setw(8) << setfill('0') << module.dcuId() << dec
1091  << " in DCU-DetId vector!"
1092  << " Could not assign 'random' DetId as no modules had appropriate number of APV pairs ("
1093  << module.nApvPairs()
1094  << "). Assigned DetId based on incremented counter, with value 0x"
1095  << hex << setw(8) << setfill('0') << module.detId() << dec;
1096  }
1097  edm::LogWarning(mlCabling_) << ss.str();
1098 
1099  }
1100  }
1101 
1102  }
1103 
1104  } // Module loop
1105  } // CCU loop
1106  } // FEC ring loop
1107  } // FEC loop
1108  } // FEC crate loop
1109 
1111  << "[SiStripFedCablingBuilderFromDb::" << __func__ << "]"
1112  << " Finished assigning \"random\" DetIds to modules with DCU ids not found in static table...";
1113 
1115  << "[SiStripFedCablingBuilderFromDb::" << __func__ << "]"
1116  << " Assigning \"random\" DetIds to modules with DCU ids not found in static table...";
1117 
1118  // ---------- Check for unassigned DetIds ----------
1119 
1120  if ( !in.empty() ) {
1121  stringstream ss;
1122  ss << "[SiStripFedCablingBuilderFromDb::" << __func__ << "]"
1123  << " Not all DetIds have been assigned to a DcuId! "
1124  << in.size() << " DetIds are unassigned!";
1125  edm::LogWarning(mlCabling_) << ss.str();
1126  }
1127 
1128 }
1129 
1130 // -----------------------------------------------------------------------------
1133  SiStripFedCabling& fed_cabling ) {
1134  vector<FedChannelConnection> conns;
1135  fec_cabling.connections( conns );
1136  fed_cabling.buildFedCabling( conns );
1137 }
1138 
1139 // -----------------------------------------------------------------------------
1142  SiStripFecCabling& fec_cabling ) {
1143  fec_cabling.buildFecCabling( fed_cabling );
1144 }
1145 
1146 // -----------------------------------------------------------------------------
1147 //
1149  const edm::IOVSyncValue& iov_sync,
1150  edm::ValidityInterval& iov_validity ) {
1151  edm::ValidityInterval infinity( iov_sync.beginOfTime(), iov_sync.endOfTime() );
1152  iov_validity = infinity;
1153 }
1154 
Device and connection information at the level of a front-end module.
Definition: SiStripModule.h:25
dictionary missing
Definition: combine.py:4
static void assignDcuAndDetIds(SiStripFecCabling &, std::vector< std::pair< uint32_t, TkDcuInfo * > >)
T getUntrackedParameter(std::string const &, T const &) const
static uint16_t ccuAddr(const uint16_t &nth_module)
void print(std::stringstream &) const
static uint16_t fecCrate(const uint16_t &nth_module)
DcuDetIds::range DcuDetIdsRange
static void buildFecCablingFromDetIds(SiStripConfigDb *const, SiStripFecCabling &)
DeviceFactory *const deviceFactory(std::string method_name="") const
static const uint32_t invalid32_
Definition: Constants.h:16
static const uint16_t LLD_CHAN_MIN
static const uint16_t LLD_CHAN_MAX
void addDevices(const FedChannelConnection &conn)
static const uint16_t FEC_RING_OFFSET
static const IOVSyncValue & endOfTime()
Definition: IOVSyncValue.cc:97
tuple db
Definition: EcalCondDB.py:151
const std::vector< SiStripFecCrate > & crates() const
SiStripFedCablingBuilderFromDb(const edm::ParameterSet &)
static uint16_t fecSlot(const uint16_t &nth_module)
static uint16_t fecRing(const uint16_t &nth_module)
virtual void setIntervalFor(const edm::eventsetup::EventSetupRecordKey &, const edm::IOVSyncValue &, edm::ValidityInterval &)
const uint16_t & i2cAddr() const
FedConnections::range FedConnectionsRange
const uint32_t & key() const
Definition: SiStripKey.h:126
int path() const
Definition: HLTadd.h:3
Utility class that identifies a position within the strip tracker control structure, down to the level of an APV25.
Definition: SiStripFecKey.h:46
static void getFecCabling(const SiStripFedCabling &in, SiStripFecCabling &out)
static const char mlCabling_[]
virtual SiStripFedCabling * make(const SiStripFedCablingRcd &)
const uint16_t & length() const
void buildFedCabling(const std::vector< FedChannelConnection > &)
static DcuDetIdsV::const_iterator findDcuDetId(DcuDetIdsV::const_iterator begin, DcuDetIdsV::const_iterator end, uint32_t dcu_id)
Definition: DcuDetIds.cc:396
static const IOVSyncValue & beginOfTime()
void connections(std::vector< FedChannelConnection > &) const
const uint16_t & fedSlot() 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
FedConnectionsRange getFedConnections(std::string partition="")
void dcuId(const FedChannelConnection &conn)
An interface class to the DeviceFactory.
const double infinity
virtual void writeFedCablingToCondDb(const SiStripFedCabling &)
FedIdsRange getFedIds(std::string partition="")
Abstract base class for producer of SiStripFedCabling record.
DeviceAddress deviceAddress(const deviceDescription &)
void buildFecCabling(const SiStripFedCabling &)
#define LogTrace(id)
Simple container class for counting devices.
DbClient *const databaseCache(std::string method_name="") const
static uint16_t ccuChan(const uint16_t &nth_module)
static void getFedCabling(const SiStripFecCabling &in, SiStripFedCabling &out)
const uint16_t & nApvPairs() const
const uint32_t & dcuId() const
std::vector< DcuDetId > DcuDetIdsV
static const uint16_t invalid_
Definition: Constants.h:17
const uint32_t & detId() const
Contains cabling info at the device level, including DetId, APV pair numbers, hardware addresses...
const uint16_t & fedCrate() const
boost::iterator_range< FedIds::const_iterator > FedIdsRange
static std::string cablingSource(const sistrip::CablingSource &)
list key
Definition: combine.py:13
static const uint16_t FEC_CRATE_OFFSET
Signal rand(Signal arg)
Definition: vlib.cc:442
FedChannel fedCh(const uint16_t &apv_pair_num) const
static void buildFecCablingFromFedConnections(SiStripConfigDb *const, SiStripFecCabling &)
DeviceDescriptionsRange getDeviceDescriptions(std::string partition="")
DcuDetIdsRange getDcuDetIds(std::string partition="")
Definition: DcuDetIds.cc:11
Definition: vlib.h:209
NumberOfDevices countDevices() const
static void buildFecCablingFromDevices(SiStripConfigDb *const, SiStripFecCabling &)