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