Project
Loading...
Searching...
No Matches
test_ObjectStore.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#include <TH1.h>
13#include <gsl/span>
14#define BOOST_TEST_MODULE Test Utilities MergerObjectStore
15#define BOOST_TEST_MAIN
16#define BOOST_TEST_DYN_LINK
17
18#include "Mergers/ObjectStore.h"
21#include "Headers/DataHeader.h"
22#include "Framework/DataRef.h"
23
24#include <TMessage.h>
25#include <boost/test/unit_test.hpp>
26
27#include <memory>
28
29using namespace o2::framework;
30using namespace o2::mergers;
31
32// Simple test to do root deserialization.
33BOOST_AUTO_TEST_SUITE(TestObjectExtraction)
34
35template <typename TypeToDataRef>
36DataRef makeDataRef(TypeToDataRef* obj)
37{
39 TMessage* tm = new TMessage(kMESS_OBJECT);
40 tm->WriteObject(obj);
41
42 ref.payload = tm->Buffer();
43
44 auto dh = new o2::header::DataHeader{};
46 dh->payloadSize = tm->BufferSize();
47 ref.header = reinterpret_cast<char const*>(dh->data());
48
49 return ref;
50}
51
52BOOST_AUTO_TEST_CASE(MergeableObject)
53{
54 auto* obj = new CustomMergeableTObject("obj1", 123);
55 DataRef ref = makeDataRef(obj);
56
58 BOOST_REQUIRE(std::holds_alternative<MergeInterfacePtr>(objStore));
59
60 auto objExtractedCustom = dynamic_cast<CustomMergeableTObject*>(std::get<MergeInterfacePtr>(objStore).get());
61 BOOST_REQUIRE(objExtractedCustom != nullptr);
62 BOOST_CHECK_EQUAL(objExtractedCustom->getSecret(), 123);
63
64 delete ref.header;
65 delete ref.payload;
66}
67
68BOOST_AUTO_TEST_CASE(NamedMergeableObject)
69{
70 auto* obj = new CustomMergeableObject(123);
71 DataRef ref = makeDataRef(obj);
72
74 BOOST_REQUIRE(std::holds_alternative<MergeInterfacePtr>(objStore));
75
76 auto objExtractedCustom = dynamic_cast<CustomMergeableObject*>(std::get<MergeInterfacePtr>(objStore).get());
77 BOOST_REQUIRE(objExtractedCustom != nullptr);
78 BOOST_CHECK_EQUAL(objExtractedCustom->getSecret(), 123);
79
80 delete ref.header;
81 delete ref.payload;
82}
83
85{
86 TH1I* obj = new TH1I("histo", "histo", 100, 0, 100);
87 obj->Fill(4);
88
89 DataRef ref = makeDataRef(obj);
90
92 BOOST_CHECK(std::holds_alternative<TObjectPtr>(objStore));
93
94 auto objExtractedHisto = dynamic_cast<TH1I*>(std::get<TObjectPtr>(objStore).get());
95 BOOST_REQUIRE(objExtractedHisto != nullptr);
96 BOOST_CHECK_EQUAL(objExtractedHisto->GetEntries(), 1);
97
98 delete ref.header;
99 delete ref.payload;
100 delete obj;
101}
102
103BOOST_AUTO_TEST_CASE(TArrayOfHisto1D)
104{
105 TObjArray* array = new TObjArray();
106 array->SetOwner(true);
107
108 TH1I* histo = new TH1I("histo 1d", "histo 1d", 100, 0, 100);
109 histo->Fill(5);
110 array->Add(histo);
111
114 BOOST_CHECK(std::holds_alternative<TObjectPtr>(objStore));
115
116 auto objExtractedArray = dynamic_cast<TObjArray*>(std::get<TObjectPtr>(objStore).get());
117 BOOST_REQUIRE(objExtractedArray != nullptr);
118 BOOST_CHECK_EQUAL(objExtractedArray->GetEntries(), 1);
119
120 delete ref.header;
121 delete ref.payload;
122 delete array;
123}
124
125BOOST_AUTO_TEST_CASE(VectorOfHistos1D)
126{
127 auto histo = std::make_shared<TH1F>("histo 1d", "histo 1d", 100, 0, 100);
128 histo->Fill(5);
129 VectorOfTObjectPtrs vectorWithData{histo};
130
131 auto vectorToDataRef = object_store_helpers::toRawObserverPointers(vectorWithData);
132
133 DataRef ref = makeDataRef(&vectorToDataRef);
135 BOOST_CHECK(std::holds_alternative<VectorOfTObjectPtrs>(objStore));
136 auto extractedVector = std::get<VectorOfTObjectPtrs>(objStore);
137 BOOST_CHECK(extractedVector.size() == 1);
138 auto* extractedHisto = dynamic_cast<TH1F*>(extractedVector[0].get());
139 BOOST_CHECK(gsl::span(histo->GetArray(), histo->GetSize()) == gsl::span(extractedHisto->GetArray(), extractedHisto->GetSize()));
140}
141
142BOOST_AUTO_TEST_SUITE_END()
An example of overriding O2 Mergers merging interface, v0.1.
An example of a custom TObject inheriting MergeInterface.
Definition of ObjectStore for Mergers, v0.1.
GLenum array
Definition glcorearb.h:4274
GLint ref
Definition glcorearb.h:291
Defining PrimaryVertex explicitly as messageable.
Definition TFIDInfo.h:20
constexpr o2::header::SerializationMethod gSerializationMethodROOT
Definition DataHeader.h:328
ObjectStore extractObjectFrom(const framework::DataRef &ref)
Takes a DataRef, deserializes it (if type is supported) and puts into an ObjectStore.
VectorOfRawTObjects toRawObserverPointers(const VectorOfTObjectPtrs &)
Helper function that converts vector of smart pointers to the vector of raw pointers that is serializ...
std::vector< TObjectPtr > VectorOfTObjectPtrs
Definition ObjectStore.h:43
the main header struct
Definition DataHeader.h:618
SerializationMethod payloadSerializationMethod
Definition DataHeader.h:651
BOOST_AUTO_TEST_CASE(MergeableObject)
DataRef makeDataRef(TypeToDataRef *obj)
BOOST_CHECK(tree)
BOOST_CHECK_EQUAL(triggersD.size(), triggers.size())