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
Branches
Tags
1 merge request!1212Add services main folder + histogram server binary w/o FairMQ + tester binary example
......@@ -18,8 +18,10 @@ namespace cbm::algo
{
// ----- 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)
, fTitle(title)
, fNumBins(numBins)
, fMinValue(minValue)
, fMaxValue(maxValue)
......@@ -56,7 +58,7 @@ namespace cbm::algo
// ----- Content access
double Histo1D::Content(uint32_t bin) const
{
if (bin >= fNumBins) return 0.;
if (fNumBins < bin) return 0.;
else
return fContent[bin];
}
......@@ -115,7 +117,8 @@ namespace cbm::algo
{
std::stringstream ss;
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();
}
......
......@@ -5,6 +5,9 @@
#ifndef ALGO_QA_HISTO1D_H
#define ALGO_QA_HISTO1D_H 1
#include <boost/serialization/access.hpp>
#include <boost/serialization/version.hpp>
#include <cstdint>
#include <string>
#include <vector>
......@@ -21,17 +24,19 @@ namespace cbm::algo
**/
class Histo1D {
public:
/** @brief No default constructor **/
Histo1D() = delete;
/** @brief Standard constructor
** @param numBins Number of bins
** @param minValue Lower edge of histogram range
** @param maxValue Upper edge of histogram range
** @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 **/
......@@ -76,6 +81,10 @@ namespace cbm::algo
const std::string& Name() const { return fName; }
/** @brief Histogram name **/
const std::string& Title() const { return fTitle; }
/** @brief Number of bins **/
uint32_t NumBins() const { return fNumBins; }
......@@ -89,6 +98,10 @@ namespace cbm::algo
double Overflow() const { return fOverflow; }
/** @brief Underflow **/
double Underflow() const { return fUnderflow; }
/** @brief Second moment of distribution **/
double Stddev() const;
......@@ -97,22 +110,37 @@ namespace cbm::algo
std::string ToString() const;
/** @brief Underflow **/
double UnderFlow() const { return fUnderflow; }
private:
/** Properties **/
const std::string fName;
const uint32_t fNumBins;
const double fMinValue;
const double fMaxValue;
/** Properties (no need for const if no accessors, avoid really complicated boost serialization) **/
std::string fName;
std::string fTitle;
uint32_t fNumBins;
double fMinValue;
double fMaxValue;
/** Content **/
std::vector<double> fContent = {};
double fUnderflow = 0;
double fOverflow = 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
} /* namespace cbm::algo */
BOOST_CLASS_VERSION(cbm::algo::Histo1D, 1)
#endif /* ALGO_QA_HISTO1D_H */
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment