CMS 3D CMS Logo

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