HepMC3 event record library: AttributeFeature.h Source File

HepMC3 event record library

AttributeFeature.h
Go to the documentation of this file.
1// -*- C++ -*-
2//
3// This file is part of HepMC
4// Copyright (C) 2014-2023 The HepMC collaboration (see AUTHORS for details)
5//
6///
7/// @file AttributeFeature.h
8/// @brief Defines AttributeFeature for obtaining Filters to search by Attribute.
9/// @class HepMC3::AttributeFeature
10/// @brief AttributeFeature
11
12#ifndef HEPMC3_ATTRIBUTE_FEATURE_H
13#define HEPMC3_ATTRIBUTE_FEATURE_H
14
15#include <memory>
16#include <string>
17#include "HepMC3/Attribute.h"
18#include "HepMC3/Filter.h"
19
20namespace HepMC3 {
21
22 class AttributeFeature {
23public:
24 /// @brief constructor
25 AttributeFeature(const std::string &name): m_name(name) {}
26
27 /// @brief existence
28 Filter exists() const {
29 std::string name = m_name;
30 return [name](ConstGenParticlePtr p)->bool{return p->attribute_as_string(name).length() != 0;};
31 }
32
33 /// @brief evaluate
34 bool operator()(ConstGenParticlePtr p) const {
35 return p->attribute_as_string(m_name).length() != 0;
36 }
37
38 /// @brief equality operator
39 Filter operator == (const Attribute &rhs) const {
40 std::string name = m_name;
41 std::string other;
42 rhs.to_string(other);
43 return [other, name](ConstGenParticlePtr p)->bool{return p->attribute_as_string(name).compare(other) == 0;};
44 }
45
46 /// @brief equality operator
47 Filter operator == (std::shared_ptr<const Attribute> rhs) const {
48 std::string name = m_name;
49 std::string other;
50 rhs->to_string(other);
51 return [other, name](ConstGenParticlePtr p)->bool{return p->attribute_as_string(name).compare(other) == 0;};
52 }
53
54 /// @brief equality operator
55 Filter operator == (std::string rhs) const {
56 const std::string &name = m_name;
57 return [name, rhs](ConstGenParticlePtr p)->bool{return p->attribute_as_string(name).compare(rhs) == 0;};
58 }
59
60private:
61 std::string m_name; ///< holds name
62};
63}
64#endif
Attribute.h
Definition of class Attribute, class IntAttribute and class StringAttribute.
Filter.h
Defines Filter operations for combingin Filters.
HepMC3::AttributeFeature::exists
Filter exists() const
existence
Definition AttributeFeature.h:28
HepMC3::AttributeFeature::operator()
bool operator()(ConstGenParticlePtr p) const
evaluate
Definition AttributeFeature.h:34
HepMC3::AttributeFeature::AttributeFeature
AttributeFeature(const std::string &name)
constructor
Definition AttributeFeature.h:25
HepMC3::AttributeFeature::operator==
Filter operator==(const Attribute &rhs) const
equality operator
Definition AttributeFeature.h:39
HepMC3::AttributeFeature::m_name
std::string m_name
holds name
Definition AttributeFeature.h:61
HepMC3::Attribute
Base attribute class.
Definition Attribute.h:44
HepMC3::Attribute::to_string
virtual bool to_string(std::string &att) const =0
Fill string from class content.
HepMC3
HepMC3 main namespace.
Definition AnalysisExample.h:24
HepMC3::Filter
std::function< bool(ConstGenParticlePtr)> Filter
type of Filter
Definition Filter.h:19