-
Notifications
You must be signed in to change notification settings - Fork 164
Expand file tree
/
Copy pathSkeletonCheck.cxx
More file actions
133 lines (113 loc) · 5.34 KB
/
SkeletonCheck.cxx
File metadata and controls
133 lines (113 loc) · 5.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
// 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 SkeletonCheck.cxx
/// \author My Name
///
#include "Skeleton/SkeletonCheck.h"
#include "QualityControl/MonitorObject.h"
#include "QualityControl/Quality.h"
#include "QualityControl/QcInfoLogger.h"
#include "Skeleton/SkeletonTask.h"
#include "QualityControl/QCInputs.h"
#include "QualityControl/QCInputsAdapters.h"
// ROOT
#include <TH1.h>
#include <DataFormatsQualityControl/FlagType.h>
#include <DataFormatsQualityControl/FlagTypeFactory.h>
using namespace std;
using namespace o2::quality_control;
namespace o2::quality_control_modules::skeleton
{
void SkeletonCheck::configure()
{
// THUS FUNCTION BODY IS AN EXAMPLE. PLEASE REMOVE EVERYTHING YOU DO NOT NEED.
// This method is called whenever CustomParameters are set.
// Example of retrieving a custom parameter
std::string parameter = mCustomParameters.atOrDefaultValue("myOwnKey1", "default");
}
Quality SkeletonCheck::check(const quality_control::core::QCInputs& data)
{
// THUS FUNCTION BODY IS AN EXAMPLE. PLEASE REMOVE EVERYTHING YOU DO NOT NEED.
Quality result = Quality::Null;
// You can get details about the activity via the object mActivity:
ILOG(Debug, Devel) << "Run " << mActivity->mId << ", type: " << mActivity->mType << ", beam: " << mActivity->mBeamType << ENDM;
// and you can get your custom parameters:
ILOG(Debug, Devel) << "custom param physics.pp.myOwnKey1 : " << mCustomParameters.atOrDefaultValue("myOwnKey1", "default_value", "physics", "pp") << ENDM;
constexpr static auto name = "example";
// get MonitorObject with a given name from generic data object and converts it into requested type (TH1 here)
const auto histOpt = getMonitorObject<TH1>(data, name);
if (!histOpt.has_value()) {
ILOG(Warning, Support) << "Data object does not contain any MonitorObject with a name: " << name << ", or it couldn't be transformed into TH1" << ENDM;
return result;
}
// histOpt contains reference_wrapper<const TH1>, it can be accesed by .get() or by implicit type conversion operator like in this example
const TH1& histogram = histOpt.value();
// unless we find issues, we assume the quality is good
result = Quality::Good;
// an example of a naive quality check: we want bins 1-7 to be non-empty and bins 0 and >7 to be empty.
for (int i = 0; i < histogram.GetNbinsX(); i++) {
if (i > 0 && i < 8 && histogram.GetBinContent(i) == 0) {
result = Quality::Bad;
// optionally, we can add flags indicating the effect on data and a comment explaining why it was assigned.
result.addFlag(FlagTypeFactory::BadPID(), "It is bad because there is nothing in bin " + std::to_string(i));
break;
} else if ((i == 0 || i > 7) && histogram.GetBinContent(i) > 0) {
result = Quality::Medium;
// optionally, we can add flags indicating the effect on data and a comment explaining why it was assigned.
result.addFlag(FlagTypeFactory::Unknown(), "It is medium because bin " + std::to_string(i) + " is not empty");
result.addFlag(FlagTypeFactory::BadTracking(), "We can assign more than one Flag to a Quality");
}
}
// optionally, we can associate some custom metadata to a Quality
result.addMetadata("mykey", "myvalue");
return result;
}
void SkeletonCheck::beautify(std::shared_ptr<MonitorObject> mo, Quality checkResult)
{
// THUS FUNCTION BODY IS AN EXAMPLE. PLEASE REMOVE EVERYTHING YOU DO NOT NEED.
// This method lets you decorate the checked object according to the computed Quality
if (mo->getName() == "example") {
auto* h = dynamic_cast<TH1F*>(mo->getObject());
if (h == nullptr) {
ILOG(Error, Support) << "Could not cast `example` to TH1*, skipping" << ENDM;
return;
}
if (checkResult == Quality::Good) {
h->SetFillColor(kGreen);
} else if (checkResult == Quality::Bad) {
ILOG(Debug, Devel) << "Quality::Bad, setting to red" << ENDM;
h->SetFillColor(kRed);
} else if (checkResult == Quality::Medium) {
ILOG(Debug, Devel) << "Quality::medium, setting to orange" << ENDM;
h->SetFillColor(kOrange);
}
h->SetLineColor(kBlack);
}
}
void SkeletonCheck::reset()
{
// THUS FUNCTION BODY IS AN EXAMPLE. PLEASE REMOVE EVERYTHING YOU DO NOT NEED.
ILOG(Debug, Devel) << "SkeletonCheck::reset" << ENDM;
// please reset the state of the check here to allow for reuse between consecutive runs.
}
void SkeletonCheck::startOfActivity(const Activity& activity)
{
// THUS FUNCTION BODY IS AN EXAMPLE. PLEASE REMOVE EVERYTHING YOU DO NOT NEED.
ILOG(Debug, Devel) << "SkeletonCheck::start : " << activity.mId << ENDM;
mActivity = make_shared<Activity>(activity);
}
void SkeletonCheck::endOfActivity(const Activity& activity)
{
// THUS FUNCTION BODY IS AN EXAMPLE. PLEASE REMOVE EVERYTHING YOU DO NOT NEED.
ILOG(Debug, Devel) << "SkeletonCheck::end : " << activity.mId << ENDM;
}
} // namespace o2::quality_control_modules::skeleton