yoda is hosted by Hepforge, IPPP Durham
YODA - Yet more Objects for Data Analysis  1.9.0
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::Histo YODA::Histo1D YODA::Histo2D YODA::Profile1D YODA::Profile2D 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...
 
void parseVariations ()
 
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 22 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 27 of file AnalysisObject.h.

Constructor & Destructor Documentation

◆ AnalysisObject() [1/3]

YODA::AnalysisObject::AnalysisObject ( )
inline

Default constructor.

Definition at line 34 of file AnalysisObject.h.

34 { }

◆ 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 37 of file AnalysisObject.h.

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

37  {
38  setAnnotation("Type", type);
39  setPath(path);
40  setTitle(title);
41  }
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 44 of file AnalysisObject.h.

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

45  {
46  for (const std::string& a : ao.annotations())
47  setAnnotation(a, ao.annotation(a));
48  setAnnotation("Type", type); // might override the copied ones
49  setPath(path);
50  setTitle(title);
51  }
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 60 of file AnalysisObject.h.

60 { }

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 203 of file AnalysisObject.h.

References setAnnotation().

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

203  {
204  setAnnotation(name, value);
205  }
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 109 of file AnalysisObject.h.

References name().

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

109  {
110  Annotations::const_iterator v = _annotations.find(name);
111  // If not found... written this way round on purpose
112  if (v == _annotations.end()) {
113  std::string missing = "YODA::AnalysisObject: No annotation named " + name;
114  throw AnnotationError(missing);
115  }
116  return v->second;
117  }
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 121 of file AnalysisObject.h.

121  {
122  Annotations::const_iterator v = _annotations.find(name);
123  if (v != _annotations.end()) return v->second;
124  return defaultreturn;
125  }
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 132 of file AnalysisObject.h.

References annotation().

132  {
133  std::string s = annotation(name);
134  return Utils::lexical_cast<T>(s);
135  }
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 142 of file AnalysisObject.h.

References annotation().

142  {
143  try {
144  std::string s = annotation(name);
145  return Utils::lexical_cast<T>(s);
146  } catch (const AnnotationError& ae) {
147  return defaultreturn;
148  }
149  }
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 94 of file AnalysisObject.h.

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

94  {
95  std::vector<std::string> rtn;
96  rtn.reserve(_annotations.size());
97  for (const Annotations::value_type& kv : _annotations) rtn.push_back(kv.first);
98  return rtn;
99  }

◆ clearAnnotations()

void YODA::AnalysisObject::clearAnnotations ( )
inline

Delete an annotation by name.

Definition at line 215 of file AnalysisObject.h.

215  {
216  _annotations.clear();
217  }

◆ 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).
Todo:
Provide a distinct fillDim() method on Fillables, and make dim always report the total dimension

Implemented in YODA::Scatter3D, YODA::Scatter2D, YODA::Histo2D, YODA::Profile2D, YODA::Histo1D, YODA::Profile1D, YODA::Scatter1D, YODA::Counter, YODA::Histo, and YODA::Scatter< N >.

Referenced by type().

◆ hasAnnotation()

◆ 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 263 of file AnalysisObject.h.

References path().

Referenced by annotation(), and setAnnotation().

263  {
264  const std::string p = path();
265  const size_t lastslash = p.rfind("/");
266  if (lastslash == std::string::npos) return p;
267  return p.substr(lastslash+1);
268  }
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 63 of file AnalysisObject.h.

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

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

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

◆ parseVariations()

void YODA::AnalysisObject::parseVariations ( )
inline

Definition at line 83 of file AnalysisObject.h.

83 { return ; }

◆ 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 241 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().

241  {
242  const std::string p = annotation("Path", "");
243  // If not set at all, return an empty string
244  if (p.empty()) return p;
245  // If missing a leading slash, one will be prepended
246  return p.find("/") == 0 ? p : ("/"+p);
247  }
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 159 of file AnalysisObject.h.

References setAnnotation().

159  {
160  // Recipe from Boost docs
161  std::stringstream ss;
162  ss << std::setprecision(std::numeric_limits<double>::max_digits10) << std::scientific << value;
163  setAnnotation(name, ss.str());
164  }
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 168 of file AnalysisObject.h.

References setAnnotation().

168  {
169  // Recipe from Boost docs
170  std::stringstream ss;
171  ss << std::setprecision(std::numeric_limits<double>::max_digits10) << std::scientific << value;
172  setAnnotation(name, ss.str());
173  }
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 177 of file AnalysisObject.h.

References setAnnotation().

177  {
178  // Recipe from Boost docs
179  std::stringstream ss;
180  ss << std::setprecision(std::numeric_limits<double>::max_digits10) << std::scientific << value;
181  setAnnotation(name, ss.str());
182  }
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 188 of file AnalysisObject.h.

References setAnnotation().

188  {
189  setAnnotation(name, Utils::lexical_cast<std::string>(value));
190  }
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 194 of file AnalysisObject.h.

194  {
195  _annotations = anns;
196  }

◆ 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 252 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().

252  {
253  const std::string p = (path.find("/") == 0) ? path : "/"+path;
254  // if (path.length() > 0 && path.find("/") != 0) {
255  // throw AnnotationError("Histo paths must start with a slash (/) character.");
256  // }
257  setAnnotation("Path", p);
258  }
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 233 of file AnalysisObject.h.

References setAnnotation().

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

233  {
234  setAnnotation("Title", title);
235  }
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 228 of file AnalysisObject.h.

References annotation().

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

228  {
229  return annotation("Title", "");
230  }
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 279 of file AnalysisObject.h.

References annotation(), and dim().

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

279  {
280  return annotation("Type");
281  }
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: