Project
Loading...
Searching...
No Matches
test_ctf_io_ctp.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 CTPCTFIO
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 "DataFormatsCTP/CTF.h"
26#include "Framework/Logger.h"
27#include <TFile.h>
28#include <TStopwatch.h>
29#include <TSystem.h>
30#include <cstring>
31#include <random>
32
33using namespace o2::ctp;
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(CTFTest, boost_data::make(ANSVersions), ansVersion)
39{
40 std::vector<CTPDigit> digits;
41 TStopwatch sw;
42 sw.Start();
44
45 std::random_device rd;
46 std::mt19937_64 eng(rd());
47 std::uniform_int_distribution<unsigned long long> distr;
48 for (int itrg = 0; itrg < 1000; itrg++) {
49 ir += 1 + distr(eng) % 200;
50 auto& dig = digits.emplace_back();
51 dig.intRecord = ir;
52 dig.CTPInputMask |= distr(eng);
53 dig.CTPClassMask |= distr(eng);
54 }
55 LumiInfo lumi{digits.front().intRecord.orbit, 30, 12345};
56
57 sw.Start();
58 std::vector<o2::ctf::BufferType> vec;
59 {
61 coder.setANSVersion(ansVersion);
62 coder.encode(vec, digits, lumi); // compress
63 }
64 sw.Stop();
65 LOG(info) << "Compressed in " << sw.CpuTime() << " s";
66
67 // writing
68 {
69 sw.Start();
71 TFile flOut("test_ctf_ctp.root", "recreate");
72 TTree ctfTree(std::string(o2::base::NameConf::CTFTREENAME).c_str(), "O2 CTF tree");
73 ctfImage->print();
74 ctfImage->appendToTree(ctfTree, "CTP");
75 ctfTree.Write();
76 sw.Stop();
77 LOG(info) << "Wrote to tree in " << sw.CpuTime() << " s";
78 }
79
80 // reading
81 vec.clear();
82 {
83 sw.Start();
84 TFile flIn("test_ctf_ctp.root");
85 std::unique_ptr<TTree> tree((TTree*)flIn.Get(std::string(o2::base::NameConf::CTFTREENAME).c_str()));
87 o2::ctp::CTF::readFromTree(vec, *(tree.get()), "CTP");
88 sw.Stop();
89 LOG(info) << "Read back from tree in " << sw.CpuTime() << " s";
90 }
91
92 std::vector<CTPDigit> digitsD;
94 sw.Start();
95 const auto ctfImage = o2::ctp::CTF::getImage(vec.data());
96 {
98 coder.decode(ctfImage, digitsD, lumiD); // decompress
99 }
100 sw.Stop();
101 LOG(info) << "Decompressed in " << sw.CpuTime() << " s";
102
103 LOG(info) << " BOOST_CHECK(digitsD.size() " << digitsD.size() << " digigits.size()) " << digits.size();
104
105 BOOST_TEST(digits == digitsD, boost::test_tools::per_element());
107}
Definitions for CTP CTF data.
class for entropy encoding/decoding of CTP data
definition of CTPDigit, CTPInputDigit
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 CTPDigit > &data, const LumiInfo &lumi)
entropy-encode data to buffer with CTF
Definition CTFCoder.h:76
o2::ctf::CTFIOSize decode(const CTF::base &ec, VTRG &data, LumiInfo &lumi)
entropy decode data from buffer with CTF
Definition CTFCoder.h:131
constexpr ANSHeader ANSVersionCompat
Definition ANSHeader.h:54
constexpr ANSHeader ANSVersion1
Definition ANSHeader.h:55
uint32_t nHBFCounted
Definition LumiInfo.h:26
uint32_t orbit
Definition LumiInfo.h:25
std::vector< o2::ctf::BufferType > vec
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"
std::mt19937_64 eng(rd())
std::vector< CTPDigit > digitsD
std::uniform_int_distribution< unsigned long long > distr
BOOST_CHECK(tree)
std::vector< o2::ctf::ANSHeader > ANSVersions
std::random_device rd
o2::InteractionRecord ir(ir0)
LumiInfo lumiD
LumiInfo lumi
TStopwatch sw
TFile flOut("test_ctf_ctp.root", "recreate")
TTree ctfTree(std::string(o2::base::NameConf::CTFTREENAME).c_str(), "O2 CTF tree")
o2::InteractionRecord ir0(3, 5)
auto * ctfImage
BOOST_TEST(digits==digitsD, boost::test_tools::per_element())
std::unique_ptr< TTree > tree((TTree *) flIn.Get(std::string(o2::base::NameConf::CTFTREENAME).c_str()))
TFile flIn("test_ctf_ctp.root")
std::vector< Digit > digits