The Gaudi Framework  master (181af51f)
Loading...
Searching...
No Matches
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>
19#include <algorithm>
20
27namespace Gaudi::Decays {
35 template <typename Iterator>
36 bool valid( Iterator begin, Iterator end ) {
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 }
59 }
60 template <class TREE>
62 return validate( tree.begin(), tree.end(), svc );
63 }
64
65 class NodeList;
66
67 namespace Nodes {
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;
88 };
89
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 }
112
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 }
124
125 _Node& operator=( const iNode& right ) {
126 m_node = right;
127 return *this;
128 }
129
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:
172 typedef std::vector<Decays::Nodes::_Node> Nodes_;
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;
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;
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;
323
324 public:
326 const Decays::iNode& node() const { return m_node.node(); }
327
328 private:
331 };
332
338
340 inline std::ostream& operator<<( std::ostream& s, const Decays::Nodes::_Node& n ) { return s << n.node(); }
341 } // namespace Nodes
342
348 return Decays::Nodes::Or( o1, o2 );
349 }
350
356 return Decays::Nodes::Or( o1, o2 );
357 }
358
364 return Decays::Nodes::And( o1, o2 );
365 }
366
372 return Decays::Nodes::And( o1, o2 );
373 }
374
380
386 Decays::Nodes::Or operator||( const Decays::iNode& o1, const std::string& o2 );
387
394
401
408
414 Decays::Nodes::Or operator||( const std::string& o2, const Decays::iNode& o1 );
415
422
429
436
442 Decays::Nodes::And operator&&( const Decays::iNode& o1, const std::string& o2 );
443
450
457
464
470 Decays::Nodes::And operator&&( const std::string& o2, const Decays::iNode& o1 );
471
478
485
492
493} // namespace Gaudi::Decays
boost::spirit::classic::position_iterator2< ForwardIterator > Iterator
Definition Iterator.h:18
#define GAUDI_API
Definition Kernel.h:49
the helper representation of the item in the decay chain
Definition Decay.h:39
The generic class to hold the pointer to other node.
Definition iNode.h:74
size_t size() const
Definition Nodes.h:206
NodeList & operator+=(const NodeList &nodes)
Definition Nodes.h:201
Nodes_::iterator iterator
Definition Nodes.h:174
std::vector< Decays::Nodes::_Node > Nodes_
the actual type of the sequence of nodes
Definition Nodes.h:172
NodeList & operator+=(const Nodes_ &nodes)
Definition Nodes.h:197
const_iterator end() const
Definition Nodes.h:211
Nodes_::value_type value_type
Definition Nodes.h:175
Nodes_::const_iterator const_iterator
Definition Nodes.h:173
Nodes_ m_nodes
the actual list of nodes
Definition Nodes.h:217
bool empty() const
Definition Nodes.h:207
NodeList(const Nodes_ &nodes=Nodes_())
constructor from the list of Nodes
Definition Nodes.cpp:25
void push_back(const Decays::Nodes::_Node &node)
Definition Nodes.cpp:26
const_iterator begin() const
Definition Nodes.h:210
NodeList & operator+=(const Decays::Nodes::_Node &node)
Definition Nodes.h:189
NodeList & operator+=(const Decays::iNode &node)
Definition Nodes.h:193
Helper structure (especially it is light version node-holder the default constructor.
Definition Nodes.h:96
_Node & operator=(const _Node &right)
pseudo-assignment from arbitrary node
Definition Nodes.h:130
bool valid() const
Check the validity.
Definition Nodes.h:107
const Decays::iNode & node() const
the accessor to the node
Definition Nodes.h:157
_Node & op_or(const NodeList &right)
Definition Nodes.cpp:43
Decays::Node m_node
the node holder itself
Definition Nodes.h:165
_Node & operator&=(const _Node &right)
Definition Nodes.h:151
_Node & operator&=(const iNode &right)
Definition Nodes.h:139
bool operator!=(const Gaudi::ParticleID &pid) const
Definition Nodes.h:117
_Node & operator&=(const NodeList &right)
Definition Nodes.h:145
StatusCode validate(const Gaudi::Interfaces::IParticlePropertySvc *svc) const
The proper validation of the node.
Definition Nodes.h:109
_Node & operator=(const iNode &right)
pseudo-assignment from arbitrary node
Definition Nodes.h:125
_Node(const _Node &node)=default
bool operator==(const Gaudi::ParticleID &pid) const
Definition Nodes.h:115
bool operator()(const Gaudi::ParticleID &pid) const
The major method.
Definition Nodes.h:113
_Node & operator|=(const _Node &right)
Definition Nodes.h:147
_Node & operator=(const Node &right)
pseudo-assignment operator:
Definition Nodes.h:120
_Node()
the default constructor
Definition Nodes.cpp:65
_Node & operator|=(const iNode &right)
Definition Nodes.h:135
_Node(const Node &node)
the constructor from Node
Definition Nodes.h:103
_Node & op_and(const NodeList &right)
Definition Nodes.cpp:47
_Node & operator|=(const NodeList &right)
Definition Nodes.h:144
_Node(const iNode &node)
the constructor from iNode
Definition Nodes.h:101
the rather simple (but powerful) node in the decay tree: it matches .AND.
Definition Nodes.h:270
bool valid() const override
MANDATORY: check the validity.
Definition Nodes.cpp:179
size_t add(const Decays::iNode &node)
Definition Nodes.cpp:151
NodeList m_nodes
the sub-nodes
Definition Nodes.h:301
And & operator+=(const Decays::iNode &node)
Definition Nodes.cpp:203
StatusCode validate(const Gaudi::Interfaces::IParticlePropertySvc *svc) const override
MANDATORY: the proper validation of the node.
Definition Nodes.cpp:181
And * clone() const override
MANDATORY: clone method ("virtual constructor")
Definition Nodes.cpp:168
And(const Decays::iNode &n1, const Decays::iNode &n2)
constructor from two nodes
Definition Nodes.cpp:130
bool operator()(const Gaudi::ParticleID &p) const override
MANDATORY: the only one essential method.
Definition Nodes.cpp:170
std::ostream & fillStream(std::ostream &s) const override
MANDATORY: the specific printout.
Definition Nodes.cpp:175
std::ostream & fillStream(std::ostream &s) const override
MANDATORY: the specific printout.
Definition Nodes.cpp:62
Invalid()=default
MANDATORY: default constructor.
bool valid() const override
MANDATORY: check the validity.
Definition Nodes.cpp:55
bool operator()(const Gaudi::ParticleID &) const override
MANDATORY: the only one essential method.
Definition Nodes.cpp:61
StatusCode validate(const Gaudi::Interfaces::IParticlePropertySvc *svc) const override
MANDATORY: the proper validation of the node.
Definition Nodes.cpp:57
Invalid * clone() const override
MANDATORY: clone method ("virtual constructor")
Definition Nodes.cpp:53
Simple node which match "NOT" for the subnode.
Definition Nodes.h:309
bool valid() const override
MANDATORY: check the validity.
Definition Nodes.cpp:191
const Decays::iNode & node() const
get the underlying node
Definition Nodes.h:326
Not * clone() const override
MANDATORY: clone method ("virtual constructor")
Definition Nodes.cpp:189
std::ostream & fillStream(std::ostream &s) const override
MANDATORY: the specific printout.
Definition Nodes.cpp:197
StatusCode validate(const Gaudi::Interfaces::IParticlePropertySvc *svc) const override
MANDATORY: the proper validation of the node.
Definition Nodes.cpp:193
Not(const Decays::iNode &node)
constructor from the node
Definition Nodes.cpp:187
bool operator()(const Gaudi::ParticleID &pid) const override
MANDATORY: the only one essential method.
Definition Nodes.cpp:192
Decays::Node m_node
the node itself
Definition Nodes.h:330
the rather simple (but powerful) node in the decay tree: it matches .OR.
Definition Nodes.h:227
StatusCode validate(const Gaudi::Interfaces::IParticlePropertySvc *svc) const override
MANDATORY: the proper validation of the node.
Definition Nodes.cpp:124
Or(const Decays::iNode &n1, const Decays::iNode &n2)
constructor from two nodes
Definition Nodes.cpp:68
Or & operator+=(const Decays::iNode &node)
Definition Nodes.cpp:199
Decays::NodeList m_nodes
the sub-nodes
Definition Nodes.h:261
Or()
the default constructor is disabled
bool valid() const override
MANDATORY: check the validity.
Definition Nodes.cpp:122
size_t add(const Decays::iNode &node)
Definition Nodes.cpp:89
bool operator()(const Gaudi::ParticleID &pid) const override
MANDATORY: the only one essential method.
Definition Nodes.cpp:108
std::ostream & fillStream(std::ostream &s) const override
MANDATORY: the specific printout.
Definition Nodes.cpp:113
Or * clone() const override
MANDATORY: clone method ("virtual constructor")
Definition Nodes.cpp:106
The abstract class which represents the single "node" of decay tree.
Definition iNode.h:35
The abstract interface to Particle Property Service.
Holds PDG + LHCb extension particle code, following the PDG particle numbering scheme (pdg....
Definition ParticleID.h:43
A trivial class to hold information about a single particle properties.
This class is used for returning status codes from appropriate routines.
Definition StatusCode.h:64
bool isFailure() const
Definition StatusCode.h:129
constexpr static const auto SUCCESS
Definition StatusCode.h:99
Decays::Nodes::Not operator!(const Decays::Nodes::Not &o)
Create the "NOT" for the node.
Definition Nodes.h:337
std::ostream & operator<<(std::ostream &s, const Decays::Nodes::_Node &n)
output operator
Definition Nodes.h:340
bool valid(Iterator begin, Iterator end)
check the validness of the trees or nodes
Definition Nodes.h:36
Decays::Nodes::And operator&&(const Decays::iNode &o1, const Decays::iNode &o2)
Create the "AND" of two nodes.
Definition Nodes.h:363
Decays::Nodes::Not operator~(const Decays::iNode &o)
Create the "NOT" for the node.
Definition Nodes.h:379
Decays::Nodes::And operator&(const Decays::iNode &o1, const Decays::iNode &o2)
Create the "AND" of two nodes.
Definition Nodes.h:371
StatusCode validate(Iterator begin, Iterator end, const Gaudi::Interfaces::IParticlePropertySvc *svc)
validate trees/nodes
Definition Nodes.h:53
Decays::Nodes::Or operator|(const Decays::iNode &o1, const Decays::iNode &o2)
Create the "OR" of two nodes.
Definition Nodes.h:355
Decays::Nodes::Or operator||(const Decays::iNode &o1, const Decays::iNode &o2)
Create the "OR" of two nodes.
Definition Nodes.h:347