 |
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>
70 TList *
List (TList * mother,
const char *
key)
const;
77 template<
class T> T
Get (TList * mother,
const char *
key)
const
79 if constexpr (std::is_arithmetic_v<T>) {
80 TObject * obj = mother->FindObject(
key);
81 auto parameter =
dynamic_cast<TParameter<T>*
>(obj);
82 if (parameter ==
nullptr)
83 BOOST_THROW_EXCEPTION(std::invalid_argument(
84 Form(
"No `TParameter` with name '%s' could be found in the `TList` '%s'.",
key, mother->GetName())));
85 return parameter->GetVal();
88 TList * daughter =
List(mother,
key);
89 TIter next(daughter->begin());
90 auto objs =
dynamic_cast<TObjString*
>(daughter->Last());
91 if (daughter->GetSize() == 0 || objs ==
nullptr)
92 BOOST_THROW_EXCEPTION(std::invalid_argument(
93 Form(
"No literal with name '%s' was found in the `TList` '%s'.",
key, mother->GetName())));
94 T literal = objs->GetString().Data();
101 template<
class T,
typename... Args> T
Get (TList * mother,
const char *
key, Args...
args)
const
103 TList * daughter =
List(mother,
key);
104 return Get<T>(daughter,
args...);
109 bool Find (TList * mother,
const char *
key)
const
112 TObject * obj = mother->FindObject(
key);
113 return (obj !=
nullptr);
118 template<
typename... Args>
bool Find (TList * mother,
const char *
key, Args...
args)
const
120 if (!
Find(mother,
key))
return false;
121 TList * daughter =
List(mother,
key);
122 if (daughter->GetSize() > 0)
131 if (TString(
key).Length() == 0)
132 BOOST_THROW_EXCEPTION( std::invalid_argument(
"Empty keys are invalid") );
140 template<
class T>
void Set (TList * mother,
const char *
key, T value)
const
144 if constexpr (std::is_arithmetic_v<T>) {
145 TObject * obj = mother->FindObject(
key);
147 auto parameter =
dynamic_cast<TParameter<T>*
>(obj);
148 if (parameter ==
nullptr)
149 BOOST_THROW_EXCEPTION(std::invalid_argument(
150 Form(
"No `TParameter` with name '%s' and typeid '%s' was found in the `TList` '%s'.",
151 key,
typeid(T).
name(), mother->GetName())));
152 parameter->SetVal(value);
155 auto parameter =
new TParameter<T>(
key, value,
'l');
156 mother->Add(parameter);
161 TList * daughter =
List(mother,
key);
162 if (str.Length() >= 0) {
163 auto objs =
new TObjString(str);
171 template<
class T,
typename... Args>
void Set (TList * mother,
const char *
key, Args...
args)
const
174 TList * daughter =
List(mother,
key);
175 Set<T>(daughter,
args...);
180 template<
typename... Args> TList *
List (TList * mother,
const char *
key, Args...
args)
const
182 TList * daughter =
List(mother,
key);
187 T
Get (TList * mother, std::string
key)
const {
return Get<T>(mother,
key.c_str()); }
188 bool Find (TList * mother, std::string
key)
const {
return Find (mother,
key.c_str()); }
189 TList *
List (TList * mother, std::string
key)
const {
return List (mother,
key.c_str()); }
196 void ConvertPtree (
const boost::property_tree::ptree&,
const std::string&, TList*);
203 boost::property_tree::ptree
MkPtree (TList *,
213 boost::property_tree::ptree
Write (
const boost::property_tree::ptree&,
221 template<
typename... Args> TList *
List (
const char *
key, Args...
args)
const
235 template<
class T,
typename... Args> T
Get (
const char *
key, Args...
args)
const
242 template<
typename... Args>
bool Find (
const char *
key, Args...
args)
const
251 template<
class T,
typename... Args>
void Set (
const char *
key, Args...
args)
const
256 UserInfo (
const char * =
"UserInfo");
257 UserInfo (
const boost::property_tree::ptree&);
260 UserInfo (TTree *,
const boost::property_tree::ptree&);
270 boost::property_tree::ptree
Write (std::ostream&,
278 boost::property_tree::ptree
Write (
const std::filesystem::path&
286 )
const {
return MkPtree(
l, format); }
290 void ls ()
const {
if (
l !=
nullptr)
l->ls(); }
297 template<>
struct std::hash<boost::property_tree::ptree> {
298 std::size_t operator() (boost::property_tree::ptree
const&)
const noexcept;
303 template<>
struct std::hash<
Darwin::Tools::UserInfo> {
313 template<>
struct std::hash<TTree *> {
314 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: Darwin_dict.cxx:1143