CMS 3D CMS Logo

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