Project
Loading...
Searching...
No Matches
test_ctf_io_hmpid.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 HMPIDCTFIO
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 "DataFormatsHMP/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::hmpid;
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<Trigger> triggers;
40 std::vector<Digit> digits;
41 TStopwatch sw;
42 sw.Start();
45 for (int irof = 0; irof < 1000; irof++) {
46 ir += 1 + gRandom->Integer(200);
47
48 auto start = digits.size();
49 uint8_t chID = 0;
50 int n = 0;
51 while ((chID += gRandom->Integer(10)) < 0xff) {
52 uint16_t q = gRandom->Integer(0xffff);
53 uint8_t ph = gRandom->Integer(0xff);
54 uint8_t x = gRandom->Integer(0xff);
55 uint8_t y = gRandom->Integer(0xff);
56 digits.emplace_back(chID, ph, x, y, q);
57 }
58 triggers.emplace_back(ir, start, digits.size() - start);
59 }
60
61 sw.Start();
62 std::vector<o2::ctf::BufferType> vec;
63 {
65 coder.setANSVersion(ansVersion);
66 coder.encode(vec, triggers, digits); // compress
67 }
68 sw.Stop();
69 LOG(info) << "Compressed in " << sw.CpuTime() << " s";
70
71 // writing
72 {
73 sw.Start();
75 TFile flOut("test_ctf_hmpid.root", "recreate");
76 TTree ctfTree(std::string(o2::base::NameConf::CTFTREENAME).c_str(), "O2 CTF tree");
77 ctfImage->print();
78 ctfImage->appendToTree(ctfTree, "HMP");
79 ctfTree.Write();
80 sw.Stop();
81 LOG(info) << "Wrote to tree in " << sw.CpuTime() << " s";
82 }
83
84 // reading
85 vec.clear();
86 LOG(info) << "Start reading from tree ";
87 {
88 sw.Start();
89 TFile flIn("test_ctf_hmpid.root");
90 std::unique_ptr<TTree> tree((TTree*)flIn.Get(std::string(o2::base::NameConf::CTFTREENAME).c_str()));
92 o2::hmpid::CTF::readFromTree(vec, *(tree.get()), "HMP");
93 sw.Stop();
94 LOG(info) << "Read back from tree in " << sw.CpuTime() << " s";
95 }
96
97 std::vector<Trigger> triggersD;
98 std::vector<Digit> digitsD;
99
100 sw.Start();
101 const auto ctfImage = o2::hmpid::CTF::getImage(vec.data());
102 {
104 coder.decode(ctfImage, triggersD, digitsD); // decompress
105 }
106 sw.Stop();
107 LOG(info) << "Decompressed in " << sw.CpuTime() << " s";
108
109 BOOST_CHECK(triggersD.size() == triggers.size());
110 BOOST_CHECK(digitsD.size() == digits.size());
111
112 BOOST_TEST(triggersD == triggers, boost::test_tools::per_element());
113 BOOST_TEST(digitsD == digits, boost::test_tools::per_element());
114}
Definitions for HMPID CTF data.
class for entropy encoding/decoding of HMPID data
BOOST_DATA_TEST_CASE(DefaultConstructorNofSamplesIsInvariant, boost::unit_test::data::make(nsamples), nofSamples)
Definition testDigit.cxx:50
Definition of the Names Generator class.
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 Trigger > &trigData, const gsl::span< const Digit > &digData)
entropy-encode data to buffer with CTF
Definition CTFCoder.h:62
o2::ctf::CTFIOSize decode(const CTF::base &ec, VTRG &trigVec, VDIG &digVec)
entropy decode data from buffer with CTF
Definition CTFCoder.h:132
HMPID Digit declaration.
Definition Digit.h:36
GLdouble n
Definition glcorearb.h:1982
GLint GLenum GLint x
Definition glcorearb.h:403
GLuint start
Definition glcorearb.h:469
constexpr ANSHeader ANSVersionCompat
Definition ANSHeader.h:54
constexpr ANSHeader ANSVersion1
Definition ANSHeader.h:55
Digit clu
std::vector< o2::ctf::BufferType > vec
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"
TFile flOut("test_ctf_hmpid.root", "recreate")
std::vector< Digit > digits
std::vector< Trigger > triggersD
BOOST_CHECK(tree)
std::vector< o2::ctf::ANSHeader > ANSVersions
o2::InteractionRecord ir(0, 0)
TStopwatch sw
TFile flIn("test_ctf_hmpid.root")
TTree ctfTree(std::string(o2::base::NameConf::CTFTREENAME).c_str(), "O2 CTF tree")
auto * ctfImage
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()))