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) {
29  addDevices(conn);
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) { edm::LogWarning(mlCabling_) << ss.str(); }
196 }
197 
198 // -----------------------------------------------------------------------------
199 //
200 void SiStripModule::nApvPairs(const uint16_t &npairs) {
201  if (npairs == 2 || npairs == 3) {
202  nApvPairs_ = npairs;
203  } else if (npairs == 0) {
204  nApvPairs_ = 0;
205  if (apv32_ || apv33_) {
206  nApvPairs_++;
207  }
208  if (apv34_ || apv35_) {
209  nApvPairs_++;
210  }
211  if (apv36_ || apv37_) {
212  nApvPairs_++;
213  }
214  } else {
215  edm::LogWarning(mlCabling_) << "SiStripModule::" << __func__ << "]"
216  << " Unexpected number of APV pairs: " << npairs;
217  }
218 }
219 
220 // -----------------------------------------------------------------------------
221 //
222 SiStripModule::PairOfU16 SiStripModule::activeApvPair(const uint16_t &lld_channel) const {
223  if (lld_channel == 1) {
224  return PairOfU16(apv32_, apv33_);
225  } else if (lld_channel == 2) {
226  return PairOfU16(apv34_, apv35_);
227  } else if (lld_channel == 3) {
228  return PairOfU16(apv36_, apv37_);
229  } else {
230  edm::LogWarning(mlCabling_) << "SiStripModule::" << __func__ << "]"
231  << " Unexpected LLD channel: " << lld_channel;
232  return PairOfU16(0, 0);
233  }
234 }
235 
236 // -----------------------------------------------------------------------------
237 //
238 uint16_t SiStripModule::lldChannel(const uint16_t &apv_pair_num) const {
239  if (apv_pair_num > 2) {
240  edm::LogWarning(mlCabling_) << "SiStripModule::" << __func__ << "]"
241  << " Unexpected APV pair number: " << apv_pair_num;
242  return 0;
243  }
244  if (nApvPairs_ != 2 && nApvPairs_ != 3) {
245  edm::LogWarning(mlCabling_) << "SiStripModule::" << __func__ << "]"
246  << " Unexpected number of APV pairs: " << nApvPairs_;
247  return 0;
248  }
249  if (nApvPairs_ == 2 && apv_pair_num == 1) {
250  return 3;
251  } else if (nApvPairs_ == 2 && apv_pair_num == 2) {
252  edm::LogWarning(mlCabling_) << "[SiStripFecCabling::" << __func__ << "]"
253  << " APV pair number is incompatible with"
254  << " respect to number of !";
255  return 0;
256  } else {
257  return apv_pair_num + 1;
258  }
259 }
260 
261 // -----------------------------------------------------------------------------
262 //
263 uint16_t SiStripModule::apvPairNumber(const uint16_t &lld_channel) const {
264  if (lld_channel < 1 || lld_channel > 3) {
265  edm::LogWarning(mlCabling_) << "SiStripModule::" << __func__ << "]"
266  << " Unexpected LLD channel: " << lld_channel;
267  return 0;
268  }
269  if (nApvPairs_ != 2 && nApvPairs_ != 3) {
270  edm::LogWarning(mlCabling_) << "SiStripModule::" << __func__ << "]"
271  << " Unexpected number of APV pairs: " << nApvPairs_;
272  return 0;
273  }
274  if (nApvPairs_ == 2 && lld_channel == 3) {
275  return 1;
276  } else if (nApvPairs_ == 2 && lld_channel == 2) {
277  edm::LogWarning(mlCabling_) << "SiStripModule::" << __func__ << "]"
278  << " LLD channel is incompatible with"
279  << " respect to number of APV pairs!";
280  return 0;
281  } else {
282  return lld_channel - 1;
283  }
284 }
285 
286 // -----------------------------------------------------------------------------
287 //
288 SiStripModule::FedChannel SiStripModule::fedCh(const uint16_t &apv_pair) const {
289  FedChannel fed_ch(0, 0, 0, 0);
290 
291  if (!nApvPairs()) {
292  edm::LogWarning(mlCabling_) << "SiStripModule::" << __func__ << "]"
293  << " No APV pairs exist!";
294  return fed_ch;
295 
296  } else {
297  uint16_t lld_ch = 0;
298  if (nApvPairs() == 2) {
299  if (apv_pair == 0) {
300  lld_ch = 1;
301  } else if (apv_pair == 1) {
302  lld_ch = 3;
303  } else {
304  edm::LogWarning(mlCabling_) << "SiStripModule::" << __func__ << "]"
305  << " Unexpected pair number! " << apv_pair;
306  }
307 
308  } else if (nApvPairs() == 3) {
309  if (apv_pair == 0) {
310  lld_ch = 1;
311  } else if (apv_pair == 1) {
312  lld_ch = 2;
313  } else if (apv_pair == 2) {
314  lld_ch = 3;
315  } else {
316  edm::LogWarning(mlCabling_) << "SiStripModule::" << __func__ << "]"
317  << " Unexpected pair number! " << apv_pair;
318  }
319 
320  } else {
321  edm::LogWarning(mlCabling_) << "SiStripModule::" << __func__ << "]"
322  << " Unexpected number of APV pairs: " << nApvPairs();
323  }
324 
325  FedCabling::const_iterator ipair = cabling_.find(lld_ch);
326  if (ipair != cabling_.end()) {
327  return (*ipair).second;
328  } else {
329  return fed_ch;
330  }
331  }
332 }
333 
334 // -----------------------------------------------------------------------------
335 //
336 bool SiStripModule::fedCh(const uint16_t &apv_address, const FedChannel &fed_ch) {
337  // Determine LLD channel
338  int16_t lld_ch = 1;
339  if (apv_address == 32 || apv_address == 33) {
340  lld_ch = 1;
341  } else if (apv_address == 34 || apv_address == 35) {
342  lld_ch = 2;
343  } else if (apv_address == 36 || apv_address == 37) {
344  lld_ch = 3;
345  } else if (apv_address == 0) {
346  ;
347  } //@@ do nothing?
348  else {
349  edm::LogWarning(mlCabling_) << "[SiStripModule::fedCh]"
350  << " Unexpected I2C address (" << apv_address << ") for APV!";
351  return false;
352  }
353  // Search for entry in std::map
354  //@@ use FedKey as key instead of lld chan? what about "duplicates"?
355  //@@ always append to std::map? then can have >3 entries. useful for debug?
356  FedCabling::iterator ipair = cabling_.find(lld_ch);
357  if (ipair == cabling_.end()) {
358  cabling_[lld_ch] = fed_ch;
359  } else {
360  ipair->second = fed_ch;
361  }
362  return true;
363 }
364 
365 // -----------------------------------------------------------------------------
366 //
367 void SiStripModule::print(std::stringstream &ss) const {
368  ss << " [SiStripModule::" << __func__ << "]" << std::endl
369  << " Crate/FEC/Ring/CCU/Module : " << key().fecCrate() << "/" << key().fecSlot() << "/"
370  << key().fecRing() << "/" << key().ccuAddr() << "/" << key().ccuChan() << std::endl;
371 
372  ss << " ActiveApvs : ";
373  std::vector<uint16_t> apvs = activeApvs();
374  if (apvs.empty()) {
375  ss << "NONE!";
376  }
377  std::vector<uint16_t>::const_iterator iapv = apvs.begin();
378  for (; iapv != apvs.end(); ++iapv) {
379  ss << *iapv << ", ";
380  }
381  ss << std::endl;
382 
383  ss << " DcuId/DetId/nPairs : " << std::hex << "0x" << std::setfill('0') << std::setw(8)
384  << dcuId() << "/"
385  << "0x" << std::setfill('0') << std::setw(8) << detId() << "/" << std::dec << nApvPairs() << std::endl;
386 
387  FedCabling channels = fedChannels();
388  ss << " ApvPairNum/FedCrate/FedSlot/FedId/FedCh : ";
389  FedCabling::const_iterator ichan = channels.begin();
390  for (; ichan != channels.end(); ++ichan) {
391  ss << ichan->first << "/" << ichan->second.fedCrate_ << "/" << ichan->second.fedSlot_ << "/" << ichan->second.fedId_
392  << "/" << ichan->second.fedCh_ << ", ";
393  }
394  ss << std::endl;
395 
396  ss << " DCU/MUX/PLL/LLD found : " << bool(dcu0x00_) << "/" << bool(mux0x43_) << "/"
397  << bool(pll0x44_) << "/" << bool(lld0x60_);
398 }
399 
400 // -----------------------------------------------------------------------------
401 //@@ NEEDS MODIFYING!!!!
402 void SiStripModule::terse(std::stringstream &ss) const {
403  ss << " [SiStripModule::" << __func__ << "]" << std::endl
404  << " Crate/FEC/Ring/CCU/Module : " << key().fecCrate() << "/" << key().fecSlot() << "/"
405  << key().fecRing() << "/" << key().ccuAddr() << "/" << key().ccuChan() << std::endl;
406 
407  ss << " ActiveApvs : ";
408  std::vector<uint16_t> apvs = activeApvs();
409  if (apvs.empty()) {
410  ss << "NONE!";
411  }
412  std::vector<uint16_t>::const_iterator iapv = apvs.begin();
413  for (; iapv != apvs.end(); ++iapv) {
414  ss << *iapv << ", ";
415  }
416  ss << std::endl;
417 
418  ss << " DcuId/DetId/nPairs : " << std::hex << "0x" << std::setfill('0') << std::setw(8)
419  << dcuId() << "/"
420  << "0x" << std::setfill('0') << std::setw(8) << detId() << "/" << std::dec << nApvPairs() << std::endl;
421 
422  FedCabling channels = fedChannels();
423  ss << " ApvPairNum/FedCrate/FedSlot/FedId/FedCh : ";
424  FedCabling::const_iterator ichan = channels.begin();
425  for (; ichan != channels.end(); ++ichan) {
426  ss << ichan->first << "/" << ichan->second.fedCrate_ << "/" << ichan->second.fedSlot_ << "/" << ichan->second.fedId_
427  << "/" << ichan->second.fedCh_ << ", ";
428  }
429  ss << std::endl;
430 
431  ss << " DCU/MUX/PLL/LLD found : " << bool(dcu0x00_) << "/" << bool(mux0x43_) << "/"
432  << bool(pll0x44_) << "/" << bool(lld0x60_);
433 }
434 
435 // -----------------------------------------------------------------------------
436 //
437 std::ostream &operator<<(std::ostream &os, const SiStripModule &device) {
438  std::stringstream ss;
439  device.print(ss);
440  os << ss.str();
441  return os;
442 }
const uint16_t & fecSlot() const
Device and connection information at the level of a front-end module.
Definition: SiStripModule.h:24
uint16_t apv35_
void terse(std::stringstream &) const
const uint16_t & fecCrate() const
const bool & lld() const
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::map< uint16_t, FedChannel > FedCabling
Definition: SiStripModule.h:58
uint16_t apv33_
const FedCabling & fedChannels() const
const uint16_t & fedId() const
sistrip classes
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
std::ostream & operator<<(std::ostream &os, const SiStripModule &device)
const uint16_t & nApvPairs() const
const uint16_t & ccuAddr() const
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_
const uint16_t & i2cAddr(const uint16_t &apv0_or_1) const
std::pair< uint16_t, uint16_t > PairOfU16
Definition: SiStripModule.h:40
const uint16_t & activeApv(const uint16_t &apv_address) const
SiStripModule(const FedChannelConnection &conn)
uint16_t apv36_
uint16_t dcu0x00_