9 #include <trg/top/modules/trgtopUnpackerWaveform/trgtopUnpackerWaveformModule.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 =
"TRGTOPUnpackerWaveformModule(" +
version() +
")" +
"Unpacks TOP TRG waveforms";
48 B2DEBUG(20,
"TRGTOPUnpackerWaveform: Constructor done.");
53 "name of TRGTOPWaveFormTimeStampsSlot store array", std::string(
""));
56 "name of TRGTOPWaveFormTimeStamp store array", std::string(
""));
58 addParam(
"overrideControlBits", m_overrideControlBits,
59 "Override control bits in data",
65 TRGTOPUnpackerWaveformModule::~TRGTOPUnpackerWaveformModule()
78 m_TRGTOPWaveFormTimeStampsSlots.registerRelationTo(m_TRGTOPWaveFormTimeStamps);
79 m_TRGTOPWaveFormTimeStamps.registerRelationTo(m_TRGTOPWaveFormTimeStampsSlots);
86 m_reportedAlreadyRun_2 =
false;
94 for (
int i = 0; i < raw_trgarray.
getEntries(); i++) {
97 if (raw_trgarray[i]->GetMaxNumOfCh(0) == 48) {
m_pciedata =
true; }
98 else if (raw_trgarray[i]->GetMaxNumOfCh(0) == 4) {
m_pciedata =
false; }
99 else { B2FATAL(
"TRGTOPUnpackerModule: Invalid value of GetMaxNumOfCh from raw data: " <<
LogVar(
"Number of ch: ", raw_trgarray[i]->GetMaxNumOfCh(0))); }
105 node_id = 0x10000001;
109 node_id = 0x12000001;
114 for (
int j = 0; j < raw_trgarray[i]->GetNumEntries(); j++) {
116 m_nodeId = raw_trgarray[i]->GetNodeID(j);
120 int numberOfChannels = raw_trgarray[i]->GetMaxNumOfCh(i);
124 for (
int channel = 0; channel < numberOfChannels; channel++) {
126 if (channel != ch_id_1 && channel != ch_id_2)
continue;
128 m_nWords = raw_trgarray[i]->GetDetectorNwords(j, channel);
135 m_eventNumber = raw_trgarray[i]->GetEveNo(j);
178 bool dataFormatKnown =
false;
181 int numberOfWindows = -1;
197 dataFormatKnown =
true;
201 numberOfWindows = 24;
202 dataFormatKnown =
true;
206 numberOfWindows = 48;
207 dataFormatKnown =
true;
211 numberOfWindows = 48;
212 dataFormatKnown =
true;
216 numberOfWindows = 96;
217 dataFormatKnown =
true;
221 if (!dataFormatKnown) {
223 B2INFO(
"Unknown data format / error / exiting. This condition is reported only once per run.");
248 unsigned int testPattern;
262 bool performBufferAnalysis =
true;
263 bool reportAllErrors =
true;
267 int counterDummyWindows = 0;
268 unsigned int testPatternDummyEvent = 0xbbbb;
269 for (
int iWindow = 0; iWindow < numberOfWindows; iWindow++) {
270 int index = iWindow * windowSize + 3;
271 testPattern = (rdat[index] >> 16) & 0xffff;
272 if (testPattern == testPatternDummyEvent) {
273 counterDummyWindows++;
277 if (!m_overrideControlBits) {
280 testPattern = (rdat[index + 2] >> 29) & 0x7;
281 if (testPattern & 0x1) performBufferAnalysis =
false;
282 if (testPattern & 0x2) reportAllErrors =
false;
288 if (counterDummyWindows == numberOfWindows) {
289 performBufferAnalysis =
false;
291 if (counterDummyWindows != 0) {
292 if (reportAllErrors) B2ERROR(
"Corrupted data? numberOfWindows = " << numberOfWindows <<
", counterDummyWindows = " <<
293 counterDummyWindows);
294 performBufferAnalysis =
false;
400 if (performBufferAnalysis) {
402 for (
int iWindow = 0; iWindow < numberOfWindows; iWindow++) {
403 int index = iWindow * windowSize + 3;
404 int dataFormatVersionNow = (rdat[index] >> 11) & 0x1f;
405 if (dataFormatVersionNow < 4)
return;
414 for (
int i = 0; i < 8; i++) {
417 if (channel == 0) slot = slot + 8;
419 auto* timeStampsSlotStore = m_TRGTOPWaveFormTimeStampsSlots.appendNew(slot, 4 * numberOfWindows);
421 int nActualTimeStamps = 0;
423 int firstActualTimeStampValue = -1;
424 int firstActualTimeStampClockCycle = -1;
427 for (
int iWindow = 0; iWindow < numberOfWindows; iWindow++) {
429 int clockCycle = iWindow * 4;
432 int index = iWindow * windowSize + 3;
436 int shift_data = i * 2;
438 int value1 = (rdat[index + 16 + shift_data] >> 16) & 0xffff;
439 int value2 = (rdat[index + 16 + shift_data]) & 0xffff;
440 int value3 = (rdat[index + 17 + shift_data] >> 16) & 0xffff;
441 int value4 = (rdat[index + 17 + shift_data]) & 0xffff;
448 auto* timeStampStore = m_TRGTOPWaveFormTimeStamps.appendNew(timeStamp1);
449 timeStampsSlotStore->addRelationTo(timeStampStore);
450 timeStampStore->addRelationTo(timeStampsSlotStore);
452 timeStampStore = m_TRGTOPWaveFormTimeStamps.appendNew(timeStamp2);
453 timeStampsSlotStore->addRelationTo(timeStampStore);
454 timeStampStore->addRelationTo(timeStampsSlotStore);
456 timeStampStore = m_TRGTOPWaveFormTimeStamps.appendNew(timeStamp3);
457 timeStampsSlotStore->addRelationTo(timeStampStore);
458 timeStampStore->addRelationTo(timeStampsSlotStore);
460 timeStampStore = m_TRGTOPWaveFormTimeStamps.appendNew(timeStamp4);
461 timeStampsSlotStore->addRelationTo(timeStampStore);
462 timeStampStore->addRelationTo(timeStampsSlotStore);
464 if (!timeStamp1.isEmptyClockCycle()) {
466 if (nActualTimeStamps == 1) {
467 firstActualTimeStampValue = value1;
468 firstActualTimeStampClockCycle = clockCycle;
473 if (!timeStamp2.isEmptyClockCycle()) {
475 if (nActualTimeStamps == 1) {
476 firstActualTimeStampValue = value2;
477 firstActualTimeStampClockCycle = clockCycle;
482 if (!timeStamp3.isEmptyClockCycle()) {
484 if (nActualTimeStamps == 1) {
485 firstActualTimeStampValue = value3;
486 firstActualTimeStampClockCycle = clockCycle;
491 if (!timeStamp4.isEmptyClockCycle()) {
493 if (nActualTimeStamps == 1) {
494 firstActualTimeStampValue = value4;
495 firstActualTimeStampClockCycle = clockCycle;
502 timeStampsSlotStore->setNumberOfActualTimeStamps(nActualTimeStamps);
503 timeStampsSlotStore->setFirstActualTimeStampValue(firstActualTimeStampValue);
504 timeStampsSlotStore->setFirstActualTimeStampClockCycle(firstActualTimeStampClockCycle);
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.
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.