YODA is hosted by Hepforge, IPPP Durham
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::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
const std::vector< std::string > annotations () const
 Get all the annotation names. More...
 
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...
 
template<typename T >
void setAnnotation (const std::string &name, const T &value)
 Add or set an annotation by name. 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
 
void setTitle (const std::string &title)
 Set the AO title. More...
 
const std::string path () const
 
void setPath (const std::string &path)
 Set the AO path. More...
 
Persistency hooks
virtual std::string type () const
 Get name of the analysis object type, for persistency. More...
 

Detailed Description

AnalysisObject is the base class for histograms and scatters.

Definition at line 18 of file AnalysisObject.h.

Member Typedef Documentation

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

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

Definition at line 23 of file AnalysisObject.h.

Constructor & Destructor Documentation

YODA::AnalysisObject::AnalysisObject ( )
inline

Default constructor.

Definition at line 30 of file AnalysisObject.h.

30 { }
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 33 of file AnalysisObject.h.

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

33  {
34  setAnnotation("Type", type);
35  setPath(path);
36  setTitle(title);
37  }
void setAnnotation(const std::string &name, const T &value)
Add or set an annotation by name.
void setPath(const std::string &path)
Set the AO path.
virtual std::string type() const
Get name of the analysis object type, for persistency.
void setTitle(const std::string &title)
Set the AO title.
const std::string path() const
const std::string title() const
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 40 of file AnalysisObject.h.

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

41  {
42  BOOST_FOREACH (const std::string& a, ao.annotations())
43  setAnnotation(a, ao.annotation(a));
44  setAnnotation("Type", type); // might override the copied ones
45  setPath(path);
46  setTitle(title);
47  }
void setAnnotation(const std::string &name, const T &value)
Add or set an annotation by name.
void setPath(const std::string &path)
Set the AO path.
virtual std::string type() const
Get name of the analysis object type, for persistency.
void setTitle(const std::string &title)
Set the AO title.
const std::string path() const
const std::string title() const
virtual YODA::AnalysisObject::~AnalysisObject ( )
inlinevirtual

Default destructor.

Definition at line 56 of file AnalysisObject.h.

56 { }

Member Function Documentation

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

References setAnnotation().

Referenced by YODA::toScatter2D().

166  {
167  setAnnotation(name, value);
168  }
void setAnnotation(const std::string &name, const T &value)
Add or set an annotation by name.
const std::string& YODA::AnalysisObject::annotation ( const std::string &  name) const
inline

Get an annotation by name (as a string)

Definition at line 101 of file AnalysisObject.h.

Referenced by AnalysisObject(), annotation(), YODA::mkScatter(), path(), title(), YODA::toTGraph(), YODA::toTH1D(), YODA::toTH2D(), YODA::toTProfile(), type(), and YODA::WriterAIDA::writeScatter2D().

101  {
102  Annotations::const_iterator v = _annotations.find(name);
103  // If not found... written this way round on purpose
104  if (v == _annotations.end()) {
105  std::string missing = "YODA::AnalysisObject: No annotation named " + name;
106  throw AnnotationError(missing);
107  }
108  return v->second;
109  }
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 113 of file AnalysisObject.h.

113  {
114  Annotations::const_iterator v = _annotations.find(name);
115  if (v != _annotations.end()) return v->second;
116  return defaultreturn;
117  }
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 124 of file AnalysisObject.h.

References annotation().

124  {
125  std::string s = annotation(name);
126  return boost::lexical_cast<T>(s);
127  }
const std::string & annotation(const std::string &name) const
Get an annotation by name (as a string)
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 134 of file AnalysisObject.h.

References annotation().

134  {
135  try {
136  std::string s = annotation(name);
137  return boost::lexical_cast<T>(s);
138  } catch (const AnnotationError& ae) {
139  return defaultreturn;
140  }
141  }
const std::string & annotation(const std::string &name) const
Get an annotation by name (as a string)
const std::vector<std::string> YODA::AnalysisObject::annotations ( ) const
inline

Get all the annotation names.

Definition at line 86 of file AnalysisObject.h.

Referenced by AnalysisObject(), YODA::mkScatter(), and YODA::WriterAIDA::writeScatter2D().

86  {
87  std::vector<std::string> rtn;
88  rtn.reserve(_annotations.size());
89  BOOST_FOREACH (const Annotations::value_type& kv, _annotations) rtn.push_back(kv.first);
90  return rtn;
91  }
void YODA::AnalysisObject::clearAnnotations ( )
inline

Delete an annotation by name.

Definition at line 178 of file AnalysisObject.h.

178  {
179  _annotations.clear();
180  }
bool YODA::AnalysisObject::hasAnnotation ( const std::string &  name) const
inline
virtual AnalysisObject* YODA::AnalysisObject::newclone ( ) const
pure virtual
virtual AnalysisObject& YODA::AnalysisObject::operator= ( const AnalysisObject ao)
inlinevirtual

Default copy assignment operator.

Definition at line 59 of file AnalysisObject.h.

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

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

59  {
60  if (ao.path().length() > 0) setPath(ao.path());
61  if (ao.title().length() > 0) setTitle(ao.title());
62  return *this;
63  }
void setPath(const std::string &path)
Set the AO path.
void setTitle(const std::string &title)
Set the AO title.
const std::string YODA::AnalysisObject::path ( ) const
inline
virtual void YODA::AnalysisObject::reset ( )
pure virtual
void YODA::AnalysisObject::rmAnnotation ( const std::string &  name)
inline
template<typename T >
void YODA::AnalysisObject::setAnnotation ( 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.
Todo:
Specialise for float, double, etc. with this safer recipe from the Boost docs:

Definition at line 148 of file AnalysisObject.h.

Referenced by addAnnotation(), AnalysisObject(), YODA::mkScatter(), YODA::Counter::scaleW(), YODA::Histo1D::scaleW(), YODA::Histo2D::scaleW(), YODA::Profile2D::scaleW(), setPath(), setTitle(), YODA::WriterAIDA::writeHisto1D(), YODA::WriterFLAT::writeHisto1D(), YODA::WriterFLAT::writeHisto2D(), YODA::WriterFLAT::writeProfile1D(), YODA::WriterAIDA::writeProfile1D(), and YODA::WriterFLAT::writeProfile2D().

148  {
149  _annotations[name] = boost::lexical_cast<std::string>(value);
151  // std::stringstream ss;
152  // ss << setprecison(std::numeric_limits<double>::max_digits10) << scientific << output_value;
153  }
void YODA::AnalysisObject::setAnnotations ( const Annotations anns)
inline

Set all annotations at once.

Definition at line 157 of file AnalysisObject.h.

157  {
158  _annotations = anns;
159  }
void YODA::AnalysisObject::setPath ( const std::string &  path)
inline

Set the AO path.

Definition at line 214 of file AnalysisObject.h.

References setAnnotation().

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

214  {
215  if (path.length() > 0 && path.find("/") != 0) {
216  throw AnnotationError("Histo paths must start with a slash (/) character.");
217  }
218  setAnnotation("Path", path);
219  }
void setAnnotation(const std::string &name, const T &value)
Add or set an annotation by name.
const std::string path() const
void YODA::AnalysisObject::setTitle ( const std::string &  title)
inline

Set the AO title.

Definition at line 199 of file AnalysisObject.h.

References setAnnotation().

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

199  {
200  setAnnotation("Title", title);
201  }
void setAnnotation(const std::string &name, const T &value)
Add or set an annotation by name.
const std::string title() const
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 Title annotation.

Definition at line 190 of file AnalysisObject.h.

References annotation().

Referenced by AnalysisObject(), operator=(), YODA::Counter::operator=(), YODA::Scatter< N >::operator=(), YODA::toTGraph(), YODA::toTH1D(), YODA::toTH2D(), YODA::toTProfile(), and YODA::WriterAIDA::writeScatter2D().

190  {
191  try {
192  return annotation("Title");
193  } catch (AnnotationError& ae) {
194  return "";
195  }
196  }
const std::string & annotation(const std::string &name) const
Get an annotation by name (as a string)
virtual std::string YODA::AnalysisObject::type ( ) const
inlinevirtual

Get name of the analysis object type, for persistency.

Reimplemented in YODA::Profile2D, and YODA::Profile1D.

Definition at line 230 of file AnalysisObject.h.

References annotation().

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

230  {
231  return annotation("Type");
232  }
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: