CMS 3D CMS Logo

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 }
HEADERSIZE
Definition: DCCRawDataDefinitions.h:12
DCCEventBlock::fedId_
unsigned int fedId_
Definition: DCCEventBlock.h:102
DCCEventBlock::fov_
unsigned int fov_
Definition: DCCEventBlock.h:101
DCCDataUnpacker.h
DCCEventBlock
Definition: DCCEventBlock.h:29
mps_fire.i
i
Definition: mps_fire.py:428
DCCEEEventBlock::unpack
void unpack(const uint64_t *buffer, size_t bufferSize, unsigned int expFedId) override
Definition: DCCEEEventBlock.cc:35
H_L1_B
Definition: DCCRawDataDefinitions.h:82
DCCEventBlock::triggerType_
unsigned int triggerType_
Definition: DCCEventBlock.h:105
H_FEDID_MASK
Definition: DCCRawDataDefinitions.h:77
DCCFEBlock::unpack
int unpack(const uint64_t **data, unsigned int *dwToEnd, bool zs, unsigned int expectedTowerID)
Definition: DCCFEBlock.cc:22
SKIP_BLOCK_UNPACKING
Definition: DCCRawDataDefinitions.h:7
DCCEventBlock::tccBlock_
DCCTCCBlock * tccBlock_
Definition: DCCEventBlock.h:120
CH_L1AIFIFOFULL
Definition: DCCRawDataDefinitions.h:28
H_TZS_B
Definition: DCCRawDataDefinitions.h:109
CH_SUPPRESS
Definition: DCCRawDataDefinitions.h:26
H_FOV_MASK
Definition: DCCRawDataDefinitions.h:102
DCCEventBlock::addHeaderToCollection
void addHeaderToCollection()
Definition: DCCEventBlock.cc:140
H_BX_MASK
Definition: DCCRawDataDefinitions.h:80
H_SR_B
Definition: DCCRawDataDefinitions.h:107
DCCDataUnpacker
Definition: DCCDataUnpacker.h:49
H_ERRORS_MASK
Definition: DCCRawDataDefinitions.h:91
DCCDataUnpacker::silentMode_
static std::atomic< bool > silentMode_
Definition: DCCDataUnpacker.h:185
DCCEventBlock::feUnpacking_
bool feUnpacking_
Definition: DCCEventBlock.h:128
H_FEDID_B
Definition: DCCRawDataDefinitions.h:76
DCCTCCBlock::unpack
int unpack(const uint64_t **data, unsigned int *dwToEnd, short tccChId=0)
Definition: DCCTCCBlock.cc:10
DCCEventBlock::unpacker_
DCCDataUnpacker * unpacker_
Definition: DCCEventBlock.h:81
H_RNUMB_B
Definition: DCCRawDataDefinitions.h:93
DCCEventBlock::towerBlock_
DCCFEBlock * towerBlock_
Definition: DCCEventBlock.h:119
H_EVLENGTH_MASK
Definition: DCCRawDataDefinitions.h:88
edm::LogWarning
Log< level::Warning, false > LogWarning
Definition: MessageLogger.h:122
EcalElectronicsMapper.h
H_ZS_B
Definition: DCCRawDataDefinitions.h:108
DCCEventBlock::bx_
unsigned int bx_
Definition: DCCEventBlock.h:103
DCCEventBlock::detailedTriggerType_
unsigned int detailedTriggerType_
Definition: DCCEventBlock.h:111
edmScanValgrind.buffer
buffer
Definition: edmScanValgrind.py:171
DCCSCBlock
Definition: DCCSCBlock.h:22
DCCEventBlock::mem_
unsigned int mem_
Definition: DCCEventBlock.h:114
EMPTYEVENTSIZE
Definition: DCCRawDataDefinitions.h:13
H_TCC4CHSTATUS_B
Definition: DCCRawDataDefinitions.h:118
DCCEventBlock::eventSize_
unsigned int eventSize_
Definition: DCCEventBlock.h:83
DCCEventBlock::runNumber_
unsigned int runNumber_
Definition: DCCEventBlock.h:109
CH_IFIFOFULL
Definition: DCCRawDataDefinitions.h:27
PHYSICTRIGGER
Definition: DCCRawDataDefinitions.h:15
H_RNUMB_MASK
Definition: DCCRawDataDefinitions.h:94
DCCEEEventBlock.h
visualization-live-secondInstance_cfg.m
m
Definition: visualization-live-secondInstance_cfg.py:79
DCCFEBlock.h
DCCSRPBlock::srFlag
unsigned short srFlag(unsigned int feChannel)
Definition: DCCSRPBlock.h:38
H_MEM_B
Definition: DCCRawDataDefinitions.h:110
HEADERLENGTH
Definition: DCCRawDataDefinitions.h:11
H_BX_B
Definition: DCCRawDataDefinitions.h:79
CH_FORCEDZS1
Definition: DCCRawDataDefinitions.h:29
H_SRCHSTATUS_B
Definition: DCCRawDataDefinitions.h:112
H_TTYPE_B
Definition: DCCRawDataDefinitions.h:85
DCCEventBlock::srpBlock_
DCCSRPBlock * srpBlock_
Definition: DCCEventBlock.h:122
CH_TIMEOUT
Definition: DCCRawDataDefinitions.h:22
DCCEventBlock::dwToEnd_
unsigned int dwToEnd_
Definition: DCCEventBlock.h:84
DCCEventBlock::memBlock_
DCCMemBlock * memBlock_
Definition: DCCEventBlock.h:121
STOP_EVENT_UNPACKING
Definition: DCCRawDataDefinitions.h:8
B_MASK
Definition: DCCRawDataDefinitions.h:10
DCCEventBlock::dccErrors_
unsigned int dccErrors_
Definition: DCCEventBlock.h:108
DCCEventBlock::forceToKeepFRdata_
bool forceToKeepFRdata_
Definition: DCCEventBlock.h:130
EcalDCCHeaderRuntypeDecoder.h
DCCEventBlock::data_
const uint64_t * data_
Definition: DCCEventBlock.h:82
CALIBRATIONTRIGGER
Definition: DCCRawDataDefinitions.h:16
H_DET_TTYPE_MASK
Definition: DCCRawDataDefinitions.h:99
DCCEventBlock::memUnpacking_
bool memUnpacking_
Definition: DCCEventBlock.h:129
DCCEEEventBlock::unpackTCCBlocks
int unpackTCCBlocks() override
Definition: DCCEEEventBlock.cc:294
CH_DISABLED
Definition: DCCRawDataDefinitions.h:21
H_FOV_B
Definition: DCCRawDataDefinitions.h:101
DCCEventBlock::tccUnpacking_
bool tccUnpacking_
Definition: DCCEventBlock.h:127
SRP_FULLREADOUT
Definition: DCCRawDataDefinitions.h:196
DCCEventBlock::feChStatus_
std::vector< short > feChStatus_
Definition: DCCEventBlock.h:88
DCCSRPBlock::unpack
int unpack(const uint64_t **data, unsigned int *dwToEnd, unsigned int numbFlags=SRP_NUMBFLAGS)
Definition: DCCSRPBlock.cc:16
SRP_NUMBFLAGS
Definition: DCCRawDataDefinitions.h:31
DCCEETCCBlock
Definition: DCCEETCCBlock.h:29
DCCEventBlock::tzs_
unsigned int tzs_
Definition: DCCEventBlock.h:117
H_TTYPE_MASK
Definition: DCCRawDataDefinitions.h:86
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
H_TCC3CHSTATUS_B
Definition: DCCRawDataDefinitions.h:117
DCCEventBlock::blockLength_
unsigned int blockLength_
Definition: DCCEventBlock.h:107
EcalElectronicsMapper
Definition: EcalElectronicsMapper.h:36
H_RTYPE_MASK
Definition: DCCRawDataDefinitions.h:96
DCCEEEventBlock::DCCEEEventBlock
DCCEEEventBlock(DCCDataUnpacker *u, EcalElectronicsMapper *m, bool hU, bool srpU, bool tccU, bool feU, bool memU, bool forceToKeepFRdata)
Definition: DCCEEEventBlock.cc:16
H_TCC1CHSTATUS_B
Definition: DCCRawDataDefinitions.h:115
H_DET_TTYPE_B
Definition: DCCRawDataDefinitions.h:98
DCCSCBlock.h
heppy_batch.val
val
Definition: heppy_batch.py:351
DCCEventBlock::sr_
unsigned int sr_
Definition: DCCEventBlock.h:115
edm::shift
static unsigned const int shift
Definition: LuminosityBlockID.cc:7
H_TCC2CHSTATUS_B
Definition: DCCRawDataDefinitions.h:116
H_ERRORS_B
Definition: DCCRawDataDefinitions.h:90
H_CHSTATUS_MASK
Definition: DCCRawDataDefinitions.h:113
DCCEETCCBlock.h
SRP_SRVAL_MASK
Definition: DCCRawDataDefinitions.h:210
H_L1_MASK
Definition: DCCRawDataDefinitions.h:83
DCCEESRPBlock.h
DCCMemBlock::unpack
int unpack(const uint64_t **data, unsigned int *dwToEnd, unsigned int expectedTowerID)
Definition: DCCMemBlock.cc:34
CH_HEADERERR
Definition: DCCRawDataDefinitions.h:23
DCCMemBlock.h
DCCEventBlock::runType_
unsigned int runType_
Definition: DCCEventBlock.h:110
DCCEventBlock::reset
void reset()
Definition: DCCEventBlock.cc:55
DCCEventBlock::orbitCounter_
unsigned int orbitCounter_
Definition: DCCEventBlock.h:113
H_ORBITCOUNTER_B
Definition: DCCRawDataDefinitions.h:104
cond::uint64_t
unsigned long long uint64_t
Definition: Time.h:13
DCCEventBlock::headerUnpacking_
bool headerUnpacking_
Definition: DCCEventBlock.h:125
DCCEventBlock::srpUnpacking_
bool srpUnpacking_
Definition: DCCEventBlock.h:126
DCCEventBlock::tccChStatus_
std::vector< short > tccChStatus_
Definition: DCCEventBlock.h:89
DCCEventBlock::zs_
unsigned int zs_
Definition: DCCEventBlock.h:116
H_ORBITCOUNTER_MASK
Definition: DCCRawDataDefinitions.h:105
CH_LENGTHERR
Definition: DCCRawDataDefinitions.h:25
DCCEventBlock::next_tower_search
unsigned int next_tower_search(const unsigned int current_tower_id)
Definition: DCCEventBlock.cc:78
DCCEventBlock::l1_
unsigned int l1_
Definition: DCCEventBlock.h:104
DCCDataUnpacker::getCCUValue
uint16_t getCCUValue(const int fed, const int ccu) const
Definition: DCCDataUnpacker.cc:89
BLOCK_UNPACKED
Definition: DCCRawDataDefinitions.h:6
CH_LINKERR
Definition: DCCRawDataDefinitions.h:24
DCCEventBlock::srChStatus_
unsigned int srChStatus_
Definition: DCCEventBlock.h:99
DCCEESRPBlock
Definition: DCCEESRPBlock.h:30