6#ifndef HEPMC3_ATTRIBUTE_H
7#define HEPMC3_ATTRIBUTE_H
29#include "HepMC3/GenParticle_fwd.h"
30#include "HepMC3/GenVertex_fwd.h"
121 return std::const_pointer_cast<GenParticle>(
m_particle);
131 return std::const_pointer_cast<GenVertex>(
m_vertex);
170 m_val = atoi( att.c_str() );
176 att = std::to_string(
m_val);
211 m_val = atol( att.c_str() );
217 att = std::to_string(
m_val);
254 m_val = atof( att.c_str() );
260 std::ostringstream oss;
261 oss << std::setprecision(std::numeric_limits<double>::digits10)
299 m_val = float(atof( att.c_str() ));
305 std::ostringstream oss;
306 oss << std::setprecision(std::numeric_limits<float>::digits10)
402 att = std::to_string(
m_val);
437 m_val = atoll( att.c_str() );
443 att = std::to_string(
m_val);
480 m_val = strtold( att.c_str(),NULL);
486 std::ostringstream oss;
487 oss << std::setprecision(std::numeric_limits<long double>::digits10)
527 m_val = strtoul(att.c_str(), NULL, 0);
533 att = std::to_string(
m_val);
570 m_val = strtoul(att.c_str(), NULL, 0);
576 att = std::to_string(
m_val);
612 m_val = strtoull(att.c_str(), NULL, 0);
618 att = std::to_string(
m_val);
652 if (att.size()!=1)
return false;
653 if(att==std::string(
"1")) {
m_val =
true;
return true;}
654 if(att==std::string(
"0")) {
m_val =
false;
return true;}
660 att = std::to_string(
m_val);
697 std::stringstream datastream(att);
698 while (datastream >> datafoo)
m_val.push_back(datafoo);
705 for (
auto a:
m_val) {
if (att.length()) att+=
" "; att+=std::to_string(a);}
742 std::stringstream datastream(att);
743 while (datastream >> datafoo)
m_val.push_back(datafoo);
750 for (
auto a:
m_val) {
if (att.length()) att+=
" "; att+=std::to_string(a);}
788 std::stringstream datastream(att);
789 while (datastream >> datafoo)
m_val.push_back(datafoo);
796 for (
auto a:
m_val) {
if (att.length()) att+=
" "; att+=std::to_string(a);}
801 std::vector<long double>
value()
const {
835 std::stringstream datastream(att);
836 while (datastream >> datafoo)
m_val.push_back(datafoo);
843 for (
auto a:
m_val) {
if (att.length()) att+=
" "; att+=std::to_string(a);}
848 std::vector<long long>
value()
const {
878 unsigned int datafoo;
880 std::stringstream datastream(att);
881 while (datastream >> datafoo)
m_val.push_back(datafoo);
888 for (
auto a:
m_val) {
if (att.length()) att+=
" "; att+=std::to_string(a);}
893 std::vector<unsigned int>
value()
const {
923 unsigned long datafoo;
925 std::stringstream datastream(att);
926 while (datastream >> datafoo)
m_val.push_back(datafoo);
933 for (
auto a:
m_val) {
if (att.length()) att+=
" "; att+=std::to_string(a);}
938 std::vector<unsigned long>
value()
const {
969 unsigned long long datafoo;
971 std::stringstream datastream(att);
972 while (datastream >> datafoo)
m_val.push_back(datafoo);
979 for (
auto a:
m_val) {
if (att.length()) att+=
" "; att+=std::to_string(a);}
984 std::vector<unsigned long long>
value()
const {
989 void set_value(
const std::vector<unsigned long long>& i) {
994 std::vector<unsigned long long>
m_val;
1016 std::stringstream datastream(att);
1017 while (datastream >> datafoo)
m_val.push_back(datafoo);
1024 for (
auto a:
m_val) {
if (att.length()) att+=
" "; att+=std::to_string(a);}
1061 std::stringstream datastream(att);
1062 while (datastream >> datafoo)
m_val.push_back(datafoo);
1069 for (
auto a:
m_val) {
if (att.length()) att+=
" "; att+=std::to_string(a);}
1106 std::stringstream datastream(att);
1107 while (datastream >> datafoo)
m_val.push_back(datafoo);
1114 for (
auto a:
m_val) {
if (att.length()) att+=
" "; att+=std::to_string(a);}
1150 size_t posb = att.find_first_not_of(
' ');
1153 pose = att.find_first_of(
' ', posb);
1154 m_val.push_back(att.substr(posb, pose - posb));
1155 posb = att.find_first_not_of(
' ', pose);
1156 }
while (posb != std::string::npos);
1163 for (
auto a:
m_val) {
if (att.length()) att+=
" "; att+=a;}
1168 std::vector<std::string>
value()
const {
Forward declaration of GenParticle.
virtual ~Attribute()
Virtual destructor.
const std::string & unparsed_string() const
Get unparsed string.
Attribute(const std::string &st)
Protected constructor that allows to set string.
bool is_parsed() const
Check if this attribute is parsed.
ConstGenVertexPtr vertex() const
const GenEvent * event() const
Attribute()
Default constructor.
ConstGenParticlePtr particle() const
std::string m_string
Raw (unparsed) string.
GenParticlePtr particle()
virtual bool from_string(const std::string &att)=0
Fill class content from string.
GenVertexPtr m_vertex
Vertex to which assigned.
void set_unparsed_string(const std::string &st)
Set unparsed string.
virtual bool to_string(std::string &att) const =0
Fill string from class content.
GenParticlePtr m_particle
controlling GenEvent object.
virtual bool init(const GenRunInfo &)
Optionally initialize the attribute after from_string.
virtual bool init()
Optionally initialize the attribute after from_string.
void set_is_parsed(bool flag)
Set is_parsed flag.
bool m_is_parsed
Is this attribute parsed?
Attribute that holds an Booleger implemented as an int.
BoolAttribute(bool val)
Constructor initializing attribute value.
BoolAttribute()
Default constructor.
bool value() const
get the value associated to this Attribute.
bool m_val
Attribute value.
bool from_string(const std::string &att) override
Implementation of Attribute::from_string.
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.
Attribute that holds an Chareger implemented as an int.
CharAttribute(char val)
Constructor initializing attribute value.
CharAttribute()
Default constructor.
void set_value(const char &i)
set the value associated to this Attribute.
char 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.
char m_val
Attribute value.
Attribute that holds a real number as a double.
double m_val
Attribute value.
void set_value(const double &d)
set the value associated to this Attribute.
double value() const
get the value associated to this Attribute.
DoubleAttribute()
Default constructor.
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.
Attribute that holds a real number as a float.
float m_val
Attribute value.
FloatAttribute()
Default constructor.
bool from_string(const std::string &att) override
Implementation of Attribute::from_string.
FloatAttribute(float val)
Constructor initializing attribute value.
void set_value(const float &f)
set the value associated to this Attribute.
float value() const
get the value associated to this Attribute.
bool to_string(std::string &att) const override
Implementation of Attribute::to_string.
Stores event-related information.
Stores run-related information.
Attribute that holds an Integer implemented as an int.
int m_val
Attribute value.
void set_value(const int &i)
set the value associated to this Attribute.
IntAttribute()
Default constructor.
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.
bool to_string(std::string &att) const override
Implementation of Attribute::to_string.
Attribute that holds an Integer implemented as an int.
long m_val
Attribute value.
LongAttribute(long val)
Constructor initializing attribute value.
void set_value(const long &l)
set the value associated to this Attribute.
long value() const
get the value associated to this Attribute.
bool from_string(const std::string &att) override
Implementation of Attribute::from_string.
LongAttribute()
Default constructor.
bool to_string(std::string &att) const override
Implementation of Attribute::to_string.
Attribute that holds a real number as a double.
long double m_val
Attribute value.
LongDoubleAttribute()
Default constructor.
LongDoubleAttribute(long double val)
Constructor initializing attribute value.
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.
long double value() const
get the value associated to this Attribute.
bool to_string(std::string &att) const override
Implementation of Attribute::to_string.
Attribute that holds an Integer implemented as an int.
long long value() const
get the value associated to this Attribute.
void set_value(const long long &l)
set the value associated to this Attribute.
bool from_string(const std::string &att) override
Implementation of Attribute::from_string.
LongLongAttribute(long long val)
Constructor initializing attribute value.
LongLongAttribute()
Default constructor.
long long m_val
Attribute value.
bool to_string(std::string &att) const override
Implementation of Attribute::to_string.
Attribute that holds a string.
StringAttribute()
Default constructor - empty string.
void set_value(const std::string &s)
set the value associated to this Attribute.
StringAttribute(const std::string &st)
String-based constructor.
bool from_string(const std::string &att) override
Implementation of Attribute::from_string.
std::string value() const
get the value associated to this Attribute.
bool to_string(std::string &att) const override
Implementation of Attribute::to_string.
Attribute that holds an unsigned int.
void set_value(const unsigned int &i)
set the value associated to this Attribute.
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.
unsigned int m_val
Attribute value.
UIntAttribute()
Default constructor.
bool to_string(std::string &att) const override
Implementation of Attribute::to_string.
Attribute that holds an unsigned long.
ULongAttribute()
Default constructor.
ULongAttribute(unsigned long val)
Constructor initializing attribute value.
void set_value(const unsigned long &i)
set the value associated to this Attribute.
unsigned long m_val
Attribute value.
unsigned long 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.
Attribute that holds an unsigned long long.
unsigned long long m_val
Attribute value.
unsigned long long value() const
get the value associated to this Attribute.
ULongLongAttribute()
Default constructor.
bool from_string(const std::string &att) override
Implementation of Attribute::from_string.
void set_value(const unsigned long long &i)
set the value associated to this Attribute.
bool to_string(std::string &att) const override
Implementation of Attribute::to_string.
ULongLongAttribute(unsigned long long val)
Constructor initializing attribute value.
Attribute that holds a vector of charegers of type char.
VectorCharAttribute(std::vector< char > val)
Constructor initializing attribute value.
std::vector< char > value() const
get the value associated to this Attribute.
std::vector< char > m_val
Attribute value.
void set_value(const std::vector< char > &i)
set the value associated to this Attribute.
bool from_string(const std::string &att) override
Implementation of Attribute::from_string.
VectorCharAttribute()
Default constructor.
bool to_string(std::string &att) const override
Implementation of Attribute::to_string.
std::vector< double > value() const
get the value associated to this Attribute.
void set_value(const std::vector< double > &i)
set the value associated to this Attribute.
bool from_string(const std::string &att) override
Implementation of Attribute::from_string.
std::vector< double > m_val
Attribute value.
VectorDoubleAttribute(std::vector< double > val)
Constructor initializing attribute value.
bool to_string(std::string &att) const override
Implementation of Attribute::to_string.
VectorDoubleAttribute()
Default constructor.
Attribute that holds a vector of floategers of type float.
VectorFloatAttribute(std::vector< float > val)
Constructor initializing attribute value.
std::vector< float > value() const
get the value associated to this Attribute.
void set_value(const std::vector< float > &i)
set the value associated to this Attribute.
bool from_string(const std::string &att) override
Implementation of Attribute::from_string.
VectorFloatAttribute()
Default constructor.
std::vector< float > m_val
Attribute value.
bool to_string(std::string &att) const override
Implementation of Attribute::to_string.
Attribute that holds a vector of integers of type int.
std::vector< int > value() const
get the value associated to this Attribute.
std::vector< int > m_val
Attribute value.
bool from_string(const std::string &att) override
Implementation of Attribute::from_string.
VectorIntAttribute()
Default constructor.
bool to_string(std::string &att) const override
Implementation of Attribute::to_string.
void set_value(const std::vector< int > &i)
set the value associated to this Attribute.
VectorIntAttribute(std::vector< int > val)
Constructor initializing attribute value.
Attribute that holds a vector of long doubleegers of type long double.
std::vector< long double > value() const
get the value associated to this Attribute.
void set_value(const std::vector< long double > &i)
set the value associated to this Attribute.
VectorLongDoubleAttribute()
Default constructor.
std::vector< long double > m_val
Attribute value.
VectorLongDoubleAttribute(std::vector< long double > 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.
VectorLongIntAttribute(std::vector< long int > val)
Constructor initializing attribute value.
VectorLongIntAttribute()
Default constructor.
std::vector< long int > value() const
get the value associated to this Attribute.
bool from_string(const std::string &att) override
Implementation of Attribute::from_string.
std::vector< long int > m_val
Attribute value.
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.
Attribute that holds a vector of long longegers of type long long.
std::vector< long long > value() const
get the value associated to this Attribute.
std::vector< long long > m_val
Attribute value.
bool from_string(const std::string &att) override
Implementation of Attribute::from_string.
VectorLongLongAttribute()
Default constructor.
void set_value(const std::vector< long long > &i)
set the value associated to this Attribute.
VectorLongLongAttribute(std::vector< long long > val)
Constructor initializing attribute value.
bool to_string(std::string &att) const override
Implementation of Attribute::to_string.
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.
void set_value(const std::vector< std::string > &i)
set the value associated to this Attribute.
VectorStringAttribute(std::vector< std::string > val)
Constructor initializing attribute value.
VectorStringAttribute()
Default constructor.
bool to_string(std::string &att) const override
Implementation of Attribute::to_string.
std::vector< std::string > m_val
Attribute value.
Attribute that holds a vector of unsigned integers of type unsigned int.
VectorUIntAttribute()
Default constructor.
std::vector< unsigned int > m_val
Attribute value.
VectorUIntAttribute(std::vector< unsigned int > val)
Constructor initializing attribute value.
std::vector< unsigned int > 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 int > &i)
set the value associated to this Attribute.
bool to_string(std::string &att) const override
Implementation of Attribute::to_string.
Attribute that holds a vector of unsigned longegers of type unsigned long.
void set_value(const std::vector< unsigned long > &i)
set the value associated to this Attribute.
std::vector< unsigned long > value() const
get the value associated to this Attribute.
std::vector< unsigned long > m_val
Attribute value.
bool from_string(const std::string &att) override
Implementation of Attribute::from_string.
VectorULongAttribute()
Default constructor.
VectorULongAttribute(std::vector< unsigned long > val)
Constructor initializing attribute value.
bool to_string(std::string &att) const override
Implementation of Attribute::to_string.
Attribute that holds a vector of unsigned long longegers of type unsigned long long.
std::vector< unsigned long long > value() const
get the value associated to this Attribute.
VectorULongLongAttribute(std::vector< unsigned long long > val)
Constructor initializing attribute value.
void set_value(const std::vector< unsigned long long > &i)
set the value associated to this Attribute.
bool from_string(const std::string &att) override
Implementation of Attribute::from_string.
std::vector< unsigned long long > m_val
Attribute value.
bool to_string(std::string &att) const override
Implementation of Attribute::to_string.
VectorULongLongAttribute()
Default constructor.