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 32 of file MiniConfig.cxx.

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

◆ ~MiniConfig()

dqi::MiniConfig::~MiniConfig ( )
virtual

Definition at line 40 of file MiniConfig.cxx.

42{
43 delete m_tree;
44}

Member Function Documentation

◆ AddAttributeKeyword()

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

Definition at line 57 of file MiniConfig.cxx.

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

◆ AddKeyword()

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

Definition at line 48 of file MiniConfig.cxx.

50{
51 const KeySet_t::value_type& keyval( std::move(keyword_) );
52 m_keywords.insert( keyval );
53}
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 296 of file MiniConfig.cxx.

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

◆ GetFloatAttribute()

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

Definition at line 265 of file MiniConfig.cxx.

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

◆ GetIntAttribute()

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

Definition at line 234 of file MiniConfig.cxx.

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

◆ GetStringAttribute()

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

Definition at line 214 of file MiniConfig.cxx.

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

◆ ReadFile()

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

Definition at line 72 of file MiniConfig.cxx.

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

◆ SendVisitor()

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

Definition at line 319 of file MiniConfig.cxx.

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

◆ SendWriter()

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

Definition at line 331 of file MiniConfig.cxx.

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

◆ SetAttribKeywordPropagateDown()

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

Definition at line 65 of file MiniConfig.cxx.

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

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: