9 #include <trg/top/modules/trgtopUnpacker/trgtopUnpackerModule.h>
30 return std::string(
"1.00");
38 :
Module::
Module(), m_eventNumber(0), m_trigType(0), m_nodeId(0), m_nWords(0), m_reportedAlreadyRun_1(false),
39 m_reportedAlreadyRun_2(false)
44 std::string desc =
"TRGTOPUnpackerModule(" +
version() +
")";
48 B2DEBUG(20,
"TRGTOPUnpacker: Constructor done.");
52 addParam(
"overrideControlBits", m_overrideControlBits,
53 "Override control bits in data",
59 TRGTOPUnpackerModule::~TRGTOPUnpackerModule()
66 m_TRGTOPCombinedT0DecisionArray.registerInDataStore();
68 m_TRGTOPSlotTimingArray.registerInDataStore();
79 m_reportedAlreadyRun_2 =
false;
87 for (
int i = 0; i < raw_trgarray.
getEntries(); i++) {
90 if (raw_trgarray[i]->GetMaxNumOfCh(0) == 48) {
m_pciedata =
true; }
91 else if (raw_trgarray[i]->GetMaxNumOfCh(0) == 4) {
m_pciedata =
false; }
92 else { B2FATAL(
"TRGTOPUnpackerModule: Invalid value of GetMaxNumOfCh from raw data: " <<
LogVar(
"Number of ch: ", raw_trgarray[i]->GetMaxNumOfCh(0))); }
102 node_id = 0x12000001;
107 for (
int j = 0; j < raw_trgarray[i]->GetNumEntries(); j++) {
109 m_nodeId = raw_trgarray[i]->GetNodeID(j);
113 int numberOfChannels = raw_trgarray[i]->GetMaxNumOfCh(i);
117 for (
int channel = 0; channel < numberOfChannels; channel++) {
119 if (channel != ch_id_1 && channel != ch_id_2)
continue;
121 m_nWords = raw_trgarray[i]->GetDetectorNwords(j, channel);
128 m_eventNumber = raw_trgarray[i]->GetEveNo(j);
162 int rvcL1 = rdat[2] & 0x7ff;
165 int eventNumberL1 = (rdat[2] >> 12) & 0xfffff;
170 bool dataFormatKnown =
false;
173 int numberOfWindows = -1;
175 int dataFormatVersionExpected = -1;
176 int revoClockDeltaExpected = 4;
177 int cntr127DeltaExpected = 4;
189 dataFormatKnown =
true;
190 dataFormatVersionExpected = 0;
193 numberOfWindows = 24;
194 dataFormatKnown =
true;
195 dataFormatVersionExpected = 2;
198 numberOfWindows = 48;
199 dataFormatKnown =
true;
200 dataFormatVersionExpected = 1;
203 numberOfWindows = 48;
204 dataFormatKnown =
true;
205 dataFormatVersionExpected = 4;
208 numberOfWindows = 96;
209 dataFormatKnown =
true;
210 dataFormatVersionExpected = 5;
213 if (!dataFormatKnown) {
215 B2INFO(
"Unknown data format / error / exiting. This condition is reported only once per run.");
240 unsigned int testPattern;
242 int revoClockLast = -1;
243 int cntr127Last = -1;
246 unsigned int errorCountEvent = 0;
248 bool performBufferAnalysis =
true;
249 bool reportAllErrors =
true;
250 bool reportSummaryErrors =
true;
253 int counterDummyWindows = 0;
254 unsigned int testPatternDummyEvent = 0xbbbb;
255 for (
int iWindow = 0; iWindow < numberOfWindows; iWindow++) {
256 int index = iWindow * windowSize + 3;
257 testPattern = (rdat[index] >> 16) & 0xffff;
258 if (testPattern == testPatternDummyEvent) {
259 counterDummyWindows++;
262 if (!m_overrideControlBits) {
265 testPattern = (rdat[index + 2] >> 29) & 0x7;
266 if (testPattern & 0x1) performBufferAnalysis =
false;
267 if (testPattern & 0x2) reportAllErrors =
false;
268 if (testPattern & 0x4) reportSummaryErrors =
false;
273 if (counterDummyWindows == numberOfWindows) {
274 performBufferAnalysis =
false;
276 if (counterDummyWindows != 0) {
277 if (reportAllErrors) B2ERROR(
"Corrupted data? numberOfWindows = " << numberOfWindows <<
", counterDummyWindows = " <<
278 counterDummyWindows);
279 performBufferAnalysis =
false;
389 if (performBufferAnalysis) {
393 int slotSegmentLast[8];
395 int otherInformationLast[8];
398 int combinedT0RVC2GDLLast;
401 for (
int iWindow = 0; iWindow < numberOfWindows; iWindow++) {
405 int clockCycle = iWindow * 4;
408 unsigned int errorCountWindow = 0;
411 int index = iWindow * windowSize + 3;
413 unsigned int testPatternExpected = 0;
414 if (dataFormatVersionExpected == 1) testPatternExpected = 0xbbba;
415 else if (dataFormatVersionExpected >= 2) testPatternExpected = 0xdddd;
417 testPattern = (rdat[index] >> 16) & 0xffff;
419 if (testPattern != testPatternExpected) {
420 if (reportAllErrors) B2ERROR(
"An unexpected test pattern: " << std::hex << testPattern << std::dec <<
", window " << iWindow <<
421 ", index = " << index);
425 int dataFormatVersionNow = (rdat[index] >> 11) & 0x1f;
427 if (dataFormatVersionNow == 3 && dataFormatVersionExpected == 2) {
428 dataFormatVersionExpected = 3;
430 if (dataFormatVersionNow == 4 && dataFormatVersionExpected == 2) {
431 dataFormatVersionExpected = 4;
433 if (dataFormatVersionNow == 5) {
434 dataFormatVersionExpected = 5;
437 if (dataFormatVersionNow != dataFormatVersionExpected) {
438 if (reportAllErrors) {
439 if (!m_reportedAlreadyRun_2) {
440 B2ERROR(
"An unexpected data format version: " << dataFormatVersionNow <<
", window " << iWindow <<
", index = " <<
442 m_reportedAlreadyRun_2 =
true;
449 int revoClockNow = rdat[index] & 0x7ff;
452 if (revoClockLast != -1) {
454 int revoClockDeltaNow = revoClockNow - revoClockLast;
455 if (revoClockDeltaNow != revoClockDeltaExpected) {
456 if (revoClockDeltaNow != -1276) {
457 if (reportAllErrors) B2INFO(
"rvc changed by an unexpected number of units (2): " << revoClockDeltaNow <<
", last rvc = " <<
459 ", current rvc = " << revoClockNow <<
", window " << iWindow <<
", index = " << index);
464 if (revoClockNow > 1279) {
465 if (reportAllErrors) B2ERROR(
"An unexpected rvc value = " << revoClockNow <<
", window " << iWindow <<
", index = " << index);
468 revoClockLast = revoClockNow;
470 int cntr127Now = (rdat[index + 1] >> 16) & 0xffff;
473 if (cntr127Last != -1) {
475 int cntr127DeltaNow = cntr127Now - cntr127Last;
476 if (cntr127DeltaNow != cntr127DeltaExpected) {
478 if (cntr127DeltaNow != 65444 && cntr127DeltaNow != -65532) {
479 if (reportAllErrors) B2INFO(
"cntr127 changed by an unexpected number of units (2): " << cntr127DeltaNow <<
", cntr127 last = " <<
481 ", cntr127 now = " << cntr127Now <<
", window " << iWindow <<
", index = " << index + 1);
486 cntr127Last = cntr127Now;
494 int otherInformation[8];
498 int combinedT0 = rdat[index + 2] & 0x3ffff;
499 int combinedT0RVC2GDL = (rdat[index + 2] >> 18) & 0x7ff;
500 int combinedT0ClockCycle = clockCycle;
502 slotT0[0] = (rdat[index + 4] >> 16) & 0xffff;
503 slotT0[1] = (rdat[index + 4]) & 0xffff;
504 slotT0[2] = (rdat[index + 5] >> 16) & 0xffff;
505 slotT0[3] = (rdat[index + 5]) & 0xffff;
506 slotT0[4] = (rdat[index + 6] >> 16) & 0xffff;
507 slotT0[5] = (rdat[index + 6]) & 0xffff;
508 slotT0[6] = (rdat[index + 7] >> 16) & 0xffff;
509 slotT0[7] = (rdat[index + 7]) & 0xffff;
511 slotNHit[0] = (rdat[index + 8] >> 20) & 0x3ff;
512 slotNHit[1] = (rdat[index + 8] >> 10) & 0x3ff;
513 slotNHit[2] = (rdat[index + 8]) & 0x3ff;
515 slotNHit[3] = (rdat[index + 9] >> 20) & 0x3ff;
516 slotNHit[4] = (rdat[index + 9] >> 10) & 0x3ff;
517 slotNHit[5] = (rdat[index + 9]) & 0x3ff;
519 slotNHit[6] = (rdat[index + 10] >> 10) & 0x3ff;
520 slotNHit[7] = (rdat[index + 10]) & 0x3ff;
522 slotSegment[0] = (rdat[index + 11] >> 28) & 0xf;
523 slotSegment[1] = (rdat[index + 11] >> 24) & 0xf;
524 slotSegment[2] = (rdat[index + 11] >> 20) & 0xf;
525 slotSegment[3] = (rdat[index + 11] >> 16) & 0xf;
526 slotSegment[4] = (rdat[index + 11] >> 12) & 0xf;
527 slotSegment[5] = (rdat[index + 11] >> 8) & 0xf;
528 slotSegment[6] = (rdat[index + 11] >> 4) & 0xf;
529 slotSegment[7] = (rdat[index + 11] >> 0) & 0xf;
532 otherInformation[0] = (rdat[index + 12] >> 16) & 0xffff;
533 otherInformation[1] = (rdat[index + 12]) & 0xffff;
534 otherInformation[2] = (rdat[index + 13] >> 16) & 0xffff;
535 otherInformation[3] = (rdat[index + 13]) & 0xffff;
536 otherInformation[4] = (rdat[index + 14] >> 16) & 0xffff;
537 otherInformation[5] = (rdat[index + 14]) & 0xffff;
538 otherInformation[6] = (rdat[index + 15] >> 16) & 0xffff;
539 otherInformation[7] = (rdat[index + 15]) & 0xffff;
545 if (combinedT0 != combinedT0Last ||
546 combinedT0RVC2GDL != combinedT0RVC2GDLLast
556 combinedT0ClockCycle,
562 m_TRGTOPCombinedT0DecisionArray.appendNew(combinedT0Decision);
577 combinedT0Last = combinedT0;
578 combinedT0RVC2GDLLast = combinedT0RVC2GDL;
584 for (
int i = 0; i < 8; i++) {
586 if (otherInformation[i] != otherInformationLast[i]) {
588 int slotOther = i + 1;
591 2 * otherInformation[i],
602 m_TRGTOPSlotTimingArray.appendNew(slotTiming);
604 otherInformationLast[i] = otherInformation[i];
613 if (channel == 0) slotNow = 9;
615 for (
int i = 0; i < 8; i++) {
617 if (slotT0[i] != slotT0Last[i] ||
618 slotNHit[i] != slotNHitLast[i] ||
619 slotSegment[i] != slotSegmentLast[i]) {
654 m_TRGTOPSlotTimingArray.appendNew(slotTiming);
668 m_TRGTOPSlotTimingArray.appendNew(slotTiming);
675 slotT0Last[i] = slotT0[i];
676 slotNHitLast[i] = slotNHit[i];
677 slotSegmentLast[i] = slotSegment[i];
686 combinedT0Last = combinedT0;
687 for (
int i = 0; i < 8; i++) {
688 slotT0Last[i] = slotT0[i];
689 slotNHitLast[i] = slotNHit[i];
690 slotSegmentLast[i] = slotSegment[i];
691 otherInformationLast[i] = otherInformation[i];
693 combinedT0Last = combinedT0;
694 combinedT0RVC2GDLLast = combinedT0RVC2GDL;
703 if (reportSummaryErrors) {
704 if (errorCountEvent != 0) {
705 B2INFO(
"Number of instances of unexpected data diagnozed during unpacking = " << errorCountEvent);
void setDescription(const std::string &description)
Sets the description of the module.
void setPropertyFlags(unsigned int propertyFlags)
Sets the flags for the module properties.
@ c_ParallelProcessingCertified
This module can be run in parallel processing mode safely (All I/O must be done through the data stor...
The Raw TOP class Class for RawCOPPER class data taken by TOP Currently, this class is almost same as...
Accessor to arrays stored in the data store.
int getEntries() const
Get the number of objects in the array.
virtual void readDAQEvent(RawTRG *, int, int)
Read data from TRG DAQ.
bool m_reportedAlreadyRun_1
PCIe40 data or copper data.
bool m_pciedata
N words in raw data.
int m_nodeId
Trigger type.
virtual void initialize() override
Initialize the Module.
int m_nWords
Our read-out ID.
virtual void event() override
This method is the core of the module.
virtual void endRun() override
This method is called if the current run ends.
virtual void terminate() override
This method is called at the end of the event processing.
virtual void beginRun() override
Called when entering a new run.
virtual void unpackT0Decisions(int *, int)
Unpacker main function.
TRGTOPUnpackerModule()
Constructor: Sets the description, the properties and the parameters of the module.
int m_trigType
Event number (according to L1/global)
std::string version() const
returns version of TRGGDLUnpackerModule.
Class to store variables with their name which were sent to the logging service.
void addParam(const std::string &name, T ¶mVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
int GetDetectorNwords(int n, int finesse_num)
get Detector buffer length
int * GetDetectorBuffer(int n, int finesse_num)
get Detector buffer
Abstract base class for different kinds of events.