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

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

#include <AnalysisObject.h>

Inheritance diagram for YODA::AnalysisObject:
YODA::DbnStorage< DbnN, AxisT... > YODA::DbnStorage< 1, AxisT > YODA::DbnStorage< 2, AxisT > YODA::DbnStorage< 2, AxisT1, AxisT2 > YODA::DbnStorage< 3, AxisT1, AxisT2 > YODA::DbnStorage< 3, AxisT1, AxisT2, AxisT3 > YODA::DbnStorage< 4, AxisT1, AxisT2, AxisT3 > YODA::EstimateStorage< AxisT... > YODA::EstimateStorage< AxisT1, AxisT2 > YODA::EstimateStorage< AxisT1, AxisT2, AxisT3 > YODA::Counter YODA::DbnStorage< DbnN, AxisT > YODA::Estimate0D YODA::EstimateStorage< AxisT > YODA::ScatterND< N >

Public Types

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

Public Member Functions

Creation and destruction
 AnalysisObject ()
 Default constructor.
 
 AnalysisObject (const std::string &type, const std::string &path, const std::string &title="")
 Constructor giving a type, a path and an optional title.
 
 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.
 
virtual ~AnalysisObject ()
 Default destructor.
 
virtual AnalysisObjectoperator= (const AnalysisObject &ao) noexcept
 Default copy assignment operator.
 
virtual AnalysisObjectnewclone () const =0
 Make a copy on the heap, via 'new'.
 
Modifiers
virtual void reset ()=0
 Reset this analysis object.
 
Annotations
std::vector< std::string > annotations () const
 
bool hasAnnotation (const std::string &name) const
 Check if an annotation is defined.
 
const std::string & annotation (const std::string &name) const
 Get an annotation by name (as a string)
 
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.
 
template<typename T >
const T annotation (const std::string &name) const
 Get an annotation by name (copied to another type)
 
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.
 
template<typename T >
void setAnnotation (const std::string &name, const T &value)
 Add or set an annotation by name (templated for remaining types)
 
void setAnnotations (const Annotations &anns)
 Set all annotations at once.
 
template<typename T >
void addAnnotation (const std::string &name, const T &value)
 Add or set an annotation by name.
 
void rmAnnotation (const std::string &name)
 Delete an annotation by name.
 
void clearAnnotations ()
 Delete an annotation by name.
 
Standard annotations
const std::string title () const
 Get the AO title.
 
void setTitle (const std::string &title)
 Set the AO title.
 
const std::string path () const
 Get the AO path.
 
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.
 
virtual size_t dim () const noexcept=0
 Get the dimension of the analysis object type.
 
virtual AnalysisObjectmkInert (const std::string &path="", const std::string &source="") const noexcept
 Return an inert version of the analysis object (e.g. scatter, estimate)
 
MPI serialisation
virtual size_t lengthContent (bool fixed_length=false) const noexcept=0
 Length of serialized content vector for MPI reduce operations.
 
virtual std::vector< double > serializeContent (bool fixed_length=false) const noexcept=0
 Content serialisation for MPI reduce operations.
 
virtual void deserializeContent (const std::vector< double > &data)=0
 Content deserialisation for MPI reduce operations.
 
size_t lengthMeta (const bool skipPath=true, const bool skipTitle=true) const noexcept
 Length of serialized meta-data vector for MPI reduce operations.
 
std::vector< std::string > serializeMeta (const bool skipPath=true, const bool skipTitle=true) const noexcept
 Mate-data serialisation for MPI reduce operations.
 
virtual void deserializeMeta (const std::vector< std::string > &data, const bool resetPath=false, const bool resetTitle=false)
 Mate-data deserialisation for MPI reduce operations.
 

Detailed Description

AnalysisObject is the base class for histograms and scatters.

Definition at line 21 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 26 of file AnalysisObject.h.

Constructor & Destructor Documentation

◆ AnalysisObject() [1/3]

YODA::AnalysisObject::AnalysisObject ( )
inline

Default constructor.

Definition at line 33 of file AnalysisObject.h.

33{ }

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

36 {
37 setAnnotation("Type", type);
40 }
virtual std::string type() const
Get name of the analysis object type.
void setAnnotation(const std::string &name, const T &value)
Add or set an annotation by name (templated for remaining types)
void setPath(const std::string &path)
const std::string title() const
Get the AO title.
void setTitle(const std::string &title)
Set the AO title.
const std::string path() const
Get the AO path.

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

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

44 {
46 setAnnotation("Type", type); // might override the copied ones
49 }
virtual AnalysisObject & operator=(const AnalysisObject &ao) noexcept
Default copy assignment operator.

References operator=(), path(), setAnnotation(), setPath(), setTitle(), title(), and type().

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

195 {
196 setAnnotation(name, value);
197 }
const std::string name() const

References name(), and setAnnotation().

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

122 {
123 Annotations::const_iterator v = _annotations.find(name);
124 // If not found... written this way round on purpose
125 if (v == _annotations.end()) {
126 std::string missing = "YODA::AnalysisObject: No annotation named " + name;
127 throw AnnotationError(missing);
128 }
129 return v->second;
130 }

References name().

Referenced by annotation(), annotation(), deserializeMeta(), YODA::Counter::mkEstimate(), YODA::DbnStorage< DbnN, AxisT >::mkEstimate(), YODA::EstimateStorage< AxisT >::mkEstimates(), YODA::DbnStorage< DbnN, AxisT >::mkHisto(), YODA::DbnStorage< DbnN, AxisT >::mkHistos(), YODA::DbnStorage< DbnN, AxisT >::mkMarginalHisto(), YODA::DbnStorage< DbnN, AxisT >::mkMarginalProfile(), YODA::DbnStorage< DbnN, AxisT >::mkProfiles(), YODA::mkScatter(), YODA::Counter::mkScatter(), YODA::Estimate0D::mkScatter(), YODA::EstimateStorage< AxisT >::mkScatter(), path(), title(), and type().

◆ annotation() [2/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 145 of file AnalysisObject.h.

145 {
146 std::string s = annotation(name);
147 return Utils::lexical_cast<T>(s);
148 }
const std::string & annotation(const std::string &name) const
Get an annotation by name (as a string)

References annotation(), and name().

◆ annotation() [3/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 134 of file AnalysisObject.h.

134 {
135 Annotations::const_iterator v = _annotations.find(name);
136 if (v != _annotations.end()) return v->second;
137 return defaultreturn;
138 }

References name().

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

155 {
156 try {
157 std::string s = annotation(name);
158 return Utils::lexical_cast<T>(s);
159 } catch (const AnnotationError& ae) {
160 return defaultreturn;
161 }
162 }

References annotation(), and name().

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

107 {
108 std::vector<std::string> rtn;
109 rtn.reserve(_annotations.size());
110 for (const Annotations::value_type& kv : _annotations) rtn.push_back(kv.first);
111 return rtn;
112 }

Referenced by YODA::Counter::mkEstimate(), YODA::DbnStorage< DbnN, AxisT >::mkEstimate(), YODA::EstimateStorage< AxisT >::mkEstimates(), YODA::DbnStorage< DbnN, AxisT >::mkHisto(), YODA::DbnStorage< DbnN, AxisT >::mkHistos(), YODA::DbnStorage< DbnN, AxisT >::mkMarginalHisto(), YODA::DbnStorage< DbnN, AxisT >::mkMarginalProfile(), YODA::DbnStorage< DbnN, AxisT >::mkProfiles(), YODA::mkScatter(), YODA::Counter::mkScatter(), YODA::Estimate0D::mkScatter(), and YODA::EstimateStorage< AxisT >::mkScatter().

◆ clearAnnotations()

void YODA::AnalysisObject::clearAnnotations ( )
inline

Delete an annotation by name.

Definition at line 207 of file AnalysisObject.h.

207 {
208 _annotations.clear();
209 }

◆ deserializeContent()

◆ deserializeMeta()

virtual void YODA::AnalysisObject::deserializeMeta ( const std::vector< std::string > &  data,
const bool  resetPath = false,
const bool  resetTitle = false 
)
inlinevirtual

Mate-data deserialisation for MPI reduce operations.

Definition at line 328 of file AnalysisObject.h.

329 {
330
331 if (data.empty()) return;
332 if (data.size() % 2)
333 throw UserError("Expected even number of annotation elements (key-value pairs)!");
334
335 const std::string path = annotation("Path");
336 const std::string type = annotation("Type");
337 const std::string title = annotation("Title");
338 _annotations.clear();
339 _annotations["Type"] = type;
340 if (!resetPath) _annotations["Path"] = path;
341 if (!resetTitle) _annotations["Title"] = title;
342
343 auto itr = data.cbegin();
344 const auto itrEnd = data.cend();
345 while (itr != itrEnd) {
346 const std::string key = *itr; ++itr;
347 const std::string val = *itr; ++itr;
348 _annotations[key] = val;
349 }
350 }

References annotation(), path(), title(), and type().

◆ dim()

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

◆ hasAnnotation()

◆ lengthContent()

◆ lengthMeta()

size_t YODA::AnalysisObject::lengthMeta ( const bool  skipPath = true,
const bool  skipTitle = true 
) const
inlinenoexcept

Length of serialized meta-data vector for MPI reduce operations.

Definition at line 305 of file AnalysisObject.h.

306 {
307 return 2*(_annotations.size() - skipPath - skipTitle);
308 }

◆ mkInert()

virtual AnalysisObject * YODA::AnalysisObject::mkInert ( const std::string &  path = "",
const std::string &  source = "" 
) const
inlinevirtualnoexcept

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

255 {
256 const std::string p = path();
257 const size_t lastslash = p.rfind("/");
258 if (lastslash == std::string::npos) return p;
259 return p.substr(lastslash+1);
260 }

References path().

Referenced by addAnnotation(), annotation(), annotation(), annotation(), hasAnnotation(), rmAnnotation(), and setAnnotation().

◆ newclone()

◆ operator=()

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

Default copy assignment operator.

Definition at line 61 of file AnalysisObject.h.

61 {
62 for (const std::string& a : ao.annotations()) {
63 if (a == "Type") continue;
64 if (a == "Path" && !ao.path().length()) continue;
65 if (a == "Title" && !ao.title().length()) continue;
66 setAnnotation(a, ao.annotation(a));
67 }
68 return *this;
69 }
std::vector< std::string > annotations() const

References setAnnotation().

Referenced by AnalysisObject(), YODA::Counter::operator=(), YODA::DbnStorage< DbnN, AxisT >::operator=(), YODA::Estimate0D::operator=(), YODA::EstimateStorage< AxisT >::operator=(), YODA::ScatterND< N >::operator=(), YODA::Counter::operator=(), YODA::DbnStorage< DbnN, AxisT >::operator=(), YODA::Estimate0D::operator=(), YODA::EstimateStorage< AxisT >::operator=(), and YODA::ScatterND< N >::operator=().

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

233 {
234 const std::string p = annotation("Path", "");
235 // If not set at all, return an empty string
236 if (p.empty()) return p;
237 // If missing a leading slash, one will be prepended
238 return p.find("/") == 0 ? p : ("/"+p);
239 }

References annotation().

Referenced by AnalysisObject(), AnalysisObject(), deserializeMeta(), YODA::divide(), YODA::divide(), YODA::divide(), YODA::divide(), YODA::efficiency(), YODA::Counter::mkEstimate(), YODA::DbnStorage< DbnN, AxisT >::mkEstimate(), YODA::EstimateStorage< AxisT >::mkEstimates(), YODA::DbnStorage< DbnN, AxisT >::mkEstimates(), YODA::DbnStorage< DbnN, AxisT >::mkHisto(), YODA::DbnStorage< DbnN, AxisT >::mkHistos(), mkInert(), YODA::DbnStorage< DbnN, AxisT >::mkInert(), YODA::EstimateStorage< AxisT >::mkInert(), YODA::Counter::mkInert(), YODA::Estimate0D::mkInert(), YODA::DbnStorage< DbnN, AxisT >::mkMarginalHisto(), YODA::DbnStorage< DbnN, AxisT >::mkMarginalProfile(), YODA::DbnStorage< DbnN, AxisT >::mkProfiles(), YODA::Counter::mkScatter(), YODA::Estimate0D::mkScatter(), YODA::DbnStorage< DbnN, AxisT >::mkScatter(), YODA::EstimateStorage< AxisT >::mkScatter(), name(), setPath(), YODA::WriterFLAT::writeAO(), YODA::WriterYODA::writeAO(), YODA::WriterYODA1::writeCounter(), YODA::WriterYODA1::writeHisto1D(), YODA::WriterYODA1::writeHisto2D(), YODA::WriterYODA1::writeProfile1D(), YODA::WriterYODA1::writeProfile2D(), YODA::WriterYODA1::writeScatter1D(), YODA::WriterYODA1::writeScatter2D(), and YODA::WriterYODA1::writeScatter3D().

◆ reset()

◆ rmAnnotation()

◆ serializeContent()

◆ serializeMeta()

std::vector< std::string > YODA::AnalysisObject::serializeMeta ( const bool  skipPath = true,
const bool  skipTitle = true 
) const
inlinenoexcept

Mate-data serialisation for MPI reduce operations.

Definition at line 311 of file AnalysisObject.h.

312 {
313
314 // Assemble annotations
315 std::vector<std::string> rtn;
316 rtn.reserve(2*(_annotations.size() - skipPath - skipTitle));
317 for (const auto& item : _annotations) {
318 if (item.first == "Type") continue;
319 if (skipPath && item.first == "Path") continue;
320 if (skipTitle && item.first == "Title") continue;
321 rtn.push_back(item.first);
322 rtn.push_back(item.second);
323 }
324 return rtn;
325 }

◆ setAnnotation()

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

169 {
170 if constexpr( std::is_floating_point<T>::value ) {
171 // Recipe from Boost docs
172 std::stringstream ss;
173 ss << std::setprecision(std::numeric_limits<double>::max_digits10) << std::scientific << value;
174 setAnnotation(name, ss.str());
175 }
176 else if constexpr( std::is_same<T, std::string>::value ) {
177 _annotations[name] = value;
178 }
179 else {
180 _annotations[name] = Utils::lexical_cast<std::string>(value);
181 }
182 }

References name(), and setAnnotation().

Referenced by addAnnotation(), AnalysisObject(), AnalysisObject(), YODA::Counter::mkEstimate(), YODA::mkScatter(), YODA::Counter::mkScatter(), YODA::Estimate0D::mkScatter(), YODA::EstimateStorage< AxisT >::mkScatter(), operator=(), YODA::EstimateStorage< AxisT >::scale(), YODA::DbnStorage< DbnN, AxisT >::scale(), YODA::DbnStorage< DbnN, AxisT >::scaleW(), YODA::Counter::scaleW(), setAnnotation(), setPath(), and setTitle().

◆ setAnnotations()

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

Set all annotations at once.

Definition at line 186 of file AnalysisObject.h.

186 {
187 _annotations = anns;
188 }

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

244 {
245 const std::string p = (path.find("/") == 0) ? path : "/"+path;
246 // if (path.length() > 0 && path.find("/") != 0) {
247 // throw AnnotationError("Histo paths must start with a slash (/) character.");
248 // }
249 setAnnotation("Path", p);
250 }

References path(), and setAnnotation().

Referenced by AnalysisObject(), AnalysisObject(), YODA::divide(), YODA::divide(), YODA::efficiency(), mkInert(), YODA::EstimateStorage< AxisT >::mkInert(), and YODA::Estimate0D::mkInert().

◆ setTitle()

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

Set the AO title.

Definition at line 225 of file AnalysisObject.h.

225 {
226 setAnnotation("Title", title);
227 }

References setAnnotation(), and title().

Referenced by AnalysisObject(), and AnalysisObject().

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

220 {
221 return annotation("Title", "");
222 }

References annotation().

Referenced by AnalysisObject(), AnalysisObject(), deserializeMeta(), and setTitle().

◆ type()

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

Get name of the analysis object type.

Definition at line 271 of file AnalysisObject.h.

271 {
272 return annotation("Type");
273 }

References annotation().

Referenced by AnalysisObject(), AnalysisObject(), deserializeMeta(), YODA::mkScatter(), YODA::WriterYODA::writeAO(), YODA::WriterYODA1::writeAO(), and YODA::Writer::writeBody().


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