-
Notifications
You must be signed in to change notification settings - Fork 499
Expand file tree
/
Copy pathtest_ObjectStore.cxx
More file actions
116 lines (89 loc) · 3.48 KB
/
test_ObjectStore.cxx
File metadata and controls
116 lines (89 loc) · 3.48 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
// Copyright CERN and copyright holders of ALICE O2. This software is
// distributed under the terms of the GNU General Public License v3 (GPL
// Version 3), copied verbatim in the file "COPYING".
//
// See http://alice-o2.web.cern.ch/license for full licensing information.
//
// 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 Utilities MergerObjectStore
#define BOOST_TEST_MAIN
#define BOOST_TEST_DYN_LINK
#include "Mergers/ObjectStore.h"
#include "Mergers/CustomMergeableObject.h"
#include "Mergers/CustomMergeableTObject.h"
#include "Headers/DataHeader.h"
#include "Framework/DataRef.h"
#include <TH1I.h>
#include <TMessage.h>
#include <boost/test/unit_test.hpp>
#include <memory>
using namespace o2::framework;
using namespace o2::mergers;
// Simple test to do root deserialization.
BOOST_AUTO_TEST_CASE(TestObjectExtraction)
{
auto makeDataRef = [](auto* obj) {
DataRef ref;
TMessage* tm = new TMessage(kMESS_OBJECT);
tm->WriteObject(obj);
ref.payload = tm->Buffer();
auto dh = new o2::header::DataHeader{};
dh->payloadSerializationMethod = o2::header::gSerializationMethodROOT;
dh->payloadSize = tm->BufferSize();
ref.header = reinterpret_cast<char const*>(dh->data());
return ref;
};
{
auto* obj = new CustomMergeableTObject("obj1", 123);
DataRef ref = makeDataRef(obj);
auto objStore = object_store_helpers::extractObjectFrom(ref);
BOOST_REQUIRE(std::holds_alternative<TObjectPtr>(objStore));
auto objExtractedCustom = dynamic_cast<CustomMergeableTObject*>(std::get<TObjectPtr>(objStore).get());
BOOST_REQUIRE(objExtractedCustom != nullptr);
BOOST_CHECK_EQUAL(objExtractedCustom->getSecret(), 123);
delete ref.header;
delete ref.payload;
}
{
auto* obj = new CustomMergeableObject(123);
DataRef ref = makeDataRef(obj);
auto objStore = object_store_helpers::extractObjectFrom(ref);
BOOST_REQUIRE(std::holds_alternative<MergeInterfacePtr>(objStore));
auto objExtractedCustom = dynamic_cast<CustomMergeableObject*>(std::get<MergeInterfacePtr>(objStore).get());
BOOST_REQUIRE(objExtractedCustom != nullptr);
BOOST_CHECK_EQUAL(objExtractedCustom->getSecret(), 123);
delete ref.header;
delete ref.payload;
}
{
TH1I* obj = new TH1I("histo", "histo", 100, 0, 100);
obj->Fill(4);
DataRef ref = makeDataRef(obj);
auto objStore = object_store_helpers::extractObjectFrom(ref);
BOOST_CHECK(std::holds_alternative<TObjectPtr>(objStore));
auto objExtractedHisto = dynamic_cast<TH1I*>(std::get<TObjectPtr>(objStore).get());
BOOST_REQUIRE(objExtractedHisto != nullptr);
BOOST_CHECK_EQUAL(objExtractedHisto->GetEntries(), 1);
delete ref.header;
delete ref.payload;
delete obj;
}
{
TObjArray* array = new TObjArray();
array->SetOwner(true);
TH1I* histo = new TH1I("histo 1d", "histo 1d", 100, 0, 100);
histo->Fill(5);
array->Add(histo);
DataRef ref = makeDataRef(array);
auto objStore = object_store_helpers::extractObjectFrom(ref);
BOOST_CHECK(std::holds_alternative<TObjectPtr>(objStore));
auto objExtractedArray = dynamic_cast<TObjArray*>(std::get<TObjectPtr>(objStore).get());
BOOST_REQUIRE(objExtractedArray != nullptr);
BOOST_CHECK_EQUAL(objExtractedArray->GetEntries(), 1);
delete ref.header;
delete ref.payload;
delete array;
}
}