CMS 3D CMS Logo

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