CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
SiStripModule.cc
Go to the documentation of this file.
1 // Last commit: $Id: SiStripModule.cc,v 1.19 2009/10/27 09:50:29 lowette Exp $
2 
6 #include <iostream>
7 #include <iomanip>
8 
9 using namespace sistrip;
10 
11 // -----------------------------------------------------------------------------
12 //
14  : key_( conn.fecCrate(),
15  conn.fecSlot(),
16  conn.fecRing(),
17  conn.ccuAddr(),
18  conn.ccuChan() ),
19  apv32_(0),
20  apv33_(0),
21  apv34_(0),
22  apv35_(0),
23  apv36_(0),
24  apv37_(0),
25  dcu0x00_(0),
26  mux0x43_(0),
27  pll0x44_(0),
28  lld0x60_(0),
29  dcuId_(0),
30  detId_(0),
31  nApvPairs_(0),
32  cabling_(),
33  length_(0)
34 {
35  addDevices( conn );
36 }
37 
38 // -----------------------------------------------------------------------------
39 //
41 
42  if ( key_.fecCrate() && key_.fecCrate() != conn.fecCrate() ) {
44  << "SiStripModule::" << __func__ << "]"
45  << " Unexpected FEC crate ("
46  << conn.fecCrate() << ") for this module ("
47  << key_.fecCrate() << ")!";
48  return;
49  }
50 
51  if ( key_.fecSlot() && key_.fecSlot() != conn.fecSlot() ) {
53  << "SiStripModule::" << __func__ << "]"
54  << " Unexpected FEC slot ("
55  << conn.fecSlot() << ") for this module ("
56  << key_.fecSlot() << ")!";
57  return;
58  }
59 
60  if ( key_.fecRing() && key_.fecRing() != conn.fecRing() ) {
62  << "SiStripModule::" << __func__ << "]"
63  << " Unexpected FEC ring ("
64  << conn.fecRing() << ") for this module ("
65  << key_.fecRing() << ")!";
66  return;
67  }
68 
69  if ( key_.ccuAddr() && key_.ccuAddr() != conn.ccuAddr() ) {
71  << "SiStripModule::" << __func__ << "]"
72  << " Unexpected CCU addr ("
73  << conn.ccuAddr() << ") for this module ("
74  << key_.ccuAddr() << ")!";
75  return;
76  }
77 
78  if ( key_.ccuChan() && key_.ccuChan() != conn.ccuChan() ) {
80  << "SiStripModule::" << __func__ << "]"
81  << " Unexpected CCU chan ("
82  << conn.ccuChan() << ") for this module ("
83  << key_.ccuChan() << ")!";
84  return;
85  }
86 
87  // APVs
88  if ( conn.i2cAddr(0) ) { addApv( conn.i2cAddr(0) ); }
89  if ( conn.i2cAddr(1) ) { addApv( conn.i2cAddr(1) ); }
90 
91  // Detector
92  dcuId( conn.dcuId() );
93  detId( conn.detId() );
94  nApvPairs( conn.nApvPairs() );
95 
96  // FED cabling
97  FedChannel fed_ch( conn.fedCrate(),
98  conn.fedSlot(),
99  conn.fedId(),
100  conn.fedCh() );
101  fedCh( conn.i2cAddr(0), fed_ch );
102 
103  // DCU, MUX, PLL, LLD
104  if ( conn.dcu() ) { dcu0x00_ = true; }
105  if ( conn.mux() ) { mux0x43_ = true; }
106  if ( conn.pll() ) { pll0x44_ = true; }
107  if ( conn.lld() ) { lld0x60_ = true; }
108 
109 }
110 
111 // -----------------------------------------------------------------------------
112 //
113 std::vector<uint16_t> SiStripModule::activeApvs() const {
114  std::vector<uint16_t> apvs;
115  if ( apv32_ ) { apvs.push_back( apv32_ ); }
116  if ( apv33_ ) { apvs.push_back( apv33_ ); }
117  if ( apv34_ ) { apvs.push_back( apv34_ ); }
118  if ( apv35_ ) { apvs.push_back( apv35_ ); }
119  if ( apv36_ ) { apvs.push_back( apv36_ ); }
120  if ( apv37_ ) { apvs.push_back( apv37_ ); }
121  return apvs;
122 }
123 
124 // -----------------------------------------------------------------------------
125 //
126  const uint16_t& SiStripModule::activeApv( const uint16_t& apv_address ) const {
127  if ( apv_address == 0 || apv_address == 32 ) { return apv32_; }
128  else if ( apv_address == 1 || apv_address == 33 ) { return apv33_; }
129  else if ( apv_address == 2 || apv_address == 34 ) { return apv34_; }
130  else if ( apv_address == 3 || apv_address == 35 ) { return apv35_; }
131  else if ( apv_address == 4 || apv_address == 36 ) { return apv36_; }
132  else if ( apv_address == 5 || apv_address == 37 ) { return apv37_; }
133  else {
135  << "SiStripModule::" << __func__ << "]"
136  << " Unexpected I2C address or number ("
137  << apv_address << ") for this module!";
138  }
139  static const uint16_t address = 0;
140  return address;
141 }
142 
143 // -----------------------------------------------------------------------------
144 //
145 void SiStripModule::addApv( const uint16_t& apv_address ) {
146 
147  // Some checks on value of APV I2C address
148  if ( apv_address == 0 ) {
150  << "SiStripModule::" << __func__ << "]"
151  << " Null APV I2C address!";
152  return;
153  } else if ( apv_address < 32 && apv_address > 37 ) {
155  << "SiStripModule::" << __func__ << "]"
156  << " Unexpected I2C address ("
157  << apv_address << ") for APV!";
158  return;
159  }
160 
161  bool added_apv = false;
162  if ( !apv32_ && apv_address == 32 ) { apv32_ = 32; added_apv = true; }
163  else if ( !apv33_ && apv_address == 33 ) { apv33_ = 33; added_apv = true; }
164  else if ( !apv34_ && apv_address == 34 ) { apv34_ = 34; added_apv = true; }
165  else if ( !apv35_ && apv_address == 35 ) { apv35_ = 35; added_apv = true; }
166  else if ( !apv36_ && apv_address == 36 ) { apv36_ = 36; added_apv = true; }
167  else if ( !apv37_ && apv_address == 37 ) { apv37_ = 37; added_apv = true; }
168 
169  std::stringstream ss;
170  ss << "SiStripModule::" << __func__ << "]";
171  if ( added_apv ) { ss << " Added new APV for"; }
172  else { ss << " APV already exists for"; }
173  ss << " Crate/FEC/Ring/CCU/Module: "
174  << key_.fecCrate() << "/"
175  << key_.fecSlot() << "/"
176  << key_.fecRing() << "/"
177  << key_.ccuAddr() << "/"
178  << key_.ccuChan() << "/"
179  << apv_address;
180  //if ( added_apv ) { LogTrace(mlCabling_) << ss.str(); }
181  /* else */ if ( !added_apv ) { edm::LogWarning(mlCabling_) << ss.str(); }
182 
183 }
184 
185 // -----------------------------------------------------------------------------
186 //
187 void SiStripModule::nApvPairs( const uint16_t& npairs ) {
188  if ( npairs == 2 || npairs == 3 ) { nApvPairs_ = npairs; }
189  else if ( npairs == 0 ) {
190  nApvPairs_ = 0;
191  if ( apv32_ || apv33_ ) { nApvPairs_++; }
192  if ( apv34_ || apv35_ ) { nApvPairs_++; }
193  if ( apv36_ || apv37_ ) { nApvPairs_++; }
194  } else {
196  << "SiStripModule::" << __func__ << "]"
197  << " Unexpected number of APV pairs: "
198  << npairs;
199  }
200 }
201 
202 // -----------------------------------------------------------------------------
203 //
204 SiStripModule::PairOfU16 SiStripModule::activeApvPair( const uint16_t& lld_channel ) const {
205  if ( lld_channel == 1 ) { return PairOfU16(apv32_,apv33_); }
206  else if ( lld_channel == 2 ) { return PairOfU16(apv34_,apv35_); }
207  else if ( lld_channel == 3 ) { return PairOfU16(apv36_,apv37_); }
208  else {
210  << "SiStripModule::" << __func__ << "]"
211  << " Unexpected LLD channel: " << lld_channel;
212  return PairOfU16(0,0);
213  }
214 }
215 
216 // -----------------------------------------------------------------------------
217 //
218 uint16_t SiStripModule::lldChannel( const uint16_t& apv_pair_num ) const {
219  if ( apv_pair_num > 2 ) {
221  << "SiStripModule::" << __func__ << "]"
222  << " Unexpected APV pair number: " << apv_pair_num;
223  return 0;
224  }
225  if ( nApvPairs_ != 2 && nApvPairs_ != 3 ) {
227  << "SiStripModule::" << __func__ << "]"
228  << " Unexpected number of APV pairs: " << nApvPairs_;
229  return 0;
230  }
231  if ( nApvPairs_ == 2 && apv_pair_num == 1 ) { return 3; }
232  else if ( nApvPairs_ == 2 && apv_pair_num == 2 ) {
234  << "[SiStripFecCabling::" << __func__ << "]"
235  << " APV pair number is incompatible with"
236  << " respect to number of !";
237  return 0;
238  } else { return apv_pair_num + 1; }
239 }
240 
241 // -----------------------------------------------------------------------------
242 //
243 uint16_t SiStripModule::apvPairNumber( const uint16_t& lld_channel ) const {
244  if ( lld_channel < 1 || lld_channel > 3 ) {
246  << "SiStripModule::" << __func__ << "]"
247  << " Unexpected LLD channel: " << lld_channel;
248  return 0;
249  }
250  if ( nApvPairs_ != 2 && nApvPairs_ != 3 ) {
252  << "SiStripModule::" << __func__ << "]"
253  << " Unexpected number of APV pairs: " << nApvPairs_;
254  return 0;
255  }
256  if ( nApvPairs_ == 2 && lld_channel == 3 ) { return 1; }
257  else if ( nApvPairs_ == 2 && lld_channel == 2 ) {
259  << "SiStripModule::" << __func__ << "]"
260  << " LLD channel is incompatible with"
261  << " respect to number of APV pairs!";
262  return 0;
263  } else { return lld_channel - 1; }
264 }
265 
266 // -----------------------------------------------------------------------------
267 //
268 SiStripModule::FedChannel SiStripModule::fedCh( const uint16_t& apv_pair ) const {
269 
270  FedChannel fed_ch(0,0,0,0);
271 
272  if ( !nApvPairs() ) {
273 
275  << "SiStripModule::" << __func__ << "]"
276  << " No APV pairs exist!";
277  return fed_ch;
278 
279  } else {
280 
281  uint16_t lld_ch = 0;
282  if ( nApvPairs() == 2 ) {
283 
284  if ( apv_pair == 0 ) { lld_ch = 1; }
285  else if ( apv_pair == 1 ) { lld_ch = 3; }
286  else {
288  << "SiStripModule::" << __func__ << "]"
289  << " Unexpected pair number! " << apv_pair;
290  }
291 
292  } else if ( nApvPairs() == 3 ) {
293 
294  if ( apv_pair == 0 ) { lld_ch = 1; }
295  else if ( apv_pair == 1 ) { lld_ch = 2; }
296  else if ( apv_pair == 2 ) { lld_ch = 3; }
297  else {
299  << "SiStripModule::" << __func__ << "]"
300  << " Unexpected pair number! " << apv_pair;
301  }
302 
303  } else {
304 
306  << "SiStripModule::" << __func__ << "]"
307  << " Unexpected number of APV pairs: " << nApvPairs();
308 
309  }
310 
311  FedCabling::const_iterator ipair = cabling_.find( lld_ch );
312  if ( ipair != cabling_.end() ) { return (*ipair).second; }
313  else { return fed_ch; }
314 
315  }
316 
317 }
318 
319 // -----------------------------------------------------------------------------
320 //
321 bool SiStripModule::fedCh( const uint16_t& apv_address,
322  const FedChannel& fed_ch ) {
323  // Determine LLD channel
324  int16_t lld_ch = 1;
325  if ( apv_address == 32 || apv_address == 33 ) { lld_ch = 1; }
326  else if ( apv_address == 34 || apv_address == 35 ) { lld_ch = 2; }
327  else if ( apv_address == 36 || apv_address == 37 ) { lld_ch = 3; }
328  else if ( apv_address == 0 ) { ; } //@@ do nothing?
329  else {
330  edm::LogWarning(mlCabling_) << "[SiStripModule::fedCh]"
331  << " Unexpected I2C address ("
332  << apv_address << ") for APV!";
333  return false;
334  }
335  // Search for entry in std::map
336  //@@ use FedKey as key instead of lld chan? what about "duplicates"?
337  //@@ always append to std::map? then can have >3 entries. useful for debug?
338  FedCabling::iterator ipair = cabling_.find( lld_ch );
339  if ( ipair == cabling_.end() ) { cabling_[lld_ch] = fed_ch; }
340  else { ipair->second = fed_ch; }
341  return true;
342 }
343 
344 // -----------------------------------------------------------------------------
345 //
346 void SiStripModule::print( std::stringstream& ss ) const {
347 
348  ss << " [SiStripModule::" << __func__ << "]" << std::endl
349  << " Crate/FEC/Ring/CCU/Module : "
350  << key().fecCrate() << "/"
351  << key().fecSlot() << "/"
352  << key().fecRing() << "/"
353  << key().ccuAddr() << "/"
354  << key().ccuChan() << std::endl;
355 
356  ss << " ActiveApvs : ";
357  std::vector<uint16_t> apvs = activeApvs();
358  if ( apvs.empty() ) { ss << "NONE!"; }
359  std::vector<uint16_t>::const_iterator iapv = apvs.begin();
360  for ( ; iapv != apvs.end(); iapv++ ) { ss << *iapv << ", "; }
361  ss << std::endl;
362 
363  ss << " DcuId/DetId/nPairs : "
364  << std::hex
365  << "0x" << std::setfill('0') << std::setw(8) << dcuId() << "/"
366  << "0x" << std::setfill('0') << std::setw(8) << detId() << "/"
367  << std::dec
368  << nApvPairs() << std::endl;
369 
370  FedCabling channels = fedChannels();
371  ss << " ApvPairNum/FedCrate/FedSlot/FedId/FedCh : ";
372  FedCabling::const_iterator ichan = channels.begin();
373  for ( ; ichan != channels.end(); ichan++ ) {
374  ss << ichan->first << "/"
375  << ichan->second.fedCrate_ << "/"
376  << ichan->second.fedSlot_ << "/"
377  << ichan->second.fedId_ << "/"
378  << ichan->second.fedCh_ << ", ";
379  }
380  ss << std::endl;
381 
382  ss << " DCU/MUX/PLL/LLD found : "
383  << bool(dcu0x00_) << "/"
384  << bool(mux0x43_) << "/"
385  << bool(pll0x44_) << "/"
386  << bool(lld0x60_);
387 
388 }
389 
390 // -----------------------------------------------------------------------------
391 //@@ NEEDS MODIFYING!!!!
392 void SiStripModule::terse( std::stringstream& ss ) const {
393 
394  ss << " [SiStripModule::" << __func__ << "]" << std::endl
395  << " Crate/FEC/Ring/CCU/Module : "
396  << key().fecCrate() << "/"
397  << key().fecSlot() << "/"
398  << key().fecRing() << "/"
399  << key().ccuAddr() << "/"
400  << key().ccuChan() << std::endl;
401 
402  ss << " ActiveApvs : ";
403  std::vector<uint16_t> apvs = activeApvs();
404  if ( apvs.empty() ) { ss << "NONE!"; }
405  std::vector<uint16_t>::const_iterator iapv = apvs.begin();
406  for ( ; iapv != apvs.end(); iapv++ ) { ss << *iapv << ", "; }
407  ss << std::endl;
408 
409  ss << " DcuId/DetId/nPairs : "
410  << std::hex
411  << "0x" << std::setfill('0') << std::setw(8) << dcuId() << "/"
412  << "0x" << std::setfill('0') << std::setw(8) << detId() << "/"
413  << std::dec
414  << nApvPairs() << std::endl;
415 
416  FedCabling channels = fedChannels();
417  ss << " ApvPairNum/FedCrate/FedSlot/FedId/FedCh : ";
418  FedCabling::const_iterator ichan = channels.begin();
419  for ( ; ichan != channels.end(); ichan++ ) {
420  ss << ichan->first << "/"
421  << ichan->second.fedCrate_ << "/"
422  << ichan->second.fedSlot_ << "/"
423  << ichan->second.fedId_ << "/"
424  << ichan->second.fedCh_ << ", ";
425  }
426  ss << std::endl;
427 
428  ss << " DCU/MUX/PLL/LLD found : "
429  << bool(dcu0x00_) << "/"
430  << bool(mux0x43_) << "/"
431  << bool(pll0x44_) << "/"
432  << bool(lld0x60_);
433 
434 }
435 
436 // -----------------------------------------------------------------------------
437 //
438 std::ostream& operator<< ( std::ostream& os, const SiStripModule& device ) {
439  std::stringstream ss;
440  device.print(ss);
441  os << ss.str();
442  return os;
443 }
const uint16_t & fecSlot() const
Device and connection information at the level of a front-end module.
Definition: SiStripModule.h:25
uint16_t apv35_
void terse(std::stringstream &) const
const uint16_t & fecCrate() const
const bool & lld() const
char * address
Definition: mlp_lapack.h:14
uint16_t pll0x44_
std::vector< uint16_t > activeApvs() const
SiStripFecKey key_
const uint16_t & fecRing() const
const uint16_t & fedCh() const
void print(std::stringstream &) const
const SiStripFecKey & key() const
uint16_t apv37_
void addDevices(const FedChannelConnection &conn)
const uint16_t & fecSlot() const
std::ostream & operator<<(std::ostream &out, const ALILine &li)
Definition: ALILine.cc:187
uint16_t apv33_
const FedCabling & fedChannels() const
const uint16_t & fedId() const
uint16_t apvPairNumber(const uint16_t &lld_channel) const
static const char mlCabling_[]
const uint16_t & fecRing() const
const uint16_t & fedSlot() const
const uint32_t & detId() const
Class containning control, module, detector and connection information, at the level of a FED channel...
uint16_t apv32_
uint16_t mux0x43_
const uint16_t & ccuChan() const
uint16_t lldChannel(const uint16_t &apv_pair_num) const
void addApv(const uint16_t &apv_address)
const bool & mux() const
const bool & dcu() const
const uint16_t & ccuAddr() const
const uint32_t & dcuId() const
const uint16_t & fecCrate() const
PairOfU16 activeApvPair(const uint16_t &lld_channel) const
const uint16_t & nApvPairs() const
const uint32_t & dcuId() const
const uint16_t & nApvPairs() const
const uint16_t & ccuAddr() const
std::pair< uint16_t, uint16_t > PairOfU16
Definition: SiStripModule.h:43
const bool & pll() const
const uint32_t & detId() const
const uint16_t & fedCrate() const
FedCabling cabling_
uint16_t lld0x60_
FedChannel fedCh(const uint16_t &apv_pair_num) const
const uint16_t & ccuChan() const
uint16_t apv34_
uint16_t nApvPairs_
std::map< uint16_t, FedChannel > FedCabling
Definition: SiStripModule.h:60
const uint16_t & i2cAddr(const uint16_t &apv0_or_1) const
tuple conn
Definition: results_mgr.py:53
const uint16_t & activeApv(const uint16_t &apv_address) const
SiStripModule(const FedChannelConnection &conn)
uint16_t apv36_
uint16_t dcu0x00_