Debian Codegraph @

include/HepMC3/AssociatedParticle.h

raw
1
2 // -*- C++ -*-
3 //
4 // This file is part of HepMC
5 // Copyright (C) 2014-2019 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 */
32 class AssociatedParticle : public IntAttribute {
33 public:
34
35 /** @brief Default constructor */
36 AssociatedParticle() {}
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 string &att) {
44 IntAttribute::from_string(att);
45 if ( associatedId() > int(event()->particles().size()) ||
46 associatedId() <= 0 ) return false;
47 m_associated = event()->particles()[associatedId() -1];
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