Project
Loading...
Searching...
No Matches
test_ctf_io_itsmft.cxx
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
12#define BOOST_TEST_MODULE Test ITSMFTCTFIO
13#define BOOST_TEST_MAIN
14#define BOOST_TEST_DYN_LINK
15
16#undef NDEBUG
17#include <cassert>
18
19#include <boost/test/unit_test.hpp>
20#include <boost/test/data/test_case.hpp>
21#include <boost/test/data/dataset.hpp>
28#include "Framework/Logger.h"
29#include <TFile.h>
30#include <TRandom.h>
31#include <TStopwatch.h>
32#include <cstring>
33
34using namespace o2::itsmft;
35namespace boost_data = boost::unit_test::data;
36
37inline std::vector<o2::ctf::ANSHeader> ANSVersions{o2::ctf::ANSVersionCompat, o2::ctf::ANSVersion1};
38
39BOOST_DATA_TEST_CASE(CompressedClustersTest, boost_data::make(ANSVersions), ansVersion)
40{
41
42 std::vector<ROFRecord> rofRecVec;
43 std::vector<CompClusterExt> cclusVec;
44 std::vector<unsigned char> pattVec;
46 TStopwatch sw;
47 sw.Start();
48 std::vector<int> row, col;
49 for (int irof = 0; irof < 100; irof++) {
50 auto& rofr = rofRecVec.emplace_back();
51 rofr.getBCData().orbit = irof / 10;
52 rofr.getBCData().bc = irof % 10;
53 int nChips = 5 * irof;
54 int chipID = irof / 2;
55 rofr.setFirstEntry(cclusVec.size());
56 for (int i = 0; i < nChips; i++) {
57 int nhits = gRandom->Poisson(50);
58 row.resize(nhits);
59 col.resize(nhits);
60 for (int i = 0; i < nhits; i++) {
61 row[i] = gRandom->Integer(512);
62 col[i] = gRandom->Integer(1024);
63 }
64 std::sort(col.begin(), col.end());
65 for (int i = 0; i < nhits; i++) {
66 auto& cl = cclusVec.emplace_back(row[i], col[i], gRandom->Integer(1000), chipID);
67 if (cl.getPatternID() > 900) {
68 int nbpatt = 1 + gRandom->Poisson(3.);
69 for (int i = nbpatt; i--;) {
70 pattVec.push_back(char(gRandom->Integer(256)));
71 }
72 }
73 }
74 chipID += 1 + gRandom->Poisson(10);
75 }
76 rofr.setNEntries(int(cclusVec.size()) - rofr.getFirstEntry());
77 }
78 sw.Stop();
79 LOG(info) << "Generated " << cclusVec.size() << " in " << rofRecVec.size() << " ROFs in " << sw.CpuTime() << " s";
80
81 sw.Start();
82 std::vector<o2::ctf::BufferType> vec;
83 {
85 coder.setANSVersion(ansVersion);
86 coder.encode(vec, rofRecVec, cclusVec, pattVec, pattIdConverter, 0); // compress
87 }
88 sw.Stop();
89 LOG(info) << "Compressed in " << sw.CpuTime() << " s";
90
91 // writing
92 {
93 sw.Start();
94 TFile flOut("test_ctf_itsmft.root", "recreate");
95 TTree ctfTree(std::string(o2::base::NameConf::CTFTREENAME).c_str(), "O2 CTF tree");
97 ctfImage->print();
98 ctfImage->appendToTree(ctfTree, "ITS");
99 ctfTree.Write();
100 sw.Stop();
101 LOG(info) << "Wrote to tree in " << sw.CpuTime() << " s";
102 }
103
104 // reading
105 vec.clear();
106 {
107 sw.Start();
108 TFile flIn("test_ctf_itsmft.root");
109 std::unique_ptr<TTree> tree((TTree*)flIn.Get(std::string(o2::base::NameConf::CTFTREENAME).c_str()));
111 o2::itsmft::CTF::readFromTree(vec, *(tree.get()), "ITS");
112 sw.Stop();
113 LOG(info) << "Read back from tree in " << sw.CpuTime() << " s";
114 }
115
116 std::vector<ROFRecord> rofRecVecD;
117 std::vector<CompClusterExt> cclusVecD;
118 std::vector<unsigned char> pattVecD;
120 sw.Start();
121 const auto ctfImage = o2::itsmft::CTF::getImage(vec.data());
122 {
124 coder.decode(ctfImage, rofRecVecD, cclusVecD, pattVecD, nullptr, clPattLookup); // decompress
125 }
126 sw.Stop();
127 LOG(info) << "Decompressed in " << sw.CpuTime() << " s";
128
129 //
130 // check
131 BOOST_CHECK(rofRecVecD.size() == rofRecVec.size());
132 BOOST_CHECK(cclusVecD.size() == cclusVec.size());
133 BOOST_CHECK(pattVecD.size() == pattVec.size());
134 int di = rofRecVec.size() / 10 ? rofRecVec.size() / 10 : 1;
135 for (int i = 0; i < int(rofRecVec.size()); i += di) {
136 BOOST_CHECK(rofRecVecD[i].getBCData() == rofRecVec[i].getBCData());
137 BOOST_CHECK(rofRecVecD[i].getFirstEntry() == rofRecVec[i].getFirstEntry());
138 BOOST_CHECK(rofRecVecD[i].getNEntries() == rofRecVec[i].getNEntries());
139 //
140 int ncl = rofRecVec[i].getNEntries();
141 int firstCl = rofRecVec[i].getFirstEntry();
142 for (int j = 0; j < ncl; j += 10) {
143 auto j1 = j + firstCl;
144 BOOST_CHECK(cclusVecD[j1].getChipID() == cclusVec[j1].getChipID());
145 BOOST_CHECK(cclusVecD[j1].getRow() == cclusVec[j1].getRow());
146 BOOST_CHECK(cclusVecD[j1].getCol() == cclusVec[j1].getCol());
147 }
148 }
149 //
150 int npatt = ctfImage.getHeader().nPatternBytes;
151 for (int i = 0; i < npatt; i += 100) {
153 }
154}
Definition of the ITSMFT compact cluster.
int32_t i
Definitions for ITS/MFT CTF data.
Definition of the ITSMFT ROFrame (trigger) record.
class for entropy encoding/decoding of ITS/MFT compressed clusters data
Definition of the LookUp class.
BOOST_DATA_TEST_CASE(DefaultConstructorNofSamplesIsInvariant, boost::unit_test::data::make(nsamples), nofSamples)
Definition testDigit.cxx:50
Definition of the Names Generator class.
uint32_t j
Definition RawData.h:0
static constexpr std::string_view CTFTREENAME
Definition NameConf.h:95
void setANSVersion(const ctf::ANSHeader &ansVersion) noexcept
void readFromTree(TTree &tree, const std::string &name, int ev=0)
read from tree to non-flat object
static auto get(void *head)
cast arbitrary buffer head to container class. Head is supposed to respect the alignment
static auto getImage(const void *newHead)
get const image of the container wrapper, with pointers in the image relocated to new head
static constexpr ID ITS
Definition DetID.h:63
o2::ctf::CTFIOSize encode(VEC &buff, const gsl::span< const ROFRecord > &rofRecVec, const gsl::span< const CompClusterExt > &cclusVec, const gsl::span< const unsigned char > &pattVec, const LookUp &clPattLookup, int strobeLength)
entropy-encode clusters to buffer with CTF
Definition CTFCoder.h:88
o2::ctf::CTFIOSize decode(const CTF::base &ec, VROF &rofRecVec, VCLUS &cclusVec, VPAT &pattVec, const NoiseMap *noiseMap, const LookUp &clPattLookup)
entropy decode clusters from buffer with CTF
Definition CTFCoder.h:140
constexpr ANSHeader ANSVersionCompat
Definition ANSHeader.h:54
constexpr ANSHeader ANSVersion1
Definition ANSHeader.h:55
LookUp clPattLookup
std::vector< int > row
std::vector< CompClusterExt > cclusVecD
LOG(info)<< "Generated "<< cclusVec.size()<< " in "<< rofRecVec.size()<< " ROFs in "<< sw.CpuTime()<< " s"
std::vector< o2::ctf::BufferType > vec
std::vector< ROFRecord > rofRecVecD
std::vector< unsigned char > pattVec
std::vector< CompClusterExt > cclusVec
BOOST_CHECK(tree)
std::vector< o2::ctf::ANSHeader > ANSVersions
TFile flIn("test_ctf_itsmft.root")
std::vector< unsigned char > pattVecD
TFile flOut("test_ctf_itsmft.root", "recreate")
std::vector< int > col
TStopwatch sw
TTree ctfTree(std::string(o2::base::NameConf::CTFTREENAME).c_str(), "O2 CTF tree")
auto * ctfImage
LookUp pattIdConverter
std::unique_ptr< TTree > tree((TTree *) flIn.Get(std::string(o2::base::NameConf::CTFTREENAME).c_str()))