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 // Last commit: $Id: SiStripFedKey.cc,v 1.17 2012/07/04 19:04:52 eulisse Exp $
2 
9 #include <iomanip>
10 
11 // -----------------------------------------------------------------------------
12 //
13 SiStripFedKey::SiStripFedKey( const uint16_t& fed_id,
14  const uint16_t& fe_unit,
15  const uint16_t& fe_chan,
16  const uint16_t& fed_apv ) :
17  SiStripKey(),
18  fedId_(fed_id),
19  feUnit_(fe_unit),
20  feChan_(fe_chan),
21  fedApv_(fed_apv)
22 {
23  // order is important!
24  initFromValue();
25  initFromKey();
26  initFromPath();
28 }
29 
30 // -----------------------------------------------------------------------------
31 //
32 SiStripFedKey::SiStripFedKey( const uint32_t& fed_key ) :
33  SiStripKey(fed_key),
34  fedId_(sistrip::invalid_),
35  feUnit_(sistrip::invalid_),
36  feChan_(sistrip::invalid_),
37  fedApv_(sistrip::invalid_)
38 {
39  // order is important!
40  initFromKey();
41  initFromValue();
42  initFromPath();
44 }
45 
46 // -----------------------------------------------------------------------------
47 //
49  SiStripKey(path),
50  fedId_(sistrip::invalid_),
51  feUnit_(sistrip::invalid_),
52  feChan_(sistrip::invalid_),
53  fedApv_(sistrip::invalid_)
54 {
55  // order is important!
56  initFromPath();
57  initFromValue();
58  initFromKey();
60 }
61 
62 // -----------------------------------------------------------------------------
63 //
65  SiStripKey(),
66  fedId_(input.fedId()),
67  feUnit_(input.feUnit()),
68  feChan_(input.feChan()),
69  fedApv_(input.fedApv())
70 {
71  key(input.key());
72  path(input.path());
73  granularity(input.granularity());
74 }
75 
76 // -----------------------------------------------------------------------------
77 //
79  SiStripKey(),
80  fedId_(sistrip::invalid_),
81  feUnit_(sistrip::invalid_),
82  feChan_(sistrip::invalid_),
83  fedApv_(sistrip::invalid_)
84 {
85  const SiStripFedKey& fed_key = dynamic_cast<const SiStripFedKey&>(input);
86  if ( (&fed_key) ) {
87  key(fed_key.key());
88  path(fed_key.path());
89  granularity(fed_key.granularity());
90  fedId_ = fed_key.fedId();
91  feUnit_ = fed_key.feUnit();
92  feChan_ = fed_key.feChan();
93  fedApv_ = fed_key.fedApv();
94  }
95 }
96 
97 // -----------------------------------------------------------------------------
98 //
100  SiStripKey(),
101  fedId_(sistrip::invalid_),
102  feUnit_(sistrip::invalid_),
103  feChan_(sistrip::invalid_),
104  fedApv_(sistrip::invalid_)
105 {;}
106 
107 // -----------------------------------------------------------------------------
108 //
109 uint16_t SiStripFedKey::fedCh( const uint16_t& fe_unit,
110  const uint16_t& fe_chan ) {
111  if ( fe_unit <= sistrip::FEUNITS_PER_FED &&
112  fe_chan <= sistrip::FEDCH_PER_FEUNIT ) {
113  if ( fe_unit != 0 && fe_chan != 0 ) {
114  return ( 95 - ( 12 * (fe_unit-1) + (fe_chan-1) ) );
115  }
116  }
117  return sistrip::invalid_;
118 }
119 
120 // -----------------------------------------------------------------------------
121 //
122 uint16_t SiStripFedKey::feUnit( const uint16_t& fed_ch ) {
123  if ( fed_ch < sistrip::FEDCH_PER_FED ) {
124  return ( (95-fed_ch)/12 + 1 );
125  }
126  return sistrip::invalid_;
127 }
128 
129 // -----------------------------------------------------------------------------
130 //
131 uint16_t SiStripFedKey::feChan( const uint16_t& fed_ch ) {
132  if ( fed_ch < sistrip::FEDCH_PER_FED ) {
133  return ( (95-fed_ch)%12 + 1 );
134  }
135  return sistrip::invalid_;
136 }
137 
138 // -----------------------------------------------------------------------------
139 //
140 uint32_t SiStripFedKey::fedIndex( const uint16_t& fed_id,
141  const uint16_t& fed_ch ) {
142  if ( fed_id < sistrip::FED_ID_MIN ||
143  fed_id > sistrip::FED_ID_MAX ||
144  fed_ch >= sistrip::FEDCH_PER_FED ) { return sistrip::invalid32_; }
145  return ( fed_id * sistrip::FEDCH_PER_FED + fed_ch );
146 }
147 
148 // -----------------------------------------------------------------------------
149 //
150 bool SiStripFedKey::isEqual( const SiStripKey& key ) const {
151  const SiStripFedKey& input = dynamic_cast<const SiStripFedKey&>(key);
152  if ( !(&input) ) { return false; }
153  if ( fedId_ == input.fedId() &&
154  feUnit_ == input.feUnit() &&
155  feChan_ == input.feChan() &&
156  fedApv_ == input.fedApv() ) {
157  return true;
158  } else { return false; }
159 }
160 
161 // -----------------------------------------------------------------------------
162 //
164  const SiStripFedKey& input = dynamic_cast<const SiStripFedKey&>(key);
165  if ( !(&input) ) { return false; }
166  if ( isEqual(input) ) { return true; }
167  else if ( ( fedId_ == 0 || input.fedId() == 0 ) &&
168  ( feUnit_ == 0 || input.feUnit() == 0 ) &&
169  ( feChan_ == 0 || input.feChan() == 0 ) &&
170  ( fedApv_ == 0 || input.fedApv() == 0 ) ) {
171  return true;
172  } else { return false; }
173 }
174 
175 // -----------------------------------------------------------------------------
176 //
177 bool SiStripFedKey::isValid() const {
178  return isValid(sistrip::FED_APV);
179 }
180 
181 // -----------------------------------------------------------------------------
182 //
183 bool SiStripFedKey::isValid( const sistrip::Granularity& gran ) const {
184  if ( gran == sistrip::FED_SYSTEM ) { return true; }
185  else if ( gran == sistrip::UNDEFINED_GRAN ||
186  gran == sistrip::UNKNOWN_GRAN ) { return false; }
187 
188  if ( fedId_ != sistrip::invalid_ ) {
189  if ( gran == sistrip::FE_DRIVER ) { return true; }
190  if ( feUnit_ != sistrip::invalid_ ) {
191  if ( gran == sistrip::FE_UNIT ) { return true; }
192  if ( feChan_ != sistrip::invalid_ ) {
193  if ( gran == sistrip::FE_CHAN ) { return true; }
194  if ( fedApv_ != sistrip::invalid_ ) {
195  if ( gran == sistrip::FED_APV ) { return true; }
196  }
197  }
198  }
199  }
200  return false;
201 }
202 
203 // -----------------------------------------------------------------------------
204 //
206  return isInvalid(sistrip::FED_APV);
207 }
208 
209 // -----------------------------------------------------------------------------
210 //
212  if ( gran == sistrip::FED_SYSTEM ) { return false; }
213  else if ( gran == sistrip::UNDEFINED_GRAN ||
214  gran == sistrip::UNKNOWN_GRAN ) { return false; }
215 
216  if ( fedId_ == sistrip::invalid_ ) {
217  if ( gran == sistrip::FE_DRIVER ) { return true; }
218  if ( feUnit_ == sistrip::invalid_ ) {
219  if ( gran == sistrip::FE_UNIT ) { return true; }
220  if ( feChan_ == sistrip::invalid_ ) {
221  if ( gran == sistrip::FE_CHAN ) { return true; }
222  if ( fedApv_ == sistrip::invalid_ ) {
223  if ( gran == sistrip::FED_APV ) { return true; }
224  }
225  }
226  }
227  }
228  return false;
229 }
230 
231 // -----------------------------------------------------------------------------
232 //
234 
235  if ( fedId_ >= sistrip::FED_ID_MIN &&
237  fedId_ = fedId_;
238  } else if ( fedId_ == 0 ) {
239  fedId_ = fedId_;
240  } else {
242  }
243 
245  else { feUnit_ = sistrip::invalid_; }
246 
248  else { feChan_ = sistrip::invalid_; }
249 
251  else { fedApv_ = sistrip::invalid_; }
252 
253 }
254 
255 // -----------------------------------------------------------------------------
256 //
258 
259  if ( key() == sistrip::invalid32_ ) {
260 
261  // ---------- Set FedKey based on member data ----------
262 
263  // Initialise to null value
264  key(0);
265 
266  // Extract FED id
267  if ( fedId_ >= sistrip::FED_ID_MIN &&
269  key( key() | (fedId_<<fedIdOffset_) );
270  } else if ( fedId_ == 0 ) {
271  key( key() | (fedId_<<fedIdOffset_) );
272  } else {
273  key( key() | (fedIdMask_<<fedIdOffset_) );
274  }
275 
276  // Extract FE unit
277  if ( feUnit_ >= 1 &&
279  key( key() | (feUnit_<<feUnitOffset_) );
280  } else if ( feUnit_ == 0 ) {
281  key( key() | (feUnit_<<feUnitOffset_) );
282  } else {
283  key( key() | (feUnitMask_<<feUnitOffset_) );
284  }
285 
286  // Extract FE chan
287  if ( feChan_ >= 1 &&
289  key( key() | (feChan_<<feChanOffset_) );
290  } else if ( feChan_ == 0 ) {
291  key( key() | (feChan_<<feChanOffset_) );
292  } else {
293  key( key() | (feChanMask_<<feChanOffset_) );
294  }
295 
296  // Extract FED APV
297  if ( fedApv_ >= 1 &&
299  key( key() | (fedApv_<<fedApvOffset_) );
300  } else if ( fedApv_ == 0 ) {
301  key( key() | (fedApv_<<fedApvOffset_) );
302  } else {
303  key( key() | (fedApvMask_<<fedApvOffset_) );
304  }
305 
306  // Set invalid key if necessary
307  if ( fedId_ == sistrip::invalid_ &&
310  fedApv_ == sistrip::invalid_ ) {
312  }
313 
314  } else {
315 
316  // ---------- Set member data based on FED key ----------
317 
318  fedId_ = ( key()>>fedIdOffset_ ) & fedIdMask_;
322 
323  if ( fedId_ == fedIdMask_ ) { fedId_ = sistrip::invalid_; }
324  if ( feUnit_ == feUnitMask_ ) { feUnit_ = sistrip::invalid_; }
325  if ( feChan_ == feChanMask_ ) { feChan_ = sistrip::invalid_; }
326  if ( fedApv_ == fedApvMask_ ) { fedApv_ = sistrip::invalid_; }
327 
328  }
329 
330 }
331 
332 // -----------------------------------------------------------------------------
333 //
335 
336  if ( path() == sistrip::null_ ) {
337 
338  // ---------- Set directory path based on member data ----------
339 
340  std::stringstream dir;
341 
342  dir << sistrip::root_ << sistrip::dir_
344 
345  // Add FED id
346  if ( fedId_ ) {
348 
349  // Add FE unit
350  if ( feUnit_ ) {
352 
353  // Add FE channel
354  if ( feChan_ ) {
356 
357  // Add FED APV
358  if ( fedApv_ ) {
360  }
361  }
362  }
363  }
364 
365  std::string temp( dir.str() );
366  path( temp );
367 
368  } else {
369 
370  // ---------- Set member data based on directory path ----------
371 
372  fedId_ = 0;
373  feUnit_ = 0;
374  feChan_ = 0;
375  fedApv_ = 0;
376 
377  // Check if root is found
378  if ( path().find( sistrip::root_ ) == std::string::npos ) {
379  std::string temp = path();
381  }
382 
383  size_t curr = 0; // current string position
384  size_t next = 0; // next string position
385  next = path().find( sistrip::readoutView_, curr );
386 
387  // Extract view
388  curr = next;
389  if ( curr != std::string::npos ) {
390  next = path().find( sistrip::feDriver_, curr );
391  std::string readout_view( path(),
392  curr+(sizeof(sistrip::readoutView_) - 1),
393  (next-(sizeof(sistrip::dir_) - 1))-curr );
394 
395  // Extract FED id
396  curr = next;
397  if ( curr != std::string::npos ) {
398  next = path().find( sistrip::feUnit_, curr );
399  std::string fed_id( path(),
400  curr+(sizeof(sistrip::feDriver_) - 1),
401  (next-(sizeof(sistrip::dir_) - 1))-curr );
402  fedId_ = atoi( fed_id.c_str() );
403 
404  // Extract FE unit
405  curr = next;
406  if ( curr != std::string::npos ) {
407  next = path().find( sistrip::feChan_, curr );
408  std::string fe_unit( path(),
409  curr+(sizeof(sistrip::feUnit_) - 1),
410  next-curr );
411  feUnit_ = atoi( fe_unit.c_str() );
412 
413  // Extract FE channel
414  curr = next;
415  if ( curr != std::string::npos ) {
416  next = path().find( sistrip::fedApv_, curr );
417  std::string fe_chan( path(),
418  curr+(sizeof(sistrip::feChan_) - 1),
419  next-curr );
420  feChan_ = atoi( fe_chan.c_str() );
421 
422  // Extract FED APV
423  curr = next;
424  if ( curr != std::string::npos ) {
425  next = std::string::npos;
426  std::string fed_apv( path(),
427  curr+(sizeof(sistrip::fedApv_) - 1),
428  next-curr );
429  fedApv_ = atoi( fed_apv.c_str() );
430  }
431  }
432  }
433  }
434  } else {
435  std::stringstream ss;
436  ss << sistrip::root_ << sistrip::dir_;
437  //ss << sistrip::root_ << sistrip::dir_
438  //<< sistrip::unknownView_ << sistrip::dir_;
439  std::string temp( ss.str() );
440  path( temp );
441  }
442 
443  }
444 
445 }
446 
447 // -----------------------------------------------------------------------------
448 //
450 
452  channel(0);
453  if ( fedId_ && fedId_ != sistrip::invalid_ ) {
455  channel(fedId_);
456  if ( feUnit_ && feUnit_ != sistrip::invalid_ ) {
458  channel(feUnit_);
459  if ( feChan_ && feChan_ != sistrip::invalid_ ) {
461  channel(feChan_);
462  if ( fedApv_ && fedApv_ != sistrip::invalid_ ) {
464  channel(fedApv_);
465  } else if ( fedApv_ == sistrip::invalid_ ) {
468  }
469  } else if ( feChan_ == sistrip::invalid_ ) {
472  }
473  } else if ( feUnit_ == sistrip::invalid_ ) {
476  }
477  } else if ( fedId_ == sistrip::invalid_ ) {
480  }
481 
482 }
483 
484 // -----------------------------------------------------------------------------
485 //
486 void SiStripFedKey::terse( std::stringstream& ss ) const {
487  ss << "FED:crate/slot/id/unit/chan/apv= "
488  << "-" << "/"
489  << "-" << "/"
490  << fedId() << "/"
491  << feUnit() << "/"
492  << feChan() << "/"
493  << fedApv();
494 // ss << " FedKey"
495 // //<<"=0x"
496 // //<< std::hex
497 // //<< std::setfill('0') << std::setw(8) << key() << std::setfill(' ')
498 // //<< std::dec
499 // //<< ", " << ( isValid() ? "Valid" : "Invalid" )
500 // //<< ", FedCrate=" << fedCrate()
501 // //<< ", FedSlot=" << fedSlot()
502 // << ", FedId=" << fedId()
503 // << ", FeUnit=" << feUnit()
504 // << ", FeChan=" << feChan()
505 // //<< ", FedChannel=" << fedChannel()
506 // << ", FedApv=" << fedApv();
507 }
508 
509 // -----------------------------------------------------------------------------
510 //
511 void SiStripFedKey::print( std::stringstream& ss ) const {
512  ss << " [SiStripFedKey::print]" << std::endl
513  << std::hex
514  << " FED key : 0x"
515  << std::setfill('0')
516  << std::setw(8) << key() << std::endl
517  << std::setfill(' ')
518  << std::dec
519  << " FED id : " << fedId() << std::endl
520  << " Front-End unit : " << feUnit() << std::endl
521  << " Front-End chan : " << feChan() << std::endl
522  << " (internal chan) : "
523  << "(" << fedChannel() << ")" << std::endl
524  << " FED APV : " << fedApv() << std::endl
525  << " Directory : " << path() << std::endl
526  << " Granularity : "
528  << " Channel : " << channel() << std::endl
529  << " isValid : " << isValid();
530 }
531 
532 // -----------------------------------------------------------------------------
533 //
534 std::ostream& operator<< ( std::ostream& os, const SiStripFedKey& input ) {
535  std::stringstream ss;
536  input.print(ss);
537  os << ss.str();
538  return os;
539 }
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:57
bool isInvalid() const
Various generic constants used by DQM.
static const uint32_t invalid32_
Definition: Constants.h:16
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.
const uint32_t & key() const
Definition: SiStripKey.h:126
const sistrip::Granularity & granularity() const
Definition: SiStripKey.h:128
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:24
const std::string & path() const
Definition: SiStripKey.h:127
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:129
static const uint16_t FEDCH_PER_FEUNIT
Constants and enumerated types for FED/FEC systems.
static const uint16_t invalid_
Definition: Constants.h:17
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:23