yoda is hosted by Hepforge, IPPP Durham
YODA - Yet more Objects for Data Analysis 2.0.2
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 192 of file AnalysisObject.h.

192 {
193 setAnnotation(name, value);
194 }
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(), 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 Annotations::const_iterator v = _annotations.find(name);
157 if (v != _annotations.end()) return Utils::lexical_cast<T>(v->second);
158 return defaultreturn;
159 }

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

204 {
205 _annotations.clear();
206 }

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

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

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

303 {
304 return 2*(_annotations.size() - skipPath - skipTitle);
305 }

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

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

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

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

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::DbnStorage< DbnN, AxisT >::mkScatter(), YODA::Estimate0D::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 308 of file AnalysisObject.h.

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

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

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

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(), setTitle(), and YODA::zipProfiles().

◆ setAnnotations()

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

Set all annotations at once.

Definition at line 183 of file AnalysisObject.h.

183 {
184 _annotations = anns;
185 }

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

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

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

222 {
223 setAnnotation("Title", title);
224 }

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

217 {
218 return annotation("Title", "");
219 }

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

268 {
269 return annotation("Type");
270 }

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: