Skip to content

Commit 716da52

Browse files
dstoccosawenzel
authored andcommitted
Test the raw buffer
1 parent cf19cd9 commit 716da52

File tree

1 file changed

+62
-1
lines changed

1 file changed

+62
-1
lines changed

Detectors/MUON/MID/Raw/test/testRaw.cxx

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <vector>
2222
#include <map>
2323
#include "CommonDataFormat/InteractionRecord.h"
24+
#include "DetectorsRaw/HBFUtils.h"
2425
#include "DataFormatsMID/ColumnData.h"
2526
#include "MIDBase/DetectorParameters.h"
2627
#include "MIDBase/Mapping.h"
@@ -75,6 +76,66 @@ void doTest(const o2::mid::EventType& inEventType, const std::map<uint16_t, std:
7576
}
7677
}
7778

79+
BOOST_AUTO_TEST_CASE(RawBuffer)
80+
{
81+
std::vector<o2::InteractionRecord> HBIRVec;
82+
o2::raw::HBFUtils hbfUtils;
83+
o2::InteractionRecord irFrom = hbfUtils.getFirstIR();
84+
o2::InteractionRecord ir(5, 4);
85+
hbfUtils.fillHBIRvector(HBIRVec, irFrom, ir);
86+
std::vector<uint8_t> bytes;
87+
unsigned int memSize = 0;
88+
for (auto& hbIr : HBIRVec) {
89+
auto rdh = hbfUtils.createRDH<o2::header::RAWDataHeader>(hbIr);
90+
rdh.offsetToNext = (hbIr.orbit == ir.orbit) ? 0x2000 : rdh.headerSize;
91+
rdh.memorySize = (hbIr.orbit == ir.orbit) ? 0x1000 : rdh.headerSize;
92+
memSize = rdh.memorySize - rdh.headerSize;
93+
auto rdhBuf = reinterpret_cast<const uint8_t*>(&rdh);
94+
for (size_t ii = 0; ii < rdh.headerSize; ++ii) {
95+
bytes.emplace_back(rdhBuf[ii]);
96+
}
97+
for (size_t ii = 0; ii < rdh.memorySize - rdh.headerSize; ++ii) {
98+
bytes.emplace_back(ii);
99+
}
100+
for (size_t ii = 0; ii < rdh.offsetToNext - rdh.memorySize; ++ii) {
101+
bytes.emplace_back(0);
102+
}
103+
104+
if (bytes.size() < rdh.offsetToNext) {
105+
o2::mid::RawBuffer<uint8_t> rb;
106+
rb.setBuffer(bytes);
107+
BOOST_TEST(rb.getRDH()->word0 == rdh.word0);
108+
}
109+
}
110+
111+
o2::mid::RawBuffer<uint8_t> rb;
112+
size_t nHeaders = 0;
113+
rb.setBuffer(bytes);
114+
// Reads only the headers
115+
while (rb.nextHeader()) {
116+
++nHeaders;
117+
}
118+
BOOST_TEST(nHeaders == HBIRVec.size());
119+
120+
// Set buffer again after full reset
121+
rb.setBuffer(bytes, o2::mid::RawBuffer<uint8_t>::ResetMode::all);
122+
rb.next();
123+
BOOST_TEST(static_cast<int>(rb.next()) == 1);
124+
125+
if (!rb.hasNext(memSize - 1)) {
126+
// Set buffer but keep unconsumed
127+
rb.setBuffer(bytes);
128+
// This should come from the last unconsumed buffer
129+
BOOST_TEST(static_cast<int>(rb.next()) == 2);
130+
131+
for (int ibyte = 0; ibyte < memSize; ++ibyte) {
132+
rb.next();
133+
}
134+
// And this comes from the new buffer
135+
BOOST_TEST(static_cast<int>(rb.next()) == 3);
136+
}
137+
}
138+
78139
BOOST_AUTO_TEST_CASE(CRUUserLogicDecoder)
79140
{
80141
/// Event with just one link fired
@@ -132,7 +193,7 @@ BOOST_AUTO_TEST_CASE(LargeBufferSample)
132193
std::map<uint16_t, std::vector<o2::mid::ColumnData>> inData;
133194
// Big event that should pass the 8kB
134195
for (int irepeat = 0; irepeat < 150; ++irepeat) {
135-
uint16_t bc = 100 + irepeat;
196+
uint16_t bc = 1 + irepeat;
136197
for (int ide = 0; ide < o2::mid::detparams::NDetectionElements; ++ide) {
137198
// Since we have 1 RDH per GBT, we can put data only on 1 column
138199
int icol = 4;

0 commit comments

Comments
 (0)