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-2019 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 "HepMC3/Attribute.h"
16#include "HepMC3/Filter.h"
17
18namespace HepMC3 {
19
21
22public:
23
24 AttributeFeature(const std::string &name): m_name(name) {}
25
26 Filter exists() const {
27 std::string name = m_name;
28 return [name](ConstGenParticlePtr p)->bool{return p->attribute_as_string(name).length() != 0;};
29 }
30
31 bool operator()(ConstGenParticlePtr p) const {
32 return p->attribute_as_string(m_name).length() != 0;
33 }
34
35 Filter operator == (const Attribute &rhs) const {
36 std::string name = m_name;
37 std::string other;
38 rhs.to_string(other);
39 return [other, name](ConstGenParticlePtr p)->bool{return p->attribute_as_string(name).compare(other) == 0;};
40 }
41
42 Filter operator == (std::shared_ptr<const Attribute> rhs) const {
43 std::string name = m_name;
44 std::string other;
45 rhs->to_string(other);
46 return [other, name](ConstGenParticlePtr p)->bool{return p->attribute_as_string(name).compare(other) == 0;};
47 }
48
49 Filter operator == (std::string rhs) const {
50 const std::string &name = m_name;
51 return [name, rhs](ConstGenParticlePtr p)->bool{return p->attribute_as_string(name).compare(rhs) == 0;};
52 }
53
54private:
55
56 std::string m_name;
57
58};
59}
60#endif
Definition of class Attribute, class IntAttribute and class StringAttribute.
Defines Filter operations for combingin Filters.
Forward declaration of GenParticle.
Definition: Attribute.h:45
virtual bool to_string(string &att) const =0
Fill string from class content.
HepMC3 main namespace.
Definition: ReaderGZ.h:28
std::function< bool(ConstGenParticlePtr)> Filter
type of Filter
Definition: Filter.h:17