8#define BOOST_BIND_GLOBAL_PLACEHOLDERS
9#include "boost/property_tree/json_parser.hpp"
75 return data().empty();
81 return data().get_value<std::string>();
86 const auto & child =
data().get_child_optional( key );
89 return child.get().empty();
94 auto child =
data().get_child_optional( key );
98 return child->get_value<std::string>() ==
"null";
104 return "DataStructure";
114 const auto & child =
data().get_child_optional( path );
122 const auto & obj =
data().get_child(key);
124 if ( !obj.empty() ) {
125 if ( obj.front().first.empty() ) {
126 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>");
128 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");
137 const auto & obj =
data().get_child_optional(key);
139 if( ignoreIfMissing ) {
142 throw std::runtime_error(
className() +
"#" +
name() +
": structure '" + key +
"' does not exist" );
146 if ( !obj.get().empty() ) {
147 if ( obj.get().front().first.empty() ) {
148 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>");
150 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");
153 return obj.get().data();
156std::vector<TrigConf::DataStructure>
159 std::vector<TrigConf::DataStructure> childList;
160 const auto & list =
data().get_child_optional(pathToChild);
162 if ( ignoreIfMissing ) {
165 throw std::runtime_error(
className() +
"#" +
name() +
": structure '" + pathToChild +
"' does not exist.");
175 if ( list.get().empty() ) {
176 if ( list.get().get_value<std::string>() !=
"" ) {
178 throw std::runtime_error(
className() +
"#" +
name() +
": structure '" + pathToChild +
"' is not a list [] but a simple attribute, it needs to be accessed via [\"" + pathToChild +
"\"] -> string");
182 }
else if ( ! list.get().front().first.empty() ) {
183 throw std::runtime_error(
className() +
"#" +
name() +
": structure '" + pathToChild +
"' is not a list [] but an object {}, it needs to be accessed via getObject(\"" + pathToChild +
"\") -> DataStructure");
186 childList.reserve(list.get().size());
188 for(
auto & childData : list.get() )
189 childList.emplace_back( childData.second );
195std::optional<std::vector<TrigConf::DataStructure> >
201 return std::optional<std::vector<TrigConf::DataStructure> >(
getList(pathToChild));
208 const auto & obj =
data().get_child_optional(pathToChild);
210 if ( ignoreIfMissing ) {
213 throw std::runtime_error(
className() +
"#" +
name() +
": structure '" + pathToChild +
"' does not exist.");
217 if( obj.get().get_value<std::string>() !=
"" ) {
218 throw std::runtime_error(
className() +
"#" +
name() +
": structure '" + pathToChild +
"' is not an object {} but a simple attribute, it needs to be accessed via [\"" + pathToChild +
"\"] -> string");
221 if ( obj.get().front().first.empty() ) {
222 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>");
224 return { obj.get() };
228std::optional<TrigConf::DataStructure>
232 if(
const auto & obj =
data().get_child_optional(pathToChild)) {
234 if( obj.get().get_value<std::string>() !=
"" ) {
235 throw std::runtime_error(
className() +
"#" +
name() +
": structure '" + pathToChild +
"' is not an object {} but a simple attribute, it needs to be accessed via [\"" + pathToChild +
"\"] -> string");
238 if ( obj.get().front().first.empty() ) {
239 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>");
241 return std::optional<TrigConf::DataStructure>(obj.get());
248std::vector<std::string>
251 std::vector<std::string> keys;
253 !
data().front().first.empty() )
255 keys.reserve(
data().size());
256 for(
auto & entry :
data() ) {
257 keys.push_back(entry.first);
266 boost::property_tree::json_parser::write_json( os,
data() );
280 constexpr char del =
'"';
282 const std::string value =
data.get_value<std::string>();
285 uint n(4*level);
while(n--) os <<
" ";
286 os << del << key << del <<
": " << del << value << del;
291 bool isArray (
data.begin()->first.empty() );
292 {
uint n(4*level);
while(n--) os <<
" "; }
294 os << del << key << del <<
": ";
295 os << (isArray ?
"[" :
"{") << std::endl;
297 size_t childCounter =
data.size();
298 for(
const boost::property_tree::ptree::value_type &
x :
data ) {
300 if( --childCounter ) os <<
",";
303 {
uint n(4*level);
while(n--) os <<
" "; }
304 os << (isArray ?
"]" :
"}");
char data[hepevt_bytes_allocation_ATLAS]
static const Attributes_t empty
Base class for Trigger configuration data and wrapper around underlying representation.
std::optional< TrigConf::DataStructure > getObject_optional(const std::string &pathToChild) const
void setName(const std::string &n)
Setting the configuration element name.
std::shared_ptr< ptree > m_dataSPtr
virtual const std::string & name() const final
std::vector< DataStructure > getList(const std::string &pathToChild, bool ignoreIfMissing=false) const
Access to array structure.
bool m_initialized
if initialized, the underlying ptree is has been assigned to (can be empty)
const ptree & data() const
Access to the underlying data, if needed.
bool hasAttribute(const std::string &key) const
Check for attribute.
std::optional< std::vector< DataStructure > > getList_optional(const std::string &pathToChild) const
DataStructure()
Default constructor, leading to an uninitialized configuration object.
void setData(const ptree &data)
Setting the configuration data.
virtual void clear()
Clearing the configuration data.
std::vector< std::string > getKeys() const
Access to the keys of an DataStructure which presents a dictionary.
virtual std::string className() const
A string that is the name of the class.
std::string getValue() const
Access to simple content.
T getAttribute(const std::string &key, bool ignoreIfMissing=false, const T &def=T()) const
Access to simple attribute.
bool isNull(const std::string &key) const
Check if an attribute is null.
void printRaw(std::ostream &os=std::cout) const
virtual void update()
Update the internal data after modification of the data object.
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.
bool hasChild(const std::string &path) const
Check if child exists.
DataStructure getObject(const std::string &pathToChild, bool ignoreIfMissing=false) const
Access to configuration object.
std::string operator[](const std::string &key) const
Access to simple attribute.
boost::property_tree::ptree ptree
bool isValue() const
Check for attribute.
virtual void print(std::ostream &os=std::cout) const
std::string find(const std::string &s)
return a remapped string