CMS 3D CMS Logo

SiStripFedKey.cc
Go to the documentation of this file.
1 
8 #include <iomanip>
9 
10 // -----------------------------------------------------------------------------
11 //
12 SiStripFedKey::SiStripFedKey(const uint16_t& fed_id,
13  const uint16_t& fe_unit,
14  const uint16_t& fe_chan,
15  const uint16_t& fed_apv)
16  : SiStripKey(), fedId_(fed_id), feUnit_(fe_unit), feChan_(fe_chan), fedApv_(fed_apv) {
17  // order is important!
18  initFromValue();
19  initFromKey();
20  initFromPath();
22 }
23 
24 // -----------------------------------------------------------------------------
25 //
26 SiStripFedKey::SiStripFedKey(const uint32_t& fed_key)
27  : SiStripKey(fed_key),
28  fedId_(sistrip::invalid_),
32  // order is important!
33  initFromKey();
34  initFromValue();
35  initFromPath();
37 }
38 
39 // -----------------------------------------------------------------------------
40 //
42  : SiStripKey(path),
43  fedId_(sistrip::invalid_),
47  // order is important!
48  initFromPath();
49  initFromValue();
50  initFromKey();
52 }
53 
54 // -----------------------------------------------------------------------------
55 //
57  : SiStripKey(), fedId_(input.fedId()), feUnit_(input.feUnit()), feChan_(input.feChan()), fedApv_(input.fedApv()) {
58  key(input.key());
59  path(input.path());
60  granularity(input.granularity());
61 }
62 
63 // -----------------------------------------------------------------------------
64 //
66  : SiStripKey(),
67  fedId_(sistrip::invalid_),
71  const SiStripFedKey& fed_key = dynamic_cast<const SiStripFedKey&>(input);
72  key(fed_key.key());
73  path(fed_key.path());
74  granularity(fed_key.granularity());
75  fedId_ = fed_key.fedId();
76  feUnit_ = fed_key.feUnit();
77  feChan_ = fed_key.feChan();
78  fedApv_ = fed_key.fedApv();
79 }
80 
81 // -----------------------------------------------------------------------------
82 //
84  : SiStripKey(),
85  fedId_(sistrip::invalid_),
89  ;
90 }
91 
92 // -----------------------------------------------------------------------------
93 //
94 uint16_t SiStripFedKey::fedCh(const uint16_t& fe_unit, const uint16_t& fe_chan) {
95  if (fe_unit <= sistrip::FEUNITS_PER_FED && fe_chan <= sistrip::FEDCH_PER_FEUNIT) {
96  if (fe_unit != 0 && fe_chan != 0) {
97  return (95 - (12 * (fe_unit - 1) + (fe_chan - 1)));
98  }
99  }
100  return sistrip::invalid_;
101 }
102 
103 // -----------------------------------------------------------------------------
104 //
105 uint16_t SiStripFedKey::feUnit(const uint16_t& fed_ch) {
106  if (fed_ch < sistrip::FEDCH_PER_FED) {
107  return ((95 - fed_ch) / 12 + 1);
108  }
109  return sistrip::invalid_;
110 }
111 
112 // -----------------------------------------------------------------------------
113 //
114 uint16_t SiStripFedKey::feChan(const uint16_t& fed_ch) {
115  if (fed_ch < sistrip::FEDCH_PER_FED) {
116  return ((95 - fed_ch) % 12 + 1);
117  }
118  return sistrip::invalid_;
119 }
120 
121 // -----------------------------------------------------------------------------
122 //
123 uint32_t SiStripFedKey::fedIndex(const uint16_t& fed_id, const uint16_t& fed_ch) {
124  if (fed_id < sistrip::FED_ID_MIN || fed_id > sistrip::FED_ID_MAX || fed_ch >= sistrip::FEDCH_PER_FED) {
125  return sistrip::invalid32_;
126  }
127  return (fed_id * sistrip::FEDCH_PER_FED + fed_ch);
128 }
129 
130 // -----------------------------------------------------------------------------
131 //
133  const SiStripFedKey& input = dynamic_cast<const SiStripFedKey&>(key);
134  if (fedId_ == input.fedId() && feUnit_ == input.feUnit() && feChan_ == input.feChan() && fedApv_ == input.fedApv()) {
135  return true;
136  } else {
137  return false;
138  }
139 }
140 
141 // -----------------------------------------------------------------------------
142 //
144  const SiStripFedKey& input = dynamic_cast<const SiStripFedKey&>(key);
145  if (isEqual(input)) {
146  return true;
147  } else if ((fedId_ == 0 || input.fedId() == 0) && (feUnit_ == 0 || input.feUnit() == 0) &&
148  (feChan_ == 0 || input.feChan() == 0) && (fedApv_ == 0 || input.fedApv() == 0)) {
149  return true;
150  } else {
151  return false;
152  }
153 }
154 
155 // -----------------------------------------------------------------------------
156 //
158 
159 // -----------------------------------------------------------------------------
160 //
162  if (gran == sistrip::FED_SYSTEM) {
163  return true;
164  } else if (gran == sistrip::UNDEFINED_GRAN || gran == sistrip::UNKNOWN_GRAN) {
165  return false;
166  }
167 
168  if (fedId_ != sistrip::invalid_) {
169  if (gran == sistrip::FE_DRIVER) {
170  return true;
171  }
172  if (feUnit_ != sistrip::invalid_) {
173  if (gran == sistrip::FE_UNIT) {
174  return true;
175  }
176  if (feChan_ != sistrip::invalid_) {
177  if (gran == sistrip::FE_CHAN) {
178  return true;
179  }
180  if (fedApv_ != sistrip::invalid_) {
181  if (gran == sistrip::FED_APV) {
182  return true;
183  }
184  }
185  }
186  }
187  }
188  return false;
189 }
190 
191 // -----------------------------------------------------------------------------
192 //
194 
195 // -----------------------------------------------------------------------------
196 //
198  if (gran == sistrip::FED_SYSTEM) {
199  return false;
200  } else if (gran == sistrip::UNDEFINED_GRAN || gran == sistrip::UNKNOWN_GRAN) {
201  return false;
202  }
203 
204  if (fedId_ == sistrip::invalid_) {
205  if (gran == sistrip::FE_DRIVER) {
206  return true;
207  }
208  if (feUnit_ == sistrip::invalid_) {
209  if (gran == sistrip::FE_UNIT) {
210  return true;
211  }
212  if (feChan_ == sistrip::invalid_) {
213  if (gran == sistrip::FE_CHAN) {
214  return true;
215  }
216  if (fedApv_ == sistrip::invalid_) {
217  if (gran == sistrip::FED_APV) {
218  return true;
219  }
220  }
221  }
222  }
223  }
224  return false;
225 }
226 
227 // -----------------------------------------------------------------------------
228 //
230  if (not((fedId_ >= sistrip::FED_ID_MIN && fedId_ <= sistrip::FED_ID_MAX) || (fedId_ == 0))) {
232  }
233 
236  }
237 
240  }
241 
244  }
245 }
246 
247 // -----------------------------------------------------------------------------
248 //
250  if (key() == sistrip::invalid32_) {
251  // ---------- Set FedKey based on member data ----------
252 
253  // Initialise to null value
254  key(0);
255 
256  // Extract FED id
258  key(key() | (fedId_ << fedIdOffset_));
259  } else if (fedId_ == 0) {
260  key(key() | (fedId_ << fedIdOffset_));
261  } else {
262  key(key() | (fedIdMask_ << fedIdOffset_));
263  }
264 
265  // Extract FE unit
266  if (feUnit_ >= 1 && feUnit_ <= sistrip::FEUNITS_PER_FED) {
267  key(key() | (feUnit_ << feUnitOffset_));
268  } else if (feUnit_ == 0) {
269  key(key() | (feUnit_ << feUnitOffset_));
270  } else {
271  key(key() | (feUnitMask_ << feUnitOffset_));
272  }
273 
274  // Extract FE chan
275  if (feChan_ >= 1 && feChan_ <= sistrip::FEDCH_PER_FEUNIT) {
276  key(key() | (feChan_ << feChanOffset_));
277  } else if (feChan_ == 0) {
278  key(key() | (feChan_ << feChanOffset_));
279  } else {
280  key(key() | (feChanMask_ << feChanOffset_));
281  }
282 
283  // Extract FED APV
284  if (fedApv_ >= 1 && fedApv_ <= sistrip::APVS_PER_FEDCH) {
285  key(key() | (fedApv_ << fedApvOffset_));
286  } else if (fedApv_ == 0) {
287  key(key() | (fedApv_ << fedApvOffset_));
288  } else {
289  key(key() | (fedApvMask_ << fedApvOffset_));
290  }
291 
292  // Set invalid key if necessary
296  }
297 
298  } else {
299  // ---------- Set member data based on FED key ----------
300 
301  fedId_ = (key() >> fedIdOffset_) & fedIdMask_;
305 
306  if (fedId_ == fedIdMask_) {
308  }
309  if (feUnit_ == feUnitMask_) {
311  }
312  if (feChan_ == feChanMask_) {
314  }
315  if (fedApv_ == fedApvMask_) {
317  }
318  }
319 }
320 
321 // -----------------------------------------------------------------------------
322 //
324  if (path() == sistrip::null_) {
325  // ---------- Set directory path based on member data ----------
326 
327  std::stringstream dir;
328 
330 
331  // Add FED id
332  if (fedId_) {
334 
335  // Add FE unit
336  if (feUnit_) {
338 
339  // Add FE channel
340  if (feChan_) {
342 
343  // Add FED APV
344  if (fedApv_) {
346  }
347  }
348  }
349  }
350 
351  std::string temp(dir.str());
352  path(temp);
353 
354  } else {
355  // ---------- Set member data based on directory path ----------
356 
357  fedId_ = 0;
358  feUnit_ = 0;
359  feChan_ = 0;
360  fedApv_ = 0;
361 
362  // Check if root is found
363  if (path().find(sistrip::root_) == std::string::npos) {
364  std::string temp = path();
366  }
367 
368  size_t curr = 0; // current string position
369  size_t next = 0; // next string position
370  next = path().find(sistrip::readoutView_, curr);
371 
372  // Extract view
373  curr = next;
374  if (curr != std::string::npos) {
375  next = path().find(sistrip::feDriver_, curr);
376  std::string readout_view(
377  path(), curr + (sizeof(sistrip::readoutView_) - 1), (next - (sizeof(sistrip::dir_) - 1)) - curr);
378 
379  // Extract FED id
380  curr = next;
381  if (curr != std::string::npos) {
382  next = path().find(sistrip::feUnit_, curr);
383  std::string fed_id(
384  path(), curr + (sizeof(sistrip::feDriver_) - 1), (next - (sizeof(sistrip::dir_) - 1)) - curr);
385  fedId_ = atoi(fed_id.c_str());
386 
387  // Extract FE unit
388  curr = next;
389  if (curr != std::string::npos) {
390  next = path().find(sistrip::feChan_, curr);
391  std::string fe_unit(path(), curr + (sizeof(sistrip::feUnit_) - 1), next - curr);
392  feUnit_ = atoi(fe_unit.c_str());
393 
394  // Extract FE channel
395  curr = next;
396  if (curr != std::string::npos) {
397  next = path().find(sistrip::fedApv_, curr);
398  std::string fe_chan(path(), curr + (sizeof(sistrip::feChan_) - 1), next - curr);
399  feChan_ = atoi(fe_chan.c_str());
400 
401  // Extract FED APV
402  curr = next;
403  if (curr != std::string::npos) {
404  next = std::string::npos;
405  std::string fed_apv(path(), curr + (sizeof(sistrip::fedApv_) - 1), next - curr);
406  fedApv_ = atoi(fed_apv.c_str());
407  }
408  }
409  }
410  }
411  } else {
412  std::stringstream ss;
414  //ss << sistrip::root_ << sistrip::dir_
415  //<< sistrip::unknownView_ << sistrip::dir_;
416  std::string temp(ss.str());
417  path(temp);
418  }
419  }
420 }
421 
422 // -----------------------------------------------------------------------------
423 //
426  channel(0);
427  if (fedId_ && fedId_ != sistrip::invalid_) {
429  channel(fedId_);
430  if (feUnit_ && feUnit_ != sistrip::invalid_) {
432  channel(feUnit_);
433  if (feChan_ && feChan_ != sistrip::invalid_) {
435  channel(feChan_);
436  if (fedApv_ && fedApv_ != sistrip::invalid_) {
438  channel(fedApv_);
439  } else if (fedApv_ == sistrip::invalid_) {
442  }
443  } else if (feChan_ == sistrip::invalid_) {
446  }
447  } else if (feUnit_ == sistrip::invalid_) {
450  }
451  } else if (fedId_ == sistrip::invalid_) {
454  }
455 }
456 
457 // -----------------------------------------------------------------------------
458 //
459 void SiStripFedKey::terse(std::stringstream& ss) const {
460  ss << "FED:crate/slot/id/unit/chan/apv= "
461  << "-"
462  << "/"
463  << "-"
464  << "/" << fedId() << "/" << feUnit() << "/" << feChan() << "/" << fedApv();
465  // ss << " FedKey"
466  // //<<"=0x"
467  // //<< std::hex
468  // //<< std::setfill('0') << std::setw(8) << key() << std::setfill(' ')
469  // //<< std::dec
470  // //<< ", " << ( isValid() ? "Valid" : "Invalid" )
471  // //<< ", FedCrate=" << fedCrate()
472  // //<< ", FedSlot=" << fedSlot()
473  // << ", FedId=" << fedId()
474  // << ", FeUnit=" << feUnit()
475  // << ", FeChan=" << feChan()
476  // //<< ", FedChannel=" << fedChannel()
477  // << ", FedApv=" << fedApv();
478 }
479 
480 // -----------------------------------------------------------------------------
481 //
482 void SiStripFedKey::print(std::stringstream& ss) const {
483  ss << " [SiStripFedKey::print]" << std::endl
484  << std::hex << " FED key : 0x" << std::setfill('0') << std::setw(8) << key() << std::endl
485  << std::setfill(' ') << std::dec << " FED id : " << fedId() << std::endl
486  << " Front-End unit : " << feUnit() << std::endl
487  << " Front-End chan : " << feChan() << std::endl
488  << " (internal chan) : "
489  << "(" << fedChannel() << ")" << std::endl
490  << " FED APV : " << fedApv() << std::endl
491  << " Directory : " << path() << std::endl
492  << " Granularity : " << SiStripEnumsAndStrings::granularity(granularity()) << std::endl
493  << " Channel : " << channel() << std::endl
494  << " isValid : " << isValid();
495 }
496 
497 // -----------------------------------------------------------------------------
498 //
499 std::ostream& operator<<(std::ostream& os, const SiStripFedKey& input) {
500  std::stringstream ss;
501  input.print(ss);
502  os << ss.str();
503  return os;
504 }
const uint16_t & channel() const
Definition: SiStripKey.h:123
static const char feDriver_[]
static const uint16_t feChanMask_
void print(std::stringstream &ss) const override
void initFromValue() override
static const uint16_t FED_ID_MIN
const uint16_t & fedApv() const
const uint16_t & feChan() const
static const uint16_t feUnitOffset_
static const char dir_[]
void initFromPath() override
const uint16_t & feUnit() const
A container class for generic run and event-related info, information required by the commissioning a...
Definition: SiStripFedKey.h:56
bool isInvalid() const override
Various generic constants used by DQM.
static const uint32_t invalid32_
Definition: Constants.h:15
const std::string & path() const
Definition: SiStripKey.h:121
void initFromKey() override
static std::string granularity(const sistrip::Granularity &)
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
static uint32_t fedIndex(const uint16_t &fed_id, const uint16_t &fed_ch)
sistrip classes
std::ostream & operator<<(std::ostream &os, const SiStripFedKey &input)
Constants and enumerated types for sistrip::View.
static std::string const input
Definition: EdmProvDump.cc:50
void terse(std::stringstream &ss) const override
bool isConsistent(const SiStripKey &) const override
uint16_t fedApv_
uint16_t fedChannel() const
static const char fedApv_[]
static const uint16_t FEUNITS_PER_FED
const uint32_t & key() const
Definition: SiStripKey.h:120
bool isEqual(const SiStripKey &) const override
Base utility class that identifies a position within a logical structure of the strip tracker...
Definition: SiStripKey.h:23
static const uint16_t feUnitMask_
uint16_t feChan_
uint16_t fedId_
uint16_t feUnit_
static const uint16_t fedIdOffset_
void initGranularity() override
static const uint16_t feChanOffset_
const uint16_t & fedId() const
static const char feChan_[]
static const uint16_t FEDCH_PER_FEUNIT
Constants and enumerated types for FED/FEC systems.
static const uint16_t invalid_
Definition: Constants.h:16
static const uint16_t FEDCH_PER_FED
static const char root_[]
static const char feUnit_[]
static const uint16_t fedApvMask_
static const uint16_t FED_ID_MAX
static uint16_t fedCh(const uint16_t &fe_unit, const uint16_t &fe_chan)
static const uint16_t fedIdMask_
static const uint16_t APVS_PER_FEDCH
static const char readoutView_[]
const sistrip::Granularity & granularity() const
Definition: SiStripKey.h:122
static const uint16_t fedApvOffset_
static const char null_[]
Definition: Constants.h:22
bool isValid() const override