Project
Loading...
Searching...
No Matches
testAbstractRefAccessor.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 Test AbstractRefAccessor class
13#define BOOST_TEST_MAIN
14#define BOOST_TEST_DYN_LINK
15#include <numeric>
16#include <boost/test/unit_test.hpp>
19#include "Framework/Logger.h"
20
21using namespace o2::dataformats;
22
23struct Base {
24 int b = 0;
25};
26
27struct Foo1 : public Base {
28 int f1 = 0;
29};
30
31struct Foo2 : public Foo1 {
32 int f2 = 0;
33};
34
35struct Bar1 : public Base {
36 double b1 = 0.;
37};
38
39struct GloIdx : public AbstractRef<25, 5, 2> {
40 enum Source : uint8_t { // provenance of the
46 };
47 using AbstractRef<25, 5, 2>::AbstractRef;
48};
49
50// basic AbstractRefAccessor
51BOOST_AUTO_TEST_CASE(AbstractRefAccess)
52{
53
54 std::vector<Base> vb(10);
55 std::vector<Foo1> vf(10);
56 std::array<Foo2, 10> af;
57 std::vector<Bar1> bar(10);
58
59 std::vector<GloIdx> vid;
60
61 for (int i = 0; i < 10; i++) {
62 vb[i].b = GloIdx::ID0 * 100 + i;
63 vid.emplace_back(i, GloIdx::ID1);
64
65 vf[i].b = GloIdx::ID1 * 100 + i;
66 vf[i].f1 = 0.5 + 100 + i;
67 vid.emplace_back(i, GloIdx::ID2);
68
69 af[i].b = GloIdx::ID2 * 100 + i;
70 af[i].f2 = 0.8 + 100 + i;
71 vid.emplace_back(i, GloIdx::ID3);
72
73 bar[i].b = GloIdx::ID3 * 100 + i;
74 bar[i].b1 = 0.2 + 300 + i;
75 vid.emplace_back(i, GloIdx::ID3);
76 }
77
79
84
85 size_t nid = vid.size();
86 for (size_t i = 0; i < nid; i++) {
87 auto gid = vid[i];
88 const auto& obj = acc.get(gid);
89 int expect = gid.getSource() * 100 + i / GloIdx::NSources;
90 LOG(info) << i << " ? " << obj.b << " == " << expect << " for " << gid.getRaw();
91 BOOST_CHECK(obj.b == expect);
92 }
93
94 const auto& barEl = acc.get_as<Bar1>(vid.back());
95 LOG(info) << " ? " << barEl.b1 << " == " << bar.back().b1;
96 BOOST_CHECK(barEl.b1 == bar.back().b1);
97}
Accessor for objects of the same base class located in different containers.
Class to refer to object indicating its Indec, Source and status flags.
int32_t i
const T & get(int src, int idx) const
get object from explicitly provided source, index
void registerContainer(const C &cont, int src)
register container in the accessor
const U & get_as(int src, int idx) const
get object as user provided type from explicitly provided source, index
GLboolean GLboolean GLboolean b
Definition glcorearb.h:1233
Definition of a container to keep/associate and arbitrary number of labels associated to an index wit...
BOOST_AUTO_TEST_CASE(AbstractRefAccess)
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"
BOOST_CHECK(tree)