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",
65TRGTOPUnpackerWaveformModule::~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.");
258 bool performBufferAnalysis =
true;
259 bool reportAllErrors =
true;
263 int counterDummyWindows = 0;
264 unsigned int testPatternDummyEvent = 0xbbbb;
265 for (
int iWindow = 0; iWindow < numberOfWindows; iWindow++) {
266 int index = iWindow * windowSize + 3;
268 unsigned int testPattern = (rdat[index] >> 16) & 0xffff;
269 if (testPattern == testPatternDummyEvent) {
270 counterDummyWindows++;
274 if (!m_overrideControlBits) {
277 testPattern = (rdat[index + 2] >> 29) & 0x7;
278 if (testPattern & 0x1) performBufferAnalysis =
false;
279 if (testPattern & 0x2) reportAllErrors =
false;
285 if (counterDummyWindows == numberOfWindows) {
286 performBufferAnalysis =
false;
288 if (counterDummyWindows != 0) {
289 if (reportAllErrors) B2ERROR(
"Corrupted data? numberOfWindows = " << numberOfWindows <<
", counterDummyWindows = " <<
290 counterDummyWindows);
291 performBufferAnalysis =
false;
397 if (performBufferAnalysis) {
399 for (
int iWindow = 0; iWindow < numberOfWindows; iWindow++) {
400 int index = iWindow * windowSize + 3;
401 int dataFormatVersionNow = (rdat[index] >> 11) & 0x1f;
402 if (dataFormatVersionNow < 4)
return;
411 for (
int i = 0; i < 8; i++) {
414 if (channel == 0) slot = slot + 8;
416 auto* timeStampsSlotStore = m_TRGTOPWaveFormTimeStampsSlots.appendNew(slot, 4 * numberOfWindows);
418 int nActualTimeStamps = 0;
420 int firstActualTimeStampValue = -1;
421 int firstActualTimeStampClockCycle = -1;
424 for (
int iWindow = 0; iWindow < numberOfWindows; iWindow++) {
426 int clockCycle = iWindow * 4;
429 int index = iWindow * windowSize + 3;
433 int shift_data = i * 2;
435 int value1 = (rdat[index + 16 + shift_data] >> 16) & 0xffff;
436 int value2 = (rdat[index + 16 + shift_data]) & 0xffff;
437 int value3 = (rdat[index + 17 + shift_data] >> 16) & 0xffff;
438 int value4 = (rdat[index + 17 + shift_data]) & 0xffff;
445 auto* timeStampStore = m_TRGTOPWaveFormTimeStamps.appendNew(timeStamp1);
446 timeStampsSlotStore->addRelationTo(timeStampStore);
447 timeStampStore->addRelationTo(timeStampsSlotStore);
449 timeStampStore = m_TRGTOPWaveFormTimeStamps.appendNew(timeStamp2);
450 timeStampsSlotStore->addRelationTo(timeStampStore);
451 timeStampStore->addRelationTo(timeStampsSlotStore);
453 timeStampStore = m_TRGTOPWaveFormTimeStamps.appendNew(timeStamp3);
454 timeStampsSlotStore->addRelationTo(timeStampStore);
455 timeStampStore->addRelationTo(timeStampsSlotStore);
457 timeStampStore = m_TRGTOPWaveFormTimeStamps.appendNew(timeStamp4);
458 timeStampsSlotStore->addRelationTo(timeStampStore);
459 timeStampStore->addRelationTo(timeStampsSlotStore);
461 if (!timeStamp1.isEmptyClockCycle()) {
463 if (nActualTimeStamps == 1) {
464 firstActualTimeStampValue = value1;
465 firstActualTimeStampClockCycle = clockCycle;
470 if (!timeStamp2.isEmptyClockCycle()) {
472 if (nActualTimeStamps == 1) {
473 firstActualTimeStampValue = value2;
474 firstActualTimeStampClockCycle = clockCycle;
479 if (!timeStamp3.isEmptyClockCycle()) {
481 if (nActualTimeStamps == 1) {
482 firstActualTimeStampValue = value3;
483 firstActualTimeStampClockCycle = clockCycle;
488 if (!timeStamp4.isEmptyClockCycle()) {
490 if (nActualTimeStamps == 1) {
491 firstActualTimeStampValue = value4;
492 firstActualTimeStampClockCycle = clockCycle;
499 timeStampsSlotStore->setNumberOfActualTimeStamps(nActualTimeStamps);
500 timeStampsSlotStore->setFirstActualTimeStampValue(firstActualTimeStampValue);
501 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.