The Gaudi Framework  master (181af51f)
Loading...
Searching...
No Matches
Nodes.cpp
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#include <Gaudi/Decays/Nodes.h>
12#include <Gaudi/ParticleID.h>
14#include <algorithm>
15#include <functional>
16
17namespace Decays = Gaudi::Decays;
18
24
26void Decays::NodeList::push_back( const Decays::Nodes::_Node& node ) { m_nodes.push_back( node ); }
27void Decays::NodeList::push_back( const Decays::iNode& node ) { m_nodes.push_back( node ); }
29 m_nodes.insert( m_nodes.end(), nodes.begin(), nodes.end() );
30}
31void Decays::NodeList::push_back( const NodeList& nodes ) { push_back( nodes.m_nodes ); }
33 m_nodes.clear();
34 push_back( node );
35 return *this;
36}
38 m_nodes.clear();
39 push_back( node );
40 return *this;
41}
42
44 if ( !right.empty() ) { m_node |= Decays::Nodes::Or( right ); }
45 return *this;
46}
48 if ( !right.empty() ) { m_node &= Decays::Nodes::And( right ); }
49 return *this;
50}
51
52// MANDATORY: clone method ("virtual constructor")
54// MANDATORY: check the validity
55bool Decays::Nodes::Invalid::valid() const { return false; }
56// MANDATORY: the proper validation of the node
60// MANDATORY: the only one essential method
61bool Decays::Nodes::Invalid::operator()( const Gaudi::ParticleID& /* p */ ) const { return false; }
62std::ostream& Decays::Nodes::Invalid::fillStream( std::ostream& s ) const { return s << " <INVALID> "; }
63
64// the default constructor
66
67// constructor from two nodes
69 add( n1 );
70 add( n2 );
71}
72// constructor from three nodes
74 add( n1 );
75 add( n2 );
76 add( n3 );
77}
78// constructor from four nodes
80 const Decays::iNode& n4 ) {
81 add( n1 );
82 add( n2 );
83 add( n3 );
84 add( n4 );
85}
86// constructor from list of nodes
87Decays::Nodes::Or::Or( const Decays::NodeList& nodes ) { add( nodes ); }
88// add the node
90 const Decays::iNode* right = &node;
91 const Or* _or = dynamic_cast<const Or*>( right );
92 if ( 0 != _or ) { return add( _or->m_nodes ); } // RETURN
93 // holder ?
94 const Node* _no = dynamic_cast<const Node*>( right );
95 if ( 0 != _no ) { return add( _no->node() ); } // RETURN
96 // just add the node
97 m_nodes.push_back( node );
98 return m_nodes.size();
99}
100// add the list of nodes
102 for ( const auto& n : nodes ) add( n );
103 return m_nodes.size();
104}
105// MANDATORY: clone method ("virtual constructor")
106Decays::Nodes::Or* Decays::Nodes::Or::clone() const { return new Or( *this ); }
107// MANDATORY: the only one essential method
109 return m_nodes.end() != std::find_if( m_nodes.begin(), m_nodes.end(),
110 [&]( const Decays::Nodes::_Node& node ) { return node( pid ); } );
111}
112// MANDATORY: the specific printout
113std::ostream& Decays::Nodes::Or::fillStream( std::ostream& s ) const {
114 s << " (";
115 for ( Decays::NodeList::const_iterator node = m_nodes.begin(); m_nodes.end() != node; ++node ) {
116 if ( m_nodes.begin() != node ) { s << "|"; }
117 s << *node;
118 }
119 return s << ") ";
120}
121// MANDATORY: check the validity
122bool Decays::Nodes::Or::valid() const { return !m_nodes.empty() && Decays::valid( m_nodes.begin(), m_nodes.end() ); }
123// MANDATORY: the proper validation of the node
125 if ( m_nodes.empty() ) { return StatusCode::FAILURE; }
126 return Decays::validate( m_nodes.begin(), m_nodes.end(), svc );
127}
128
129// constructor from two nodes
131 add( n1 );
132 add( n2 );
133}
134// constructor from three nodes
136 add( n1 );
137 add( n2 );
138 add( n3 );
139}
140// constructor from four nodes
142 const Decays::iNode& n4 ) {
143 add( n1 );
144 add( n2 );
145 add( n3 );
146 add( n4 );
147}
148// constructor form list of nodes
149Decays::Nodes::And::And( const Decays::NodeList& nodes ) { add( nodes ); }
150// add the node
152 const Decays::iNode* right = &node;
153 const And* _and = dynamic_cast<const And*>( right );
154 if ( 0 != _and ) { return add( _and->m_nodes ); } // RETURN
155 // holder ?
156 const Node* _no = dynamic_cast<const Node*>( right );
157 if ( 0 != _no ) { return add( _no->node() ); } // RETURN
158 // just add the node
159 m_nodes.push_back( node );
160 return m_nodes.size();
161}
162// add the list of nodes
164 for ( const auto& n : nodes ) add( n );
165 return m_nodes.size();
166}
167// MANDATORY: clone method ("virtual constructor")
168Decays::Nodes::And* Decays::Nodes::And::clone() const { return new And( *this ); }
169// MANDATORY: the only one essential method
171 if ( m_nodes.empty() ) { return false; }
172 return std::all_of( m_nodes.begin(), m_nodes.end(), [&]( const Decays::Nodes::_Node& n ) { return n == pid; } );
173}
174// MANDATORY: the specific printout
175std::ostream& Decays::Nodes::And::fillStream( std::ostream& s ) const {
176 return GaudiUtils::details::ostream_joiner( s << " (", m_nodes, "&" ) << ") ";
177}
178// MANDATORY: check the validity
179bool Decays::Nodes::And::valid() const { return !m_nodes.empty() && Decays::valid( m_nodes.begin(), m_nodes.end() ); }
180// MANDATORY: the proper validation of the node
182 if ( m_nodes.empty() ) { return StatusCode::FAILURE; }
183 return Decays::validate( m_nodes.begin(), m_nodes.end(), svc );
184}
185
186// constructor from the node
188// MANDATORY: clone method ("virtual constructor")
189Decays::Nodes::Not* Decays::Nodes::Not::clone() const { return new Not( *this ); }
190// valid ?
191bool Decays::Nodes::Not::valid() const { return m_node.valid(); }
192bool Decays::Nodes::Not::operator()( const Gaudi::ParticleID& pid ) const { return !m_node.node( pid ); }
194 return m_node.validate( svc );
195}
196
197std::ostream& Decays::Nodes::Not::fillStream( std::ostream& s ) const { return s << " ~(" << m_node << ") "; }
198
200 add( node );
201 return *this;
202}
204 add( node );
205 return *this;
206}
208 add( nodes );
209 return *this;
210}
212 add( nodes );
213 return *this;
214}
Helper general purpose utilities to deal with decay nodes.
Provide serialization function (output only) for some common STL classes (vectors,...
The generic class to hold the pointer to other node.
Definition iNode.h:74
const iNode & node() const
Definition iNode.h:96
NodeList & operator=(const Decays::Nodes::_Node &node)
Definition Nodes.cpp:32
std::vector< Decays::Nodes::_Node > Nodes_
the actual type of the sequence of nodes
Definition Nodes.h:172
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
Helper structure (especially it is light version node-holder the default constructor.
Definition Nodes.h:96
_Node & op_or(const NodeList &right)
Definition Nodes.cpp:43
Decays::Node m_node
the node holder itself
Definition Nodes.h:165
_Node()
the default constructor
Definition Nodes.cpp:65
_Node & op_and(const NodeList &right)
Definition Nodes.cpp:47
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
the most simple node to represent the invalid node it matches to all valid the Gaudi::Particles
Definition Nodes.h:74
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
This class is used for returning status codes from appropriate routines.
Definition StatusCode.h:64
constexpr static const auto FAILURE
Definition StatusCode.h:100
bool valid(Iterator begin, Iterator end)
check the validness of the trees or nodes
Definition Nodes.h:36
StatusCode validate(Iterator begin, Iterator end, const Gaudi::Interfaces::IParticlePropertySvc *svc)
validate trees/nodes
Definition Nodes.h:53
Stream & ostream_joiner(Stream &os, Iterator first, Iterator last, Separator sep, OutputElement output=OutputElement{})