Project
Loading...
Searching...
No Matches
testDigitTreeReader.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 MCH DigitTreeReader
13#define BOOST_TEST_DYN_LINK
14#include <boost/test/unit_test.hpp>
15
16#include "DigitTreeReader.h"
17#include <TFile.h>
18#include <TTree.h>
20#include <vector>
21#include <memory>
22
23using namespace o2::mch;
24using namespace o2::mch::raw;
25
26std::unique_ptr<TTree> createTestTree()
27{
28 auto tree = std::make_unique<TTree>();
29
30 tree->SetName("o2sim");
31
32 std::vector<Digit>* digits = new std::vector<Digit>();
33 std::vector<ROFRecord>* rofs = new std::vector<ROFRecord>();
34
35 tree->Branch("MCHDigit", digits);
36 tree->Branch("MCHROFRecords", rofs);
37
38 constexpr int ndigits{10};
39
40 for (auto i = 0; i < ndigits; i++) {
41 digits->emplace_back(100, i, i * 10, 0);
42 }
43
44 rofs->emplace_back(o2::InteractionRecord{1234, 42}, 0, 2);
45 rofs->emplace_back(o2::InteractionRecord{1234, 43}, 4, 3);
46 rofs->emplace_back(o2::InteractionRecord{1234, 44}, 7, 4);
47
48 tree->Fill();
49
50 digits->clear();
51 rofs->clear();
52 tree->Fill();
53 tree->Fill();
54 return tree;
55}
56
57BOOST_AUTO_TEST_CASE(NofEntriesIsNumberOfTFIs3)
58{
59 auto tree = createTestTree();
60 BOOST_CHECK_EQUAL(tree->GetEntries(), 3);
61 TFile f("toto.root", "RECREATE");
62 tree->Write("o2sim");
63}
64
65BOOST_AUTO_TEST_CASE(NofDigitsOfFirstRofIs2)
66{
67 std::vector<Digit> digits;
69 auto tree = createTestTree();
70 DigitTreeReader dtr(tree.get());
71 dtr.nextDigits(rof, digits);
72 BOOST_CHECK_EQUAL(digits.size(), 2);
73}
74
75BOOST_AUTO_TEST_CASE(DigitTreeReaderMustThrowIfDigitAndRofBranchesDoNotExist)
76{
77 TTree emptyTree("emptyTree", "no branch at all");
78 BOOST_CHECK_THROW(DigitTreeReader dtr(&emptyTree), std::invalid_argument);
79}
80
81BOOST_AUTO_TEST_CASE(DigitTreeReaderMustThrowIfInputTreeIsNullptr)
82{
83 BOOST_CHECK_THROW(DigitTreeReader dtr(nullptr), std::invalid_argument);
84}
85
86BOOST_AUTO_TEST_CASE(DigitTreeReaderMustThrowIfRofBranchIsMissing)
87{
88 TTree missingRofs("missingRofs", "MCHDigit branch alone");
89 std::vector<o2::mch::Digit> digits;
90 missingRofs.Branch("MCHDigit", &digits);
91 BOOST_CHECK_THROW(DigitTreeReader dtr(&missingRofs), std::invalid_argument);
92}
93
94BOOST_AUTO_TEST_CASE(DigitTreeReaderMustThrowIfDigitBranchIsMissing)
95{
96 TTree missingDigits("missingDigits", "MCHROFRecords branch alone");
97 std::vector<o2::mch::ROFRecord> rofs;
98 missingDigits.Branch("MCHROFRecords", &rofs);
99 BOOST_CHECK_THROW(DigitTreeReader dtr(&missingDigits), std::invalid_argument);
100}
101
102BOOST_AUTO_TEST_CASE(DigitTreeReaderMustThrowIfDigitBranchIsOfTheWrongType)
103{
104 TTree invalidDigits("invalidDigits", "MCHDigit branch present but of wrong type");
105 std::vector<o2::mch::ROFRecord> rofs;
106 invalidDigits.Branch("MCHDigit", &rofs); // setting wrong type on purpose
107 invalidDigits.Branch("MCHROFRecords", &rofs);
108 invalidDigits.Fill();
109 BOOST_CHECK_THROW(DigitTreeReader dtr(&invalidDigits), std::invalid_argument);
110}
111
112BOOST_AUTO_TEST_CASE(DigitTreeReaderMustThrowIfRofBranchIsOfTheWrongType)
113{
114 TTree invalidRofs("invalidRofs", "MCHROFRecords branch present but of wrong type");
115 std::vector<o2::mch::Digit> digits;
116 invalidRofs.Branch("MCHDigit", &digits);
117 invalidRofs.Branch("MCHROFRecords", &digits); // setting wrong type on purpose
118 invalidRofs.Fill();
119 BOOST_CHECK_THROW(DigitTreeReader dtr(&invalidRofs), std::invalid_argument);
120}
121
122BOOST_AUTO_TEST_CASE(DigitTreeReaderMustThrowIfNoEntry)
123{
124 TTree noEntry("noEntry", "All branches correct but no entry");
125 std::vector<o2::mch::Digit> digits;
126 std::vector<o2::mch::ROFRecord> rofs;
127 noEntry.Branch("MCHDigit", &digits);
128 noEntry.Branch("MCHROFRecords", &rofs);
129 BOOST_CHECK_THROW(DigitTreeReader dtr(&noEntry), std::invalid_argument);
130}
131
132BOOST_AUTO_TEST_CASE(DigitTreeReaderMustNotThrowIfInputTreeHasAllBranchesAndAtLeastOneEntry)
133{
134 TTree correct("noEntry", "All branches correct but no entry");
135 std::vector<o2::mch::Digit> digits;
136 std::vector<o2::mch::ROFRecord> rofs;
137 correct.Branch("MCHDigit", &digits);
138 correct.Branch("MCHROFRecords", &rofs);
139 correct.Fill();
141}
int32_t i
bool nextDigits(o2::mch::ROFRecord &rof, std::vector< o2::mch::Digit > &digits)
GLdouble f
Definition glcorearb.h:310
BOOST_AUTO_TEST_CASE(FlatHisto)
std::unique_ptr< TTree > createTestTree()
BOOST_CHECK_NO_THROW(algorithm::merge(target, other))
std::unique_ptr< TTree > tree((TTree *) flIn.Get(std::string(o2::base::NameConf::CTFTREENAME).c_str()))
BOOST_CHECK_EQUAL(triggersD.size(), triggers.size())
std::vector< Digit > digits