Skip to content

Commit b77f031

Browse files
committed
DPL: move a bunch of Variant helpers out of line
1 parent f70fb9b commit b77f031

File tree

3 files changed

+115
-24
lines changed

3 files changed

+115
-24
lines changed

Framework/Core/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ o2_add_library(Framework
138138
src/Task.cxx
139139
src/Array2D.cxx
140140
src/Variant.cxx
141+
src/VariantPropertyTreeHelpers.cxx
141142
src/WorkflowCustomizationHelpers.cxx
142143
src/WorkflowHelpers.cxx
143144
src/WorkflowSerializationHelpers.cxx

Framework/Core/include/Framework/VariantPropertyTreeHelpers.h

Lines changed: 57 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,14 @@
1111
#ifndef FRAMEWORK_VARIANTPTREEHELPERS_H
1212
#define FRAMEWORK_VARIANTPTREEHELPERS_H
1313

14+
#include "Array2D.h"
1415
#include "Framework/Variant.h"
1516
#include <boost/property_tree/ptree.hpp>
1617

1718
namespace o2::framework
1819
{
19-
namespace
20-
{
2120
template <typename T>
22-
auto basicVectorToBranch(T* values, size_t size)
21+
boost::property_tree::ptree basicVectorToBranch(T* values, size_t size)
2322
{
2423
boost::property_tree::ptree branch;
2524
for (auto i = 0u; i < size; ++i) {
@@ -31,30 +30,27 @@ auto basicVectorToBranch(T* values, size_t size)
3130
}
3231

3332
template <typename T>
34-
auto basicVectorToBranch(std::vector<T>&& values)
33+
boost::property_tree::ptree basicVectorToBranch(std::vector<T>&& values)
3534
{
3635
return basicVectorToBranch(values.data(), values.size());
3736
}
3837

3938
template <typename T>
40-
auto vectorToBranch(T* values, size_t size)
39+
boost::property_tree::ptree vectorToBranch(T* values, size_t size)
4140
{
4241
boost::property_tree::ptree branch;
4342
branch.put_child("values", basicVectorToBranch(values, size));
4443
return branch;
4544
}
46-
} // namespace
4745

4846
template <typename T>
49-
auto vectorToBranch(std::vector<T>&& values)
47+
boost::property_tree::ptree vectorToBranch(std::vector<T>&& values)
5048
{
5149
return vectorToBranch(values.data(), values.size());
5250
}
5351

54-
namespace
55-
{
5652
template <typename T>
57-
auto basicArray2DToBranch(Array2D<T>&& array)
53+
boost::property_tree::ptree basicArray2DToBranch(Array2D<T>&& array)
5854
{
5955
boost::property_tree::ptree subtree;
6056
for (auto i = 0u; i < array.rows; ++i) {
@@ -68,20 +64,17 @@ auto basicArray2DToBranch(Array2D<T>&& array)
6864
}
6965
return subtree;
7066
}
71-
} // namespace
7267

7368
template <typename T>
74-
auto array2DToBranch(Array2D<T>&& array)
69+
boost::property_tree::ptree array2DToBranch(Array2D<T>&& array)
7570
{
7671
boost::property_tree::ptree subtree;
7772
subtree.put_child("values", basicArray2DToBranch(std::forward<Array2D<T>>(array)));
7873
return subtree;
7974
}
8075

81-
namespace
82-
{
8376
template <typename T>
84-
auto basicVectorFromBranch(boost::property_tree::ptree const& branch)
77+
std::vector<T> basicVectorFromBranch(boost::property_tree::ptree const& branch)
8578
{
8679
std::vector<T> result(branch.size());
8780
auto count = 0U;
@@ -90,18 +83,15 @@ auto basicVectorFromBranch(boost::property_tree::ptree const& branch)
9083
}
9184
return result;
9285
}
93-
} // namespace
9486

9587
template <typename T>
96-
auto vectorFromBranch(boost::property_tree::ptree const& branch)
88+
std::vector<T> vectorFromBranch(boost::property_tree::ptree const& branch)
9789
{
9890
return basicVectorFromBranch<T>(branch.get_child("values"));
9991
}
10092

101-
namespace
102-
{
10393
template <typename T>
104-
auto basicArray2DFromBranch(boost::property_tree::ptree const& branch)
94+
Array2D<T> basicArray2DFromBranch(boost::property_tree::ptree const& branch)
10595
{
10696
std::vector<T> cache;
10797
uint32_t nrows = branch.size();
@@ -122,18 +112,17 @@ auto basicArray2DFromBranch(boost::property_tree::ptree const& branch)
122112
}
123113
return Array2D<T>{cache, nrows, ncols};
124114
}
125-
} // namespace
126115

127116
template <typename T>
128-
auto array2DFromBranch(boost::property_tree::ptree const& ptree)
117+
Array2D<T> array2DFromBranch(boost::property_tree::ptree const& ptree)
129118
{
130119
return basicArray2DFromBranch<T>(ptree.get_child("values"));
131120
}
132121

133122
std::pair<std::vector<std::string>, std::vector<std::string>> extractLabels(boost::property_tree::ptree const& tree);
134123

135124
template <typename T>
136-
auto labeledArrayFromBranch(boost::property_tree::ptree const& tree)
125+
LabeledArray<T> labeledArrayFromBranch(boost::property_tree::ptree const& tree)
137126
{
138127
auto [labels_rows, labels_cols] = extractLabels(tree);
139128
auto values = basicArray2DFromBranch<T>(tree.get_child("values"));
@@ -142,7 +131,7 @@ auto labeledArrayFromBranch(boost::property_tree::ptree const& tree)
142131
}
143132

144133
template <typename T>
145-
auto labeledArrayToBranch(LabeledArray<T>&& array)
134+
boost::property_tree::ptree labeledArrayToBranch(LabeledArray<T>&& array)
146135
{
147136
boost::property_tree::ptree subtree;
148137
subtree.put_child(labels_rows_str, basicVectorToBranch(array.getLabelsRows()));
@@ -153,4 +142,48 @@ auto labeledArrayToBranch(LabeledArray<T>&& array)
153142
}
154143
} // namespace o2::framework
155144

145+
extern template boost::property_tree::ptree o2::framework::basicVectorToBranch(std::vector<float>&& values);
146+
extern template boost::property_tree::ptree o2::framework::basicVectorToBranch(std::vector<int>&& values);
147+
extern template boost::property_tree::ptree o2::framework::basicVectorToBranch(std::vector<double>&& values);
148+
extern template boost::property_tree::ptree o2::framework::basicVectorToBranch(std::vector<std::string>&& values);
149+
extern template boost::property_tree::ptree o2::framework::basicVectorToBranch(float*, size_t);
150+
extern template boost::property_tree::ptree o2::framework::basicVectorToBranch(int*, size_t);
151+
extern template boost::property_tree::ptree o2::framework::basicVectorToBranch(double*, size_t);
152+
extern template boost::property_tree::ptree o2::framework::basicVectorToBranch(bool*, size_t);
153+
extern template boost::property_tree::ptree o2::framework::basicVectorToBranch(std::basic_string<char>*, size_t);
154+
155+
extern template boost::property_tree::ptree o2::framework::vectorToBranch(std::vector<float>&& values);
156+
extern template boost::property_tree::ptree o2::framework::vectorToBranch(std::vector<int>&& values);
157+
extern template boost::property_tree::ptree o2::framework::vectorToBranch(std::vector<double>&& values);
158+
extern template boost::property_tree::ptree o2::framework::vectorToBranch(std::vector<std::string>&& values);
159+
extern template boost::property_tree::ptree o2::framework::vectorToBranch(float*, size_t);
160+
extern template boost::property_tree::ptree o2::framework::vectorToBranch(int*, size_t);
161+
extern template boost::property_tree::ptree o2::framework::vectorToBranch(double*, size_t);
162+
extern template boost::property_tree::ptree o2::framework::vectorToBranch(bool*, size_t);
163+
extern template boost::property_tree::ptree o2::framework::vectorToBranch(std::basic_string<char>*, size_t);
164+
165+
extern template boost::property_tree::ptree o2::framework::labeledArrayToBranch(o2::framework::LabeledArray<float>&& array);
166+
extern template boost::property_tree::ptree o2::framework::labeledArrayToBranch(o2::framework::LabeledArray<int>&& array);
167+
extern template boost::property_tree::ptree o2::framework::labeledArrayToBranch(o2::framework::LabeledArray<double>&& array);
168+
extern template boost::property_tree::ptree o2::framework::labeledArrayToBranch(o2::framework::LabeledArray<std::string>&& array);
169+
170+
extern template std::vector<float> o2::framework::basicVectorFromBranch<float>(boost::property_tree::ptree const& tree);
171+
extern template std::vector<int> o2::framework::basicVectorFromBranch<int>(boost::property_tree::ptree const& tree);
172+
extern template std::vector<std::basic_string<char>> o2::framework::basicVectorFromBranch<std::basic_string<char>>(boost::property_tree::ptree const& tree);
173+
extern template std::vector<double> o2::framework::basicVectorFromBranch<double>(boost::property_tree::ptree const& tree);
174+
175+
extern template o2::framework::LabeledArray<float> o2::framework::labeledArrayFromBranch<float>(boost::property_tree::ptree const& tree);
176+
extern template o2::framework::LabeledArray<int> o2::framework::labeledArrayFromBranch<int>(boost::property_tree::ptree const& tree);
177+
extern template o2::framework::LabeledArray<std::string> o2::framework::labeledArrayFromBranch<std::string>(boost::property_tree::ptree const& tree);
178+
extern template o2::framework::LabeledArray<double> o2::framework::labeledArrayFromBranch<double>(boost::property_tree::ptree const& tree);
179+
180+
extern template o2::framework::Array2D<float> o2::framework::array2DFromBranch<float>(boost::property_tree::ptree const& tree);
181+
extern template o2::framework::Array2D<int> o2::framework::array2DFromBranch<int>(boost::property_tree::ptree const& tree);
182+
extern template o2::framework::Array2D<std::string> o2::framework::array2DFromBranch<std::string>(boost::property_tree::ptree const& tree);
183+
extern template o2::framework::Array2D<double> o2::framework::array2DFromBranch<double>(boost::property_tree::ptree const& tree);
184+
185+
extern template boost::property_tree::ptree o2::framework::array2DToBranch(o2::framework::Array2D<float>&& array);
186+
extern template boost::property_tree::ptree o2::framework::array2DToBranch(o2::framework::Array2D<int>&& array);
187+
extern template boost::property_tree::ptree o2::framework::array2DToBranch(o2::framework::Array2D<double>&& array);
188+
extern template boost::property_tree::ptree o2::framework::array2DToBranch(o2::framework::Array2D<std::string>&& array);
156189
#endif // FRAMEWORK_VARIANTPTREEHELPERS_H
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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 "Framework/VariantPropertyTreeHelpers.h"
13+
14+
template boost::property_tree::ptree o2::framework::basicVectorToBranch(std::vector<float>&& values);
15+
template boost::property_tree::ptree o2::framework::basicVectorToBranch(std::vector<int>&& values);
16+
template boost::property_tree::ptree o2::framework::basicVectorToBranch(std::vector<double>&& values);
17+
template boost::property_tree::ptree o2::framework::basicVectorToBranch(std::vector<std::string>&& values);
18+
template boost::property_tree::ptree o2::framework::basicVectorToBranch(float*, size_t);
19+
template boost::property_tree::ptree o2::framework::basicVectorToBranch(int*, size_t);
20+
template boost::property_tree::ptree o2::framework::basicVectorToBranch(double*, size_t);
21+
template boost::property_tree::ptree o2::framework::basicVectorToBranch(bool*, size_t);
22+
template boost::property_tree::ptree o2::framework::basicVectorToBranch(std::basic_string<char>*, size_t);
23+
24+
template boost::property_tree::ptree o2::framework::vectorToBranch(std::vector<float>&& values);
25+
template boost::property_tree::ptree o2::framework::vectorToBranch(std::vector<int>&& values);
26+
template boost::property_tree::ptree o2::framework::vectorToBranch(std::vector<double>&& values);
27+
template boost::property_tree::ptree o2::framework::vectorToBranch(std::vector<std::string>&& values);
28+
template boost::property_tree::ptree o2::framework::vectorToBranch(float*, size_t);
29+
template boost::property_tree::ptree o2::framework::vectorToBranch(int*, size_t);
30+
template boost::property_tree::ptree o2::framework::vectorToBranch(double*, size_t);
31+
template boost::property_tree::ptree o2::framework::vectorToBranch(bool*, size_t);
32+
template boost::property_tree::ptree o2::framework::vectorToBranch(std::basic_string<char>*, size_t);
33+
34+
template boost::property_tree::ptree o2::framework::labeledArrayToBranch(o2::framework::LabeledArray<float>&& array);
35+
template boost::property_tree::ptree o2::framework::labeledArrayToBranch(o2::framework::LabeledArray<int>&& array);
36+
template boost::property_tree::ptree o2::framework::labeledArrayToBranch(o2::framework::LabeledArray<double>&& array);
37+
template boost::property_tree::ptree o2::framework::labeledArrayToBranch(o2::framework::LabeledArray<std::string>&& array);
38+
39+
template std::vector<float> o2::framework::basicVectorFromBranch<float>(boost::property_tree::ptree const& tree);
40+
template std::vector<int> o2::framework::basicVectorFromBranch<int>(boost::property_tree::ptree const& tree);
41+
template std::vector<std::basic_string<char>> o2::framework::basicVectorFromBranch<std::basic_string<char>>(boost::property_tree::ptree const& tree);
42+
template std::vector<double> o2::framework::basicVectorFromBranch<double>(boost::property_tree::ptree const& tree);
43+
44+
template o2::framework::LabeledArray<float> o2::framework::labeledArrayFromBranch<float>(boost::property_tree::ptree const& tree);
45+
template o2::framework::LabeledArray<int> o2::framework::labeledArrayFromBranch<int>(boost::property_tree::ptree const& tree);
46+
template o2::framework::LabeledArray<std::string> o2::framework::labeledArrayFromBranch<std::string>(boost::property_tree::ptree const& tree);
47+
template o2::framework::LabeledArray<double> o2::framework::labeledArrayFromBranch<double>(boost::property_tree::ptree const& tree);
48+
49+
template o2::framework::Array2D<float> o2::framework::array2DFromBranch<float>(boost::property_tree::ptree const& tree);
50+
template o2::framework::Array2D<int> o2::framework::array2DFromBranch<int>(boost::property_tree::ptree const& tree);
51+
template o2::framework::Array2D<std::string> o2::framework::array2DFromBranch<std::string>(boost::property_tree::ptree const& tree);
52+
template o2::framework::Array2D<double> o2::framework::array2DFromBranch<double>(boost::property_tree::ptree const& tree);
53+
54+
template boost::property_tree::ptree o2::framework::array2DToBranch(o2::framework::Array2D<float>&& array);
55+
template boost::property_tree::ptree o2::framework::array2DToBranch(o2::framework::Array2D<int>&& array);
56+
template boost::property_tree::ptree o2::framework::array2DToBranch(o2::framework::Array2D<double>&& array);
57+
template boost::property_tree::ptree o2::framework::array2DToBranch(o2::framework::Array2D<std::string>&& array);

0 commit comments

Comments
 (0)