CMS 3D CMS Logo

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