CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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),
33  fedId_(sistrip::invalid_),
34  feUnit_(sistrip::invalid_),
35  feChan_(sistrip::invalid_),
36  fedApv_(sistrip::invalid_)
37 {
38  // order is important!
39  initFromKey();
40  initFromValue();
41  initFromPath();
43 }
44 
45 // -----------------------------------------------------------------------------
46 //
48  SiStripKey(path),
49  fedId_(sistrip::invalid_),
50  feUnit_(sistrip::invalid_),
51  feChan_(sistrip::invalid_),
52  fedApv_(sistrip::invalid_)
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(),
79  fedId_(sistrip::invalid_),
80  feUnit_(sistrip::invalid_),
81  feChan_(sistrip::invalid_),
82  fedApv_(sistrip::invalid_)
83 {
84  const SiStripFedKey& fed_key = dynamic_cast<const SiStripFedKey&>(input);
85  if ( (&fed_key) ) {
86  key(fed_key.key());
87  path(fed_key.path());
88  granularity(fed_key.granularity());
89  fedId_ = fed_key.fedId();
90  feUnit_ = fed_key.feUnit();
91  feChan_ = fed_key.feChan();
92  fedApv_ = fed_key.fedApv();
93  }
94 }
95 
96 // -----------------------------------------------------------------------------
97 //
99  SiStripKey(),
100  fedId_(sistrip::invalid_),
101  feUnit_(sistrip::invalid_),
102  feChan_(sistrip::invalid_),
103  fedApv_(sistrip::invalid_)
104 {;}
105 
106 // -----------------------------------------------------------------------------
107 //
108 uint16_t SiStripFedKey::fedCh( const uint16_t& fe_unit,
109  const uint16_t& fe_chan ) {
110  if ( fe_unit <= sistrip::FEUNITS_PER_FED &&
111  fe_chan <= sistrip::FEDCH_PER_FEUNIT ) {
112  if ( fe_unit != 0 && fe_chan != 0 ) {
113  return ( 95 - ( 12 * (fe_unit-1) + (fe_chan-1) ) );
114  }
115  }
116  return sistrip::invalid_;
117 }
118 
119 // -----------------------------------------------------------------------------
120 //
121 uint16_t SiStripFedKey::feUnit( const uint16_t& fed_ch ) {
122  if ( fed_ch < sistrip::FEDCH_PER_FED ) {
123  return ( (95-fed_ch)/12 + 1 );
124  }
125  return sistrip::invalid_;
126 }
127 
128 // -----------------------------------------------------------------------------
129 //
130 uint16_t SiStripFedKey::feChan( const uint16_t& fed_ch ) {
131  if ( fed_ch < sistrip::FEDCH_PER_FED ) {
132  return ( (95-fed_ch)%12 + 1 );
133  }
134  return sistrip::invalid_;
135 }
136 
137 // -----------------------------------------------------------------------------
138 //
139 uint32_t SiStripFedKey::fedIndex( const uint16_t& fed_id,
140  const uint16_t& fed_ch ) {
141  if ( fed_id < sistrip::FED_ID_MIN ||
142  fed_id > sistrip::FED_ID_MAX ||
143  fed_ch >= sistrip::FEDCH_PER_FED ) { return sistrip::invalid32_; }
144  return ( fed_id * sistrip::FEDCH_PER_FED + fed_ch );
145 }
146 
147 // -----------------------------------------------------------------------------
148 //
149 bool SiStripFedKey::isEqual( const SiStripKey& key ) const {
150  const SiStripFedKey& input = dynamic_cast<const SiStripFedKey&>(key);
151  if ( !(&input) ) { return false; }
152  if ( fedId_ == input.fedId() &&
153  feUnit_ == input.feUnit() &&
154  feChan_ == input.feChan() &&
155  fedApv_ == input.fedApv() ) {
156  return true;
157  } else { return false; }
158 }
159 
160 // -----------------------------------------------------------------------------
161 //
163  const SiStripFedKey& input = dynamic_cast<const SiStripFedKey&>(key);
164  if ( !(&input) ) { return false; }
165  if ( isEqual(input) ) { return true; }
166  else if ( ( fedId_ == 0 || input.fedId() == 0 ) &&
167  ( feUnit_ == 0 || input.feUnit() == 0 ) &&
168  ( feChan_ == 0 || input.feChan() == 0 ) &&
169  ( fedApv_ == 0 || input.fedApv() == 0 ) ) {
170  return true;
171  } else { return false; }
172 }
173 
174 // -----------------------------------------------------------------------------
175 //
176 bool SiStripFedKey::isValid() const {
177  return isValid(sistrip::FED_APV);
178 }
179 
180 // -----------------------------------------------------------------------------
181 //
182 bool SiStripFedKey::isValid( const sistrip::Granularity& gran ) const {
183  if ( gran == sistrip::FED_SYSTEM ) { return true; }
184  else if ( gran == sistrip::UNDEFINED_GRAN ||
185  gran == sistrip::UNKNOWN_GRAN ) { return false; }
186 
187  if ( fedId_ != sistrip::invalid_ ) {
188  if ( gran == sistrip::FE_DRIVER ) { return true; }
189  if ( feUnit_ != sistrip::invalid_ ) {
190  if ( gran == sistrip::FE_UNIT ) { return true; }
191  if ( feChan_ != sistrip::invalid_ ) {
192  if ( gran == sistrip::FE_CHAN ) { return true; }
193  if ( fedApv_ != sistrip::invalid_ ) {
194  if ( gran == sistrip::FED_APV ) { return true; }
195  }
196  }
197  }
198  }
199  return false;
200 }
201 
202 // -----------------------------------------------------------------------------
203 //
205  return isInvalid(sistrip::FED_APV);
206 }
207 
208 // -----------------------------------------------------------------------------
209 //
211  if ( gran == sistrip::FED_SYSTEM ) { return false; }
212  else if ( gran == sistrip::UNDEFINED_GRAN ||
213  gran == sistrip::UNKNOWN_GRAN ) { return false; }
214 
215  if ( fedId_ == sistrip::invalid_ ) {
216  if ( gran == sistrip::FE_DRIVER ) { return true; }
217  if ( feUnit_ == sistrip::invalid_ ) {
218  if ( gran == sistrip::FE_UNIT ) { return true; }
219  if ( feChan_ == sistrip::invalid_ ) {
220  if ( gran == sistrip::FE_CHAN ) { return true; }
221  if ( fedApv_ == sistrip::invalid_ ) {
222  if ( gran == sistrip::FED_APV ) { return true; }
223  }
224  }
225  }
226  }
227  return false;
228 }
229 
230 // -----------------------------------------------------------------------------
231 //
233 
234  if ( fedId_ >= sistrip::FED_ID_MIN &&
236  fedId_ = fedId_;
237  } else if ( fedId_ == 0 ) {
238  fedId_ = fedId_;
239  } else {
241  }
242 
244  else { feUnit_ = sistrip::invalid_; }
245 
247  else { feChan_ = sistrip::invalid_; }
248 
250  else { fedApv_ = sistrip::invalid_; }
251 
252 }
253 
254 // -----------------------------------------------------------------------------
255 //
257 
258  if ( key() == sistrip::invalid32_ ) {
259 
260  // ---------- Set FedKey based on member data ----------
261 
262  // Initialise to null value
263  key(0);
264 
265  // Extract FED id
266  if ( fedId_ >= sistrip::FED_ID_MIN &&
268  key( key() | (fedId_<<fedIdOffset_) );
269  } else if ( fedId_ == 0 ) {
270  key( key() | (fedId_<<fedIdOffset_) );
271  } else {
272  key( key() | (fedIdMask_<<fedIdOffset_) );
273  }
274 
275  // Extract FE unit
276  if ( feUnit_ >= 1 &&
278  key( key() | (feUnit_<<feUnitOffset_) );
279  } else if ( feUnit_ == 0 ) {
280  key( key() | (feUnit_<<feUnitOffset_) );
281  } else {
282  key( key() | (feUnitMask_<<feUnitOffset_) );
283  }
284 
285  // Extract FE chan
286  if ( feChan_ >= 1 &&
288  key( key() | (feChan_<<feChanOffset_) );
289  } else if ( feChan_ == 0 ) {
290  key( key() | (feChan_<<feChanOffset_) );
291  } else {
292  key( key() | (feChanMask_<<feChanOffset_) );
293  }
294 
295  // Extract FED APV
296  if ( fedApv_ >= 1 &&
298  key( key() | (fedApv_<<fedApvOffset_) );
299  } else if ( fedApv_ == 0 ) {
300  key( key() | (fedApv_<<fedApvOffset_) );
301  } else {
302  key( key() | (fedApvMask_<<fedApvOffset_) );
303  }
304 
305  // Set invalid key if necessary
306  if ( fedId_ == sistrip::invalid_ &&
309  fedApv_ == sistrip::invalid_ ) {
311  }
312 
313  } else {
314 
315  // ---------- Set member data based on FED key ----------
316 
317  fedId_ = ( key()>>fedIdOffset_ ) & fedIdMask_;
321 
322  if ( fedId_ == fedIdMask_ ) { fedId_ = sistrip::invalid_; }
323  if ( feUnit_ == feUnitMask_ ) { feUnit_ = sistrip::invalid_; }
324  if ( feChan_ == feChanMask_ ) { feChan_ = sistrip::invalid_; }
325  if ( fedApv_ == fedApvMask_ ) { fedApv_ = sistrip::invalid_; }
326 
327  }
328 
329 }
330 
331 // -----------------------------------------------------------------------------
332 //
334 
335  if ( path() == sistrip::null_ ) {
336 
337  // ---------- Set directory path based on member data ----------
338 
339  std::stringstream dir;
340 
341  dir << sistrip::root_ << sistrip::dir_
343 
344  // Add FED id
345  if ( fedId_ ) {
347 
348  // Add FE unit
349  if ( feUnit_ ) {
351 
352  // Add FE channel
353  if ( feChan_ ) {
355 
356  // Add FED APV
357  if ( fedApv_ ) {
359  }
360  }
361  }
362  }
363 
364  std::string temp( dir.str() );
365  path( temp );
366 
367  } else {
368 
369  // ---------- Set member data based on directory path ----------
370 
371  fedId_ = 0;
372  feUnit_ = 0;
373  feChan_ = 0;
374  fedApv_ = 0;
375 
376  // Check if root is found
377  if ( path().find( sistrip::root_ ) == std::string::npos ) {
378  std::string temp = path();
380  }
381 
382  size_t curr = 0; // current string position
383  size_t next = 0; // next string position
384  next = path().find( sistrip::readoutView_, curr );
385 
386  // Extract view
387  curr = next;
388  if ( curr != std::string::npos ) {
389  next = path().find( sistrip::feDriver_, curr );
390  std::string readout_view( path(),
391  curr+(sizeof(sistrip::readoutView_) - 1),
392  (next-(sizeof(sistrip::dir_) - 1))-curr );
393 
394  // Extract FED id
395  curr = next;
396  if ( curr != std::string::npos ) {
397  next = path().find( sistrip::feUnit_, curr );
398  std::string fed_id( path(),
399  curr+(sizeof(sistrip::feDriver_) - 1),
400  (next-(sizeof(sistrip::dir_) - 1))-curr );
401  fedId_ = atoi( fed_id.c_str() );
402 
403  // Extract FE unit
404  curr = next;
405  if ( curr != std::string::npos ) {
406  next = path().find( sistrip::feChan_, curr );
407  std::string fe_unit( path(),
408  curr+(sizeof(sistrip::feUnit_) - 1),
409  next-curr );
410  feUnit_ = atoi( fe_unit.c_str() );
411 
412  // Extract FE channel
413  curr = next;
414  if ( curr != std::string::npos ) {
415  next = path().find( sistrip::fedApv_, curr );
416  std::string fe_chan( path(),
417  curr+(sizeof(sistrip::feChan_) - 1),
418  next-curr );
419  feChan_ = atoi( fe_chan.c_str() );
420 
421  // Extract FED APV
422  curr = next;
423  if ( curr != std::string::npos ) {
424  next = std::string::npos;
425  std::string fed_apv( path(),
426  curr+(sizeof(sistrip::fedApv_) - 1),
427  next-curr );
428  fedApv_ = atoi( fed_apv.c_str() );
429  }
430  }
431  }
432  }
433  } else {
434  std::stringstream ss;
435  ss << sistrip::root_ << sistrip::dir_;
436  //ss << sistrip::root_ << sistrip::dir_
437  //<< sistrip::unknownView_ << sistrip::dir_;
438  std::string temp( ss.str() );
439  path( temp );
440  }
441 
442  }
443 
444 }
445 
446 // -----------------------------------------------------------------------------
447 //
449 
451  channel(0);
452  if ( fedId_ && fedId_ != sistrip::invalid_ ) {
454  channel(fedId_);
455  if ( feUnit_ && feUnit_ != sistrip::invalid_ ) {
457  channel(feUnit_);
458  if ( feChan_ && feChan_ != sistrip::invalid_ ) {
460  channel(feChan_);
461  if ( fedApv_ && fedApv_ != sistrip::invalid_ ) {
463  channel(fedApv_);
464  } else if ( fedApv_ == sistrip::invalid_ ) {
467  }
468  } else if ( feChan_ == sistrip::invalid_ ) {
471  }
472  } else if ( feUnit_ == sistrip::invalid_ ) {
475  }
476  } else if ( fedId_ == sistrip::invalid_ ) {
479  }
480 
481 }
482 
483 // -----------------------------------------------------------------------------
484 //
485 void SiStripFedKey::terse( std::stringstream& ss ) const {
486  ss << "FED:crate/slot/id/unit/chan/apv= "
487  << "-" << "/"
488  << "-" << "/"
489  << fedId() << "/"
490  << feUnit() << "/"
491  << feChan() << "/"
492  << fedApv();
493 // ss << " FedKey"
494 // //<<"=0x"
495 // //<< std::hex
496 // //<< std::setfill('0') << std::setw(8) << key() << std::setfill(' ')
497 // //<< std::dec
498 // //<< ", " << ( isValid() ? "Valid" : "Invalid" )
499 // //<< ", FedCrate=" << fedCrate()
500 // //<< ", FedSlot=" << fedSlot()
501 // << ", FedId=" << fedId()
502 // << ", FeUnit=" << feUnit()
503 // << ", FeChan=" << feChan()
504 // //<< ", FedChannel=" << fedChannel()
505 // << ", FedApv=" << fedApv();
506 }
507 
508 // -----------------------------------------------------------------------------
509 //
510 void SiStripFedKey::print( std::stringstream& ss ) const {
511  ss << " [SiStripFedKey::print]" << std::endl
512  << std::hex
513  << " FED key : 0x"
514  << std::setfill('0')
515  << std::setw(8) << key() << std::endl
516  << std::setfill(' ')
517  << std::dec
518  << " FED id : " << fedId() << std::endl
519  << " Front-End unit : " << feUnit() << std::endl
520  << " Front-End chan : " << feChan() << std::endl
521  << " (internal chan) : "
522  << "(" << fedChannel() << ")" << std::endl
523  << " FED APV : " << fedApv() << std::endl
524  << " Directory : " << path() << std::endl
525  << " Granularity : "
527  << " Channel : " << channel() << std::endl
528  << " isValid : " << isValid();
529 }
530 
531 // -----------------------------------------------------------------------------
532 //
533 std::ostream& operator<< ( std::ostream& os, const SiStripFedKey& input ) {
534  std::stringstream ss;
535  input.print(ss);
536  os << ss.str();
537  return os;
538 }
static const char feDriver_[]
static const uint16_t feChanMask_
static const uint16_t FED_ID_MIN
bool isConsistent(const SiStripKey &) const
virtual void print(std::stringstream &ss) const
static const uint16_t feUnitOffset_
static const char dir_[]
A container class for generic run and event-related info, information required by the commissioning a...
Definition: SiStripFedKey.h:56
bool isInvalid() const
Various generic constants used by DQM.
static const uint32_t invalid32_
Definition: Constants.h:15
static std::string granularity(const sistrip::Granularity &)
std::ostream & operator<<(std::ostream &out, const ALILine &li)
Definition: ALILine.cc:187
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
static uint32_t fedIndex(const uint16_t &fed_id, const uint16_t &fed_ch)
virtual void terse(std::stringstream &ss) const
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_[]
bool isEqual(const SiStripKey &) const
static const uint16_t FEUNITS_PER_FED
bool isValid() const
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_
void initFromValue()
uint16_t fedChannel() const
uint16_t fedId_
uint16_t feUnit_
static const uint16_t fedIdOffset_
void initGranularity()
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
list key
Definition: combine.py:13
static const uint16_t FEDCH_PER_FED
const uint16_t & feChan() const
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_
static const uint16_t APVS_PER_FEDCH
static const char readoutView_[]
static const uint16_t fedApvOffset_
static const char null_[]
Definition: Constants.h:22