|
21 | 21 | #include <vector> |
22 | 22 | #include <map> |
23 | 23 | #include "CommonDataFormat/InteractionRecord.h" |
| 24 | +#include "DetectorsRaw/HBFUtils.h" |
24 | 25 | #include "DataFormatsMID/ColumnData.h" |
25 | 26 | #include "MIDBase/DetectorParameters.h" |
26 | 27 | #include "MIDBase/Mapping.h" |
@@ -75,6 +76,66 @@ void doTest(const o2::mid::EventType& inEventType, const std::map<uint16_t, std: |
75 | 76 | } |
76 | 77 | } |
77 | 78 |
|
| 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 | + |
78 | 139 | BOOST_AUTO_TEST_CASE(CRUUserLogicDecoder) |
79 | 140 | { |
80 | 141 | /// Event with just one link fired |
@@ -132,7 +193,7 @@ BOOST_AUTO_TEST_CASE(LargeBufferSample) |
132 | 193 | std::map<uint16_t, std::vector<o2::mid::ColumnData>> inData; |
133 | 194 | // Big event that should pass the 8kB |
134 | 195 | for (int irepeat = 0; irepeat < 150; ++irepeat) { |
135 | | - uint16_t bc = 100 + irepeat; |
| 196 | + uint16_t bc = 1 + irepeat; |
136 | 197 | for (int ide = 0; ide < o2::mid::detparams::NDetectionElements; ++ide) { |
137 | 198 | // Since we have 1 RDH per GBT, we can put data only on 1 column |
138 | 199 | int icol = 4; |
|
0 commit comments