Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DPL: move a bunch of Variant helpers out of line #13840

Merged
merged 1 commit into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Framework/Core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ o2_add_library(Framework
src/Task.cxx
src/Array2D.cxx
src/Variant.cxx
src/VariantPropertyTreeHelpers.cxx
src/WorkflowCustomizationHelpers.cxx
src/WorkflowHelpers.cxx
src/WorkflowSerializationHelpers.cxx
Expand Down
81 changes: 57 additions & 24 deletions Framework/Core/include/Framework/VariantPropertyTreeHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,14 @@
#ifndef FRAMEWORK_VARIANTPTREEHELPERS_H
#define FRAMEWORK_VARIANTPTREEHELPERS_H

#include "Array2D.h"
#include "Framework/Variant.h"
#include <boost/property_tree/ptree.hpp>

namespace o2::framework
{
namespace
{
template <typename T>
auto basicVectorToBranch(T* values, size_t size)
boost::property_tree::ptree basicVectorToBranch(T* values, size_t size)
{
boost::property_tree::ptree branch;
for (auto i = 0u; i < size; ++i) {
Expand All @@ -31,30 +30,27 @@ auto basicVectorToBranch(T* values, size_t size)
}

template <typename T>
auto basicVectorToBranch(std::vector<T>&& values)
boost::property_tree::ptree basicVectorToBranch(std::vector<T>&& values)
{
return basicVectorToBranch(values.data(), values.size());
}

template <typename T>
auto vectorToBranch(T* values, size_t size)
boost::property_tree::ptree vectorToBranch(T* values, size_t size)
{
boost::property_tree::ptree branch;
branch.put_child("values", basicVectorToBranch(values, size));
return branch;
}
} // namespace

template <typename T>
auto vectorToBranch(std::vector<T>&& values)
boost::property_tree::ptree vectorToBranch(std::vector<T>&& values)
{
return vectorToBranch(values.data(), values.size());
}

namespace
{
template <typename T>
auto basicArray2DToBranch(Array2D<T>&& array)
boost::property_tree::ptree basicArray2DToBranch(Array2D<T>&& array)
{
boost::property_tree::ptree subtree;
for (auto i = 0u; i < array.rows; ++i) {
Expand All @@ -68,20 +64,17 @@ auto basicArray2DToBranch(Array2D<T>&& array)
}
return subtree;
}
} // namespace

template <typename T>
auto array2DToBranch(Array2D<T>&& array)
boost::property_tree::ptree array2DToBranch(Array2D<T>&& array)
{
boost::property_tree::ptree subtree;
subtree.put_child("values", basicArray2DToBranch(std::forward<Array2D<T>>(array)));
return subtree;
}

namespace
{
template <typename T>
auto basicVectorFromBranch(boost::property_tree::ptree const& branch)
std::vector<T> basicVectorFromBranch(boost::property_tree::ptree const& branch)
{
std::vector<T> result(branch.size());
auto count = 0U;
Expand All @@ -90,18 +83,15 @@ auto basicVectorFromBranch(boost::property_tree::ptree const& branch)
}
return result;
}
} // namespace

template <typename T>
auto vectorFromBranch(boost::property_tree::ptree const& branch)
std::vector<T> vectorFromBranch(boost::property_tree::ptree const& branch)
{
return basicVectorFromBranch<T>(branch.get_child("values"));
}

namespace
{
template <typename T>
auto basicArray2DFromBranch(boost::property_tree::ptree const& branch)
Array2D<T> basicArray2DFromBranch(boost::property_tree::ptree const& branch)
{
std::vector<T> cache;
uint32_t nrows = branch.size();
Expand All @@ -122,18 +112,17 @@ auto basicArray2DFromBranch(boost::property_tree::ptree const& branch)
}
return Array2D<T>{cache, nrows, ncols};
}
} // namespace

template <typename T>
auto array2DFromBranch(boost::property_tree::ptree const& ptree)
Array2D<T> array2DFromBranch(boost::property_tree::ptree const& ptree)
{
return basicArray2DFromBranch<T>(ptree.get_child("values"));
}

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

template <typename T>
auto labeledArrayFromBranch(boost::property_tree::ptree const& tree)
LabeledArray<T> labeledArrayFromBranch(boost::property_tree::ptree const& tree)
{
auto [labels_rows, labels_cols] = extractLabels(tree);
auto values = basicArray2DFromBranch<T>(tree.get_child("values"));
Expand All @@ -142,7 +131,7 @@ auto labeledArrayFromBranch(boost::property_tree::ptree const& tree)
}

template <typename T>
auto labeledArrayToBranch(LabeledArray<T>&& array)
boost::property_tree::ptree labeledArrayToBranch(LabeledArray<T>&& array)
{
boost::property_tree::ptree subtree;
subtree.put_child(labels_rows_str, basicVectorToBranch(array.getLabelsRows()));
Expand All @@ -153,4 +142,48 @@ auto labeledArrayToBranch(LabeledArray<T>&& array)
}
} // namespace o2::framework

extern template boost::property_tree::ptree o2::framework::basicVectorToBranch(std::vector<float>&& values);
extern template boost::property_tree::ptree o2::framework::basicVectorToBranch(std::vector<int>&& values);
extern template boost::property_tree::ptree o2::framework::basicVectorToBranch(std::vector<double>&& values);
extern template boost::property_tree::ptree o2::framework::basicVectorToBranch(std::vector<std::string>&& values);
extern template boost::property_tree::ptree o2::framework::basicVectorToBranch(float*, size_t);
extern template boost::property_tree::ptree o2::framework::basicVectorToBranch(int*, size_t);
extern template boost::property_tree::ptree o2::framework::basicVectorToBranch(double*, size_t);
extern template boost::property_tree::ptree o2::framework::basicVectorToBranch(bool*, size_t);
extern template boost::property_tree::ptree o2::framework::basicVectorToBranch(std::basic_string<char>*, size_t);

extern template boost::property_tree::ptree o2::framework::vectorToBranch(std::vector<float>&& values);
extern template boost::property_tree::ptree o2::framework::vectorToBranch(std::vector<int>&& values);
extern template boost::property_tree::ptree o2::framework::vectorToBranch(std::vector<double>&& values);
extern template boost::property_tree::ptree o2::framework::vectorToBranch(std::vector<std::string>&& values);
extern template boost::property_tree::ptree o2::framework::vectorToBranch(float*, size_t);
extern template boost::property_tree::ptree o2::framework::vectorToBranch(int*, size_t);
extern template boost::property_tree::ptree o2::framework::vectorToBranch(double*, size_t);
extern template boost::property_tree::ptree o2::framework::vectorToBranch(bool*, size_t);
extern template boost::property_tree::ptree o2::framework::vectorToBranch(std::basic_string<char>*, size_t);

extern template boost::property_tree::ptree o2::framework::labeledArrayToBranch(o2::framework::LabeledArray<float>&& array);
extern template boost::property_tree::ptree o2::framework::labeledArrayToBranch(o2::framework::LabeledArray<int>&& array);
extern template boost::property_tree::ptree o2::framework::labeledArrayToBranch(o2::framework::LabeledArray<double>&& array);
extern template boost::property_tree::ptree o2::framework::labeledArrayToBranch(o2::framework::LabeledArray<std::string>&& array);

extern template std::vector<float> o2::framework::basicVectorFromBranch<float>(boost::property_tree::ptree const& tree);
extern template std::vector<int> o2::framework::basicVectorFromBranch<int>(boost::property_tree::ptree const& tree);
extern template std::vector<std::basic_string<char>> o2::framework::basicVectorFromBranch<std::basic_string<char>>(boost::property_tree::ptree const& tree);
extern template std::vector<double> o2::framework::basicVectorFromBranch<double>(boost::property_tree::ptree const& tree);

extern template o2::framework::LabeledArray<float> o2::framework::labeledArrayFromBranch<float>(boost::property_tree::ptree const& tree);
extern template o2::framework::LabeledArray<int> o2::framework::labeledArrayFromBranch<int>(boost::property_tree::ptree const& tree);
extern template o2::framework::LabeledArray<std::string> o2::framework::labeledArrayFromBranch<std::string>(boost::property_tree::ptree const& tree);
extern template o2::framework::LabeledArray<double> o2::framework::labeledArrayFromBranch<double>(boost::property_tree::ptree const& tree);

extern template o2::framework::Array2D<float> o2::framework::array2DFromBranch<float>(boost::property_tree::ptree const& tree);
extern template o2::framework::Array2D<int> o2::framework::array2DFromBranch<int>(boost::property_tree::ptree const& tree);
extern template o2::framework::Array2D<std::string> o2::framework::array2DFromBranch<std::string>(boost::property_tree::ptree const& tree);
extern template o2::framework::Array2D<double> o2::framework::array2DFromBranch<double>(boost::property_tree::ptree const& tree);

extern template boost::property_tree::ptree o2::framework::array2DToBranch(o2::framework::Array2D<float>&& array);
extern template boost::property_tree::ptree o2::framework::array2DToBranch(o2::framework::Array2D<int>&& array);
extern template boost::property_tree::ptree o2::framework::array2DToBranch(o2::framework::Array2D<double>&& array);
extern template boost::property_tree::ptree o2::framework::array2DToBranch(o2::framework::Array2D<std::string>&& array);
#endif // FRAMEWORK_VARIANTPTREEHELPERS_H
57 changes: 57 additions & 0 deletions Framework/Core/src/VariantPropertyTreeHelpers.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// 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.

#include "Framework/VariantPropertyTreeHelpers.h"

template boost::property_tree::ptree o2::framework::basicVectorToBranch(std::vector<float>&& values);
template boost::property_tree::ptree o2::framework::basicVectorToBranch(std::vector<int>&& values);
template boost::property_tree::ptree o2::framework::basicVectorToBranch(std::vector<double>&& values);
template boost::property_tree::ptree o2::framework::basicVectorToBranch(std::vector<std::string>&& values);
template boost::property_tree::ptree o2::framework::basicVectorToBranch(float*, size_t);
template boost::property_tree::ptree o2::framework::basicVectorToBranch(int*, size_t);
template boost::property_tree::ptree o2::framework::basicVectorToBranch(double*, size_t);
template boost::property_tree::ptree o2::framework::basicVectorToBranch(bool*, size_t);
template boost::property_tree::ptree o2::framework::basicVectorToBranch(std::basic_string<char>*, size_t);

template boost::property_tree::ptree o2::framework::vectorToBranch(std::vector<float>&& values);
template boost::property_tree::ptree o2::framework::vectorToBranch(std::vector<int>&& values);
template boost::property_tree::ptree o2::framework::vectorToBranch(std::vector<double>&& values);
template boost::property_tree::ptree o2::framework::vectorToBranch(std::vector<std::string>&& values);
template boost::property_tree::ptree o2::framework::vectorToBranch(float*, size_t);
template boost::property_tree::ptree o2::framework::vectorToBranch(int*, size_t);
template boost::property_tree::ptree o2::framework::vectorToBranch(double*, size_t);
template boost::property_tree::ptree o2::framework::vectorToBranch(bool*, size_t);
template boost::property_tree::ptree o2::framework::vectorToBranch(std::basic_string<char>*, size_t);

template boost::property_tree::ptree o2::framework::labeledArrayToBranch(o2::framework::LabeledArray<float>&& array);
template boost::property_tree::ptree o2::framework::labeledArrayToBranch(o2::framework::LabeledArray<int>&& array);
template boost::property_tree::ptree o2::framework::labeledArrayToBranch(o2::framework::LabeledArray<double>&& array);
template boost::property_tree::ptree o2::framework::labeledArrayToBranch(o2::framework::LabeledArray<std::string>&& array);

template std::vector<float> o2::framework::basicVectorFromBranch<float>(boost::property_tree::ptree const& tree);
template std::vector<int> o2::framework::basicVectorFromBranch<int>(boost::property_tree::ptree const& tree);
template std::vector<std::basic_string<char>> o2::framework::basicVectorFromBranch<std::basic_string<char>>(boost::property_tree::ptree const& tree);
template std::vector<double> o2::framework::basicVectorFromBranch<double>(boost::property_tree::ptree const& tree);

template o2::framework::LabeledArray<float> o2::framework::labeledArrayFromBranch<float>(boost::property_tree::ptree const& tree);
template o2::framework::LabeledArray<int> o2::framework::labeledArrayFromBranch<int>(boost::property_tree::ptree const& tree);
template o2::framework::LabeledArray<std::string> o2::framework::labeledArrayFromBranch<std::string>(boost::property_tree::ptree const& tree);
template o2::framework::LabeledArray<double> o2::framework::labeledArrayFromBranch<double>(boost::property_tree::ptree const& tree);

template o2::framework::Array2D<float> o2::framework::array2DFromBranch<float>(boost::property_tree::ptree const& tree);
template o2::framework::Array2D<int> o2::framework::array2DFromBranch<int>(boost::property_tree::ptree const& tree);
template o2::framework::Array2D<std::string> o2::framework::array2DFromBranch<std::string>(boost::property_tree::ptree const& tree);
template o2::framework::Array2D<double> o2::framework::array2DFromBranch<double>(boost::property_tree::ptree const& tree);

template boost::property_tree::ptree o2::framework::array2DToBranch(o2::framework::Array2D<float>&& array);
template boost::property_tree::ptree o2::framework::array2DToBranch(o2::framework::Array2D<int>&& array);
template boost::property_tree::ptree o2::framework::array2DToBranch(o2::framework::Array2D<double>&& array);
template boost::property_tree::ptree o2::framework::array2DToBranch(o2::framework::Array2D<std::string>&& array);
Loading