CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DCCEEEventBlock.cc
Go to the documentation of this file.
5 
6 
12 #include <sys/time.h>
13 
14 #include <iomanip>
15 #include <sstream>
16 
17 
18 DCCEEEventBlock::DCCEEEventBlock( DCCDataUnpacker * u,EcalElectronicsMapper * m, bool hU, bool srpU, bool tccU, bool feU, bool memU, bool forceToKeepFRdata) :
19  DCCEventBlock(u,m,hU,srpU,tccU,feU,memU,forceToKeepFRdata)
20 {
21 
22  //Builds a tower unpacker block
24 
25  //Builds a srp unpacker block
26  srpBlock_ = new DCCEESRPBlock(u,m,this,srpUnpacking_);
27 
28  //Builds a tcc unpacker block
29  tccBlock_ = new DCCEETCCBlock(u,m,this,tccUnpacking_);
30 
31 
32 }
33 
34 
35 
36 void DCCEEEventBlock::unpack(const uint64_t * buffer, size_t numbBytes, unsigned int expFedId){
37 
38  reset();
39 
40  eventSize_ = numbBytes;
41  data_ = buffer;
42 
43  // First Header Word of fed block
44  fedId_ = ((*data_)>>H_FEDID_B) & H_FEDID_MASK;
45  bx_ = ((*data_)>>H_BX_B ) & H_BX_MASK;
46  l1_ = ((*data_)>>H_L1_B ) & H_L1_MASK;
47  triggerType_ = ((*data_)>>H_TTYPE_B) & H_TTYPE_MASK;
48 
49  // Check if fed id is the same as expected...
50  if( fedId_ != expFedId ){
51 
53  edm::LogWarning("IncorrectEvent")
54  <<"\n For event L1A: "<<l1_
55  <<"\n Expected FED id is: "<<expFedId<<" while current FED id is: "<<fedId_
56  <<"\n => Skipping to next fed block...";
57  }
58 
59  //TODO : add this to an error event collection
60 
61  return;
62  }
63 
64  // Check if this event is an empty event
65  if( eventSize_ == EMPTYEVENTSIZE ){
67  edm::LogWarning("IncorrectEvent")
68  <<"\n Event L1A: "<<l1_<<" is empty for fed: "<<fedId_
69  <<"\n => Skipping to next fed block...";
70  }
71  return;
72 
73  }
74 
75  //Check if event size allows at least building the header
76  else if( eventSize_ < HEADERSIZE ){
78  edm::LogError("IncorrectEvent")
79  <<"\n Event L1A: "<<l1_<<" in fed: "<< fedId_
80  <<"\n Event size is "<<eventSize_<<" bytes while the minimum is "<<HEADERSIZE<<" bytes"
81  <<"\n => Skipping to next fed block...";
82  }
83 
84  //TODO : add this to a dcc size error collection
85 
86  return;
87 
88  }
89 
90  //Second Header Word of fed block
91  data_++;
92 
93  blockLength_ = (*data_ ) & H_EVLENGTH_MASK;
94  dccErrors_ = ((*data_)>>H_ERRORS_B) & H_ERRORS_MASK;
95  runNumber_ = ((*data_)>>H_RNUMB_B ) & H_RNUMB_MASK;
96 
97 
98  if( eventSize_ != blockLength_*8 ){
100  edm::LogError("IncorrectEvent")
101  <<"\n Event L1A: "<<l1_<<" in fed: "<< fedId_
102  <<"\n size is "<<eventSize_<<" bytes while "<<(blockLength_*8)<<" are set in the event header "
103  <<"\n => Skipping to next fed block...";
104  //TODO : add this to a dcc size error collection
105  }
106  return;
107 
108  }
109 
110  //Third Header Word of fed block
111  data_++;
112 
113  // bits 0.. 31 of the 3rd DCC header word
114  runType_ = (*data_) & H_RTYPE_MASK;
115 
116  fov_ = ((*data_)>>H_FOV_B) & H_FOV_MASK;
117 
118  // bits 32.. 47 of the 3rd DCC header word
120 
121  //Forth Header Word
122  data_++;
124  sr_ = ((*data_)>>H_SR_B) & B_MASK;
125  zs_ = ((*data_)>>H_ZS_B) & B_MASK;
126  tzs_ = ((*data_)>>H_TZS_B) & B_MASK;
127 
128  // MEM (forces readout of MEM channels if enabled)is only used in the EE DCCs and for FOV >1
129  mem_ = ((*data_)>>H_MEM_B) & B_MASK;
130  if( fov_ < 2) { mem_ = 0;}
131 
132 
133  bool ignoreSR(true);
134 
136 
137  // getting TCC channel status bits
138  tccChStatus_[0] = ((*data_)>>H_TCC1CHSTATUS_B) & H_CHSTATUS_MASK;
139  tccChStatus_[1] = ((*data_)>>H_TCC2CHSTATUS_B) & H_CHSTATUS_MASK;
140  tccChStatus_[2] = ((*data_)>>H_TCC3CHSTATUS_B) & H_CHSTATUS_MASK;
141  tccChStatus_[3] = ((*data_)>>H_TCC4CHSTATUS_B) & H_CHSTATUS_MASK;
142 
143  // FE channel Status data
144  int channel(0);
145  for( int dw = 0; dw<5; dw++ ){
146  data_++;
147  for( int i = 0; i<14; i++, channel++){
148  unsigned int shift = i*4; //each channel has 4 bits
149  feChStatus_[channel] = ( (*data_)>>shift ) & H_CHSTATUS_MASK ;
150  }
151  }
152 
153  // debugging
154  //display(cout);
155 
156 
157  // pointer for the
158  std::vector<short>::iterator it;
159 
160  // Update number of available dwords
162 
163  int STATUS = unpackTCCBlocks();
164 
165  if( STATUS != STOP_EVENT_UNPACKING && (feUnpacking_ || srpUnpacking_) ){
166 
167  //NMGA note : SR comes before TCC blocks
168  // Emmanuelle please change this in the digi to raw
169 
170  // Unpack SRP block
172  STATUS = srpBlock_->unpack(&data_,&dwToEnd_);
173  if ( STATUS == BLOCK_UNPACKED ){ ignoreSR = false; }
174  }
175  }
176 
177  // See number of FE channels that we need according to the trigger type //
178  // TODO : WHEN IN LOCAL MODE WE SHOULD CHECK RUN TYPE
179  unsigned int numbChannels(0);
180 
181  if( triggerType_ == PHYSICTRIGGER ){ numbChannels = 68; }
182  else if ( triggerType_ == CALIBRATIONTRIGGER ){ numbChannels = 70; }
183  else {
185  edm::LogError("IncorrectEvent")
186  <<"\n Event L1A: "<<l1_<<" in fed: "<< fedId_
187  <<"\n Event has an unsupported trigger type "<<triggerType_
188  <<"\n => Skipping to next fed block...";
189  //TODO : add this to a dcc trigger type error collection
190  }
191  return;
192  }
193 
194  // note: there is no a-priori check that number_active_channels_from_header
195  // equals number_channels_found_in_data.
196  // The checks are doing f.e. by f.e. only.
197 
198  if( feUnpacking_ || memUnpacking_ ){
199  it = feChStatus_.begin();
200 
201  // fields for tower recovery code
202  unsigned int next_tower_id = 1000;
203  const uint64_t* next_data = data_;
204  unsigned int next_dwToEnd = dwToEnd_;
205 
206  // looping over FE channels, i.e. tower blocks
207  for( unsigned int chNumber=1; chNumber<= numbChannels && STATUS!=STOP_EVENT_UNPACKING; chNumber++, it++ ){
208  //for( unsigned int i=1; chNumber<= numbChannels; chNumber++, it++ ){
209 
210  const short chStatus(*it);
211 
212  // skip unpacking if channel disabled
213  if (chStatus == CH_DISABLED) {
214  continue;
215  }
216 
217  // force MEM readout if mem_ is enabled in EEs regardless on ch suppress status flag
218  if (chStatus == CH_SUPPRESS && !mem_ ) {
219  continue;
220  }
221 
222  // issuiung messages for problematic cases, even though handled by the DCC
223  // and skip channel
224  if (chStatus == CH_TIMEOUT || chStatus == CH_HEADERERR ||
225  chStatus == CH_LINKERR || chStatus == CH_LENGTHERR ||
226  chStatus == CH_IFIFOFULL || chStatus == CH_L1AIFIFOFULL)
227  {
229  const int val = unpacker_->getCCUValue(fedId_, chNumber);
230  const bool ttProblem = (val == 13) || (val == 14);
231  if (! ttProblem) {
232  edm::LogWarning("IncorrectBlock")
233  << "Bad channel status: " << chStatus
234  << " in the DCC channel: " << chNumber
235  << " (LV1 " << l1_ << " fed " << fedId_ << ")\n"
236  << " => DCC channel is not being unpacked";
237  }
238  }
239  continue;
240  }
241 
242  // preserve data pointer
243  const uint64_t* const prev_data = data_;
244  const unsigned int prev_dwToEnd = dwToEnd_;
245 
246  // skip corrupted/problematic data block
247  if (chNumber >= next_tower_id) {
248  data_ = next_data;
249  dwToEnd_ = next_dwToEnd;
250  next_tower_id = 1000;
251  }
252 
253 
254  // Unpack Tower (Xtal Block)
255  if (feUnpacking_ && chNumber <= 68) {
256 
257  // in case of SR (data are 0 suppressed)
258  if (sr_) {
259  const bool applyZS =
260  (fov_ == 0) || // backward compatibility with FOV = 0;
261  ignoreSR ||
262  (chStatus == CH_FORCEDZS1) ||
263  ((srpBlock_->srFlag(chNumber) & SRP_SRVAL_MASK) != SRP_FULLREADOUT);
264 
265  STATUS = towerBlock_->unpack(&data_,&dwToEnd_,applyZS,chNumber);
266 
267  // If there is a decision to fully suppress data this is updated in channel status by the dcc
268  //if ( ( srpBlock_->srFlag(chNumber) & SRP_SRVAL_MASK) != SRP_NREAD ){
269  // STATUS = towerBlock_->unpack(&data_,&dwToEnd_,applyZS,chNumber);
270  //}
271  }
272  // no SR (possibly 0 suppression flags)
273  else {
274  // if tzs_ data are not really suppressed, even though zs flags are calculated
275  if(tzs_){ zs_ = false;}
276  STATUS = towerBlock_->unpack(&data_,&dwToEnd_,zs_,chNumber);
277  }
278  }
279 
280  // Unpack Mem blocks
281  if(memUnpacking_ && chNumber>68 )
282  {
283  STATUS = memBlock_->unpack(&data_,&dwToEnd_,chNumber);
284  }
285 
286 
287  // corruption recovery
288  if (STATUS == SKIP_BLOCK_UNPACKING) {
289  data_ = prev_data;
290  dwToEnd_ = prev_dwToEnd;
291 
292  next_tower_id = next_tower_search(chNumber);
293 
294  next_data = data_;
295  next_dwToEnd = dwToEnd_;
296 
297  data_ = prev_data;
298  dwToEnd_ = prev_dwToEnd;
299  }
300 
301  }
302  // closing loop over FE/TTblock channels
303 
304  }// check if we need to perform unpacking of FE or mem data
305 
306 
308 
309 }
310 
311 
312 
313 
315 
316  int STATUS(BLOCK_UNPACKED);
317  std::vector<short>::iterator it;
318  unsigned int tccChId(0);
319  for(it=tccChStatus_.begin();it!=tccChStatus_.end();it++, tccChId++){
320  if( (*it) != CH_TIMEOUT && (*it) != CH_DISABLED){
321  STATUS = tccBlock_->unpack(&data_,&dwToEnd_,tccChId);
322  if(STATUS == STOP_EVENT_UNPACKING) break;
323  }
324  }
325  return STATUS;
326 
327 }
328 
DCCEEEventBlock(DCCDataUnpacker *u, EcalElectronicsMapper *m, bool hU, bool srpU, bool tccU, bool feU, bool memU, bool forceToKeepFRdata)
int i
Definition: DBlmapReader.cc:9
bool forceToKeepFRdata_
int unpack(const uint64_t **data, unsigned int *dwToEnd, short tccChId=0)
Definition: DCCTCCBlock.cc:11
unsigned int runType_
Definition: DCCEventBlock.h:98
DCCFEBlock * towerBlock_
DCCSRPBlock * srpBlock_
unsigned int dwToEnd_
Definition: DCCEventBlock.h:74
unsigned int mem_
int unpack(const uint64_t **data, unsigned int *dwToEnd, bool zs, unsigned int expectedTowerID)
Definition: DCCFEBlock.cc:29
DCCMemBlock * memBlock_
unsigned int srChStatus_
Definition: DCCEventBlock.h:87
static bool silentMode_
unsigned int detailedTriggerType_
Definition: DCCEventBlock.h:99
unsigned int blockLength_
Definition: DCCEventBlock.h:95
unsigned int triggerType_
Definition: DCCEventBlock.h:93
const uint64_t * data_
Definition: DCCEventBlock.h:72
DCCDataUnpacker * unpacker_
Definition: DCCEventBlock.h:71
unsigned int runNumber_
Definition: DCCEventBlock.h:97
unsigned int sr_
unsigned short srFlag(unsigned int feChannel)
Definition: DCCSRPBlock.h:43
unsigned int l1_
Definition: DCCEventBlock.h:92
unsigned int eventSize_
Definition: DCCEventBlock.h:73
uint16_t getCCUValue(const int fed, const int ccu) const
unsigned int orbitCounter_
DCCTCCBlock * tccBlock_
std::vector< short > feChStatus_
Definition: DCCEventBlock.h:78
unsigned long long uint64_t
Definition: Time.h:15
unsigned int fov_
Definition: DCCEventBlock.h:89
unsigned int bx_
Definition: DCCEventBlock.h:91
void unpack(const uint64_t *buffer, size_t bufferSize, unsigned int expFedId)
int unpack(const uint64_t **data, unsigned int *dwToEnd, unsigned int numbFlags=SRP_NUMBFLAGS)
Definition: DCCSRPBlock.cc:19
static unsigned int const shift
unsigned int zs_
void addHeaderToCollection()
unsigned int next_tower_search(const unsigned int current_tower_id)
unsigned int tzs_
std::vector< short > tccChStatus_
Definition: DCCEventBlock.h:79
unsigned int fedId_
Definition: DCCEventBlock.h:90
int unpack(const uint64_t **data, unsigned int *dwToEnd, unsigned int expectedTowerID)
Definition: DCCMemBlock.cc:41
unsigned int dccErrors_
Definition: DCCEventBlock.h:96