Project
Loading...
Searching...
No Matches
test_ctf_io_fv0.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 FV0CTFIO
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 "FV0Base/Constants.h"
25#include "Framework/Logger.h"
26#include <TFile.h>
27#include <TRandom.h>
28#include <TStopwatch.h>
29#include <cstring>
30
31using namespace o2::fv0;
32namespace boost_data = boost::unit_test::data;
33
34inline std::vector<o2::ctf::ANSHeader> ANSVersions{o2::ctf::ANSVersionCompat, o2::ctf::ANSVersion1};
35
36BOOST_DATA_TEST_CASE(CTFTest, boost_data::make(ANSVersions), ansVersion)
37{
38 std::vector<Digit> digits;
39 std::vector<ChannelData> channels;
40 TStopwatch sw;
41 sw.Start();
43
45 for (int idig = 0; idig < 1000; idig++) {
46 ir += 1 + gRandom->Integer(200);
47 uint8_t ich = gRandom->Poisson(10);
48 auto start = channels.size();
49 int16_t tMeanA = 0, tMeanC = 0; // TODO: Actual values are not set
50 int32_t ampTotA = 0, ampTotC = 0;
51 int8_t nChanA = 0, nChanC = 0;
52 while (ich < MAXChan) {
53 int16_t t = -2048 + gRandom->Integer(2048 * 2);
54 uint16_t q = gRandom->Integer(4096);
55 uint8_t chain = gRandom->Rndm() > 0.5 ? 0 : 1;
56 channels.emplace_back(ich, t, q, chain);
57 ich += 1 + gRandom->Poisson(10);
58 }
59 Triggers trig; // TODO: Actual values are not set
60 trig.setTriggers(gRandom->Integer(128), nChanA, nChanC, ampTotA, ampTotC, tMeanA, tMeanC);
61 auto end = channels.size();
62 digits.emplace_back(start, end - start, ir, trig, idig);
63 }
64
65 LOG(info) << "Generated " << channels.size() << " channels in " << digits.size() << " digits " << sw.CpuTime() << " s";
66
67 sw.Start();
68 std::vector<o2::ctf::BufferType> vec;
69 {
71 coder.setANSVersion(ansVersion);
72 coder.encode(vec, digits, channels); // compress
73 }
74 sw.Stop();
75 LOG(info) << "Compressed in " << sw.CpuTime() << " s";
76
77 // writing
78 {
79 sw.Start();
80 TFile flOut("test_ctf_fv0.root", "recreate");
81 TTree ctfTree(std::string(o2::base::NameConf::CTFTREENAME).c_str(), "O2 CTF tree");
83 ctfImage->print();
84 ctfImage->appendToTree(ctfTree, "FV0");
85 ctfTree.Write();
86 sw.Stop();
87 LOG(info) << "Wrote to tree in " << sw.CpuTime() << " s";
88 }
89
90 // reading
91 vec.clear();
92 {
93 sw.Start();
94 TFile flIn("test_ctf_fv0.root");
95 std::unique_ptr<TTree> tree((TTree*)flIn.Get(std::string(o2::base::NameConf::CTFTREENAME).c_str()));
97 o2::fv0::CTF::readFromTree(vec, *(tree.get()), "FV0");
98 sw.Stop();
99 LOG(info) << "Read back from tree in " << sw.CpuTime() << " s";
100 }
101
102 std::vector<Digit> digitsD;
103 std::vector<ChannelData> channelsD;
104
105 sw.Start();
106 const auto ctfImage = o2::fv0::CTF::getImage(vec.data());
107 {
109 coder.decode(ctfImage, digitsD, channelsD); // decompress
110 }
111 sw.Stop();
112 LOG(info) << "Decompressed in " << sw.CpuTime() << " s";
113
114 BOOST_CHECK(digitsD.size() == digits.size());
115 BOOST_CHECK(channelsD.size() == channels.size());
116 LOG(info) << " BOOST_CHECK digitsD.size() " << digitsD.size() << " digits.size() " << digits.size() << " BOOST_CHECK(channelsD.size() " << channelsD.size() << " channels.size()) " << channels.size();
117
118 for (int i = digits.size(); i--;) {
119 const auto& dor = digits[i];
120 const auto& ddc = digitsD[i];
121 LOG(debug) << " dor " << dor.mTriggers.print();
122 LOG(debug) << " ddc " << ddc.mTriggers.print();
123
124 BOOST_CHECK(dor.mIntRecord == ddc.mIntRecord);
125 // BOOST_CHECK(dor.mTriggers == ddc.mTriggers);
126 }
127 for (int i = channels.size(); i--;) {
128 const auto& cor = channels[i];
129 const auto& cdc = channelsD[i];
130 BOOST_CHECK(cor.ChId == cdc.ChId);
131 // BOOST_CHECK(cor.ChainQTC == cdc.ChainQTC);
132 BOOST_CHECK(cor.CFDTime == cdc.CFDTime);
133 BOOST_CHECK(cor.QTCAmpl == cdc.QTCAmpl);
134 // BOOST_CHECK(channels[i] == channelsD[i]);
135 }
136}
General constants in FV0.
class for entropy encoding/decoding of FV0 digits data
uint64_t nChanC
uint64_t nChanA
int32_t i
GPUChain * chain
BOOST_DATA_TEST_CASE(DefaultConstructorNofSamplesIsInvariant, boost::unit_test::data::make(nsamples), nofSamples)
Definition testDigit.cxx:50
Definition of the Names Generator class.
std::ostringstream debug
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
void setTriggers(uint8_t trgsig, uint8_t chanA, uint8_t chanC, int32_t aamplA, int32_t aamplC, int16_t atimeA, int16_t atimeC)
Definition Triggers.h:97
o2::ctf::CTFIOSize encode(VEC &buff, const gsl::span< const Digit > &digitVec, const gsl::span< const ChannelData > &channelVec)
entropy-encode digits to buffer with CTF
Definition CTFCoder.h:66
o2::ctf::CTFIOSize decode(const CTF::base &ec, VDIG &digitVec, VCHAN &channelVec)
entropy decode clusters from buffer with CTF
Definition CTFCoder.h:123
GLuint GLuint end
Definition glcorearb.h:469
GLuint start
Definition glcorearb.h:469
constexpr ANSHeader ANSVersionCompat
Definition ANSHeader.h:54
constexpr ANSHeader ANSVersion1
Definition ANSHeader.h:55
static constexpr int nChannelsPerPm
Definition Constants.h:28
static constexpr int nPms
Definition Constants.h:29
TFile flOut("test_ctf_fv0.root", "recreate")
TFile flIn("test_ctf_fv0.root")
std::vector< o2::ctf::BufferType > vec
std::vector< ChannelData > channelsD
std::vector< ChannelData > channels
BOOST_CHECK(tree)
std::vector< o2::ctf::ANSHeader > ANSVersions
o2::InteractionRecord ir(0, 0)
constexpr int MAXChan
TStopwatch sw
TTree ctfTree(std::string(o2::base::NameConf::CTFTREENAME).c_str(), "O2 CTF tree")
auto * ctfImage
std::vector< Digit > digitsD
std::unique_ptr< TTree > tree((TTree *) flIn.Get(std::string(o2::base::NameConf::CTFTREENAME).c_str()))
LOG(info)<< "Generated "<< channels.size()<< " channels in "<< digits.size()<< " digits "<< sw.CpuTime()<< " s"
std::vector< Digit > digits