Skip to content

Commit 305c575

Browse files
committed
polish the skeleton-example of a late task
1 parent def21e2 commit 305c575

4 files changed

Lines changed: 52 additions & 45 deletions

File tree

Framework/basic-late-task.json

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,13 @@
4040
"moduleName": "QcSkeleton",
4141
"detectorName": "TST",
4242
"cycleDurationSeconds": "10",
43+
"resetAfterCycles": "1",
4344
"dataSource": {
4445
"type": "dataSamplingPolicy",
4546
"name": "tst-raw"
46-
}
47+
},
48+
"movingWindows": ["example"],
49+
"location": "local"
4750
}
4851
},
4952
"checks": {
@@ -65,25 +68,6 @@
6568
}
6669
}
6770
}
68-
},
69-
"latecheck": {
70-
"active": "true",
71-
"className": "o2::quality_control_modules::skeleton::SkeletonCheck",
72-
"moduleName": "QcSkeleton",
73-
"policy": "OnAny",
74-
"detectorName": "TST",
75-
"dataSource": [{
76-
"type": "LateTask",
77-
"name": "late",
78-
"MOs": ["graph_example"]
79-
}],
80-
"extendedCheckParameters": {
81-
"physics": {
82-
"pp": {
83-
"myOwnKey1": "myOwnValue1c"
84-
}
85-
}
86-
}
8771
}
8872
},
8973
"lateTasks": {
@@ -95,8 +79,9 @@
9579
"dataSources": [{
9680
"type": "Task",
9781
"name": "QcTask",
98-
"MOs": ["example"]
99-
}]
82+
"MOs": ["example", "example2"]
83+
}],
84+
"outputActivityStrategy": "integrated"
10085
}
10186
}
10287
},

Modules/Skeleton/include/Skeleton/SkeletonLateTask.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <memory>
1010

1111
class TGraph;
12+
class TH2I;
1213

1314
using namespace o2::quality_control::core;
1415

@@ -32,7 +33,8 @@ class SkeletonLateTask final : public LateTaskInterface
3233
void reset() override;
3334

3435
private:
35-
std::shared_ptr<TGraph> mGraph = nullptr;
36+
std::shared_ptr<TGraph> mMeanTrend = nullptr;
37+
std::shared_ptr<TH2I> mCorrelation = nullptr;
3638
};
3739

3840
} // namespace o2::quality_control_modules::skeleton

Modules/Skeleton/src/SkeletonLateTask.cxx

Lines changed: 38 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <TCanvas.h>
1818
#include <TGraph.h>
1919
#include <TH1.h>
20+
#include <TH2I.h>
2021

2122
#include "QualityControl/QcInfoLogger.h"
2223
#include "QualityControl/QCInputs.h"
@@ -38,19 +39,20 @@ void SkeletonLateTask::initialize(o2::framework::InitContext& /*ctx*/)
3839
{
3940
// THUS FUNCTION BODY IS AN EXAMPLE. PLEASE REMOVE EVERYTHING YOU DO NOT NEED.
4041

41-
// This is how logs are created. QcInfoLogger is used. In production, FairMQ logs will go to InfoLogger as well.
42-
ILOG(Debug, Devel) << "initialize SkeletonLateTask" << ENDM;
43-
ILOG(Debug, Support) << "A debug targeted for support" << ENDM;
44-
ILOG(Info, Ops) << "An Info log targeted for operators" << ENDM;
42+
// This creates and registers a graph for publication, we will track "example" histogram mean here
43+
mMeanTrend = std::make_unique<TGraph>();
44+
mMeanTrend->SetName("mean_trend");
45+
mMeanTrend->SetTitle("mean_trend");
46+
mMeanTrend->GetXaxis()->SetTimeDisplay(kTRUE);
47+
mMeanTrend->SetMarkerStyle(kStar); // star markers
48+
mMeanTrend->SetLineStyle(kSolid); // solid line
49+
getObjectsManager()->startPublishing(mMeanTrend.get(), PublicationPolicy::Forever);
4550

46-
// This creates and registers a histogram for publication at the end of each cycle, until the end of the task lifetime
47-
mGraph = std::make_unique<TGraph>();
48-
mGraph->SetName("graph_example");
49-
mGraph->SetTitle("graph_example");
50-
mGraph->SetMarkerStyle(kStar); // star markers
51-
mGraph->SetLineStyle(kSolid); // solid line
52-
getObjectsManager()->startPublishing(mGraph.get(), PublicationPolicy::Forever);
51+
// This creates and registers a 2D histogram for publication, we will fill it with means of "example" and "example2" histograms
52+
mCorrelation = std::make_unique<TH2I>("correlation", "correlation", 20, 0, 10500, 20, 0, 255);
53+
getObjectsManager()->startPublishing(mCorrelation.get(), PublicationPolicy::Forever);
5354

55+
// this demonstrates how to get a property tree of custom parameters
5456
auto plots = mCustomParameters.getOptionalPtree("plots");
5557
if (plots.has_value()) {
5658
ILOG(Info, Support) << "nested param: " << plots.value().get<std::string>("nested") << ENDM;
@@ -62,23 +64,35 @@ void SkeletonLateTask::startOfActivity(const Activity& activity)
6264
// THIS FUNCTION BODY IS AN EXAMPLE. PLEASE REMOVE EVERYTHING YOU DO NOT NEED.
6365
ILOG(Debug, Devel) << "startOfActivity " << activity.mId << ENDM;
6466

65-
// remove all existing points
66-
mGraph->Set(0);
67+
// remove all existing data in plots to have them clean in a start->stop->start sequence
68+
reset();
6769
}
6870

6971
void SkeletonLateTask::process(const quality_control::core::QCInputs& data)
7072
{
7173
// THIS FUNCTION BODY IS AN EXAMPLE. PLEASE REMOVE EVERYTHING YOU DO NOT NEED.
7274

73-
if (auto histoOpt = getMonitorObject<TH1>(data, "example")) {
74-
const TH1& histo = histoOpt.value();
75+
// this is how a MonitorObject can be obtained, incl. the wrapper itself
76+
if (auto moOpt = getMonitorObject(data, "example")) {
77+
const MonitorObject& mo = moOpt.value();
78+
auto validityEndSeconds = mo.getValidity().getMax() / 1000;
7579

76-
ILOG(Info, Ops) << "Histogram " << histo.GetName() << " has " << histo.GetEntries() << " entries" << ENDM;
77-
mGraph->AddPoint(histo.GetEntries(), histo.GetMean());
80+
auto histo = dynamic_cast<TH1*>(mo.getObject());
81+
if (histo) {
82+
mMeanTrend->AddPoint(validityEndSeconds, histo->GetMean());
83+
ILOG(Debug, Devel) << "New point in graph" << ENDM;
84+
}
7885
}
7986

80-
if (auto qoOpt = getQualityObject(data, "QcCheck")) {
81-
ILOG(Info, Ops) << "Got QcCheck result: " << qoOpt.value().get().getQuality() << ENDM;
87+
// this is how objects can be retrieved without a MonitorObject wrapper
88+
auto example1Opt = getMonitorObject<TH1>(data, "example");
89+
auto example2Opt = getMonitorObject<TH1>(data, "example2");
90+
if (example1Opt.has_value() && example2Opt.has_value()) {
91+
const TH1& example1 = example1Opt.value();
92+
const TH1& example2 = example2Opt.value();
93+
94+
mCorrelation->Fill(example1.GetMean(), example2.GetMean());
95+
ILOG(Debug, Devel) << "New entry in correlation" << ENDM;
8296
}
8397
}
8498

@@ -94,8 +108,11 @@ void SkeletonLateTask::reset()
94108

95109
// Clean all the monitor objects here.
96110
ILOG(Debug, Devel) << "Resetting the plots" << ENDM;
97-
if (mGraph) {
98-
mGraph->Clear();
111+
if (mMeanTrend) {
112+
mMeanTrend->Set(0);
113+
}
114+
if (mCorrelation) {
115+
mCorrelation->Reset();
99116
}
100117
}
101118

doc/Configuration.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,10 @@ declared inside in the "lateTasks" path. Please also refer to [the Late Tasks do
383383
"name": "Clusters", "": "Name of the user component which will provide the data",
384384
"MOs": ["example_object"], "": "List of reuqested MOs. If empty, all are requested.",
385385
"": " Use \"QOs\" to requested QualityObjects"
386-
}]
386+
}],
387+
"outputActivityStrategy": "integrated", "": "Defines how Activity and Validity of objects should be calculated.",
388+
"": "The default \"integrated\" is a union of all inputs during an activity,",
389+
"": "while \"last\" copies the Activity of the latest inputs."
387390
}
388391
}
389392
}

0 commit comments

Comments
 (0)