ATLAS Offline Software
MiniConfigTreeNode.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 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 
19 namespace dqi {
20 
21 // *********************************************************************
22 // Public Methods
23 // *********************************************************************
24 
26 MiniConfigTreeNode( 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 
45 const char*
47 GetName() const
48 {
49  return m_name.c_str();
50 }
51 
52 
53 std::string
55 GetPathName() 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 
72 GetNewDaughter( 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( nodeVal );
83  return node;
84 }
85 
86 
89 GetDaughter( 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 
99 std::map<std::string,MiniConfigTreeNode*>
101 GetDaughters() const
102 {
103  return m_daughters;
104 }
105 
106 const MiniConfigTreeNode*
108 GetNode( 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 
137 void
139 SetAttribute( std::string attName, std::string attValue, bool isAttribKeyword )
140 {
141  AttMap_t::value_type attMapVal( attName, AttMap_t::mapped_type(attValue, isAttribKeyword) );
142  m_attributes.insert( attMapVal );
143 }
144 
145 
146 std::string
148 GetAttribute( 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
165 std::string
167 GetAttributeLocal( 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 
177 void
179 GetAttributeNames( 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( setVal );
190  }
191  }
192 }
193 
194 // Like GetAttributeNames, but only returns attributes of this node
195 void
197 GetAttributeNamesLocal( 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( setVal );
203  }
204 }
205 
206 void
208 Accept( 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 
218 void
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 
230 void
232 SetAttribKeywordPropagateDown( bool propagateDown )
233 {
234  this->m_propagateDown = propagateDown;
235 }
236 
237 bool
240 {
241  return this->m_propagateDown;
242 }
243 
244 } // namespace dqi
dqi::MiniConfigTreeNode
A node of a tree structure holding a configuration, where each node may be given attributes,...
Definition: MiniConfigTreeNode.h:25
athena.path
path
python interpreter configuration --------------------------------------—
Definition: athena.py:128
dqi::MiniConfigTreeNode::m_propagateDown
bool m_propagateDown
Definition: MiniConfigTreeNode.h:106
MiniConfigTreeNode.h
dqi::MiniConfigTreeNode::GetAttribute
virtual std::string GetAttribute(std::string attName, bool calledFromDaughter=false) const
Definition: MiniConfigTreeNode.cxx:148
dqi::MiniConfigTreeNode::NodeIter_t
NodeMap_t::const_iterator NodeIter_t
Definition: MiniConfigTreeNode.h:95
dqi::MiniConfigTreeNode::SetAttribKeywordPropagateDown
virtual void SetAttribKeywordPropagateDown(bool propagateDown)
Definition: MiniConfigTreeNode.cxx:232
dqi::MiniConfigTreeNode::AttIter_t
AttMap_t::const_iterator AttIter_t
Definition: MiniConfigTreeNode.h:98
dqi::MiniConfigTreeNode::SetAttribute
virtual void SetAttribute(std::string attName, std::string attValue, bool isAttribKeyword=false)
Definition: MiniConfigTreeNode.cxx:139
dqi::MiniConfigTreeNode::Visitor::Visit
virtual void Visit(const MiniConfigTreeNode *node)=0
dqi::MiniConfigTreeNode::GetAttributeNames
virtual void GetAttributeNames(std::set< std::string > &attSet, bool calledFromDaughter=false) const
Definition: MiniConfigTreeNode.cxx:179
dqi::MiniConfigTreeNode::GetPathName
virtual std::string GetPathName() const
Definition: MiniConfigTreeNode.cxx:55
ClassImp
ClassImp(xAOD::TFileChecker) namespace xAOD
Definition: TFileChecker.cxx:28
lumiFormat.i
int i
Definition: lumiFormat.py:85
dqi::MiniConfigTreeNode::Visitor
Definition: MiniConfigTreeNode.h:28
dqi::MiniConfigTreeNode::m_attributes
AttMap_t m_attributes
Definition: MiniConfigTreeNode.h:104
dqi::MiniConfigTreeNode::Writer
Definition: MiniConfigTreeNode.h:34
PyPoolBrowser.node
node
Definition: PyPoolBrowser.py:131
dqi::MiniConfigTreeNode::GetDaughter
virtual MiniConfigTreeNode * GetDaughter(std::string name_) const
Definition: MiniConfigTreeNode.cxx:89
dqi::MiniConfigTreeNode::GetNode
virtual const MiniConfigTreeNode * GetNode(std::string name_) const
This function takes the full path name of a subnode (in UNIX directory style) and returns the corresp...
Definition: MiniConfigTreeNode.cxx:108
dqi::MiniConfigTreeNode::GetNewDaughter
virtual MiniConfigTreeNode * GetNewDaughter(std::string name_)
Returns a daughter of this node, creating one if necessary.
Definition: MiniConfigTreeNode.cxx:72
dqi::MiniConfigTreeNode::GetAttributeLocal
virtual std::string GetAttributeLocal(std::string attName) const
Definition: MiniConfigTreeNode.cxx:167
dqi::MiniConfigTreeNode::GetAttribKeywordPropagateDown
virtual bool GetAttribKeywordPropagateDown() const
Definition: MiniConfigTreeNode.cxx:239
dqi::MiniConfigTreeNode::MiniConfigTreeNode
MiniConfigTreeNode(std::string name_, MiniConfigTreeNode *parent_)
Definition: MiniConfigTreeNode.cxx:26
dqi::MiniConfigTreeNode::GetName
virtual const char * GetName() const
Definition: MiniConfigTreeNode.cxx:47
dqi::MiniConfigTreeNode::m_daughters
NodeMap_t m_daughters
Definition: MiniConfigTreeNode.h:103
dqi::MiniConfigTreeNode::Accept
virtual void Accept(Visitor &visitor) const
Definition: MiniConfigTreeNode.cxx:208
dqi::MiniConfigTreeNode::~MiniConfigTreeNode
virtual ~MiniConfigTreeNode()
Definition: MiniConfigTreeNode.cxx:35
example.writer
writer
show summary of content
Definition: example.py:36
dqi
Definition: CompositeAlgorithm.h:16
dqi::MiniConfigTreeNode::m_parent
MiniConfigTreeNode * m_parent
Definition: MiniConfigTreeNode.h:101
dqi::MiniConfigTreeNode::GetAttributeNamesLocal
virtual void GetAttributeNamesLocal(std::set< std::string > &attSet) const
Definition: MiniConfigTreeNode.cxx:197
node
Definition: memory_hooks-stdcmalloc.h:74
dqi::MiniConfigTreeNode::GetDaughters
virtual std::map< std::string, dqi::MiniConfigTreeNode * > GetDaughters() const
Definition: MiniConfigTreeNode.cxx:101
fitman.k
k
Definition: fitman.py:528
dqi::MiniConfigTreeNode::m_name
const std::string m_name
Definition: MiniConfigTreeNode.h:100
inode
Definition: listroot.cxx:155