CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
SiStripFecCabling.cc
Go to the documentation of this file.
1 
6 #include <iostream>
7 #include <iomanip>
8 
9 using namespace sistrip;
10 
11 // -----------------------------------------------------------------------------
12 //
14  : crates_()
15 {
17  << "[SiStripFecCabling::" << __func__ << "]"
18  << " Constructing object...";
19  crates_.reserve(4);
20  buildFecCabling( fed_cabling );
21 }
22 
23 // -----------------------------------------------------------------------------
24 //
27  << "[SiStripFecCabling::" << __func__ << "]"
28  << " Building FEC cabling...";
29 
30  // Retrieve and iterate through FED ids
31  auto feds = fed_cabling.fedIds();
32  for ( auto ifed = feds.begin(); ifed != feds.end(); ifed++ ) {
33 
34  // Retrieve and iterate through FED channel connections
35  auto conns = fed_cabling.fedConnections( *ifed );
36  for ( auto iconn = conns.begin(); iconn != conns.end(); iconn++ ) {
37 
38  // Check that FED id is not invalid and add devices
39  if ( iconn->fedId() != sistrip::invalid_ ) { addDevices( *iconn ); }
40 
41  }
42  }
43 
44  // Consistency checks
45  for ( std::vector<SiStripFecCrate>::const_iterator icrate = this->crates().begin(); icrate != this->crates().end(); ++icrate ) {
46  for ( std::vector<SiStripFec>::const_iterator ifec = icrate->fecs().begin(); ifec != icrate->fecs().end(); ++ifec ) {
47  for ( std::vector<SiStripRing>::const_iterator iring = ifec->rings().begin(); iring != ifec->rings().end(); ++iring ) {
48  for ( std::vector<SiStripCcu>::const_iterator iccu = iring->ccus().begin(); iccu != iring->ccus().end(); ++iccu ) {
49  for ( std::vector<SiStripModule>::const_iterator imod = iccu->modules().begin(); imod != iccu->modules().end(); ++imod ) {
50  //@@ need consistency checks here!
51  }
52  }
53  }
54  }
55  }
57  << "[SiStripFecCabling::" << __func__ << "]"
58  << " Finished building FEC cabling";
59 }
60 
61 // -----------------------------------------------------------------------------
62 //
64  auto icrate = crates_.begin();
65  while ( icrate != crates_.end() && (*icrate).fecCrate() != conn.fecCrate() ) { icrate++; }
66  if ( icrate == crates_.end() ) {
67  crates_.push_back( SiStripFecCrate( conn ) );
68  } else {
69  icrate->addDevices( conn );
70  }
71 }
72 
73 // -----------------------------------------------------------------------------
74 //
75 void SiStripFecCabling::connections( std::vector<FedChannelConnection>& conns ) const {
77  << "[SiStripFecCabling::" << __func__ << "]"
78  << " Building vector of FedChannelConnection objects...";
79  conns.clear();
80  for ( std::vector<SiStripFecCrate>::const_iterator icrate = this->crates().begin(); icrate != this->crates().end(); ++icrate ) {
81  for ( std::vector<SiStripFec>::const_iterator ifec = icrate->fecs().begin(); ifec != icrate->fecs().end(); ++ifec ) {
82  for ( std::vector<SiStripRing>::const_iterator iring = ifec->rings().begin(); iring != ifec->rings().end(); ++iring ) {
83  for ( std::vector<SiStripCcu>::const_iterator iccu = iring->ccus().begin(); iccu != iring->ccus().end(); ++iccu ) {
84  for ( std::vector<SiStripModule>::const_iterator imod = iccu->modules().begin(); imod != iccu->modules().end(); ++imod ) {
85  for ( uint16_t ipair = 0; ipair < imod->nApvPairs(); ipair++ ) {
86  conns.push_back( FedChannelConnection( icrate->fecCrate(),
87  ifec->fecSlot(),
88  iring->fecRing(),
89  iccu->ccuAddr(),
90  imod->ccuChan(),
91  imod->activeApvPair( imod->lldChannel(ipair) ).first,
92  imod->activeApvPair( imod->lldChannel(ipair) ).second,
93  imod->dcuId(),
94  imod->detId(),
95  imod->nApvPairs(),
96  imod->fedCh(ipair).fedId_,
97  imod->fedCh(ipair).fedCh_,
98  imod->length(),
99  imod->dcu(),
100  imod->pll(),
101  imod->mux(),
102  imod->lld() ) );
103  uint16_t fed_crate = imod->fedCh(ipair).fedCrate_;
104  uint16_t fed_slot = imod->fedCh(ipair).fedSlot_;
105  conns.back().fedCrate( fed_crate );
106  conns.back().fedSlot( fed_slot );
107  }
108  }
109  }
110  }
111  }
112  }
113 }
114 
115 // -----------------------------------------------------------------------------
116 //
117 namespace {
118  // Using a template allows the const and non-const version to share the same code
119  template<typename T>
120  auto moduleFrom( T& crates, const FedChannelConnection& conn ) -> decltype(& (crates[0].fecs()[0].rings()[0].ccus()[0].modules()[0])) {
121  std::stringstream ss;
122  auto icrate = crates.begin();
123  while ( icrate != crates.end() && icrate->fecCrate() != conn.fecCrate() ) { icrate++; }
124  if ( icrate != crates.end() ) {
125  auto ifec = icrate->fecs().begin();
126  while ( ifec != icrate->fecs().end() && ifec->fecSlot() != conn.fecSlot() ) { ifec++; }
127  if ( ifec != icrate->fecs().end() ) {
128  auto iring = ifec->rings().begin();
129  while ( iring != ifec->rings().end() && iring->fecRing() != conn.fecRing() ) { iring++; }
130  if ( iring != ifec->rings().end() ) {
131  auto iccu = iring->ccus().begin();
132  while ( iccu != iring->ccus().end() && iccu->ccuAddr() != conn.ccuAddr() ) { iccu++; }
133  if ( iccu != iring->ccus().end() ) {
134  auto imod = iccu->modules().begin();
135  while ( imod != iccu->modules().end() && imod->ccuChan() != conn.ccuChan() ) { imod++; }
136  if ( imod != iccu->modules().end() ) {
137  return &(*imod);
138  } else {
139  ss << "[SiStripFecCabling::" << __func__ << "]"
140  << " CCU channel " << conn.ccuChan()
141  << " not found!"; }
142  } else {
143  ss << "[SiStripFecCabling::" << __func__ << "]"
144  << " CCU address " << conn.ccuAddr()
145  << " not found!"; }
146  } else {
147  ss << "[SiStripFecCabling::" << __func__ << "]"
148  << " FEC ring " << conn.fecRing()
149  << " not found!"; }
150  } else {
151  ss << "[SiStripFecCabling::" << __func__ << "]"
152  << " FEC slot " << conn.fecSlot()
153  << " not found!"; }
154  } else {
155  ss << "[SiStripFecCabling::" << __func__ << "]"
156  << " FEC crate " << conn.fecCrate()
157  << " not found!";
158  }
159 
160  if ( !ss.str().empty() ) { edm::LogWarning(mlCabling_) << ss.str(); }
161  return nullptr;
162  }
163 }
164 
166  auto module = moduleFrom(crates(), conn);
167  if(module) {
168  return *module;
169  }
170 
171  static const SiStripModule s_module{FedChannelConnection{}};
172  return s_module;
173 }
174 
176  return moduleFrom(crates(), conn);
177 }
178 
179 
180 // -----------------------------------------------------------------------------
181 //
182 const SiStripModule& SiStripFecCabling::module( const uint32_t& dcu_id ) const {
183  for ( std::vector<SiStripFecCrate>::const_iterator icrate = this->crates().begin(); icrate != this->crates().end(); ++icrate ) {
184  for ( std::vector<SiStripFec>::const_iterator ifec = icrate->fecs().begin(); ifec != icrate->fecs().end(); ++ifec ) {
185  for ( std::vector<SiStripRing>::const_iterator iring = ifec->rings().begin(); iring != ifec->rings().end(); ++iring ) {
186  for ( std::vector<SiStripCcu>::const_iterator iccu = iring->ccus().begin(); iccu != iring->ccus().end(); ++iccu ) {
187  for ( std::vector<SiStripModule>::const_iterator imod = iccu->modules().begin(); imod != iccu->modules().end(); ++imod ) {
188  if ( (*imod).dcuId() == dcu_id ) { return *imod; }
189  }
190  }
191  }
192  }
193  }
194  static const SiStripModule module{FedChannelConnection{}};
195  return module;
196 }
197 
198 // -----------------------------------------------------------------------------
199 //
201 
202  NumberOfDevices num_of_devices; // simple container class used for counting
203 
204  std::vector<uint16_t> fed_crates;
205  std::vector<uint16_t> fed_slots;
206  std::vector<uint16_t> fed_ids;
207  for ( std::vector<SiStripFecCrate>::const_iterator icrate = this->crates().begin(); icrate != this->crates().end(); ++icrate ) {
208  for ( std::vector<SiStripFec>::const_iterator ifec = icrate->fecs().begin(); ifec != icrate->fecs().end(); ++ifec ) {
209  for ( std::vector<SiStripRing>::const_iterator iring = ifec->rings().begin(); iring != ifec->rings().end(); ++iring ) {
210  for ( std::vector<SiStripCcu>::const_iterator iccu = iring->ccus().begin(); iccu != iring->ccus().end(); ++iccu ) {
211  for ( std::vector<SiStripModule>::const_iterator imod = iccu->modules().begin(); imod != iccu->modules().end(); ++imod ) {
212 
213  // APVs
214  if ( imod->activeApv(32) ) { num_of_devices.nApvs_++; }
215  if ( imod->activeApv(33) ) { num_of_devices.nApvs_++; }
216  if ( imod->activeApv(34) ) { num_of_devices.nApvs_++; }
217  if ( imod->activeApv(35) ) { num_of_devices.nApvs_++; }
218  if ( imod->activeApv(36) ) { num_of_devices.nApvs_++; }
219  if ( imod->activeApv(37) ) { num_of_devices.nApvs_++; }
220  if ( imod->dcuId() ) { num_of_devices.nDcuIds_++; }
221  if ( imod->detId() ) { num_of_devices.nDetIds_++; }
222 
223  // APV pairs
224  num_of_devices.nApvPairs_ += imod->nApvPairs();
225  if ( imod->nApvPairs() == 0 ) { num_of_devices.nApvPairs0_++; }
226  else if ( imod->nApvPairs() == 1 ) { num_of_devices.nApvPairs1_++; }
227  else if ( imod->nApvPairs() == 2 ) { num_of_devices.nApvPairs2_++; }
228  else if ( imod->nApvPairs() == 3 ) { num_of_devices.nApvPairs3_++; }
229  else { num_of_devices.nApvPairsX_++; }
230 
231  // FED crates, slots, ids, channels
232  for ( uint16_t ipair = 0; ipair < imod->nApvPairs(); ipair++ ) {
233 
234  uint16_t fed_crate = imod->fedCh(ipair).fedCrate_;
235  uint16_t fed_slot = imod->fedCh(ipair).fedSlot_;
236  uint16_t fed_id = imod->fedCh(ipair).fedId_;
237 
238  if ( fed_id ) {
239 
240  num_of_devices.nFedChans_++;
241 
242  std::vector<uint16_t>::iterator icrate = find( fed_crates.begin(), fed_crates.end(), fed_crate );
243  if ( icrate == fed_crates.end() ) {
244  num_of_devices.nFedCrates_++;
245  fed_crates.push_back(fed_crate);
246  }
247 
248  std::vector<uint16_t>::iterator islot = find( fed_slots.begin(), fed_slots.end(), fed_slot );
249  if ( islot == fed_slots.end() ) {
250  num_of_devices.nFedSlots_++;
251  fed_slots.push_back(fed_slot);
252  }
253 
254  std::vector<uint16_t>::iterator ifed = find( fed_ids.begin(), fed_ids.end(), fed_id );
255  if ( ifed == fed_ids.end() ) {
256  num_of_devices.nFedIds_++;
257  fed_ids.push_back(fed_id);
258  }
259 
260  }
261 
262  }
263 
264  // FE devices
265  if ( imod->dcu() ) { num_of_devices.nDcus_++; }
266  if ( imod->mux() ) { num_of_devices.nMuxes_++; }
267  if ( imod->pll() ) { num_of_devices.nPlls_++; }
268  if ( imod->lld() ) { num_of_devices.nLlds_++; }
269 
270  // FE modules
271  num_of_devices.nCcuChans_++;
272  }
273  num_of_devices.nCcuAddrs_++;
274  }
275  num_of_devices.nFecRings_++;
276  }
277  num_of_devices.nFecSlots_++;
278  }
279  num_of_devices.nFecCrates_++;
280  }
281 
282  return num_of_devices;
283 
284 }
285 
286 // -----------------------------------------------------------------------------
287 //
288 void SiStripFecCabling::print( std::stringstream& ss ) const {
289  uint32_t valid = 0;
290  uint32_t total = 0;
291  ss << "[SiStripFecCabling::" << __func__ << "] Printing FEC cabling:" << std::endl;
292  ss << "Printing cabling for " << crates().size() << " crates" << std::endl;
293  for ( std::vector<SiStripFecCrate>::const_iterator icrate = crates().begin(); icrate != crates().end(); ++icrate ) {
294  ss << "Printing cabling for " << icrate->fecs().size() << " FECs for crate " << icrate->fecCrate() << std::endl;
295  for ( std::vector<SiStripFec>::const_iterator ifec = icrate->fecs().begin(); ifec != icrate->fecs().end(); ++ifec ) {
296  ss << "Printing cabling for " << ifec->rings().size() << " rings for FEC " << ifec->fecSlot() << std::endl;
297  for ( std::vector<SiStripRing>::const_iterator iring = ifec->rings().begin(); iring != ifec->rings().end(); ++iring ) {
298  ss << "Printing cabling for " << iring->ccus().size() << " CCUs for ring " << iring->fecRing() << std::endl;
299  for ( std::vector<SiStripCcu>::const_iterator iccu = iring->ccus().begin(); iccu != iring->ccus().end(); ++iccu ) {
300  ss << "Printing cabling for " << iccu->modules().size() << " modules for CCU " << iccu->ccuAddr() << std::endl;
301  for ( std::vector<SiStripModule>::const_iterator imod = iccu->modules().begin(); imod != iccu->modules().end(); ++imod ) {
302 
303  SiStripModule::FedCabling conns = imod->fedChannels();
304  SiStripModule::FedCabling::const_iterator ii = conns.begin();
305  SiStripModule::FedCabling::const_iterator jj = conns.end();
306  for ( ; ii != jj; ++ii ) {
307  if ( ii->second.fedId_ != sistrip::invalid_ &&
308  ii->second.fedCh_ != sistrip::invalid_ ) { valid++; }
309  total++;
310  }
311  ss << *imod << std::endl;
312  }
313  }
314  }
315  }
316  }
317  ss << "Number of connected: " << valid << std::endl
318  << "Number of connections: " << total << std::endl;
319 }
320 
321 // -----------------------------------------------------------------------------
322 //
323 void SiStripFecCabling::terse( std::stringstream& ss ) const {
324  ss << "[SiStripFecCabling::" << __func__ << "] Printing FEC cabling:" << std::endl;
325  for ( std::vector<SiStripFecCrate>::const_iterator icrate = crates().begin(); icrate != crates().end(); ++icrate ) {
326  for ( std::vector<SiStripFec>::const_iterator ifec = icrate->fecs().begin(); ifec != icrate->fecs().end(); ++ifec ) {
327  for ( std::vector<SiStripRing>::const_iterator iring = ifec->rings().begin(); iring != ifec->rings().end(); ++iring ) {
328  for ( std::vector<SiStripCcu>::const_iterator iccu = iring->ccus().begin(); iccu != iring->ccus().end(); ++iccu ) {
329  for ( std::vector<SiStripModule>::const_iterator imod = iccu->modules().begin(); imod != iccu->modules().end(); ++imod ) {
330  imod->terse(ss);
331  ss << std::endl;
332  }
333  }
334  }
335  }
336  }
337 }
338 
339 // -----------------------------------------------------------------------------
340 //
341 std::ostream& operator<< ( std::ostream& os, const SiStripFecCabling& cabling ) {
342  std::stringstream ss;
343  cabling.print(ss);
344  os << ss.str();
345  return os;
346 }
Device and connection information at the level of a front-end module.
Definition: SiStripModule.h:24
const uint16_t & fecCrate() const
uint32_t nFecCrates_
const SiStripModule & module(const FedChannelConnection &conn) const
void addDevices(const FedChannelConnection &conn)
std::vector< SiStripFecCrate > crates_
void terse(std::stringstream &) const
const std::vector< SiStripFecCrate > & crates() const
std::ostream & operator<<(std::ostream &out, const ALILine &li)
Definition: ALILine.cc:187
int ii
Definition: cuy.py:588
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
U second(std::pair< T, U > const &p)
static const char mlCabling_[]
void connections(std::vector< FedChannelConnection > &) const
Class containning control, module, detector and connection information, at the level of a FED channel...
FedsConstIterRange fedIds() const
uint32_t nApvPairs3_
void print(std::stringstream &) const
void buildFecCabling(const SiStripFedCabling &)
#define LogTrace(id)
uint32_t nApvPairsX_
uint32_t nApvPairs0_
Simple container class for counting devices.
static const uint16_t invalid_
Definition: Constants.h:16
uint32_t nApvPairs2_
ConnsConstIterRange fedConnections(uint16_t fed_id) const
Contains cabling info at the device level, including DetId, APV pair numbers, hardware addresses...
#define begin
Definition: vmac.h:30
std::map< uint16_t, FedChannel > FedCabling
Definition: SiStripModule.h:59
uint32_t nApvPairs1_
uint32_t nFedCrates_
long double T
Definition: vlib.h:208
NumberOfDevices countDevices() const