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