forked from AliceO2Group/AliceO2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestAbstractRefAccessor.cxx
More file actions
97 lines (79 loc) · 2.51 KB
/
testAbstractRefAccessor.cxx
File metadata and controls
97 lines (79 loc) · 2.51 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
// 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 Test AbstractRefAccessor class
#define BOOST_TEST_MAIN
#define BOOST_TEST_DYN_LINK
#include <numeric>
#include <boost/test/unit_test.hpp>
#include "CommonDataFormat/AbstractRefAccessor.h"
#include "CommonDataFormat/AbstractRef.h"
#include "Framework/Logger.h"
using namespace o2::dataformats;
struct Base {
int b = 0;
};
struct Foo1 : public Base {
int f1 = 0;
};
struct Foo2 : public Foo1 {
int f2 = 0;
};
struct Bar1 : public Base {
double b1 = 0.;
};
struct GloIdx : public AbstractRef<25, 5, 2> {
enum Source : uint8_t { // provenance of the
ID0,
ID1,
ID2,
ID3,
NSources
};
using AbstractRef<25, 5, 2>::AbstractRef;
};
// basic AbstractRefAccessor
BOOST_AUTO_TEST_CASE(AbstractRefAccess)
{
std::vector<Base> vb(10);
std::vector<Foo1> vf(10);
std::array<Foo2, 10> af;
std::vector<Bar1> bar(10);
std::vector<GloIdx> vid;
for (int i = 0; i < 10; i++) {
vb[i].b = GloIdx::ID0 * 100 + i;
vid.emplace_back(i, GloIdx::ID1);
vf[i].b = GloIdx::ID1 * 100 + i;
vf[i].f1 = 0.5 + 100 + i;
vid.emplace_back(i, GloIdx::ID2);
af[i].b = GloIdx::ID2 * 100 + i;
af[i].f2 = 0.8 + 100 + i;
vid.emplace_back(i, GloIdx::ID3);
bar[i].b = GloIdx::ID3 * 100 + i;
bar[i].b1 = 0.2 + 300 + i;
vid.emplace_back(i, GloIdx::ID3);
}
AbstractRefAccessor<Base, GloIdx::NSources> acc;
acc.registerContainer(vb, GloIdx::ID0);
acc.registerContainer(vf, GloIdx::ID1);
acc.registerContainer(af, GloIdx::ID2);
acc.registerContainer(bar, GloIdx::ID3);
size_t nid = vid.size();
for (size_t i = 0; i < nid; i++) {
auto gid = vid[i];
const auto& obj = acc.get(gid);
int expect = gid.getSource() * 100 + i / GloIdx::NSources;
LOG(INFO) << i << " ? " << obj.b << " == " << expect << " for " << gid.getRaw();
BOOST_CHECK(obj.b == expect);
}
const auto& barEl = acc.get_as<Bar1>(vid.back());
LOG(INFO) << " ? " << barEl.b1 << " == " << bar.back().b1;
BOOST_CHECK(barEl.b1 == bar.back().b1);
}