ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Trigger
TrigConfiguration
TrigConfMuctpi
src
MuctpiXMLHelper.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
#include "
TrigConfMuctpi/MuctpiXMLHelper.h
"
6
#include <charconv>
7
#include <string_view>
8
#include <iostream>
9
10
using namespace
std
;
11
using
boost::property_tree::ptree;
12
13
MuctpiXMLHelper::MuctpiXMLHelper
() :
14
TrigConf
::
TrigConfMessaging
(
"MuctpiXML"
)
15
{}
16
17
void
18
MuctpiXMLHelper::printAttributes
(
const
ptree
&
tree
) {
19
20
// initialize attributes ptree
21
ptree
tmp_ptree;
22
ptree
attributes =
tree
.get_child(
"<xmlattr>"
, tmp_ptree);
23
24
// iterate through elements
25
for
(
const
ptree::value_type &
a
: attributes) {
26
string
attrName =
a
.first;
27
string
attrVal =
a
.second.data();
28
std::cout << attrName <<
" : "
<< attrVal << std::endl;
29
}
30
}
31
32
bool
33
MuctpiXMLHelper::hasAttribute
(
const
ptree
&
tree
, string_view attr) {
34
35
// initialize attributes ptree
36
ptree
tmp_ptree;
37
ptree
attributes =
tree
.get_child(
"<xmlattr>"
, tmp_ptree);
38
39
if
(attributes.empty())
return
false
;
40
41
for
(
const
ptree::value_type &
a
: attributes) {
42
string
attrName =
a
.first;
43
if
(attrName == attr) {
44
return
true
;
45
}
46
}
47
return
false
;
48
}
49
50
51
std::string
52
MuctpiXMLHelper::readAttribute
(
const
ptree
&
tree
, std::string_view attr){
53
const
auto
attributes =
tree
.get_child_optional(
"<xmlattr>"
);
54
if
(!attributes) {
55
return
{};
56
}
57
for
(
const
auto
& [name, value] : *attributes) {
58
if
(name == attr) {
59
return
value.data();
60
}
61
}
62
return
{};
63
}
64
65
66
std::string
67
MuctpiXMLHelper::getAttribute
(
const
ptree
&
tree
, string_view attr) {
68
if
( !
hasAttribute
(
tree
, attr) ) {
69
TRG_MSG_WARNING
(
"attribute "
<< attr <<
" does not exist"
);
70
return
""
;
71
}
72
return
readAttribute
(
tree
,attr);
73
}
74
75
std::string
76
MuctpiXMLHelper::getAttribute
(
const
ptree
&
tree
, string_view attr, std::string_view defval) {
77
if
( !
hasAttribute
(
tree
, attr) )
78
return
std::string{defval};
79
return
readAttribute
(
tree
,attr);
80
}
81
82
83
int
84
MuctpiXMLHelper::getIntAttribute
(
const
ptree
&
tree
, string_view attr) {
85
if
( !
hasAttribute
(
tree
, attr) ) {
86
TRG_MSG_WARNING
(
"attribute "
<< attr <<
" does not exist"
);
87
return
0;
88
}
89
90
int
ret_value{0};
91
std::string attr_value =
readAttribute
(
tree
, attr);
92
auto
[ptr, ec] = std::from_chars(attr_value.data(), attr_value.data() + attr_value.size(), ret_value);
93
if
(ec != std::errc()) {
94
TRG_MSG_ERROR
(
"attribute '"
<< attr <<
"' is not an int (it is '"
<< attr_value <<
"')"
);
95
}
96
return
ret_value;
97
}
98
99
int
100
MuctpiXMLHelper::getIntAttribute
(
const
ptree
&
tree
, string_view attr,
int
defval) {
101
if
( !
hasAttribute
(
tree
, attr) )
102
return
defval;
103
int
ret_value{0};
104
std::string attr_value =
readAttribute
(
tree
, attr);
105
auto
[ptr, ec] = std::from_chars(attr_value.data(), attr_value.data() + attr_value.size(), ret_value);
106
if
(ec != std::errc()) {
107
TRG_MSG_ERROR
(
"attribute '"
<< attr <<
"' is not an int (it is '"
<< attr_value <<
"')"
);
108
}
109
return
ret_value;
110
}
111
112
113
unsigned
int
114
MuctpiXMLHelper::getUIntAttribute
(
const
ptree
&
tree
, string_view attr) {
115
if
( !
hasAttribute
(
tree
, attr) ) {
116
TRG_MSG_WARNING
(
"attribute "
<< attr <<
" does not exist"
);
117
return
0;
118
}
119
unsigned
int
ret_value{0};
120
std::string attr_value =
readAttribute
(
tree
, attr);
121
auto
[ptr, ec] = std::from_chars(attr_value.data(), attr_value.data() + attr_value.size(), ret_value);
122
if
(ec != std::errc()) {
123
TRG_MSG_ERROR
(
"attribute '"
<< attr <<
"' is not an unsigned int (it is "
<< attr_value <<
")"
);
124
}
125
return
ret_value;
126
}
127
128
unsigned
int
129
MuctpiXMLHelper::getUIntAttribute
(
const
ptree
&
tree
, string_view attr,
unsigned
int
& defval) {
130
if
( !
hasAttribute
(
tree
, attr) )
131
return
defval;
132
unsigned
int
ret_value{0};
133
std::string attr_value =
readAttribute
(
tree
, attr);
134
auto
[ptr, ec] = std::from_chars(attr_value.data(), attr_value.data() + attr_value.size(), ret_value);
135
if
(ec != std::errc()) {
136
TRG_MSG_ERROR
(
"attribute '"
<< attr <<
"' is not an unsigned int (it is "
<< attr_value <<
")"
);
137
}
138
return
ret_value;
139
}
140
141
142
float
143
MuctpiXMLHelper::getFloatAttribute
(
const
ptree
&
tree
, string_view attr) {
144
if
( !
hasAttribute
(
tree
, attr) ) {
145
TRG_MSG_WARNING
(
"attribute "
<< attr <<
" does not exist"
);
146
return
0;
147
}
148
float
ret_value{0};
149
std::string attr_value =
readAttribute
(
tree
, attr);
150
auto
[ptr, ec] = std::from_chars(attr_value.data(), attr_value.data() + attr_value.size(), ret_value, std::chars_format::general);
151
if
(ec != std::errc()) {
152
TRG_MSG_ERROR
(
"attribute '"
<< attr <<
"' is not a float (it is "
<< attr_value <<
")"
);
153
printAttributes
(
tree
);
154
}
155
return
ret_value;
156
}
157
158
float
159
MuctpiXMLHelper::getFloatAttribute
(
const
ptree
&
tree
, string_view attr,
float
& defval) {
160
if
( !
hasAttribute
(
tree
, attr) )
161
return
defval;
162
float
ret_value{0};
163
std::string attr_value =
readAttribute
(
tree
, attr);
164
auto
[ptr, ec] = std::from_chars(attr_value.data(), attr_value.data() + attr_value.size(), ret_value, std::chars_format::general);
165
if
(ec != std::errc()) {
166
TRG_MSG_ERROR
(
"attribute '"
<< attr <<
"' is not a float (it is "
<< attr_value <<
")"
);
167
printAttributes
(
tree
);
168
}
169
return
ret_value;
170
}
ptree
boost::property_tree::ptree ptree
Definition
JsonFileLoader.cxx:16
a
static Double_t a
Definition
LArPhysWaveHECTool.cxx:38
MuctpiXMLHelper.h
TRG_MSG_WARNING
#define TRG_MSG_WARNING(x)
Definition
Trigger/TrigConfiguration/TrigConfBase/TrigConfBase/MsgStreamMacros.h:28
TRG_MSG_ERROR
#define TRG_MSG_ERROR(x)
Definition
Trigger/TrigConfiguration/TrigConfBase/TrigConfBase/MsgStreamMacros.h:29
MuctpiXMLHelper::readAttribute
std::string readAttribute(const boost::property_tree::ptree &tree, std::string_view attr)
Definition
MuctpiXMLHelper.cxx:52
MuctpiXMLHelper::getFloatAttribute
float getFloatAttribute(const boost::property_tree::ptree &tree, std::string_view attr)
Definition
MuctpiXMLHelper.cxx:143
MuctpiXMLHelper::getIntAttribute
int getIntAttribute(const boost::property_tree::ptree &tree, std::string_view attr)
Definition
MuctpiXMLHelper.cxx:84
MuctpiXMLHelper::MuctpiXMLHelper
MuctpiXMLHelper()
Definition
MuctpiXMLHelper.cxx:13
MuctpiXMLHelper::printAttributes
void printAttributes(const boost::property_tree::ptree &tree)
Definition
MuctpiXMLHelper.cxx:18
MuctpiXMLHelper::hasAttribute
bool hasAttribute(const boost::property_tree::ptree &tree, std::string_view attr)
Definition
MuctpiXMLHelper.cxx:33
MuctpiXMLHelper::getAttribute
std::string getAttribute(const boost::property_tree::ptree &tree, std::string_view attr)
Definition
MuctpiXMLHelper.cxx:67
MuctpiXMLHelper::getUIntAttribute
unsigned int getUIntAttribute(const boost::property_tree::ptree &tree, std::string_view attr)
Definition
MuctpiXMLHelper.cxx:114
TrigConf::TrigConfMessaging::TrigConfMessaging
TrigConfMessaging(const std::string &name)
Constructor with parameters.
Definition
TrigConfMessaging.h:34
TrigConf
Forward iterator to traverse the main components of the trigger configuration.
Definition
IDPerfMonZmumu.h:57
std
STL namespace.
tree
TChain * tree
Definition
tile_monitor.h:30
Generated on
for ATLAS Offline Software by
1.17.0