Skip to content

Commit 5e9b78a

Browse files
committed
adopt QcInputs in LateTaskInterface::process
1 parent a8cfaa8 commit 5e9b78a

File tree

4 files changed

+56
-46
lines changed

4 files changed

+56
-46
lines changed

Framework/include/QualityControl/LateTaskInterface.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
#include "QualityControl/UserCodeInterface.h"
2828
#include "QualityControl/MonitorObject.h"
2929
#include "QualityControl/QualityObject.h"
30+
#include "QualityControl/QCInputs.h"
31+
3032

3133
namespace o2::monitoring
3234
{
@@ -96,7 +98,7 @@ class LateTaskInterface : public UserCodeInterface
9698
// optionally, it could also hide DPL's InputRecord or decorate it with a method which allows to access sampled
9799
// and unsampled data in a unified way.
98100
// virtual void process(std::map<std::string, std::shared_ptr<const core::MonitorObject>>& moMap, std::map<std::string, std::shared_ptr<const core::QualityObject>>& qoMap) = 0;
99-
virtual void process(o2::framework::ProcessingContext& ctx) = 0;
101+
virtual void process(const core::QCInputs& data) = 0;
100102
virtual void endOfActivity(const Activity& activity) = 0;
101103
virtual void reset() = 0;
102104

Framework/src/LateTaskRunner.cxx

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,47 @@ void LateTaskRunner::init(InitContext& iCtx)
8787

8888
void LateTaskRunner::run(ProcessingContext& pCtx)
8989
{
90+
// todo: derive from received objects
9091
mValidity.update(getCurrentTimestamp());
9192

93+
QCInputs taskInputs;
94+
for (const auto& ref : InputRecordWalker(pCtx.inputs())) {
95+
// InputRecordWalker because the output of CheckRunner can be multi-part
96+
const auto* inputSpec = ref.spec;
97+
if (inputSpec == nullptr) {
98+
continue;
99+
}
100+
const auto dataOrigin = DataSpecUtils::asConcreteOrigin(*inputSpec);
101+
102+
// fixme: come up with an elegant way for this. LateTask should be probably aware of the requested user inputs aside from just InputSpecs
103+
// also, we should filter only expect objects from the received collections
104+
if (dataOrigin.str[0] == 'Q' || dataOrigin.str[0] == 'W') { // main MOs and moving windows from QC tasks
105+
auto moc = DataRefUtils::as<MonitorObjectCollection>(ref);
106+
moc->postDeserialization();
107+
108+
for (const auto& obj : *moc) {
109+
auto mo = dynamic_cast<MonitorObject*>(obj);
110+
if (mo != nullptr) {
111+
taskInputs.insert(mo->getName(), std::shared_ptr<MonitorObject>(mo));
112+
}
113+
}
114+
115+
moc->SetOwner(false);
116+
} else if (dataOrigin.str[0] == 'C' || dataOrigin.str[0] == 'A') { // QOs from Checks and Aggregators
117+
// QO
118+
auto qo = DataRefUtils::as<QualityObject>(ref);
119+
auto key = qo->getName();
120+
taskInputs.insert(key, std::shared_ptr<QualityObject>(std::move(qo)));
121+
122+
} else {
123+
BOOST_THROW_EXCEPTION(FatalException() << errinfo_details("LateTaskRunner currently supports only MonitorObject and Quality inputs"));
124+
}
125+
}
126+
127+
128+
92129
// run the task
93-
mTask->process(pCtx);
130+
mTask->process(taskInputs);
94131

95132
// publish objects
96133
mObjectsManager->setValidity(mValidity);

Modules/Skeleton/include/Skeleton/SkeletonLateTask.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ class SkeletonLateTask final : public LateTaskInterface
2424
~SkeletonLateTask() override;
2525

2626
// Definition of the methods for the template method pattern
27-
void initialize(o2::framework::InitContext& ctx) override;
28-
void startOfActivity(const Activity& activity) override;
29-
void process(o2::framework::ProcessingContext& ctx) override;
30-
void endOfActivity(const Activity& activity) override;
27+
void initialize(o2::framework::InitContext&) override;
28+
void startOfActivity(const Activity&) override;
29+
void process(const quality_control::core::QCInputs&) override;
30+
void endOfActivity(const Activity&) override;
3131
void reset() override;
3232

3333
private:

Modules/Skeleton/src/SkeletonLateTask.cxx

Lines changed: 11 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
#include <TH1.h>
2020

2121
#include "QualityControl/QcInfoLogger.h"
22+
#include "QualityControl/QCInputs.h"
23+
#include "QualityControl/QCInputsAdapters.h"
2224
#include "Skeleton/SkeletonLateTask.h"
2325
#include <Framework/InputRecordWalker.h>
2426
#include <Framework/DataRefUtils.h>
@@ -54,50 +56,19 @@ void SkeletonLateTask::startOfActivity(const Activity& activity)
5456
// mGraph->Clear();
5557
}
5658

57-
void SkeletonLateTask::process(o2::framework::ProcessingContext& ctx)
59+
void SkeletonLateTask::process(const quality_control::core::QCInputs& data)
5860
{
5961
// THIS FUNCTION BODY IS AN EXAMPLE. PLEASE REMOVE EVERYTHING YOU DO NOT NEED.
6062

61-
if (ctx.inputs().isValid("QcTask")) {
62-
auto qcTaskMOs = ctx.inputs().get<MonitorObjectCollection*>("QcTask");
63-
if (qcTaskMOs == nullptr) {
64-
ILOG(Error, Ops) << "empty ptr" << ENDM;
65-
return;
66-
}
67-
68-
ILOG(Info, Ops) << "MOC has " << qcTaskMOs->GetEntries() << " entries" << ENDM;
69-
for (auto const& obj : *qcTaskMOs) {
70-
71-
if (obj == nullptr) {
72-
ILOG(Error, Ops) << "Found a null MonitorObject in the collection" << ENDM;
73-
continue;
74-
}
75-
76-
auto mo = dynamic_cast<o2::quality_control::core::MonitorObject*>(obj);
77-
if (mo == nullptr) {
78-
ILOG(Error, Ops) << "Could not cast TObject into MonitorObject" << ENDM;
79-
continue;
80-
}
81-
82-
if (mo->getName() == "example") {
83-
ILOG(Info, Ops) << "Got the 'example' object" << ENDM;
84-
} else {
85-
continue;
86-
}
87-
88-
auto histo = dynamic_cast<TH1*>(mo->getObject());
89-
if (histo == nullptr) {
90-
ILOG(Error, Ops) << "Could not cast MonitorObject to TH1" << ENDM;
91-
continue;
92-
}
93-
94-
ILOG(Info, Ops) << "Histogram " << histo->GetName() << " has " << histo->GetEntries() << " entries" << ENDM;
95-
96-
mGraph->AddPoint(histo->GetEntries(), histo->GetMean());
97-
}
63+
if (auto histoOpt = getMonitorObject<TH1>(data, "example")) {
64+
const TH1& histo = histoOpt.value();
65+
66+
ILOG(Info, Ops) << "Histogram " << histo.GetName() << " has " << histo.GetEntries() << " entries" << ENDM;
67+
mGraph->AddPoint(histo.GetEntries(), histo.GetMean());
9868
}
99-
if (ctx.inputs().isValid("QcCheck")) {
100-
ILOG(Info, Ops) << "got QcCheck results" << ENDM;
69+
70+
if (auto qoOpt = getQualityObject(data, "QcCheck")) {
71+
ILOG(Info, Ops) << "Got QcCheck result: " << qoOpt.value().get().getQuality() << ENDM;
10172
}
10273
}
10374

0 commit comments

Comments
 (0)