CMS 3D CMS Logo

DCCSCBlock.cc
Go to the documentation of this file.
4 #include <cstdio>
6 
8  DCCDataUnpacker *u, EcalElectronicsMapper *m, DCCEventBlock *e, bool unpack, bool forceToKeepFRdata)
9  : DCCFEBlock(u, m, e, unpack, forceToKeepFRdata) {}
10 
13 
14  // needs to be update for eb/ee
16 
20 }
21 
22 int DCCSCBlock::unpackXtalData(unsigned int expStripID, unsigned int expXtalID) {
23  bool errorOnXtal(false);
24 
25  const uint16_t *xData_ = reinterpret_cast<const uint16_t *>(data_);
26 
27  // Get xtal data ids
28  unsigned int stripId = (*xData_) & TOWER_STRIPID_MASK;
29  unsigned int xtalId = ((*xData_) >> TOWER_XTALID_B) & TOWER_XTALID_MASK;
30 
31  // std::cout<<"\n DEBUG : unpacked xtal data for strip id "<<stripId<<" and xtal id "<<xtalId<<std::endl;
32  // std::cout<<"\n DEBUG : expected strip id "<<expStripID<<" expected xtal id "<<expXtalID<<std::endl;
33 
34  if (!zs_ && (expStripID != stripId || expXtalID != xtalId)) {
36  edm::LogWarning("IncorrectBlock") << "For event LV1: " << event_->l1A() << ", fed " << mapper_->getActiveDCC()
37  << " and tower " << towerId_ << "\n The expected strip is " << expStripID
38  << " and " << stripId << " was found"
39  << "\n The expected xtal is " << expXtalID << " and " << xtalId
40  << " was found";
41  }
42 
43  // using expected cry_di to raise warning about xtal_id problem
44  pDetId_ = (EEDetId *)mapper_->getDetIdPointer(towerId_, expStripID, expXtalID);
45  if (pDetId_) {
46  (*invalidChIds_)->push_back(*pDetId_);
47  }
48 
49  // return here, so to skip all following checks
51  return BLOCK_UNPACKED;
52  }
53 
54  // check id in case of 0suppressed data
55 
56  else if (zs_) {
57  // Check for valid Ids 1) values out of range
58 
59  if (stripId == 0 || stripId > 5 || xtalId == 0 || xtalId > 5) {
61  edm::LogWarning("IncorrectBlock")
62  << "For event LV1: " << event_->l1A() << ", fed " << mapper_->getActiveDCC() << " and tower " << towerId_
63  << "\n Invalid strip : " << stripId << " or xtal : " << xtalId << " ids ( last strip was: " << lastStripId_
64  << " last ch was: " << lastXtalId_ << ")";
65  }
66 
67  int st = lastStripId_;
68  int ch = lastXtalId_;
69  ch++;
70  if (ch > NUMB_XTAL) {
71  ch = 1;
72  st++;
73  }
74  if (st > NUMB_STRIP) {
75  ch = 1;
76  st = 1;
77  }
78 
79  // adding channel following the last valid
80  //pDetId_ = (EEDetId*) mapper_->getDetIdPointer(towerId_,st,ch);
81  //(*invalidChIds_)->push_back(*pDetId_);
83 
84  lastStripId_ = st;
85  lastXtalId_ = ch;
86 
87  // return here, so to skip all following checks
88  return SKIP_BLOCK_UNPACKING;
89  } else {
90  // Check for zs valid Ids 2) if channel-in-strip has increased wrt previous xtal
91  // 3) if strip has increased wrt previous xtal
92  if ((stripId == lastStripId_ && xtalId <= lastXtalId_) || (stripId < lastStripId_)) {
94  edm::LogWarning("IncorrectBlock")
95  << "Xtal id was expected to increase but it didn't - last xtal id was " << lastXtalId_
96  << " while current xtal is " << xtalId << " (LV1 " << event_->l1A() << " fed " << mapper_->getActiveDCC()
97  << " tower " << towerId_ << ")";
98  }
99 
100  int st = lastStripId_;
101  int ch = lastXtalId_;
102  ch++;
103  if (ch > NUMB_XTAL) {
104  ch = 1;
105  st++;
106  }
107  if (st > NUMB_STRIP) {
108  ch = 1;
109  st = 1;
110  }
111 
112  // adding channel following the last valid
113  //pDetId_ = (EEDetId*) mapper_->getDetIdPointer(towerId_,stripId,xtalId);
114  //(*invalidChIds_)->push_back(*pDetId_);
116 
117  lastStripId_ = st;
118  lastXtalId_ = ch;
119 
120  // return here, so to skip all following checks
121  return SKIP_BLOCK_UNPACKING;
122  }
123 
124  lastStripId_ = stripId;
125  lastXtalId_ = xtalId;
126  } // end else
127  } // end if(zs_)
128 
129  bool addedFrame = false;
130 
131  // if there is an error on xtal id ignore next error checks
132  // otherwise, assume channel_id is valid and proceed with making and checking the data frame
133  if (errorOnXtal)
134  return SKIP_BLOCK_UNPACKING;
135 
136  pDetId_ = (EEDetId *)mapper_->getDetIdPointer(towerId_, stripId, xtalId);
137 
138  if (pDetId_) { // checking that requested EEDetId exists
139 
140  (*digis_)->push_back(*pDetId_);
141  EEDataFrame df((*digis_)->back());
142  addedFrame = true;
143  bool wrongGain(false);
144 
145  //set samples in the frame
146  for (unsigned int i = 0; i < nTSamples_; i++) {
147  xData_++;
148  unsigned int data = (*xData_) & TOWER_DIGI_MASK;
149  unsigned int gain = data >> 12;
150  xtalGains_[i] = gain;
151  if (gain == 0) {
152  wrongGain = true;
153  } // although gain==0 found, produce the dataFrame in order to have it, for saturation case
154  df.setSample(i, data);
155  }
156 
157  bool isSaturation(true);
158  if (wrongGain) {
159  // check whether the gain==0 has features of saturation or not
160  // gain==0 occurs either in case of data corruption or of ADC saturation
161  // \->reject digi \-> keep digi
162 
163  // determine where gainId==0 starts
164  short firstGainZeroSampID(-1);
165  short firstGainZeroSampADC(-1);
166  for (unsigned int s = 0; s < nTSamples_; s++) {
167  if (df.sample(s).gainId() == 0 && firstGainZeroSampID == -1) {
168  firstGainZeroSampID = s;
169  firstGainZeroSampADC = df.sample(s).adc();
170  break;
171  }
172  }
173 
174  // check whether gain==0 and adc() stays constant for (at least) 5 consecutive samples
175  unsigned int plateauEnd = std::min(nTSamples_, (unsigned int)(firstGainZeroSampID + 5));
176  for (unsigned int s = firstGainZeroSampID; s < plateauEnd; s++) {
177  if (df.sample(s).gainId() == 0 && df.sample(s).adc() == firstGainZeroSampADC) {
178  ;
179  } else {
180  isSaturation = false;
181  break;
182  } //it's not saturation
183  }
184  // get rid of channels which are stuck in gain0
185  if (firstGainZeroSampID < 3) {
186  isSaturation = false;
187  }
188 
190  if (unpacker_->getChannelValue(mapper_->getActiveDCC(), towerId_, stripId, xtalId) != 10) {
191  edm::LogWarning("IncorrectGain")
192  << "Gain zero" << (isSaturation ? " with features of saturation" : "") << " was found in SC Block"
193  << " (L1A " << event_->l1A() << " bx " << event_->bx() << " fed " << mapper_->getActiveDCC() << " tower "
194  << towerId_ << " strip " << stripId << " xtal " << xtalId << ")";
195  }
196  }
197 
198  if (!isSaturation) {
199  (*invalidGains_)->push_back(*pDetId_);
200  (*digis_)->pop_back();
201 
202  //return here, so to skip all the rest
203  //make special collection for gain0 data frames (saturation)
204  //Point to begin of next xtal Block
206 
207  return BLOCK_UNPACKED;
208 
209  } //end isSaturation
210  else {
212  return BLOCK_UNPACKED;
213  }
214  } //end WrongGain
215 
216  short firstGainWrong = -1;
217  short numGainWrong = 0;
218 
219  for (unsigned int i = 1; i < nTSamples_; i++) {
220  if (xtalGains_[i - 1] > xtalGains_[i]) {
221  numGainWrong++;
222 
223  if (firstGainWrong == -1) {
224  firstGainWrong = i;
225  }
226  }
227  }
228 
229  if (numGainWrong > 0) {
231  edm::LogWarning("IncorrectGain") << "A wrong gain transition switch was found for SC Block in strip " << stripId
232  << " and xtal " << xtalId << " (L1A " << event_->l1A() << " bx "
233  << event_->bx() << " fed " << mapper_->getActiveDCC() << " tower " << towerId_
234  << ")";
235  }
236 
237  (*invalidGainsSwitch_)->push_back(*pDetId_);
238 
239  errorOnXtal = true;
240  }
241 
242  //Add frame to collection only if all data format and gain rules are respected
243  if (errorOnXtal && addedFrame) {
244  (*digis_)->pop_back();
245  }
246 
247  } // End 'if EE id exist'
248 
249  else {
250  // in case EEDetId do not exist
251  // In EE we may have crystals with no valid EEDetId
252  if (!mapper_->isGhost(mapper_->getActiveDCC(), towerId_, stripId)) { // check the VFE is not a 'ghost'
253 
254  // this is real EE VFE - print warning
256  edm::LogWarning("IncorrectBlock") << "An EEDetId was requested that does not exist "
257  << "(LV1 " << event_->l1A() << " fed " << mapper_->getActiveDCC() << " tower "
258  << towerId_ << " strip " << stripId << " xtal " << xtalId << ")";
259  }
260  }
261  }
262 
263  //Point to begin of next xtal Block
265 
266  return BLOCK_UNPACKED;
267 }
268 
269 void DCCSCBlock::fillEcalElectronicsError(std::unique_ptr<EcalElectronicsIdCollection> *errorColection) {
270  const int activeDCC = mapper_->getActiveSM();
271 
272  if ((NUMB_SM_EE_MIN_MIN <= activeDCC && activeDCC <= NUMB_SM_EE_MIN_MAX) ||
273  (NUMB_SM_EE_PLU_MIN <= activeDCC && activeDCC <= NUMB_SM_EE_PLU_MAX)) {
275  (*errorColection)->push_back(*eleTp);
276  } else {
278  edm::LogWarning("IncorrectBlock") << "For event " << event_->l1A() << " there's fed: " << activeDCC
279  << " activeDcc: " << mapper_->getActiveSM()
280  << " but that activeDcc is not valid in EE.";
281  }
282  }
283 }
unsigned int towerId_
Definition: DCCFEBlock.h:53
std::unique_ptr< EEDigiCollection > * eeDigisCollection()
std::unique_ptr< EEDetIdCollection > * invalidEEChIdsCollection()
unsigned int expTowerID_
Definition: DCCFEBlock.h:46
std::pair< unsigned int, unsigned int > unpack(cond::Time_t since)
std::unique_ptr< EEDetIdCollection > * invalidGainsSwitch_
Definition: DCCSCBlock.h:41
bool zs_
Definition: DCCFEBlock.h:42
Ecal readout channel identification [32:20] Unused (so far) [19:13] DCC id [12:6] tower [5:3] strip [...
EcalElectronicsId * getSCElectronicsPointer(unsigned int smId, unsigned int feChannel)
DetId * getDetIdPointer(unsigned int feChannel, unsigned int strip, unsigned int xtal)
unsigned int nTSamples_
Definition: DCCFEBlock.h:56
std::unique_ptr< EEDetIdCollection > * invalidEEGainsSwitchCollection()
void updateCollectors() override
Definition: DCCSCBlock.cc:11
uint16_t getChannelValue(const DetId &id) const
void updateCollectors() override
Definition: DCCFEBlock.cc:16
static std::atomic< bool > silentMode_
unsigned int lastXtalId_
Definition: DCCFEBlock.h:51
unsigned int bx()
Definition: DCCEventBlock.h:58
DCCSCBlock(DCCDataUnpacker *u, EcalElectronicsMapper *m, DCCEventBlock *e, bool unpack, bool forceToKeepFRdata)
Definition: DCCSCBlock.cc:7
std::unique_ptr< EEDetIdCollection > * invalidEEGainsCollection()
EEDetId * pDetId_
Definition: DCCSCBlock.h:34
std::unique_ptr< EEDetIdCollection > * invalidChIds_
Definition: DCCSCBlock.h:42
bool isGhost(const int FED, const int CCU, const int VFE)
std::unique_ptr< EEDetIdCollection > * invalidGains_
Definition: DCCSCBlock.h:40
int unpackXtalData(unsigned int stripID, unsigned int xtalID) override
Definition: DCCSCBlock.cc:22
unsigned int lastStripId_
Definition: DCCFEBlock.h:50
DCCDataUnpacker * unpacker_
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
unsigned int numbDWInXtalBlock_
Definition: DCCFEBlock.h:54
EcalElectronicsMapper * mapper_
std::unique_ptr< EcalElectronicsIdCollection > * invalidZSXtalIds_
Definition: DCCFEBlock.h:64
Log< level::Warning, false > LogWarning
short * xtalGains_
Definition: DCCFEBlock.h:62
std::unique_ptr< EEDigiCollection > * digis_
Definition: DCCSCBlock.h:37
void fillEcalElectronicsError(std::unique_ptr< EcalElectronicsIdCollection > *) override
Definition: DCCSCBlock.cc:269
unsigned int l1A()
Definition: DCCEventBlock.h:57