CMS 3D CMS Logo

EcalSampleMask.cc
Go to the documentation of this file.
1 
7 #include <cassert>
11 
12 
13 using edm::LogError;
14 
16 {
17  // by default, all samples are set as active
20 }
21 
22 
23 EcalSampleMask::EcalSampleMask(const unsigned int ebmask, const unsigned int eemask) {
24  sampleMaskEB_ = ebmask;
25  sampleMaskEE_ = eemask;
26 }
27 
28 
29 EcalSampleMask::EcalSampleMask( const std::vector<unsigned int> &ebmask, const std::vector<unsigned int> &eemask) {
30  setEcalSampleMaskRecordEB( ebmask );
31  setEcalSampleMaskRecordEE( eemask );
32 }
33 
34 
36 
37 }
38 
39 
40 void EcalSampleMask::setEcalSampleMaskRecordEB( const std::vector<unsigned int> & ebmask ) {
41 
42  // check that size of the vector is adequate
43  if( ebmask.size() != static_cast<unsigned int>(EcalDataFrame::MAXSAMPLES) ){
44  LogError("DataMismatch")<< " in EcalSampleMask::setEcalSampleMaskRecordEB size of ebmask (" << ebmask.size() << ") need to be: " << EcalDataFrame::MAXSAMPLES
45  << ". Bailing out."<< std::endl;
46  assert(0);
47  }
48 
49  // check that values of vector are allowed
50  for (unsigned int s=0; s<ebmask.size(); s++ ) {
51  if ( ebmask.at(s)==0 || ebmask.at(s)==1 ) {;}
52  else {
53  LogError("DataMismatch")<< "in EcalSampleMask::setEcalSampleMaskRecordEB ebmask can only have values 0 or 1, while " << ebmask.at(s) << " was found. Bailing out. " << std::endl;
54  assert(0);
55  }
56  }
57 
58  // ordering of bits:
59  // ebmask.at(0) refers to the first sample read out and is mapped into the _most_ significant bit of sampleMaskEB_
60  // ebmask.at(EcalDataFrame::MAXSAMPLES) refers to the last sample read out and is mapped into the _least_ significant bit of sampleMaskEB_
61  sampleMaskEB_=0;
62  for (unsigned int sampleId=0; sampleId<ebmask.size(); sampleId++ ) {
63  sampleMaskEB_ |= (0x1 << (EcalDataFrame::MAXSAMPLES -(sampleId+1) ));
64  }
65 
66 }
67 
68 void EcalSampleMask::setEcalSampleMaskRecordEE( const std::vector<unsigned int> & eemask ) {
69 
70  // check that size of the vector is adequate
71  if( eemask.size() != static_cast<unsigned int>(EcalDataFrame::MAXSAMPLES) ){
72  LogError("DataMismatch") << " in EcalSampleMask::setEcalSampleMaskRecordEE size of eemask (" << eemask.size() << ") need to be: " << EcalDataFrame::MAXSAMPLES
73  << ". Bailing out."<< std::endl;
74  assert(0);
75  }
76 
77  // check that values of vector are allowed
78  for (unsigned int s=0; s<eemask.size(); s++ ) {
79  if ( eemask.at(s)==0 || eemask.at(s)==1 ) {;}
80  else {
81  LogError("DataMismatch") << "in EcalSampleMask::setEcalSampleMaskRecordEE eemask can only have values 0 or 1, while " << eemask.at(s) << " was found. Bailing out. " << std::endl;
82  assert(0);
83  }
84  }
85 
86  // ordering of bits:
87  // eemask.at(0) refers to the first sample read out and is mapped into the _most_ significant bit of sampleMaskEE_
88  // eemask.at(EcalDataFrame::MAXSAMPLES) refers to the last sample read out and is mapped into the _least_ significant bit of sampleMaskEE_
89  sampleMaskEE_=0;
90  for (unsigned int sampleId=0; sampleId<eemask.size(); sampleId++ ) {
91  sampleMaskEE_ |= (0x1 << (EcalDataFrame::MAXSAMPLES -(sampleId+1) ));
92  }
93 
94 }
95 
96 
97 bool EcalSampleMask::useSampleEB (const int sampleId) const {
98 
99  if( sampleId >= EcalDataFrame::MAXSAMPLES ){
100  LogError("DataMismatch")<< "in EcalSampleMask::useSampleEB only sampleId up to: " << EcalDataFrame::MAXSAMPLES
101  << " can be used, while: " << sampleId << " was found. Bailing out." << std::endl;
102  assert(0);
103  }
104 
105  // ordering convention:
106  // ebmask.at(0) refers to the first sample read out and is mapped into the _most_ significant bit of sampleMaskEB_
107  // ebmask.at(EcalDataFrame::MAXSAMPLES) refers to the last sample read out and is mapped into the _least_ significant bit of sampleMaskEB_
108  return ( sampleMaskEB_ & ( 0x1<< (EcalDataFrame::MAXSAMPLES -(sampleId+1) )) );
109 
110 }
111 
112 
113 bool EcalSampleMask::useSampleEE (const int sampleId) const {
114 
115  if( sampleId >= EcalDataFrame::MAXSAMPLES ){
116  LogError("DataMismatch")<< "in EcalSampleMask::useSampleEE only sampleId up to: " << EcalDataFrame::MAXSAMPLES
117  << " can be used, while: " << sampleId << " was found. Bailing out." << std::endl;
118  assert(0);
119  }
120 
121  // ordering convention:
122  // ebmask.at(0) refers to the first sample read out and is mapped into the _most_ significant bit of sampleMaskEB_
123  // ebmask.at(EcalDataFrame::MAXSAMPLES) refers to the last sample read out and is mapped into the _least_ significant bit of sampleMaskEB_
124  return ( sampleMaskEE_ & ( 0x1<< (EcalDataFrame::MAXSAMPLES -(sampleId+1) )) );
125 
126 }
127 
128 
129 bool EcalSampleMask::useSample (const int sampleId, DetId &theCrystalId) const {
130 
131  if( sampleId >= EcalDataFrame::MAXSAMPLES ){
132  LogError("DataMismatch")<< "in EcalSampleMask::useSample only sampleId up to: " << EcalDataFrame::MAXSAMPLES
133  << " can be used, while: " << sampleId << " was found. Bailing out." << std::endl;
134  assert(0);
135  }
136 
137 
138  if (theCrystalId.subdetId()==EcalBarrel) {
139  return useSampleEB ( sampleId );
140  }
141  else if (theCrystalId.subdetId()==EcalEndcap) {
142  return useSampleEE ( sampleId );
143  }
144  else {
145  LogError("DataMismatch")<< "EcalSampleMaskuseSample::useSample can only be called for EcalBarrel or EcalEndcap DetID" << std::endl;
146  assert(0);
147  }
148 
149 }
150 
151 // LocalWords: eemask
void setEcalSampleMaskRecordEE(const unsigned int mask)
unsigned int sampleMaskEB_
bool useSample(const int sampleId, DetId &theCrystal) const
bool useSampleEB(const int sampleId) const
unsigned int sampleMaskEE_
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:41
Definition: DetId.h:18
void setEcalSampleMaskRecordEB(const unsigned int mask)
static constexpr int MAXSAMPLES
Definition: EcalDataFrame.h:48
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40
bool useSampleEE(const int sampleId) const