Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:01:11

0001 // -*- C++ -*-
0002 //
0003 // This file is part of HepMC
0004 // Copyright (C) 2014-2023 The HepMC collaboration (see AUTHORS for details)
0005 //
0006 ///
0007 /// @file AttributeFeature.h
0008 /// @brief Defines AttributeFeature for obtaining Filters to search by Attribute.
0009 /// @class HepMC3::AttributeFeature
0010 /// @brief AttributeFeature
0011 
0012 #ifndef HEPMC3_ATTRIBUTE_FEATURE_H
0013 #define HEPMC3_ATTRIBUTE_FEATURE_H
0014 
0015 #include <memory>
0016 #include <string>
0017 #include "HepMC3/Attribute.h"
0018 #include "HepMC3/Filter.h"
0019 
0020 namespace HepMC3 {
0021 
0022 class AttributeFeature {
0023 public:
0024     /// @brief constructor
0025     AttributeFeature(const std::string &name): m_name(name) {}
0026 
0027     /// @brief existence
0028     Filter exists() const {
0029         std::string name = m_name;
0030         return [name](ConstGenParticlePtr p)->bool{return p->attribute_as_string(name).length() != 0;};
0031     }
0032 
0033     /// @brief evaluate
0034     bool operator()(ConstGenParticlePtr p) const {
0035         return p->attribute_as_string(m_name).length() != 0;
0036     }
0037 
0038     /// @brief equality operator
0039     Filter operator == (const Attribute &rhs) const {
0040         std::string name = m_name;
0041         std::string other;
0042         rhs.to_string(other);
0043         return [other, name](ConstGenParticlePtr p)->bool{return p->attribute_as_string(name).compare(other) == 0;};
0044     }
0045 
0046     /// @brief equality operator
0047     Filter operator == (std::shared_ptr<const Attribute> rhs) const {
0048         std::string name = m_name;
0049         std::string other;
0050         rhs->to_string(other);
0051         return [other, name](ConstGenParticlePtr p)->bool{return p->attribute_as_string(name).compare(other) == 0;};
0052     }
0053 
0054     /// @brief equality operator
0055     Filter operator == (std::string rhs) const {
0056         const std::string &name = m_name;
0057         return [name, rhs](ConstGenParticlePtr p)->bool{return p->attribute_as_string(name).compare(rhs) == 0;};
0058     }
0059 
0060 private:
0061     std::string m_name;  ///< holds name
0062 };
0063 }
0064 #endif