yoda is hosted by Hepforge, IPPP Durham
YODA - Yet more Objects for Data Analysis  1.7.2
YODA::AnalysisObject Class Referenceabstract

AnalysisObject is the base class for histograms and scatters. More...

#include <AnalysisObject.h>

Inheritance diagram for YODA::AnalysisObject:
YODA::Counter YODA::Histo1D YODA::Histo2D YODA::Profile1D YODA::Profile2D YODA::Scatter< N > YODA::Scatter< N > YODA::Scatter1D YODA::Scatter2D YODA::Scatter3D

Public Types

typedef std::map< std::string, std::string > Annotations
 Collection type for annotations, as a string-string map. More...
 

Public Member Functions

Creation and destruction
 AnalysisObject ()
 Default constructor. More...
 
 AnalysisObject (const std::string &type, const std::string &path, const std::string &title="")
 Constructor giving a type, a path and an optional title. More...
 
 AnalysisObject (const std::string &type, const std::string &path, const AnalysisObject &ao, const std::string &title="")
 Constructor giving a type, a path, another AO to copy annotation from, and an optional title. More...
 
virtual ~AnalysisObject ()
 Default destructor. More...
 
virtual AnalysisObjectoperator= (const AnalysisObject &ao)
 Default copy assignment operator. More...
 
virtual AnalysisObjectnewclone () const =0
 Make a copy on the heap, via 'new'. More...
 
Modifiers
virtual void reset ()=0
 Reset this analysis object. More...
 
Annotations
std::vector< std::string > annotations () const
 
bool hasAnnotation (const std::string &name) const
 Check if an annotation is defined. More...
 
const std::string & annotation (const std::string &name) const
 Get an annotation by name (as a string) More...
 
const std::string & annotation (const std::string &name, const std::string &defaultreturn) const
 Get an annotation by name (as a string) with a default in case the annotation is not found. More...
 
template<typename T >
const T annotation (const std::string &name) const
 Get an annotation by name (copied to another type) More...
 
template<typename T >
const T annotation (const std::string &name, const T &defaultreturn) const
 Get an annotation by name (copied to another type) with a default in case the annotation is not found. More...
 
void setAnnotation (const std::string &name, const std::string &value)
 Add or set a string-valued annotation by name. More...
 
void setAnnotation (const std::string &name, double value)
 Add or set a double-valued annotation by name. More...
 
void setAnnotation (const std::string &name, float value)
 Add or set a float-valued annotation by name. More...
 
void setAnnotation (const std::string &name, long double value)
 Add or set a long-double-valued annotation by name. More...
 
template<typename T >
void setAnnotation (const std::string &name, const T &value)
 Add or set an annotation by name (templated for remaining types) More...
 
void setAnnotations (const Annotations &anns)
 Set all annotations at once. More...
 
template<typename T >
void addAnnotation (const std::string &name, const T &value)
 Add or set an annotation by name. More...
 
void rmAnnotation (const std::string &name)
 Delete an annotation by name. More...
 
void clearAnnotations ()
 Delete an annotation by name. More...
 
Standard annotations
const std::string title () const
 Get the AO title. More...
 
void setTitle (const std::string &title)
 Set the AO title. More...
 
const std::string path () const
 Get the AO path. More...
 
void setPath (const std::string &path)
 
const std::string name () const
 
Persistency hooks / object type info
virtual std::string type () const
 Get name of the analysis object type. More...
 
virtual size_t dim () const =0
 Get the dimension of the analysis object type. More...
 

Detailed Description

AnalysisObject is the base class for histograms and scatters.

Definition at line 20 of file AnalysisObject.h.

Member Typedef Documentation

◆ Annotations

typedef std::map<std::string, std::string> YODA::AnalysisObject::Annotations

Collection type for annotations, as a string-string map.

Definition at line 25 of file AnalysisObject.h.

Constructor & Destructor Documentation

◆ AnalysisObject() [1/3]

YODA::AnalysisObject::AnalysisObject ( )
inline

Default constructor.

Definition at line 32 of file AnalysisObject.h.

32 { }

◆ AnalysisObject() [2/3]

YODA::AnalysisObject::AnalysisObject ( const std::string &  type,
const std::string &  path,
const std::string &  title = "" 
)
inline

Constructor giving a type, a path and an optional title.

Definition at line 35 of file AnalysisObject.h.

References setAnnotation(), setPath(), setTitle(), and title().

35  {
36  setAnnotation("Type", type);
37  setPath(path);
38  setTitle(title);
39  }
const std::string path() const
Get the AO path.
void setPath(const std::string &path)
const std::string title() const
Get the AO title.
virtual std::string type() const
Get name of the analysis object type.
void setTitle(const std::string &title)
Set the AO title.
void setAnnotation(const std::string &name, const std::string &value)
Add or set a string-valued annotation by name.

◆ AnalysisObject() [3/3]

YODA::AnalysisObject::AnalysisObject ( const std::string &  type,
const std::string &  path,
const AnalysisObject ao,
const std::string &  title = "" 
)
inline

Constructor giving a type, a path, another AO to copy annotation from, and an optional title.

Definition at line 42 of file AnalysisObject.h.

References annotation(), annotations(), setAnnotation(), setPath(), setTitle(), and title().

43  {
44  for (const std::string& a : ao.annotations())
45  setAnnotation(a, ao.annotation(a));
46  setAnnotation("Type", type); // might override the copied ones
47  setPath(path);
48  setTitle(title);
49  }
const std::string path() const
Get the AO path.
void setPath(const std::string &path)
const std::string title() const
Get the AO title.
virtual std::string type() const
Get name of the analysis object type.
void setTitle(const std::string &title)
Set the AO title.
void setAnnotation(const std::string &name, const std::string &value)
Add or set a string-valued annotation by name.

◆ ~AnalysisObject()

virtual YODA::AnalysisObject::~AnalysisObject ( )
inlinevirtual

Default destructor.

Definition at line 58 of file AnalysisObject.h.

58 { }

Member Function Documentation

◆ addAnnotation()

template<typename T >
void YODA::AnalysisObject::addAnnotation ( const std::string &  name,
const T &  value 
)
inline

Add or set an annotation by name.

Note: Templated on arg type, but stored as a string. This is just a synonym for setAnnotation.

Definition at line 198 of file AnalysisObject.h.

References setAnnotation().

Referenced by YODA::toScatter2D(), and YODA::toScatter3D().

198  {
199  setAnnotation(name, value);
200  }
void setAnnotation(const std::string &name, const std::string &value)
Add or set a string-valued annotation by name.
const std::string name() const

◆ annotation() [1/4]

const std::string& YODA::AnalysisObject::annotation ( const std::string &  name) const
inline

Get an annotation by name (as a string)

Definition at line 104 of file AnalysisObject.h.

References name().

Referenced by AnalysisObject(), annotation(), YODA::WriterFLAT::create(), YODA::mkScatter(), path(), YODA::Scatter1D::Scatter1D(), YODA::Scatter2D::Scatter2D(), YODA::Scatter3D::Scatter3D(), title(), YODA::toTGraph(), YODA::toTH1D(), YODA::toTH2D(), YODA::toTProfile(), and type().

104  {
105  Annotations::const_iterator v = _annotations.find(name);
106  // If not found... written this way round on purpose
107  if (v == _annotations.end()) {
108  std::string missing = "YODA::AnalysisObject: No annotation named " + name;
109  throw AnnotationError(missing);
110  }
111  return v->second;
112  }
const std::string name() const

◆ annotation() [2/4]

const std::string& YODA::AnalysisObject::annotation ( const std::string &  name,
const std::string &  defaultreturn 
) const
inline

Get an annotation by name (as a string) with a default in case the annotation is not found.

Definition at line 116 of file AnalysisObject.h.

116  {
117  Annotations::const_iterator v = _annotations.find(name);
118  if (v != _annotations.end()) return v->second;
119  return defaultreturn;
120  }
const std::string name() const

◆ annotation() [3/4]

template<typename T >
const T YODA::AnalysisObject::annotation ( const std::string &  name) const
inline

Get an annotation by name (copied to another type)

Note
Templated on return type

Definition at line 127 of file AnalysisObject.h.

References annotation().

127  {
128  std::string s = annotation(name);
129  return Utils::lexical_cast<T>(s);
130  }
const std::string & annotation(const std::string &name) const
Get an annotation by name (as a string)
const std::string name() const

◆ annotation() [4/4]

template<typename T >
const T YODA::AnalysisObject::annotation ( const std::string &  name,
const T &  defaultreturn 
) const
inline

Get an annotation by name (copied to another type) with a default in case the annotation is not found.

Note
Templated on return type

Definition at line 137 of file AnalysisObject.h.

References annotation().

137  {
138  try {
139  std::string s = annotation(name);
140  return Utils::lexical_cast<T>(s);
141  } catch (const AnnotationError& ae) {
142  return defaultreturn;
143  }
144  }
const std::string & annotation(const std::string &name) const
Get an annotation by name (as a string)
const std::string name() const

◆ annotations()

std::vector<std::string> YODA::AnalysisObject::annotations ( ) const
inline

Get all the annotation names

Todo:
Change this to return the str->str map, with a separate annotationKeys, etc.

Definition at line 89 of file AnalysisObject.h.

Referenced by AnalysisObject(), YODA::WriterFLAT::create(), YODA::mkScatter(), YODA::Scatter1D::Scatter1D(), YODA::Scatter2D::Scatter2D(), and YODA::Scatter3D::Scatter3D().

89  {
90  std::vector<std::string> rtn;
91  rtn.reserve(_annotations.size());
92  for (const Annotations::value_type& kv : _annotations) rtn.push_back(kv.first);
93  return rtn;
94  }

◆ clearAnnotations()

void YODA::AnalysisObject::clearAnnotations ( )
inline

Delete an annotation by name.

Definition at line 210 of file AnalysisObject.h.

210  {
211  _annotations.clear();
212  }

◆ dim()

virtual size_t YODA::AnalysisObject::dim ( ) const
pure virtual

Get the dimension of the analysis object type.

Note
For fillable types this is the dimension of the fill space (e.g. Histo1D -> dim=1). For scatter types, it is the total dimension of the points (e.g. Scatter3D -> dim=3).

Implemented in YODA::Scatter3D, YODA::Scatter2D, YODA::Histo2D, YODA::Profile2D, YODA::Scatter1D, YODA::Histo1D, YODA::Profile1D, and YODA::Counter.

Referenced by type().

◆ hasAnnotation()

bool YODA::AnalysisObject::hasAnnotation ( const std::string &  name) const
inline

◆ name()

const std::string YODA::AnalysisObject::name ( ) const
inline

Get the AO name – the last part of the path. Returns a null string if path is undefined

Definition at line 258 of file AnalysisObject.h.

References path().

Referenced by annotation(), and setAnnotation().

258  {
259  const std::string p = path();
260  const size_t lastslash = p.rfind("/");
261  if (lastslash == std::string::npos) return p;
262  return p.substr(lastslash+1);
263  }
const std::string path() const
Get the AO path.

◆ newclone()

virtual AnalysisObject* YODA::AnalysisObject::newclone ( ) const
pure virtual

◆ operator=()

virtual AnalysisObject& YODA::AnalysisObject::operator= ( const AnalysisObject ao)
inlinevirtual

Default copy assignment operator.

Definition at line 61 of file AnalysisObject.h.

References newclone(), path(), reset(), setPath(), setTitle(), and title().

Referenced by YODA::Histo1D::operator=(), YODA::Profile1D::operator=(), YODA::Scatter1D::operator=(), YODA::Histo2D::operator=(), YODA::Profile2D::operator=(), YODA::Scatter2D::operator=(), and YODA::Scatter3D::operator=().

61  {
62  if (ao.path().length() > 0) setPath(ao.path());
63  if (ao.title().length() > 0) setTitle(ao.title());
64  return *this;
65  }
void setPath(const std::string &path)
void setTitle(const std::string &title)
Set the AO title.

◆ path()

const std::string YODA::AnalysisObject::path ( ) const
inline

Get the AO path.

Returns a null string if undefined, rather than throwing an exception cf. annotation("Path").

Note
A leading / will be prepended if not already set.

Definition at line 236 of file AnalysisObject.h.

References annotation().

Referenced by YODA::add(), YODA::Counter::Counter(), YODA::divide(), YODA::Histo1D::Histo1D(), YODA::Histo2D::Histo2D(), YODA::multiply(), name(), operator=(), YODA::Counter::operator=(), YODA::Profile1D::Profile1D(), YODA::Profile2D::Profile2D(), YODA::subtract(), YODA::toTGraph(), YODA::toTH1D(), YODA::toTH2D(), YODA::toTProfile(), YODA::WriterFLAT::writeCounter(), YODA::WriterFLAT::writeScatter1D(), YODA::WriterFLAT::writeScatter2D(), YODA::WriterAIDA::writeScatter2D(), and YODA::WriterFLAT::writeScatter3D().

236  {
237  const std::string p = annotation("Path", "");
238  // If not set at all, return an empty string
239  if (p.empty()) return p;
240  // If missing a leading slash, one will be prepended
241  return p.find("/") == 0 ? p : ("/"+p);
242  }
const std::string & annotation(const std::string &name) const
Get an annotation by name (as a string)

◆ reset()

virtual void YODA::AnalysisObject::reset ( )
pure virtual

◆ rmAnnotation()

void YODA::AnalysisObject::rmAnnotation ( const std::string &  name)
inline

◆ setAnnotation() [1/5]

◆ setAnnotation() [2/5]

void YODA::AnalysisObject::setAnnotation ( const std::string &  name,
double  value 
)
inline

Add or set a double-valued annotation by name.

Todo:
Can we cover all FP types in one function via SFINAE?

Definition at line 154 of file AnalysisObject.h.

References setAnnotation().

154  {
155  // Recipe from Boost docs
156  std::stringstream ss;
157  ss << std::setprecision(std::numeric_limits<double>::max_digits10) << std::scientific << value;
158  setAnnotation(name, ss.str());
159  }
void setAnnotation(const std::string &name, const std::string &value)
Add or set a string-valued annotation by name.
const std::string name() const

◆ setAnnotation() [3/5]

void YODA::AnalysisObject::setAnnotation ( const std::string &  name,
float  value 
)
inline

Add or set a float-valued annotation by name.

Todo:
Can we cover all FP types in one function via SFINAE?

Definition at line 163 of file AnalysisObject.h.

References setAnnotation().

163  {
164  // Recipe from Boost docs
165  std::stringstream ss;
166  ss << std::setprecision(std::numeric_limits<double>::max_digits10) << std::scientific << value;
167  setAnnotation(name, ss.str());
168  }
void setAnnotation(const std::string &name, const std::string &value)
Add or set a string-valued annotation by name.
const std::string name() const

◆ setAnnotation() [4/5]

void YODA::AnalysisObject::setAnnotation ( const std::string &  name,
long double  value 
)
inline

Add or set a long-double-valued annotation by name.

Todo:
Can we cover all FP types in one function via SFINAE?

Definition at line 172 of file AnalysisObject.h.

References setAnnotation().

172  {
173  // Recipe from Boost docs
174  std::stringstream ss;
175  ss << std::setprecision(std::numeric_limits<double>::max_digits10) << std::scientific << value;
176  setAnnotation(name, ss.str());
177  }
void setAnnotation(const std::string &name, const std::string &value)
Add or set a string-valued annotation by name.
const std::string name() const

◆ setAnnotation() [5/5]

template<typename T >
void YODA::AnalysisObject::setAnnotation ( const std::string &  name,
const T &  value 
)
inline

Add or set an annotation by name (templated for remaining types)

Note
Templated on arg type, but stored as a string.

Definition at line 183 of file AnalysisObject.h.

References setAnnotation().

183  {
184  setAnnotation(name, Utils::lexical_cast<std::string>(value));
185  }
void setAnnotation(const std::string &name, const std::string &value)
Add or set a string-valued annotation by name.
const std::string name() const

◆ setAnnotations()

void YODA::AnalysisObject::setAnnotations ( const Annotations anns)
inline

Set all annotations at once.

Definition at line 189 of file AnalysisObject.h.

189  {
190  _annotations = anns;
191  }

◆ setPath()

void YODA::AnalysisObject::setPath ( const std::string &  path)
inline

Set the AO path

Note
A leading / will be prepended if not already given.

Definition at line 247 of file AnalysisObject.h.

References setAnnotation().

Referenced by YODA::add(), AnalysisObject(), YODA::divide(), YODA::multiply(), operator=(), YODA::Counter::operator=(), YODA::Scatter< N >::operator=(), YODA::subtract(), YODA::toScatter2D(), and YODA::toScatter3D().

247  {
248  const std::string p = (path.find("/") == 0) ? path : "/"+path;
249  // if (path.length() > 0 && path.find("/") != 0) {
250  // throw AnnotationError("Histo paths must start with a slash (/) character.");
251  // }
252  setAnnotation("Path", p);
253  }
const std::string path() const
Get the AO path.
void setAnnotation(const std::string &name, const std::string &value)
Add or set a string-valued annotation by name.

◆ setTitle()

void YODA::AnalysisObject::setTitle ( const std::string &  title)
inline

Set the AO title.

Definition at line 228 of file AnalysisObject.h.

References setAnnotation().

Referenced by AnalysisObject(), operator=(), YODA::Counter::operator=(), YODA::Scatter< N >::operator=(), YODA::toScatter2D(), and YODA::toScatter3D().

228  {
229  setAnnotation("Title", title);
230  }
const std::string title() const
Get the AO title.
void setAnnotation(const std::string &name, const std::string &value)
Add or set a string-valued annotation by name.

◆ title()

const std::string YODA::AnalysisObject::title ( ) const
inline

Get the AO title.

Returns a null string if undefined, rather than throwing an exception cf. the annotation("Title").

Definition at line 223 of file AnalysisObject.h.

References annotation().

Referenced by AnalysisObject(), operator=(), YODA::Counter::operator=(), YODA::toTGraph(), YODA::toTH1D(), YODA::toTH2D(), and YODA::toTProfile().

223  {
224  return annotation("Title", "");
225  }
const std::string & annotation(const std::string &name) const
Get an annotation by name (as a string)

◆ type()

virtual std::string YODA::AnalysisObject::type ( ) const
inlinevirtual

Get name of the analysis object type.

Definition at line 274 of file AnalysisObject.h.

References annotation(), and dim().

Referenced by YODA::mkScatter(), and YODA::Writer::writeBody().

274  {
275  return annotation("Type");
276  }
const std::string & annotation(const std::string &name) const
Get an annotation by name (as a string)

The documentation for this class was generated from the following file: