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
1718namespace o2 ::framework
1819{
19- namespace
20- {
2120template <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
3332template <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
3938template <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
4846template <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- {
5652template <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
7368template <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- {
8376template <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
9587template <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- {
10393template <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
127116template <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
133122std::pair<std::vector<std::string>, std::vector<std::string>> extractLabels (boost::property_tree::ptree const & tree);
134123
135124template <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
144133template <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
0 commit comments