The Gaudi Framework  master (da3d77e1)
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 
17 namespace Decays = Gaudi::Decays;
18 
25 Decays::NodeList::NodeList( const Decays::NodeList::Nodes_& nodes ) : m_nodes( nodes ) {}
26 void Decays::NodeList::push_back( const Decays::Nodes::_Node& node ) { m_nodes.push_back( node ); }
27 void 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 }
31 void 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
55 bool Decays::Nodes::Invalid::valid() const { return false; }
56 // MANDATORY: the proper validation of the node
58  return StatusCode::FAILURE;
59 }
60 // MANDATORY: the only one essential method
61 bool Decays::Nodes::Invalid::operator()( const Gaudi::ParticleID& /* p */ ) const { return false; }
62 std::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
73 Decays::Nodes::Or::Or( const Decays::iNode& n1, const Decays::iNode& n2, const Decays::iNode& n3 ) {
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
87 Decays::Nodes::Or::Or( const Decays::NodeList& nodes ) { add( nodes ); }
88 // add the node
89 size_t Decays::Nodes::Or::add( const Decays::iNode& 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
101 size_t Decays::Nodes::Or::add( const Decays::NodeList& nodes ) {
102  for ( const auto& n : nodes ) add( n );
103  return m_nodes.size();
104 }
105 // MANDATORY: clone method ("virtual constructor")
106 Decays::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
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
122 bool 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
149 Decays::Nodes::And::And( const Decays::NodeList& nodes ) { add( nodes ); }
150 // add the node
151 size_t Decays::Nodes::And::add( const Decays::iNode& 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")
168 Decays::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
176  return GaudiUtils::details::ostream_joiner( s << " (", m_nodes, "&" ) << ") ";
177 }
178 // MANDATORY: check the validity
179 bool 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
187 Decays::Nodes::Not::Not( const Decays::iNode& node ) : Decays::iNode(), m_node( node ) {}
188 // MANDATORY: clone method ("virtual constructor")
189 Decays::Nodes::Not* Decays::Nodes::Not::clone() const { return new Not( *this ); }
190 // valid ?
191 bool Decays::Nodes::Not::valid() const { return m_node.valid(); }
192 bool Decays::Nodes::Not::operator()( const Gaudi::ParticleID& pid ) const { return !m_node.node( pid ); }
194  return m_node.validate( svc );
195 }
196 
197 std::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 }
Gaudi::Decays::Nodes::Not::clone
Not * clone() const override
MANDATORY: clone method ("virtual constructor")
Definition: Nodes.cpp:189
Gaudi::Functional::details::details2::push_back
void push_back(Container &c, const Value &v, std::true_type)
Definition: details.h:252
Gaudi::Decays::Nodes::Or::Or
Or()
the default constructor is disabled
Gaudi::Decays::Node
Definition: iNode.h:74
Gaudi::Decays::NodeList
Definition: Nodes.h:169
DataOnDemand.Nodes
Nodes
Definition: DataOnDemand.py:34
Gaudi::Decays::Nodes::Invalid::operator()
bool operator()(const Gaudi::ParticleID &) const override
MANDATORY: the only one essential method.
Definition: Nodes.cpp:61
Gaudi::Decays::Nodes::Or::validate
StatusCode validate(const Gaudi::Interfaces::IParticlePropertySvc *svc) const override
MANDATORY: the proper validation of the node.
Definition: Nodes.cpp:124
Gaudi::Decays::Nodes::Or::operator()
bool operator()(const Gaudi::ParticleID &pid) const override
MANDATORY: the only one essential method.
Definition: Nodes.cpp:108
Gaudi::Decays::NodeList::const_iterator
Nodes_::const_iterator const_iterator
Definition: Nodes.h:173
gaudirun.s
string s
Definition: gaudirun.py:346
std::vector< Decays::Nodes::_Node >
std::find_if
T find_if(T... args)
Gaudi::Decays::Nodes::Invalid::validate
StatusCode validate(const Gaudi::Interfaces::IParticlePropertySvc *svc) const override
MANDATORY: the proper validation of the node.
Definition: Nodes.cpp:57
Gaudi::Interfaces::IParticlePropertySvc
Definition: IParticlePropertySvc.h:29
Gaudi::Decays::Nodes::Invalid::fillStream
std::ostream & fillStream(std::ostream &s) const override
MANDATORY: the specific printout.
Definition: Nodes.cpp:62
Gaudi::Decays::Nodes::_Node::op_or
_Node & op_or(const NodeList &right)
Definition: Nodes.cpp:43
Gaudi::Decays::Nodes::_Node
Definition: Nodes.h:96
Gaudi::Decays::Nodes::Not::Not
Not(const Decays::iNode &node)
constructor from the node
Definition: Nodes.cpp:187
ParticleID.h
Gaudi::Decays::NodeList::clear
void clear()
Definition: Nodes.h:184
Nodes.h
Gaudi::Decays::Nodes::Invalid::valid
bool valid() const override
MANDATORY: check the validity.
Definition: Nodes.cpp:55
std::all_of
T all_of(T... args)
Gaudi::Decays::Nodes::And::m_nodes
NodeList m_nodes
the sub-nodes
Definition: Nodes.h:301
Gaudi::Decays::Nodes::_Node::op_and
_Node & op_and(const NodeList &right)
Definition: Nodes.cpp:47
Gaudi::Decays::Nodes::Not::operator()
bool operator()(const Gaudi::ParticleID &pid) const override
MANDATORY: the only one essential method.
Definition: Nodes.cpp:192
EventStatus::Invalid
@ Invalid
Definition: IAlgExecStateSvc.h:72
Gaudi::Decays::Nodes::Not::validate
StatusCode validate(const Gaudi::Interfaces::IParticlePropertySvc *svc) const override
MANDATORY: the proper validation of the node.
Definition: Nodes.cpp:193
Gaudi::Decays::Nodes::Or::operator+=
Or & operator+=(const Decays::iNode &node)
Definition: Nodes.cpp:199
Gaudi::Decays::Nodes::Or::fillStream
std::ostream & fillStream(std::ostream &s) const override
MANDATORY: the specific printout.
Definition: Nodes.cpp:113
Gaudi::Decays::Nodes::And::operator+=
And & operator+=(const Decays::iNode &node)
Definition: Nodes.cpp:203
Gaudi::Decays::Nodes::Invalid
Definition: Nodes.h:74
Gaudi::Decays::Nodes::Or::add
size_t add(const Decays::iNode &node)
Definition: Nodes.cpp:89
Gaudi::Decays::Nodes::And::clone
And * clone() const override
MANDATORY: clone method ("virtual constructor")
Definition: Nodes.cpp:168
Gaudi::Decays::NodeList::operator=
NodeList & operator=(const Decays::Nodes::_Node &node)
Definition: Nodes.cpp:32
StatusCode
Definition: StatusCode.h:65
std::ostream
STL class.
Gaudi::Decays::Nodes::Or::m_nodes
Decays::NodeList m_nodes
the sub-nodes
Definition: Nodes.h:261
Gaudi::Decays::Nodes::And::fillStream
std::ostream & fillStream(std::ostream &s) const override
MANDATORY: the specific printout.
Definition: Nodes.cpp:175
Gaudi::Decays::Nodes::And::validate
StatusCode validate(const Gaudi::Interfaces::IParticlePropertySvc *svc) const override
MANDATORY: the proper validation of the node.
Definition: Nodes.cpp:181
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
GaudiPartProp.Nodes.Or
Or
Definition: Nodes.py:269
Gaudi::Decays::Nodes::And::And
And(const Decays::iNode &n1, const Decays::iNode &n2)
constructor from two nodes
Definition: Nodes.cpp:130
Gaudi::Decays::Node::node
const iNode & node() const
Definition: iNode.h:96
cpluginsvc.n
n
Definition: cpluginsvc.py:234
GaudiPartProp.decorators.Decays
Decays
Definition: decorators.py:33
Gaudi::Decays::Nodes::Or::clone
Or * clone() const override
MANDATORY: clone method ("virtual constructor")
Definition: Nodes.cpp:106
Gaudi::Decays
Definition: CC.h:17
GaudiPartProp.Nodes.Not
Not
Definition: Nodes.py:271
Gaudi::Decays::Nodes::And::add
size_t add(const Decays::iNode &node)
Definition: Nodes.cpp:151
std::vector::begin
T begin(T... args)
Gaudi::Decays::valid
bool valid(Iterator begin, Iterator end)
check the validness of the trees or nodes
Definition: Nodes.h:36
Gaudi::Decays::Nodes::And::operator()
bool operator()(const Gaudi::ParticleID &p) const override
MANDATORY: the only one essential method.
Definition: Nodes.cpp:170
Gaudi::ParticleID
Definition: ParticleID.h:43
Gaudi::Decays::Nodes::Invalid::clone
Invalid * clone() const override
MANDATORY: clone method ("virtual constructor")
Definition: Nodes.cpp:53
Gaudi::Decays::NodeList::NodeList
NodeList(const Nodes_ &nodes=Nodes_())
constructor from the list of Nodes
Definition: Nodes.cpp:25
Gaudi::Decays::Nodes::Or::valid
bool valid() const override
MANDATORY: check the validity.
Definition: Nodes.cpp:122
Gaudi::Decays::iNode
Definition: iNode.h:35
GaudiPartProp.Nodes.And
And
Definition: Nodes.py:270
SerializeSTL.h
Gaudi::Decays::NodeList::m_nodes
Nodes_ m_nodes
the actual list of nodes
Definition: Nodes.h:217
Gaudi::Decays::Nodes::And::valid
bool valid() const override
MANDATORY: check the validity.
Definition: Nodes.cpp:179
Gaudi::Decays::Nodes::Not::valid
bool valid() const override
MANDATORY: check the validity.
Definition: Nodes.cpp:191
std::vector::end
T end(T... args)
Gaudi::Decays::Nodes::_Node::_Node
_Node()
the default constructor
Definition: Nodes.cpp:65
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition: StatusCode.h:101
Gaudi::Decays::Nodes::Not
Definition: Nodes.h:309
Gaudi::Decays::NodeList::push_back
void push_back(const Decays::Nodes::_Node &node)
Definition: Nodes.cpp:26
GaudiPython.Persistency.add
def add(instance)
Definition: Persistency.py:50
Gaudi::Decays::Nodes::And
Definition: Nodes.h:270
GaudiUtils::details::ostream_joiner
Stream & ostream_joiner(Stream &os, Iterator first, Iterator last, Separator sep, OutputElement output=OutputElement{})
Definition: SerializeSTL.h:87
Gaudi::Decays::Nodes::Not::fillStream
std::ostream & fillStream(std::ostream &s) const override
MANDATORY: the specific printout.
Definition: Nodes.cpp:197