ATLAS Offline Software
Loading...
Searching...
No Matches
MiniConfigTreeNode.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
5// **********************************************************************
6// **********************************************************************
7
8#include <utility>
9
11
12
13//Get rid of Root macros that confuse Doxygen
17
18
19namespace dqi {
20
21// *********************************************************************
22// Public Methods
23// *********************************************************************
24
26MiniConfigTreeNode( std::string name_, MiniConfigTreeNode* parent_ )
27 : m_name(std::move(name_))
28 , m_parent(parent_)
29 , m_propagateDown(true)
30{
31}
32
33
36{
37 NodeIter_t daugEnd = m_daughters.end();
38 for( NodeIter_t i = m_daughters.begin(); i != daugEnd; ++i ) {
39 MiniConfigTreeNode* inode = i->second;
40 delete inode;
41 }
42}
43
44
45const char*
47GetName() const
48{
49 return m_name.c_str();
50}
51
52
53std::string
55GetPathName() const
56{
57 std::string path;
58 if( m_parent != 0 ) {
59 std::string parentPath( m_parent->GetPathName() );
60 if( !parentPath.empty() ) {
61 path += parentPath;
62 path += std::string("/");
63 }
64 path += m_name;
65 }
66 return path;
67}
68
69
72GetNewDaughter( std::string name_ )
73{
74 NodeIter_t i = m_daughters.find( name_ );
75 if( i != m_daughters.end() ) {
76 return i->second;
77 }
78
79 MiniConfigTreeNode* node = new MiniConfigTreeNode( name_, this );
80 node->SetAttribKeywordPropagateDown(this->m_propagateDown);
81 NodeMap_t::value_type nodeVal( name_, node );
82 m_daughters.insert( std::move(nodeVal) );
83 return node;
84}
85
86
89GetDaughter( std::string name_ ) const
90{
91 NodeIter_t i = m_daughters.find( name_ );
92 if( i != m_daughters.end() ) {
93 return i->second;
94 }
95 return 0;
96}
97
98
99std::map<std::string,MiniConfigTreeNode*>
101GetDaughters() const
102{
103 return m_daughters;
104}
105
108GetNode( const std::string & name_ ) const
109{
110 if( m_daughters.size() == 0 ) {
111 return this;
112 }
113
114 std::string::size_type k = name_.find_first_of('/');
115 if( k != std::string::npos ) {
116 std::string dName( name_, 0, k );
117 std::string pName( name_, k+1, std::string::npos );
118 if( dName != "" ) {
119 NodeIter_t i = m_daughters.find( dName );
120 if( i == m_daughters.end() ) {
121 return this;
122 }
123 MiniConfigTreeNode* node = i->second;
124 return node->GetNode( pName );
125 }
126 return GetNode( pName );
127 }
128
129 NodeIter_t i = m_daughters.find( name_ );
130 if( i == m_daughters.end() ) {
131 return this;
132 }
133 return i->second;
134}
135
136
137void
139SetAttribute( const std::string & attName, const std::string & attValue, bool isAttribKeyword )
140{
141 AttMap_t::value_type attMapVal( attName, AttMap_t::mapped_type(attValue, isAttribKeyword) );
142 m_attributes.insert( std::move(attMapVal) );
143}
144
145
146std::string
148GetAttribute( const std::string & attName, bool calledFromDaughter ) const
149{
150 AttIter_t i = m_attributes.find( attName );
151 if( i == m_attributes.end() ) {
152 if( m_parent != 0 )
153 return m_parent->GetAttribute( attName, true );
154 else
155 return std::string("");
156 }
157 if (calledFromDaughter && ! m_propagateDown && i->second.second) {
158 return std::string("");
159 }
160 return i->second.first;
161}
162
163// Like GetAttributes, but only returns attributes of *this* node,
164// not inherited ones
165std::string
167GetAttributeLocal( const std::string & attName ) const
168{
169 AttIter_t i = m_attributes.find( attName );
170 if( i == m_attributes.end() ) {
171 return std::string("");
172 }
173 return i->second.first;
174}
175
176
177void
179GetAttributeNames( std::set<std::string>& attSet, bool calledFromDaughter ) const
180{
181 if( m_parent !=0 ) {
182 m_parent->GetAttributeNames( attSet, true );
183 }
184 AttIter_t attEnd = m_attributes.end();
185 for( AttIter_t i = m_attributes.begin(); i != attEnd; ++i ) {
186 if (calledFromDaughter && ! m_propagateDown && i->second.second) {
187 } else {
188 std::set<std::string>::value_type setVal( i->first );
189 attSet.insert( std::move(setVal) );
190 }
191 }
192}
193
194// Like GetAttributeNames, but only returns attributes of this node
195void
197GetAttributeNamesLocal( std::set<std::string>& attSet ) const
198{
199 AttIter_t attEnd = m_attributes.end();
200 for( AttIter_t i = m_attributes.begin(); i != attEnd; ++i ) {
201 std::set<std::string>::value_type setVal( i->first );
202 attSet.insert( std::move(setVal) );
203 }
204}
205
206void
208Accept( Visitor& visitor ) const
209{
210 visitor.Visit(this);
211 NodeIter_t daugEnd = m_daughters.end();
212 for( NodeIter_t i = m_daughters.begin(); i != daugEnd; ++i ) {
213 MiniConfigTreeNode* node = i->second;
214 node->Accept(visitor);
215 }
216}
217
218void
220Accept(Writer& writer )
221{
222 writer.Write(this);
223 NodeIter_t daugEnd = m_daughters.end();
224 for( NodeIter_t i = m_daughters.begin(); i != daugEnd; ++i ) {
225 MiniConfigTreeNode* node = i->second;
226 node->Accept(writer);
227 }
228}
229
230void
232SetAttribKeywordPropagateDown( bool propagateDown )
233{
234 this->m_propagateDown = propagateDown;
235}
236
237bool
243
244} // namespace dqi
ClassImp(xAOD::Experimental::RFileChecker) namespace xAOD
virtual void Visit(const MiniConfigTreeNode *node)=0
A node of a tree structure holding a configuration, where each node may be given attributes,...
MiniConfigTreeNode * m_parent
virtual std::string GetAttributeLocal(const std::string &attName) const
MiniConfigTreeNode(std::string name_, MiniConfigTreeNode *parent_)
virtual const MiniConfigTreeNode * GetNode(const std::string &name_) const
This function takes the full path name of a subnode (in UNIX directory style) and returns the corresp...
virtual bool GetAttribKeywordPropagateDown() const
virtual MiniConfigTreeNode * GetDaughter(std::string name_) const
virtual const char * GetName() const
virtual std::map< std::string, dqi::MiniConfigTreeNode * > GetDaughters() const
virtual void Accept(Visitor &visitor) const
virtual MiniConfigTreeNode * GetNewDaughter(std::string name_)
Returns a daughter of this node, creating one if necessary.
AttMap_t::const_iterator AttIter_t
virtual std::string GetAttribute(const std::string &attName, bool calledFromDaughter=false) const
virtual void GetAttributeNames(std::set< std::string > &attSet, bool calledFromDaughter=false) const
virtual void SetAttribute(const std::string &attName, const std::string &attValue, bool isAttribKeyword=false)
virtual void SetAttribKeywordPropagateDown(bool propagateDown)
virtual std::string GetPathName() const
virtual void GetAttributeNamesLocal(std::set< std::string > &attSet) const
NodeMap_t::const_iterator NodeIter_t
Definition node.h:24
STL namespace.