Project
Loading...
Searching...
No Matches
common.h
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#ifndef ALICEO2_MERGER_TEST_COMMON_H_
13#define ALICEO2_MERGER_TEST_COMMON_H_
14
15#include <sstream>
16#include <gsl/span>
17#include <TH1.h>
19
21{
22inline auto to_span(const TH1F& histo)
23{
24 return gsl::span(histo.GetArray(), histo.GetSize());
25}
26
27void registerCallbacksForTestFailure(framework::CallbackService& cb, std::shared_ptr<bool> success)
28{
30 if (*success == false) {
31 LOG(fatal) << "Received an EndOfStream without having received the expected object";
32 }
33 });
35 if (*success == false) {
36 LOG(fatal) << "STOP transition without having received the expected object";
37 }
38 });
40 if (*success == false) {
41 LOG(fatal) << "EXIT transition without having received the expected object";
42 }
43 });
44}
45
46} // namespace o2::mergers::test
47
48namespace std
49{
50
51template <typename T, size_t Size>
52inline std::string to_string(gsl::span<T, Size> span)
53{
54 std::stringstream ss{};
55 for (size_t i = 0; auto v : span) {
56 ss << v;
57 if (++i != span.size()) {
58 ss << " ";
59 }
60 }
61 return std::move(ss).str();
62}
63
64template <size_t Size>
65inline std::string to_string(const std::array<float, Size>& arr)
66{
67 return to_string(gsl::span(arr));
68}
69
70inline std::string to_string(const TH1F& histo)
71{
73}
74
75template <typename Deleter>
76inline std::string to_string(const std::unique_ptr<const TH1F, Deleter>& histo_ptr)
77{
78 return to_string(o2::mergers::test::to_span(*histo_ptr.get()));
79}
80
81template <size_t Size>
82inline std::string to_string(const std::vector<std::array<float, Size>>& arrays)
83{
84 std::string res{};
85 for (size_t i = 0; const auto& array : arrays) {
86 res.append("[");
87 res.append(to_string(gsl::span(array)));
88 res.append("]");
89 }
90 return res;
91}
92
93template <typename Deleter>
94inline std::string to_string(const std::unique_ptr<const std::vector<TObject*>, Deleter>& histos)
95{
96 std::string res{};
97 for (size_t i = 0; const auto& histo : *histos) {
98 res.append("[");
99 res.append(to_string(*dynamic_cast<TH1F const*>(histo)));
100 res.append("]");
101 }
102 return res;
103}
104
105} // namespace std
106
107#endif
int32_t i
uint32_t res
Definition RawData.h:0
@ ExitRequested
Invoked when the device was requested to stop.
const GLdouble * v
Definition glcorearb.h:832
GLenum array
Definition glcorearb.h:4274
const GLuint * arrays
Definition glcorearb.h:1314
void registerCallbacksForTestFailure(framework::CallbackService &cb, std::shared_ptr< bool > success)
Definition common.h:27
auto to_span(const TH1F &histo)
Definition common.h:22
Defining DataPointCompositeObject explicitly as copiable.
std::string to_string(gsl::span< T, Size > span)
Definition common.h:52
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"