HepMC3 event record library
AssociatedParticle.h
Go to the documentation of this file.
1 
2 // -*- C++ -*-
3 //
4 // This file is part of HepMC
5 // Copyright (C) 2014-2020 The HepMC collaboration (see AUTHORS for details)
6 //
7 #ifndef HEPMC3_AssociatedParticle_H
8 #define HEPMC3_AssociatedParticle_H
9 /**
10  * @file AssociatedParticle.h
11  * @brief Definition of \b class AssociatedParticle,
12  *
13  * @class HepMC3::AssociatedParticle
14  * @brief Attribute class allowing
15  * eg. a GenParticle to refer to another GenParticle.
16 
17  * @ingroup attributes
18  *
19  */
20 
21 #include "HepMC3/Attribute.h"
22 #include "HepMC3/GenParticle.h"
23 
24 namespace HepMC3 {
25 
26 /**
27  * @class HepMC3::IntAttribute
28  * @brief Attribute that holds an Integer implemented as an int
29  *
30  * @ingroup attributes
31  */
33 public:
34 
35  /** @brief Default constructor */
37 
38  /** @brief Constructor initializing attribute value */
39  AssociatedParticle(ConstGenParticlePtr p)
40  : IntAttribute(p->id()), m_associated(p) {}
41 
42  /** @brief Implementation of Attribute::from_string */
43  bool from_string(const std::string &att) {
45  if ( associatedId() > int(event()->particles().size()) ||
46  associatedId() <= 0 ) return false;
48  return true;
49  }
50 
51  /** @brief get id of the associated particle. */
52  int associatedId() const {
53  return value();
54  }
55 
56  /** @brief get a pointer to the associated particle. */
57  ConstGenParticlePtr associated() const {
58  return m_associated;
59  }
60 
61  /** @brief set the value associated to this Attribute. */
62  void set_associated(ConstGenParticlePtr p) {
63  IntAttribute::set_value(p->id());
64  m_associated = p;
65  }
66 
67 private:
68 
69  ConstGenParticlePtr m_associated; ///< The associated particle.
70 
71 };
72 
73 } // namespace HepMC3
74 
75 #endif
ConstGenParticlePtr associated() const
get a pointer to the associated particle.
bool from_string(const std::string &att)
Implementation of Attribute::from_string.
void set_associated(ConstGenParticlePtr p)
set the value associated to this Attribute.
Definition of class GenParticle.
bool from_string(const std::string &att) override
Implementation of Attribute::from_string.
Definition: Attribute.h:168
ConstGenParticlePtr m_associated
The associated particle.
int associatedId() const
get id of the associated particle.
void set_value(const int &i)
set the value associated to this Attribute.
Definition: Attribute.h:185
AssociatedParticle()
Default constructor.
const GenEvent * event() const
Definition: Attribute.h:109
Attribute class allowing eg. a GenParticle to refer to another GenParticle.
Definition of class Attribute, class IntAttribute and class StringAttribute.
const std::vector< ConstGenParticlePtr > & particles() const
Get list of particles (const)
Definition: GenEvent.cc:39
int value() const
get the value associated to this Attribute.
Definition: Attribute.h:180
AssociatedParticle(ConstGenParticlePtr p)
Constructor initializing attribute value.
Attribute that holds an Integer implemented as an int.
Definition: Attribute.h:158