Project
Loading...
Searching...
No Matches
test_ctf_io_tof.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 TOFCTFIO
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>
22#include "DataFormatsTOF/CTF.h"
23#include "TOFBase/Geo.h"
24#include "TOFBase/Digit.h"
27#include "Framework/Logger.h"
28#include <TFile.h>
29#include <TRandom.h>
30#include <TStopwatch.h>
31#include <cstring>
32
33using namespace o2::tof;
34namespace boost_data = boost::unit_test::data;
35
36inline std::vector<o2::ctf::ANSHeader> ANSVersions{o2::ctf::ANSVersionCompat, o2::ctf::ANSVersion1};
37
38BOOST_DATA_TEST_CASE(CompressedClustersTest, boost_data::make(ANSVersions), ansVersion)
39{
40
41 std::vector<Digit> digits;
42 std::vector<ReadoutWindowData> rows;
43 std::vector<uint8_t> pattVec;
44
45 TStopwatch sw;
46 sw.Start();
47 std::vector<int> row, col;
48 for (int irof = 0; irof < 100; irof++) { // loop over row
49 auto& rofr = rows.emplace_back();
50 int orbit = irof / Geo::NWINDOW_IN_ORBIT;
51 int bc = Geo::BC_IN_ORBIT / Geo::NWINDOW_IN_ORBIT * (irof % 3);
52 rofr.SetOrbit(orbit);
53 rofr.SetBC(bc);
54 int ndig = gRandom->Poisson(50);
55
56 rofr.setFirstEntry(digits.size());
57 rofr.setNEntries(ndig);
58 // fill empty pattern (to be changed)
59 rofr.setFirstEntryDia(pattVec.size());
60 rofr.setNEntriesDia(0);
61 std::vector<int> istrip;
62 for (int i = 0; i < ndig; i++) {
63 istrip.emplace_back(gRandom->Integer(Geo::NSTRIPS));
64 }
65 std::sort(istrip.begin(), istrip.end());
66
67 for (int i = 0; i < ndig; i++) {
68 int ch = istrip[i] * Geo::NPADS + gRandom->Integer(Geo::NPADS);
69 uint16_t TDC = gRandom->Integer(1024);
70 uint16_t TOT = gRandom->Integer(2048);
71 uint64_t BC = Geo::BC_IN_ORBIT * orbit + bc + gRandom->Integer(Geo::BC_IN_ORBIT / Geo::NWINDOW_IN_ORBIT);
72
73 digits.emplace_back(ch, TDC, TOT, BC);
74 }
75
76 std::sort(digits.begin(), digits.end(),
77 [](const Digit& a, const Digit& b) {
78 int strip1 = a.getChannel() / Geo::NPADS, strip2 = b.getChannel() / Geo::NPADS;
79 if (strip1 == strip2) {
80 if (a.getBC() == b.getBC()) {
81 return a.getTDC() < b.getTDC();
82 }
83 return a.getBC() < b.getBC();
84 }
85 return strip1 < strip2;
86 });
87
88 // for (int i = 0; i < ndig; i++)
89 // LOG(info) << "ROW = " << irof << " - Strip = " << digits[i].getChannel() / Geo::NPADS << " - BC = " << digits[i].getBC() << " - TDC = " << digits[i].getTDC();
90 }
91 sw.Stop();
92 LOG(info) << "Generated " << digits.size() << " in " << rows.size() << " ROFs in " << sw.CpuTime() << " s";
93
94 sw.Start();
95 std::vector<o2::ctf::BufferType> vec;
96 {
98 coder.setANSVersion(ansVersion);
99 coder.encode(vec, rows, digits, pattVec); // compress
100 }
101 sw.Stop();
102 LOG(info) << "Compressed in " << sw.CpuTime() << " s";
103
104 // writing
105 {
106 sw.Start();
107 TFile flOut("test_ctf_tof.root", "recreate");
108 TTree ctfTree(std::string(o2::base::NameConf::CTFTREENAME).c_str(), "O2 CTF tree");
109 auto* ctfImage = CTF::get(vec.data());
110 ctfImage->print();
111 ctfImage->appendToTree(ctfTree, "TOF");
112 ctfTree.Write();
113 sw.Stop();
114 LOG(info) << "Wrote to tree in " << sw.CpuTime() << " s";
115 }
116
117 // reading
118 vec.clear();
119 {
120 sw.Start();
121 TFile flIn("test_ctf_tof.root");
122 std::unique_ptr<TTree> tree((TTree*)flIn.Get(std::string(o2::base::NameConf::CTFTREENAME).c_str()));
124 CTF::readFromTree(vec, *(tree.get()), "TOF");
125 sw.Stop();
126 LOG(info) << "Read back from tree in " << sw.CpuTime() << " s";
127 }
128
129 std::vector<Digit> digitsD;
130 std::vector<ReadoutWindowData> rowsD;
131 std::vector<uint8_t> pattVecD;
132 sw.Start();
133 const auto ctfImage = CTF::getImage(vec.data());
134 {
136 coder.decode(ctfImage, rowsD, digitsD, pattVecD); // decompress
137 }
138 sw.Stop();
139 LOG(info) << "Decompressed in " << sw.CpuTime() << " s";
140
141 //
142 // simple checks
143 BOOST_CHECK(rows.size() == rowsD.size());
144 BOOST_CHECK(digits.size() == digitsD.size());
145 BOOST_CHECK(pattVec.size() == pattVecD.size());
146
147 // more sophisticated checks
148
149 // checks on patterns
150 int npatt = ctfImage.getHeader().nPatternBytes;
151 for (int i = 0; i < npatt; i += 100) {
153 }
154}
uint64_t orbit
Definition RawEventData.h:6
uint64_t bc
Definition RawEventData.h:5
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.
Definitions for TOF CTF data.
class for entropy encoding/decoding of TOF compressed infos data
static constexpr std::string_view CTFTREENAME
Definition NameConf.h:95
void setANSVersion(const ctf::ANSHeader &ansVersion) noexcept
o2::ctf::CTFIOSize encode(VEC &buff, const gsl::span< const ReadoutWindowData > &rofRecVec, const gsl::span< const Digit > &cdigVec, const gsl::span< const uint8_t > &pattVec)
entropy-encode clusters to buffer with CTF
Definition CTFCoder.h:65
o2::ctf::CTFIOSize decode(const CTF::base &ec, VROF &rofRecVec, VDIG &cdigVec, VPAT &pattVec)
entropy decode clusters from buffer with CTF
Definition CTFCoder.h:119
TOF digit implementation.
Definition Digit.h:31
static constexpr Int_t NPADS
Definition Geo.h:110
static constexpr int BC_IN_ORBIT
Definition Geo.h:105
static constexpr int NWINDOW_IN_ORBIT
Definition Geo.h:163
static constexpr Int_t NSTRIPS
Definition Geo.h:121
GLboolean GLboolean GLboolean b
Definition glcorearb.h:1233
GLboolean GLboolean GLboolean GLboolean a
Definition glcorearb.h:1233
constexpr ANSHeader ANSVersionCompat
Definition ANSHeader.h:54
constexpr ANSHeader ANSVersion1
Definition ANSHeader.h:55
std::vector< Digit > digits
std::vector< int > row
std::vector< o2::ctf::BufferType > vec
std::vector< uint8_t > pattVec
std::vector< ReadoutWindowData > rowsD
BOOST_CHECK(tree)
std::vector< o2::ctf::ANSHeader > ANSVersions
int npatt
std::vector< uint8_t > pattVecD
TFile flIn("test_ctf_tof.root")
std::vector< int > col
TStopwatch sw
TTree ctfTree(std::string(o2::base::NameConf::CTFTREENAME).c_str(), "O2 CTF tree")
std::vector< ReadoutWindowData > rows
TFile flOut("test_ctf_tof.root", "recreate")
auto * ctfImage
LOG(info)<< "Generated "<< digits.size()<< " in "<< rows.size()<< " ROFs in "<< sw.CpuTime()<< " s"
std::vector< Digit > digitsD
std::unique_ptr< TTree > tree((TTree *) flIn.Get(std::string(o2::base::NameConf::CTFTREENAME).c_str()))