File indexing completed on 2025-07-03 08:36:34
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #pragma once
0012
0013 #include <Gaudi/Decays/Decay.h>
0014 #include <Gaudi/Decays/iNode.h>
0015 #include <Gaudi/ParticleID.h>
0016 #include <GaudiKernel/Kernel.h>
0017 #include <GaudiKernel/SmartIF.h>
0018 #include <GaudiKernel/StatusCode.h>
0019 #include <algorithm>
0020
0021
0022
0023
0024
0025
0026
0027 namespace Gaudi::Decays {
0028
0029
0030
0031
0032
0033
0034
0035 template <typename Iterator>
0036 bool valid( Iterator begin, Iterator end ) {
0037 return std::all_of( begin, end, []( const auto& i ) { return i.valid(); } );
0038 }
0039 template <typename Container>
0040 bool valid( Container const& c ) {
0041 return valid( c.begin(), c.end() );
0042 }
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052 template <class Iterator>
0053 StatusCode validate( Iterator begin, Iterator end, const Gaudi::Interfaces::IParticlePropertySvc* svc ) {
0054 for ( ; begin != end; ++begin ) {
0055 StatusCode sc = begin->validate( svc );
0056 if ( sc.isFailure() ) { return sc; }
0057 }
0058 return StatusCode::SUCCESS;
0059 }
0060 template <class TREE>
0061 StatusCode validate( TREE const& tree, const Gaudi::Interfaces::IParticlePropertySvc* svc ) {
0062 return validate( tree.begin(), tree.end(), svc );
0063 }
0064
0065 class NodeList;
0066
0067 namespace Nodes {
0068
0069
0070
0071
0072
0073
0074 class GAUDI_API Invalid : public Decays::iNode {
0075 public:
0076
0077 Invalid() = default;
0078
0079 Invalid* clone() const override;
0080
0081 bool operator()( const Gaudi::ParticleID& ) const override;
0082
0083 std::ostream& fillStream( std::ostream& s ) const override;
0084
0085 bool valid() const override;
0086
0087 StatusCode validate( const Gaudi::Interfaces::IParticlePropertySvc* svc ) const override;
0088 };
0089
0090
0091
0092
0093
0094
0095
0096 class GAUDI_API _Node {
0097 public:
0098
0099 _Node();
0100
0101 _Node( const iNode& node ) : m_node( node ) {}
0102
0103 _Node( const Node& node ) : m_node( node ) {}
0104
0105 _Node( const _Node& node ) = default;
0106
0107 inline bool valid() const { return m_node.node().valid(); }
0108
0109 inline StatusCode validate( const Gaudi::Interfaces::IParticlePropertySvc* svc ) const {
0110 return m_node.node().validate( svc );
0111 }
0112
0113 inline bool operator()( const Gaudi::ParticleID& pid ) const { return m_node.node( pid ); }
0114
0115 inline bool operator==( const Gaudi::ParticleID& pid ) const { return m_node.node( pid ); }
0116
0117 inline bool operator!=( const Gaudi::ParticleID& pid ) const { return !m_node.node( pid ); }
0118
0119
0120 _Node& operator=( const Node& right ) {
0121 m_node = right;
0122 return *this;
0123 }
0124
0125 _Node& operator=( const iNode& right ) {
0126 m_node = right;
0127 return *this;
0128 }
0129
0130 _Node& operator=( const _Node& right ) {
0131 m_node = right.m_node;
0132 return *this;
0133 }
0134
0135 _Node& operator|=( const iNode& right ) {
0136 m_node |= right;
0137 return *this;
0138 }
0139 _Node& operator&=( const iNode& right ) {
0140 m_node &= right;
0141 return *this;
0142 }
0143
0144 _Node& operator|=( const NodeList& right ) { return op_or( right ); }
0145 _Node& operator&=( const NodeList& right ) { return op_and( right ); }
0146
0147 _Node& operator|=( const _Node& right ) {
0148 m_node |= right;
0149 return *this;
0150 }
0151 _Node& operator&=( const _Node& right ) {
0152 m_node &= right;
0153 return *this;
0154 }
0155
0156
0157 const Decays::iNode& node() const { return m_node.node(); }
0158
0159 operator const Decays::iNode&() const { return node(); }
0160
0161 private:
0162 _Node& op_or( const NodeList& right );
0163 _Node& op_and( const NodeList& right );
0164
0165 Decays::Node m_node;
0166 };
0167 }
0168
0169 class GAUDI_API NodeList {
0170 public:
0171
0172 typedef std::vector<Decays::Nodes::_Node> Nodes_;
0173 typedef Nodes_::const_iterator const_iterator;
0174 typedef Nodes_::iterator iterator;
0175 typedef Nodes_::value_type value_type;
0176
0177
0178 NodeList( const Nodes_& nodes = Nodes_() );
0179
0180 void push_back( const Decays::Nodes::_Node& node );
0181 void push_back( const Decays::iNode& node );
0182 void push_back( const Nodes_& nodes );
0183 void push_back( const NodeList& nodes );
0184 void clear() { m_nodes.clear(); }
0185
0186 NodeList& operator=( const Decays::Nodes::_Node& node );
0187 NodeList& operator=( const Decays::iNode& node );
0188
0189 NodeList& operator+=( const Decays::Nodes::_Node& node ) {
0190 push_back( node );
0191 return *this;
0192 }
0193 NodeList& operator+=( const Decays::iNode& node ) {
0194 push_back( node );
0195 return *this;
0196 }
0197 NodeList& operator+=( const Nodes_& nodes ) {
0198 push_back( nodes );
0199 return *this;
0200 }
0201 NodeList& operator+=( const NodeList& nodes ) {
0202 push_back( nodes );
0203 return *this;
0204 }
0205
0206 size_t size() const { return m_nodes.size(); }
0207 bool empty() const { return m_nodes.empty(); }
0208 iterator begin() { return m_nodes.begin(); }
0209 iterator end() { return m_nodes.end(); }
0210 const_iterator begin() const { return m_nodes.begin(); }
0211 const_iterator end() const { return m_nodes.end(); }
0212
0213 operator const Nodes_&() const { return m_nodes; }
0214
0215 private:
0216
0217 Nodes_ m_nodes;
0218 };
0219
0220 namespace Nodes {
0221
0222
0223
0224
0225
0226
0227 class GAUDI_API Or : public Decays::iNode {
0228 public:
0229
0230 Or( const Decays::iNode& n1, const Decays::iNode& n2 );
0231
0232 Or( const Decays::iNode& n1, const Decays::iNode& n2, const Decays::iNode& n3 );
0233
0234 Or( const Decays::iNode& n1, const Decays::iNode& n2, const Decays::iNode& n3, const Decays::iNode& n4 );
0235
0236 Or( const Decays::NodeList& nodes );
0237
0238 Or* clone() const override;
0239
0240 bool operator()( const Gaudi::ParticleID& pid ) const override;
0241
0242 std::ostream& fillStream( std::ostream& s ) const override;
0243
0244 bool valid() const override;
0245
0246 StatusCode validate( const Gaudi::Interfaces::IParticlePropertySvc* svc ) const override;
0247
0248 protected:
0249 size_t add( const Decays::iNode& node );
0250 size_t add( const Decays::NodeList& nodes );
0251
0252 public:
0253 Or& operator+=( const Decays::iNode& node );
0254 Or& operator+=( const Decays::NodeList& node );
0255
0256 private:
0257
0258 Or();
0259
0260
0261 Decays::NodeList m_nodes;
0262 };
0263
0264
0265
0266
0267
0268
0269
0270 class GAUDI_API And : public Decays::iNode {
0271 public:
0272
0273 And( const Decays::iNode& n1, const Decays::iNode& n2 );
0274
0275 And( const Decays::iNode& n1, const Decays::iNode& n2, const Decays::iNode& n3 );
0276
0277 And( const Decays::iNode& n1, const Decays::iNode& n2, const Decays::iNode& n3, const Decays::iNode& n4 );
0278
0279 And( const Decays::NodeList& nodes );
0280
0281 And* clone() const override;
0282
0283 bool operator()( const Gaudi::ParticleID& p ) const override;
0284
0285 std::ostream& fillStream( std::ostream& s ) const override;
0286
0287 bool valid() const override;
0288
0289 StatusCode validate( const Gaudi::Interfaces::IParticlePropertySvc* svc ) const override;
0290
0291 protected:
0292 size_t add( const Decays::iNode& node );
0293 size_t add( const Decays::NodeList& nodes );
0294
0295 public:
0296 And& operator+=( const Decays::iNode& node );
0297 And& operator+=( const Decays::NodeList& nodes );
0298
0299 private:
0300
0301 NodeList m_nodes;
0302 };
0303
0304
0305
0306
0307
0308
0309 class GAUDI_API Not : public Decays::iNode {
0310 public:
0311
0312 Not( const Decays::iNode& node );
0313
0314 Not* clone() const override;
0315
0316 bool operator()( const Gaudi::ParticleID& pid ) const override;
0317
0318 std::ostream& fillStream( std::ostream& s ) const override;
0319
0320 bool valid() const override;
0321
0322 StatusCode validate( const Gaudi::Interfaces::IParticlePropertySvc* svc ) const override;
0323
0324 public:
0325
0326 const Decays::iNode& node() const { return m_node.node(); }
0327
0328 private:
0329
0330 Decays::Node m_node;
0331 };
0332
0333
0334
0335
0336
0337 inline Decays::Nodes::Not operator!( const Decays::Nodes::Not& o ) { return Decays::Node( o.node() ); }
0338
0339
0340 inline std::ostream& operator<<( std::ostream& s, const Decays::Nodes::_Node& n ) { return s << n.node(); }
0341 }
0342
0343
0344
0345
0346
0347 inline Decays::Nodes::Or operator||( const Decays::iNode& o1, const Decays::iNode& o2 ) {
0348 return Decays::Nodes::Or( o1, o2 );
0349 }
0350
0351
0352
0353
0354
0355 inline Decays::Nodes::Or operator|( const Decays::iNode& o1, const Decays::iNode& o2 ) {
0356 return Decays::Nodes::Or( o1, o2 );
0357 }
0358
0359
0360
0361
0362
0363 inline Decays::Nodes::And operator&&( const Decays::iNode& o1, const Decays::iNode& o2 ) {
0364 return Decays::Nodes::And( o1, o2 );
0365 }
0366
0367
0368
0369
0370
0371 inline Decays::Nodes::And operator&( const Decays::iNode& o1, const Decays::iNode& o2 ) {
0372 return Decays::Nodes::And( o1, o2 );
0373 }
0374
0375
0376
0377
0378
0379 inline Decays::Nodes::Not operator~( const Decays::iNode& o ) { return Decays::Nodes::Not( o ); }
0380
0381
0382
0383
0384
0385 GAUDI_API
0386 Decays::Nodes::Or operator||( const Decays::iNode& o1, const std::string& o2 );
0387
0388
0389
0390
0391
0392 GAUDI_API
0393 Decays::Nodes::Or operator||( const Decays::iNode& o1, const Gaudi::ParticleID& o2 );
0394
0395
0396
0397
0398
0399 GAUDI_API
0400 Decays::Nodes::Or operator||( const Decays::iNode& o1, const Decays::Decay::Item& o2 );
0401
0402
0403
0404
0405
0406 GAUDI_API
0407 Decays::Nodes::Or operator||( const Decays::iNode& o1, const Gaudi::ParticleProperty* o2 );
0408
0409
0410
0411
0412
0413 GAUDI_API
0414 Decays::Nodes::Or operator||( const std::string& o2, const Decays::iNode& o1 );
0415
0416
0417
0418
0419
0420 GAUDI_API
0421 Decays::Nodes::Or operator||( const Gaudi::ParticleID& o2, const Decays::iNode& o1 );
0422
0423
0424
0425
0426
0427 GAUDI_API
0428 Decays::Nodes::Or operator||( const Decays::Decay::Item& o2, const Decays::iNode& o1 );
0429
0430
0431
0432
0433
0434 GAUDI_API
0435 Decays::Nodes::Or operator||( const Gaudi::ParticleProperty* o2, const Decays::iNode& o1 );
0436
0437
0438
0439
0440
0441 GAUDI_API
0442 Decays::Nodes::And operator&&( const Decays::iNode& o1, const std::string& o2 );
0443
0444
0445
0446
0447
0448 GAUDI_API
0449 Decays::Nodes::And operator&&( const Decays::iNode& o1, const Gaudi::ParticleID& o2 );
0450
0451
0452
0453
0454
0455 GAUDI_API
0456 Decays::Nodes::And operator&&( const Decays::iNode& o1, const Decays::Decay::Item& o2 );
0457
0458
0459
0460
0461
0462 GAUDI_API
0463 Decays::Nodes::And operator&&( const Decays::iNode& o1, const Gaudi::ParticleProperty* o2 );
0464
0465
0466
0467
0468
0469 GAUDI_API
0470 Decays::Nodes::And operator&&( const std::string& o2, const Decays::iNode& o1 );
0471
0472
0473
0474
0475
0476 GAUDI_API
0477 Decays::Nodes::And operator&&( const Gaudi::ParticleID& o2, const Decays::iNode& o1 );
0478
0479
0480
0481
0482
0483 GAUDI_API
0484 Decays::Nodes::And operator&&( const Decays::Decay::Item& o2, const Decays::iNode& o1 );
0485
0486
0487
0488
0489
0490 GAUDI_API
0491 Decays::Nodes::And operator&&( const Gaudi::ParticleProperty* o2, const Decays::iNode& o1 );
0492
0493 }