Skip to content

Commit 7386f31

Browse files
author
Ionut Cristian Arsene
committed
added posibility to define multiple histogram classes for JSON histograms; the histClass field is now a vector of strings
1 parent 17131ce commit 7386f31

File tree

1 file changed

+39
-15
lines changed

1 file changed

+39
-15
lines changed

PWGDQ/Core/HistogramsLibrary.cxx

Lines changed: 39 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2008,6 +2008,18 @@ bool o2::aod::dqhistograms::ValidateJSONHistogram(T hist)
20082008
return false;
20092009
}
20102010

2011+
// check that the histClass field is an array of strings
2012+
if (!hist->FindMember("histClass")->value.IsArray()) {
2013+
LOG(fatal) << "histClass field should be an array of strings, e.g. ["class1", "class2"]";
2014+
return false;
2015+
}
2016+
for (auto& v : hist->FindMember("histClass")->value.GetArray()) {
2017+
if (!v.IsString()) {
2018+
LOG(fatal) << "histClass field should be an array of strings, e.g. ["class1", "class2"]";
2019+
return false;
2020+
}
2021+
}
2022+
20112023
TString histTypeStr = hist->FindMember("type")->value.GetString();
20122024
bool isTH1 = (histTypeStr.CompareTo("TH1") == 0);
20132025
bool isTH2 = (histTypeStr.CompareTo("TH2") == 0);
@@ -2218,7 +2230,11 @@ void o2::aod::dqhistograms::AddHistogramsFromJSON(HistogramManager* hm, const ch
22182230
isConstantBinning = false;
22192231
}
22202232

2221-
const char* histClass = hist.FindMember("histClass")->value.GetString();
2233+
// create an array of strings to store the different histogram classes
2234+
std::vector<const char*> histClasses;
2235+
for (auto& v : hist.FindMember("histClass")->value.GetArray()) {
2236+
histClasses.push_back(v.GetString());
2237+
}
22222238
const char* title = hist.FindMember("title")->value.GetString();
22232239

22242240
if (isTHn) {
@@ -2282,9 +2298,13 @@ void o2::aod::dqhistograms::AddHistogramsFromJSON(HistogramManager* hm, const ch
22822298
bool isDouble = (hist.HasMember("isDouble") ? hist.FindMember("isDouble")->value.GetBool() : false);
22832299

22842300
if (isConstantBinning) {
2285-
hm->AddHistogram(histClass, histName, title, nDimensions, vars, nBins, xmin, xmax, axLabels, varW, useSparse, isDouble);
2301+
for (auto histClass : histClasses) {
2302+
hm->AddHistogram(histClass, histName, title, nDimensions, vars, nBins, xmin, xmax, axLabels, varW, useSparse, isDouble);
2303+
}
22862304
} else {
2287-
hm->AddHistogram(histClass, histName, title, nDimensions, vars, binLimits, axLabels, varW, useSparse, isDouble);
2305+
for (auto histClass : histClasses) {
2306+
hm->AddHistogram(histClass, histName, title, nDimensions, vars, binLimits, axLabels, varW, useSparse, isDouble);
2307+
}
22882308
}
22892309

22902310
} else { // TH1, TH2 or TH3
@@ -2379,12 +2399,14 @@ void o2::aod::dqhistograms::AddHistogramsFromJSON(HistogramManager* hm, const ch
23792399
LOG(debug) << "isFillLabelx: " << isFillLabelx;
23802400

23812401
if (isConstantBinning) {
2382-
hm->AddHistogram(histClass, histName, title, isProfile,
2383-
nXbins, xmin, xmax, VarManager::fgVarNamesMap[varX],
2384-
nYbins, ymin, ymax, VarManager::fgVarNamesMap[varY],
2385-
nZbins, zmin, zmax, VarManager::fgVarNamesMap[varZ],
2386-
xLabels, yLabels, zLabels,
2387-
VarManager::fgVarNamesMap[varT], VarManager::fgVarNamesMap[varW], isdouble, isFillLabelx);
2402+
for (auto histClass : histClasses) {
2403+
hm->AddHistogram(histClass, histName, title, isProfile,
2404+
nXbins, xmin, xmax, VarManager::fgVarNamesMap[varX],
2405+
nYbins, ymin, ymax, VarManager::fgVarNamesMap[varY],
2406+
nZbins, zmin, zmax, VarManager::fgVarNamesMap[varZ],
2407+
xLabels, yLabels, zLabels,
2408+
VarManager::fgVarNamesMap[varT], VarManager::fgVarNamesMap[varW], isdouble, isFillLabelx);
2409+
}
23882410
} else {
23892411
int xBinsSize = xbinsVec.size();
23902412
if (xBinsSize != (nXbins + 1)) {
@@ -2413,12 +2435,14 @@ void o2::aod::dqhistograms::AddHistogramsFromJSON(HistogramManager* hm, const ch
24132435
zbins = new double[zbinsVec.size()];
24142436
std::copy(zbinsVec.begin(), zbinsVec.end(), zbins);
24152437
}
2416-
hm->AddHistogram(histClass, histName, title, isProfile,
2417-
nXbins, xbins, VarManager::fgVarNamesMap[varX],
2418-
nYbins, ybins, VarManager::fgVarNamesMap[varY],
2419-
nZbins, zbins, VarManager::fgVarNamesMap[varZ],
2420-
xLabels, yLabels, zLabels,
2421-
VarManager::fgVarNamesMap[varT], VarManager::fgVarNamesMap[varW], isdouble, isFillLabelx);
2438+
for (auto histClass : histClasses) {
2439+
hm->AddHistogram(histClass, histName, title, isProfile,
2440+
nXbins, xbins, VarManager::fgVarNamesMap[varX],
2441+
nYbins, ybins, VarManager::fgVarNamesMap[varY],
2442+
nZbins, zbins, VarManager::fgVarNamesMap[varZ],
2443+
xLabels, yLabels, zLabels,
2444+
VarManager::fgVarNamesMap[varT], VarManager::fgVarNamesMap[varW], isdouble, isFillLabelx);
2445+
}
24222446
} // end if (!isTHn)
24232447
}
24242448
}

0 commit comments

Comments
 (0)