6#ifndef HEPMC3_ATTRIBUTE_H
7#define HEPMC3_ATTRIBUTE_H
29#include "HepMC3/GenParticle_fwd.h"
30#include "HepMC3/GenVertex_fwd.h"
66 explicit Attribute(
const std::string &st):m_is_parsed(false),m_string(st) { m_event=
nullptr; }
119 return std::const_pointer_cast<GenParticle>(m_particle);
129 return std::const_pointer_cast<GenVertex>(m_vertex);
144 std::string m_string;
147 GenParticlePtr m_particle;
148 GenVertexPtr m_vertex;
168 m_val = atoi( att.c_str() );
175 att = std::to_string(m_val);
211 m_val = atol( att.c_str() );
218 att = std::to_string(m_val);
256 m_val = atof( att.c_str() );
263 std::ostringstream oss;
264 oss << std::setprecision(std::numeric_limits<double>::digits10)
303 m_val = float(atof( att.c_str() ));
310 std::ostringstream oss;
311 oss << std::setprecision(std::numeric_limits<float>::digits10)
409 att = std::to_string(m_val);
445 m_val = atoll( att.c_str() );
452 att = std::to_string(m_val);
490 m_val = strtold( att.c_str(),NULL);
497 std::ostringstream oss;
498 oss << std::setprecision(std::numeric_limits<long double>::digits10)
539 m_val = strtoul(att.c_str(), NULL, 0);
546 att = std::to_string(m_val);
584 m_val = strtoul(att.c_str(), NULL, 0);
591 att = std::to_string(m_val);
628 m_val = strtoull(att.c_str(), NULL, 0);
635 att = std::to_string(m_val);
651 unsigned long long m_val;
671 if (att.size()!=1)
return false;
672 if (att==std::string(
"1")) {m_val =
true;
return true;}
673 if (att==std::string(
"0")) {m_val =
false;
return true;}
680 att = std::to_string(m_val);
718 std::stringstream datastream(att);
719 while (datastream >> datafoo) m_val.emplace_back(datafoo);
727 for (
const auto& a: m_val) {
if (att.length()) att+=
" "; att+=std::to_string(a);}
744 std::vector<char> m_val;
766 std::stringstream datastream(att);
767 while (datastream >> datafoo) m_val.emplace_back(datafoo);
775 for (
const auto& a: m_val) {
if (att.length()) att+=
" "; att+=std::to_string(a);}
791 std::vector<float> m_val;
814 std::stringstream datastream(att);
815 while (datastream >> datafoo) m_val.emplace_back(datafoo);
823 for (
const auto& a: m_val) {
if (att.length()) att+=
" "; att+=std::to_string(a);}
828 std::vector<long double>
value()
const {
839 std::vector<long double> m_val;
863 std::stringstream datastream(att);
864 while (datastream >> datafoo) m_val.emplace_back(datafoo);
872 for (
const auto& a: m_val) {
if (att.length()) att+=
" "; att+=std::to_string(a);}
877 std::vector<long long>
value()
const {
888 std::vector<long long> m_val;
908 unsigned int datafoo;
910 std::stringstream datastream(att);
911 while (datastream >> datafoo) m_val.emplace_back(datafoo);
919 for (
const auto& a: m_val) {
if (att.length()) att+=
" "; att+=std::to_string(a);}
924 std::vector<unsigned int>
value()
const {
935 std::vector<unsigned int> m_val;
955 unsigned long datafoo;
957 std::stringstream datastream(att);
958 while (datastream >> datafoo) m_val.emplace_back(datafoo);
966 for (
const auto& a: m_val) {
if (att.length()) att+=
" "; att+=std::to_string(a);}
971 std::vector<unsigned long>
value()
const {
982 std::vector<unsigned long> m_val;
1003 unsigned long long datafoo;
1005 std::stringstream datastream(att);
1006 while (datastream >> datafoo) m_val.emplace_back(datafoo);
1014 for (
const auto& a: m_val) {
if (att.length()) att+=
" "; att+=std::to_string(a);}
1019 std::vector<unsigned long long>
value()
const {
1030 std::vector<unsigned long long> m_val;
1052 std::stringstream datastream(att);
1053 while (datastream >> datafoo) m_val.emplace_back(datafoo);
1061 for (
const auto& a: m_val) {
if (att.length()) att+=
" "; att+=std::to_string(a);}
1078 std::vector<int> m_val;
1100 std::stringstream datastream(att);
1101 while (datastream >> datafoo) m_val.emplace_back(datafoo);
1109 for (
const auto& a: m_val) {
if (att.length()) att+=
" "; att+=std::to_string(a);}
1125 std::vector<long int> m_val;
1147 std::stringstream datastream(att);
1148 while (datastream >> datafoo) m_val.emplace_back(datafoo);
1156 for (
const auto& a: m_val) {
if (att.length()) att+=
" "; att+=std::to_string(a);}
1172 std::vector<double> m_val;
1193 size_t posb = att.find_first_not_of(
' ');
1195 size_t pose = att.find_first_of(
' ', posb);
1196 m_val.push_back(att.substr(posb, pose - posb));
1197 posb = att.find_first_not_of(
' ', pose);
1198 }
while (posb != std::string::npos);
1206 for (
const auto& a: m_val) {
if (att.length()) att+=
" "; att+=a;}
1211 std::vector<std::string>
value()
const {
1222 std::vector<std::string> m_val;
virtual ~Attribute()
Virtual destructor.
virtual bool from_string(const std::string &att)=0
Fill class content from string.
void set_is_parsed(bool flag)
Set is_parsed flag.
const std::string & unparsed_string() const
Get unparsed string.
bool is_parsed() const
Check if this attribute is parsed.
GenParticlePtr particle()
void set_unparsed_string(const std::string &st)
Set unparsed string.
virtual bool init()
Optionally initialize the attribute after from_string.
virtual bool to_string(std::string &att) const =0
Fill string from class content.
ConstGenParticlePtr particle() const
const GenEvent * event() const
virtual bool init(const GenRunInfo &)
Optionally initialize the attribute after from_string.
ConstGenVertexPtr vertex() const
friend class GenEvent
GenEvent is a friend.
Attribute(const std::string &st)
Protected constructor that allows to set string.
Attribute()
Default constructor.
bool from_string(const std::string &att) override
Implementation of Attribute::from_string.
bool value() const
get the value associated to this Attribute.
BoolAttribute()
Default constructor.
void set_value(const bool &i)
set the value associated to this Attribute.
bool to_string(std::string &att) const override
Implementation of Attribute::to_string.
BoolAttribute(bool val)
Constructor initializing attribute value.
void set_value(const char &i)
set the value associated to this Attribute.
CharAttribute()
Default constructor.
CharAttribute(char val)
Constructor initializing attribute value.
bool from_string(const std::string &att) override
Implementation of Attribute::from_string.
bool to_string(std::string &att) const override
Implementation of Attribute::to_string.
char value() const
get the value associated to this Attribute.
double value() const
get the value associated to this Attribute.
DoubleAttribute()
Default constructor.
void set_value(const double &d)
set the value associated to this Attribute.
bool from_string(const std::string &att) override
Implementation of Attribute::from_string.
DoubleAttribute(double val)
Constructor initializing attribute value.
bool to_string(std::string &att) const override
Implementation of Attribute::to_string.
FloatAttribute()
Default constructor.
void set_value(const float &f)
set the value associated to this Attribute.
float value() const
get the value associated to this Attribute.
bool from_string(const std::string &att) override
Implementation of Attribute::from_string.
bool to_string(std::string &att) const override
Implementation of Attribute::to_string.
FloatAttribute(float val)
Constructor initializing attribute value.
Stores event-related information.
Stores run-related information.
int value() const
get the value associated to this Attribute.
bool from_string(const std::string &att) override
Implementation of Attribute::from_string.
IntAttribute(int val)
Constructor initializing attribute value.
void set_value(const int &i)
set the value associated to this Attribute.
IntAttribute()
Default constructor.
bool to_string(std::string &att) const override
Implementation of Attribute::to_string.
void set_value(const long &l)
set the value associated to this Attribute.
bool from_string(const std::string &att) override
Implementation of Attribute::from_string.
long value() const
get the value associated to this Attribute.
LongAttribute()
Default constructor.
LongAttribute(long val)
Constructor initializing attribute value.
bool to_string(std::string &att) const override
Implementation of Attribute::to_string.
LongDoubleAttribute()
Default constructor.
bool from_string(const std::string &att) override
Implementation of Attribute::from_string.
void set_value(const long double &d)
set the value associated to this Attribute.
bool to_string(std::string &att) const override
Implementation of Attribute::to_string.
LongDoubleAttribute(long double val)
Constructor initializing attribute value.
long double value() const
get the value associated to this Attribute.
bool to_string(std::string &att) const override
Implementation of Attribute::to_string.
LongLongAttribute()
Default constructor.
bool from_string(const std::string &att) override
Implementation of Attribute::from_string.
LongLongAttribute(long long val)
Constructor initializing attribute value.
void set_value(const long long &l)
set the value associated to this Attribute.
long long value() const
get the value associated to this Attribute.
std::string value() const
get the value associated to this Attribute.
void set_value(const std::string &s)
set the value associated to this Attribute.
StringAttribute(const std::string &st)
String-based constructor.
bool to_string(std::string &att) const override
Implementation of Attribute::to_string.
StringAttribute()
Default constructor - empty string.
bool from_string(const std::string &att) override
Implementation of Attribute::from_string.
UIntAttribute()
Default constructor.
void set_value(const unsigned int &i)
set the value associated to this Attribute.
bool from_string(const std::string &att) override
Implementation of Attribute::from_string.
bool to_string(std::string &att) const override
Implementation of Attribute::to_string.
unsigned int value() const
get the value associated to this Attribute.
UIntAttribute(unsigned int val)
Constructor initializing attribute value.
bool from_string(const std::string &att) override
Implementation of Attribute::from_string.
ULongAttribute(unsigned long val)
Constructor initializing attribute value.
bool to_string(std::string &att) const override
Implementation of Attribute::to_string.
unsigned long value() const
get the value associated to this Attribute.
ULongAttribute()
Default constructor.
void set_value(const unsigned long &i)
set the value associated to this Attribute.
ULongLongAttribute(unsigned long long val)
Constructor initializing attribute value.
bool from_string(const std::string &att) override
Implementation of Attribute::from_string.
bool to_string(std::string &att) const override
Implementation of Attribute::to_string.
void set_value(const unsigned long long &i)
set the value associated to this Attribute.
ULongLongAttribute()
Default constructor.
unsigned long long value() const
get the value associated to this Attribute.
VectorCharAttribute(std::vector< char > val)
Constructor initializing attribute value.
void set_value(const std::vector< char > &i)
set the value associated to this Attribute.
std::vector< char > value() const
get the value associated to this Attribute.
VectorCharAttribute()
Default constructor.
bool to_string(std::string &att) const override
Implementation of Attribute::to_string.
bool from_string(const std::string &att) override
Implementation of Attribute::from_string.
VectorDoubleAttribute(std::vector< double > val)
Constructor initializing attribute value.
bool from_string(const std::string &att) override
Implementation of Attribute::from_string.
std::vector< double > value() const
get the value associated to this Attribute.
bool to_string(std::string &att) const override
Implementation of Attribute::to_string.
VectorDoubleAttribute()
Default constructor.
void set_value(const std::vector< double > &i)
set the value associated to this Attribute.
std::vector< float > value() const
get the value associated to this Attribute.
bool from_string(const std::string &att) override
Implementation of Attribute::from_string.
VectorFloatAttribute(std::vector< float > val)
Constructor initializing attribute value.
VectorFloatAttribute()
Default constructor.
bool to_string(std::string &att) const override
Implementation of Attribute::to_string.
void set_value(const std::vector< float > &i)
set the value associated to this Attribute.
void set_value(const std::vector< int > &i)
set the value associated to this Attribute.
bool to_string(std::string &att) const override
Implementation of Attribute::to_string.
std::vector< int > value() const
get the value associated to this Attribute.
VectorIntAttribute(std::vector< int > val)
Constructor initializing attribute value.
VectorIntAttribute()
Default constructor.
bool from_string(const std::string &att) override
Implementation of Attribute::from_string.
void set_value(const std::vector< long double > &i)
set the value associated to this Attribute.
bool from_string(const std::string &att) override
Implementation of Attribute::from_string.
std::vector< long double > value() const
get the value associated to this Attribute.
bool to_string(std::string &att) const override
Implementation of Attribute::to_string.
VectorLongDoubleAttribute(std::vector< long double > val)
Constructor initializing attribute value.
VectorLongDoubleAttribute()
Default constructor.
bool from_string(const std::string &att) override
Implementation of Attribute::from_string.
VectorLongIntAttribute()
Default constructor.
VectorLongIntAttribute(std::vector< long int > val)
Constructor initializing attribute value.
bool to_string(std::string &att) const override
Implementation of Attribute::to_string.
std::vector< long int > value() const
get the value associated to this Attribute.
void set_value(const std::vector< long int > &i)
set the value associated to this Attribute.
bool to_string(std::string &att) const override
Implementation of Attribute::to_string.
VectorLongLongAttribute(std::vector< long long > val)
Constructor initializing attribute value.
VectorLongLongAttribute()
Default constructor.
bool from_string(const std::string &att) override
Implementation of Attribute::from_string.
void set_value(const std::vector< long long > &i)
set the value associated to this Attribute.
std::vector< long long > value() const
get the value associated to this Attribute.
VectorStringAttribute(std::vector< std::string > val)
Constructor initializing attribute value.
bool from_string(const string &att) override
Implementation of Attribute::from_string.
std::vector< std::string > value() const
get the value associated to this Attribute.
VectorStringAttribute()
Default constructor.
bool to_string(std::string &att) const override
Implementation of Attribute::to_string.
void set_value(const std::vector< std::string > &i)
set the value associated to this Attribute.
VectorUIntAttribute()
Default constructor.
void set_value(const std::vector< unsigned int > &i)
set the value associated to this Attribute.
bool to_string(std::string &att) const override
Implementation of Attribute::to_string.
VectorUIntAttribute(std::vector< unsigned int > val)
Constructor initializing attribute value.
bool from_string(const std::string &att) override
Implementation of Attribute::from_string.
std::vector< unsigned int > value() const
get the value associated to this Attribute.
VectorULongAttribute()
Default constructor.
bool to_string(std::string &att) const override
Implementation of Attribute::to_string.
void set_value(const std::vector< unsigned long > &i)
set the value associated to this Attribute.
VectorULongAttribute(std::vector< unsigned long > val)
Constructor initializing attribute value.
std::vector< unsigned long > value() const
get the value associated to this Attribute.
bool from_string(const std::string &att) override
Implementation of Attribute::from_string.
void set_value(const std::vector< unsigned long long > &i)
set the value associated to this Attribute.
VectorULongLongAttribute(std::vector< unsigned long long > val)
Constructor initializing attribute value.
bool from_string(const std::string &att) override
Implementation of Attribute::from_string.
std::vector< unsigned long long > value() const
get the value associated to this Attribute.
VectorULongLongAttribute()
Default constructor.
bool to_string(std::string &att) const override
Implementation of Attribute::to_string.