ATLAS Offline Software
Loading...
Searching...
No Matches
MuctpiXMLHelper Class Reference

#include <MuctpiXMLHelper.h>

Inheritance diagram for MuctpiXMLHelper:
Collaboration diagram for MuctpiXMLHelper:

Public Member Functions

 MuctpiXMLHelper ()
std::string readAttribute (const boost::property_tree::ptree &tree, std::string_view attr)
bool hasAttribute (const boost::property_tree::ptree &tree, std::string_view attr)
std::string getAttribute (const boost::property_tree::ptree &tree, std::string_view attr)
std::string getAttribute (const boost::property_tree::ptree &tree, std::string_view attr, std::string_view defval)
int getIntAttribute (const boost::property_tree::ptree &tree, std::string_view attr)
int getIntAttribute (const boost::property_tree::ptree &tree, std::string_view attr, int defval)
unsigned int getUIntAttribute (const boost::property_tree::ptree &tree, std::string_view attr)
unsigned int getUIntAttribute (const boost::property_tree::ptree &tree, std::string_view attr, unsigned int &defval)
float getFloatAttribute (const boost::property_tree::ptree &tree, std::string_view attr)
float getFloatAttribute (const boost::property_tree::ptree &tree, const std::string_view attr, float &defval)
void printAttributes (const boost::property_tree::ptree &tree)

Private Member Functions

bool msgLvl (const MSGTC::Level lvl) const
 Test the output level.
MsgStreamTC & msg () const
 The standard message stream.
MsgStreamTC & msg (const MSGTC::Level lvl) const
 The standard message stream.
const std::string & getName () const
 name accessor

Private Attributes

boost::thread_specific_ptr< MsgStreamTC > m_msg_tls
 MsgStreamTC instance (a std::cout like with print-out levels).
std::string m_name

Detailed Description

Definition at line 14 of file MuctpiXMLHelper.h.

Constructor & Destructor Documentation

◆ MuctpiXMLHelper()

MuctpiXMLHelper::MuctpiXMLHelper ( )

Definition at line 13 of file MuctpiXMLHelper.cxx.

13 :
14 TrigConf::TrigConfMessaging("MuctpiXML")
15{}

Member Function Documentation

◆ getAttribute() [1/2]

std::string MuctpiXMLHelper::getAttribute ( const boost::property_tree::ptree & tree,
std::string_view attr )

Definition at line 67 of file MuctpiXMLHelper.cxx.

67 {
68 if( ! hasAttribute(tree, attr) ) {
69 TRG_MSG_WARNING("attribute " << attr << " does not exist");
70 return "";
71 }
72 return readAttribute(tree,attr);
73}
std::string readAttribute(const boost::property_tree::ptree &tree, std::string_view attr)
bool hasAttribute(const boost::property_tree::ptree &tree, std::string_view attr)
TChain * tree

◆ getAttribute() [2/2]

std::string MuctpiXMLHelper::getAttribute ( const boost::property_tree::ptree & tree,
std::string_view attr,
std::string_view defval )

Definition at line 76 of file MuctpiXMLHelper.cxx.

76 {
77 if( ! hasAttribute(tree, attr) )
78 return std::string{defval};
79 return readAttribute(tree,attr);
80}

◆ getFloatAttribute() [1/2]

float MuctpiXMLHelper::getFloatAttribute ( const boost::property_tree::ptree & tree,
const std::string_view attr,
float & defval )

Definition at line 159 of file MuctpiXMLHelper.cxx.

159 {
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 << ")");
168 }
169 return ret_value;
170}
void printAttributes(const boost::property_tree::ptree &tree)
void * ptr(T *p)
Definition SGImplSvc.cxx:74

◆ getFloatAttribute() [2/2]

float MuctpiXMLHelper::getFloatAttribute ( const boost::property_tree::ptree & tree,
std::string_view attr )

Definition at line 143 of file MuctpiXMLHelper.cxx.

143 {
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 << ")");
154 }
155 return ret_value;
156}

◆ getIntAttribute() [1/2]

int MuctpiXMLHelper::getIntAttribute ( const boost::property_tree::ptree & tree,
std::string_view attr )

Definition at line 84 of file MuctpiXMLHelper.cxx.

84 {
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}

◆ getIntAttribute() [2/2]

int MuctpiXMLHelper::getIntAttribute ( const boost::property_tree::ptree & tree,
std::string_view attr,
int defval )

Definition at line 100 of file MuctpiXMLHelper.cxx.

100 {
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}

◆ getName()

const std::string & TrigConf::TrigConfMessaging::getName ( ) const
inlineinherited

name accessor

Returns
the name

Definition at line 101 of file TrigConfMessaging.h.

101 {
102 return m_name;
103 }

◆ getUIntAttribute() [1/2]

unsigned int MuctpiXMLHelper::getUIntAttribute ( const boost::property_tree::ptree & tree,
std::string_view attr )

Definition at line 114 of file MuctpiXMLHelper.cxx.

114 {
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}

◆ getUIntAttribute() [2/2]

unsigned int MuctpiXMLHelper::getUIntAttribute ( const boost::property_tree::ptree & tree,
std::string_view attr,
unsigned int & defval )

Definition at line 129 of file MuctpiXMLHelper.cxx.

129 {
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}

◆ hasAttribute()

bool MuctpiXMLHelper::hasAttribute ( const boost::property_tree::ptree & tree,
std::string_view attr )

Definition at line 33 of file MuctpiXMLHelper.cxx.

33 {
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}
boost::property_tree::ptree ptree
static Double_t a

◆ msg() [1/2]

MsgStreamTC & TrigConf::TrigConfMessaging::msg ( ) const
inlineinherited

The standard message stream.

Returns a reference to the message stream May not be invoked before sysInitialize() has been invoked.

Definition at line 86 of file TrigConfMessaging.h.

87 {
88 MsgStreamTC* ms = m_msg_tls.get();
89 if (!ms) {
90 ms = new MsgStreamTC(m_name);
91 m_msg_tls.reset(ms);
92 }
93 return *ms;
94 }
boost::thread_specific_ptr< MsgStreamTC > m_msg_tls
MsgStreamTC instance (a std::cout like with print-out levels).

◆ msg() [2/2]

MsgStreamTC & TrigConf::TrigConfMessaging::msg ( const MSGTC::Level lvl) const
inlineinherited

The standard message stream.

Returns a reference to the default message stream May not be invoked before sysInitialize() has been invoked.

Definition at line 96 of file TrigConfMessaging.h.

97 {
98 return msg() << lvl;
99 }
MsgStreamTC & msg() const
The standard message stream.

◆ msgLvl()

bool TrigConf::TrigConfMessaging::msgLvl ( const MSGTC::Level lvl) const
inlineinherited

Test the output level.

Parameters
lvlThe message level to test against
Returns
boolean Indicting if messages at given level will be printed
Return values
trueMessages at level "lvl" will be printed

Definition at line 75 of file TrigConfMessaging.h.

76 {
77 if (msg().level() <= lvl) {
78 msg() << lvl;
79 return true;
80 }
81 else {
82 return false;
83 }
84 }

◆ printAttributes()

void MuctpiXMLHelper::printAttributes ( const boost::property_tree::ptree & tree)

Definition at line 18 of file MuctpiXMLHelper.cxx.

18 {
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}

◆ readAttribute()

std::string MuctpiXMLHelper::readAttribute ( const boost::property_tree::ptree & tree,
std::string_view attr )

Definition at line 52 of file MuctpiXMLHelper.cxx.

52 {
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}

Member Data Documentation

◆ m_msg_tls

boost::thread_specific_ptr<MsgStreamTC> TrigConf::TrigConfMessaging::m_msg_tls
mutableprivateinherited

MsgStreamTC instance (a std::cout like with print-out levels).

Definition at line 71 of file TrigConfMessaging.h.

◆ m_name

std::string TrigConf::TrigConfMessaging::m_name
privateinherited

Definition at line 72 of file TrigConfMessaging.h.


The documentation for this class was generated from the following files: