|
DAS
3.0
Das Analysis System
|
Go to the documentation of this file. 1 #ifndef DARWIN_USERINFO_H
2 #define DARWIN_USERINFO_H
17 #include <TParameter.h>
18 #include <TObjString.h>
20 #include <boost/property_tree/ptree.hpp>
21 #include <boost/exception/all.hpp>
68 TList *
List (TList * mother,
const char *
key)
const;
75 template<
class T> T
Get (TList * mother,
const char *
key)
const
77 if constexpr (std::is_arithmetic_v<T>) {
78 TObject * obj = mother->FindObject(
key);
79 auto parameter =
dynamic_cast<TParameter<T>*
>(obj);
80 if (parameter ==
nullptr)
81 BOOST_THROW_EXCEPTION(std::invalid_argument(
82 Form(
"No `TParameter` with name '%s' could be found in the `TList` '%s'.",
key, mother->GetName())));
83 return parameter->GetVal();
86 TList * daughter =
List(mother,
key);
87 TIter next(daughter->begin());
88 auto objs =
dynamic_cast<TObjString*
>(daughter->Last());
89 if (daughter->GetSize() == 0 || objs ==
nullptr)
90 BOOST_THROW_EXCEPTION(std::invalid_argument(
91 Form(
"No literal with name '%s' was found in the `TList` '%s'.",
key, mother->GetName())));
92 T literal = objs->GetString().Data();
99 template<
class T,
typename... Args> T
Get (TList * mother,
const char *
key, Args...
args)
const
101 TList * daughter =
List(mother,
key);
102 return Get<T>(daughter,
args...);
107 bool Find (TList * mother,
const char *
key)
const
109 TObject * obj = mother->FindObject(
key);
110 return (obj !=
nullptr);
115 template<
typename... Args>
bool Find (TList * mother,
const char *
key, Args...
args)
const
117 if (!
Find(mother,
key))
return false;
118 TList * daughter =
List(mother,
key);
119 if (daughter->GetSize() > 0)
129 template<
class T>
void Set (TList * mother,
const char *
key, T value)
const
131 if constexpr (std::is_arithmetic_v<T>) {
132 TObject * obj = mother->FindObject(
key);
134 auto parameter =
dynamic_cast<TParameter<T>*
>(obj);
135 if (parameter ==
nullptr)
136 BOOST_THROW_EXCEPTION(std::invalid_argument(
137 Form(
"No `TParameter` with name '%s' and typeid '%s' was found in the `TList` '%s'.",
138 key,
typeid(T).
name(), mother->GetName())));
139 parameter->SetVal(value);
142 auto parameter =
new TParameter<T>(
key, value,
'l');
143 mother->Add(parameter);
147 TList * daughter =
List(mother,
key);
149 auto objs =
new TObjString(str);
156 template<
class T,
typename... Args>
void Set (TList * mother,
const char *
key, Args...
args)
const
158 TList * daughter =
List(mother,
key);
159 Set<T>(daughter,
args...);
164 template<
typename... Args> TList *
List (TList * mother,
const char *
key, Args...
args)
const
166 TList * daughter =
List(mother,
key);
171 inline T
Get (TList * mother, std::string
key)
const {
return Get<T>(mother,
key.c_str()); }
172 inline bool Find (TList * mother, std::string
key)
const {
return Find (mother,
key.c_str()); }
173 inline TList *
List (TList * mother, std::string
key)
const {
return List (mother,
key.c_str()); }
178 void ConvertPtree (
const boost::property_tree::ptree&,
const std::string&, TList*);
194 template<
typename... Args> TList *
List (
const char *
key, Args...
args)
const
208 template<
class T,
typename... Args> T
Get (
const char *
key, Args...
args)
const
215 template<
typename... Args>
bool Find (
const char *
key, Args...
args)
const
224 template<
class T,
typename... Args>
void Set (
const char *
key, Args...
args)
const
233 UserInfo (TTree *,
const boost::property_tree::ptree&);
243 boost::property_tree::ptree
Write (std::ostream&,
251 boost::property_tree::ptree
Write (
const std::filesystem::path&
259 )
const {
return MkPtree(
l, format); }
263 inline void ls ()
const {
if (
l !=
nullptr)
l->ls(); }
270 template<>
struct std::hash<boost::property_tree::ptree> {
271 std::size_t operator() (boost::property_tree::ptree
const&)
const noexcept;
276 template<>
struct std::hash<
Darwin::Tools::UserInfo> {
286 template<>
struct std::hash<TTree *> {
287 std::size_t operator() (TTree *
const&)
const noexcept;
name
Definition: DYToLL_M-50_13TeV_pythia8_cff_GEN_SIM_RECOBEFMIX_DIGI_L1_DIGI2RAW_L1Reco_RECO.py:48
args
Definition: Ntupliser_cfg.py:11
string key
Definition: jercExample.py:109
Global namespace for libraries and executables for analysis with Darwin.
Definition: Dict_rdict.cxx:989