ATLAS Offline Software
Loading...
Searching...
No Matches
dqi::MiniConfig Class Reference

description More...

#include <MiniConfig.h>

Inheritance diagram for dqi::MiniConfig:
Collaboration diagram for dqi::MiniConfig:

Public Member Functions

 MiniConfig ()
virtual ~MiniConfig ()
virtual void AddKeyword (std::string keyword_)
virtual void AddAttributeKeyword (std::string keyword_)
virtual void SetAttribKeywordPropagateDown (bool propagateDown)
virtual bool ReadFile (std::string fileName)
virtual std::string GetStringAttribute (std::string objName, std::string attName) const
virtual int GetIntAttribute (std::string objName, std::string attName) const
virtual float GetFloatAttribute (std::string objName, std::string attName) const
virtual void GetAttributeNames (std::string objName, std::set< std::string > &attSet) const
virtual void SendVisitor (MiniConfigTreeNode::Visitor &visitor) const
virtual void SendWriter (MiniConfigTreeNode::Writer &writer)

Protected Types

typedef std::set< std::string > KeySet_t
typedef KeySet_t::const_iterator KeyIter_t

Protected Attributes

KeySet_t m_keywords
KeySet_t m_attKeywords
MiniConfigTreeNodem_tree
bool m_propagateDown

Detailed Description

description

Author
Michael Wilson, CERN, March 2007

Definition at line 25 of file MiniConfig.h.

Member Typedef Documentation

◆ KeyIter_t

typedef KeySet_t::const_iterator dqi::MiniConfig::KeyIter_t
protected

Definition at line 55 of file MiniConfig.h.

◆ KeySet_t

typedef std::set<std::string> dqi::MiniConfig::KeySet_t
protected

Definition at line 54 of file MiniConfig.h.

Constructor & Destructor Documentation

◆ MiniConfig()

dqi::MiniConfig::MiniConfig ( )

Definition at line 33 of file MiniConfig.cxx.

35 : m_tree(0)
36 , m_propagateDown(true)
37{
38}
MiniConfigTreeNode * m_tree
Definition MiniConfig.h:59

◆ ~MiniConfig()

dqi::MiniConfig::~MiniConfig ( )
virtual

Definition at line 41 of file MiniConfig.cxx.

43{
44 delete m_tree;
45}

Member Function Documentation

◆ AddAttributeKeyword()

void dqi::MiniConfig::AddAttributeKeyword ( std::string keyword_)
virtual

Definition at line 58 of file MiniConfig.cxx.

60{
61 const KeySet_t::value_type& keyval( std::move(keyword_) );
62 m_attKeywords.insert( keyval );
63}
KeySet_t m_attKeywords
Definition MiniConfig.h:58

◆ AddKeyword()

void dqi::MiniConfig::AddKeyword ( std::string keyword_)
virtual

Definition at line 49 of file MiniConfig.cxx.

51{
52 const KeySet_t::value_type& keyval( std::move(keyword_) );
53 m_keywords.insert( keyval );
54}
KeySet_t m_keywords
Definition MiniConfig.h:57

◆ GetAttributeNames()

void dqi::MiniConfig::GetAttributeNames ( std::string objName,
std::set< std::string > & attSet ) const
virtual

Definition at line 297 of file MiniConfig.cxx.

299{
300 attSet.clear();
301
302 if( m_tree == 0 ) {
303 std::cerr << "MiniConfig::GetAttributeNames(): "
304 << "not configured (no file has been read)\n";
305 return;
306 }
307
308 const MiniConfigTreeNode* node = m_tree->GetNode( objName );
309 if( node == 0 ) {
310 std::cerr << "MiniConfig::GetAttributeNames(): "
311 << "\"" << objName << "\" does not exist\n";
312 return;
313 }
314
315 node->GetAttributeNames( attSet );
316}

◆ GetFloatAttribute()

float dqi::MiniConfig::GetFloatAttribute ( std::string objName,
std::string attName ) const
virtual

Definition at line 266 of file MiniConfig.cxx.

268{
269 if( m_tree == 0 ) {
270 std::cerr << "MiniConfig::GetFloatAttribute(): "
271 << "not configured (no file has been read)\n";
272 return 0;
273 }
274
275 const MiniConfigTreeNode* node = m_tree->GetNode( objName );
276 if( node == 0 ) {
277 std::cerr << "MiniConfig::GetFloatAttribute(): "
278 << "\"" << objName << "\" does not exist\n";
279 return 0;
280 }
281
282 float val;
283 std::string valstring = node->GetAttribute( attName );
284 std::istringstream valstream(valstring);
285 valstream >> val;
286 if( !valstream ) {
287 std::cerr << "MiniConfig::GetFloatAttribute(): object \"" << objName << "\""
288 << ": \"" << attName << "\" not a floating-point type\n";
289 return 0;
290 }
291
292 return val;
293}

◆ GetIntAttribute()

int dqi::MiniConfig::GetIntAttribute ( std::string objName,
std::string attName ) const
virtual

Definition at line 235 of file MiniConfig.cxx.

237{
238 if( m_tree == 0 ) {
239 std::cerr << "MiniConfig::GetIntAttribute(): "
240 << "not configured (no file has been read)\n";
241 return 0;
242 }
243
244 const MiniConfigTreeNode* node = m_tree->GetNode( objName );
245 if( node == 0 ) {
246 std::cerr << "MiniConfig::GetIntAttribute(): "
247 << "\"" << objName << "\" does not exist\n";
248 return 0;
249 }
250
251 int val;
252 std::string valstring = node->GetAttribute( attName );
253 std::istringstream valstream(valstring);
254 valstream >> val;
255 if( !valstream ) {
256 std::cerr << "MiniConfig::GetIntAttribute(): "
257 << "\"" << attName << "\" not an integer type\n";
258 return 0;
259 }
260
261 return val;
262}

◆ GetStringAttribute()

std::string dqi::MiniConfig::GetStringAttribute ( std::string objName,
std::string attName ) const
virtual

Definition at line 215 of file MiniConfig.cxx.

217{
218 if( m_tree == 0 ) {
219 std::cerr << "MiniConfig::GetStringAttribute(): "
220 << "not configured (no file has been read)\n";
221 return std::string("");
222 }
223
224 const MiniConfigTreeNode* node = m_tree->GetNode( objName );
225 if( node == 0 ) {
226 std::cerr << "MiniConfig::GetStringAttribute(): "
227 << "\"" << objName << "\" does not exist\n";
228 return std::string("");
229 }
230 return node->GetAttribute( std::move(attName) );
231}

◆ ReadFile()

bool dqi::MiniConfig::ReadFile ( std::string fileName)
virtual

Definition at line 73 of file MiniConfig.cxx.

75{
76 bool success(true);
77
78 delete m_tree;
79 m_tree = new MiniConfigTreeNode( "global", 0 );
80 m_tree->SetAttribKeywordPropagateDown( m_propagateDown );
81 MiniConfigTreeNode* node = m_tree;
82
83 std::ifstream file( fileName.c_str() );
84 if( !file ) {
85 std::cerr << "MiniConfig::ReadFile(): "
86 << "cannot read from file: " << fileName << "\n";
87 return false;
88 }
89
90 std::string line;
91 char c;
92 std::string key;
93 std::string id;
94 std::string sep;
95 std::string att;
96 std::string val;
97 int skipCount(0);
98 int lineNumber = 0;
99
100 while( getline(file,line) ) {
101 ++lineNumber;
102 std::istringstream linestream(line);
103 c = 0;
104
105 while( linestream.get(c) ) {
106 // ignore leading whitespace
107 if( !isspace(c) ) {
108 break;
109 }
110 }
111
112 // ignore empty lines
113 if( c == 0 || isspace(c) ) {
114 continue;
115 }
116
117 // ignore comments
118 if( c == '#' ) {
119 continue;
120 }
121
122 linestream.putback(c);
123
124 // check for: }
125 linestream >> sep;
126 if( !linestream ) {
127 std::cerr << "MiniConfig::ReadFile(): "
128 << "badly formatted line: \"" << line << "\", line number " << lineNumber << "\n";
129 success = false;
130 continue;
131 }
132 if( sep == "}" ) {
133 if( skipCount > 0 ) {
134 --skipCount;
135 }
136 else {
137 node = node->GetParent();
138 if( node == 0 ) {
139 std::cerr << "MiniConfig::ReadFile(): "
140 << "unmatched \"}\", line number " << lineNumber << "\n";
141 success = false;
142 node = m_tree;
143 }
144 }
145 continue;
146 }
147
148 // check for: <att> = <val>
149 att = sep;
150 linestream >> sep;
151 if( !linestream ) {
152 std::cerr << "MiniConfig::ReadFile(): "
153 << "badly formatted line: \"" << line << "\", line number " << lineNumber << "\n";
154 success = false;
155 continue;
156 }
157 if( sep == "=" ) {
158 val = line.substr(linestream.tellg(), std::string::npos);
159 boost::trim(val);
160 //linestream >> val;
161 if( val.size() == 0 ) {
162 std::cerr << "MiniConfig::ReadFile(): "
163 << "badly formatted line: \"" << line << "\", line number " << lineNumber << "\n";
164 success = false;
165 continue;
166 }
167 if( skipCount == 0 ) {
168 node->SetAttribute( att, val, false );
169 }
170 continue;
171 }
172
173 // check for: keyword <identifier> {
174 key = att;
175 // Don't use to_lower_copy in order to avoid gcc 13.1 bug
176 // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109703
177 // (Should be fixed in 13.2.)
178 //const std::string& lokey = boost::algorithm::to_lower_copy(key);
179 std::string lokey = key;
180 std::ranges::transform(lokey, lokey.begin(), [](unsigned char c) { return std::tolower(c); });
181 id = sep;
182 linestream >> sep;
183 if( !linestream ) {
184 std::cerr << "MiniConfig::ReadFile(): "
185 << "badly formatted line: \"" << line << "\", line number " << lineNumber << "\n";
186 success = false;
187 continue;
188 }
189 if( sep == "{" ) {
190 if( m_keywords.find(key) != m_keywords.end()
191 || m_keywords.find(lokey) != m_keywords.end() ) {
192 node = node->GetNewDaughter( id );
193 }
194 else if( m_attKeywords.find(key) != m_attKeywords.end()
195 || m_attKeywords.find(lokey) != m_attKeywords.end() ) {
196 node->SetAttribute( id, node->GetPathName(), true );
197 node = node->GetNewDaughter( id );
198 }
199 else {
200 skipCount++;
201 }
202 continue;
203 }
204
205 std::cerr << "MiniConfig::ReadFile(): "
206 << "badly formatted line: \"" << line << "\", line number " << lineNumber << "\n";
207 success = false;
208 }
209
210 return success;
211}
TFile * file

◆ SendVisitor()

void dqi::MiniConfig::SendVisitor ( MiniConfigTreeNode::Visitor & visitor) const
virtual

Definition at line 320 of file MiniConfig.cxx.

322{
323 if( m_tree == 0 ) {
324 std::cerr << "MiniConfig::SendVisitor(): "
325 << "not configured (no file has been read)\n";
326 } else {
327 m_tree->Accept(visitor);
328 }
329}

◆ SendWriter()

void dqi::MiniConfig::SendWriter ( MiniConfigTreeNode::Writer & writer)
virtual

Definition at line 332 of file MiniConfig.cxx.

334{
335 if( m_tree == 0 ) {
336 std::cerr << "MiniConfig::SendWriter(): "
337 << "not configured (no file has been read)\n";
338 } else {
339 m_tree->Accept(writer);
340 }
341}
std::shared_ptr< HepMC3::Writer > writer

◆ SetAttribKeywordPropagateDown()

void dqi::MiniConfig::SetAttribKeywordPropagateDown ( bool propagateDown)
virtual

Definition at line 66 of file MiniConfig.cxx.

68{
69 this->m_propagateDown = propagateDown;
70}

Member Data Documentation

◆ m_attKeywords

KeySet_t dqi::MiniConfig::m_attKeywords
protected

Definition at line 58 of file MiniConfig.h.

◆ m_keywords

KeySet_t dqi::MiniConfig::m_keywords
protected

Definition at line 57 of file MiniConfig.h.

◆ m_propagateDown

bool dqi::MiniConfig::m_propagateDown
protected

Definition at line 61 of file MiniConfig.h.

◆ m_tree

MiniConfigTreeNode* dqi::MiniConfig::m_tree
protected

Definition at line 59 of file MiniConfig.h.


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