Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Framework: slice labels in 1D slice trending #2155

Merged
merged 1 commit into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Framework/include/QualityControl/SliceTrendingTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class SliceTrendingTask : public PostProcessingInterface
void trendValues(const Trigger& t, o2::quality_control::repository::DatabaseInterface&);
void generatePlots();
void drawCanvasMO(TCanvas* thisCanvas, const std::string& var,
const std::string& name, const std::string& opt, const std::string& err, const std::vector<std::vector<float>>& axis, const TitleSettings& titlesettings);
const std::string& name, const std::string& opt, const std::string& err, const std::vector<std::vector<float>>& axis, const std::vector<std::vector<std::string>>& sliceLabels, const TitleSettings& titlesettings);
void getUserAxisRange(const std::string& graphAxisRange, float& limitLow, float& limitUp);
void setUserAxisLabel(TAxis* xAxis, TAxis* yAxis, const std::string& graphAxisLabel);
void getTrendVariables(const std::string& inputvar, std::string& sourceName, std::string& variableName, std::string& trend);
Expand All @@ -102,6 +102,7 @@ class SliceTrendingTask : public PostProcessingInterface
std::unordered_map<std::string, std::vector<SliceInfo>*> mSources;
std::unordered_map<std::string, int> mNumberPads;
std::unordered_map<std::string, std::vector<std::vector<float>>> mAxisDivision;
std::unordered_map<std::string, std::vector<std::vector<std::string>>> mSliceLabel;
};

} // namespace o2::quality_control::postprocessing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ struct SliceTrendingTaskConfig : PostProcessingConfig {
std::string name;
std::string reductorName;
std::vector<std::vector<float>> axisDivision;
std::vector<std::vector<std::string>> sliceLabels;
std::string moduleName;
};

Expand Down
4 changes: 3 additions & 1 deletion Framework/postprocessing.json
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@
"names": [ "example" ],
"reductorName": "o2::quality_control_modules::common::TH1SliceReductor",
"axisDivision": [ [ "0", "4500", "10500" ] ],
"sliceLabels": [ [ "Slice 1", "Slice 2" ] ],
"moduleName": "QcCommon"
}
],
Expand Down Expand Up @@ -185,7 +186,8 @@
"graphErrors": "errMeanY:0.5",
"graphYRange": "",
"graphXRange": "",
"graphAxisLabel": "Mean Y:time"
"graphAxisLabel": "Mean Y:time",
"legendTextSize": "10.0"
},
{
"name": "ExtendedTrending_NEntries_of_histogram",
Expand Down
32 changes: 27 additions & 5 deletions Framework/src/SliceTrendingTask.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ void SliceTrendingTask::trendValues(const Trigger& t,
TObject* obj = mo ? mo->getObject() : nullptr;

mAxisDivision[dataSource.name] = dataSource.axisDivision;
mSliceLabel[dataSource.name] = dataSource.sliceLabels;

if (obj) {
mReductors[dataSource.name]->update(obj, *mSources[dataSource.name],
Expand Down Expand Up @@ -183,7 +184,7 @@ void SliceTrendingTask::generatePlots()
c->SetTitle(plot.title.c_str());

TitleSettings titlesettings{ plot.legendObservableX, plot.legendObservableY, plot.legendUnitX, plot.legendUnitY, plot.legendCentmodeX, plot.legendCentmodeY };
drawCanvasMO(c, plot.varexp, plot.name, plot.option, plot.graphErrors, mAxisDivision[varName], titlesettings);
drawCanvasMO(c, plot.varexp, plot.name, plot.option, plot.graphErrors, mAxisDivision[varName], mSliceLabel[varName], titlesettings);

int NumberPlots = 1;
if (plot.varexp.find(":time") != std::string::npos || plot.varexp.find(":run") != std::string::npos) { // we plot vs time, multiple plots on canvas possible
Expand Down Expand Up @@ -245,7 +246,7 @@ void SliceTrendingTask::generatePlots()
} // void SliceTrendingTask::generatePlots()

void SliceTrendingTask::drawCanvasMO(TCanvas* thisCanvas, const std::string& var,
const std::string& name, const std::string& opt, const std::string& err, const std::vector<std::vector<float>>& axis, const TitleSettings& titlesettings)
const std::string& name, const std::string& opt, const std::string& err, const std::vector<std::vector<float>>& axis, const std::vector<std::vector<std::string>>& sliceLabels, const TitleSettings& titlesettings)
{
// Determine the order of the plot (1 - histo, 2 - graph, ...)
const size_t plotOrder = std::count(var.begin(), var.end(), ':') + 1;
Expand Down Expand Up @@ -282,6 +283,15 @@ void SliceTrendingTask::drawCanvasMO(TCanvas* thisCanvas, const std::string& var
const int nEntriesRuns = mTrend->GetBranch("meta")->GetEntries();
const int nEntriesData = mTrend->GetBranch(varName.data())->GetEntries();

bool useSliceLabels = false;
if (axis.size() == 1 && sliceLabels.size() == 1) { // currently we use custom labels only in the 1D case
if (axis[0].size() - 1 != sliceLabels[0].size() && sliceLabels[0].size() > 0) {
ILOG(Warning, Support) << "Slicing of 1D Objects: Labels do not match number of slices, using ranges as slice names" << ENDM;
} else {
useSliceLabels = true;
}
}

// Fill the graph(errors) to be published.
if (trendType == "time" || trendType == "run") {

Expand Down Expand Up @@ -310,7 +320,13 @@ void SliceTrendingTask::drawCanvasMO(TCanvas* thisCanvas, const std::string& var

iEntry++;
}
graphErrors->SetTitle((dataRetrieveVector->at(p)).title.data());

if (!useSliceLabels) {
graphErrors->SetTitle((dataRetrieveVector->at(p)).title.data());
} else {
graphErrors->SetTitle(sliceLabels[0][p].data());
}

myReader.Restart();

if (!err.empty()) {
Expand Down Expand Up @@ -352,7 +368,8 @@ void SliceTrendingTask::drawCanvasMO(TCanvas* thisCanvas, const std::string& var
iEntry++;
}

const std::string_view title = (dataRetrieveVector->at(p)).title;
const std::string_view title = useSliceLabels ? sliceLabels[0][p] : (dataRetrieveVector->at(p)).title;
// const std::string_view title = (dataRetrieveVector->at(p)).title;
const auto posDivider = title.find("RangeX");
if (posDivider != std::string_view::npos) {
auto rawtitle = title.substr(posDivider, -1);
Expand Down Expand Up @@ -608,7 +625,7 @@ std::string SliceTrendingTask::beautifyTitle(const std::string_view rawtitle, co
std::string beautified;
int indexrangeX = rawtitle.find("RangeX"),
indexrangeY = rawtitle.find("RangeY");
if (settings.observableX != "None" && indexrangeY != std::string::npos) {
if (settings.observableX != "None" && indexrangeX != std::string::npos) {
auto rangestring = rawtitle.substr(indexrangeX);
rangestring = rangestring.substr(0, rangestring.find("]") + 1);
if (!settings.observableX.length()) {
Expand All @@ -631,5 +648,10 @@ std::string SliceTrendingTask::beautifyTitle(const std::string_view rawtitle, co
beautified += " " + rangehandler(rangestring, settings.observableY, settings.unitY, centmode);
}
}

if (beautified == "") {
beautified = rawtitle;
}

return beautified;
}
16 changes: 16 additions & 0 deletions Framework/src/SliceTrendingTaskConfig.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ SliceTrendingTaskConfig::SliceTrendingTaskConfig(const std::string& id,
std::vector<std::vector<float>> axisBoundaries;
std::vector<float> singleAxis;

std::vector<std::vector<std::string>> sliceLabels;
std::vector<std::string> singleAxisLabels;

if (const auto& multiAxisValues = dataSourceConfig.second.get_child_optional("axisDivision"); multiAxisValues.has_value()) {
for (const auto& multiAxisValue : multiAxisValues.value()) {
for (const auto& axis : multiAxisValue.second) {
Expand All @@ -64,6 +67,16 @@ SliceTrendingTaskConfig::SliceTrendingTaskConfig(const std::string& id,
}
}

if (const auto& multiAxisLabels = dataSourceConfig.second.get_child_optional("sliceLabels"); multiAxisLabels.has_value()) {
for (const auto& multiAxisLabel : multiAxisLabels.value()) {
for (const auto& axis : multiAxisLabel.second) {
singleAxisLabels.push_back(std::string(axis.second.data()));
}
sliceLabels.push_back(singleAxisLabels);
singleAxisLabels.clear();
}
}

// Parse the vector of "names" or just get the "name" of sources.
if (const auto& sourceNames = dataSourceConfig.second.get_child_optional("names"); sourceNames.has_value()) {
for (const auto& sourceName : sourceNames.value()) {
Expand All @@ -72,6 +85,7 @@ SliceTrendingTaskConfig::SliceTrendingTaskConfig(const std::string& id,
sourceName.second.data(),
dataSourceConfig.second.get<std::string>("reductorName"),
axisBoundaries,
sliceLabels,
dataSourceConfig.second.get<std::string>("moduleName") });
}
} else if (!dataSourceConfig.second.get<std::string>("name").empty()) {
Expand All @@ -81,12 +95,14 @@ SliceTrendingTaskConfig::SliceTrendingTaskConfig(const std::string& id,
dataSourceConfig.second.get<std::string>("name"),
dataSourceConfig.second.get<std::string>("reductorName"),
axisBoundaries,
sliceLabels,
dataSourceConfig.second.get<std::string>("moduleName") });
} else {
throw std::runtime_error("No 'name' value or a 'names' vector in the path 'qc.postprocessing." + id + ".dataSources'");
}

axisBoundaries.clear();
sliceLabels.clear();
}
}

Expand Down
Loading