Project
Loading...
Searching...
No Matches
testCompressedClusters.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
15
16#define BOOST_TEST_MODULE Test TPC DataFormats
17#define BOOST_TEST_MAIN
18#define BOOST_TEST_DYN_LINK
19#include "../include/DataFormatsTPC/CompressedClusters.h"
20#include "../include/DataFormatsTPC/CompressedClustersHelpers.h"
21#include <boost/test/unit_test.hpp>
22#include <string>
23#include <vector>
24#include <TSystem.h>
25#include <TFile.h>
26#include <TTree.h>
27#include <TBranch.h>
28
29namespace o2::tpc
30{
31
32template <typename ContainerType>
33void fillRandom(ContainerType& target, size_t size)
34{
35 target.resize(size);
36 std::generate(target.begin(), target.end(), []() { return rand() % 256; });
37}
38
40 std::vector<unsigned short> qTotA;
41 std::vector<unsigned short> qMaxA;
42 std::vector<unsigned char> flagsA;
43 std::vector<unsigned char> rowDiffA;
44 std::vector<unsigned char> sliceLegDiffA;
45 std::vector<unsigned short> padResA;
46 std::vector<unsigned int> timeResA;
47 std::vector<unsigned char> sigmaPadA;
48 std::vector<unsigned char> sigmaTimeA;
49
50 std::vector<unsigned char> qPtA;
51 std::vector<unsigned char> rowA;
52 std::vector<unsigned char> sliceA;
53 std::vector<unsigned int> timeA;
54 std::vector<unsigned short> padA;
55
56 std::vector<unsigned short> qTotU;
57 std::vector<unsigned short> qMaxU;
58 std::vector<unsigned char> flagsU;
59 std::vector<unsigned short> padDiffU;
60 std::vector<unsigned int> timeDiffU;
61 std::vector<unsigned char> sigmaPadU;
62 std::vector<unsigned char> sigmaTimeU;
63
64 std::vector<unsigned short> nTrackClusters;
65 std::vector<unsigned int> nSliceRowClusters;
66};
67
69{
70 clusters.nAttachedClusters = rand() % 32;
71 fillRandom(data.qTotA, clusters.nAttachedClusters);
72 clusters.qTotA = data.qTotA.data();
73 fillRandom(data.qMaxA, clusters.nAttachedClusters);
74 clusters.qMaxA = data.qMaxA.data();
75 fillRandom(data.flagsA, clusters.nAttachedClusters);
76 clusters.flagsA = data.flagsA.data();
77 fillRandom(data.sigmaPadA, clusters.nAttachedClusters);
78 clusters.sigmaPadA = data.sigmaPadA.data();
79 fillRandom(data.sigmaTimeA, clusters.nAttachedClusters);
80 clusters.sigmaTimeA = data.sigmaTimeA.data();
81
82 clusters.nAttachedClustersReduced = rand() % 32;
83 fillRandom(data.rowDiffA, clusters.nAttachedClustersReduced);
84 clusters.rowDiffA = data.rowDiffA.data();
85 fillRandom(data.sliceLegDiffA, clusters.nAttachedClustersReduced);
86 clusters.sliceLegDiffA = data.sliceLegDiffA.data();
87 fillRandom(data.padResA, clusters.nAttachedClustersReduced);
88 clusters.padResA = data.padResA.data();
89 fillRandom(data.timeResA, clusters.nAttachedClustersReduced);
90 clusters.timeResA = data.timeResA.data();
91
92 clusters.nTracks = rand() % 32;
93 fillRandom(data.qPtA, clusters.nTracks);
94 clusters.qPtA = data.qPtA.data();
95 fillRandom(data.rowA, clusters.nTracks);
96 clusters.rowA = data.rowA.data();
97 fillRandom(data.sliceA, clusters.nTracks);
98 clusters.sliceA = data.sliceA.data();
99 fillRandom(data.timeA, clusters.nTracks);
100 clusters.timeA = data.timeA.data();
101 fillRandom(data.padA, clusters.nTracks);
102 clusters.padA = data.padA.data();
103 fillRandom(data.nTrackClusters, clusters.nTracks);
104 clusters.nTrackClusters = data.nTrackClusters.data();
105
106 clusters.nUnattachedClusters = rand() % 32;
107 fillRandom(data.qTotU, clusters.nUnattachedClusters);
108 clusters.qTotU = data.qTotU.data();
109 fillRandom(data.qMaxU, clusters.nUnattachedClusters);
110 clusters.qMaxU = data.qMaxU.data();
111 fillRandom(data.flagsU, clusters.nUnattachedClusters);
112 clusters.flagsU = data.flagsU.data();
113 fillRandom(data.padDiffU, clusters.nUnattachedClusters);
114 clusters.padDiffU = data.padDiffU.data();
115 fillRandom(data.timeDiffU, clusters.nUnattachedClusters);
116 clusters.timeDiffU = data.timeDiffU.data();
117 fillRandom(data.sigmaPadU, clusters.nUnattachedClusters);
118 clusters.sigmaPadU = data.sigmaPadU.data();
119 fillRandom(data.sigmaTimeU, clusters.nUnattachedClusters);
120 clusters.sigmaTimeU = data.sigmaTimeU.data();
121
122 clusters.nSliceRows = rand() % 32;
123 fillRandom(data.nSliceRowClusters, clusters.nSliceRows);
124 clusters.nSliceRowClusters = data.nSliceRowClusters.data();
125}
126
127BOOST_AUTO_TEST_CASE(test_tpc_compressedclusters)
128{
132 std::vector<char> buffer;
134 CompressedClustersROOT restored;
135 CompressedClustersCounters& x = restored;
136 x = static_cast<CompressedClustersCounters&>(clusters);
137 BOOST_REQUIRE(restored.qTotA == nullptr);
139
140 // check one entry from each category
141 BOOST_CHECK(restored.nAttachedClusters == data.qMaxA.size());
142 BOOST_CHECK(memcmp(restored.qMaxA, data.qMaxA.data(), restored.nAttachedClusters * sizeof(decltype(data.qMaxA)::value_type)) == 0);
143 BOOST_CHECK(restored.nTracks == data.nTrackClusters.size());
144 BOOST_CHECK(memcmp(restored.nTrackClusters, data.nTrackClusters.data(), restored.nTracks * sizeof(decltype(data.nTrackClusters)::value_type)) == 0);
145 BOOST_CHECK(restored.nUnattachedClusters == data.qMaxU.size());
146 BOOST_CHECK(memcmp(restored.qMaxU, data.qMaxU.data(), restored.nUnattachedClusters * sizeof(decltype(data.qMaxU)::value_type)) == 0);
147 BOOST_CHECK(restored.nSliceRows == data.nSliceRowClusters.size());
148 BOOST_CHECK(memcmp(restored.nSliceRowClusters, data.nSliceRowClusters.data(), restored.nSliceRows * sizeof(decltype(data.nSliceRowClusters)::value_type)) == 0);
149}
150
151BOOST_AUTO_TEST_CASE(test_tpc_compressedclusters_root_streaming)
152{
156
157 std::string fileName = gSystem->TempDirectory();
158 fileName += "/testCompressedClusters.root";
159
160 { // scope for the creation of the test file
161 std::unique_ptr<TFile> testFile(TFile::Open(fileName.c_str(), "RECREATE"));
162 std::unique_ptr<TTree> testTree = std::make_unique<TTree>("testtree", "testtree");
163
164 auto* branch = testTree->Branch("compclusters", &clusters);
165 testTree->Fill();
166 testTree->Write();
167 testTree->SetDirectory(nullptr);
168 testFile->Close();
169 }
170
171 { // scope for read back of the streamed object
172 std::unique_ptr<TFile> file(TFile::Open(fileName.c_str()));
173 BOOST_REQUIRE(file != nullptr);
174 TTree* tree = reinterpret_cast<TTree*>(file->GetObjectChecked("testtree", "TTree"));
175 BOOST_REQUIRE(tree != nullptr);
176 TBranch* branch = tree->GetBranch("compclusters");
177 BOOST_REQUIRE(branch != nullptr);
178 CompressedClustersROOT* readback = nullptr;
179 branch->SetAddress(&readback);
180 branch->GetEntry(0);
181 BOOST_REQUIRE(readback != nullptr);
182
183 CompressedClustersROOT& restored = *readback;
184 // check one entry from each category
185 BOOST_CHECK(restored.nAttachedClusters == data.qMaxA.size());
186 BOOST_CHECK(memcmp(restored.qMaxA, data.qMaxA.data(), restored.nAttachedClusters * sizeof(decltype(data.qMaxA)::value_type)) == 0);
187 BOOST_CHECK(restored.nTracks == data.nTrackClusters.size());
188 BOOST_CHECK(memcmp(restored.nTrackClusters, data.nTrackClusters.data(), restored.nTracks * sizeof(decltype(data.nTrackClusters)::value_type)) == 0);
189 BOOST_CHECK(restored.nUnattachedClusters == data.qMaxU.size());
190 BOOST_CHECK(memcmp(restored.qMaxU, data.qMaxU.data(), restored.nUnattachedClusters * sizeof(decltype(data.qMaxU)::value_type)) == 0);
191 BOOST_CHECK(restored.nSliceRows == data.nSliceRowClusters.size());
192 BOOST_CHECK(memcmp(restored.nSliceRowClusters, data.nSliceRowClusters.data(), restored.nSliceRows * sizeof(decltype(data.nSliceRowClusters)::value_type)) == 0);
193 }
194}
195
196} // namespace o2::tpc
GLint GLenum GLint x
Definition glcorearb.h:403
GLuint buffer
Definition glcorearb.h:655
GLsizeiptr size
Definition glcorearb.h:659
GLenum target
Definition glcorearb.h:1641
GLboolean * data
Definition glcorearb.h:298
Global TPC definitions and constants.
Definition SimTraits.h:167
BOOST_AUTO_TEST_CASE(ClusterHardware_test1)
void fillClusters(CompressedClustersROOT &clusters, ClustersData &data)
void fillRandom(ContainerType &target, size_t size)
std::vector< unsigned short > padResA
[nAttachedClustersReduced]
std::vector< unsigned char > sigmaTimeA
[nAttachedClusters]
std::vector< unsigned int > timeDiffU
[nUnattachedClusters]
std::vector< unsigned char > qPtA
[nAttachedClusters]
std::vector< unsigned char > sliceA
[nTracks]
std::vector< unsigned char > sigmaTimeU
[nUnattachedClusters]
std::vector< unsigned short > padA
[nTracks]
std::vector< unsigned short > qTotA
std::vector< unsigned short > nTrackClusters
[nUnattachedClusters]
std::vector< unsigned char > rowA
[nTracks]
std::vector< unsigned int > timeResA
[nAttachedClustersReduced]
std::vector< unsigned short > padDiffU
[nUnattachedClusters]
std::vector< unsigned char > flagsU
[nUnattachedClusters]
std::vector< unsigned short > qMaxU
[nUnattachedClusters]
std::vector< unsigned char > flagsA
[nAttachedClusters]
std::vector< unsigned char > rowDiffA
[nAttachedClusters]
std::vector< unsigned int > timeA
[nTracks]
std::vector< unsigned char > sigmaPadA
[nAttachedClustersReduced]
std::vector< unsigned int > nSliceRowClusters
[nTracks]
std::vector< unsigned short > qTotU
[nTracks]
std::vector< unsigned char > sigmaPadU
[nUnattachedClusters]
std::vector< unsigned char > sliceLegDiffA
[nAttachedClustersReduced]
std::vector< unsigned short > qMaxA
[nAttachedClusters]
static size_t flattenTo(ContainerType &container, CompressedClustersROOT &clusters)
static size_t restoreFrom(ContainerType &container, CompressedClustersROOT &clusters)
Restore the array pointers from the data in the container.
BOOST_CHECK(tree)
std::vector< Cluster > clusters
std::unique_ptr< TTree > tree((TTree *) flIn.Get(std::string(o2::base::NameConf::CTFTREENAME).c_str()))