forked from AliceO2Group/QualityControl
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPostProcessingDevice.cxx
More file actions
153 lines (126 loc) · 5.72 KB
/
PostProcessingDevice.cxx
File metadata and controls
153 lines (126 loc) · 5.72 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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
// 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 PostProcessingDevice.cxx
/// \author Piotr Konopka
///
#include "QualityControl/PostProcessingDevice.h"
#include "QualityControl/PostProcessingRunner.h"
#include "QualityControl/PostProcessingConfig.h"
#include "QualityControl/PostProcessingInterface.h"
#include "QualityControl/PostProcessingRunnerConfig.h"
#include "QualityControl/QcInfoLogger.h"
#include "QualityControl/DataHeaderHelpers.h"
#include "QualityControl/runnerUtils.h"
#include <Common/Exceptions.h>
#include <Framework/CallbackService.h>
#include <Framework/ControlService.h>
#include <Framework/InitContext.h>
#include <Framework/ConfigParamRegistry.h>
using namespace AliceO2::Common;
using namespace o2::framework;
constexpr auto outputBinding = "mo";
namespace o2::quality_control::postprocessing
{
PostProcessingDevice::PostProcessingDevice(const PostProcessingRunnerConfig& runnerConfig)
: mRunner(std::make_unique<PostProcessingRunner>(runnerConfig.id)),
mDeviceName(createPostProcessingDeviceName(runnerConfig.taskName, runnerConfig.detectorName)),
mRunnerConfig(runnerConfig)
{
}
void PostProcessingDevice::init(framework::InitContext& ctx)
{
core::initInfologger(ctx, mRunnerConfig.infologgerDiscardParameters, ("post/" + mRunnerConfig.taskName).substr(0, core::QcInfoLogger::maxFacilityLength), mRunnerConfig.detectorName);
if (ctx.options().isSet("configKeyValues")) {
mRunnerConfig.configKeyValues = ctx.options().get<std::string>("configKeyValues");
}
// todo: read the updated config from ctx, one available
mRunner->init(mRunnerConfig, PostProcessingConfig{ mRunner->getID(), mRunnerConfig.configTree });
// registering state machine callbacks
ctx.services().get<CallbackService>().set<CallbackService::Id::Start>([this, services = ctx.services()]() mutable { start(services); });
ctx.services().get<CallbackService>().set<CallbackService::Id::Reset>([this]() { reset(); });
ctx.services().get<CallbackService>().set<CallbackService::Id::Stop>([this, services = ctx.services()]() mutable { stop(services); });
}
void PostProcessingDevice::run(framework::ProcessingContext& ctx)
{
// we set the publication callback each time, because we cannot be sure that
// the reference to DataAllocator does not change
mRunner->setPublicationCallback(publishToDPL(ctx.outputs(), outputBinding));
// When run returns false, it has done its processing.
if (!mRunner->run()) {
ctx.services().get<ControlService>().endOfStream();
ctx.services().get<ControlService>().readyToQuit(QuitRequest::Me);
}
}
std::string PostProcessingDevice::createPostProcessingDeviceName(const std::string& taskName, const std::string& detectorName)
{
return "qc-pp-" + detectorName + "-" + taskName;
}
header::DataOrigin PostProcessingDevice::createPostProcessingDataOrigin(const std::string& detectorCode)
{
// We need a unique Data Origin, so we can have PP Tasks with the same names for different detectors.
// However, to avoid colliding with data marked as e.g. TPC/CLUSTERS, we add 'P' to the data origin, so it is P<det>.
std::string originStr = "P";
if (detectorCode.empty()) {
ILOG(Warning, Support) << "empty detector code for a task data origin, trying to survive with: DET" << ENDM;
originStr += "DET";
} else if (detectorCode.size() > 3) {
ILOG(Warning, Support) << "too long detector code for a task data origin: " + detectorCode + ", trying to survive with: " + detectorCode.substr(0, 3) << ENDM;
originStr += detectorCode.substr(0, 3);
} else {
originStr += detectorCode;
}
o2::header::DataOrigin origin;
origin.runtimeInit(originStr.c_str());
return origin;
}
header::DataDescription PostProcessingDevice::createPostProcessingDataDescription(const std::string& taskName)
{
if (taskName.empty()) {
BOOST_THROW_EXCEPTION(FatalException() << errinfo_details("Empty taskName for pp-task's data description"));
}
return quality_control::core::createDataDescription(taskName, PostProcessingDevice::descriptionHashLength);
}
void PostProcessingDevice::start(ServiceRegistryRef services)
{
mRunner->start(services);
}
void PostProcessingDevice::stop(ServiceRegistryRef services)
{
mRunner->stop(services);
}
void PostProcessingDevice::reset()
{
mRunner->reset();
}
const std::string& PostProcessingDevice::getDeviceName()
{
return mDeviceName;
}
framework::Inputs PostProcessingDevice::getInputsSpecs()
{
o2::header::DataDescription timerDescription;
timerDescription.runtimeInit(std::string("T-" + mRunner->getID()).substr(0, o2::header::DataDescription::size).c_str());
return { { "timer-pp-" + mRunner->getID(),
createPostProcessingDataOrigin(mRunnerConfig.detectorName),
timerDescription,
0,
Lifetime::Timer } };
}
framework::Outputs PostProcessingDevice::getOutputSpecs() const
{
return { { { outputBinding }, createPostProcessingDataOrigin(mRunnerConfig.detectorName), createPostProcessingDataDescription(mRunnerConfig.taskName), 0, Lifetime::Sporadic } };
}
framework::Options PostProcessingDevice::getOptions()
{
return { { "period-timer-pp-" + mRunner->getID(), framework::VariantType::Int, static_cast<int>(mRunnerConfig.periodSeconds * 1000000), { "PP task timer period" } } };
}
} // namespace o2::quality_control::postprocessing