CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DCCSCBlock.cc
Go to the documentation of this file.
4 #include <stdio.h>
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  stripId = expStripID;
59  xtalId = expXtalID;
60  errorOnXtal = true;
61 
62  // return here, so to skip all following checks
64  return BLOCK_UNPACKED;
65  }
66 
67 
68  // check id in case of 0suppressed data
69 
70  else if(zs_) {
71 
72  // Check for valid Ids 1) values out of range
73 
74  if (stripId == 0 || stripId > 5 || xtalId == 0 || xtalId > 5) {
75 
77  edm::LogWarning("IncorrectBlock")
78  <<"For event LV1: "<<event_->l1A()<<", fed "<<mapper_->getActiveDCC()<<" and tower "<<towerId_
79  <<"\n Invalid strip : "<<stripId<<" or xtal : "<<xtalId
80  <<" ids ( last strip was: " << lastStripId_ << " last ch was: " << lastXtalId_ << ")";
81  }
82 
83  int st = lastStripId_;
84  int ch = lastXtalId_;
85  ch++;
86  if (ch > NUMB_XTAL) {ch=1; st++;}
87  if (st > NUMB_STRIP) {ch=1; st=1;}
88 
89  // adding channel following the last valid
90  //pDetId_ = (EEDetId*) mapper_->getDetIdPointer(towerId_,st,ch);
91  //(*invalidChIds_)->push_back(*pDetId_);
93  errorOnXtal = true;
94 
95  lastStripId_ = st;
96  lastXtalId_ = ch;
97 
98  // return here, so to skip all following checks
99  return SKIP_BLOCK_UNPACKING;
100  }
101  else {
102  // Check for zs valid Ids 2) if channel-in-strip has increased wrt previous xtal
103  // 3) if strip has increased wrt previous xtal
104  if ((stripId == lastStripId_ && xtalId <= lastXtalId_ ) ||
105  (stripId < lastStripId_))
106  {
108  edm::LogWarning("IncorrectBlock")
109  << "Xtal id was expected to increase but it didn't - last xtal id was " << lastXtalId_ << " while current xtal is " << xtalId
110  << " (LV1 " << event_->l1A() << " fed " << mapper_->getActiveDCC() << " tower " << towerId_ << ")";
111  }
112 
113  int st = lastStripId_;
114  int ch = lastXtalId_;
115  ch++;
116  if (ch > NUMB_XTAL) {ch=1; st++;}
117  if (st > NUMB_STRIP) {ch=1; st=1;}
118 
119  // adding channel following the last valid
120  //pDetId_ = (EEDetId*) mapper_->getDetIdPointer(towerId_,stripId,xtalId);
121  //(*invalidChIds_)->push_back(*pDetId_);
123 
124  errorOnXtal = true;
125  lastStripId_ = st;
126  lastXtalId_ = ch;
127 
128  // return here, so to skip all following checks
129  return SKIP_BLOCK_UNPACKING;
130 
131  }
132 
133  lastStripId_ = stripId;
134  lastXtalId_ = xtalId;
135  }// end else
136  }// end if(zs_)
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_ = (EEDetId*) mapper_->getDetIdPointer(towerId_, stripId, xtalId);
145 
146  if(pDetId_){// checking that requested EEDetId exists
147 
148  (*digis_)->push_back(*pDetId_);
149  EEDataFrame df( (*digis_)->back() );
150  addedFrame=true;
151  bool wrongGain(false);
152 
153  //set samples in the frame
154  for(unsigned int i =0; i< nTSamples_ ;i++){
155  xData_++;
156  unsigned int data = (*xData_) & TOWER_DIGI_MASK;
157  unsigned int gain = data>>12;
158  xtalGains_[i]=gain;
159  if(gain == 0){ wrongGain = true; } // although gain==0 found, produce the dataFrame in order to have it, for saturation case
160  df.setSample(i,data);
161  }
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 SC 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  errorOnXtal = true;
206 
207  //return here, so to skip all the rest
208  //make special collection for gain0 data frames (saturation)
209  //Point to begin of next xtal Block
211 
212  return BLOCK_UNPACKED;
213 
214  }//end isSaturation
215  else {
217  return BLOCK_UNPACKED;
218  }
219  }//end WrongGain
220 
221  short firstGainWrong=-1;
222  short numGainWrong=0;
223 
224  for (unsigned int i=1; i<nTSamples_; i++ ) {
225  if (xtalGains_[i-1]>xtalGains_[i]) {
226  numGainWrong++;
227 
228  if (firstGainWrong == -1) { firstGainWrong=i;}
229  }
230  }
231 
232  if (numGainWrong > 0) {
234  edm::LogWarning("IncorrectGain")
235  << "A wrong gain transition switch was found for SC 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 
241  errorOnXtal = true;
242  }
243 
244  //Add frame to collection only if all data format and gain rules are respected
245  if (errorOnXtal && addedFrame) {
246  (*digis_)->pop_back();
247  }
248 
249  }// End 'if EE id exist'
250 
251  else {
252  // in case EEDetId do not exist
253  // In EE we may have crystals with no valid EEDetId
254  if (! mapper_->isGhost(mapper_->getActiveDCC(), towerId_, stripId)) { // check the VFE is not a 'ghost'
255 
256  // this is real EE VFE - print warning
258  edm::LogWarning("IncorrectBlock")
259  << "An EEDetId was requested that does not exist "
260  << "(LV1 " << event_->l1A()
261  << " fed " << mapper_->getActiveDCC()
262  << " tower " << towerId_
263  << " strip " << stripId
264  << " xtal " << xtalId << ")";
265  }
266  }
267  }
268 
269  //Point to begin of next xtal Block
271 
272  return BLOCK_UNPACKED;
273 }
274 
275 
276 void DCCSCBlock::fillEcalElectronicsError( std::auto_ptr<EcalElectronicsIdCollection> * errorColection){
277 
278  const int activeDCC = mapper_->getActiveSM();
279 
280  if ( (NUMB_SM_EE_MIN_MIN <=activeDCC && activeDCC<=NUMB_SM_EE_MIN_MAX) ||
281  (NUMB_SM_EE_PLU_MIN <=activeDCC && activeDCC<=NUMB_SM_EE_PLU_MAX) ){
283  (*errorColection)->push_back(*eleTp);
284  }else{
286  edm::LogWarning("IncorrectBlock")
287  <<"For event "<<event_->l1A()<<" there's fed: "<< activeDCC
288  <<" activeDcc: "<<mapper_->getActiveSM()
289  <<" but that activeDcc is not valid in EE.";
290  }
291  }
292 
293 }
int i
Definition: DBlmapReader.cc:9
unsigned int towerId_
Definition: DCCFEBlock.h:57
unsigned int expTowerID_
Definition: DCCFEBlock.h:50
bool zs_
Definition: DCCFEBlock.h:45
void fillEcalElectronicsError(std::auto_ptr< EcalElectronicsIdCollection > *)
Definition: DCCSCBlock.cc:276
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)
std::auto_ptr< EEDetIdCollection > * invalidEEChIdsCollection()
DetId * getDetIdPointer(unsigned int feChannel, unsigned int strip, unsigned int xtal)
std::auto_ptr< EEDetIdCollection > * invalidGainsSwitch_
Definition: DCCSCBlock.h:45
static bool silentMode_
std::auto_ptr< EEDetIdCollection > * invalidEEGainsCollection()
unsigned int nTSamples_
Definition: DCCFEBlock.h:60
virtual void updateCollectors()
Definition: DCCFEBlock.cc:20
std::auto_ptr< EEDetIdCollection > * invalidGains_
Definition: DCCSCBlock.h:44
unsigned int lastXtalId_
Definition: DCCFEBlock.h:55
int unpackXtalData(unsigned int stripID, unsigned int xtalID)
Definition: DCCSCBlock.cc:29
uint16_t getChannelValue(const DetId &id) const
unsigned int bx()
Definition: DCCEventBlock.h:55
std::auto_ptr< EcalElectronicsIdCollection > * invalidZSXtalIds_
Definition: DCCFEBlock.h:68
DCCSCBlock(DCCDataUnpacker *u, EcalElectronicsMapper *m, DCCEventBlock *e, bool unpack, bool forceToKeepFRdata)
Definition: DCCSCBlock.cc:9
EEDetId * pDetId_
Definition: DCCSCBlock.h:38
std::auto_ptr< EEDigiCollection > * digis_
Definition: DCCSCBlock.h:41
bool isGhost(const int FED, const int CCU, const int VFE)
void updateCollectors()
Definition: DCCSCBlock.cc:13
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
std::auto_ptr< EEDigiCollection > * eeDigisCollection()
EcalElectronicsMapper * mapper_
short * xtalGains_
Definition: DCCFEBlock.h:66
std::auto_ptr< EEDetIdCollection > * invalidEEGainsSwitchCollection()
unsigned int l1A()
Definition: DCCEventBlock.h:54
std::auto_ptr< EEDetIdCollection > * invalidChIds_
Definition: DCCSCBlock.h:46