Skip to content
Snippets Groups Projects
Commit a0a2da48 authored by Pierre-Alain Loizeau's avatar Pierre-Alain Loizeau Committed by Volker Friese
Browse files

[Algo] Add boost serialization (in. std vect) to Histo1D + related fixes

- Also fix boundary bug in Histo1D content access
parent a182a361
No related branches found
No related tags found
1 merge request!1212Add services main folder + histogram server binary w/o FairMQ + tester binary example
...@@ -18,8 +18,10 @@ namespace cbm::algo ...@@ -18,8 +18,10 @@ namespace cbm::algo
{ {
// ----- Standard constructor // ----- Standard constructor
Histo1D::Histo1D(uint32_t numBins, double minValue, double maxValue, const std::string& name) Histo1D::Histo1D(uint32_t numBins, double minValue, double maxValue, const std::string& name,
const std::string& title)
: fName(name) : fName(name)
, fTitle(title)
, fNumBins(numBins) , fNumBins(numBins)
, fMinValue(minValue) , fMinValue(minValue)
, fMaxValue(maxValue) , fMaxValue(maxValue)
...@@ -56,7 +58,7 @@ namespace cbm::algo ...@@ -56,7 +58,7 @@ namespace cbm::algo
// ----- Content access // ----- Content access
double Histo1D::Content(uint32_t bin) const double Histo1D::Content(uint32_t bin) const
{ {
if (bin >= fNumBins) return 0.; if (fNumBins < bin) return 0.;
else else
return fContent[bin]; return fContent[bin];
} }
...@@ -115,7 +117,8 @@ namespace cbm::algo ...@@ -115,7 +117,8 @@ namespace cbm::algo
{ {
std::stringstream ss; std::stringstream ss;
ss << fName << ": bins " << fNumBins << " range " << fMinValue << " to " << fMaxValue << " entries " << fNumEntries ss << fName << ": bins " << fNumBins << " range " << fMinValue << " to " << fMaxValue << " entries " << fNumEntries
<< " mean " << Mean() << " stddev " << Stddev() << " out of range " << fUnderflow << " , " << fOverflow; << " mean " << Mean() << " stddev " << Stddev() << " out of range " << fUnderflow << " , " << fOverflow
<< " title <" << fTitle << ">";
return ss.str(); return ss.str();
} }
......
...@@ -5,6 +5,9 @@ ...@@ -5,6 +5,9 @@
#ifndef ALGO_QA_HISTO1D_H #ifndef ALGO_QA_HISTO1D_H
#define ALGO_QA_HISTO1D_H 1 #define ALGO_QA_HISTO1D_H 1
#include <boost/serialization/access.hpp>
#include <boost/serialization/version.hpp>
#include <cstdint> #include <cstdint>
#include <string> #include <string>
#include <vector> #include <vector>
...@@ -21,17 +24,19 @@ namespace cbm::algo ...@@ -21,17 +24,19 @@ namespace cbm::algo
**/ **/
class Histo1D { class Histo1D {
public: public:
/** @brief No default constructor **/
Histo1D() = delete;
/** @brief Standard constructor /** @brief Standard constructor
** @param numBins Number of bins ** @param numBins Number of bins
** @param minValue Lower edge of histogram range ** @param minValue Lower edge of histogram range
** @param maxValue Upper edge of histogram range ** @param maxValue Upper edge of histogram range
** @param name Histogram name ** @param name Histogram name
** @param title ROOT convention: Histogram title; Axis X title; Axis Y title
**/ **/
Histo1D(uint32_t numBins, double minValue, double maxValue, const std::string& name = ""); Histo1D(uint32_t numBins, double minValue, double maxValue, const std::string& name = "",
const std::string& title = "");
/** @brief Copy constructor: needed for boost serialization of vector of Histo1D **/
Histo1D(const Histo1D&) = default;
/** @brief Destructor **/ /** @brief Destructor **/
...@@ -76,6 +81,10 @@ namespace cbm::algo ...@@ -76,6 +81,10 @@ namespace cbm::algo
const std::string& Name() const { return fName; } const std::string& Name() const { return fName; }
/** @brief Histogram name **/
const std::string& Title() const { return fTitle; }
/** @brief Number of bins **/ /** @brief Number of bins **/
uint32_t NumBins() const { return fNumBins; } uint32_t NumBins() const { return fNumBins; }
...@@ -89,6 +98,10 @@ namespace cbm::algo ...@@ -89,6 +98,10 @@ namespace cbm::algo
double Overflow() const { return fOverflow; } double Overflow() const { return fOverflow; }
/** @brief Underflow **/
double Underflow() const { return fUnderflow; }
/** @brief Second moment of distribution **/ /** @brief Second moment of distribution **/
double Stddev() const; double Stddev() const;
...@@ -97,22 +110,37 @@ namespace cbm::algo ...@@ -97,22 +110,37 @@ namespace cbm::algo
std::string ToString() const; std::string ToString() const;
/** @brief Underflow **/
double UnderFlow() const { return fUnderflow; }
private: private:
/** Properties **/ /** Properties (no need for const if no accessors, avoid really complicated boost serialization) **/
const std::string fName; std::string fName;
const uint32_t fNumBins; std::string fTitle;
const double fMinValue; uint32_t fNumBins;
const double fMaxValue; double fMinValue;
double fMaxValue;
/** Content **/ /** Content **/
std::vector<double> fContent = {}; std::vector<double> fContent = {};
double fUnderflow = 0; double fUnderflow = 0;
double fOverflow = 0; double fOverflow = 0;
size_t fNumEntries = 0; size_t fNumEntries = 0;
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive& ar, const unsigned int /*version*/)
{
ar& fName;
ar& fTitle;
ar& fNumBins;
ar& fMinValue;
ar& fMaxValue;
ar& fContent;
ar& fUnderflow;
ar& fOverflow;
ar& fNumEntries;
}
/** @brief Default constructor: needed for boost serialization of vector of Histo1D, need copy ctor call after! **/
Histo1D() : fName(""), fTitle(""), fNumBins(0), fMinValue(0), fMaxValue(0) {};
}; };
...@@ -128,4 +156,6 @@ namespace cbm::algo ...@@ -128,4 +156,6 @@ namespace cbm::algo
} /* namespace cbm::algo */ } /* namespace cbm::algo */
BOOST_CLASS_VERSION(cbm::algo::Histo1D, 1)
#endif /* ALGO_QA_HISTO1D_H */ #endif /* ALGO_QA_HISTO1D_H */
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment