CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
SiStripFedCabling.cc
Go to the documentation of this file.
5 #include <iostream>
6 #include <iomanip>
7 
8 using namespace sistrip;
9 
10 
11 // -----------------------------------------------------------------------------
12 //
14  : feds_(),
15  registry_(),
16  connections_(),
17  detected_(),
18  undetected_()
19 {
21  << "[SiStripFedCabling::" << __func__ << "]"
22  << " Constructing object from connection range...";
23  buildFedCabling( input );
24 }
25 
26 // -----------------------------------------------------------------------------
27 //
29  : feds_( input.feds_ ),
30  registry_( input.registry_ ),
31  connections_( input.connections_ ),
32  detected_( input.detected_ ),
33  undetected_( input.undetected_ )
34 {
36  << "[SiStripFedCabling::" << __func__ << "]"
37  << " Copy constructing object...";
38 }
39 
40 // -----------------------------------------------------------------------------
41 //
43  : feds_(),
44  registry_(),
45  connections_(),
46  detected_(),
47  undetected_()
48 {
50  << "[SiStripFedCabling::" << __func__ << "]"
51  << " Default constructing object...";
52 }
53 
54 // -----------------------------------------------------------------------------
55 //
58  << "[SiStripFedCabling::" << __func__ << "]"
59  << " Destructing object...";
60 }
61 
62 // -----------------------------------------------------------------------------
63 //
65 
66  // Check input
67  if ( input.empty() ) {
69  << "[SiStripFedCabling::" << __func__ << "]"
70  << " Input vector of FedChannelConnections is of zero size!"
71  << " Unable to populate FED cabling object!";
72  return;
73  }
74 
75  std::stringstream ss;
76  ss << "[SiStripFedCabling::" << __func__ << "]"
77  << " Building FED cabling from "
78  << input.size()
79  << " connections...";
80  LogTrace(mlCabling_) << ss.str();
81 
82  // Sort input vector by FED id and channel
83  Conns temp( input.size() );
84  std::copy( input.begin(), input.end(), temp.begin() );
85  std::sort( temp.begin(), temp.end() );
86 
87  // Strip FED ids
88  uint16_t min_id = static_cast<uint16_t>( FEDNumbering::MINSiStripFEDID );
89  uint16_t max_id = static_cast<uint16_t>( FEDNumbering::MAXSiStripFEDID );
90  uint16_t nfeds = max_id - min_id + 1;
91 
92  // Initialise containers
93  connections_.clear();
94  connections_.reserve( 96 * nfeds );
95  registry_.clear();
96  feds_.clear();
97  registry_.resize( nfeds, ConnsRange::emptyPair() );
98 
99  // Populate container
100  ConnsIter ii = temp.begin();
101  ConnsIter jj = temp.end();
102  for ( ; ii != jj; ++ii ) {
103 
104  uint16_t fed_id = ii->fedId();
105  uint16_t fed_ch = ii->fedCh();
106  uint16_t index = fed_id - min_id;
107 
108  if ( fed_id < min_id || fed_id > max_id ) { continue; }
109  if ( index >= registry_.size() ) { continue; }
110  if ( !ii->isConnected() ) { continue; }
111 
112  FedsConstIter iter = find( feds_.begin(), feds_.end(), fed_id );
113  if ( iter == feds_.end() ) { feds_.push_back( fed_id ); }
114 
115  if ( registry_[index] == ConnsRange::emptyPair() ) {
116  ConnsPair conns_pair;
117  conns_pair.first = std::distance( connections_.begin(), connections_.end() );
118  connections_.insert( connections_.end(), 96, FedChannelConnection() );
119  conns_pair.second = std::distance( connections_.begin(), connections_.end() );
120  registry_[index] = conns_pair;
121  }
122 
123  ConnsRange conns = range( registry_[index] );
124  ConnsConstIter iconn = conns.begin() + fed_ch;
125  FedChannelConnection& conn = const_cast<FedChannelConnection&>(*iconn);
126  conn = *ii;
127 
128  }
129 
130 }
131 
132 // -----------------------------------------------------------------------------
133 //
135  vector_( c.begin(), c.end() ),
136  range_( c.begin()+p.first, c.begin()+p.second )
137 {
138  if ( p.first > p.second ||
139  p.first == sistrip::invalid32_ ||
140  p.second == sistrip::invalid32_ ||
141  p.first > c.size() ||
142  p.second > c.size() ) {
143  range_ = ConnsConstIterRange( c.end(), c.end() );
144  }
145 }
146 
147 // -----------------------------------------------------------------------------
148 //
150  vector_( c.begin(), c.end() ),
151  range_( c.end(), c.end() )
152 {;}
153 
154 // -----------------------------------------------------------------------------
155 //
156 void SiStripFedCabling::ConnsRange::print( std::stringstream& ss ) const {
157  ss << "[SiStripFedCabling::ConnsRange::" << __func__ << "] Debug info:" << std::endl
158  << " Vector : " << std::endl
159  << " size : " << vector_.size() << std::endl
160  << " begin : "
161  << std::hex << std::setfill('0') << std::setw(8)
162  << &*vector_.begin()
163  << std::dec << std::endl
164  << " end : "
165  << std::hex << std::setfill('0') << std::setw(8)
166  << &*vector_.end()
167  << std::dec << std::endl
168  << " Range : " << std::endl
169  << " size : " << range_.size() << std::endl
170  << " begin : "
171  << std::hex << std::setfill('0') << std::setw(8)
172  << &*range_.begin()
173  << std::dec
174  << " (dist=" << std::distance( vector_.begin(), range_.begin() ) << ")"
175  << std::endl
176  << " end : "
177  << std::hex << std::setfill('0') << std::setw(8)
178  << &*range_.end()
179  << std::dec
180  << " (dist=" << std::distance( vector_.begin(), range_.end() ) << ")"
181  << std::endl
182  << " Offsets : " << std::endl
183  << " first : " << connsPair().first << std::endl
184  << " second : " << connsPair().second << std::endl;
185 }
186 
187 // -----------------------------------------------------------------------------
188 //
189 std::ostream& operator<<( std::ostream& os, const SiStripFedCabling::ConnsRange& input ) {
190  std::stringstream ss;
191  input.print(ss);
192  os << ss.str();
193  return os;
194 }
195 
196 // -----------------------------------------------------------------------------
197 // Returns connection info for FE devices connected to given FED
199  uint16_t index = fed_id - FEDNumbering::MINSiStripFEDID;
200  if ( index < registry_.size() ) {
201  return range( registry_[ index ] ).range();
202  } else { return range( registry_[ index ] ).invalid(); }
203 }
204 
205 // -----------------------------------------------------------------------------
206 // Returns connection info for FE devices connected to given FED id and channel
208  uint16_t fed_ch ) const {
209  ConnsConstIterRange conns = fedConnections( fed_id );
210  if ( !conns.empty() && conns.size() == 96 && fed_ch < 96 ) {
211  return *( conns.begin() + fed_ch );
212  } else { return FedChannelConnection(); }
213 }
214 
215 // -----------------------------------------------------------------------------
216 //
217 void SiStripFedCabling::printDebug( std::stringstream& ss ) const {
218 
219  uint16_t total = 0;
220  uint16_t nfeds = 0;
221  uint16_t cntr = 0;
222 
223  if ( feds_.empty() ) {
224  ss << "[SiStripFedCabling::" << __func__ << "]"
225  << " No FEDs found! Unable to print cabling map!";
226  return;
227  } else {
228  ss << "[SiStripFedCabling::" << __func__ << "]"
229  << " Printing cabling map for " << feds_.size()
230  << " FEDs with following ids: ";
231  }
232 
233  std::vector<uint16_t>::const_iterator ii = feds_.begin();
234  std::vector<uint16_t>::const_iterator jj = feds_.end();
235  for ( ; ii != jj; ++ii ) { ss << *ii << " "; }
236  ss << std::endl << std::endl;
237 
238  std::vector<uint16_t>::const_iterator ifed = feds_.begin();
239  std::vector<uint16_t>::const_iterator jfed = feds_.end();
240  for ( ; ifed != jfed; ++ifed ) {
241 
242  uint16_t index = *ifed - FEDNumbering::MINSiStripFEDID;
243  if ( index < registry_.size() ) {
244  ConnsRange conns = range( registry_[ index ] );
245 
246  ss << " Printing cabling information for FED id " << *ifed
247  << " (found " << conns.size()
248  << " FedChannelConnection objects...)"
249  << std::endl;
250 
251  uint16_t ichan = 0;
252  uint16_t connected = 0;
253  ConnsConstIter iconn = conns.begin();
254  ConnsConstIter jconn = conns.end();
255  for ( ; iconn != jconn; ++iconn ) {
256  if ( iconn->fedId() != sistrip::invalid_ ) {
257  connected++;
258  ss << *iconn << std::endl;
259  } else {
260  ss << " (FedId/Ch " << *ifed << "/" << ichan
261  << ": unconnected channel...)" << std::endl;
262  cntr++;
263  }
264  ichan++;
265  }
266 
267  ss << " Found " << connected
268  << " connected channels for FED id " << *ifed << std::endl
269  << std::endl;
270  if ( connected ) { nfeds++; total += connected; }
271 
272  }
273 
274  }
275 
276  float percent = (100.*cntr) / (96.*nfeds);
277  percent = static_cast<uint16_t>( 10.*percent );
278  percent /= 10.;
279  ss << " Found " << total
280  << " APV pairs that are connected to a total of "
281  << nfeds << " FEDs" << std::endl
282  << " " << detected_.size()
283  << " APV pairs have been detected, but are not connected" << std::endl
284  << " " << undetected_.size()
285  << " APV pairs are undetected (wrt DCU-DetId map)" << std::endl
286  << " " << cntr
287  << " FED channels out of a possible " << (96*nfeds)
288  << " (" << nfeds << " FEDs) are unconnected ("
289  << percent << "%)" << std::endl
290  << std::endl;
291 
292 }
293 
294 // -----------------------------------------------------------------------------
295 //
296 void SiStripFedCabling::terse( std::stringstream& ss ) const {
297 
298 
299  ss << "[SiStripFedCabling::" << __func__ << "]";
300 
301  if ( feds_.empty() ) {
302  ss << " No FEDs found! Unable to print cabling map!";
303  return;
304  }
305 
306  ss << " Printing cabling map for " << feds_.size()
307  << " FEDs: " << std::endl << std::endl;
308 
309  std::vector<uint16_t>::const_iterator ifed = feds_.begin();
310  std::vector<uint16_t>::const_iterator jfed = feds_.end();
311  for ( ; ifed != jfed; ++ifed ) {
312 
313  uint16_t index = *ifed - FEDNumbering::MINSiStripFEDID;
314  if ( index < registry_.size() ) {
315  ConnsRange conns = range( registry_[ index ] );
316 
317  ss << " Printing cabling information for FED id " << *ifed
318  << " (found " << conns.size()
319  << " FedChannelConnection objects...)"
320  << std::endl;
321 
322  uint16_t connected = 0;
323  ConnsConstIter iconn = conns.begin();
324  ConnsConstIter jconn = conns.end();
325  for ( ; iconn != jconn; ++iconn ) {
326  if ( iconn->fedId() != sistrip::invalid_ ) {
327  connected++;
328  iconn->terse(ss);
329  ss << std::endl;
330  }
331  }
332 
333  ss << " Found " << connected
334  << " connected channels for FED id " << *ifed << std::endl
335  << std::endl;
336 
337  }
338 
339  }
340 
341 }
342 
343 // -----------------------------------------------------------------------------
344 //
345 void SiStripFedCabling::printSummary( std::stringstream& ss ) const {
346 
347  ss << "[SiStripFedCabling::" << __func__ << "]";
348 
349  if ( feds_.empty() ) {
350  ss << " No FEDs found!";
351  return;
352  }
353 
354  ss << " Found " << feds_.size() << " FEDs"
355  << " with number of connected channels per front-end unit: "
356  << std::endl
357  << " FedId FeUnit1 FeUnit2 FeUnit3 FeUnit4 FeUnit5 FeUnit6 FeUnit7 FeUnit8 Total"
358  << std::endl;
359 
360  uint16_t total = 0;
361  uint16_t nfeds = 0;
362 
363  // iterate through fed ids
364  std::vector<uint16_t>::const_iterator ii = feds_.begin();
365  std::vector<uint16_t>::const_iterator jj = feds_.end();
366  for ( ; ii != jj; ++ii ) {
367 
368  // check number of connection objects
369  uint16_t index = *ii - FEDNumbering::MINSiStripFEDID;
370  if ( index < registry_.size() ) {
371  ConnsRange conns = range( registry_[ index ] );
372 
373  if ( conns.size() < 96 ) {
375  << "[SiStripFedCabling::" << __func__ << "]"
376  << " Unexpected size for FedChannelConnection vector! "
377  << conns.size();
378  return;
379  }
380 
381  // count connected channels at level of fe unit
382  std::vector<uint16_t> connected;
383  connected.resize(8,0);
384  for ( uint16_t ichan = 0; ichan < 96; ++ichan ) {
385  ConnsConstIter iconn = conns.begin() + ichan;
386  if ( iconn->fedId() < sistrip::valid_ ) {
387  uint16_t unit = SiStripFedKey::feUnit(ichan);
388  if ( unit > 8 ) { continue; }
389  connected[unit-1]++;
390  }
391  }
392 
393  // increment counters
394  uint16_t tot = 0 ;
395  ss << " " << std::setw(5) << *ii;
396  if ( !connected.empty() ) { nfeds++; }
397  for ( uint16_t unit = 0; unit < 8; ++unit ) {
398  ss << " " << std::setw(7) << connected[unit];
399  if ( !connected.empty() ) { tot += connected[unit]; }
400  }
401  ss << " " << std::setw(5) << tot << std::endl;
402  total += tot;
403 
404  }
405 
406  }
407 
408  // print out
409  float percent = (100.*total) / (96.*nfeds);
410  percent = static_cast<uint16_t>( 10.*percent );
411  percent /= 10.;
412  ss << " Found: " << std::endl
413  << " " << nfeds << " out of " << feds_.size()
414  << " FEDs with at least one connected channel " << std::endl
415  << " " << feds_.size() - nfeds << " out of " << feds_.size()
416  << " FEDs with no connected channels." << std::endl
417  << " " << total << " connected channels in total" << std::endl
418  << " " << detected_.size()
419  << " APV pairs have been detected, but are not connected" << std::endl
420  << " " << undetected_.size()
421  << " APV pairs are undetected (wrt DCU-DetId map)" << std::endl
422  << " " << percent
423  << "% of FED channels are connected" << std::endl;
424 
425 }
426 
427 // -----------------------------------------------------------------------------
428 //
429 std::ostream& operator<< ( std::ostream& os, const SiStripFedCabling& cabling ) {
430  std::stringstream ss;
431  cabling.print(ss);
432  os << ss.str();
433  return os;
434 }
ConnsConstIter end() const
void print(std::stringstream &) const
ConnsConstIterRange range() const
Conns connections_
Container of connection objects.
Feds feds_
&quot;Active&quot; FEDs that have connected FE devices
std::pair< uint32_t, uint32_t > ConnsPair
FedChannelConnection fedConnection(uint16_t fed_id, uint16_t fed_ch) const
static const uint32_t invalid32_
Definition: Constants.h:15
void terse(std::stringstream &) const
void printSummary(std::stringstream &) const
Builds range of iterators from pair of offsets.
std::ostream & operator<<(std::ostream &out, const ALILine &li)
Definition: ALILine.cc:187
static const uint16_t valid_
Definition: Constants.h:17
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
Registry registry_
Container of &quot;ranges&quot; indexed by FED id.
Conns::iterator ConnsIter
Conns undetected_
FE devices that are detected.
static std::string const input
Definition: EdmProvDump.cc:43
U second(std::pair< T, U > const &p)
static const char mlCabling_[]
boost::iterator_range< ConnsConstIter > ConnsConstIterRange
Class containning control, module, detector and connection information, at the level of a FED channel...
Conns detected_
Connections to FE devices that are not detected.
string unit
Definition: csvLumiCalc.py:46
void print(std::stringstream &ss) const
LEFT FOR COMPATIBILITY. SHOULD BE REPLACED BY PRINTDEBUG.
ConnsConstIterRange invalid() const
#define end
Definition: vmac.h:37
Feds::const_iterator FedsConstIter
#define LogTrace(id)
void buildFedCabling(ConnsConstIterRange connections)
ConnsConstIter begin() const
ConnsRange range(ConnsPair) const
Builds range of iterators from pair of offsets.
const uint16_t & feUnit() const
static const uint16_t invalid_
Definition: Constants.h:16
ConnsConstIterRange fedConnections(uint16_t fed_id) const
Contains cabling info at the device level, including DetId, APV pair numbers, hardware addresses...
std::vector< FedChannelConnection > Conns
#define begin
Definition: vmac.h:30
Conns::const_iterator ConnsConstIter
void printDebug(std::stringstream &) const
tuple conn
Definition: results_mgr.py:53