Belle II Software development
PXDUnpackerOTModule.cc
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8
9#include <pxd/unpacking/PXDRawDataDefinitions.h>
10#include <pxd/unpacking/PXDRawDataStructs.h>
11#include <pxd/unpacking/PXDMappingLookup.h>
12#include <pxd/modules/pxdUnpacking/PXDUnpackerOTModule.h>
13#include <framework/datastore/DataStore.h>
14#include <framework/logging/Logger.h>
15#include <framework/datastore/StoreObjPtr.h>
16
17using namespace std;
18using namespace Belle2;
19using namespace Belle2::PXD;
20using namespace Belle2::PXD::PXDError;
21
22//-----------------------------------------------------------------
23// Register the Module
24//-----------------------------------------------------------------
25REG_MODULE(PXDUnpackerOT);
26
27//-----------------------------------------------------------------
28// Implementation
29//-----------------------------------------------------------------
30
34
36 Module(),
37 m_storeRawHits(),
38 m_storeROIs(),
39 m_storeRawAdc()
40{
41 //Set module properties
42 setDescription("Unpack Raw PXD Hits from ONSEN data stream");
44
45 addParam("RawPXDsName", m_RawPXDsName, "The name of the StoreArray of RawPXDs to be processed", std::string(""));
46 addParam("PXDRawHitsName", m_PXDRawHitsName, "The name of the StoreArray of generated PXDRawHits", std::string(""));
47 addParam("PXDDAQEvtStatsName", m_PXDDAQEvtStatsName, "The name of the StoreObjPtr of generated PXDDAQEvtStats", std::string(""));
48 addParam("PXDRawAdcsName", m_PXDRawAdcsName, "The name of the StoreArray of generated PXDRawAdcs", std::string(""));
49 addParam("PXDRawROIsName", m_PXDRawROIsName, "The name of the StoreArray of generated PXDRawROIs", std::string(""));
50 addParam("DoNotStore", m_doNotStore, "only unpack and check, but do not store", false);
51// addParam("CriticalErrorMask", m_criticalErrorMask, "Set error mask which stops processing by returning false by task", 0);
52 // m_criticalErrorMask not longer a aparameter
53 // the constructor default to zero anyway
54// addParam("SuppressErrorMask", m_suppressErrorMask, "Set mask for errors msgs which are not printed", getSilenceMask());
55 // m_suppressErrorMask not longer a aparameter
56 m_suppressErrorMask = getSilenceMask();
57 addParam("ForceMapping", m_forceMapping, "Force Mapping even if DHH bit is NOT requesting it", false);
58 addParam("ForceNoMapping", m_forceNoMapping, "Force NO Mapping even if DHH bit is requesting it", false);
59 addParam("CheckPaddingCRC", m_checkPaddingCRC, "Check for susp. padding (debug option, many false positive)", false);
60 addParam("MaxDHPFrameDiff", m_maxDHPFrameDiff, "Maximum DHP Frame Nr Difference w/o reporting error", 2u);
61 addParam("FormatBonnDAQ", m_formatBonnDAQ, "ONSEN or BonnDAQ format", false);
62 addParam("Verbose", m_verbose, "Turn on extra verbosity for log-level debug", false);
63 addParam("ContinueOnError", m_continueOnError, "Continue package depacking on error (for debugging)", false);
64// (
65// /*EPXDErrFlag::c_DHC_END | EPXDErrFlag::c_DHE_START | EPXDErrFlag::c_DATA_OUTSIDE |*/
66// EPXDErrFlag::c_FIX_SIZE | EPXDErrFlag::c_DHE_CRC | EPXDErrFlag::c_DHC_UNKNOWN | /*EPXDErrFlag::c_MERGER_CRC |*/
67// EPXDErrFlag::c_DHP_SIZE | /*EPXDErrFlag::c_DHP_PIX_WO_ROW | EPXDErrFlag::c_DHE_START_END_ID | EPXDErrFlag::c_DHE_START_ID |*/
68// EPXDErrFlag::c_DHE_START_WO_END | EPXDErrFlag::c_DHP_NOT_CONT
69// ));
70
71 // this is not really a parameter, it should be fixed.
72 m_errorSkipPacketMask[c_nrDHE_CRC] = true;
73 m_errorSkipPacketMask[c_nrFIX_SIZE] = true;
74}
75
77{
78 // Required input
79 m_eventMetaData.isRequired();
80 // Optional input
81 m_storeRawPXD.isOptional(m_RawPXDsName);
82
83 //Register output collections
89
90 B2DEBUG(29, "ForceMapping: " << m_forceMapping);
91 B2DEBUG(29, "ForceNoMapping: " << m_forceNoMapping);
92 B2DEBUG(29, "CheckPaddingCRC: " << m_checkPaddingCRC);
93 B2DEBUG(29, "MaxDHPFrameDiff: " << m_maxDHPFrameDiff);
94
96 m_sendrois = 0;
97 m_notaccepted = 0;
99 for (int i = 0; i < ONSEN_MAX_TYPE_ERR; i++) m_errorCounter[i] = 0;
100
101}
102
104{
105 int flag = 0;
106 string errstr = "Statistic ( ;";
107 errstr += to_string(m_unpackedEventsCount) + ";";
108 for (int i = 0; i < ONSEN_MAX_TYPE_ERR; i++) { errstr += to_string(m_errorCounter[i]) + ";"; flag |= m_errorCounter[i];}
109 if (flag != 0) {
110 B2RESULT("PXD Unpacker --> Error Statistics (counted once per event!) in Events: " << m_unpackedEventsCount);
111 B2RESULT(errstr + " )");
112 for (int i = 0; i < ONSEN_MAX_TYPE_ERR; i++) {
113 if (m_errorCounter[i]) {
114 B2RESULT(getPXDBitErrorName(i) << ": " << m_errorCounter[i]);
115 }
116 }
117 } else {
118 B2RESULT("PXD Unpacker --> No Error found in Events: " << m_unpackedEventsCount);
119 }
120 B2RESULT("Statistic 2: !Accepted: " << m_notaccepted << " SendROIs: " << m_sendrois << " Unfiltered: " << m_sendunfiltered);
121}
122
124{
125 m_storeDAQEvtStats.create();
126
127 m_errorMask = 0;
129
130 m_meta_event_nr = m_eventMetaData->getEvent();// used for error output below
131
132 if (!m_storeRawPXD) {// if no input, nothing to do
133 m_errorMask[c_nrNO_PXD] = true;
134 } else {
135 int nRaws = m_storeRawPXD.getEntries();
136 if (m_verbose) {
137 B2DEBUG(29, "PXD Unpacker --> RawPXD Objects in event: " << LogVar("Objects", nRaws));
138 };
139
140 m_meta_run_nr = m_eventMetaData->getRun();
141 m_meta_subrun_nr = m_eventMetaData->getSubrun();
142 m_meta_experiment = m_eventMetaData->getExperiment();
143 m_meta_time = m_eventMetaData->getTime();
144 m_meta_ticks = (unsigned int)std::round((m_meta_time % 1000000000ull) * 0.127216); // calculate ticks in 127MHz RF clock
145 m_meta_sec = (unsigned int)(m_meta_time / 1000000000ull) & 0x1FFFF;
146
147 int inx = 0; // count index for output objects
148 for (auto& it : m_storeRawPXD) {
149 if (m_verbose) {
150 B2DEBUG(29, "PXD Unpacker --> Unpack Objects: ");
151 };
152 unpack_rawpxd(it, inx++);
153 }
154
155 if (nRaws == 0) m_errorMask[c_nrNO_PXD] = true;
156 }
159
161 {
162 for (unsigned int i = 0; i < ONSEN_MAX_TYPE_ERR; i++) {
163 if (m_errorMaskEvent[i]) m_errorCounter[i]++;
164 }
165 }
166
167 if ((PXDErrorFlags(m_criticalErrorMask) & m_errorMaskEvent) != PXDErrorFlags(0)) B2ERROR("Error in PXD unpacking" <<
168 LogVar("event nr", m_meta_event_nr));
169 setReturnValue(PXDErrorFlags(0) == (PXDErrorFlags(m_criticalErrorMask) & m_errorMaskEvent));
170}
171
173{
174 int Frames_in_event;
175 int fullsize;
176 int datafullsize;
177
178 m_errorMaskDHE = 0;
179 m_errorMaskDHC = 0;
181 PXDDAQPacketStatus& daqpktstat = m_storeDAQEvtStats->newPacket(inx);
182
183 if (px.size() <= 0 || px.size() > 16 * 1024 * 1024) {
184 if (!(m_suppressErrorMask[c_nrPACKET_SIZE])) {
185 B2WARNING("PXD Unpacker --> invalid packet size" <<
186 LogVar("size [32bit words] $", static_cast < std::ostringstream && >(std::ostringstream() << hex << px.size()).str()));
187 }
188 m_errorMask[c_nrPACKET_SIZE] = true;
189 return;
190 }
191 std::vector<unsigned int> data(px.size());
192 fullsize = px.size() * 4;
193 std::copy_n(px.data(), px.size(), data.begin());
194
195 if (fullsize < 8) {
196 if (!(m_suppressErrorMask[c_nrPACKET_SIZE])) {
197 B2WARNING("Data is to small to hold a valid Header! Will not unpack anything." << LogVar("size [32bit words] $",
198 static_cast < std::ostringstream && >(std::ostringstream() << hex << fullsize).str()));
199 }
200 m_errorMask[c_nrPACKET_SIZE] = true;
201 return;
202 }
203
204 if (data[0] != 0xCAFEBABE && data[0] != 0xBEBAFECA) {
205 if (!(m_suppressErrorMask[c_nrMAGIC])) {
206 B2WARNING("Magic invalid: Will not unpack anything. Header corrupted." <<
207 LogVar("Header Magic $", static_cast < std::ostringstream && >(std::ostringstream() << hex << data[0]).str()));
208 }
209 m_errorMask[c_nrMAGIC] = true;
210 return;
211 }
212
213
214 Frames_in_event = ((ubig32_t*)data.data())[1];
215 if (Frames_in_event < 0 || Frames_in_event > 256) {
216 if (!(m_suppressErrorMask[c_nrFRAME_NR])) {
217 B2WARNING("Number of Frames invalid: Will not unpack anything. Header corrupted!" << LogVar("Frames in event", Frames_in_event));
218 }
219 m_errorMask[c_nrFRAME_NR] = true;
220 return;
221 }
222 if (Frames_in_event < 3) {
223 if (!(m_suppressErrorMask[c_nrNR_FRAMES_TO_SMALL])) {
224 B2WARNING("Number of Frames too small: It cannot contain anything useful." << LogVar("Frames in event", Frames_in_event));
225 }
226 m_errorMask[c_nrNR_FRAMES_TO_SMALL] = true;
227 }
228
230 if (m_verbose) {
231 B2DEBUG(29, "PXD Unpacker --> data[0]: <-- Magic $" << hex << data[0]);
232 B2DEBUG(29, "PXD Unpacker --> data[1]: <-- #Frames $" << hex << data[1]);
233 if (data[1] >= 1 && fullsize < 12) B2DEBUG(29, "PXD Unpacker --> data[2]: <-- Frame 1 len $" << hex << data[2]);
234 if (data[1] >= 2 && fullsize < 16) B2DEBUG(29, "PXD Unpacker --> data[3]: <-- Frame 2 len $" << hex << data[3]);
235 if (data[1] >= 3 && fullsize < 20) B2DEBUG(29, "PXD Unpacker --> data[4]: <-- Frame 3 len $" << hex << data[4]);
236 if (data[1] >= 4 && fullsize < 24) B2DEBUG(29, "PXD Unpacker --> data[5]: <-- Frame 4 len $" << hex << data[5]);
237 };
238
239 unsigned int* tableptr;
240 tableptr = &data[2]; // skip header!!!
241
242 unsigned int* dataptr;
243 dataptr = &tableptr[Frames_in_event];
244 datafullsize = fullsize - 2 * 4 - Frames_in_event * 4; // Size is fullsize minus header minus table
245
246 int ll = 0; // Offset in dataptr in bytes
247 for (int j = 0; j < Frames_in_event; j++) {
248 int lo;
249
250 lo = ((ubig32_t*)tableptr)[j];
251 if (lo <= 0) {
252 if (!(m_suppressErrorMask[c_nrFRAME_SIZE])) {
253 B2WARNING("size of frame invalid");
254 B2DEBUG(29, "size of frame invalid: " << j << "size " << lo << " at byte offset in dataptr " << ll);
255 }
256 m_errorMask[c_nrFRAME_SIZE] = true;
257 return;
258 }
259 if (ll + lo > datafullsize) {
260 if (!(m_suppressErrorMask[c_nrFRAME_SIZE])) {
261 B2WARNING("Frames exceed packet size");
262 B2DEBUG(29, "Frames exceed packet size: " << j << " size " << lo << " at byte offset in dataptr " << ll << " of datafullsize " <<
263 datafullsize << " of fullsize " << fullsize);
264 }
265 m_errorMask[c_nrFRAME_SIZE] = true;
266 return;
267 }
268 if (lo & 0x3) {
269 if (!(m_suppressErrorMask[c_nrFRAME_SIZE])) {
270 B2WARNING("SKIP Frame with Data with not MOD 4 length");
271 B2DEBUG(29, "SKIP Frame with Data with not MOD 4 length " << " ( $" << hex << lo << " ) ");
272 }
273 ll += (lo + 3) & 0xFFFFFFFC;
274 m_errorMask[c_nrFRAME_SIZE] = true;
275 } else {
276 B2DEBUG(29, "unpack DHE(C) frame: " << j << " with size " << lo << " at byte offset in dataptr " << ll);
277 unpack_dhc_frame(ll + (char*)dataptr, lo, j, Frames_in_event, daqpktstat);
278 ll += lo;
279 }
284 m_errorMask = 0;
285
286 if (!m_continueOnError && (m_errorMaskPacket & PXDErrorFlags(m_errorSkipPacketMask)) != PXDErrorFlags(0)) {
287 // skip full package on error, recovery to next DHC/DHE Start might be possible in some cases
288 // But that's to hard to implement
289 // Remark: PXD data for broken events is removed in next PXDPostChecker module, thus skipping the
290 // unpacking is not strictly necessary here.
291 break;
292 }
293 }
295}
296
297void PXDUnpackerOTModule::unpack_dhp_raw(void* data, unsigned int frame_len, unsigned int dhe_ID, unsigned dhe_DHPport,
298 VxdID vxd_id)
299{
300// unsigned int nr_words = frame_len / 2; // frame_len in bytes (excl. CRC)!!!
301 ubig16_t* dhp_pix = (ubig16_t*)data;
302
309
310 // Size: 64*768 + 8 bytes for a full frame readout
311 if (frame_len != 0xC008) {
312 if (!(m_suppressErrorMask[c_nrFIX_SIZE])) B2WARNING("Frame size unsupported for RAW ADC frame! $" <<
313 LogVar("size [bytes] $", static_cast < std::ostringstream && >(std::ostringstream() << hex << frame_len).str())
314 << LogVar("DHE", dhe_ID) << LogVar("DHP", dhe_DHPport));
315 m_errorMask[c_nrFIX_SIZE] = true;
316 return;
317 }
318 unsigned int dhp_header_type = 0;
319// unsigned int dhp_reserved = 0;
320 unsigned int dhp_dhe_id = 0;
321 unsigned int dhp_dhp_id = 0;
322
323 dhp_header_type = (dhp_pix[2] & 0xE000) >> 13;
324// dhp_reserved = (dhp_pix[2] >> 8) & 0x1F;
325 dhp_dhe_id = (dhp_pix[2] & 0x00FC) >> 2;
326 dhp_dhp_id = dhp_pix[2] & 0x0003;
327
328 if (dhe_ID != dhp_dhe_id) {
329 if (!(m_suppressErrorMask[c_nrDHE_DHP_DHEID])) {
330 B2WARNING("DHE ID in DHE and DHP header differ");
331 B2DEBUG(29, "DHE ID in DHE and DHP header differ $" << hex << dhe_ID << " != $" << dhp_dhe_id);
332 }
333 m_errorMask[c_nrDHE_DHP_DHEID] = true;
334 }
335 if (dhe_DHPport != dhp_dhp_id) {
336 if (!(m_suppressErrorMask[c_nrDHE_DHP_PORT])) {
337 B2WARNING("DHP ID (Chip/Port) in DHE and DHP header differ");
338 B2DEBUG(29, "DHP ID (Chip/Port) in DHE and DHP header differ $" << hex << dhe_DHPport << " != $" << dhp_dhp_id);
339 }
340 m_errorMask[c_nrDHE_DHP_PORT] = true;
341 }
342
343 if (dhp_header_type != EDHPFrameHeaderDataType::c_RAW) {
344 if (!(m_suppressErrorMask[c_nrHEADERTYPE_INV])) {
345 B2WARNING("Header type invalid for this kind of DHE frame");
346 B2DEBUG(29, "Header type invalid for this kind of DHE frame: $" << hex << dhp_header_type);
347 }
348 m_errorMask[c_nrHEADERTYPE_INV] = true;
349 return;
350 }
351
353 B2DEBUG(29, "Raw ADC Data");
354 // size checked already above
355 m_storeRawAdc.appendNew(vxd_id, data, frame_len);
356};
357
358void PXDUnpackerOTModule::unpack_fce([[maybe_unused]] unsigned short* data, [[maybe_unused]] unsigned int length,
359 [[maybe_unused]] VxdID vxd_id)
360{
367
368 B2WARNING("FCE (Cluster) Packet have not yet been tested with real HW clusters. Dont assume that this code is working!");
369 return;
370
371 // implement the unpacking here and not as a separate module ... when it is available in HW
372// ubig16_t* cluster = (ubig16_t*)data;
373// int nr_words; //words in dhp frame
374// unsigned int words_in_cluster = 0; //counts 16bit words in cluster
375// nr_words = length / 2;
376// ubig16_t sor;
377// sor = 0x0000;
378//
379// for (int i = 2 ; i < nr_words ; i++) {
380// if (i != 2) { //skip header
381// if ((((cluster[i] & 0x8000) == 0)
382// && ((cluster[i] & 0x4000) >> 14) == 1)) { //searches for start of row frame with start of cluster flag = 1 => new cluster
383// if (!m_doNotStore) m_storeRawCluster.appendNew(&data[i - words_in_cluster], words_in_cluster, vxd_id);
384// words_in_cluster = 0;
385// }
386// }
387// if ((cluster[i] & 0x8000) == 0) {
388// sor = cluster[i];
389// }
390// words_in_cluster++;
391//
392// if ((cluster[nr_words - 1] & 0xFFFF) == (sor &
393// 0xFFFF)) {//if frame is not 32bit aligned last word will be the last start of row word
394// cluster[nr_words - 1] = 0x0000;//overwrites the last redundant word with zero to make checking easier in PXDHardwareClusterUnpacker
395// }
396//
397// if (i == nr_words - 1) {
398// if (!m_doNotStore) m_storeRawCluster.appendNew(&data[i - words_in_cluster + 1], words_in_cluster, vxd_id);
399// }
400// }
401}
402
403void PXDUnpackerOTModule::dump_dhp(void* data, unsigned int frame_len)
404{
405 // called only for debugging purpose, will never be called in normal running
406 unsigned int w = frame_len / 2;
407 ubig16_t* d = (ubig16_t*)data;
408
409 B2WARNING("HEADER -- $" << hex << d[0] << ",$" << hex << d[1] << ",$" << hex << d[2] << ",$" << hex << d[3] << " -- ");
410
411 auto dhp_header_type = (d[2] & 0xE000) >> 13;
412 auto dhp_reserved = (d[2] & 0x1F00) >> 8;
413 auto dhp_dhe_id = (d[2] & 0x00FC) >> 2;
414 auto dhp_dhp_id = d[2] & 0x0003;
415
416 B2WARNING("DHP type | $" << hex << dhp_header_type << " ( " << dec << dhp_header_type << " ) ");
417 B2WARNING("DHP reserved | $" << hex << dhp_reserved << " ( " << dec << dhp_reserved << " ) ");
418 B2WARNING("DHP DHE ID | $" << hex << dhp_dhe_id << " ( " << dec << dhp_dhe_id << " ) ");
419 B2WARNING("DHP DHP ID | $" << hex << dhp_dhp_id << " ( " << dec << dhp_dhp_id << " ) ");
420 for (unsigned int i = 4; i < w; i++) {
421 B2WARNING("DHP DATA $" << hex << d[i]);
422 }
423 B2WARNING("DHP CRC $" << hex << d[w] << ",$" << hex << d[w + 1]);
424}
425
426void PXDUnpackerOTModule::dump_roi(void* data, unsigned int frame_len)
427{
428 // called only for debugging purpose, will never be called in normal running
429 unsigned int w = frame_len / 4;
430 ubig32_t* d = (ubig32_t*)data;
431
432 B2WARNING("HEADER -- $" << hex << d[0] << ",$" << hex << d[1] << ",$" << hex << d[2] << ",$" << hex << d[3] << " -- Len $" << hex
433 << frame_len);
434
435 for (unsigned int i = 0; i < w; i++) {
436 B2WARNING("ROI DATA $" << hex << d[i]);
437 }
438 B2WARNING("ROI CRC $" << hex << d[w]);
439}
440
441void PXDUnpackerOTModule::unpack_dhp(void* data, unsigned int frame_len, unsigned int dhe_first_readout_frame_id_lo,
442 unsigned int dhe_ID, unsigned dhe_DHPport, unsigned dhe_reformat, VxdID vxd_id,
443 PXDDAQPacketStatus& daqpktstat)
444{
445 unsigned int nr_words = frame_len / 2; // frame_len in bytes (excl. CRC)!!!
446 ubig16_t* dhp_pix = (ubig16_t*)data;
447
448 unsigned int dhp_readout_frame_lo = 0;
449 unsigned int dhp_header_type = 0;
450 unsigned int dhp_reserved = 0;
451 unsigned int dhp_dhe_id = 0;
452 unsigned int dhp_dhp_id = 0;
453 unsigned int wrap = 0; // workaround to recalc a relative frame number
454 int last_gate = -1; // workaround to recalc a relative frame number
455
456 // cppcheck-suppress unreadVariable
457 unsigned int dhp_row = 0, dhp_col = 0, dhp_cm = 0;
458// unsigned int dhp_offset = 0;
459 bool rowflag = false;
460 bool pixelflag = true; // just for first row start
461
462 if (nr_words < 4) {
463 if (!(m_suppressErrorMask[c_nrDHP_SIZE])) B2WARNING("DHP frame size error (too small)" << LogVar("Nr words", nr_words));
464 m_errorMask[c_nrDHP_SIZE] = true;
465 return;
466 }
467
468 B2DEBUG(29, "HEADER -- $" << hex << dhp_pix[0] << hex << dhp_pix[1] << hex << dhp_pix[2] << hex << dhp_pix[3] << " -- ");
469
470 B2DEBUG(29, "DHP Header | $" << hex << dhp_pix[2] << " ( " << dec << dhp_pix[2] << " ) ");
471 dhp_header_type = (dhp_pix[2] & 0xE000) >> 13;
472 dhp_reserved = (dhp_pix[2] & 0x1F00) >> 8;
473 dhp_dhe_id = (dhp_pix[2] & 0x00FC) >> 2;
474 dhp_dhp_id = dhp_pix[2] & 0x0003;
475
476 B2DEBUG(29, "DHP type | $" << hex << dhp_header_type << " ( " << dec << dhp_header_type << " ) ");
477 B2DEBUG(29, "DHP reserved | $" << hex << dhp_reserved << " ( " << dec << dhp_reserved << " ) ");
478 B2DEBUG(29, "DHP DHE ID | $" << hex << dhp_dhe_id << " ( " << dec << dhp_dhe_id << " ) ");
479 B2DEBUG(29, "DHP DHP ID | $" << hex << dhp_dhp_id << " ( " << dec << dhp_dhp_id << " ) ");
480
481 if (dhe_ID != dhp_dhe_id) {
482 if (!(m_suppressErrorMask[c_nrDHE_DHP_DHEID])) {
483 B2WARNING("DHE ID in DHE and DHP header differ");
484 B2DEBUG(29, "DHE ID in DHE and DHP header differ $" << hex << dhe_ID << " != $" << dhp_dhe_id);
485 }
486 m_errorMask[c_nrDHE_DHP_DHEID] = true;
487 }
488 if (dhe_DHPport != dhp_dhp_id) {
489 if (!(m_suppressErrorMask[c_nrDHE_DHP_PORT])) {
490 B2WARNING("DHP ID (Chip/Port) in DHE and DHP header differ");
491 B2DEBUG(29, "DHP ID (Chip/Port) in DHE and DHP header differ $" << hex << dhe_DHPport << " != $" << dhp_dhp_id);
492 }
493 m_errorMask[c_nrDHE_DHP_PORT] = true;
494 }
495
496 if (dhp_header_type != EDHPFrameHeaderDataType::c_ZSD) {
497 if (!(m_suppressErrorMask[c_nrHEADERTYPE_INV])) {
498 B2WARNING("Header type invalid for this kind of DHE frame");
499 B2DEBUG(29, "Header type invalid for this kind of DHE frame: $" << hex << dhp_header_type);
500 }
501 m_errorMask[c_nrHEADERTYPE_INV] = true;
502 return;
503 }
504
505// static int offtab[4] = {0, 64, 128, 192};
506// dhp_offset = offtab[dhp_dhp_id];
507
508 dhp_readout_frame_lo = dhp_pix[3] & 0xFFFF;
509 B2DEBUG(29, "DHP Frame Nr | $" << hex << dhp_readout_frame_lo << " ( " << dec << dhp_readout_frame_lo << " ) ");
510
511 /* // TODO removed because data format error is not to be fixed soon
512 if (((dhp_readout_frame_lo - dhe_first_readout_frame_id_lo) & 0x3F) > m_maxDHPFrameDiff) {
513 if(!m_suppressErrorMask&c_DHP_DHE_FRAME_DIFFER ) B2WARNING("DHP Frame Nr differ from DHE Frame Nr by >1 DHE " << dhe_first_readout_frame_id_lo << " != DHP " << (dhp_readout_frame_lo & 0x3F) << " delta "<< ((dhp_readout_frame_lo - dhe_first_readout_frame_id_lo) & 0x3F) );
514 m_errorMask[c_nrDHP_DHE_FRAME_DIFFER] = true;
515 }
516 */
517 /* // TODO removed because data format error is not to be fixed soon
518 if (m_last_dhp_readout_frame_lo[dhp_dhp_id] != -1) {
519 if (((dhp_readout_frame_lo - m_last_dhp_readout_frame_lo[dhp_dhp_id]) & 0xFFFF) > m_maxDHPFrameDiff) {
520 if(!m_suppressErrorMask&c_DHP_NOT_CONT ) B2WARNING("Two DHP Frames per sensor which frame number differ more than one! " << m_last_dhp_readout_frame_lo[dhp_dhp_id] << ", " <<
521 dhp_readout_frame_lo);
522 m_errorMask[c_nrDHP_NOT_CONT] = true;
523 }
524 }
525 */
526
527 if (daqpktstat.dhc_size() > 0) {
528 if (daqpktstat.dhc_back().dhe_size() > 0) {
529 // only is we have a DHC and DHE object... or back() is undefined
530 // Remark, if we have a broken data (DHE_START/END) structure, we might fill the
531 // previous DHE object ... but then the data is junk anyway
532 daqpktstat.dhc_back().dhe_back().newDHP(dhp_dhp_id, dhp_readout_frame_lo);
533 }
534 }
535
536 /* // TODO removed because the data is not ordered as expected in current firmware
537 for (auto j = 0; j < 4; j++) {
538 if (m_last_dhp_readout_frame_lo[j] != -1) {
539 if (((dhp_readout_frame_lo - m_last_dhp_readout_frame_lo[j]) & 0xFFFF) > m_maxDHPFrameDiff) {
540 if(!m_suppressErrorMask&c_DHP_DHP_FRAME_DIFFER ) B2WARNING("Two DHP Frames (different DHP) per sensor which frame number differ more than one! " << m_last_dhp_readout_frame_lo[j] <<
541 ", " <<
542 dhp_readout_frame_lo);
543 m_errorMask[c_nrDHP_DHP_FRAME_DIFFER] = true;
544 break;// give msg only once
545 }
546 }
547 }
548 */
549 m_last_dhp_readout_frame_lo[dhp_dhp_id] = dhp_readout_frame_lo;
550
551// TODO Please check if this can happen by accident with valid data!
552 if (dhp_pix[2] == dhp_pix[4] && dhp_pix[3] + 1 == dhp_pix[5]) {
553 // We see a second "header" with framenr+1 ...
554 if (!(m_suppressErrorMask[c_nrDHP_DBL_HEADER])) {
555 B2WARNING("DHP data: seems to be double header! skipping.");
556 B2DEBUG(29, "DHP data: seems to be double header! skipping." << LogVar("Length",
557 frame_len));
558 }
559 m_errorMask[c_nrDHP_DBL_HEADER] = true;
560 // dump_dhp(data, frame_len); print out guilty dhp packet
561 return;
562 }
563
564 // Start with offset 4, thus skipping header words
565 for (unsigned int i = 4; i < nr_words ; i++) {
566
567 B2DEBUG(29, "-- $" << hex << dhp_pix[i] << " -- " << dec << i);
568 {
569 if (((dhp_pix[i] & 0x8000) >> 15) == 0) {
570 rowflag = true;
571 if (!pixelflag) {
572 if (!(m_suppressErrorMask[c_nrDHP_ROW_WO_PIX])) B2WARNING("DHP Unpacking: Row w/o Pix");
573 m_errorMask[c_nrDHP_ROW_WO_PIX] = true;
574 }
575 pixelflag = false;
576 dhp_row = (dhp_pix[i] & 0xFFC0) >> 5;
577 dhp_cm = dhp_pix[i] & 0x3F;
578 if (last_gate != -1 && (int)dhp_row / 4 < last_gate) {
579 // B2DEBUF(29,"Wrap " << LogVar("last", last_gate) << LogVar("curr", dhp_row / 4) << LogVar("DHE", dhe_ID) << LogVar("DHP", dhp_dhp_id));
580 wrap++; // relies on the order of data before mapping and the fact that OT firmware delivers only one frame
581 }
582 last_gate = dhp_row / 4;
583
584 if (dhp_cm == 63) { // fifo overflow
585 B2WARNING("DHP data loss (CM=63) in " << LogVar("DHE", dhe_ID) << LogVar("DHP", dhp_dhp_id));
587 m_errorMask[c_nrDHH_MISC_ERROR] = true;
588 }
589 if (daqpktstat.dhc_size() > 0) {
590 if (daqpktstat.dhc_back().dhe_size() > 0) {
591 PXDDAQDHPComMode cm(dhp_dhp_id, dhp_row, dhp_cm);
592 // only is we have a DHC and DHE object... or back() is undefined
593 // Remark, if we have a broken data (DHE_START/END) structure, we might fill the
594 // previous DHE object ... but then the data is junk anyway
595 daqpktstat.dhc_back().dhe_back().addCM(cm);
596 }
597 }
598 B2DEBUG(29, "SetRow: $" << hex << dhp_row << " CM $" << hex << dhp_cm);
599 } else {
600 if (!rowflag) {
601 if (!(m_suppressErrorMask[c_nrDHP_PIX_WO_ROW])) B2WARNING("DHP Unpacking: Pix without Row!!! skip dhp data ");
602 m_errorMask[c_nrDHP_PIX_WO_ROW] = true;
603 // dump_dhp(data, frame_len);// print out faulty dhp frame
604 return;
605 } else {
606 pixelflag = true;
607 dhp_row = (dhp_row & 0xFFE) | ((dhp_pix[i] & 0x4000) >> 14);
608 dhp_col = ((dhp_pix[i] & 0x3F00) >> 8);
609 unsigned int v_cellID, u_cellID;
610 v_cellID = dhp_row;// defaults for no mapping
611 if (dhp_row >= 768) {
612 if (!(m_suppressErrorMask[c_nrROW_OVERFLOW])) B2WARNING("DHP ROW Overflow " << LogVar("Row", dhp_row));
613 m_errorMask[c_nrROW_OVERFLOW] = true;
614 }
615 // we cannot do col overflow check before mapping :-(
616
617 if ((dhe_reformat == 0 && !m_forceNoMapping) || m_forceMapping) {
618 u_cellID = dhp_col;// defaults for no mapping
619 // data has not been pre-processed by DHH, thus we have to do the mapping ourselves
620 if ((dhe_ID & 0x21) == 0x00 || (dhe_ID & 0x21) == 0x21) {
621 // if IFOB
622 PXDMappingLookup::map_rc_to_uv_IF_OB(v_cellID, u_cellID, dhp_dhp_id, dhe_ID);
623 } else { // else OFIB
624 PXDMappingLookup::map_rc_to_uv_IB_OF(v_cellID, u_cellID, dhp_dhp_id, dhe_ID);
625 }
626 } else {
627 u_cellID = dhp_col + 64 * dhp_dhp_id; // defaults for already mapped
628 }
629 if (u_cellID >= 250) {
630 if (!(m_suppressErrorMask[c_nrCOL_OVERFLOW])) {
631 B2WARNING("DHP COL Overflow (unconnected drain lines)");
632 B2DEBUG(29, "DHP COL Overflow (unconnected drain lines) " << u_cellID << ", reformat " << dhe_reformat << ", dhpcol " << dhp_col <<
633 ", id " << dhp_dhp_id);
634 }
635 m_errorMask[c_nrCOL_OVERFLOW] = true;
636 }
637 auto dhp_adc = dhp_pix[i] & 0xFF;
638 B2DEBUG(29, "SetPix: Row $" << hex << dhp_row << " Col $" << hex << dhp_col << " ADC $" << hex << dhp_adc
639 << " CM $" << hex << dhp_cm);
640
641 if (dhp_adc == 0) {
642 // if !suppress error flag
643 B2WARNING("DHE Event truncation in DHE " << dhe_ID << " DHP " << dhp_dhp_id);
644 // m_errorMask |= c_DHE_EVENT_TRUNC;
645 daqpktstat.dhc_back().dhe_back().dhp_back().setTruncated();
646 } else {
647 // in new firmware, (dhp_readout_frame_lo - dhe_first_readout_frame_id_lo) would always been 0
648 if (!m_doNotStore) m_storeRawHits.appendNew(vxd_id, v_cellID, u_cellID, dhp_adc,
649 (dhp_readout_frame_lo - dhe_first_readout_frame_id_lo + wrap) & 0x3F);
650 }
651 }
652 }
653 }
654 }
655
656 B2DEBUG(29, "(DHE) DHE_ID $" << hex << dhe_ID << " (DHE) DHP ID $" << hex << dhe_DHPport << " (DHP) DHE_ID $" << hex << dhp_dhe_id
657 << " (DHP) DHP ID $" << hex << dhp_dhp_id);
658 /*for (int i = 0; i < raw_nr_words ; i++) {
659 B2DEBUG(29, "RAW | " << hex << p_pix[i]);
660 printf("raw %08X | ", p_pix[i]);
661 B2DEBUG(29, "row " << hex << ((p_pix[i] >> 20) & 0xFFF) << dec << " ( " << ((p_pix[i] >> 20) & 0xFFF) << " ) " << " col " << hex << ((p_pix[i] >> 8) & 0xFFF)
662 << " ( " << dec << ((p_pix[i] >> 8) & 0xFFF) << " ) " << " adc " << hex << (p_pix[i] & 0xFF) << " ( " << (p_pix[i] & 0xFF) << " ) "
663 );
664 }*/
665}
666
667void PXDUnpackerOTModule::unpack_dhc_frame(void* data, const int len, const int Frame_Number, const int Frames_in_event,
668 PXDDAQPacketStatus& daqpktstat)
669{
673 static unsigned int eventNrOfOnsenTrgFrame = 0;
674 static int countedBytesInDHC = 0;
675 static bool cancheck_countedBytesInDHC = false;
676 static int countedBytesInDHE = 0;
677 static bool cancheck_countedBytesInDHE = false;
678 static int countedDHEStartFrames = 0;
679 static int countedDHEEndFrames = 0;
680 static int mask_active_dhe = 0;// DHE mask (5 bit)
681 static int nr_active_dhe =
682 0;// TODO just count the active DHEs. Until now, it is not possible to check for the bit mask. we would need the info on which DHE connects to which DHC at which port from gearbox/geometry?
683 static int mask_active_dhp = 0;// DHP active mask, 4 bit, per current DHE
684 static int found_mask_active_dhp = 0;// mask which DHP send data and check on DHE END frame if it matches
685 static int found_good_mask_active_dhp = 0;// mask which DHP send useful data
686 static unsigned int dhe_first_readout_frame_id_lo = 0;
687 // cppcheck-suppress variableScope
688 static unsigned int dhe_first_triggergate = 0;
689 static unsigned int currentDHCID = 0xFFFFFFFF;
690 static unsigned int currentDHEID = 0xFFFFFFFF;
691 static unsigned int currentVxdId = 0;
692 static bool isFakedData_event = false;
693 static bool isUnfiltered_event = false;
694
695
696 if (Frame_Number == 0) {
697 // We reset the counters on the first event
698 // we do this before any other check is done
699 eventNrOfOnsenTrgFrame = 0;
700 countedDHEStartFrames = 0;
701 countedDHEEndFrames = 0;
702 countedBytesInDHC = 0;
703 cancheck_countedBytesInDHC = false;
704 countedBytesInDHE = 0;
705 cancheck_countedBytesInDHE = false;
706 currentDHCID = 0xFFFFFFFF;
707 currentDHEID = 0xFFFFFFFF;
708 currentVxdId = 0;
709 isUnfiltered_event = false;
710 isFakedData_event = false;
711 mask_active_dhe = 0;
712 nr_active_dhe = 0;
713 mask_active_dhp = 0;
714 found_mask_active_dhp = 0;
715 found_good_mask_active_dhp = 0;
716 }
717
719
720 dhc_frames dhc;
721 dhc.set(data, hw->getFrameType(), len);
722
723 {
724 // if a fixed size frame has a different length, how can we rely on its content???
725 // AND we could by typecasting access memory beyond end of data (but very unlikely)
726 // for that reason this we have to check before any CRC and stop unpacking the frame
727 int s = dhc.getFixedSize();
728 if (len != s && s != 0) {
729 if (!(m_suppressErrorMask[c_nrFIX_SIZE])) {
730 B2WARNING("Fixed frame type size does not match specs" << LogVar("expected length",
731 len) << LogVar("length in data", s));
732 }
733 m_errorMask[c_nrFIX_SIZE] = true;
734 if (!m_continueOnError) return;
735 }
736 }
737
738 // What do we do with wrong checksum frames? As we do not know WHAT is wrong, we have to skip them altogether.
739 // As they might contain HEADER Info, we might better skip the processing of the full package, too.
740 dhc.check_crc(m_errorMask, m_suppressErrorMask[c_nrDHE_CRC]);
741 if (!m_continueOnError && m_errorMask[c_nrDHE_CRC]) {
742 // if CRC is wrong, we cannot rely on the content of the frame, thus skipping is the best option
743 return;
744 }
745
746 unsigned int eventNrOfThisFrame = dhc.getEventNrLo();
747 int frame_type = dhc.getFrameType();
748
749 if (Frame_Number == 0) {
750 if (m_formatBonnDAQ) {
751 if (frame_type != EDHCFrameHeaderDataType::c_DHC_START) {
752 if (!(m_suppressErrorMask[c_nrEVENT_STRUCT])) B2WARNING("This looks not like BonnDAQ format.");
753 m_errorMask[c_nrEVENT_STRUCT] = true;
754// if (!m_continueOnError) return; // requires more testing
755 }
756 } else {
757 if (frame_type == EDHCFrameHeaderDataType::c_DHC_START) {
758 if (!(m_suppressErrorMask[c_nrEVENT_STRUCT]))
759 B2WARNING("This looks like BonnDAQ or old Desy 2013/14 testbeam format. Please use formatBonnDAQ or the pxdUnpackerDesy1314 module.");
760 m_errorMask[c_nrEVENT_STRUCT] = true;
761// if (!m_continueOnError) return; // requires more testing
762 }
763 }
764 }
765
766 if (!m_formatBonnDAQ) {
767 if (Frame_Number == 1) {
768 if (frame_type == EDHCFrameHeaderDataType::c_DHC_START) {
769 isFakedData_event = dhc.data_dhc_start_frame->isFakedData();
770 }
771 }
772
773 // please check if this mask is suitable. At least here we are limited by the 16 bit trigger number in the DHH packet header.
774 // we can use more bits in the DHC and DHE START Frame
775 if ((eventNrOfThisFrame & 0xFFFF) != (m_meta_event_nr & 0xFFFF)) {
776 if (!isFakedData_event) {
777 if (!(m_suppressErrorMask[c_nrMETA_MM])) {
778 B2WARNING("Event Numbers do not match for this frame");
779 B2DEBUG(29, "Event Numbers do not match for this frame" <<
780 LogVar("Event nr in frame $", static_cast < std::ostringstream
781 && >(std::ostringstream() << hex << eventNrOfThisFrame).str()) <<
782 LogVar("Event nr in MetaInfo (bits masked) $",
783 static_cast < std::ostringstream && >(std::ostringstream() << hex << m_meta_event_nr).str()));
784 }
785 m_errorMask[c_nrMETA_MM] = true;
786// if (!m_continueOnError) return; // requires more testing
787 }
788 }
789
790 if (Frame_Number > 1 && Frame_Number < Frames_in_event - 1) {
791 if (countedDHEStartFrames != countedDHEEndFrames + 1)
792 if (frame_type != EDHCFrameHeaderDataType::c_ONSEN_ROI && frame_type != EDHCFrameHeaderDataType::c_DHE_START) {
793 if (!(m_suppressErrorMask[c_nrDATA_OUTSIDE])) B2WARNING("Data Frame outside a DHE START/END");
794 m_errorMask[c_nrDATA_OUTSIDE] = true;
795// if (!m_continueOnError) return; // requires more testing
796 }
797 }
798 }
799
800 // TODO How do we handle Frames where Error Bit is set in header?
801 // Currently there is no documentation what it actually means... only an error bit is set (below)
802 // the following errors must be "accepted", as all firmware sets it wrong from Ghost frames.
803 if (hw->getErrorFlag()) {
804 if (frame_type != EDHCFrameHeaderDataType::c_GHOST) {
805 // We get ERROR bits in header even if only one module or DHP link is missing... thus
806 // we better filter a bit more ... but how?
807 if (!(m_suppressErrorMask[c_nrHEADER_ERR])) B2WARNING("Error Bit set in DHE Header");
808 m_errorMask[c_nrHEADER_ERR] = true;// TODO this should have some effect ... when does it mean something? documentation missing
809 }
810 } else {
811 if (frame_type == EDHCFrameHeaderDataType::c_GHOST) {
812 m_errorMask[c_nrHEADER_ERR_GHOST] = true;
813 }
814 }
815
816 switch (frame_type) {
817 case EDHCFrameHeaderDataType::c_DHP_RAW: {
818
820 if (currentDHEID != dhc.data_direct_readout_frame_raw->getDHEId()) {
821 if (!(m_suppressErrorMask[c_nrDHE_START_ID])) {
822 B2WARNING("DHE ID from DHE Start and this frame do not match");
823 B2DEBUG(29, "DHE ID from DHE Start and this frame do not match" <<
824 LogVar("DHEID in this frame $", static_cast < std::ostringstream
825 && >(std::ostringstream() << hex << dhc.data_direct_readout_frame_raw->getDHEId()).str()) <<
826 LogVar("DHEID expected $", static_cast < std::ostringstream && >(std::ostringstream() << hex << currentDHEID).str()));
827 }
828 m_errorMask[c_nrDHE_START_ID] = true;
829 }
830 dhc.check_crc(m_errorMask, m_suppressErrorMask[c_nrDHE_CRC]);
831 if ((found_mask_active_dhp & (1 << dhc.data_direct_readout_frame->getDHPPort())) != 0) {
832 B2ERROR("Second DHP data packet (MEMDUMP) for " << LogVar("DHE", currentDHEID) << LogVar("DHP",
834 }
835
836 found_mask_active_dhp |= 1 << dhc.data_direct_readout_frame->getDHPPort();
837
838 unpack_dhp_raw(data, len - 4,
841 currentVxdId);
842
843 break;
844 };
845 case EDHCFrameHeaderDataType::c_ONSEN_DHP:
846 // Set the counted size invalid if negative, needs a large negative value because we are adding up to that
847 cancheck_countedBytesInDHC = false;
848 cancheck_countedBytesInDHE = false;
849 [[fallthrough]];
850 case EDHCFrameHeaderDataType::c_DHP_ZSD: {
851
853 if (isUnfiltered_event) {
854 if (frame_type == EDHCFrameHeaderDataType::c_ONSEN_DHP) m_errorMask[c_nrSENDALL_TYPE] = true;
855 } else {
856 if (frame_type == EDHCFrameHeaderDataType::c_DHP_ZSD) m_errorMask[c_nrNOTSENDALL_TYPE] = true;
857 }
858
859 //m_errorMask |= dhc.data_direct_readout_frame->check_error();
860
861 if (currentDHEID != dhc.data_direct_readout_frame_raw->getDHEId()) {
862 if (!(m_suppressErrorMask[c_nrDHE_START_ID])) {
863 B2WARNING("DHE ID from DHE Start and this frame do not match");
864 B2DEBUG(29, "DHE ID from DHE Start and this frame do not match" <<
865 LogVar("DHEID in this frame $", static_cast < std::ostringstream
866 && >(std::ostringstream() << hex << dhc.data_direct_readout_frame_raw->getDHEId()).str()) <<
867 LogVar("DHEID expected $", static_cast < std::ostringstream && >(std::ostringstream() << hex << currentDHEID).str()));
868 }
869 m_errorMask[c_nrDHE_START_ID] = true;
870 }
871 dhc.check_crc(m_errorMask, m_suppressErrorMask[c_nrDHE_CRC]);
872 if ((found_mask_active_dhp & (1 << dhc.data_direct_readout_frame->getDHPPort())) != 0) {
873 B2ERROR("Second DHP data packet for " << LogVar("DHE", currentDHEID) << LogVar("DHP", dhc.data_direct_readout_frame->getDHPPort()));
874 }
875 found_mask_active_dhp |= 1 << dhc.data_direct_readout_frame->getDHPPort();
876 found_good_mask_active_dhp |= 1 << dhc.data_direct_readout_frame->getDHPPort();// only this frametype has useful data
877 if (m_checkPaddingCRC) dhc.check_padding(m_errorMask); // isUnfiltered_event
878
879
880 unpack_dhp(data, len - 4,
881 dhe_first_readout_frame_id_lo,
885 currentVxdId, daqpktstat);
886
887 break;
888 };
889 case EDHCFrameHeaderDataType::c_ONSEN_FCE:
890 // Set the counted size invalid if negative, needs a large negative value because we are adding up to that
891 cancheck_countedBytesInDHC = false;
892 cancheck_countedBytesInDHE = false;
893 [[fallthrough]];
894 case EDHCFrameHeaderDataType::c_FCE_RAW: {
895 if (!(m_suppressErrorMask[c_nrUNEXPECTED_FRAME_TYPE])) B2WARNING("Unexpected Frame Type (Clustering FCE)");
896 m_errorMask[c_nrUNEXPECTED_FRAME_TYPE] = true;
897 if (m_verbose) hw->print();
898 if (isUnfiltered_event) {
899 if (frame_type == EDHCFrameHeaderDataType::c_ONSEN_FCE) {
900 // TODO add error message
901 m_errorMask[c_nrSENDALL_TYPE] = true;
902 }
903 } else {
904 if (frame_type == EDHCFrameHeaderDataType::c_FCE_RAW) {
905 // TODO add error message
906 m_errorMask[c_nrNOTSENDALL_TYPE] = true;
907 }
908 }
909
910 if (currentDHEID != dhc.data_direct_readout_frame_raw->getDHEId()) {
911 if (!(m_suppressErrorMask[c_nrDHE_START_ID])) {
912 B2WARNING("DHE ID from DHE Start and this frame do not match");
913 B2DEBUG(29, "DHE ID from DHE Start and this frame do not match" <<
914 LogVar("DHEID in this frame $", static_cast < std::ostringstream
915 && >(std::ostringstream() << hex << dhc.data_direct_readout_frame_raw->getDHEId()).str()) <<
916 LogVar("DHEID expected $", static_cast < std::ostringstream && >(std::ostringstream() << hex << currentDHEID).str()));
917 }
918 m_errorMask[c_nrDHE_START_ID] = true;
919 }
920 dhc.check_crc(m_errorMask, m_suppressErrorMask[c_nrDHE_CRC]);
921 if ((found_mask_active_dhp & (1 << dhc.data_direct_readout_frame->getDHPPort())) != 0) {
922 B2ERROR("Second DHP data packet (FCE) for " << LogVar("DHE", currentDHEID) << LogVar("DHP",
924 }
925 found_mask_active_dhp |= 1 << dhc.data_direct_readout_frame->getDHPPort();
926
927 B2DEBUG(29, "UNPACK FCE FRAME with len $" << hex << len);
928 unpack_fce((unsigned short*) data, len - 4, currentVxdId);
929
930 break;
931 };
932 case EDHCFrameHeaderDataType::c_COMMODE: {
933 // this frame type has up to now not been well defined, we do not expect it until
934 // the firmware supports clustering in hardware
935 if (!(m_suppressErrorMask[c_nrUNEXPECTED_FRAME_TYPE])) B2WARNING("Unexpected Frame Type (COMMODE)");
936 m_errorMask[c_nrUNEXPECTED_FRAME_TYPE] = true;
937
938 if (m_verbose) hw->print();
939 if (currentDHEID != dhc.data_commode_frame->getDHEId()) {
940 if (!(m_suppressErrorMask[c_nrDHE_START_ID])) {
941 B2WARNING("DHE ID from DHE Start and this frame do not match");
942 B2DEBUG(29, "DHE ID from DHE Start and this frame do not match" <<
943 LogVar("DHEID in this frame $", static_cast < std::ostringstream
944 && >(std::ostringstream() << hex << dhc.data_commode_frame->getDHEId()).str()) <<
945 LogVar("DHEID expected $", static_cast < std::ostringstream && >(std::ostringstream() << hex << currentDHEID).str()));
946 }
947 m_errorMask[c_nrDHE_START_ID] = true;
948 }
949 dhc.check_crc(m_errorMask, m_suppressErrorMask[c_nrDHE_CRC]);
950 break;
951 };
952 case EDHCFrameHeaderDataType::c_DHC_START: {
953 countedBytesInDHC = 0;
954 cancheck_countedBytesInDHC = true;
955 if (isFakedData_event != dhc.data_dhc_start_frame->isFakedData()) {
956 if (!(m_suppressErrorMask[c_nrFAKE_NO_FAKE_DATA])) B2WARNING("DHC START mixed Fake/no Fake event.");
957 m_errorMask[c_nrFAKE_NO_FAKE_DATA] = true;
958 }
960 if (!(m_suppressErrorMask[c_nrFAKE_NO_DATA_TRIG])) B2WARNING("Faked DHC START Data -> trigger without Data!");
961 m_errorMask[c_nrFAKE_NO_DATA_TRIG] = true;
962 } else {
964 }
965
966// eventNrOfOnsenTrgFrame = eventNrOfThisFrame;
967 currentDHEID = 0xFFFFFFFF;
968 currentVxdId = 0;
969 currentDHCID = dhc.data_dhc_start_frame->get_dhc_id();
970 dhc.check_crc(m_errorMask, m_suppressErrorMask[c_nrDHE_CRC]);
971
972 if (m_formatBonnDAQ) eventNrOfOnsenTrgFrame = eventNrOfThisFrame;
973
974 if (!isFakedData_event) {
978 if (!(m_suppressErrorMask[c_nrMETA_MM_DHC_ERS])) {
979 B2WARNING("DHC-Meta Experiment number mismatch");
980 B2DEBUG(29, "DHC-Meta Experiment number mismatch" <<
981 LogVar("DHC exp nr",
983 LogVar("META exp nr", m_meta_experiment));
984 }
985 m_errorMask[c_nrMETA_MM_DHC_ERS] = true;
986 }
988 if (!(m_suppressErrorMask[c_nrMETA_MM_DHC_ERS])) {
989 B2WARNING("DHC-Meta Run number mismatch");
990 B2DEBUG(29, "DHC-Meta Run number mismatch" <<
991 LogVar("DHC Run nr",
993 LogVar("META run nr", m_meta_run_nr));
994 }
995 m_errorMask[c_nrMETA_MM_DHC_ERS] = true;
996 }
998 if (!(m_suppressErrorMask[c_nrMETA_MM_DHC_ERS])) {
999 B2WARNING("DHC-Meta Sub-Run number mismatch");
1000 B2DEBUG(29, "DHC-Meta Sub-Run number mismatch" <<
1001 LogVar("DHC subrun nr",
1003 LogVar("META subrun nr", m_meta_subrun_nr));
1004 }
1005 m_errorMask[c_nrMETA_MM_DHC_ERS] = true;
1006 }
1007 if ((((unsigned int)dhc.data_dhc_start_frame->getEventNrHi() << 16) | dhc.data_dhc_start_frame->getEventNrLo()) !=
1008 (m_meta_event_nr & 0xFFFFFFFF)) {
1009 if (!(m_suppressErrorMask[c_nrMETA_MM_DHC])) {
1010 B2WARNING("DHC-Meta 32 bit event number mismatch");
1011 B2DEBUG(29, "DHC-Meta 32 bit event number mismatch" <<
1012 LogVar("DHC trigger nr", (((unsigned int) dhc.data_dhc_start_frame->getEventNrHi() << 16) |
1014 LogVar("META trigger nr", (unsigned int)(m_meta_event_nr & 0xFFFFFFFF)));
1015 }
1016 m_errorMask[c_nrMETA_MM_DHC] = true;
1017 }
1018 uint32_t trig_ticks = (((unsigned int)dhc.data_dhc_start_frame->time_tag_mid & 0x7FFF) << 12) | ((unsigned int)
1020 uint32_t trig_sec = (dhc.data_dhc_start_frame->time_tag_hi * 2) ;
1021 if (dhc.data_dhc_start_frame->time_tag_mid & 0x8000) trig_sec++;
1022
1023 if ((trig_ticks - m_meta_ticks) != 0 || (trig_sec - m_meta_sec) != 0) {
1024 m_errorMask[c_nrMETA_MM_DHC_TT] = true;
1025 if (!(m_suppressErrorMask[c_nrMETA_MM_DHC_TT])) {
1026 B2WARNING("DHC-Meta TimeTag mismatch");
1027 B2DEBUG(29, "DHC-Meta TimeTag mismatch" <<
1028 LogVar("Header Time $", static_cast < std::ostringstream && >(std::ostringstream() <<
1029 hex << dhc.data_dhc_start_frame->time_tag_hi << "." <<
1030 dhc.data_dhc_start_frame->time_tag_mid << "." <<
1032 LogVar("Meta Time $", static_cast < std::ostringstream && >(std::ostringstream() << hex << m_meta_time).str()) <<
1033 LogVar("Trigger Type", static_cast < std::ostringstream
1034 && >(std::ostringstream() << hex << (dhc.data_dhc_start_frame->time_tag_lo_and_type & 0xF)).str()) <<
1035 LogVar("Meta seconds: $", static_cast < std::ostringstream && >(std::ostringstream() << hex << m_meta_sec).str()) <<
1036 LogVar("DHC seconds $", static_cast < std::ostringstream && >(std::ostringstream() << hex << trig_sec).str()) <<
1037 LogVar("Seconds difference $", static_cast < std::ostringstream
1038 && >(std::ostringstream() << hex << (trig_sec - m_meta_sec)).str()) <<
1039 LogVar("Meta ticks from 127MHz $", static_cast < std::ostringstream && >(std::ostringstream() << hex << m_meta_ticks).str()) <<
1040 LogVar("DHC ticks from 127MHz $", static_cast < std::ostringstream && >(std::ostringstream() << hex << trig_ticks).str()) <<
1041 LogVar("Tick difference $", static_cast < std::ostringstream
1042 && >(std::ostringstream() << hex << (trig_ticks - m_meta_ticks)).str()));
1043 }
1044 } else {
1045 B2DEBUG(29, "DHC TT: $" << hex << dhc.data_dhc_start_frame->time_tag_hi << "." << dhc.data_dhc_start_frame->time_tag_mid << "." <<
1046 dhc.data_dhc_start_frame->time_tag_lo_and_type << " META " << m_meta_time << " TRG Type " <<
1048 }
1049 }
1050 mask_active_dhe = dhc.data_dhc_start_frame->get_active_dhe_mask();
1051 nr_active_dhe = nr5bits(mask_active_dhe);
1052
1053 m_errorMaskDHC = m_errorMask; // forget about anything before this frame
1054 daqpktstat.newDHC(currentDHCID, m_errorMask);
1057
1058 break;
1059 };
1060 case EDHCFrameHeaderDataType::c_DHE_START: {
1061 countedBytesInDHE = 0;
1062 cancheck_countedBytesInDHE = true;
1068 dhe_first_readout_frame_id_lo = dhc.data_dhe_start_frame->getStartFrameNr();
1069 dhe_first_triggergate = dhc.data_dhe_start_frame->getTriggerGate();
1070 if (currentDHEID != 0xFFFFFFFF && (currentDHEID & 0xFFFF) >= dhc.data_dhe_start_frame->getDHEId()) {
1071 if (!(m_suppressErrorMask[c_nrDHE_WRONG_ID_SEQ])) {
1072 B2WARNING("DHH IDs are not in expected order");
1073 B2DEBUG(29, "DHH IDs are not in expected order" <<
1074 LogVar("Previous ID", (currentDHEID & 0xFFFF)) <<
1075 LogVar("Current ID", dhc.data_dhe_start_frame->getDHEId()));
1076 }
1077 m_errorMask[c_nrDHE_WRONG_ID_SEQ] = true;
1078 }
1079 currentDHEID = dhc.data_dhe_start_frame->getDHEId();
1080 dhc.check_crc(m_errorMask, m_suppressErrorMask[c_nrDHE_CRC]);
1081
1082 if (countedDHEStartFrames > countedDHEEndFrames) {
1083 if (!(m_suppressErrorMask[c_nrDHE_START_WO_END])) B2WARNING("DHE_START without DHE_END");
1084 m_errorMask[c_nrDHE_START_WO_END] = true;
1085 }
1086 countedDHEStartFrames++;
1087
1088 found_mask_active_dhp = 0;
1089 found_good_mask_active_dhp = 0;
1090 mask_active_dhp = dhc.data_dhe_start_frame->getActiveDHPMask();
1091
1092 if ((((unsigned int)dhc.data_dhe_start_frame->getEventNrHi() << 16) | dhc.data_dhe_start_frame->getEventNrLo()) != (unsigned int)(
1093 m_meta_event_nr & 0xFFFFFFFF)) {
1094 if (!(m_suppressErrorMask[c_nrMETA_MM_DHE])) {
1095 B2WARNING("DHE START trigger mismatch in EVT32b/HI WORD");
1096 B2DEBUG(29, "DHE START trigger mismatch in EVT32b/HI WORD" <<
1097 LogVar("DHE Start trigger nr", (dhc.data_dhe_start_frame->getEventNrHi() << 16) | dhc.data_dhe_start_frame->getEventNrLo()) <<
1098 LogVar("Meta trigger nr", (m_meta_event_nr & 0xFFFFFFFF)));
1099 }
1100 m_errorMask[c_nrMETA_MM_DHE] = true;
1101 }
1102// B2WARNING("DHE TT: $" << hex << dhc.data_dhe_start_frame->dhe_time_tag_hi << "." << dhc.data_dhe_start_frame->dhe_time_tag_lo <<
1103// " META " << m_meta_time);
1104
1105 if (currentDHEID == 0) {
1106 if (!(m_suppressErrorMask[c_nrDHE_ID_INVALID])) B2WARNING("DHE ID is invalid=0 (not initialized)");
1107 m_errorMask[c_nrDHE_ID_INVALID] = true;
1108 }
1109 // calculate the VXDID for DHE and save them for DHP unpacking
1110 {
1117 unsigned short sensor, ladder, layer;
1118 sensor = (currentDHEID & 0x1) + 1;
1119 ladder = (currentDHEID & 0x1E) >> 1; // no +1
1120 layer = ((currentDHEID & 0x20) >> 5) + 1;
1121 currentVxdId = VxdID(layer, ladder, sensor);
1122 if (ladder == 0 || (layer == 1 && ladder > 8) || (layer == 2 && ladder > 12)) {
1123 if (!(m_suppressErrorMask[c_nrDHE_ID_INVALID])) {
1124 B2WARNING("DHE ID is invalid");
1125 B2DEBUG(29, "DHE ID is invalid" <<
1126 LogVar("DHE ID", currentDHEID) <<
1127 LogVar("Layer", layer) <<
1128 LogVar("Ladder", ladder) <<
1129 LogVar("Sensor", sensor));
1130 }
1131 m_errorMask[c_nrDHE_ID_INVALID] = true;
1132 }
1133 }
1134
1135 m_errorMaskDHE = m_errorMask; // forget about anything before this frame
1136 if (daqpktstat.dhc_size() > 0) {
1137 // if no DHC has been defined yet, do nothing!
1138 daqpktstat.dhc_back().newDHE(currentVxdId, currentDHEID, m_errorMask, dhe_first_triggergate, dhe_first_readout_frame_id_lo);
1139 }
1140 break;
1141 };
1142 case EDHCFrameHeaderDataType::c_GHOST:
1143 if (m_verbose) dhc.data_ghost_frame->print();
1144 if (currentDHEID != dhc.data_ghost_frame->getDHEId()) {
1145 if (!(m_suppressErrorMask[c_nrDHE_START_ID])) {
1146 B2WARNING("DHE ID from DHE Start and this frame do not match");
1147 B2DEBUG(29, "Start ID $" << hex << currentDHEID << " != $" << dhc.data_ghost_frame->getDHEId());
1148 }
1149 m_errorMask[c_nrDHE_START_ID] = true;
1150 }
1152 if ((found_mask_active_dhp & (1 << dhc.data_ghost_frame->getDHPPort())) != 0) {
1153 B2ERROR("Second DHP data packet (GHOST) for " << LogVar("DHE", currentDHEID) << LogVar("DHP", dhc.data_ghost_frame->getDHPPort()));
1154 }
1155 found_mask_active_dhp |= 1 << dhc.data_ghost_frame->getDHPPort();
1156
1157 dhc.check_crc(m_errorMask, m_suppressErrorMask[c_nrDHE_CRC]);
1158
1159 break;
1160 case EDHCFrameHeaderDataType::c_DHC_END: {
1161 if (dhc.data_dhc_end_frame->isFakedData() != isFakedData_event) {
1162 if (!(m_suppressErrorMask[c_nrFAKE_NO_FAKE_DATA])) B2WARNING("DHC END mixed Fake/no Fake event.");
1163 m_errorMask[c_nrFAKE_NO_FAKE_DATA] = true;
1164 }
1165 if (dhc.data_dhc_end_frame->isFakedData()) {
1166 if (!(m_suppressErrorMask[c_nrFAKE_NO_DATA_TRIG])) B2WARNING("Faked DHC END Data -> trigger without Data!");
1167 m_errorMask[c_nrFAKE_NO_DATA_TRIG] = true;
1168 } else {
1170 }
1171
1172 if (!isFakedData_event) {
1173 if (dhc.data_dhc_end_frame->get_dhc_id() != currentDHCID) {
1174 if (!(m_suppressErrorMask[c_nrDHC_DHCID_START_END_MM])) {
1175 B2WARNING("DHC ID Mismatch between Start and End");
1176 B2DEBUG(29, "DHC ID Mismatch between Start and End $" << std::hex <<
1177 currentDHCID << "!=$" << dhc.data_dhc_end_frame->get_dhc_id());
1178 }
1179 m_errorMask[c_nrDHC_DHCID_START_END_MM] = true;
1180 }
1181 int w;
1182 w = dhc.data_dhc_end_frame->get_words() * 4;
1183 if (cancheck_countedBytesInDHC) {
1184 if (countedBytesInDHC != w) {
1185 if (!(m_suppressErrorMask[c_nrDHC_WIE])) {
1186 B2WARNING("Number of Words in DHC END does not match");
1187 B2DEBUG(29, "Number of Words in DHC END does not match: WIE $" << hex << countedBytesInDHC << " != DHC END $" << hex << w);
1188 }
1189 m_errorMask[c_nrDHC_WIE] = true;
1190 } else {
1191 if (m_verbose)
1192 B2DEBUG(29, "EVT END: WIE $" << hex << countedBytesInDHC << " == DHC END $" << hex << w);
1193 }
1194 // else ... processed data -> length invalid
1195 }
1196 }
1198 if (dhc.data_dhc_end_frame->getErrorInfo() != 0) {
1199 if (!(m_suppressErrorMask[c_nrDHH_END_ERRORBITS])) B2ERROR("DHC END Error Info set to $" << hex <<
1201 m_errorMask[c_nrDHH_END_ERRORBITS] = true;
1202 }
1203 dhc.check_crc(m_errorMask, m_suppressErrorMask[c_nrDHE_CRC]);
1204 m_errorMaskDHC |= m_errorMask; // do latest updates
1205
1206 if (daqpktstat.dhc_size() > 0) {
1207 // only is we have a DHC object... or back() is undefined
1208 // Remark, if we have a broken data (DHC_START/END) structure, we might fill the
1209 // previous DHC object ... but then the data is junk anyway
1210 daqpktstat.dhc_back().setErrorMask(m_errorMaskDHC);
1211 //B2DEBUG(98,"** DHC "<<currentDHCID<<" Raw"<<dhc.data_dhc_end_frame->get_words() * 4 <<" Red"<<countedBytesInDHC);
1212 daqpktstat.dhc_back().setCounters(dhc.data_dhc_end_frame->get_words() * 4, countedBytesInDHC);
1214 }
1215 m_errorMaskDHC = 0;
1216 currentDHEID = 0xFFFFFFFF;
1217 currentDHCID = 0xFFFFFFFF;
1218 currentVxdId = 0;
1219 break;
1220 };
1221 case EDHCFrameHeaderDataType::c_DHE_END: {
1223 if (currentDHEID != dhc.data_dhe_end_frame->getDHEId()) {
1224 if (!(m_suppressErrorMask[c_nrDHE_START_END_ID])) {
1225 B2WARNING("DHE ID from DHE Start and this frame do not match");
1226 B2DEBUG(29, "DHE ID from DHE Start and this frame do not match $" << hex << currentDHEID << " != $" <<
1228 }
1229 m_errorMask[c_nrDHE_START_END_ID] = true;
1230 }
1232 if (dhc.data_dhe_end_frame->getErrorInfo() != 0) {
1233 if (!(m_suppressErrorMask[c_nrDHH_END_ERRORBITS])) {
1234 B2ERROR("DHE END Error Info set to $" << hex << dhc.data_dhe_end_frame->getErrorInfo());
1235 }
1236 m_errorMask[c_nrDHH_END_ERRORBITS] = true;
1237 }
1238 dhc.check_crc(m_errorMask, m_suppressErrorMask[c_nrDHE_CRC]);
1239 if (found_mask_active_dhp != mask_active_dhp) {
1240 if (!(m_suppressErrorMask[c_nrDHP_ACTIVE])) {
1241 B2WARNING("DHE_END: DHP active mask differs from found data");
1242 B2DEBUG(29, "DHE_END: DHP active mask differs from found data $" << hex << mask_active_dhp << " != $" << hex <<
1243 found_mask_active_dhp
1244 << " mask of found dhp/ghost frames");
1245 }
1246 m_errorMask[c_nrDHP_ACTIVE] = true;
1247 }
1248 countedDHEEndFrames++;
1249 if (countedDHEStartFrames < countedDHEEndFrames) {
1250 // the other case is checked in Start
1251 if (!(m_suppressErrorMask[c_nrDHE_END_WO_START])) B2WARNING("DHE_END without DHE_START");
1252 m_errorMask[c_nrDHE_END_WO_START] = true;
1253 }
1254 {
1255 int w;
1256 w = dhc.data_dhe_end_frame->get_words() * 2;
1257 if (cancheck_countedBytesInDHE) {
1258 if (countedBytesInDHE != w) {
1259 if (!(m_suppressErrorMask[c_nrDHE_WIE])) {
1260 B2WARNING("Number of Words in DHE END does not match");
1261 B2DEBUG(29, "Number of Words in DHE END does not match: WIE $" << hex << countedBytesInDHE << " != DHE END $" << hex << w);
1262 }
1263 m_errorMask[c_nrDHE_WIE] = true;
1264 } else {
1265 if (m_verbose)
1266 B2DEBUG(29, "EVT END: WIE $" << hex << countedBytesInDHE << " == DHE END $" << hex << w);
1267 }
1268 // else ... processed data -> length invalid
1269 }
1270 }
1271 m_errorMaskDHE |= m_errorMask; // do latest updates
1272
1273 if (daqpktstat.dhc_size() > 0) {
1274 if (daqpktstat.dhc_back().dhe_size() > 0) {
1275 // only is we have a DHC and DHE object... or back() is undefined
1276 // Remark, if we have a broken data (DHE_START/END) structure, we might fill the
1277 // previous DHE object ... but then the data is junk anyway
1279 // B2DEBUG(98,"** DHC "<<currentDHEID<<" Raw "<<dhc.data_dhe_end_frame->get_words() * 2 <<" Red"<<countedBytesInDHE);
1280 daqpktstat.dhc_back().dhe_back().setCounters(dhc.data_dhe_end_frame->get_words() * 2, countedBytesInDHE);
1281 daqpktstat.dhc_back().dhe_back().setDHPFoundMask(found_good_mask_active_dhp);
1283 }
1284 }
1285 m_errorMaskDHE = 0;
1286 currentDHEID |= 0xFF000000;// differentiate from 0xFFFFFFFFF as initial value
1287 currentVxdId = 0;
1288 break;
1289 };
1290 case EDHCFrameHeaderDataType::c_ONSEN_ROI:
1292 dhc.data_onsen_roi_frame->check_error(m_errorMask, len, m_suppressErrorMask[c_nrROI_PACKET_INV_SIZE]);
1294 dhc.check_crc(m_errorMask, m_suppressErrorMask[c_nrDHE_CRC]);
1295 if (!m_doNotStore) {
1296 //dhc.data_onsen_roi_frame->save(m_storeROIs, len, (unsigned int*) data);
1297 // void save(StoreArray<PXDRawROIs>& sa, unsigned int length, unsigned int* data) const
1298 // 4 byte header, ROIS (n*8), 4 byte copy of inner CRC, 4 byte outer CRC
1299 if (len >= dhc.data_onsen_roi_frame->getMinSize()) {
1300 //if ((len - dhc.data_onsen_roi_frame->getMinSize()) % 8 != 0) {
1301 // error checking in check_error() above, this is only for dump-ing
1302 // dump_roi(data, len - 4); // dump ROI payload, minus CRC
1303 //}
1304 unsigned int l;
1305 l = (len - dhc.data_onsen_roi_frame->getMinSize()) / 8;
1306 // Endian swapping is done in Constructor of RawRoi object
1307 m_storeROIs.appendNew(l, &((unsigned int*) data)[1]);
1308 }
1309 }
1310 break;
1311 case EDHCFrameHeaderDataType::c_ONSEN_TRG:
1312 eventNrOfOnsenTrgFrame = eventNrOfThisFrame;
1313 if (dhc.data_onsen_trigger_frame->get_trig_nr1() != (unsigned int)(m_meta_event_nr & 0xFFFFFFFF)) {
1314 if (!(m_suppressErrorMask[c_nrMETA_MM_ONS_HLT])) {
1315 B2WARNING("Trigger Frame HLT Trigger Nr mismatch");
1316 B2DEBUG(29, "Trigger Frame HLT Trigger Nr mismatch: HLT $" <<
1317 dhc.data_onsen_trigger_frame->get_trig_nr1() << " META " << (m_meta_event_nr & 0xFFFFFFFF));
1318 }
1319 m_errorMask[c_nrMETA_MM_ONS_HLT] = true;
1320 }
1324 if (!(m_suppressErrorMask[c_nrMETA_MM_ONS_HLT])) {
1325 B2WARNING("Trigger Frame HLT Exp/Run/Subrun Nr mismatch");
1326 B2DEBUG(29, "Trigger Frame HLT Exp/Run/Subrun Nr mismatch: Exp HLT $" <<
1328 " Run HLT $" << dhc.data_onsen_trigger_frame->get_run1() << " META " << m_meta_run_nr <<
1329 " Subrun HLT $" << dhc.data_onsen_trigger_frame->get_subrun1() << " META " << m_meta_subrun_nr);
1330 }
1331 m_errorMask[c_nrMETA_MM_ONS_HLT] = true;
1332 }
1333
1335 if (dhc.data_onsen_trigger_frame->get_trig_nr2() != (unsigned int)(m_meta_event_nr & 0xFFFFFFFF)) {
1336 if (!(m_suppressErrorMask[c_nrMETA_MM_ONS_DC])) {
1337 B2WARNING("Trigger Frame DATCON Trigger Nr mismatch");
1338 B2DEBUG(29, "Trigger Frame DATCON Trigger Nr mismatch: DC $" <<
1339 dhc.data_onsen_trigger_frame->get_trig_nr2() << " META " << (m_meta_event_nr & 0xFFFFFFFF));
1340 }
1341 m_errorMask[c_nrMETA_MM_ONS_DC] = true;
1342 }
1346 if (!(m_suppressErrorMask[c_nrMETA_MM_ONS_DC])) {
1347 B2WARNING("Trigger Frame DATCON Exp/Run/Subrun Nr mismatch");
1348 B2DEBUG(29, "Trigger Frame DATCON Exp/Run/Subrun Nr mismatch: Exp DC $" <<
1350 " Run DC $" << dhc.data_onsen_trigger_frame->get_run2() << " META " << m_meta_run_nr <<
1351 " Subrun DC $" << dhc.data_onsen_trigger_frame->get_subrun2() << " META " << m_meta_subrun_nr);
1352 }
1353 m_errorMask[c_nrMETA_MM_ONS_DC] = true;
1354 }
1355 }
1356
1357// B2WARNING("TRG TAG HLT: $" << hex << dhc.data_onsen_trigger_frame->get_trig_tag1() << " DATCON $" << dhc.data_onsen_trigger_frame->get_trig_tag2() << " META " << m_meta_time);
1358
1361 m_suppressErrorMask[c_nrMERGER_TRIGNR]);
1362 dhc.check_crc(m_errorMask, m_suppressErrorMask[c_nrDHE_CRC]);
1363 if (Frame_Number != 0) {
1364 if (!(m_suppressErrorMask[c_nrEVENT_STRUCT])) B2WARNING("ONSEN TRG Frame must be the first one.");
1365 m_errorMask[c_nrEVENT_STRUCT] = true;
1366 }
1367 isUnfiltered_event = dhc.data_onsen_trigger_frame->is_SendUnfiltered();
1368 if (isUnfiltered_event) m_sendunfiltered++;
1371 break;
1372 default:
1373 if (!(m_suppressErrorMask[c_nrDHC_UNKNOWN])) B2WARNING("UNKNOWN DHC frame type");
1374 m_errorMask[c_nrDHC_UNKNOWN] = true;
1375 if (m_verbose) hw->print();
1376 break;
1377 }
1378
1379 if (eventNrOfThisFrame != eventNrOfOnsenTrgFrame && !isFakedData_event) {
1380 if (!(m_suppressErrorMask[c_nrFRAME_TNR_MM])) {
1381 B2WARNING("Frame TrigNr != ONSEN Trig Nr");
1382 B2DEBUG(29, "Frame TrigNr != ONSEN Trig Nr $" << hex << eventNrOfThisFrame << " != $" << eventNrOfOnsenTrgFrame);
1383 }
1384 m_errorMask[c_nrFRAME_TNR_MM] = true;
1385 }
1386
1387 if (Frame_Number == 0) {
1389 if (frame_type != EDHCFrameHeaderDataType::c_ONSEN_TRG) {
1390 if (!m_formatBonnDAQ) {
1391 if (!(m_suppressErrorMask[c_nrONSEN_TRG_FIRST])) B2WARNING("First frame is not a ONSEN Trigger frame");
1392 m_errorMask[c_nrONSEN_TRG_FIRST] = true;
1393 }
1394 }
1395 } else { // (Frame_Number != 0 &&
1397 if (frame_type == EDHCFrameHeaderDataType::c_ONSEN_TRG) {
1398 if (!(m_suppressErrorMask[c_nrONSEN_TRG_FIRST])) B2WARNING("More than one ONSEN Trigger frame");
1399 m_errorMask[c_nrONSEN_TRG_FIRST] = true;
1400 }
1401 }
1402
1403 if (!m_formatBonnDAQ) {
1404 if (Frame_Number == 1) {
1406 if (frame_type != EDHCFrameHeaderDataType::c_DHC_START) {
1407 if (!(m_suppressErrorMask[c_nrDHC_START_SECOND])) B2WARNING("Second frame is not a DHC start of subevent frame");
1408 m_errorMask[c_nrDHC_START_SECOND] = true;
1409 }
1410 } else { // (Frame_Number != 0 &&
1412 if (frame_type == EDHCFrameHeaderDataType::c_DHC_START) {
1413 if (!(m_suppressErrorMask[c_nrDHC_START_SECOND])) B2WARNING("More than one DHC start of subevent frame");
1414 m_errorMask[c_nrDHC_START_SECOND] = true;
1415 }
1416 }
1417 }
1418
1419 if (Frame_Number == Frames_in_event - 1) {
1421 if (frame_type != EDHCFrameHeaderDataType::c_DHC_END) {
1422 if (!(m_suppressErrorMask[c_nrDHC_END_MISS])) B2WARNING("Last frame is not a DHC end of subevent frame");
1423 m_errorMask[c_nrDHC_END_MISS] = true;
1424 }
1425
1427 if (countedDHEStartFrames != countedDHEEndFrames || countedDHEStartFrames != nr_active_dhe) {
1428 if (!(m_suppressErrorMask[c_nrDHE_ACTIVE]) || !(m_suppressErrorMask[c_nrDHE_START_WO_END])
1429 || !(m_suppressErrorMask[c_nrDHE_END_WO_START])) {
1430 B2WARNING("The number of DHE Start/End does not match the number of active DHE in DHC Header!");
1431 B2DEBUG(29, "The number of DHE Start/End does not match the number of active DHE in DHC Header! Header: " << nr_active_dhe <<
1432 " Start: " << countedDHEStartFrames << " End: " << countedDHEEndFrames << " Mask: $" << hex << mask_active_dhe << " in Event Nr " <<
1433 eventNrOfThisFrame);
1434 }
1435 if (countedDHEStartFrames == countedDHEEndFrames) m_errorMask[c_nrDHE_ACTIVE] = true;
1436 if (countedDHEStartFrames > countedDHEEndFrames) m_errorMask[c_nrDHE_START_WO_END] = true;
1437 if (countedDHEStartFrames < countedDHEEndFrames) m_errorMask[c_nrDHE_END_WO_START] = true;
1438 }
1439
1440 } else { // (Frame_Number != Frames_in_event - 1 &&
1442 if (frame_type == EDHCFrameHeaderDataType::c_DHC_END) {
1443 if (!(m_suppressErrorMask[c_nrDHC_END_DBL])) B2WARNING("More than one DHC end of subevent frame");
1444 m_errorMask[c_nrDHC_END_DBL] = true;
1445 }
1446 }
1447
1448 if (!m_formatBonnDAQ) {
1450 if (Frame_Number == 2 && nr_active_dhe != 0 && frame_type != EDHCFrameHeaderDataType::c_DHE_START) {
1451 if (!(m_suppressErrorMask[c_nrDHE_START_THIRD])) B2WARNING("Third frame is not a DHE start frame");
1452 m_errorMask[c_nrDHE_START_THIRD] = true;
1453 }
1454 }
1455
1456 if (frame_type != EDHCFrameHeaderDataType::c_ONSEN_ROI && frame_type != EDHCFrameHeaderDataType::c_ONSEN_TRG) {
1457 // actually, they should not be within Start and End, but better be sure.
1458 countedBytesInDHC += len;
1459 countedBytesInDHE += len;
1460 }
1461 B2DEBUG(29, "DHC/DHE $" << hex << countedBytesInDHC << ", $" << hex << countedBytesInDHE);
1462}
1463
1465{
1467 const int lut[32] = {
1468 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4,
1469 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5
1470 };
1471 return lut[i & 0x1F];
1472}
1473
@ c_ErrorIfAlreadyRegistered
If the object/array was already registered, produce an error (aborting initialisation).
Definition: DataStore.h:72
Base class for Modules.
Definition: Module.h:72
void setDescription(const std::string &description)
Sets the description of the module.
Definition: Module.cc:214
void setPropertyFlags(unsigned int propertyFlags)
Sets the flags for the module properties.
Definition: Module.cc:208
void setReturnValue(int value)
Sets the return value for this module as integer.
Definition: Module.cc:220
@ c_ParallelProcessingCertified
This module can be run in parallel processing mode safely (All I/O must be done through the data stor...
Definition: Module.h:80
void setErrorMask(const PXDErrorFlags &mask)
Set Error bit mask This should be the OR of error masks of all sub-objects (DHC, DHE)
void setGatedFlag(bool gm)
set gating info from the DHC END
PXDDAQDHEStatus & newDHE(Args &&... params)
Add new DHE information.
void setGatedHER(bool isher)
set HER/LER gating info from the DHC END
PXDDAQDHEStatus & dhe_back()
Returns PXDDAQDHEStatus for last DHE.
void setEndErrorInfo(uint32_t e)
set errorinfo from the DHC END
size_t dhe_size() const
Returns number of DHEs.
void setCounters(uint32_t raw, uint32_t red)
Set Data counters for reduction calculation.
PXDDAQDHPStatus & newDHP(Args &&... params)
New DHP information.
void setDHPFoundMask(unsigned short dhpmask)
set Mask for found DHPs with valid data
void setErrorMask(const PXDErrorFlags &mask)
Set Error bit mask.
auto addCM(PXDDAQDHPComMode &daqcm)
Add Common Mode information.
PXDDAQDHPStatus & dhp_back()
Returns PXDDAQDHPStatus for the last DHP.
void setEndErrorInfo(uint32_t e)
set erroinfo from the DHE END
void setCounters(uint32_t raw, uint32_t red)
Set Data counters for reduction calculation.
void setTruncated(void)
set Truncation
The PXD DAQ Packet Status class.
void setErrorMask(const PXDErrorFlags &mask)
Set Error bit mask This should be the OR of error masks of all sub-objects (DHC, DHE)
size_t dhc_size() const
Returns number of DHCs.
PXDDAQDHCStatus & dhc_back()
Returns PXDDAQDHCStatus for last DHC.
PXDDAQDHCStatus & newDHC(Args &&... params)
Add new DHC information.
static void map_rc_to_uv_IF_OB(unsigned int &row_u, unsigned int &col_v, const unsigned int dhp_id, const unsigned int dhe_ID)
Maps row/col of inner forward (IF) and outer backward (OB) modules of the PXD to U/V cell.
static void map_rc_to_uv_IB_OF(unsigned int &row_u, unsigned int &col_v, const unsigned int dhp_id, const unsigned int dhe_ID)
Maps row/cols of inner backward (IB) and outer forward (OF) modules of the PXD to U/V cell.
std::string m_PXDRawHitsName
The name of the StoreArray of PXDRawHits to be generated.
void initialize() override final
Initialize the module.
unsigned long m_meta_experiment
Experiment from MetaInfo.
PXDError::PXDErrorFlags m_errorMaskEvent
Error Mask set per packet / event.
StoreObjPtr< PXDDAQStatus > m_storeDAQEvtStats
Output array for DAQ Status.
bool m_doNotStore
Only unpack, but Do Not Store anything to file.
StoreArray< RawPXD > m_storeRawPXD
Input array for PXD Raw.
bool m_forceNoMapping
Force No Mapping even if DHH bit is requesting it.
std::string m_PXDDAQEvtStatsName
The name of the StoreObjPtr of PXDDAQStatus to be generated.
static void dump_roi(void *data, unsigned int frame_len)
dump to a file, helper function for debugging.
PXDError::PXDErrorFlags m_suppressErrorMask
Mask for suppressing selected error messages.
bool m_formatBonnDAQ
flag ONSEN or BonnDAQ format
unsigned int m_errorCounter[PXDError::ONSEN_MAX_TYPE_ERR]
Error counters.
PXDUnpackerOTModule()
Constructor defining the parameters.
StoreArray< PXDRawROIs > m_storeROIs
Output array for Raw ROIs.
unsigned int m_sendunfiltered
counter for send unfiltered
PXDError::PXDErrorFlags m_errorMaskDHC
Error Mask set per packet / DHC.
PXDError::PXDErrorFlags m_errorMaskPacket
Error Mask set per packet / packet.
std::string m_RawPXDsName
The name of the StoreArray of processed RawPXDs.
void unpack_dhp(void *data, unsigned int len, unsigned int dhe_first_readout_frame_lo, unsigned int dhe_ID, unsigned dhe_DHPport, unsigned dhe_reformat, VxdID vxd_id, PXDDAQPacketStatus &daqpktstat)
Unpack DHP data within one DHE frame.
void terminate() override final
Terminate the module.
StoreObjPtr< EventMetaData > m_eventMetaData
Input ptr for EventMetaData.
int m_last_dhp_readout_frame_lo[4]
some workaround check for continouous frame ids
unsigned long m_meta_subrun_nr
Subrun Number from MetaInfo.
void event() override final
do the unpacking
StoreArray< PXDRawAdc > m_storeRawAdc
Output array for Raw Adcs.
unsigned long m_meta_event_nr
Event Number from MetaInfo.
PXDError::PXDErrorFlags m_errorSkipPacketMask
Mask for error which stop package unpacking directly.
static int nr5bits(int i)
helper function to "count" nr of set bits within lower 5 bits.
void unpack_fce(unsigned short *data, unsigned int length, VxdID vxd_id)
Unpack DHP/FCE data within one DHE frame Not fully implemented as cluster format not 100% fixed.
std::string m_PXDRawAdcsName
The name of the StoreArray of PXDRawAdcs to be generated.
unsigned long m_meta_run_nr
Run Number from MetaInfo.
bool m_continueOnError
flag continue unpacking of frames even after error (for debugging)
unsigned int m_notaccepted
counter for not accepted events... should not happen TODO discussion ongoing with DAQ group
unsigned int m_meta_sec
Time(Tag) from MetaInfo, seconds (masked to lower bits)
void unpack_dhp_raw(void *data, unsigned int len, unsigned int dhe_ID, unsigned dhe_DHPport, VxdID vxd_id)
Unpack DHP RAW data within one DHE frame (pedestals, etc)
PXDError::PXDErrorFlags m_criticalErrorMask
Critical error mask which defines return value of task.
unsigned int m_sendrois
counter for send debug rois
static void dump_dhp(void *data, unsigned int frame_len)
dump to a file, helper function for debugging.
void unpack_rawpxd(RawPXD &px, int inx)
Unpack one event (several frames) stored in RawPXD object.
unsigned long long int m_meta_time
Time(Tag) from MetaInfo.
unsigned int m_maxDHPFrameDiff
Maximum DHP frame difference until error is reported.
PXDError::PXDErrorFlags m_errorMask
Error Mask set per packet / frame.
unsigned int m_unpackedEventsCount
Event counter.
StoreArray< PXDRawHit > m_storeRawHits
Output array for Raw Hits.
void unpack_dhc_frame(void *data, const int len, const int Frame_Number, const int Frames_in_event, PXDDAQPacketStatus &daqpktstat)
Unpack one frame (within an event).
bool m_forceMapping
Force Mapping even if DHH bit is not requesting it.
unsigned int m_meta_ticks
Time(Tag) from MetaInfo, Ticks of 127MHz.
bool m_verbose
give verbose unpacking information
PXDError::PXDErrorFlags m_errorMaskDHE
Error Mask set per packet / DHE.
std::string m_PXDRawROIsName
The name of the StoreArray of PXDRawROIs to be generated.
DHC frame wrapper class.
const dhc_ghost_frame * data_ghost_frame
data_ghost_frame
unsigned int getEventNrLo(void) const
get event nr lo (from data)
const dhc_end_frame * data_dhc_end_frame
data_dhc_end_frame
unsigned int getFixedSize(void)
get fixed size
int getFrameType(void)
get type of frame
const dhc_dhe_start_frame * data_dhe_start_frame
data_dhe_start_frame
void set(const void *d, unsigned int t)
set data and type (and length to 0)
const dhc_start_frame * data_dhc_start_frame
data_dhc_start_frame
const dhc_direct_readout_frame * data_direct_readout_frame
data_direct_readout_frame
const dhc_dhe_end_frame * data_dhe_end_frame
data_dhe_end_frame
void check_padding(PXDErrorFlags &errormask)
check padding and return it
const dhc_onsen_roi_frame * data_onsen_roi_frame
data_onsen_roi_frame
const dhc_direct_readout_frame_raw * data_direct_readout_frame_raw
data_direct_readout_frame_raw
const dhc_commode_frame * data_commode_frame
data_commode_frame
void check_crc(PXDErrorFlags &errormask, bool ignore_crc_flag=false)
check crc and return it
const dhc_onsen_trigger_frame * data_onsen_trigger_frame
data_onsen_trigger_frame
The Raw PXD class.
Definition: RawPXD.h:27
virtual int * data(void)
get pointer to data
Definition: RawPXD.cc:81
virtual int size() const
get size of buffer in 32 Bit words
Definition: RawPXD.cc:76
Class to uniquely identify a any structure of the PXD and SVD.
Definition: VxdID.h:33
Class to store variables with their name which were sent to the logging service.
void addParam(const std::string &name, T &paramVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
Definition: Module.h:559
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:649
std::tuple< uint8_t, uint16_t, uint8_t > PXDDAQDHPComMode
tuple of Chip ID (2 bit), Row (10 bit), Common Mode (6 bit)
Namespace to encapsulate code needed for simulation and reconstrucion of the PXD.
boost::endian::big_uint32_t ubig32_t
define alias ubig32_t
boost::endian::big_uint16_t ubig16_t
define alias ubig16_t
Abstract base class for different kinds of events.
STL namespace.
unsigned int getDHEId(void) const
get DHE Id (from word0)
unsigned int get_words(void) const
get words
unsigned int getDHEId(void) const
get DHE Id
unsigned int getErrorInfo(void) const
get error info
unsigned int getDHEId(void) const
get DHE Id (from word0)
unsigned short getEventNrLo(void) const
get trigger_nr_lo
unsigned short getTriggerGate(void) const
trigger gate (updated to 8 bit, before 10!)
unsigned short getStartFrameNr(void) const
last DHP frame before trigger
unsigned short getEventNrHi(void) const
get trigger_nr_hi
unsigned int getActiveDHPMask(void) const
get Active DHP Mask (from word0)
bool getDataReformattedFlag(void) const
get DataReformattedFlag (from word0)
unsigned short getDHEId(void) const
get DHE Id (from word0)
unsigned short getDHPPort(void) const
get DHP Port (from word0)
void print(void) const
print
unsigned int get_words(void) const
get words
bool isFakedData(void) const
is faked data
unsigned int get_dhc_id(void) const
get dhc id (from word0)
unsigned int getErrorInfo(void) const
get error info
DHC frame header word data struct.
unsigned short getFrameType(void) const
get type of frame
unsigned short getErrorFlag(void) const
get error flag
unsigned short getDHEId(void) const
get DHE Id (from word0)
unsigned short getDHPPort(void) const
get DDHP port (from word0)
unsigned int check_inner_crc(PXDErrorFlags &, unsigned int) const
check inner crc (currently not implemented/needed)
void check_error(PXDErrorFlags &errormask, int length, bool ignore_inv_size_flag=false) const
check error and return error mask
int getMinSize(void) const
4 byte header, ROIS (n*8), 4 byte copy of inner CRC, 4 byte outer CRC
unsigned short get_subrun1(void) const
get subrun1 (from trigtag1)
unsigned int get_trig_nr1(void) const
get trignr1
bool is_SendUnfiltered(void) const
is sendUnfiltered
bool is_SendROIs(void) const
is sendROIs
void check_error(PXDErrorFlags &errormask, bool ignore_datcon_flag=false, bool ignore_hltroi_magic_flag=false, bool ignore_merger_mm_flag=false) const
check error and return error mask
unsigned short get_run2(void) const
get run2 (from trigtag2)
bool is_fake_datcon(void) const
is fake datcon
unsigned short get_experiment1(void) const
get experiment1 (from trigtag1)
unsigned int get_trig_nr2(void) const
get trignr2
unsigned short get_experiment2(void) const
get experiment2
unsigned short get_subrun2(void) const
get subrun2 (from trigtag2)
bool is_Accepted(void) const
is accepted
unsigned short get_run1(void) const
get run1 (from trigtag1)
void print(void) const
print
unsigned short get_gated_isher(void) const
get gated_isher (from word0)
unsigned short get_subrun(void) const
get subrun (from run_subrun)
unsigned short get_run(void) const
get run (from run_subrun)
unsigned short get_dhc_id(void) const
get dhc_id (from word0)
const ubig16_t time_tag_hi
time_tag_hi
const ubig16_t time_tag_mid
time_tag_mid
bool isFakedData(void) const
isFakedData
unsigned short getEventNrLo(void) const
get trigger_nr_lo
unsigned short get_experiment(void) const
get experiment (from exp_run)
unsigned short get_gated_flag(void) const
get gated_flag (from word0)
unsigned short get_active_dhe_mask(void) const
get active_dhe_mask (from word0)
const ubig16_t time_tag_lo_and_type
time_tag_lo_and_type
unsigned short getEventNrHi(void) const
get trigger_nr_hi