Project
Loading...
Searching...
No Matches
VariantPropertyTreeHelpers.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#ifndef FRAMEWORK_VARIANTPTREEHELPERS_H
12#define FRAMEWORK_VARIANTPTREEHELPERS_H
13
14#include "Array2D.h"
15#include "Framework/Variant.h"
16#include <boost/property_tree/ptree.hpp>
17
18namespace o2::framework
19{
20template <typename T>
21boost::property_tree::ptree basicVectorToBranch(T* values, size_t size)
22{
23 boost::property_tree::ptree branch;
24 for (auto i = 0u; i < size; ++i) {
25 boost::property_tree::ptree leaf;
26 leaf.put("", values[i]);
27 branch.push_back(std::make_pair("", leaf));
28 }
29 return branch;
30}
31
32template <typename T>
33boost::property_tree::ptree basicVectorToBranch(std::vector<T>&& values)
34{
35 return basicVectorToBranch(values.data(), values.size());
36}
37
38template <typename T>
39boost::property_tree::ptree vectorToBranch(T* values, size_t size)
40{
41 boost::property_tree::ptree branch;
42 branch.put_child("values", basicVectorToBranch(values, size));
43 return branch;
44}
45
46template <typename T>
47boost::property_tree::ptree vectorToBranch(std::vector<T>&& values)
48{
49 return vectorToBranch(values.data(), values.size());
50}
51
52template <typename T>
53boost::property_tree::ptree basicArray2DToBranch(Array2D<T>&& array)
54{
55 boost::property_tree::ptree subtree;
56 for (auto i = 0u; i < array.rows; ++i) {
57 boost::property_tree::ptree branch;
58 for (auto j = 0u; j < array.cols; ++j) {
59 boost::property_tree::ptree leaf;
60 leaf.put("", array(i, j));
61 branch.push_back(std::make_pair("", leaf));
62 }
63 subtree.push_back(std::make_pair("", branch));
64 }
65 return subtree;
66}
67
68template <typename T>
69boost::property_tree::ptree array2DToBranch(Array2D<T>&& array)
70{
71 boost::property_tree::ptree subtree;
72 subtree.put_child("values", basicArray2DToBranch(std::forward<Array2D<T>>(array)));
73 return subtree;
74}
75
76template <typename T>
77std::vector<T> basicVectorFromBranch(boost::property_tree::ptree const& branch)
78{
79 std::vector<T> result(branch.size());
80 auto count = 0U;
81 for (auto const& entry : branch) {
82 result[count++] = entry.second.get_value<T>();
83 }
84 return result;
85}
86
87template <typename T>
88std::vector<T> vectorFromBranch(boost::property_tree::ptree const& branch)
89{
90 return basicVectorFromBranch<T>(branch.get_child("values"));
91}
92
93template <typename T>
94Array2D<T> basicArray2DFromBranch(boost::property_tree::ptree const& branch)
95{
96 std::vector<T> cache;
97 uint32_t nrows = branch.size();
98 uint32_t ncols = 0;
99 bool first = true;
100 auto irow = 0u;
101 for (auto const& row : branch) {
102 if (first) {
103 ncols = row.second.size();
104 first = false;
105 }
106 auto icol = 0u;
107 for (auto const& entry : row.second) {
108 cache.push_back(entry.second.get_value<T>());
109 ++icol;
110 }
111 ++irow;
112 }
113 return Array2D<T>{cache, nrows, ncols};
114}
115
116template <typename T>
117Array2D<T> array2DFromBranch(boost::property_tree::ptree const& ptree)
118{
119 return basicArray2DFromBranch<T>(ptree.get_child("values"));
120}
121
122std::pair<std::vector<std::string>, std::vector<std::string>> extractLabels(boost::property_tree::ptree const& tree);
123
124template <typename T>
125LabeledArray<T> labeledArrayFromBranch(boost::property_tree::ptree const& tree)
126{
128 auto values = basicArray2DFromBranch<T>(tree.get_child("values"));
129
131}
132
133template <typename T>
134boost::property_tree::ptree labeledArrayToBranch(LabeledArray<T>&& array)
135{
136 boost::property_tree::ptree subtree;
137 subtree.put_child(labels_rows_str, basicVectorToBranch(array.getLabelsRows()));
138 subtree.put_child(labels_cols_str, basicVectorToBranch(array.getLabelsCols()));
139 subtree.put_child("values", basicArray2DToBranch(array.getData()));
140
141 return subtree;
142}
143} // namespace o2::framework
144
145extern template boost::property_tree::ptree o2::framework::basicVectorToBranch(std::vector<float>&& values);
146extern template boost::property_tree::ptree o2::framework::basicVectorToBranch(std::vector<int>&& values);
147extern template boost::property_tree::ptree o2::framework::basicVectorToBranch(std::vector<double>&& values);
148extern template boost::property_tree::ptree o2::framework::basicVectorToBranch(std::vector<std::string>&& values);
149extern template boost::property_tree::ptree o2::framework::basicVectorToBranch(float*, size_t);
150extern template boost::property_tree::ptree o2::framework::basicVectorToBranch(int*, size_t);
151extern template boost::property_tree::ptree o2::framework::basicVectorToBranch(double*, size_t);
152extern template boost::property_tree::ptree o2::framework::basicVectorToBranch(bool*, size_t);
153extern template boost::property_tree::ptree o2::framework::basicVectorToBranch(std::basic_string<char>*, size_t);
154
155extern template boost::property_tree::ptree o2::framework::vectorToBranch(std::vector<float>&& values);
156extern template boost::property_tree::ptree o2::framework::vectorToBranch(std::vector<int>&& values);
157extern template boost::property_tree::ptree o2::framework::vectorToBranch(std::vector<double>&& values);
158extern template boost::property_tree::ptree o2::framework::vectorToBranch(std::vector<std::string>&& values);
159extern template boost::property_tree::ptree o2::framework::vectorToBranch(float*, size_t);
160extern template boost::property_tree::ptree o2::framework::vectorToBranch(int*, size_t);
161extern template boost::property_tree::ptree o2::framework::vectorToBranch(double*, size_t);
162extern template boost::property_tree::ptree o2::framework::vectorToBranch(bool*, size_t);
163extern template boost::property_tree::ptree o2::framework::vectorToBranch(std::basic_string<char>*, size_t);
164
165extern template boost::property_tree::ptree o2::framework::labeledArrayToBranch(o2::framework::LabeledArray<float>&& array);
166extern template boost::property_tree::ptree o2::framework::labeledArrayToBranch(o2::framework::LabeledArray<int>&& array);
167extern template boost::property_tree::ptree o2::framework::labeledArrayToBranch(o2::framework::LabeledArray<double>&& array);
168extern template boost::property_tree::ptree o2::framework::labeledArrayToBranch(o2::framework::LabeledArray<std::string>&& array);
169
170extern template std::vector<float> o2::framework::basicVectorFromBranch<float>(boost::property_tree::ptree const& tree);
171extern template std::vector<int> o2::framework::basicVectorFromBranch<int>(boost::property_tree::ptree const& tree);
172extern template std::vector<std::basic_string<char>> o2::framework::basicVectorFromBranch<std::basic_string<char>>(boost::property_tree::ptree const& tree);
173extern template std::vector<double> o2::framework::basicVectorFromBranch<double>(boost::property_tree::ptree const& tree);
174
175extern template o2::framework::LabeledArray<float> o2::framework::labeledArrayFromBranch<float>(boost::property_tree::ptree const& tree);
176extern template o2::framework::LabeledArray<int> o2::framework::labeledArrayFromBranch<int>(boost::property_tree::ptree const& tree);
177extern template o2::framework::LabeledArray<std::string> o2::framework::labeledArrayFromBranch<std::string>(boost::property_tree::ptree const& tree);
178extern template o2::framework::LabeledArray<double> o2::framework::labeledArrayFromBranch<double>(boost::property_tree::ptree const& tree);
179
180extern template o2::framework::Array2D<float> o2::framework::array2DFromBranch<float>(boost::property_tree::ptree const& tree);
181extern template o2::framework::Array2D<int> o2::framework::array2DFromBranch<int>(boost::property_tree::ptree const& tree);
182extern template o2::framework::Array2D<std::string> o2::framework::array2DFromBranch<std::string>(boost::property_tree::ptree const& tree);
183extern template o2::framework::Array2D<double> o2::framework::array2DFromBranch<double>(boost::property_tree::ptree const& tree);
184
185extern template boost::property_tree::ptree o2::framework::array2DToBranch(o2::framework::Array2D<float>&& array);
186extern template boost::property_tree::ptree o2::framework::array2DToBranch(o2::framework::Array2D<int>&& array);
187extern template boost::property_tree::ptree o2::framework::array2DToBranch(o2::framework::Array2D<double>&& array);
188extern template boost::property_tree::ptree o2::framework::array2DToBranch(o2::framework::Array2D<std::string>&& array);
189#endif // FRAMEWORK_VARIANTPTREEHELPERS_H
int32_t i
uint32_t j
Definition RawData.h:0
std::vector< std::string > labels_rows
std::vector< std::string > labels_cols
GLint GLsizei count
Definition glcorearb.h:399
GLuint64EXT * result
Definition glcorearb.h:5662
GLuint entry
Definition glcorearb.h:5735
GLsizeiptr size
Definition glcorearb.h:659
GLenum array
Definition glcorearb.h:4274
GLenum GLsizei GLsizei GLint * values
Definition glcorearb.h:1576
Defining PrimaryVertex explicitly as messageable.
Definition TFIDInfo.h:20
LabeledArray< T > labeledArrayFromBranch(boost::property_tree::ptree const &tree)
Array2D< T > basicArray2DFromBranch(boost::property_tree::ptree const &branch)
boost::property_tree::ptree labeledArrayToBranch(LabeledArray< T > &&array)
boost::property_tree::ptree basicVectorToBranch(T *values, size_t size)
boost::property_tree::ptree basicArray2DToBranch(Array2D< T > &&array)
std::pair< std::vector< std::string >, std::vector< std::string > > extractLabels(boost::property_tree::ptree const &tree)
Definition Variant.cxx:233
boost::property_tree::ptree vectorToBranch(T *values, size_t size)
boost::property_tree::ptree array2DToBranch(Array2D< T > &&array)
Array2D< T > array2DFromBranch(boost::property_tree::ptree const &ptree)
std::vector< T > vectorFromBranch(boost::property_tree::ptree const &branch)
std::vector< T > basicVectorFromBranch(boost::property_tree::ptree const &branch)
std::unique_ptr< TTree > tree((TTree *) flIn.Get(std::string(o2::base::NameConf::CTFTREENAME).c_str()))
std::vector< int > row