forked from AliceO2Group/AliceO2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestDigitTreeReader.cxx
More file actions
141 lines (119 loc) · 4.49 KB
/
testDigitTreeReader.cxx
File metadata and controls
141 lines (119 loc) · 4.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.
#define BOOST_TEST_MODULE MCH DigitTreeReader
#define BOOST_TEST_DYN_LINK
#include <boost/test/unit_test.hpp>
#include "DigitTreeReader.h"
#include <TFile.h>
#include <TTree.h>
#include "CommonDataFormat/InteractionRecord.h"
#include <vector>
#include <memory>
using namespace o2::mch;
using namespace o2::mch::raw;
std::unique_ptr<TTree> createTestTree()
{
auto tree = std::make_unique<TTree>();
tree->SetName("o2sim");
std::vector<Digit>* digits = new std::vector<Digit>();
std::vector<ROFRecord>* rofs = new std::vector<ROFRecord>();
tree->Branch("MCHDigit", digits);
tree->Branch("MCHROFRecords", rofs);
constexpr int ndigits{10};
for (auto i = 0; i < ndigits; i++) {
digits->emplace_back(100, i, i * 10, 0);
}
rofs->emplace_back(o2::InteractionRecord{1234, 42}, 0, 2);
rofs->emplace_back(o2::InteractionRecord{1234, 43}, 4, 3);
rofs->emplace_back(o2::InteractionRecord{1234, 44}, 7, 4);
tree->Fill();
digits->clear();
rofs->clear();
tree->Fill();
tree->Fill();
return tree;
}
BOOST_AUTO_TEST_CASE(NofEntriesIsNumberOfTFIs3)
{
auto tree = createTestTree();
BOOST_CHECK_EQUAL(tree->GetEntries(), 3);
TFile f("toto.root", "RECREATE");
tree->Write("o2sim");
}
BOOST_AUTO_TEST_CASE(NofDigitsOfFirstRofIs2)
{
std::vector<Digit> digits;
o2::mch::ROFRecord rof;
auto tree = createTestTree();
DigitTreeReader dtr(tree.get());
dtr.nextDigits(rof, digits);
BOOST_CHECK_EQUAL(digits.size(), 2);
}
BOOST_AUTO_TEST_CASE(DigitTreeReaderMustThrowIfDigitAndRofBranchesDoNotExist)
{
TTree emptyTree("emptyTree", "no branch at all");
BOOST_CHECK_THROW(DigitTreeReader dtr(&emptyTree), std::invalid_argument);
}
BOOST_AUTO_TEST_CASE(DigitTreeReaderMustThrowIfInputTreeIsNullptr)
{
BOOST_CHECK_THROW(DigitTreeReader dtr(nullptr), std::invalid_argument);
}
BOOST_AUTO_TEST_CASE(DigitTreeReaderMustThrowIfRofBranchIsMissing)
{
TTree missingRofs("missingRofs", "MCHDigit branch alone");
std::vector<o2::mch::Digit> digits;
missingRofs.Branch("MCHDigit", &digits);
BOOST_CHECK_THROW(DigitTreeReader dtr(&missingRofs), std::invalid_argument);
}
BOOST_AUTO_TEST_CASE(DigitTreeReaderMustThrowIfDigitBranchIsMissing)
{
TTree missingDigits("missingDigits", "MCHROFRecords branch alone");
std::vector<o2::mch::ROFRecord> rofs;
missingDigits.Branch("MCHROFRecords", &rofs);
BOOST_CHECK_THROW(DigitTreeReader dtr(&missingDigits), std::invalid_argument);
}
BOOST_AUTO_TEST_CASE(DigitTreeReaderMustThrowIfDigitBranchIsOfTheWrongType)
{
TTree invalidDigits("invalidDigits", "MCHDigit branch present but of wrong type");
std::vector<o2::mch::ROFRecord> rofs;
invalidDigits.Branch("MCHDigit", &rofs); // setting wrong type on purpose
invalidDigits.Branch("MCHROFRecords", &rofs);
invalidDigits.Fill();
BOOST_CHECK_THROW(DigitTreeReader dtr(&invalidDigits), std::invalid_argument);
}
BOOST_AUTO_TEST_CASE(DigitTreeReaderMustThrowIfRofBranchIsOfTheWrongType)
{
TTree invalidRofs("invalidRofs", "MCHROFRecords branch present but of wrong type");
std::vector<o2::mch::Digit> digits;
invalidRofs.Branch("MCHDigit", &digits);
invalidRofs.Branch("MCHROFRecords", &digits); // setting wrong type on purpose
invalidRofs.Fill();
BOOST_CHECK_THROW(DigitTreeReader dtr(&invalidRofs), std::invalid_argument);
}
// BOOST_AUTO_TEST_CASE(DigitTreeReaderMustThrowIfNoEntry)
//{
// TTree noEntry("noEntry", "All branches correct but no entry");
// std::vector<o2::mch::Digit> digits;
// std::vector<o2::mch::ROFRecord> rofs;
// noEntry.Branch("MCHDigit", &digits);
// noEntry.Branch("MCHROFRecords", &rofs);
// BOOST_CHECK_NO_THROW(DigitTreeReader dtr(&noEntry));
// }
BOOST_AUTO_TEST_CASE(DigitTreeReaderMustNotThrowIfInputTreeHasAllBranchesAndAtLeastOneEntry)
{
TTree correct("noEntry", "All branches correct but no entry");
std::vector<o2::mch::Digit> digits;
std::vector<o2::mch::ROFRecord> rofs;
correct.Branch("MCHDigit", &digits);
correct.Branch("MCHROFRecords", &rofs);
correct.Fill();
BOOST_CHECK_NO_THROW(DigitTreeReader dtr(&correct));
}