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.16 2009/10/23 13:07:17 lowette 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 //
48 SiStripFedKey::SiStripFedKey( const std::string& path ) :
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  SiStripKey& temp = const_cast<SiStripKey&>(input);
86  SiStripFedKey& fed_key = dynamic_cast<SiStripFedKey&>(temp);
87  if ( (&fed_key) ) {
88  key(fed_key.key());
89  path(fed_key.path());
90  granularity(fed_key.granularity());
91  fedId_ = fed_key.fedId();
92  feUnit_ = fed_key.feUnit();
93  feChan_ = fed_key.feChan();
94  fedApv_ = fed_key.fedApv();
95  }
96 }
97 
98 // -----------------------------------------------------------------------------
99 //
101  SiStripKey(),
102  fedId_(sistrip::invalid_),
103  feUnit_(sistrip::invalid_),
104  feChan_(sistrip::invalid_),
105  fedApv_(sistrip::invalid_)
106 {;}
107 
108 // -----------------------------------------------------------------------------
109 //
110 uint16_t SiStripFedKey::fedCh( const uint16_t& fe_unit,
111  const uint16_t& fe_chan ) {
112  if ( fe_unit <= sistrip::FEUNITS_PER_FED &&
113  fe_chan <= sistrip::FEDCH_PER_FEUNIT ) {
114  if ( fe_unit != 0 && fe_chan != 0 ) {
115  return ( 95 - ( 12 * (fe_unit-1) + (fe_chan-1) ) );
116  }
117  }
118  return sistrip::invalid_;
119 }
120 
121 // -----------------------------------------------------------------------------
122 //
123 uint16_t SiStripFedKey::feUnit( const uint16_t& fed_ch ) {
124  if ( fed_ch < sistrip::FEDCH_PER_FED ) {
125  return ( (95-fed_ch)/12 + 1 );
126  }
127  return sistrip::invalid_;
128 }
129 
130 // -----------------------------------------------------------------------------
131 //
132 uint16_t SiStripFedKey::feChan( const uint16_t& fed_ch ) {
133  if ( fed_ch < sistrip::FEDCH_PER_FED ) {
134  return ( (95-fed_ch)%12 + 1 );
135  }
136  return sistrip::invalid_;
137 }
138 
139 // -----------------------------------------------------------------------------
140 //
141 uint32_t SiStripFedKey::fedIndex( const uint16_t& fed_id,
142  const uint16_t& fed_ch ) {
143  if ( fed_id < sistrip::FED_ID_MIN ||
144  fed_id > sistrip::FED_ID_MAX ||
145  fed_ch >= sistrip::FEDCH_PER_FED ) { return sistrip::invalid32_; }
146  return ( fed_id * sistrip::FEDCH_PER_FED + fed_ch );
147 }
148 
149 // -----------------------------------------------------------------------------
150 //
151 bool SiStripFedKey::isEqual( const SiStripKey& key ) const {
152  SiStripKey& temp = const_cast<SiStripKey&>(key);
153  SiStripFedKey& input = dynamic_cast<SiStripFedKey&>(temp);
154  if ( !(&input) ) { return false; }
155  if ( fedId_ == input.fedId() &&
156  feUnit_ == input.feUnit() &&
157  feChan_ == input.feChan() &&
158  fedApv_ == input.fedApv() ) {
159  return true;
160  } else { return false; }
161 }
162 
163 // -----------------------------------------------------------------------------
164 //
166  SiStripKey& temp = const_cast<SiStripKey&>(key);
167  SiStripFedKey& input = dynamic_cast<SiStripFedKey&>(temp);
168  if ( !(&input) ) { return false; }
169  if ( isEqual(input) ) { return true; }
170  else if ( ( fedId_ == 0 || input.fedId() == 0 ) &&
171  ( feUnit_ == 0 || input.feUnit() == 0 ) &&
172  ( feChan_ == 0 || input.feChan() == 0 ) &&
173  ( fedApv_ == 0 || input.fedApv() == 0 ) ) {
174  return true;
175  } else { return false; }
176 }
177 
178 // -----------------------------------------------------------------------------
179 //
180 bool SiStripFedKey::isValid() const {
181  return isValid(sistrip::FED_APV);
182 }
183 
184 // -----------------------------------------------------------------------------
185 //
186 bool SiStripFedKey::isValid( const sistrip::Granularity& gran ) const {
187  if ( gran == sistrip::FED_SYSTEM ) { return true; }
188  else if ( gran == sistrip::UNDEFINED_GRAN ||
189  gran == sistrip::UNKNOWN_GRAN ) { return false; }
190 
191  if ( fedId_ != sistrip::invalid_ ) {
192  if ( gran == sistrip::FE_DRIVER ) { return true; }
193  if ( feUnit_ != sistrip::invalid_ ) {
194  if ( gran == sistrip::FE_UNIT ) { return true; }
195  if ( feChan_ != sistrip::invalid_ ) {
196  if ( gran == sistrip::FE_CHAN ) { return true; }
197  if ( fedApv_ != sistrip::invalid_ ) {
198  if ( gran == sistrip::FED_APV ) { return true; }
199  }
200  }
201  }
202  }
203  return false;
204 }
205 
206 // -----------------------------------------------------------------------------
207 //
209  return isInvalid(sistrip::FED_APV);
210 }
211 
212 // -----------------------------------------------------------------------------
213 //
215  if ( gran == sistrip::FED_SYSTEM ) { return false; }
216  else if ( gran == sistrip::UNDEFINED_GRAN ||
217  gran == sistrip::UNKNOWN_GRAN ) { return false; }
218 
219  if ( fedId_ == sistrip::invalid_ ) {
220  if ( gran == sistrip::FE_DRIVER ) { return true; }
221  if ( feUnit_ == sistrip::invalid_ ) {
222  if ( gran == sistrip::FE_UNIT ) { return true; }
223  if ( feChan_ == sistrip::invalid_ ) {
224  if ( gran == sistrip::FE_CHAN ) { return true; }
225  if ( fedApv_ == sistrip::invalid_ ) {
226  if ( gran == sistrip::FED_APV ) { return true; }
227  }
228  }
229  }
230  }
231  return false;
232 }
233 
234 // -----------------------------------------------------------------------------
235 //
237 
238  if ( fedId_ >= sistrip::FED_ID_MIN &&
240  fedId_ = fedId_;
241  } else if ( fedId_ == 0 ) {
242  fedId_ = fedId_;
243  } else {
245  }
246 
248  else { feUnit_ = sistrip::invalid_; }
249 
251  else { feChan_ = sistrip::invalid_; }
252 
254  else { fedApv_ = sistrip::invalid_; }
255 
256 }
257 
258 // -----------------------------------------------------------------------------
259 //
261 
262  if ( key() == sistrip::invalid32_ ) {
263 
264  // ---------- Set FedKey based on member data ----------
265 
266  // Initialise to null value
267  key(0);
268 
269  // Extract FED id
270  if ( fedId_ >= sistrip::FED_ID_MIN &&
272  key( key() | (fedId_<<fedIdOffset_) );
273  } else if ( fedId_ == 0 ) {
274  key( key() | (fedId_<<fedIdOffset_) );
275  } else {
276  key( key() | (fedIdMask_<<fedIdOffset_) );
277  }
278 
279  // Extract FE unit
280  if ( feUnit_ >= 1 &&
282  key( key() | (feUnit_<<feUnitOffset_) );
283  } else if ( feUnit_ == 0 ) {
284  key( key() | (feUnit_<<feUnitOffset_) );
285  } else {
286  key( key() | (feUnitMask_<<feUnitOffset_) );
287  }
288 
289  // Extract FE chan
290  if ( feChan_ >= 1 &&
292  key( key() | (feChan_<<feChanOffset_) );
293  } else if ( feChan_ == 0 ) {
294  key( key() | (feChan_<<feChanOffset_) );
295  } else {
296  key( key() | (feChanMask_<<feChanOffset_) );
297  }
298 
299  // Extract FED APV
300  if ( fedApv_ >= 1 &&
302  key( key() | (fedApv_<<fedApvOffset_) );
303  } else if ( fedApv_ == 0 ) {
304  key( key() | (fedApv_<<fedApvOffset_) );
305  } else {
306  key( key() | (fedApvMask_<<fedApvOffset_) );
307  }
308 
309  // Set invalid key if necessary
310  if ( fedId_ == sistrip::invalid_ &&
313  fedApv_ == sistrip::invalid_ ) {
315  }
316 
317  } else {
318 
319  // ---------- Set member data based on FED key ----------
320 
321  fedId_ = ( key()>>fedIdOffset_ ) & fedIdMask_;
325 
326  if ( fedId_ == fedIdMask_ ) { fedId_ = sistrip::invalid_; }
327  if ( feUnit_ == feUnitMask_ ) { feUnit_ = sistrip::invalid_; }
328  if ( feChan_ == feChanMask_ ) { feChan_ = sistrip::invalid_; }
329  if ( fedApv_ == fedApvMask_ ) { fedApv_ = sistrip::invalid_; }
330 
331  }
332 
333 }
334 
335 // -----------------------------------------------------------------------------
336 //
338 
339  if ( path() == sistrip::null_ ) {
340 
341  // ---------- Set directory path based on member data ----------
342 
343  std::stringstream dir;
344 
345  dir << sistrip::root_ << sistrip::dir_
347 
348  // Add FED id
349  if ( fedId_ ) {
351 
352  // Add FE unit
353  if ( feUnit_ ) {
355 
356  // Add FE channel
357  if ( feChan_ ) {
359 
360  // Add FED APV
361  if ( fedApv_ ) {
363  }
364  }
365  }
366  }
367 
368  std::string temp( dir.str() );
369  path( temp );
370 
371  } else {
372 
373  // ---------- Set member data based on directory path ----------
374 
375  fedId_ = 0;
376  feUnit_ = 0;
377  feChan_ = 0;
378  fedApv_ = 0;
379 
380  // Check if root is found
381  if ( path().find( sistrip::root_ ) == std::string::npos ) {
382  std::string temp = path();
383  path( std::string(sistrip::root_) + sistrip::dir_ + temp );
384  }
385 
386  size_t curr = 0; // current string position
387  size_t next = 0; // next string position
388  next = path().find( sistrip::readoutView_, curr );
389 
390  // Extract view
391  curr = next;
392  if ( curr != std::string::npos ) {
393  next = path().find( sistrip::feDriver_, curr );
394  std::string readout_view( path(),
395  curr+(sizeof(sistrip::readoutView_) - 1),
396  (next-(sizeof(sistrip::dir_) - 1))-curr );
397 
398  // Extract FED id
399  curr = next;
400  if ( curr != std::string::npos ) {
401  next = path().find( sistrip::feUnit_, curr );
402  std::string fed_id( path(),
403  curr+(sizeof(sistrip::feDriver_) - 1),
404  (next-(sizeof(sistrip::dir_) - 1))-curr );
405  fedId_ = atoi( fed_id.c_str() );
406 
407  // Extract FE unit
408  curr = next;
409  if ( curr != std::string::npos ) {
410  next = path().find( sistrip::feChan_, curr );
411  std::string fe_unit( path(),
412  curr+(sizeof(sistrip::feUnit_) - 1),
413  next-curr );
414  feUnit_ = atoi( fe_unit.c_str() );
415 
416  // Extract FE channel
417  curr = next;
418  if ( curr != std::string::npos ) {
419  next = path().find( sistrip::fedApv_, curr );
420  std::string fe_chan( path(),
421  curr+(sizeof(sistrip::feChan_) - 1),
422  next-curr );
423  feChan_ = atoi( fe_chan.c_str() );
424 
425  // Extract FED APV
426  curr = next;
427  if ( curr != std::string::npos ) {
428  next = std::string::npos;
429  std::string fed_apv( path(),
430  curr+(sizeof(sistrip::fedApv_) - 1),
431  next-curr );
432  fedApv_ = atoi( fed_apv.c_str() );
433  }
434  }
435  }
436  }
437  } else {
438  std::stringstream ss;
439  ss << sistrip::root_ << sistrip::dir_;
440  //ss << sistrip::root_ << sistrip::dir_
441  //<< sistrip::unknownView_ << sistrip::dir_;
442  std::string temp( ss.str() );
443  path( temp );
444  }
445 
446  }
447 
448 }
449 
450 // -----------------------------------------------------------------------------
451 //
453 
455  channel(0);
456  if ( fedId_ && fedId_ != sistrip::invalid_ ) {
458  channel(fedId_);
459  if ( feUnit_ && feUnit_ != sistrip::invalid_ ) {
461  channel(feUnit_);
462  if ( feChan_ && feChan_ != sistrip::invalid_ ) {
464  channel(feChan_);
465  if ( fedApv_ && fedApv_ != sistrip::invalid_ ) {
467  channel(fedApv_);
468  } else if ( fedApv_ == sistrip::invalid_ ) {
471  }
472  } else if ( feChan_ == sistrip::invalid_ ) {
475  }
476  } else if ( feUnit_ == sistrip::invalid_ ) {
479  }
480  } else if ( fedId_ == sistrip::invalid_ ) {
483  }
484 
485 }
486 
487 // -----------------------------------------------------------------------------
488 //
489 void SiStripFedKey::terse( std::stringstream& ss ) const {
490  ss << "FED:crate/slot/id/unit/chan/apv= "
491  << "-" << "/"
492  << "-" << "/"
493  << fedId() << "/"
494  << feUnit() << "/"
495  << feChan() << "/"
496  << fedApv();
497 // ss << " FedKey"
498 // //<<"=0x"
499 // //<< std::hex
500 // //<< std::setfill('0') << std::setw(8) << key() << std::setfill(' ')
501 // //<< std::dec
502 // //<< ", " << ( isValid() ? "Valid" : "Invalid" )
503 // //<< ", FedCrate=" << fedCrate()
504 // //<< ", FedSlot=" << fedSlot()
505 // << ", FedId=" << fedId()
506 // << ", FeUnit=" << feUnit()
507 // << ", FeChan=" << feChan()
508 // //<< ", FedChannel=" << fedChannel()
509 // << ", FedApv=" << fedApv();
510 }
511 
512 // -----------------------------------------------------------------------------
513 //
514 void SiStripFedKey::print( std::stringstream& ss ) const {
515  ss << " [SiStripFedKey::print]" << std::endl
516  << std::hex
517  << " FED key : 0x"
518  << std::setfill('0')
519  << std::setw(8) << key() << std::endl
520  << std::setfill(' ')
521  << std::dec
522  << " FED id : " << fedId() << std::endl
523  << " Front-End unit : " << feUnit() << std::endl
524  << " Front-End chan : " << feChan() << std::endl
525  << " (internal chan) : "
526  << "(" << fedChannel() << ")" << std::endl
527  << " FED APV : " << fedApv() << std::endl
528  << " Directory : " << path() << std::endl
529  << " Granularity : "
531  << " Channel : " << channel() << std::endl
532  << " isValid : " << isValid();
533 }
534 
535 // -----------------------------------------------------------------------------
536 //
537 std::ostream& operator<< ( std::ostream& os, const SiStripFedKey& input ) {
538  std::stringstream ss;
539  input.print(ss);
540  os << ss.str();
541  return os;
542 }
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
list path
Definition: scaleCards.py:51
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