The Gaudi Framework  master (37c0b60a)
Nodes.h
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2023 CERN for the benefit of the LHCb and ATLAS collaborations *
3 * *
4 * This software is distributed under the terms of the Apache version 2 licence, *
5 * copied verbatim in the file "LICENSE". *
6 * *
7 * In applying this licence, CERN does not waive the privileges and immunities *
8 * granted to it by virtue of its status as an Intergovernmental Organization *
9 * or submit itself to any jurisdiction. *
10 \***********************************************************************************/
11 #pragma once
12 
13 #include <Gaudi/Decays/Decay.h>
14 #include <Gaudi/Decays/iNode.h>
15 #include <Gaudi/ParticleID.h>
16 #include <GaudiKernel/Kernel.h>
17 #include <GaudiKernel/SmartIF.h>
18 #include <GaudiKernel/StatusCode.h>
19 #include <algorithm>
20 
27 namespace Gaudi::Decays {
35  template <typename Iterator>
37  return std::all_of( begin, end, []( const auto& i ) { return i.valid(); } );
38  }
39  template <typename Container>
40  bool valid( Container const& c ) {
41  return valid( c.begin(), c.end() );
42  }
43 
52  template <class Iterator>
54  for ( ; begin != end; ++begin ) {
55  StatusCode sc = begin->validate( svc );
56  if ( sc.isFailure() ) { return sc; }
57  }
58  return StatusCode::SUCCESS;
59  }
60  template <class TREE>
62  return validate( tree.begin(), tree.end(), svc );
63  }
64 
65  class NodeList;
66 
67  namespace Nodes {
74  class GAUDI_API Invalid : public Decays::iNode {
75  public:
77  Invalid() = default;
79  Invalid* clone() const override;
81  bool operator()( const Gaudi::ParticleID& /* p */ ) const override;
83  std::ostream& fillStream( std::ostream& s ) const override;
85  bool valid() const override;
87  StatusCode validate( const Gaudi::Interfaces::IParticlePropertySvc* svc ) const override;
88  };
89 
96  class GAUDI_API _Node {
97  public:
99  _Node();
101  _Node( const iNode& node ) : m_node( node ) {}
103  _Node( const Node& node ) : m_node( node ) {}
104  // default copy constructor
105  _Node( const _Node& node ) = default;
107  inline bool valid() const { return m_node.node().valid(); }
110  return m_node.node().validate( svc );
111  }
113  inline bool operator()( const Gaudi::ParticleID& pid ) const { return m_node.node( pid ); }
114 
115  inline bool operator==( const Gaudi::ParticleID& pid ) const { return m_node.node( pid ); }
116 
117  inline bool operator!=( const Gaudi::ParticleID& pid ) const { return !m_node.node( pid ); }
118 
120  _Node& operator=( const Node& right ) {
121  m_node = right;
122  return *this;
123  }
125  _Node& operator=( const iNode& right ) {
126  m_node = right;
127  return *this;
128  }
130  _Node& operator=( const _Node& right ) {
131  m_node = right.m_node;
132  return *this;
133  }
134 
135  _Node& operator|=( const iNode& right ) {
136  m_node |= right;
137  return *this;
138  }
139  _Node& operator&=( const iNode& right ) {
140  m_node &= right;
141  return *this;
142  }
143 
144  _Node& operator|=( const NodeList& right ) { return op_or( right ); }
145  _Node& operator&=( const NodeList& right ) { return op_and( right ); }
146 
147  _Node& operator|=( const _Node& right ) {
148  m_node |= right;
149  return *this;
150  }
151  _Node& operator&=( const _Node& right ) {
152  m_node &= right;
153  return *this;
154  }
155 
157  const Decays::iNode& node() const { return m_node.node(); }
159  operator const Decays::iNode&() const { return node(); }
160 
161  private:
162  _Node& op_or( const NodeList& right );
163  _Node& op_and( const NodeList& right );
166  };
167  } // namespace Nodes
168 
170  public:
173  typedef Nodes_::const_iterator const_iterator;
174  typedef Nodes_::iterator iterator;
175  typedef Nodes_::value_type value_type;
176 
178  NodeList( const Nodes_& nodes = Nodes_() );
179 
180  void push_back( const Decays::Nodes::_Node& node );
181  void push_back( const Decays::iNode& node );
182  void push_back( const Nodes_& nodes );
183  void push_back( const NodeList& nodes );
184  void clear() { m_nodes.clear(); }
185 
186  NodeList& operator=( const Decays::Nodes::_Node& node );
187  NodeList& operator=( const Decays::iNode& node );
188 
190  push_back( node );
191  return *this;
192  }
194  push_back( node );
195  return *this;
196  }
197  NodeList& operator+=( const Nodes_& nodes ) {
198  push_back( nodes );
199  return *this;
200  }
201  NodeList& operator+=( const NodeList& nodes ) {
202  push_back( nodes );
203  return *this;
204  }
205 
206  size_t size() const { return m_nodes.size(); }
207  bool empty() const { return m_nodes.empty(); }
208  iterator begin() { return m_nodes.begin(); }
209  iterator end() { return m_nodes.end(); }
210  const_iterator begin() const { return m_nodes.begin(); }
211  const_iterator end() const { return m_nodes.end(); }
212 
213  operator const Nodes_&() const { return m_nodes; }
214 
215  private:
218  };
219 
220  namespace Nodes {
227  class GAUDI_API Or : public Decays::iNode {
228  public:
230  Or( const Decays::iNode& n1, const Decays::iNode& n2 );
232  Or( const Decays::iNode& n1, const Decays::iNode& n2, const Decays::iNode& n3 );
234  Or( const Decays::iNode& n1, const Decays::iNode& n2, const Decays::iNode& n3, const Decays::iNode& n4 );
236  Or( const Decays::NodeList& nodes );
238  Or* clone() const override;
240  bool operator()( const Gaudi::ParticleID& pid ) const override;
242  std::ostream& fillStream( std::ostream& s ) const override;
244  bool valid() const override;
246  StatusCode validate( const Gaudi::Interfaces::IParticlePropertySvc* svc ) const override;
247 
248  protected:
249  size_t add( const Decays::iNode& node );
250  size_t add( const Decays::NodeList& nodes );
251 
252  public:
253  Or& operator+=( const Decays::iNode& node );
254  Or& operator+=( const Decays::NodeList& node );
255 
256  private:
258  Or(); // the default constructor is disabled
259 
262  };
263 
270  class GAUDI_API And : public Decays::iNode {
271  public:
273  And( const Decays::iNode& n1, const Decays::iNode& n2 );
275  And( const Decays::iNode& n1, const Decays::iNode& n2, const Decays::iNode& n3 );
277  And( const Decays::iNode& n1, const Decays::iNode& n2, const Decays::iNode& n3, const Decays::iNode& n4 );
279  And( const Decays::NodeList& nodes );
281  And* clone() const override;
283  bool operator()( const Gaudi::ParticleID& p ) const override;
285  std::ostream& fillStream( std::ostream& s ) const override;
287  bool valid() const override;
289  StatusCode validate( const Gaudi::Interfaces::IParticlePropertySvc* svc ) const override;
290 
291  protected:
292  size_t add( const Decays::iNode& node );
293  size_t add( const Decays::NodeList& nodes );
294 
295  public:
296  And& operator+=( const Decays::iNode& node );
297  And& operator+=( const Decays::NodeList& nodes );
298 
299  private:
302  };
303 
309  class GAUDI_API Not : public Decays::iNode {
310  public:
312  Not( const Decays::iNode& node );
314  Not* clone() const override;
316  bool operator()( const Gaudi::ParticleID& pid ) const override;
318  std::ostream& fillStream( std::ostream& s ) const override;
320  bool valid() const override;
322  StatusCode validate( const Gaudi::Interfaces::IParticlePropertySvc* svc ) const override;
323 
324  public:
326  const Decays::iNode& node() const { return m_node.node(); }
327 
328  private:
331  };
332 
337  inline Decays::Nodes::Not operator!( const Decays::Nodes::Not& o ) { return Decays::Node( o.node() ); }
338 
340  inline std::ostream& operator<<( std::ostream& s, const Decays::Nodes::_Node& n ) { return s << n.node(); }
341  } // namespace Nodes
342 
347  inline Decays::Nodes::Or operator||( const Decays::iNode& o1, const Decays::iNode& o2 ) {
348  return Decays::Nodes::Or( o1, o2 );
349  }
350 
355  inline Decays::Nodes::Or operator|( const Decays::iNode& o1, const Decays::iNode& o2 ) {
356  return Decays::Nodes::Or( o1, o2 );
357  }
358 
363  inline Decays::Nodes::And operator&&( const Decays::iNode& o1, const Decays::iNode& o2 ) {
364  return Decays::Nodes::And( o1, o2 );
365  }
366 
371  inline Decays::Nodes::And operator&( const Decays::iNode& o1, const Decays::iNode& o2 ) {
372  return Decays::Nodes::And( o1, o2 );
373  }
374 
379  inline Decays::Nodes::Not operator~( const Decays::iNode& o ) { return Decays::Nodes::Not( o ); }
380 
385  GAUDI_API
386  Decays::Nodes::Or operator||( const Decays::iNode& o1, const std::string& o2 );
387 
392  GAUDI_API
394 
399  GAUDI_API
401 
406  GAUDI_API
408 
413  GAUDI_API
414  Decays::Nodes::Or operator||( const std::string& o2, const Decays::iNode& o1 );
415 
420  GAUDI_API
422 
427  GAUDI_API
429 
434  GAUDI_API
436 
441  GAUDI_API
442  Decays::Nodes::And operator&&( const Decays::iNode& o1, const std::string& o2 );
443 
448  GAUDI_API
450 
455  GAUDI_API
457 
462  GAUDI_API
464 
469  GAUDI_API
470  Decays::Nodes::And operator&&( const std::string& o2, const Decays::iNode& o1 );
471 
476  GAUDI_API
478 
483  GAUDI_API
485 
490  GAUDI_API
492 
493 } // namespace Gaudi::Decays
Gaudi::Decays::NodeList::size
size_t size() const
Definition: Nodes.h:206
Gaudi::Decays::Nodes::_Node::operator==
bool operator==(const Gaudi::ParticleID &pid) const
Definition: Nodes.h:115
Gaudi::Functional::details::details2::push_back
void push_back(Container &c, const Value &v, std::true_type)
Definition: details.h:252
Gaudi::Decays::NodeList::Nodes_
std::vector< Decays::Nodes::_Node > Nodes_
the actual type of the sequence of nodes
Definition: Nodes.h:172
Gaudi::Decays::Nodes::Or::Or
Or()
the default constructor is disabled
GaudiPartProp.Nodes.NodeList
NodeList
Definition: Nodes.py:315
Gaudi::Decays::Node
Definition: iNode.h:74
Gaudi::Decays::Nodes::_Node::operator=
_Node & operator=(const Node &right)
pseudo-assignment operator:
Definition: Nodes.h:120
Gaudi::Decays::NodeList
Definition: Nodes.h:169
DataOnDemand.Nodes
Nodes
Definition: DataOnDemand.py:34
std::string
STL class.
Gaudi::Decays::NodeList::begin
const_iterator begin() const
Definition: Nodes.h:210
Gaudi::Decays::NodeList::empty
bool empty() const
Definition: Nodes.h:207
Gaudi::Decays::Nodes::_Node::_Node
_Node(const iNode &node)
the constructor from iNode
Definition: Nodes.h:101
Gaudi::Decays::operator&&
Decays::Nodes::And operator&&(const Decays::iNode &o1, const Decays::iNode &o2)
Create the "AND" of two nodes.
Definition: Nodes.h:363
Gaudi::Decays::NodeList::end
iterator end()
Definition: Nodes.h:209
Gaudi::Decays::NodeList::const_iterator
Nodes_::const_iterator const_iterator
Definition: Nodes.h:173
Gaudi::Decays::Nodes::_Node::operator&=
_Node & operator&=(const iNode &right)
Definition: Nodes.h:139
Gaudi::Decays::Nodes::Not::node
const Decays::iNode & node() const
get the underlying node
Definition: Nodes.h:326
gaudirun.s
string s
Definition: gaudirun.py:346
std::vector< Decays::Nodes::_Node >
Gaudi::Decays::Nodes::_Node::m_node
Decays::Node m_node
the node holder itself
Definition: Nodes.h:165
Gaudi::Interfaces::IParticlePropertySvc
Definition: IParticlePropertySvc.h:29
Gaudi::Decays::Nodes::_Node
Definition: Nodes.h:96
Gaudi::Decays::operator&
Decays::Nodes::And operator&(const Decays::iNode &o1, const Decays::iNode &o2)
Create the "AND" of two nodes.
Definition: Nodes.h:371
ParticleID.h
Gaudi::Decays::NodeList::clear
void clear()
Definition: Nodes.h:184
gaudirun.c
c
Definition: gaudirun.py:525
GaudiPartProp.Nodes._Node
_Node
Definition: Nodes.py:273
std::all_of
T all_of(T... args)
Gaudi::Decays::Nodes::And::m_nodes
NodeList m_nodes
the sub-nodes
Definition: Nodes.h:301
GaudiPartProp.Nodes.Node
Node
Definition: Nodes.py:247
Gaudi::Decays::Nodes::_Node::validate
StatusCode validate(const Gaudi::Interfaces::IParticlePropertySvc *svc) const
The proper validation of the node.
Definition: Nodes.h:109
Gaudi::Decays::Nodes::_Node::operator|=
_Node & operator|=(const _Node &right)
Definition: Nodes.h:147
StatusCode.h
Gaudi::Decays::NodeList::begin
iterator begin()
Definition: Nodes.h:208
Gaudi::Decays::Nodes::_Node::operator!=
bool operator!=(const Gaudi::ParticleID &pid) const
Definition: Nodes.h:117
Gaudi::Decays::NodeList::operator+=
NodeList & operator+=(const Decays::Nodes::_Node &node)
Definition: Nodes.h:189
Gaudi::Decays::Nodes::Invalid::Invalid
Invalid()=default
MANDATORY: default constructor.
Gaudi::Decays::Nodes::Invalid
Definition: Nodes.h:74
Gaudi::Decays::Nodes::operator<<
std::ostream & operator<<(std::ostream &s, const Decays::Nodes::_Node &n)
output operator
Definition: Nodes.h:340
SmartIF.h
Gaudi::Utils::begin
AttribStringParser::Iterator begin(const AttribStringParser &parser)
Definition: AttribStringParser.h:136
StatusCode
Definition: StatusCode.h:65
Gaudi::Decays::NodeList::end
const_iterator end() const
Definition: Nodes.h:211
Gaudi::Decays::NodeList::operator+=
NodeList & operator+=(const Nodes_ &nodes)
Definition: Nodes.h:197
Gaudi::Decays::operator||
Decays::Nodes::Or operator||(const Decays::iNode &o1, const Decays::iNode &o2)
Create the "OR" of two nodes.
Definition: Nodes.h:347
std::ostream
STL class.
Gaudi::Decays::Nodes::Or::m_nodes
Decays::NodeList m_nodes
the sub-nodes
Definition: Nodes.h:261
Gaudi::Decays::NodeList::iterator
Nodes_::iterator iterator
Definition: Nodes.h:174
Gaudi::Decays::validate
StatusCode validate(Iterator begin, Iterator end, const Gaudi::Interfaces::IParticlePropertySvc *svc)
validate trees/nodes
Definition: Nodes.h:53
Gaudi::Decays::Nodes::Or
Definition: Nodes.h:227
Gaudi::Decays::Nodes::_Node::node
const Decays::iNode & node() const
the accessor to the node
Definition: Nodes.h:157
GaudiPartProp.Nodes.Or
Or
Definition: Nodes.py:269
Gaudi::Decays::operator|
Decays::Nodes::Or operator|(const Decays::iNode &o1, const Decays::iNode &o2)
Create the "OR" of two nodes.
Definition: Nodes.h:355
Gaudi::Decays::Nodes::Not::m_node
Decays::Node m_node
the node itself
Definition: Nodes.h:330
Gaudi::ParticleProperty
Definition: ParticleProperty.h:37
Gaudi::Decays::operator~
Decays::Nodes::Not operator~(const Decays::iNode &o)
Create the "NOT" for the node.
Definition: Nodes.h:379
Gaudi::Decays::NodeList::operator+=
NodeList & operator+=(const NodeList &nodes)
Definition: Nodes.h:201
cpluginsvc.n
n
Definition: cpluginsvc.py:234
Gaudi::Decays::Nodes::_Node::valid
bool valid() const
Check the validity.
Definition: Nodes.h:107
Gaudi::Decays::NodeList::operator+=
NodeList & operator+=(const Decays::iNode &node)
Definition: Nodes.h:193
StatusCode::isFailure
bool isFailure() const
Definition: StatusCode.h:129
Gaudi::Decays
Definition: CC.h:17
GaudiPartProp.Nodes.Not
Not
Definition: Nodes.py:271
Gaudi::Decays::Nodes::_Node::operator&=
_Node & operator&=(const NodeList &right)
Definition: Nodes.h:145
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:100
Decay.h
Gaudi::Decays::valid
bool valid(Iterator begin, Iterator end)
check the validness of the trees or nodes
Definition: Nodes.h:36
Gaudi::Decays::Nodes::_Node::operator=
_Node & operator=(const iNode &right)
pseudo-assignment from arbitrary node
Definition: Nodes.h:125
Kernel.h
Gaudi::ParticleID
Definition: ParticleID.h:43
Gaudi::Decays::Nodes::_Node::operator&=
_Node & operator&=(const _Node &right)
Definition: Nodes.h:151
Gaudi::Decays::Decay::Item
Definition: Decay.h:39
Gaudi::Decays::Nodes::_Node::operator=
_Node & operator=(const _Node &right)
pseudo-assignment from arbitrary node
Definition: Nodes.h:130
Gaudi::Decays::NodeList::value_type
Nodes_::value_type value_type
Definition: Nodes.h:175
Gaudi::Decays::Nodes::_Node::operator|=
_Node & operator|=(const iNode &right)
Definition: Nodes.h:135
iNode.h
Gaudi::Decays::iNode
Definition: iNode.h:35
GaudiPartProp.Nodes.And
And
Definition: Nodes.py:270
Gaudi::Decays::NodeList::m_nodes
Nodes_ m_nodes
the actual list of nodes
Definition: Nodes.h:217
Gaudi::Decays::Nodes::_Node::_Node
_Node(const _Node &node)=default
IOTest.end
end
Definition: IOTest.py:125
Gaudi::Decays::Nodes::operator!
Decays::Nodes::Not operator!(const Decays::Nodes::Not &o)
Create the "NOT" for the node.
Definition: Nodes.h:337
Gaudi::Decays::Nodes::_Node::operator|=
_Node & operator|=(const NodeList &right)
Definition: Nodes.h:144
Gaudi::Decays::Nodes::Not
Definition: Nodes.h:309
GAUDI_API
#define GAUDI_API
Definition: Kernel.h:81
GaudiPython.Persistency.add
def add(instance)
Definition: Persistency.py:50
Gaudi::Decays::Nodes::And
Definition: Nodes.h:270
Gaudi::Decays::Nodes::_Node::operator()
bool operator()(const Gaudi::ParticleID &pid) const
The major method.
Definition: Nodes.h:113
Iterator
boost::spirit::classic::position_iterator2< ForwardIterator > Iterator
Definition: Iterator.h:28
Gaudi::Decays::Nodes::_Node::_Node
_Node(const Node &node)
the constructor from Node
Definition: Nodes.h:103