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(),
17  fedId_(fed_id),
18  feUnit_(fe_unit),
19  feChan_(fe_chan),
20  fedApv_(fed_apv)
21 {
22  // order is important!
23  initFromValue();
24  initFromKey();
25  initFromPath();
27 }
28 
29 // -----------------------------------------------------------------------------
30 //
31 SiStripFedKey::SiStripFedKey( const uint32_t& fed_key ) :
32  SiStripKey(fed_key),
37 {
38  // order is important!
39  initFromKey();
40  initFromValue();
41  initFromPath();
43 }
44 
45 // -----------------------------------------------------------------------------
46 //
48  SiStripKey(path),
53 {
54  // order is important!
55  initFromPath();
56  initFromValue();
57  initFromKey();
59 }
60 
61 // -----------------------------------------------------------------------------
62 //
64  SiStripKey(),
65  fedId_(input.fedId()),
66  feUnit_(input.feUnit()),
67  feChan_(input.feChan()),
68  fedApv_(input.fedApv())
69 {
70  key(input.key());
71  path(input.path());
72  granularity(input.granularity());
73 }
74 
75 // -----------------------------------------------------------------------------
76 //
78  SiStripKey(),
83 {
84  const SiStripFedKey& fed_key = dynamic_cast<const SiStripFedKey&>(input);
85  key(fed_key.key());
86  path(fed_key.path());
87  granularity(fed_key.granularity());
88  fedId_ = fed_key.fedId();
89  feUnit_ = fed_key.feUnit();
90  feChan_ = fed_key.feChan();
91  fedApv_ = fed_key.fedApv();
92 }
93 
94 // -----------------------------------------------------------------------------
95 //
97  SiStripKey(),
102 {;}
103 
104 // -----------------------------------------------------------------------------
105 //
106 uint16_t SiStripFedKey::fedCh( const uint16_t& fe_unit,
107  const uint16_t& fe_chan ) {
108  if ( fe_unit <= sistrip::FEUNITS_PER_FED &&
109  fe_chan <= sistrip::FEDCH_PER_FEUNIT ) {
110  if ( fe_unit != 0 && fe_chan != 0 ) {
111  return ( 95 - ( 12 * (fe_unit-1) + (fe_chan-1) ) );
112  }
113  }
114  return sistrip::invalid_;
115 }
116 
117 // -----------------------------------------------------------------------------
118 //
119 uint16_t SiStripFedKey::feUnit( const uint16_t& fed_ch ) {
120  if ( fed_ch < sistrip::FEDCH_PER_FED ) {
121  return ( (95-fed_ch)/12 + 1 );
122  }
123  return sistrip::invalid_;
124 }
125 
126 // -----------------------------------------------------------------------------
127 //
128 uint16_t SiStripFedKey::feChan( const uint16_t& fed_ch ) {
129  if ( fed_ch < sistrip::FEDCH_PER_FED ) {
130  return ( (95-fed_ch)%12 + 1 );
131  }
132  return sistrip::invalid_;
133 }
134 
135 // -----------------------------------------------------------------------------
136 //
137 uint32_t SiStripFedKey::fedIndex( const uint16_t& fed_id,
138  const uint16_t& fed_ch ) {
139  if ( fed_id < sistrip::FED_ID_MIN ||
140  fed_id > sistrip::FED_ID_MAX ||
141  fed_ch >= sistrip::FEDCH_PER_FED ) { return sistrip::invalid32_; }
142  return ( fed_id * sistrip::FEDCH_PER_FED + fed_ch );
143 }
144 
145 // -----------------------------------------------------------------------------
146 //
147 bool SiStripFedKey::isEqual( const SiStripKey& key ) const {
148  const SiStripFedKey& input = dynamic_cast<const SiStripFedKey&>(key);
149  if ( fedId_ == input.fedId() &&
150  feUnit_ == input.feUnit() &&
151  feChan_ == input.feChan() &&
152  fedApv_ == input.fedApv() ) {
153  return true;
154  } else { return false; }
155 }
156 
157 // -----------------------------------------------------------------------------
158 //
160  const SiStripFedKey& input = dynamic_cast<const SiStripFedKey&>(key);
161  if ( isEqual(input) ) { return true; }
162  else if ( ( fedId_ == 0 || input.fedId() == 0 ) &&
163  ( feUnit_ == 0 || input.feUnit() == 0 ) &&
164  ( feChan_ == 0 || input.feChan() == 0 ) &&
165  ( fedApv_ == 0 || input.fedApv() == 0 ) ) {
166  return true;
167  } else { return false; }
168 }
169 
170 // -----------------------------------------------------------------------------
171 //
172 bool SiStripFedKey::isValid() const {
173  return isValid(sistrip::FED_APV);
174 }
175 
176 // -----------------------------------------------------------------------------
177 //
178 bool SiStripFedKey::isValid( const sistrip::Granularity& gran ) const {
179  if ( gran == sistrip::FED_SYSTEM ) { return true; }
180  else if ( gran == sistrip::UNDEFINED_GRAN ||
181  gran == sistrip::UNKNOWN_GRAN ) { return false; }
182 
183  if ( fedId_ != sistrip::invalid_ ) {
184  if ( gran == sistrip::FE_DRIVER ) { return true; }
185  if ( feUnit_ != sistrip::invalid_ ) {
186  if ( gran == sistrip::FE_UNIT ) { return true; }
187  if ( feChan_ != sistrip::invalid_ ) {
188  if ( gran == sistrip::FE_CHAN ) { return true; }
189  if ( fedApv_ != sistrip::invalid_ ) {
190  if ( gran == sistrip::FED_APV ) { return true; }
191  }
192  }
193  }
194  }
195  return false;
196 }
197 
198 // -----------------------------------------------------------------------------
199 //
201  return isInvalid(sistrip::FED_APV);
202 }
203 
204 // -----------------------------------------------------------------------------
205 //
207  if ( gran == sistrip::FED_SYSTEM ) { return false; }
208  else if ( gran == sistrip::UNDEFINED_GRAN ||
209  gran == sistrip::UNKNOWN_GRAN ) { return false; }
210 
211  if ( fedId_ == sistrip::invalid_ ) {
212  if ( gran == sistrip::FE_DRIVER ) { return true; }
213  if ( feUnit_ == sistrip::invalid_ ) {
214  if ( gran == sistrip::FE_UNIT ) { return true; }
215  if ( feChan_ == sistrip::invalid_ ) {
216  if ( gran == sistrip::FE_CHAN ) { return true; }
217  if ( fedApv_ == sistrip::invalid_ ) {
218  if ( gran == sistrip::FED_APV ) { return true; }
219  }
220  }
221  }
222  }
223  return false;
224 }
225 
226 // -----------------------------------------------------------------------------
227 //
229 
230  if ( fedId_ >= sistrip::FED_ID_MIN &&
232  fedId_ = fedId_;
233  } else if ( fedId_ == 0 ) {
234  fedId_ = fedId_;
235  } else {
237  }
238 
240  else { feUnit_ = sistrip::invalid_; }
241 
243  else { feChan_ = sistrip::invalid_; }
244 
246  else { fedApv_ = sistrip::invalid_; }
247 
248 }
249 
250 // -----------------------------------------------------------------------------
251 //
253 
254  if ( key() == sistrip::invalid32_ ) {
255 
256  // ---------- Set FedKey based on member data ----------
257 
258  // Initialise to null value
259  key(0);
260 
261  // Extract FED id
262  if ( fedId_ >= sistrip::FED_ID_MIN &&
264  key( key() | (fedId_<<fedIdOffset_) );
265  } else if ( fedId_ == 0 ) {
266  key( key() | (fedId_<<fedIdOffset_) );
267  } else {
268  key( key() | (fedIdMask_<<fedIdOffset_) );
269  }
270 
271  // Extract FE unit
272  if ( feUnit_ >= 1 &&
274  key( key() | (feUnit_<<feUnitOffset_) );
275  } else if ( feUnit_ == 0 ) {
276  key( key() | (feUnit_<<feUnitOffset_) );
277  } else {
278  key( key() | (feUnitMask_<<feUnitOffset_) );
279  }
280 
281  // Extract FE chan
282  if ( feChan_ >= 1 &&
284  key( key() | (feChan_<<feChanOffset_) );
285  } else if ( feChan_ == 0 ) {
286  key( key() | (feChan_<<feChanOffset_) );
287  } else {
288  key( key() | (feChanMask_<<feChanOffset_) );
289  }
290 
291  // Extract FED APV
292  if ( fedApv_ >= 1 &&
294  key( key() | (fedApv_<<fedApvOffset_) );
295  } else if ( fedApv_ == 0 ) {
296  key( key() | (fedApv_<<fedApvOffset_) );
297  } else {
298  key( key() | (fedApvMask_<<fedApvOffset_) );
299  }
300 
301  // Set invalid key if necessary
302  if ( fedId_ == sistrip::invalid_ &&
305  fedApv_ == sistrip::invalid_ ) {
307  }
308 
309  } else {
310 
311  // ---------- Set member data based on FED key ----------
312 
313  fedId_ = ( key()>>fedIdOffset_ ) & fedIdMask_;
317 
318  if ( fedId_ == fedIdMask_ ) { fedId_ = sistrip::invalid_; }
319  if ( feUnit_ == feUnitMask_ ) { feUnit_ = sistrip::invalid_; }
320  if ( feChan_ == feChanMask_ ) { feChan_ = sistrip::invalid_; }
321  if ( fedApv_ == fedApvMask_ ) { fedApv_ = sistrip::invalid_; }
322 
323  }
324 
325 }
326 
327 // -----------------------------------------------------------------------------
328 //
330 
331  if ( path() == sistrip::null_ ) {
332 
333  // ---------- Set directory path based on member data ----------
334 
335  std::stringstream dir;
336 
337  dir << sistrip::root_ << sistrip::dir_
339 
340  // Add FED id
341  if ( fedId_ ) {
343 
344  // Add FE unit
345  if ( feUnit_ ) {
347 
348  // Add FE channel
349  if ( feChan_ ) {
351 
352  // Add FED APV
353  if ( fedApv_ ) {
355  }
356  }
357  }
358  }
359 
360  std::string temp( dir.str() );
361  path( temp );
362 
363  } else {
364 
365  // ---------- Set member data based on directory path ----------
366 
367  fedId_ = 0;
368  feUnit_ = 0;
369  feChan_ = 0;
370  fedApv_ = 0;
371 
372  // Check if root is found
373  if ( path().find( sistrip::root_ ) == std::string::npos ) {
374  std::string temp = path();
376  }
377 
378  size_t curr = 0; // current string position
379  size_t next = 0; // next string position
380  next = path().find( sistrip::readoutView_, curr );
381 
382  // Extract view
383  curr = next;
384  if ( curr != std::string::npos ) {
385  next = path().find( sistrip::feDriver_, curr );
386  std::string readout_view( path(),
387  curr+(sizeof(sistrip::readoutView_) - 1),
388  (next-(sizeof(sistrip::dir_) - 1))-curr );
389 
390  // Extract FED id
391  curr = next;
392  if ( curr != std::string::npos ) {
393  next = path().find( sistrip::feUnit_, curr );
394  std::string fed_id( path(),
395  curr+(sizeof(sistrip::feDriver_) - 1),
396  (next-(sizeof(sistrip::dir_) - 1))-curr );
397  fedId_ = atoi( fed_id.c_str() );
398 
399  // Extract FE unit
400  curr = next;
401  if ( curr != std::string::npos ) {
402  next = path().find( sistrip::feChan_, curr );
403  std::string fe_unit( path(),
404  curr+(sizeof(sistrip::feUnit_) - 1),
405  next-curr );
406  feUnit_ = atoi( fe_unit.c_str() );
407 
408  // Extract FE channel
409  curr = next;
410  if ( curr != std::string::npos ) {
411  next = path().find( sistrip::fedApv_, curr );
412  std::string fe_chan( path(),
413  curr+(sizeof(sistrip::feChan_) - 1),
414  next-curr );
415  feChan_ = atoi( fe_chan.c_str() );
416 
417  // Extract FED APV
418  curr = next;
419  if ( curr != std::string::npos ) {
420  next = std::string::npos;
421  std::string fed_apv( path(),
422  curr+(sizeof(sistrip::fedApv_) - 1),
423  next-curr );
424  fedApv_ = atoi( fed_apv.c_str() );
425  }
426  }
427  }
428  }
429  } else {
430  std::stringstream ss;
431  ss << sistrip::root_ << sistrip::dir_;
432  //ss << sistrip::root_ << sistrip::dir_
433  //<< sistrip::unknownView_ << sistrip::dir_;
434  std::string temp( ss.str() );
435  path( temp );
436  }
437 
438  }
439 
440 }
441 
442 // -----------------------------------------------------------------------------
443 //
445 
447  channel(0);
448  if ( fedId_ && fedId_ != sistrip::invalid_ ) {
450  channel(fedId_);
451  if ( feUnit_ && feUnit_ != sistrip::invalid_ ) {
453  channel(feUnit_);
454  if ( feChan_ && feChan_ != sistrip::invalid_ ) {
456  channel(feChan_);
457  if ( fedApv_ && fedApv_ != sistrip::invalid_ ) {
459  channel(fedApv_);
460  } else if ( fedApv_ == sistrip::invalid_ ) {
463  }
464  } else if ( feChan_ == sistrip::invalid_ ) {
467  }
468  } else if ( feUnit_ == sistrip::invalid_ ) {
471  }
472  } else if ( fedId_ == sistrip::invalid_ ) {
475  }
476 
477 }
478 
479 // -----------------------------------------------------------------------------
480 //
481 void SiStripFedKey::terse( std::stringstream& ss ) const {
482  ss << "FED:crate/slot/id/unit/chan/apv= "
483  << "-" << "/"
484  << "-" << "/"
485  << fedId() << "/"
486  << feUnit() << "/"
487  << feChan() << "/"
488  << fedApv();
489 // ss << " FedKey"
490 // //<<"=0x"
491 // //<< std::hex
492 // //<< std::setfill('0') << std::setw(8) << key() << std::setfill(' ')
493 // //<< std::dec
494 // //<< ", " << ( isValid() ? "Valid" : "Invalid" )
495 // //<< ", FedCrate=" << fedCrate()
496 // //<< ", FedSlot=" << fedSlot()
497 // << ", FedId=" << fedId()
498 // << ", FeUnit=" << feUnit()
499 // << ", FeChan=" << feChan()
500 // //<< ", FedChannel=" << fedChannel()
501 // << ", FedApv=" << fedApv();
502 }
503 
504 // -----------------------------------------------------------------------------
505 //
506 void SiStripFedKey::print( std::stringstream& ss ) const {
507  ss << " [SiStripFedKey::print]" << std::endl
508  << std::hex
509  << " FED key : 0x"
510  << std::setfill('0')
511  << std::setw(8) << key() << std::endl
512  << std::setfill(' ')
513  << std::dec
514  << " FED id : " << fedId() << std::endl
515  << " Front-End unit : " << feUnit() << std::endl
516  << " Front-End chan : " << feChan() << std::endl
517  << " (internal chan) : "
518  << "(" << fedChannel() << ")" << std::endl
519  << " FED APV : " << fedApv() << std::endl
520  << " Directory : " << path() << std::endl
521  << " Granularity : "
523  << " Channel : " << channel() << std::endl
524  << " isValid : " << isValid();
525 }
526 
527 // -----------------------------------------------------------------------------
528 //
529 std::ostream& operator<< ( std::ostream& os, const SiStripFedKey& input ) {
530  std::stringstream ss;
531  input.print(ss);
532  os << ss.str();
533  return os;
534 }
static const char feDriver_[]
static const uint16_t feChanMask_
void initFromValue() override
static const uint16_t FED_ID_MIN
static const uint16_t feUnitOffset_
static const char dir_[]
void initFromPath() override
A container class for generic run and event-related info, information required by the commissioning a...
Definition: SiStripFedKey.h:56
Various generic constants used by DQM.
static const uint32_t invalid32_
Definition: Constants.h:15
void initFromKey() override
static std::string granularity(const sistrip::Granularity &)
bool isEqual(const SiStripKey &) const override
void terse(std::stringstream &ss) const override
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:20
void print(std::stringstream &ss) const override
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:44
const uint32_t & key() const
Definition: SiStripKey.h:125
const sistrip::Granularity & granularity() const
Definition: SiStripKey.h:127
uint16_t fedApv_
static const char fedApv_[]
static const uint16_t FEUNITS_PER_FED
Base utility class that identifies a position within a logical structure of the strip tracker...
Definition: SiStripKey.h:23
const std::string & path() const
Definition: SiStripKey.h:126
static const uint16_t feUnitMask_
uint16_t feChan_
uint16_t fedChannel() const
uint16_t fedId_
uint16_t feUnit_
static const uint16_t fedIdOffset_
void initGranularity() override
static const uint16_t feChanOffset_
const uint16_t & fedApv() const
const uint16_t & feUnit() const
static const char feChan_[]
const uint16_t & channel() const
Definition: SiStripKey.h:128
static const uint16_t FEDCH_PER_FEUNIT
Constants and enumerated types for FED/FEC systems.
static const uint16_t invalid_
Definition: Constants.h:16
bool isConsistent(const SiStripKey &) const override
static const uint16_t FEDCH_PER_FED
const uint16_t & feChan() const
bool isValid() const override
static const char root_[]
static const char feUnit_[]
static const uint16_t fedApvMask_
const uint16_t & fedId() const
static const uint16_t FED_ID_MAX
static uint16_t fedCh(const uint16_t &fe_unit, const uint16_t &fe_chan)
dbl *** dir
Definition: mlp_gen.cc:35
static const uint16_t fedIdMask_
bool isInvalid() const override
static const uint16_t APVS_PER_FEDCH
static const char readoutView_[]
static const uint16_t fedApvOffset_
static const char null_[]
Definition: Constants.h:22