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",
59TRGTOPUnpackerModule::~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;
177 int revoClockDeltaExpected = 4;
179 int cntr127DeltaExpected = 4;
191 dataFormatKnown =
true;
192 dataFormatVersionExpected = 0;
195 numberOfWindows = 24;
196 dataFormatKnown =
true;
197 dataFormatVersionExpected = 2;
200 numberOfWindows = 48;
201 dataFormatKnown =
true;
202 dataFormatVersionExpected = 1;
205 numberOfWindows = 48;
206 dataFormatKnown =
true;
207 dataFormatVersionExpected = 4;
210 numberOfWindows = 96;
211 dataFormatKnown =
true;
212 dataFormatVersionExpected = 5;
215 if (!dataFormatKnown) {
217 B2INFO(
"Unknown data format / error / exiting. This condition is reported only once per run.");
242 unsigned int testPattern;
244 int revoClockLast = -1;
245 int cntr127Last = -1;
247 bool performBufferAnalysis =
true;
248 bool reportAllErrors =
true;
252 int counterDummyWindows = 0;
253 unsigned int testPatternDummyEvent = 0xbbbb;
254 for (
int iWindow = 0; iWindow < numberOfWindows; iWindow++) {
255 int index = iWindow * windowSize + 3;
256 testPattern = (rdat[index] >> 16) & 0xffff;
257 if (testPattern == testPatternDummyEvent) {
258 counterDummyWindows++;
261 if (!m_overrideControlBits) {
264 testPattern = (rdat[index + 2] >> 29) & 0x7;
265 if (testPattern & 0x1) performBufferAnalysis =
false;
266 if (testPattern & 0x2) reportAllErrors =
false;
272 if (counterDummyWindows == numberOfWindows) {
273 performBufferAnalysis =
false;
275 if (counterDummyWindows != 0) {
276 if (reportAllErrors) B2ERROR(
"Corrupted data? numberOfWindows = " << numberOfWindows <<
", counterDummyWindows = " <<
277 counterDummyWindows);
278 performBufferAnalysis =
false;
388 if (performBufferAnalysis) {
392 int slotSegmentLast[8];
394 int otherInformationLast[8];
397 int combinedT0RVC2GDLLast;
400 for (
int iWindow = 0; iWindow < numberOfWindows; iWindow++) {
404 int clockCycle = iWindow * 4;
407 unsigned int errorCountWindow = 0;
410 int index = iWindow * windowSize + 3;
412 unsigned int testPatternExpected = 0;
413 if (dataFormatVersionExpected == 1) testPatternExpected = 0xbbba;
414 else if (dataFormatVersionExpected >= 2) testPatternExpected = 0xdddd;
416 testPattern = (rdat[index] >> 16) & 0xffff;
418 if (testPattern != testPatternExpected) {
419 if (reportAllErrors) B2ERROR(
"An unexpected test pattern: " << std::hex << testPattern << std::dec <<
", window " << iWindow <<
420 ", index = " << index);
424 int dataFormatVersionNow = (rdat[index] >> 11) & 0x1f;
426 if (dataFormatVersionNow == 3 && dataFormatVersionExpected == 2) {
427 dataFormatVersionExpected = 3;
429 if (dataFormatVersionNow == 4 && dataFormatVersionExpected == 2) {
430 dataFormatVersionExpected = 4;
432 if (dataFormatVersionNow == 5) {
433 dataFormatVersionExpected = 5;
436 if (dataFormatVersionNow != dataFormatVersionExpected) {
437 if (reportAllErrors) {
438 if (!m_reportedAlreadyRun_2) {
439 B2ERROR(
"An unexpected data format version: " << dataFormatVersionNow <<
", window " << iWindow <<
", index = " <<
441 m_reportedAlreadyRun_2 =
true;
448 int revoClockNow = rdat[index] & 0x7ff;
451 if (revoClockLast != -1) {
453 int revoClockDeltaNow = revoClockNow - revoClockLast;
454 if (revoClockDeltaNow != revoClockDeltaExpected) {
455 if (revoClockDeltaNow != -1276) {
456 if (reportAllErrors) B2INFO(
"rvc changed by an unexpected number of units (2): " << revoClockDeltaNow <<
", last rvc = " <<
458 ", current rvc = " << revoClockNow <<
", window " << iWindow <<
", index = " << index);
463 if (revoClockNow > 1279) {
464 if (reportAllErrors) B2ERROR(
"An unexpected rvc value = " << revoClockNow <<
", window " << iWindow <<
", index = " << index);
467 revoClockLast = revoClockNow;
469 int cntr127Now = (rdat[index + 1] >> 16) & 0xffff;
472 if (cntr127Last != -1) {
474 int cntr127DeltaNow = cntr127Now - cntr127Last;
475 if (cntr127DeltaNow != cntr127DeltaExpected) {
477 if (cntr127DeltaNow != 65444 && cntr127DeltaNow != -65532) {
478 if (reportAllErrors) B2INFO(
"cntr127 changed by an unexpected number of units (2): " << cntr127DeltaNow <<
", cntr127 last = " <<
480 ", cntr127 now = " << cntr127Now <<
", window " << iWindow <<
", index = " << index + 1);
485 cntr127Last = cntr127Now;
493 int otherInformation[8];
497 int combinedT0 = rdat[index + 2] & 0x3ffff;
498 int combinedT0RVC2GDL = (rdat[index + 2] >> 18) & 0x7ff;
499 int combinedT0ClockCycle = clockCycle;
501 slotT0[0] = (rdat[index + 4] >> 16) & 0xffff;
502 slotT0[1] = (rdat[index + 4]) & 0xffff;
503 slotT0[2] = (rdat[index + 5] >> 16) & 0xffff;
504 slotT0[3] = (rdat[index + 5]) & 0xffff;
505 slotT0[4] = (rdat[index + 6] >> 16) & 0xffff;
506 slotT0[5] = (rdat[index + 6]) & 0xffff;
507 slotT0[6] = (rdat[index + 7] >> 16) & 0xffff;
508 slotT0[7] = (rdat[index + 7]) & 0xffff;
510 slotNHit[0] = (rdat[index + 8] >> 20) & 0x3ff;
511 slotNHit[1] = (rdat[index + 8] >> 10) & 0x3ff;
512 slotNHit[2] = (rdat[index + 8]) & 0x3ff;
514 slotNHit[3] = (rdat[index + 9] >> 20) & 0x3ff;
515 slotNHit[4] = (rdat[index + 9] >> 10) & 0x3ff;
516 slotNHit[5] = (rdat[index + 9]) & 0x3ff;
518 slotNHit[6] = (rdat[index + 10] >> 10) & 0x3ff;
519 slotNHit[7] = (rdat[index + 10]) & 0x3ff;
521 slotSegment[0] = (rdat[index + 11] >> 28) & 0xf;
522 slotSegment[1] = (rdat[index + 11] >> 24) & 0xf;
523 slotSegment[2] = (rdat[index + 11] >> 20) & 0xf;
524 slotSegment[3] = (rdat[index + 11] >> 16) & 0xf;
525 slotSegment[4] = (rdat[index + 11] >> 12) & 0xf;
526 slotSegment[5] = (rdat[index + 11] >> 8) & 0xf;
527 slotSegment[6] = (rdat[index + 11] >> 4) & 0xf;
528 slotSegment[7] = (rdat[index + 11] >> 0) & 0xf;
531 otherInformation[0] = (rdat[index + 12] >> 16) & 0xffff;
532 otherInformation[1] = (rdat[index + 12]) & 0xffff;
533 otherInformation[2] = (rdat[index + 13] >> 16) & 0xffff;
534 otherInformation[3] = (rdat[index + 13]) & 0xffff;
535 otherInformation[4] = (rdat[index + 14] >> 16) & 0xffff;
536 otherInformation[5] = (rdat[index + 14]) & 0xffff;
537 otherInformation[6] = (rdat[index + 15] >> 16) & 0xffff;
538 otherInformation[7] = (rdat[index + 15]) & 0xffff;
544 if (combinedT0 != combinedT0Last ||
545 combinedT0RVC2GDL != combinedT0RVC2GDLLast
555 combinedT0ClockCycle,
561 m_TRGTOPCombinedT0DecisionArray.appendNew(combinedT0Decision);
576 combinedT0Last = combinedT0;
577 combinedT0RVC2GDLLast = combinedT0RVC2GDL;
581 for (
int i = 0; i < 8; i++) {
583 if (otherInformation[i] != otherInformationLast[i]) {
585 int slotOther = i + 1;
588 2 * otherInformation[i],
599 m_TRGTOPSlotTimingArray.appendNew(slotTiming);
601 otherInformationLast[i] = otherInformation[i];
610 if (channel == 0) slotNow = 9;
612 for (
int i = 0; i < 8; i++) {
614 if (slotT0[i] != slotT0Last[i] ||
615 slotNHit[i] != slotNHitLast[i] ||
616 slotSegment[i] != slotSegmentLast[i]) {
651 m_TRGTOPSlotTimingArray.appendNew(slotTiming);
665 m_TRGTOPSlotTimingArray.appendNew(slotTiming);
672 slotT0Last[i] = slotT0[i];
673 slotNHitLast[i] = slotNHit[i];
674 slotSegmentLast[i] = slotSegment[i];
683 combinedT0Last = combinedT0;
684 for (
int i = 0; i < 8; i++) {
685 slotT0Last[i] = slotT0[i];
686 slotNHitLast[i] = slotNHit[i];
687 slotSegmentLast[i] = slotSegment[i];
688 otherInformationLast[i] = otherInformation[i];
690 combinedT0Last = combinedT0;
691 combinedT0RVC2GDLLast = combinedT0RVC2GDL;
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.