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
23namespace HepMC3 {
24
25/**
26 * @class HepMC3::IntAttribute
27 * @brief Attribute that holds an Integer implemented as an int
28 *
29 * @ingroup attributes
30 */
32public:
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) {
63 m_associated = p;
64 }
65
66private:
67
68 ConstGenParticlePtr m_associated; ///< The associated particle.
69
70};
71
72} // namespace HepMC3
73
74#endif
Definition of class Attribute, class IntAttribute and class StringAttribute.
Definition of class GenParticle.
Attribute class allowing eg. a GenParticle to refer to another GenParticle.
bool from_string(const std::string &att)
Implementation of Attribute::from_string.
void set_associated(ConstGenParticlePtr p)
set the value associated to this Attribute.
AssociatedParticle(ConstGenParticlePtr p)
Constructor initializing attribute value.
ConstGenParticlePtr m_associated
The associated particle.
AssociatedParticle()
Default constructor.
int associatedId() const
get id of the associated particle.
ConstGenParticlePtr associated() const
get a pointer to the associated particle.
const GenEvent * event() const
Definition: Attribute.h:108
const std::vector< ConstGenParticlePtr > & particles() const
Get list of particles (const)
Definition: GenEvent.cc:39
Attribute that holds an Integer implemented as an int.
Definition: Attribute.h:157
void set_value(const int &i)
set the value associated to this Attribute.
Definition: Attribute.h:184
int value() const
get the value associated to this Attribute.
Definition: Attribute.h:179
bool from_string(const std::string &att) override
Implementation of Attribute::from_string.
Definition: Attribute.h:167
HepMC3 main namespace.