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 ( not ( (fedId_ >= sistrip::FED_ID_MIN &&
232  ( fedId_ == 0 ) ) ) {
234  }
235 
237 
239 
241 
242 }
243 
244 // -----------------------------------------------------------------------------
245 //
247 
248  if ( key() == sistrip::invalid32_ ) {
249 
250  // ---------- Set FedKey based on member data ----------
251 
252  // Initialise to null value
253  key(0);
254 
255  // Extract FED id
256  if ( fedId_ >= sistrip::FED_ID_MIN &&
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 &&
268  key( key() | (feUnit_<<feUnitOffset_) );
269  } else if ( feUnit_ == 0 ) {
270  key( key() | (feUnit_<<feUnitOffset_) );
271  } else {
272  key( key() | (feUnitMask_<<feUnitOffset_) );
273  }
274 
275  // Extract FE chan
276  if ( feChan_ >= 1 &&
278  key( key() | (feChan_<<feChanOffset_) );
279  } else if ( feChan_ == 0 ) {
280  key( key() | (feChan_<<feChanOffset_) );
281  } else {
282  key( key() | (feChanMask_<<feChanOffset_) );
283  }
284 
285  // Extract FED APV
286  if ( fedApv_ >= 1 &&
288  key( key() | (fedApv_<<fedApvOffset_) );
289  } else if ( fedApv_ == 0 ) {
290  key( key() | (fedApv_<<fedApvOffset_) );
291  } else {
292  key( key() | (fedApvMask_<<fedApvOffset_) );
293  }
294 
295  // Set invalid key if necessary
296  if ( fedId_ == sistrip::invalid_ &&
299  fedApv_ == sistrip::invalid_ ) {
301  }
302 
303  } else {
304 
305  // ---------- Set member data based on FED key ----------
306 
307  fedId_ = ( key()>>fedIdOffset_ ) & fedIdMask_;
311 
312  if ( fedId_ == fedIdMask_ ) { fedId_ = sistrip::invalid_; }
313  if ( feUnit_ == feUnitMask_ ) { feUnit_ = sistrip::invalid_; }
314  if ( feChan_ == feChanMask_ ) { feChan_ = sistrip::invalid_; }
315  if ( fedApv_ == fedApvMask_ ) { fedApv_ = sistrip::invalid_; }
316 
317  }
318 
319 }
320 
321 // -----------------------------------------------------------------------------
322 //
324 
325  if ( path() == sistrip::null_ ) {
326 
327  // ---------- Set directory path based on member data ----------
328 
329  std::stringstream dir;
330 
331  dir << sistrip::root_ << sistrip::dir_
333 
334  // Add FED id
335  if ( fedId_ ) {
337 
338  // Add FE unit
339  if ( feUnit_ ) {
341 
342  // Add FE channel
343  if ( feChan_ ) {
345 
346  // Add FED APV
347  if ( fedApv_ ) {
349  }
350  }
351  }
352  }
353 
354  std::string temp( dir.str() );
355  path( temp );
356 
357  } else {
358 
359  // ---------- Set member data based on directory path ----------
360 
361  fedId_ = 0;
362  feUnit_ = 0;
363  feChan_ = 0;
364  fedApv_ = 0;
365 
366  // Check if root is found
367  if ( path().find( sistrip::root_ ) == std::string::npos ) {
368  std::string temp = path();
370  }
371 
372  size_t curr = 0; // current string position
373  size_t next = 0; // next string position
374  next = path().find( sistrip::readoutView_, curr );
375 
376  // Extract view
377  curr = next;
378  if ( curr != std::string::npos ) {
379  next = path().find( sistrip::feDriver_, curr );
380  std::string readout_view( path(),
381  curr+(sizeof(sistrip::readoutView_) - 1),
382  (next-(sizeof(sistrip::dir_) - 1))-curr );
383 
384  // Extract FED id
385  curr = next;
386  if ( curr != std::string::npos ) {
387  next = path().find( sistrip::feUnit_, curr );
388  std::string fed_id( path(),
389  curr+(sizeof(sistrip::feDriver_) - 1),
390  (next-(sizeof(sistrip::dir_) - 1))-curr );
391  fedId_ = atoi( fed_id.c_str() );
392 
393  // Extract FE unit
394  curr = next;
395  if ( curr != std::string::npos ) {
396  next = path().find( sistrip::feChan_, curr );
397  std::string fe_unit( path(),
398  curr+(sizeof(sistrip::feUnit_) - 1),
399  next-curr );
400  feUnit_ = atoi( fe_unit.c_str() );
401 
402  // Extract FE channel
403  curr = next;
404  if ( curr != std::string::npos ) {
405  next = path().find( sistrip::fedApv_, curr );
406  std::string fe_chan( path(),
407  curr+(sizeof(sistrip::feChan_) - 1),
408  next-curr );
409  feChan_ = atoi( fe_chan.c_str() );
410 
411  // Extract FED APV
412  curr = next;
413  if ( curr != std::string::npos ) {
414  next = std::string::npos;
415  std::string fed_apv( path(),
416  curr+(sizeof(sistrip::fedApv_) - 1),
417  next-curr );
418  fedApv_ = atoi( fed_apv.c_str() );
419  }
420  }
421  }
422  }
423  } else {
424  std::stringstream ss;
425  ss << sistrip::root_ << sistrip::dir_;
426  //ss << sistrip::root_ << sistrip::dir_
427  //<< sistrip::unknownView_ << sistrip::dir_;
428  std::string temp( ss.str() );
429  path( temp );
430  }
431 
432  }
433 
434 }
435 
436 // -----------------------------------------------------------------------------
437 //
439 
441  channel(0);
442  if ( fedId_ && fedId_ != sistrip::invalid_ ) {
444  channel(fedId_);
445  if ( feUnit_ && feUnit_ != sistrip::invalid_ ) {
447  channel(feUnit_);
448  if ( feChan_ && feChan_ != sistrip::invalid_ ) {
450  channel(feChan_);
451  if ( fedApv_ && fedApv_ != sistrip::invalid_ ) {
453  channel(fedApv_);
454  } else if ( fedApv_ == sistrip::invalid_ ) {
457  }
458  } else if ( feChan_ == sistrip::invalid_ ) {
461  }
462  } else if ( feUnit_ == sistrip::invalid_ ) {
465  }
466  } else if ( fedId_ == sistrip::invalid_ ) {
469  }
470 
471 }
472 
473 // -----------------------------------------------------------------------------
474 //
475 void SiStripFedKey::terse( std::stringstream& ss ) const {
476  ss << "FED:crate/slot/id/unit/chan/apv= "
477  << "-" << "/"
478  << "-" << "/"
479  << fedId() << "/"
480  << feUnit() << "/"
481  << feChan() << "/"
482  << fedApv();
483 // ss << " FedKey"
484 // //<<"=0x"
485 // //<< std::hex
486 // //<< std::setfill('0') << std::setw(8) << key() << std::setfill(' ')
487 // //<< std::dec
488 // //<< ", " << ( isValid() ? "Valid" : "Invalid" )
489 // //<< ", FedCrate=" << fedCrate()
490 // //<< ", FedSlot=" << fedSlot()
491 // << ", FedId=" << fedId()
492 // << ", FeUnit=" << feUnit()
493 // << ", FeChan=" << feChan()
494 // //<< ", FedChannel=" << fedChannel()
495 // << ", FedApv=" << fedApv();
496 }
497 
498 // -----------------------------------------------------------------------------
499 //
500 void SiStripFedKey::print( std::stringstream& ss ) const {
501  ss << " [SiStripFedKey::print]" << std::endl
502  << std::hex
503  << " FED key : 0x"
504  << std::setfill('0')
505  << std::setw(8) << key() << std::endl
506  << std::setfill(' ')
507  << std::dec
508  << " FED id : " << fedId() << std::endl
509  << " Front-End unit : " << feUnit() << std::endl
510  << " Front-End chan : " << feChan() << std::endl
511  << " (internal chan) : "
512  << "(" << fedChannel() << ")" << std::endl
513  << " FED APV : " << fedApv() << std::endl
514  << " Directory : " << path() << std::endl
515  << " Granularity : "
517  << " Channel : " << channel() << std::endl
518  << " isValid : " << isValid();
519 }
520 
521 // -----------------------------------------------------------------------------
522 //
523 std::ostream& operator<< ( std::ostream& os, const SiStripFedKey& input ) {
524  std::stringstream ss;
525  input.print(ss);
526  os << ss.str();
527  return os;
528 }
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:45
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