Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ namespace mid

enum class EventType {
Standard = 0,
Noise = 1,
Dead = 2
Calib = 1,
FET = 2
};
constexpr uint32_t NEvTypes = 3;

/// ROFRecord class encodes the trigger interaction record of given ROF and
/// the reference on the 1st object (digit, cluster etc) of this ROF in the data tree
Expand All @@ -41,6 +42,7 @@ struct ROFRecord {
ROFRecord() = default;
ROFRecord(const o2::InteractionRecord& intRecord, const EventType& evtType, size_t first, size_t nElements) : interactionRecord(intRecord), eventType(evtType), firstEntry(first), nEntries(nElements) {}
ROFRecord(const ROFRecord& other, size_t first, size_t nElements) : interactionRecord(other.interactionRecord), eventType(other.eventType), firstEntry(first), nEntries(nElements) {}
size_t getEndIndex() const { return firstEntry + nEntries; }

ClassDefNV(ROFRecord, 1);
};
Expand Down
96 changes: 57 additions & 39 deletions Detectors/CTF/test/test_ctf_io_mid.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ using namespace o2::mid;

BOOST_AUTO_TEST_CASE(CTFTest)
{
std::vector<ROFRecord> rofs;
std::vector<ColumnData> cols;
std::array<std::vector<ColumnData>, NEvTypes> colData{};
std::array<std::vector<ROFRecord>, NEvTypes> rofData{};
CTFHelper::TFData tfData;
// RS: don't understand why, but this library is not loaded automatically, although the dependencies are clearly
// indicated. What it more weird is that for similar tests of other detectors the library is loaded!
// Absence of the library leads to complains about the StreamerInfo and eventually segm.faul when appending the
Expand All @@ -40,27 +41,37 @@ BOOST_AUTO_TEST_CASE(CTFTest)
std::array<uint16_t, 5> pattern;
for (int irof = 0; irof < 1000; irof++) {
ir += 1 + gRandom->Integer(200);
uint8_t nch = 0, evtyp = gRandom->Integer(3);
while (nch == 0) {
nch = gRandom->Poisson(10);
}
auto start = cols.size();
for (int ich = 0; ich < nch; ich++) {
uint8_t deId = gRandom->Integer(128);
uint8_t columnId = gRandom->Integer(128);
for (int i = 0; i < 5; i++) {
pattern[i] = gRandom->Integer(0x7fff);
for (uint8_t evtyp = 0; evtyp < NEvTypes; evtyp++) {
if (gRandom->Rndm() > 0.8) {
continue; // sometimes skip some event types
}
uint8_t nch = 0;
while (nch == 0) {
nch = gRandom->Poisson(10);
}
cols.emplace_back(ColumnData{deId, columnId, pattern});
auto start = colData[evtyp].size();
for (int ich = 0; ich < nch; ich++) {
uint8_t deId = gRandom->Integer(128);
uint8_t columnId = gRandom->Integer(128);
for (int i = 0; i < 5; i++) {
pattern[i] = gRandom->Integer(0x7fff);
}
colData[evtyp].emplace_back(ColumnData{deId, columnId, pattern});
}
rofData[evtyp].emplace_back(ROFRecord{ir, EventType(evtyp), start, colData[evtyp].size() - start});
}
rofs.emplace_back(ROFRecord{ir, EventType(evtyp), start, cols.size() - start});
}
for (uint32_t i = 0; i < NEvTypes; i++) {
tfData.colData[i] = {colData[i].data(), colData[i].size()};
tfData.rofData[i] = {rofData[i].data(), rofData[i].size()};
}
tfData.buildReferences();

sw.Start();
std::vector<o2::ctf::BufferType> vec;
{
CTFCoder coder;
coder.encode(vec, rofs, cols); // compress
coder.encode(vec, tfData); // compress
}
sw.Stop();
LOG(INFO) << "Compressed in " << sw.CpuTime() << " s";
Expand Down Expand Up @@ -90,42 +101,49 @@ BOOST_AUTO_TEST_CASE(CTFTest)
LOG(INFO) << "Read back from tree in " << sw.CpuTime() << " s";
}

std::vector<ROFRecord> rofsD;
std::vector<ColumnData> colsD;
std::array<std::vector<ColumnData>, NEvTypes> colDataD{};
std::array<std::vector<ROFRecord>, NEvTypes> rofDataD{};

sw.Start();
const auto ctfImage = o2::mid::CTF::getImage(vec.data());
{
CTFCoder coder;
coder.decode(ctfImage, rofsD, colsD); // decompress
coder.decode(ctfImage, rofDataD, colDataD); // decompress
}
sw.Stop();
LOG(INFO) << "Decompressed in " << sw.CpuTime() << " s";

BOOST_CHECK(rofsD.size() == rofs.size());
BOOST_CHECK(colsD.size() == cols.size());
LOG(INFO) << " BOOST_CHECK rofsD.size() " << rofsD.size() << " rofs.size() " << rofs.size()
<< " BOOST_CHECK(colsD.size() " << colsD.size() << " cols.size()) " << cols.size();
for (uint32_t it = 0; it < NEvTypes; it++) {
const auto& rofsD = rofDataD[it];
const auto& rofs = rofData[it];
const auto& colsD = colDataD[it];
const auto& cols = colData[it];
LOG(INFO) << "Test for event type " << it;
BOOST_CHECK(rofsD.size() == rofs.size());
BOOST_CHECK(colsD.size() == cols.size());
LOG(INFO) << " BOOST_CHECK rofsD.size() " << rofsD.size() << " rofs.size() " << rofData[0].size()
<< " BOOST_CHECK(colsD.size() " << colsD.size() << " cols.size()) " << colData[0].size();

for (size_t i = 0; i < rofs.size(); i++) {
const auto& dor = rofs[i];
const auto& ddc = rofsD[i];
LOG(DEBUG) << " Orig.ROFRecord " << i << " " << dor.interactionRecord << " " << dor.firstEntry << " " << dor.nEntries;
LOG(DEBUG) << " Deco.ROFRecord " << i << " " << ddc.interactionRecord << " " << ddc.firstEntry << " " << ddc.nEntries;
for (size_t i = 0; i < rofs.size(); i++) {
const auto& dor = rofs[i];
const auto& ddc = rofsD[i];
LOG(DEBUG) << " Orig.ROFRecord " << i << " " << dor.interactionRecord << " " << dor.firstEntry << " " << dor.nEntries;
LOG(DEBUG) << " Deco.ROFRecord " << i << " " << ddc.interactionRecord << " " << ddc.firstEntry << " " << ddc.nEntries;

BOOST_CHECK(dor.interactionRecord == ddc.interactionRecord);
BOOST_CHECK(dor.firstEntry == ddc.firstEntry);
BOOST_CHECK(dor.nEntries == dor.nEntries);
}
BOOST_CHECK(dor.interactionRecord == ddc.interactionRecord);
BOOST_CHECK(dor.firstEntry == ddc.firstEntry);
BOOST_CHECK(dor.nEntries == dor.nEntries);
}

for (size_t i = 0; i < cols.size(); i++) {
const auto& cor = cols[i];
const auto& cdc = colsD[i];
BOOST_CHECK(cor.deId == cdc.deId);
BOOST_CHECK(cor.columnId == cdc.columnId);
for (int j = 0; j < 5; j++) {
BOOST_CHECK(cor.patterns[j] == cdc.patterns[j]);
LOG(DEBUG) << "col " << i << " pat " << j << " : " << cor.patterns[j] << " : " << cdc.patterns[j];
for (size_t i = 0; i < cols.size(); i++) {
const auto& cor = cols[i];
const auto& cdc = colsD[i];
BOOST_CHECK(cor.deId == cdc.deId);
BOOST_CHECK(cor.columnId == cdc.columnId);
for (int j = 0; j < 5; j++) {
BOOST_CHECK(cor.patterns[j] == cdc.patterns[j]);
LOG(DEBUG) << "col " << i << " pat " << j << " : " << cor.patterns[j] << " : " << cdc.patterns[j];
}
}
}
}
30 changes: 16 additions & 14 deletions Detectors/MUON/MID/CTF/include/MIDCTF/CTFCoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,22 +43,22 @@ class CTFCoder : public o2::ctf::CTFCoderBase

/// entropy-encode data to buffer with CTF
template <typename VEC>
void encode(VEC& buff, const gsl::span<const ROFRecord>& rofData, const gsl::span<const ColumnData>& colData);
void encode(VEC& buff, const CTFHelper::TFData& tfData);

/// entropy decode data from buffer with CTF
template <typename VROF, typename VCOL>
void decode(const CTF::base& ec, VROF& rofVec, VCOL& colVec);
void decode(const CTF::base& ec, std::array<VROF, NEvTypes>& rofVec, std::array<VCOL, NEvTypes>& colVec);

void createCoders(const std::string& dictPath, o2::ctf::CTFCoderBase::OpType op);

private:
void appendToTree(TTree& tree, CTF& ec);
void readFromTree(TTree& tree, int entry, std::vector<ROFRecord>& rofVec, std::vector<ColumnData>& colVec);
void readFromTree(TTree& tree, int entry, std::array<std::vector<ROFRecord>, NEvTypes>& rofVec, std::array<std::vector<ColumnData>, NEvTypes>& colVec);
};

/// entropy-encode clusters to buffer with CTF
template <typename VEC>
void CTFCoder::encode(VEC& buff, const gsl::span<const ROFRecord>& rofData, const gsl::span<const ColumnData>& colData)
void CTFCoder::encode(VEC& buff, const CTFHelper::TFData& tfData)
{
using MD = o2::ctf::Metadata::OptStore;
// what to do which each field: see o2::ctd::Metadata explanation
Expand All @@ -71,7 +71,7 @@ void CTFCoder::encode(VEC& buff, const gsl::span<const ROFRecord>& rofData, cons
MD::EENCODE, // BLC_deId
MD::EENCODE // BLC_colId
};
CTFHelper helper(rofData, colData);
CTFHelper helper(tfData);

// book output size with some margin
auto szIni = sizeof(CTFHeader) + helper.getSize() * 2. / 3; // will be autoexpanded if needed
Expand Down Expand Up @@ -101,7 +101,7 @@ void CTFCoder::encode(VEC& buff, const gsl::span<const ROFRecord>& rofData, cons

/// decode entropy-encoded clusters to standard compact clusters
template <typename VROF, typename VCOL>
void CTFCoder::decode(const CTF::base& ec, VROF& rofVec, VCOL& colVec)
void CTFCoder::decode(const CTF::base& ec, std::array<VROF, NEvTypes>& rofVec, std::array<VCOL, NEvTypes>& colVec)
{
auto header = ec.getHeader();
checkDictVersion(static_cast<const o2::ctf::CTFDictHeader&>(header));
Expand All @@ -122,10 +122,12 @@ void CTFCoder::decode(const CTF::base& ec, VROF& rofVec, VCOL& colVec)
DECODEMID(colId, CTF::BLC_colId);
// clang-format on
//
rofVec.clear();
colVec.clear();
rofVec.reserve(header.nROFs);
colVec.reserve(header.nColumns);
for (uint32_t i = 0; i < NEvTypes; i++) {
rofVec[i].clear();
colVec[i].clear();
rofVec[i].reserve(header.nROFs);
colVec[i].reserve(header.nColumns);
}

uint32_t firstEntry = 0, rofCount = 0, colCount = 0, pCount = 0;
o2::InteractionRecord ir(header.firstBC, header.firstOrbit);
Expand All @@ -138,14 +140,14 @@ void CTFCoder::decode(const CTF::base& ec, VROF& rofVec, VCOL& colVec)
} else {
ir.bc += bcInc[irof];
}

firstEntry = colVec.size();
auto& cv = colVec[evType[irof]];
firstEntry = cv.size();
for (uint8_t ic = 0; ic < entries[irof]; ic++) {
colVec.emplace_back(ColumnData{deId[colCount], colId[colCount], std::array{pattern[pCount], pattern[pCount + 1], pattern[pCount + 2], pattern[pCount + 3], pattern[pCount + 4]}});
cv.emplace_back(ColumnData{deId[colCount], colId[colCount], std::array{pattern[pCount], pattern[pCount + 1], pattern[pCount + 2], pattern[pCount + 3], pattern[pCount + 4]}});
pCount += 5;
colCount++;
}
rofVec.emplace_back(ROFRecord{ir, EventType(evType[irof]), firstEntry, entries[irof]});
rofVec[evType[irof]].emplace_back(ROFRecord{ir, EventType(evType[irof]), firstEntry, entries[irof]});
}
assert(colCount == header.nColumns);
}
Expand Down
Loading