Project
Loading...
Searching...
No Matches
RootConfigParamHelpers.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 O2_FRAMEWORK_ROOTCONFIGPARAMHELPERS_H_
12#define O2_FRAMEWORK_ROOTCONFIGPARAMHELPERS_H_
13
16#include <TClass.h>
17#include <boost/property_tree/ptree_fwd.hpp>
18#include <type_traits>
19#include <typeinfo>
20
21namespace o2::framework
22{
23
26 static std::vector<ConfigParamSpec> asConfigParamSpecsImpl(std::string const& mainkey, TClass* cl, void* obj);
29 static void fillFromPtree(TClass* cl, void* obj, boost::property_tree::ptree const& pt);
30
31 // Grab the list of data members of a type T and construct the list of
32 // associated ConfigParamSpec. Optionally provide a prototype object @a proto
33 // to use for the defaults.
34 template <typename T>
35 static std::vector<ConfigParamSpec> asConfigParamSpecs(std::string const& mainKey, T const& proto = T{})
36 {
37 auto cl = TClass::GetClass<T>();
38 if (!cl) {
39 throw runtime_error_f("Unable to convert object %s", typeid(T).name());
40 }
41
42 return asConfigParamSpecsImpl(mainKey, cl, reinterpret_cast<void*>(const_cast<T*>(&proto)));
43 }
44
48 template <typename T>
49 static T as(boost::property_tree::ptree const& pt)
50 {
51 T obj;
52 TClass* cl = TClass::GetClass<T>();
53 fillFromPtree(cl, reinterpret_cast<void*>(&obj), pt);
54 return obj;
55 }
56};
57
58} // namespace o2::framework
59
60#endif /* O2_FRAMEWORK_ROOTCONFIGPARAMHELPERS_H_ */
GLuint const GLchar * name
Definition glcorearb.h:781
Defining PrimaryVertex explicitly as messageable.
Definition TFIDInfo.h:20
RuntimeErrorRef runtime_error_f(const char *,...)
Helpers to Serialise / Deserialise ROOT objects using the ConfigParamSpec mechanism.
static std::vector< ConfigParamSpec > asConfigParamSpecsImpl(std::string const &mainkey, TClass *cl, void *obj)
static std::vector< ConfigParamSpec > asConfigParamSpecs(std::string const &mainKey, T const &proto=T{})
static void fillFromPtree(TClass *cl, void *obj, boost::property_tree::ptree const &pt)
static T as(boost::property_tree::ptree const &pt)