CMS 3D CMS Logo

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