12#define BOOST_TEST_MODULE Test MCTruthContainer class
13#define BOOST_TEST_MAIN
14#define BOOST_TEST_DYN_LINK
15#include <boost/test/unit_test.hpp>
29 using TruthElement =
long;
39 BOOST_CHECK_THROW(container.
addElement(0, TruthElement(0)), std::runtime_error);
58 std::sort(view.begin(), view.end(), [](TruthElement
a, TruthElement
b) { return a > b; });
76 auto copy = container;
82 std::vector<TruthElement> newlabels = {101, 102, 103};
96 std::vector<TruthElement> newlabels2 = {};
130 BOOST_CHECK(lview[0] == lviewA[0] && lview[1] == lviewA[1]);
136 using TruthElement =
long;
172 using TruthElement =
long;
174 TruthContainer container;
176 container.addElement(0, TruthElement(2));
177 container.addElement(1, TruthElement(1));
178 container.addElement(2, TruthElement(10));
181 container.flatten_to(
buffer);
182 BOOST_REQUIRE(
buffer.size() >
sizeof(TruthContainer::FlatHeader));
183 auto& header = *
reinterpret_cast<TruthContainer::FlatHeader*
>(
buffer.data());
184 BOOST_CHECK(header.nofHeaderElements == container.getIndexedSize());
185 BOOST_CHECK(header.nofTruthElements == container.getNElements());
187 TruthContainer restoredContainer;
188 restoredContainer.restore_from(
buffer.data(),
buffer.size());
191 BOOST_CHECK(restoredContainer.getMCTruthHeader(0).index == 0);
192 BOOST_CHECK(restoredContainer.getMCTruthHeader(1).index == 2);
193 BOOST_CHECK(restoredContainer.getMCTruthHeader(2).index == 3);
199 BOOST_CHECK(restoredContainer.getElement(3) == 10);
203 ConstMCTruthContainer
cc;
204 container.flatten_to(
cc);
206 BOOST_CHECK(
cc.getIndexedSize() == container.getIndexedSize());
208 BOOST_CHECK(
cc.getLabels(0).size() == container.getLabels(0).size());
209 BOOST_CHECK(
cc.getLabels(1).size() == container.getLabels(1).size());
210 BOOST_CHECK(
cc.getLabels(2).size() == container.getLabels(2).size());
211 BOOST_CHECK(
cc.getLabels(2)[0] == container.getLabels(2)[0]);
217 using TruthElement =
long;
220 container.
addLabel(0, TruthElement(1));
221 container.
addLabel(1, TruthElement(1));
222 container.
addLabel(0, TruthElement(10));
223 container.
addLabel(2, TruthElement(20));
227 for (
auto& e : view) {
228 std::cerr << e <<
"\n";
234 for (
auto& e : view2) {
243 std::cout <<
"ELEMENTS OF LABEL 2\n";
244 for (
auto& e : view2) {
246 std::cout << e <<
"\n";
248 std::cout <<
"------\n";
251 std::vector<TruthElement>
v;
254 std::sort(
v.begin(),
v.end(), [](TruthElement
a, TruthElement
b) { return a > b; });
256 std::cerr << e <<
"\n";
263 for (
int run = 0; run <
R; ++run) {
264 for (
int i = 0;
i < L; ++
i) {
265 container2.
addLabel(
i, TruthElement(run));
269 for (
int i = 0;
i < L; ++
i) {
274 std::cout <<
"CHECK CONTENT FOR INDEX " <<
i <<
"\n";
275 std::cout <<
"----- \n";
276 for (
auto& l : labelview) {
278 std::cout << l <<
"\n";
280 std::cout <<
"#### " <<
i <<
"\n";
288 cont2.
addLabel(0, TruthElement(10));
290 cont2.
addLabel(2, TruthElement(20));
294 for (
auto& e : view2) {
295 std::cerr << e <<
"\n";
301 for (
auto& e : view2) {
302 std::cerr << e <<
"\n";
308 for (
auto& e : view2) {
309 std::cerr << e <<
"\n";
319 using TruthElement =
long;
323 container.addElement(0, TruthElement(2));
324 container.addElement(1, TruthElement(1));
325 container.addElement(2, TruthElement(10));
327 Container container2 = std::move(container);
331 std::swap(container, container2);
343 const size_t BIGSIZE{1000000};
345 for (
int i = 1;
i < BIGSIZE; ++
i) {
346 container.addElement(
i, TruthElement(
i,
i,
i));
347 container.addElement(
i, TruthElement(
i + 1,
i,
i));
350 container.flatten_to(
buffer);
355 TFile
f(
"tmp2.root",
"RECREATE");
356 TTree
tree(
"o2sim",
"o2sim");
357 auto br =
tree.Branch(
"Labels", &io, 32000, 2);
358 tree.Branch(
"LabelsOriginal", &container, 32000, 2);
365 TFile f2(
"tmp2.root",
"OPEN");
366 auto tree2 = (TTree*)f2.Get(
"o2sim");
368 auto br2 = tree2->GetBranch(
"Labels");
370 br2->SetAddress(&io2);
375 ConstMCTruthContainer
cc;
385 BOOST_CHECK(
cc.getLabels(BIGSIZE - 1)[0] == TruthElement(BIGSIZE - 1, BIGSIZE - 1, BIGSIZE - 1));
386 BOOST_CHECK(
cc.getLabels(BIGSIZE - 1)[1] == TruthElement(BIGSIZE, BIGSIZE - 1, BIGSIZE - 1));
394 BOOST_CHECK(cont->getNElements() == (BIGSIZE - 1) * 2);
395 BOOST_CHECK(cont2->getNElements() == (BIGSIZE - 1) * 2);
398 BOOST_CHECK(cont->getLabels(BIGSIZE - 1)[0] == TruthElement(BIGSIZE - 1, BIGSIZE - 1, BIGSIZE - 1));
399 BOOST_CHECK(cont->getLabels(BIGSIZE - 1)[1] == TruthElement(BIGSIZE, BIGSIZE - 1, BIGSIZE - 1));
400 BOOST_CHECK(cont2->getLabels(BIGSIZE - 1)[0] == TruthElement(BIGSIZE - 1, BIGSIZE - 1, BIGSIZE - 1));
401 BOOST_CHECK(cont2->getLabels(BIGSIZE - 1)[1] == TruthElement(BIGSIZE, BIGSIZE - 1, BIGSIZE - 1));
A const (ready only) version of MCTruthContainer.
A special IO container - splitting a given vector to enable ROOT IO.
GLboolean GLboolean GLboolean b
GLboolean GLboolean GLboolean GLboolean a
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
BOOST_AUTO_TEST_CASE(FlatHisto)
std::vector< o2::mch::ChannelCode > cc
std::unique_ptr< TTree > tree((TTree *) flIn.Get(std::string(o2::base::NameConf::CTFTREENAME).c_str()))