CMS 3D CMS Logo

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