HepMC event record
include/HepMC/Search/Filter.h
1 // -*- C++ -*-
2 //
3 // This file is part of HepMC
4 // Copyright (C) 2014 The HepMC collaboration (see AUTHORS for details)
5 //
6 #ifndef HEPMC_SEARCH_FILTER_H
7 #define HEPMC_SEARCH_FILTER_H
8 /**
9  * @file Filter.h
10  * @brief Definition of \b class Filter
11  *
12  * @class HepMC::Filter
13  * @brief Class used to define filters for search engine
14  *
15  * Objects of this class cannot be directly created by user.
16  * Use predefined static const HepMC::FilterBase objects to construct
17  * appropriate filters. See @ref search_engine for more details.
18  *
19  * @ingroup search_engine
20  *
21  */
22 #include "HepMC/Search/FilterBase.h"
23 #include "HepMC/Data/SmartPointer.h"
24 #include "HepMC/Attribute.h"
25 #include <string>
26 
27 namespace HepMC {
28 
29 using std::string;
30 
31 class GenEvent;
32 
33 class Filter : protected FilterBase {
34 
35 friend class FilterBase; // To allow call to protected constructor
36 
37 //
38 // Constructors
39 //
40 protected:
41  /** @brief Internal constructor for integer-type filters
42  *
43  * Invoked when an operator == != < > <= or >= with integer value
44  * is used on a filter.
45  */
47 
48  /** @brief Internal constructor for boolean-type filters
49  *
50  * Used to initialize global static const filters and to create
51  * new filters using operator '!'
52  */
53  Filter(FilterBoolParam p, bool value = true):FilterBase(p),m_operator(EQUAL),m_int_value(0),m_bool_value(value) {}
54 
55  /** @brief Internal constructor for attribute-type filters
56  *
57  * Used when class ATTRIBUTE is called to provide attribute name
58  */
59  Filter(FilterAttributeParam p, const string name):FilterBase(p),m_operator(EQUAL),m_int_value(0),m_bool_value(true),m_attribute_name(name) {}
60 
61 //
62 // Functions
63 //
64 public:
65  /** @brief Check if HepMC::GenParticle passed this filter */
66  bool passed_filter(const GenParticlePtr &p) const;
67 
68  /** @brief Logical NOT operator for boolean filters */
69  Filter operator!() const { return Filter(m_bool,!m_bool_value); }
70 
71 private:
72  /** @brief Filter::passed_filter helper for integer-type filters */
73  bool passed_int_filter(const GenParticlePtr &p) const;
74 
75  /** @brief Filter::passed_filter helper for pointer-type filters */
76  bool passed_bool_filter(const GenParticlePtr &p) const;
77 
78  /** @brief Filter::passed_filter helper for attribute-type filters */
79  bool passed_attribute_filter(const GenParticlePtr &p) const;
80 //
81 // Fields
82 //
83 protected:
84  FilterOperator m_operator; //!< Operator used by filter
85  int m_int_value; //!< Filter parameter for integer-type filter
86  bool m_bool_value; //!< Filter parameter for boolean-type filter
87  string m_attribute_name; //!< Filter parameter for attribute-type filters
88  string m_attribute_str; //!< Filter parameter for attribute-type filters
89 };
90 
91 static const Filter HAS_END_VERTEX = FilterBase::init_has_end_vertex(); //!< Filter for checking if HepMC::GenParticle::end_vertex() != NULL
92 static const Filter HAS_PRODUCTION_VERTEX = FilterBase::init_has_production_vertex(); //!< Filter for checking if HepMC::GenParticle::production_vertex() != NULL
93 static const Filter HAS_SAME_PDG_ID_DAUGHTER = FilterBase::init_has_same_pdg_id_daughter(); //!< Filter for checking if end vertex has particle with same pdg_id
94 static const Filter IS_STABLE = FilterBase::init_is_stable(); //!< Filter for checking if particle is stable
95 static const Filter IS_BEAM = FilterBase::init_is_beam(); //!< Filter for checking if particle is a beam particle
96 
97 } // namespace HepMC
98 
99 #endif
static const Filter init_has_production_vertex()
init static const HAS_PRODUCTION_VERTEX
Definition: FilterBase.cc:26
static const Filter HAS_PRODUCTION_VERTEX
Filter for checking if HepMC::GenParticle::production_vertex() != NULL.
bool m_bool_value
Filter parameter for boolean-type filter.
FilterBoolParam m_bool
Boolean value (if boolean parameter type)
FilterBoolParam
List of filters with boolean parameter.
Class used to define filters for search engine.
FilterIntegerParam
List of filters with integer parameter.
bool passed_attribute_filter(const GenParticlePtr &p) const
Filter::passed_filter helper for attribute-type filters.
Definition: Filter.cc:99
FilterOperator m_operator
Operator used by filter.
bool passed_bool_filter(const GenParticlePtr &p) const
Filter::passed_filter helper for pointer-type filters.
Definition: Filter.cc:59
bool passed_int_filter(const GenParticlePtr &p) const
Filter::passed_filter helper for integer-type filters.
Definition: Filter.cc:31
static const Filter HAS_END_VERTEX
Filter for checking if HepMC::GenParticle::end_vertex() != NULL.
static const Filter init_is_stable()
init static const IS_STABLE
Definition: FilterBase.cc:28
static const Filter init_is_beam()
init static const IS_BEAM
Definition: FilterBase.cc:29
static const Filter HAS_SAME_PDG_ID_DAUGHTER
Filter for checking if end vertex has particle with same pdg_id.
static const Filter IS_STABLE
Filter for checking if particle is stable.
Filter(FilterBoolParam p, bool value=true)
Internal constructor for boolean-type filters.
string m_attribute_str
Filter parameter for attribute-type filters.
static const Filter init_has_end_vertex()
init static const HAS_END_VERTEX
Definition: FilterBase.cc:25
FilterOperator
List of operators on filter values.
Filter operator!() const
Logical NOT operator for boolean filters.
bool passed_filter(const GenParticlePtr &p) const
Check if HepMC::GenParticle passed this filter.
Definition: Filter.cc:20
Filter(FilterIntegerParam p, FilterOperator o, int value)
Internal constructor for integer-type filters.
static const Filter IS_BEAM
Filter for checking if particle is a beam particle.
string m_attribute_name
Filter parameter for attribute-type filters.
int m_int_value
Filter parameter for integer-type filter.
Definition of template class SmartPointer.
Filter(FilterAttributeParam p, const string name)
Internal constructor for attribute-type filters.
static const Filter init_has_same_pdg_id_daughter()
init static const HAS_SAME_PDG_ID_DAUGHTER
Definition: FilterBase.cc:27
FilterAttributeParam
List of filters with attribute parameter.