13#include "TDirectory.h"
22#include <yaml-cpp/yaml.h>
55 std::string res =
fvFiles[iFile];
56 res = std::regex_replace(res, std::regex(
"\\%v"),
fvVersionPaths[iVersion]);
57 res = std::regex_replace(res, std::regex(
"\\%d"),
fvDatasets[iDataset]);
67 LOG_IF(fatal, !
GetNofObjects()) <<
"ObjectDB: No objects were passed to the checker";
68 LOG_IF(fatal,
GetNofDatasets() < 1) <<
"ObjectDB: No datasets were found, at least one dataset should be provided";
69 LOG_IF(fatal,
GetNofVersions() < 2) <<
"ObjectDB: File handler should have at least two versions to compare ("
82 std::stringstream msg;
83 msg <<
"ObjectDB: registered default label \"" <<
fsDefaultLabel <<
"\" is not found among the version labels:\n";
85 msg <<
"\t- " << label <<
'\n';
87 LOG(fatal) << msg.str();
93 LOG(warn) <<
"ObjectDB: default version was not registered. Using the first version as the default one (\""
101 for (
size_t iFile = 0; iFile <
fvObjects.size(); ++iFile) {
112 for (
size_t iFile = 1; iFile <=
fvObjects.size(); ++iFile) {
117 auto regexSlashes = std::regex(
"(/+)");
122 path = std::regex_replace(path, regexSlashes,
"/");
133 config = YAML::LoadFile(configName)[
"checker"];
135 catch (
const YAML::BadFile& exc) {
136 LOG(fatal) <<
"ObjectDB: configuration file " << configName <<
" does not exist";
138 catch (
const YAML::ParserException& exc) {
139 LOG(fatal) <<
"ObjectDB: configuration file " << configName <<
" is badly formatted";
142 std::unordered_map<std::string, uint32_t> mParIndexMap;
145 if (
const auto& settingsNode = config[
"settings"]) {
146 for (
const auto& paramEntry : settingsNode) {
148 const std::string label = paramEntry.first.as<std::string>();
149 const auto& node = paramEntry.second;
154 params.
compMethod = node[
"comp_method"].as<std::string>(
"E");
161 if (
const auto& node = config[
"files"]) {
163 LOG(warn) <<
"ObjectDB: file-object map was defined before. Redefining it from the config file " << configName;
170 size_t nFiles = node.size();
176 for (
const auto& fileNode : node) {
177 const auto& objectsNode = fileNode[
"objects"];
178 int nObjects = objectsNode ? objectsNode.size() : 0;
179 std::vector<std::pair<std::string, uint32_t>> objectsInFile;
182 for (
const auto& objectNode : objectsNode) {
184 std::string name = objectNode[
"name"].as<std::string>();
186 if (
auto parLabelNode = objectNode[
"setting"]) {
187 auto parKey = parLabelNode.as<std::string>();
188 auto keyIdIt = mParIndexMap.find(parKey);
189 if (keyIdIt != mParIndexMap.end()) {
190 parId = keyIdIt->second;
193 std::stringstream msg;
194 msg <<
"Error: object '" << name <<
"' uses undefined setting '" << parKey <<
"'";
195 throw std::runtime_error(msg.str());
198 objectsInFile.emplace_back(name, parId);
201 fvFiles.push_back(fileNode[
"name"].as<std::string>());
202 fvFileLabels.push_back(fileNode[
"label"].as<std::string>());
203 fvObjects.push_back(std::move(objectsInFile));
206 catch (
const YAML::InvalidNode& exc) {
207 LOG(fatal) <<
"ObjectDB: error while reading checker/files node from the config " << configName;
211 LOG(warn) <<
"ObjectDB: node checker/inputformat is not defined in the config " << configName;
215 if (
const auto& node = config[
"datasets"]) {
217 <<
"ObjectDB: dataset names were defined before. Please, use only one initialisation method:"
218 <<
" either configuration file, or setters of the checker::Core class";
221 for (
const auto& datasetNode : node) {
222 fvDatasets.push_back(datasetNode.as<std::string>());
225 catch (
const YAML::InvalidNode& exc) {
226 LOG(fatal) <<
"ObjectDB:: error while reading checker/datasets node from the config " << configName;
230 LOG(warn) <<
"ObjectDB: node checker/datasets is not defined in the config " << configName;
234 if (
const auto& node = config[
"versions"]) {
236 <<
"ObjectDB: dataset names were defined before. Attempt to redefine dataset names from config " << configName;
240 for (
const auto& versionNode : node) {
245 catch (
const YAML::InvalidNode& exc) {
246 LOG(fatal) <<
"ObjectDB:: error while reading checker/versions node from the config " << configName;
250 LOG(warn) <<
"ObjectDB: node checker/versions is not defined in the config " << configName;
254 if (
const auto& node = config[
"default_label"]) {
258 catch (
const YAML::InvalidNode& exc) {
259 LOG(fatal) <<
"ObjectDB:: error while reading checker/default_label node from the config " << configName;
270 for (
auto&& pKey : *(pDir->GetListOfKeys())) {
271 TString sName = parentPath + pKey->GetName();
272 if (gFile->Get<TH1>(sName)) {
273 paths.insert(sName.Data());
275 else if (
auto* pSubDir = gFile->Get<TDirectory>(sName)) {
287 std::set<std::string> objectPaths;
288 LOG(info) <<
"Reading object list from files: ...";
290 for (
int iDs = 0; iDs < static_cast<int>(
fvDatasets.size()); ++iDs) {
292 LOG(info) <<
"- file: " << fileName;
293 TFile fileIn{fileName,
"READONLY"};
300 std::vector<std::pair<std::string, uint32_t>> objectsInFile;
301 objectsInFile.reserve(objectPaths.size());
303 for (
const auto& path : objectPaths) {
304 objectsInFile.emplace_back(path, 0);
308 fvObjects[iFile] = std::move(objectsInFile);
310 LOG(info) <<
"Reading object list from files: done";
318 if (pVal <= 0 || pVal >= 1) {
319 LOG(fatal) <<
"ObjectDB::SetPvalThreshold(): p-value threshold runs out the range (0, 1): " << pVal;
329 LOG(fatal) <<
"ObjectDB::SetPvalThreshold(): min and max for ratio run out the range: min = " <<
min
330 <<
", max = " <<
max;
341 std::stringstream msg;
344 msg <<
" ********************\n";
345 msg <<
" ** CBM QA-Checker **\n";
346 msg <<
" ********************\n\n";
348 msg <<
"\e[1mVersions\e[0m:\n";
358 msg <<
"\e[1mDatasets\e[0m:\n";
360 msg <<
"\t- " << dataset <<
"\n";
363 msg <<
"\e[1mFiles\e[0m:\n";
364 for (
size_t iF = 0; iF <
fvFiles.size(); ++iF) {
367 msg <<
" with objects:\n";
368 for (
const auto&
object :
fvObjects[iF]) {
369 msg <<
"\t\t- " <<
object.first <<
" (param: " <<
object.second <<
")\n";
Database for processed objects in the QA checker framework (implementation)
friend fscal max(fscal x, fscal y)
friend fscal min(fscal x, fscal y)
static constexpr size_t size()
void Clear()
Clears content.
A data base class for processed objects.
std::vector< std::string > fvFileLabels
Container of file labels (used in output)
int GetNofObjects() const
Gets total number of objects.
void ReadObjectList(int iFile)
Reads list of histograms from file.
std::string ToString(int verbose=1) const
String representation of the content.
static void CollectObjectPaths(TDirectory *pDir, const TString &parentPah, std::set< std::string > &paths)
Loops over ROOT-file and collects object paths.
std::string GetInputFileName(int iVersion, int iFile, int iDataset) const
Gets name of file from indexes of version, file and dataset.
std::vector< int > fvObjectFirstGlobIndex
First global index of object in a file.
std::vector< std::string > fvVersionPaths
Container of version paths.
void AddDataset(const char *dataset)
Adds dataset.
int GetNofDatasets() const
Gets number of datasets.
std::vector< ObjectParameters > fvObjectParameters
Container of object parameters.
std::string fsInputRootPath
Root path for input files.
void SetPvalThreshold(double pVal)
Sets P-value threshold.
void SetRatioRange(double min, double max)
Sets ratio accepted range.
std::vector< std::string > fvDatasets
Container of dataset names.
int GetNofVersions() const
Gets number of versions.
std::vector< std::string > fvFiles
Container of file names.
void AddVersion(const char *label, const char *path)
Adds version.
std::vector< std::string > fvVersionLabels
Container of version labels.
double fRatioMin
Lower boundary for ratio deviation.
void SetDefaultLabel(const char *defaultLabel)
Sets default version label.
double fPvalThresh
P-value threshold for histograms equality.
double fRatioMax
Upper boundary for ratio deviation.
void ReadFromYAML(const char *configName)
Reads DB from YAML node.
int fDefVersionID
Index of default version.
void Init()
Initializes the database.
std::string fsDefaultLabel
Name of default version label.
std::vector< std::vector< std::pair< std::string, uint32_t > > > fvObjects
Container of object names and corresponding parameter IDs in fvObjectParameters.
std::string fsOutputPath
Path to the output file.