forked from AliceO2Group/AliceO2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommon.h
More file actions
107 lines (93 loc) · 2.89 KB
/
common.h
File metadata and controls
107 lines (93 loc) · 2.89 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
// 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.
#ifndef ALICEO2_MERGER_TEST_COMMON_H_
#define ALICEO2_MERGER_TEST_COMMON_H_
#include <sstream>
#include <gsl/span>
#include <TH1.h>
#include <Framework/CallbackService.h>
namespace o2::mergers::test
{
inline auto to_span(const TH1F& histo)
{
return gsl::span(histo.GetArray(), histo.GetSize());
}
void registerCallbacksForTestFailure(framework::CallbackService& cb, std::shared_ptr<bool> success)
{
cb.set<framework::CallbackService::Id::EndOfStream>([success](framework::EndOfStreamContext& ctx) {
if (*success == false) {
LOG(fatal) << "Received an EndOfStream without having received the expected object";
}
});
cb.set<framework::CallbackService::Id::Stop>([success]() {
if (*success == false) {
LOG(fatal) << "STOP transition without having received the expected object";
}
});
cb.set<framework::CallbackService::Id::ExitRequested>([success](framework::ServiceRegistryRef) {
if (*success == false) {
LOG(fatal) << "EXIT transition without having received the expected object";
}
});
}
} // namespace o2::mergers::test
namespace std
{
template <typename T, size_t Size>
inline std::string to_string(gsl::span<T, Size> span)
{
std::stringstream ss{};
for (size_t i = 0; auto v : span) {
ss << v;
if (++i != span.size()) {
ss << " ";
}
}
return std::move(ss).str();
}
template <size_t Size>
inline std::string to_string(const std::array<float, Size>& arr)
{
return to_string(gsl::span(arr));
}
inline std::string to_string(const TH1F& histo)
{
return to_string(o2::mergers::test::to_span(histo));
}
template <typename Deleter>
inline std::string to_string(const std::unique_ptr<const TH1F, Deleter>& histo_ptr)
{
return to_string(o2::mergers::test::to_span(*histo_ptr.get()));
}
template <size_t Size>
inline std::string to_string(const std::vector<std::array<float, Size>>& arrays)
{
std::string res{};
for (size_t i = 0; const auto& array : arrays) {
res.append("[");
res.append(to_string(gsl::span(array)));
res.append("]");
}
return res;
}
template <typename Deleter>
inline std::string to_string(const std::unique_ptr<const std::vector<TObject*>, Deleter>& histos)
{
std::string res{};
for (size_t i = 0; const auto& histo : *histos) {
res.append("[");
res.append(to_string(*dynamic_cast<TH1F const*>(histo)));
res.append("]");
}
return res;
}
} // namespace std
#endif