Creates a QA (ROOT) object, using properties defined with a tag in config.
nambeBase = "/stations/station0/xy_occupancy;xy_station0" will be decayed into: 1) subdirectory "stations/station0" 2) name of histogram "catrd_hit_xy_occupancy" 3) tag for configuration file "xy_station0" If configuration file or tag are not defined, default parameters will be used
#ifndef CbmQaIO_h
#define CbmQaIO_h 1
#include "Logger.h"
#include "TCanvas.h"
#include "TEfficiency.h"
#include "TH1.h"
#include "TH2.h"
#include "TH3.h"
#include "TObject.h"
#include "TParameter.h"
#include "TProfile.h"
#include "TProfile2D.h"
#include "TProfile3D.h"
#include "TROOT.h"
#include "TString.h"
#include <limits>
#include <optional>
#include <type_traits>
#include <vector>
#include <yaml-cpp/yaml.h>
class TFile;
public:
using ObjList_t = std::vector<std::pair<TObject*, TString>>;
{
};
CbmQaIO(TString prefixName, std::shared_ptr<ObjList_t> pObjList =
nullptr);
template<typename T, typename... Args>
T*
MakeQaObject(TString sName, TString sTitle, Args... args);
protected:
template<typename T>
template<class Config>
{
std::optional<Config> res = std::nullopt;
if (node) {
}
return res;
}
private:
template<typename T, typename... Args>
};
template<typename T>
{
bool bPropertyUndefined = false;
if constexpr (std::is_signed_v<T>) {
bPropertyUndefined = property < 0;
}
else if constexpr (std::is_floating_point_v<T>) {
bPropertyUndefined = std::isnan(property);
}
if (bPropertyUndefined) {
std::stringstream msg;
msg << "Property " << name << " is undefined in the configuration file";
throw std::runtime_error(msg.str());
}
}
template<typename T, typename... Args>
{
if constexpr (std::is_base_of_v<CbmQaTable, T>) {
static_assert(sizeof...(Args) == 3);
}
auto iLastSlashPos = static_cast<int>(sName.Last('/'));
TString sDirectory = TString(sName(0, iLastSlashPos)).Strip(TString::kBoth, '/');
sName = sName(iLastSlashPos + 1, sName.Length() - iLastSlashPos);
T* pObj = new T(sName.Data(), args...);
if constexpr (std::is_base_of_v<TH1, T>) {
pObj->SetDirectory(nullptr);
}
if constexpr (std::is_same_v<TH1F, T> || std::is_same_v<TH1D, T> || std::is_same_v<TProfile, T>) {
}
else if constexpr (std::is_same_v<TH2F, T> || std::is_same_v<TH2D, T>) {
}
else if constexpr (std::is_same_v<TProfile2D, T>) {
}
else if constexpr (std::is_base_of_v<TCanvas, T>) {
auto* pListOfCanvases = gROOT->GetListOfCanvases();
if (-1 != pListOfCanvases->IndexOf(pObj)) {
pListOfCanvases->Remove(pObj);
}
}
if constexpr (std::is_base_of_v<CbmQaTable, T> || std::is_base_of_v<TCanvas, T>) {
sDirectory = TString("Summary/") + sDirectory;
}
}
if (sDirectory.Length() != 0) {
}
else {
}
}
fpvObjList->push_back(std::make_pair(
static_cast<TObject*
>(pObj), sDirectory));
return pObj;
}
template<typename T, typename... Args>
{
if constexpr (std::is_base_of_v<CbmQaTable, T>) {
static_assert(sizeof...(Args) == 2);
}
auto iLastSepPos = static_cast<int>(sName.Last(';'));
TString sTagName = sName(iLastSepPos + 1, sName.Length() - iLastSepPos);
if (iLastSepPos != -1) {
sName = sName(0, iLastSepPos);
}
bool bUseConfig = false;
if constexpr (std::is_base_of_v<TH1, T>) {
bUseConfig = true;
}
}
}
else if constexpr (std::is_base_of_v<TCanvas, T>) {
bUseConfig = true;
}
}
}
}
const char* title = sTitle.Data();
if (bUseConfig) {
if constexpr (std::is_base_of_v<TH1, T>) {
const auto& tagNode =
fConfigNode[
"histograms"][sTagName.Data()];
[[maybe_unused]] int nBinsX = -1;
[[maybe_unused]] double minX = std::numeric_limits<double>::signaling_NaN();
[[maybe_unused]] double maxX = std::numeric_limits<double>::signaling_NaN();
[[maybe_unused]] int nBinsY = -1;
[[maybe_unused]] double minY = std::numeric_limits<double>::signaling_NaN();
[[maybe_unused]] double maxY = std::numeric_limits<double>::signaling_NaN();
[[maybe_unused]] int nBinsZ = -1;
[[maybe_unused]] double minZ = std::numeric_limits<double>::signaling_NaN();
[[maybe_unused]] double maxZ = std::numeric_limits<double>::signaling_NaN();
if (const auto& axisNode = tagNode["x"]) {
nBinsX = axisNode["nbins"].as<int>();
minX = axisNode["min"].as<double>();
maxX = axisNode["max"].as<double>();
}
if (const auto& axisNode = tagNode["y"]) {
nBinsY = axisNode["nbins"].as<int>();
minY = axisNode["min"].as<double>();
maxY = axisNode["max"].as<double>();
}
if (const auto& axisNode = tagNode["z"]) {
nBinsZ = axisNode["nbins"].as<int>();
minZ = axisNode["min"].as<double>();
maxZ = axisNode["max"].as<double>();
}
if constexpr (std::is_base_of_v<CbmQaTable, T>) {
}
else if constexpr (std::is_base_of_v<TProfile2D, T>) {
CheckProperty(nBinsX, Form(
"qa/histograms/%s/x/nbins", sTagName.Data()));
CheckProperty(minX, Form(
"qa/histograms/%s/x/min", sTagName.Data()));
CheckProperty(maxX, Form(
"qa/histograms/%s/x/max", sTagName.Data()));
CheckProperty(nBinsY, Form(
"qa/histograms/%s/y/nbins", sTagName.Data()));
CheckProperty(minY, Form(
"qa/histograms/%s/y/min", sTagName.Data()));
CheckProperty(maxY, Form(
"qa/histograms/%s/y/max", sTagName.Data()));
CheckProperty(minZ, Form(
"qa/histograms/%s/z/min", sTagName.Data()));
CheckProperty(maxZ, Form(
"qa/histograms/%s/z/max", sTagName.Data()));
}
else if constexpr (std::is_base_of_v<TProfile, T>) {
CheckProperty(nBinsX, Form(
"qa/histograms/%s/x/nbins", sTagName.Data()));
CheckProperty(minX, Form(
"qa/histograms/%s/x/min", sTagName.Data()));
CheckProperty(maxX, Form(
"qa/histograms/%s/x/max", sTagName.Data()));
CheckProperty(minY, Form(
"qa/histograms/%s/y/min", sTagName.Data()));
CheckProperty(maxY, Form(
"qa/histograms/%s/y/max", sTagName.Data()));
}
else if constexpr (std::is_base_of_v<TH3, T>) {
CheckProperty(nBinsX, Form(
"qa/histograms/%s/x/nbins", sTagName.Data()));
CheckProperty(minX, Form(
"qa/histograms/%s/x/min", sTagName.Data()));
CheckProperty(maxX, Form(
"qa/histograms/%s/x/max", sTagName.Data()));
CheckProperty(nBinsY, Form(
"qa/histograms/%s/y/nbins", sTagName.Data()));
CheckProperty(minY, Form(
"qa/histograms/%s/y/min", sTagName.Data()));
CheckProperty(maxY, Form(
"qa/histograms/%s/y/max", sTagName.Data()));
CheckProperty(nBinsZ, Form(
"qa/histograms/%s/z/nbins", sTagName.Data()));
CheckProperty(minZ, Form(
"qa/histograms/%s/z/min", sTagName.Data()));
CheckProperty(maxZ, Form(
"qa/histograms/%s/z/max", sTagName.Data()));
return ConstructAndRegisterQaObject<T>(sName, title, nBinsX, minX, maxX, nBinsY, minY, maxY, nBinsZ, minZ,
maxZ);
}
else if constexpr (std::is_base_of_v<TH2, T>) {
CheckProperty(nBinsX, Form(
"qa/histograms/%s/x/nbins", sTagName.Data()));
CheckProperty(minX, Form(
"qa/histograms/%s/x/min", sTagName.Data()));
CheckProperty(maxX, Form(
"qa/histograms/%s/x/max", sTagName.Data()));
CheckProperty(nBinsY, Form(
"qa/histograms/%s/y/nbins", sTagName.Data()));
CheckProperty(minY, Form(
"qa/histograms/%s/y/min", sTagName.Data()));
CheckProperty(maxY, Form(
"qa/histograms/%s/y/max", sTagName.Data()));
}
else if constexpr (std::is_base_of_v<TH1, T>) {
CheckProperty(nBinsX, Form(
"qa/histograms/%s/x/nbins", sTagName.Data()));
CheckProperty(minX, Form(
"qa/histograms/%s/x/min", sTagName.Data()));
CheckProperty(maxX, Form(
"qa/histograms/%s/x/max", sTagName.Data()));
}
}
}
}
#endif
Definition of the CbmQaCanvas class.
Declaration of CbmQaEff class.
Definition of CbmQaTable class.
ROOT object IO interface for QA.
CbmQaIO & operator=(const CbmQaIO &)=delete
Copy assignment operator.
T * MakeQaObject(TString sName, TString sTitle, Args... args)
virtual void SetTProfile2DProperties(TProfile2D *pHist) const
Applies properties on the profile 2D created with the MakeQaObject function.
virtual void SetCanvasProperties(TCanvas *pCanv) const
Applies properties on the canvas created with the MakeQaObject funciton.
void SetConfigName(const char *path)
Creates a ROOT object.
void WriteToFile(TFile *pOutFile) const
Writes objects into file.
YAML::Node fConfigNode
Configuration node.
void MakeQaDirectory(TString sName)
virtual void SetTH2Properties(TH2 *pHist) const
Applies properties on the histogram created with the MakeQaObject function.
std::optional< Config > ReadSpecificConfig() const
Reads the specific configuration structure from the YAML node.
virtual ~CbmQaIO()
Destructor.
TString fsPrefix
Unique prefix for all writeable root.
void SetStoringMode(EStoringMode mode)
Set storing mode.
const char * GetConfigName() const
Gets config name.
virtual void SetTH1Properties(TH1 *pHist) const
Applies properties on the histogram created with the MakeQaObject function.
std::shared_ptr< ObjList_t > fpvObjList
List of registered ROOT objects.
CbmQaIO(TString prefixName, std::shared_ptr< ObjList_t > pObjList=nullptr)
Constructor.
TString fsRootFolderName
Name of root folder.
@ kSUBDIR
Objects of different type will be stored in different subdirectories like histograms/ canvases/.
@ kSAMEDIR
Objects of different type will be stored to root directory.
void SetRootFolderName(const TString &path)
Sets a common root path to the objects in the output file.
EStoringMode fStoringMode
Objects storing mode.
void CheckProperty(T &&property, const char *name) const
Function to check, if a property is defined.
T * ConstructAndRegisterQaObject(TString name, Args... args)
Creates and registers a ROOT object.
TString fsConfigName
Name of configuration file.
std::vector< std::pair< TObject *, TString > > ObjList_t
T Read(const YAML::Node &node)