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

Common: add generic checker for trending plots #2383

Merged
Merged
Show file tree
Hide file tree
Changes from 3 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: 3 additions & 0 deletions Modules/Common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ target_sources(O2QcCommon
src/ReferenceComparatorTask.cxx
src/ReferenceComparatorTaskConfig.cxx
src/ReferenceComparatorCheck.cxx
src/CheckerThresholdsConfig.cxx
src/TrendCheck.cxx
src/NonEmpty.cxx
src/MeanIsAbove.cxx
src/TH1Reductor.cxx
Expand Down Expand Up @@ -68,6 +70,7 @@ add_root_dictionary(O2QcCommon
include/Common/ObjectComparatorKolmogorov.h
include/Common/ReferenceComparatorTask.h
include/Common/ReferenceComparatorCheck.h
include/Common/TrendCheck.h
include/Common/MeanIsAbove.h
include/Common/TH1Ratio.h
include/Common/TH2Ratio.h
Expand Down
71 changes: 71 additions & 0 deletions Modules/Common/include/Common/CheckerThresholdsConfig.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.

///
/// \file CheckerThresholdsConfig.h
/// \author Andrea Ferrero
/// \brief Utility class handling thresholds and axis ranges and retrieve them from the custom parameters
///

#ifndef QC_MODULE_COMMON_CHECKERTHRESHOLDSCONFIG_H
#define QC_MODULE_COMMON_CHECKERTHRESHOLDSCONFIG_H

#include "QualityControl/Activity.h"
#include "QualityControl/CustomParameters.h"

#include <string>
#include <optional>
#include <array>
#include <vector>

using namespace o2::quality_control::core;

namespace o2::quality_control_modules::common
{

namespace internal
{
class Thresholds;
class XYRanges;
} // namespace internal

class CheckerThresholdsConfig
{
public:
CheckerThresholdsConfig(const CustomParameters& customParameters, const Activity& activity);
~CheckerThresholdsConfig() = default;

/// \brief function to retrieve the thresholds for a given interaction rate, if available
std::array<std::optional<std::pair<double, double>>, 2> getThresholdsForPlot(const std::string& plotName, double rate);

/// \brief optional X-Y ranges over which the check must be restricted
std::array<std::optional<std::pair<double, double>>, 2> getRangesForPlot(const std::string& plotName);

private:
void initThresholdsForPlot(const std::string& plotName);
void initRangesForPlot(const std::string& plotName);

CustomParameters mCustomParameters;
Activity mActivity;

/// vectors of [min,max,rate] tuples. The first two values are the minimum and maximum threshold values,
/// and the third is the associated reference interaction rate (optional)
std::array<std::shared_ptr<internal::Thresholds>, 2> mDefaultThresholds;
std::array<std::unordered_map<std::string, std::shared_ptr<internal::Thresholds>>, 2> mThresholds;

/// \brief optional X-Y ranges over which the check must be restricted
std::array<std::shared_ptr<internal::XYRanges>, 2> mDefaultRanges;
std::array<std::unordered_map<std::string, std::shared_ptr<internal::XYRanges>>, 2> mRanges;
};

} // namespace o2::quality_control_modules::common

#endif // QC_MODULE_COMMON_CHECKERTHRESHOLDSCONFIG_H
1 change: 1 addition & 0 deletions Modules/Common/include/Common/LinkDef.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#pragma link C++ class o2::quality_control_modules::common::ObjectComparatorKolmogorov + ;
#pragma link C++ class o2::quality_control_modules::common::ReferenceComparatorTask + ;
#pragma link C++ class o2::quality_control_modules::common::ReferenceComparatorCheck + ;
#pragma link C++ class o2::quality_control_modules::common::TrendCheck + ;
#pragma link C++ class o2::quality_control_modules::common::WorstOfAllAggregator + ;
#pragma link C++ class o2::quality_control_modules::common::IncreasingEntries + ;
#pragma link C++ class o2::quality_control_modules::common::TH1SliceReductor + ;
Expand Down
83 changes: 83 additions & 0 deletions Modules/Common/include/Common/TrendCheck.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.

///
/// \file TrendCheck.h
/// \author Andrea Ferrero
/// \brief Generic checker for trending graphs
///

#ifndef QC_MODULE_COMMON_TRENDCHECK_H
#define QC_MODULE_COMMON_TRENDCHECK_H

#include "QualityControl/CheckInterface.h"

#include <optional>
#include <array>
#include <unordered_map>

class TGraph;
class TObject;

using namespace o2::quality_control::core;

namespace o2::quality_control_modules::common
{

class CheckerThresholdsConfig;

/// \brief Generic checker for trending graphs
///
/// \author Andrea Ferrero
class TrendCheck : public o2::quality_control::checker::CheckInterface
{
public:
/// Default constructor
TrendCheck() = default;
/// Destructor
~TrendCheck() override = default;

void configure() override;
Quality check(std::map<std::string, std::shared_ptr<MonitorObject>>* moMap) override;
void beautify(std::shared_ptr<MonitorObject> mo, Quality checkResult = Quality::Null) override;
std::string getAcceptedType() override;

void startOfActivity(const Activity& activity) override;
void endOfActivity(const Activity& activity) override;

ClassDefOverride(TrendCheck, 1);

private:
enum ThresholdsMode {
ExpectedRange,
DeviationFromMean,
StdDeviation
};

std::array<std::optional<std::pair<double, double>>, 2> getThresholds(std::string key, TGraph* graph);
void getGraphsFromObject(TObject* object, std::vector<TGraph*>& graphs);
double getInteractionRate();

Activity mActivity;
ThresholdsMode mTrendCheckMode{ ExpectedRange };
int mNPointsForAverage{ 0 };
std::pair<float, float> mQualityLabelPosition{ 0.12, 0.8 };
std::pair<float, float> mQualityLabelSize{ 0.5, 0.07 };
std::shared_ptr<CheckerThresholdsConfig> mThresholds;
std::unordered_map<std::string, std::vector<std::pair<double, std::pair<double, double>>>> mAverageTrend;
std::unordered_map<std::string, std::vector<std::pair<double, std::pair<double, double>>>> mThresholdsTrendBad;
std::unordered_map<std::string, std::vector<std::pair<double, std::pair<double, double>>>> mThresholdsTrendMedium;
std::unordered_map<std::string, Quality> mQualities;
};

} // namespace o2::quality_control_modules::common

#endif // QC_MODULE_COMMON_TRENDCHECK_H
6 changes: 5 additions & 1 deletion Modules/Common/include/Common/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,11 @@ T getFromExtendedConfig(const quality_control::core::Activity& activity, const q
if (auto param = params.atOptional(name, activity)) {
parameter = param.value();
} else {
parameter = params.atOrDefaultValue(name, std::to_string(retVal));
if constexpr (std::is_same<std::string, T>::value) {
parameter = params.atOrDefaultValue(name, retVal);
} else {
parameter = params.atOrDefaultValue(name, std::to_string(retVal));
}
}
return internal::stringToType<T>(parameter);
}
Expand Down
Loading
Loading