|
ATLAS Offline Software
|
Go to the documentation of this file.
8 #define BOOST_BIND_GLOBAL_PLACEHOLDERS // Needed to silence Boost pragma message
9 #include "boost/property_tree/json_parser.hpp"
28 m_dataSPtr(std::make_shared<
ptree>(std::move(
data)))
33 m_dataSPtr(std::make_shared<
ptree>(std::move(
data))),
54 m_dataSPtr = std::make_shared<ptree>(std::move(
data));
67 m_initialized =
false;
75 return data().empty();
81 const std::string
value =
data().get_value<std::string>();
87 const auto & child =
data().get_child_optional(
key );
90 return child.get().empty();
95 auto child =
data().get_child_optional(
key );
99 return child->get_value<std::string>() ==
"null";
105 return "DataStructure";
115 const auto & child =
data().get_child_optional(
path );
125 if ( !
obj.empty() ) {
126 if (
obj.front().first.empty() ) {
127 throw std::runtime_error(
className() +
"#" +
name() +
": structure '" +
key +
"' is not a simple attribute but a list [], it needs to be accessed via getList(\"" +
key +
"\") -> vector<DataStructure>");
129 throw std::runtime_error(
className() +
"#" +
name() +
": structure '" +
key +
"' is not a simple attribute but an object {}, it needs to be accessed via getObject(\"" +
key +
"\") -> DataStructure");
138 const auto &
obj =
data().get_child_optional(
key);
140 if( ignoreIfMissing ) {
143 throw std::runtime_error(
className() +
"#" +
name() +
": structure '" +
key +
"' does not exist" );
147 if ( !
obj.get().empty() ) {
148 if (
obj.get().front().first.empty() ) {
149 throw std::runtime_error(
className() +
"#" +
name() +
": structure '" +
key +
"' is not a simple attribute but a list [], it needs to be accessed via getList(\"" +
key +
"\") -> vector<DataStructure>");
151 throw std::runtime_error(
className() +
"#" +
name() +
": structure '" +
key +
"' is not a simple attribute but an object {}, it needs to be accessed via getObject(\"" +
key +
"\") -> DataStructure");
154 return obj.get().data();
157 std::vector<TrigConf::DataStructure>
160 std::vector<TrigConf::DataStructure> childList;
161 const auto &
list =
data().get_child_optional(pathToChild);
163 if ( ignoreIfMissing ) {
166 throw std::runtime_error(
className() +
"#" +
name() +
": structure '" + pathToChild +
"' does not exist.");
176 if (
list.get().empty() ) {
177 if (
list.get().get_value<std::string>() !=
"" ) {
179 throw std::runtime_error(
className() +
"#" +
name() +
": structure '" + pathToChild +
"' is not a list [] but a simple attribute, it needs to be accessed via [\"" + pathToChild +
"\"] -> string");
183 }
else if ( !
list.get().front().first.empty() ) {
184 throw std::runtime_error(
className() +
"#" +
name() +
": structure '" + pathToChild +
"' is not a list [] but an object {}, it needs to be accessed via getObject(\"" + pathToChild +
"\") -> DataStructure");
187 childList.reserve(
list.get().size());
189 for(
auto & childData :
list.get() )
190 childList.emplace_back( childData.second );
196 std::optional<std::vector<TrigConf::DataStructure> >
202 return std::optional<std::vector<TrigConf::DataStructure> >(getList(pathToChild));
209 const auto &
obj =
data().get_child_optional(pathToChild);
211 if ( ignoreIfMissing ) {
214 throw std::runtime_error(
className() +
"#" +
name() +
": structure '" + pathToChild +
"' does not exist.");
218 if(
obj.get().get_value<std::string>() !=
"" ) {
219 throw std::runtime_error(
className() +
"#" +
name() +
": structure '" + pathToChild +
"' is not an object {} but a simple attribute, it needs to be accessed via [\"" + pathToChild +
"\"] -> string");
222 if (
obj.get().front().first.empty() ) {
223 throw std::runtime_error(
className() +
"#" +
name() +
": structure '" + pathToChild +
"' is not an object {} but a list [], it needs to be accessed via getList(\"" + pathToChild +
"\") -> vector<DataStructure>");
225 return {
obj.get() };
229 std::optional<TrigConf::DataStructure>
233 if(
const auto &
obj =
data().get_child_optional(pathToChild)) {
235 if(
obj.get().get_value<std::string>() !=
"" ) {
236 throw std::runtime_error(
className() +
"#" +
name() +
": structure '" + pathToChild +
"' is not an object {} but a simple attribute, it needs to be accessed via [\"" + pathToChild +
"\"] -> string");
239 if (
obj.get().front().first.empty() ) {
240 throw std::runtime_error(
className() +
"#" +
name() +
": structure '" + pathToChild +
"' is not an object {} but a list [], it needs to be accessed via getList(\"" + pathToChild +
"\") -> vector<DataStructure>");
242 return std::optional<TrigConf::DataStructure>(
obj.get());
249 std::vector<std::string>
252 std::vector<std::string>
keys;
267 boost::property_tree::json_parser::write_json(
os,
data() );
281 constexpr
char del =
'"';
283 const std::string
value =
data.get_value<std::string>();
287 os << del <<
key << del <<
": " << del <<
value << del;
292 bool isArray (
data.begin()->first.empty() );
295 os << del <<
key << del <<
": ";
296 os << (isArray ?
"[" :
"{") << std::endl;
298 size_t childCounter =
data.size();
299 for(
const boost::property_tree::ptree::value_type &
x :
data ) {
301 if( --childCounter )
os <<
",";
305 os << (isArray ?
"]" :
"}");
DataStructure getObject(const std::string &pathToChild, bool ignoreIfMissing=false) const
Access to configuration object.
char data[hepevt_bytes_allocation_ATLAS]
path
python interpreter configuration --------------------------------------—
std::string find(const std::string &s)
return a remapped string
std::optional< TrigConf::DataStructure > getObject_optional(const std::string &pathToChild) const
static void printElement(const std::string &key, const ptree &data, uint level=0, std::ostream &os=std::cout)
Static function to print a ptree object.
void setName(const std::string &n)
Setting the configuration element name.
T getAttribute(const std::string &key, bool ignoreIfMissing=false, const T &def=T()) const
Access to simple attribute.
std::vector< std::string > getKeys() const
Access to the keys of an DataStructure which presents a dictionary.
virtual const std::string & name() const final
void setData(const ptree &data)
Setting the configuration data.
bool hasChild(const std::string &path) const
Check if child exists.
std::string operator[](const std::string &key) const
Access to simple attribute.
virtual std::string className() const
A string that is the name of the class.
std::optional< std::vector< DataStructure > > getList_optional(const std::string &pathToChild) const
std::vector< DataStructure > getList(const std::string &pathToChild, bool ignoreIfMissing=false) const
Access to array structure.
void printRaw(std::ostream &os=std::cout) const
Base class for Trigger configuration data and wrapper around underlying representation.
std::string getValue() const
Access to simple content.
bool isNull(const std::string &key) const
Check if an attribute is null.
virtual void clear()
Clearing the configuration data.
virtual void print(std::ostream &os=std::cout) const
DataStructure()
Default constructor, leading to an uninitialized configuration object.
bool isValue() const
Check for attribute.
setBGCode setTAP setLVL2ErrorBits bool
boost::property_tree::ptree ptree
int printElement(GeoElement *&p_element)
bool hasAttribute(const std::string &key) const
Check for attribute.