Project
Loading...
Searching...
No Matches
test_ctf_io_trd.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 TRDCTFIO
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>
24#include "DataFormatsTRD/CTF.h"
25#include "Framework/Logger.h"
26#include <TFile.h>
27#include <TRandom.h>
28#include <TStopwatch.h>
29#include <TSystem.h>
30#include <cstring>
31
32using namespace o2::trd;
33namespace boost_data = boost::unit_test::data;
34
35inline std::vector<o2::ctf::ANSHeader> ANSVersions{o2::ctf::ANSVersionCompat, o2::ctf::ANSVersion1};
36
37BOOST_DATA_TEST_CASE(CTFTest, boost_data::make(ANSVersions), ansVersion)
38{
39 std::vector<TriggerRecord> triggers;
40 std::vector<Tracklet64> tracklets;
41 std::vector<Digit> digits;
42
43 TStopwatch sw;
44 sw.Start();
46 constexpr int NCID = 540, NHCID = 2 * NCID;
47 constexpr uint32_t formatTrk = 5;
49
50 for (int irof = 0; irof < 200; irof++) {
51 ir += 1 + gRandom->Integer(600);
52 bool doDigits = gRandom->Rndm() > 0.8;
53
54 auto startTrk = tracklets.size();
55 auto startDig = digits.size();
56 int cid = 0;
57 while ((cid += gRandom->Poisson(5)) < NHCID) {
58 int hcid = cid / 2;
59 int nTrk = gRandom->Poisson(3);
60 int nDig = doDigits ? nTrk * 5 * (1. + gRandom->Rndm()) : 0;
61
62 for (int i = nTrk; i--;) {
63 tracklets.emplace_back(formatTrk, hcid, gRandom->Integer(0x1 << 4), gRandom->Integer(0x1 << 2),
64 gRandom->Integer(0x1 << 11), gRandom->Integer(0x1 << 8), gRandom->Integer(0x1 << 24));
65 }
66 for (int i = nDig; i--;) {
67 auto& dig = digits.emplace_back(cid, gRandom->Integer(0x1 << 8), gRandom->Integer(0x1 << 8), gRandom->Integer(0x1 << 8));
68 for (int j = constants::TIMEBINS; j--;) {
69 adc[j] = gRandom->Integer(0x1 << 16);
70 }
71 dig.setADC(adc);
72 }
73 }
74
75 triggers.emplace_back(ir, startDig, digits.size() - startDig, startTrk, tracklets.size() - startTrk);
76 }
77
78 sw.Start();
79 std::vector<o2::ctf::BufferType> vec;
80 {
82 coder.setANSVersion(ansVersion);
83 coder.encode(vec, triggers, tracklets, digits); // compress
84 }
85 sw.Stop();
86 LOG(info) << "Compressed in " << sw.CpuTime() << " s";
87
88 // writing
89 {
90 sw.Start();
92 TFile flOut("test_ctf_trd.root", "recreate");
93 TTree ctfTree(std::string(o2::base::NameConf::CTFTREENAME).c_str(), "O2 CTF tree");
94 ctfImage->print();
95 ctfImage->appendToTree(ctfTree, "TRD");
96 ctfTree.Write();
97 sw.Stop();
98 LOG(info) << "Wrote to tree in " << sw.CpuTime() << " s";
99 }
100
101 // reading
102 vec.clear();
103 LOG(info) << "Start reading from tree ";
104 {
105 sw.Start();
106 TFile flIn("test_ctf_trd.root");
107 std::unique_ptr<TTree> tree((TTree*)flIn.Get(std::string(o2::base::NameConf::CTFTREENAME).c_str()));
109 o2::trd::CTF::readFromTree(vec, *(tree.get()), "TRD");
110 sw.Stop();
111 LOG(info) << "Read back from tree in " << sw.CpuTime() << " s";
112 }
113
114 std::vector<TriggerRecord> triggersD;
115 std::vector<Tracklet64> trackletsD;
116 std::vector<Digit> digitsD;
117
118 sw.Start();
119 const auto ctfImage = o2::trd::CTF::getImage(vec.data());
120 {
122 coder.decode(ctfImage, triggersD, trackletsD, digitsD); // decompress
123 }
124 sw.Stop();
125 LOG(info) << "Decompressed in " << sw.CpuTime() << " s";
126
127 BOOST_CHECK(triggersD.size() == triggers.size());
129 BOOST_CHECK(digitsD.size() == digitsD.size());
130
131 BOOST_TEST(triggersD == triggers, boost::test_tools::per_element());
132 BOOST_TEST(trackletsD == tracklets, boost::test_tools::per_element());
133 BOOST_TEST(digitsD == digits, boost::test_tools::per_element());
134}
int32_t i
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
Definitions for TRD CTF data.
class for entropy encoding/decoding of TRD data
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
o2::ctf::CTFIOSize encode(VEC &buff, const gsl::span< const TriggerRecord > &trigData, const gsl::span< const Tracklet64 > &trkData, const gsl::span< const Digit > &digData)
entropy-encode data to buffer with CTF
Definition CTFCoder.h:69
o2::ctf::CTFIOSize decode(const CTF::base &ec, VTRG &trigVec, VTRK &trkVec, VDIG &digVec)
entropy decode data from buffer with CTF
Definition CTFCoder.h:179
constexpr ANSHeader ANSVersionCompat
Definition ANSHeader.h:54
constexpr ANSHeader ANSVersion1
Definition ANSHeader.h:55
constexpr int TIMEBINS
the number of time bins
Definition Constants.h:74
std::array< ADC_t, constants::TIMEBINS > ArrayADC
Definition Digit.h:32
constexpr uint32_t formatTrk
std::vector< o2::ctf::BufferType > vec
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"
TFile flIn("test_ctf_trd.root")
std::vector< Digit > digits
constexpr int NCID
BOOST_CHECK(tree)
std::vector< o2::ctf::ANSHeader > ANSVersions
o2::InteractionRecord ir(0, 0)
TFile flOut("test_ctf_trd.root", "recreate")
TStopwatch sw
std::vector< Tracklet64 > tracklets
std::vector< TriggerRecord > triggersD
TTree ctfTree(std::string(o2::base::NameConf::CTFTREENAME).c_str(), "O2 CTF tree")
constexpr int NHCID
auto * ctfImage
ArrayADC adc
std::vector< Tracklet64 > trackletsD
std::vector< Digit > digitsD
BOOST_TEST(triggersD==triggers, boost::test_tools::per_element())
std::unique_ptr< TTree > tree((TTree *) flIn.Get(std::string(o2::base::NameConf::CTFTREENAME).c_str()))