forked from AliceO2Group/AliceO2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVdAndExBCalibSpec.h
More file actions
168 lines (149 loc) · 6.82 KB
/
VdAndExBCalibSpec.h
File metadata and controls
168 lines (149 loc) · 6.82 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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
// 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.
#ifndef O2_TRD_VDANDEXBCALIBSPEC_H
#define O2_TRD_VDANDEXBCALIBSPEC_H
/// \file VdAndExBCalibSpec.h
/// \brief DPL device for steering the TRD vD and ExB time slot based calibration
/// \author Ole Schmidt
#include "TRDCalibration/CalibratorVdExB.h"
#include "DetectorsCalibration/Utils.h"
#include "DataFormatsTRD/AngularResidHistos.h"
#include "CommonUtils/MemFileHelper.h"
#include "Framework/Task.h"
#include "Framework/ConfigParamRegistry.h"
#include "Framework/ControlService.h"
#include "Framework/WorkflowSpec.h"
#include "CCDB/CcdbApi.h"
#include "CCDB/CcdbObjectInfo.h"
#include "Framework/CCDBParamSpec.h"
#include "DetectorsBase/GRPGeomHelper.h"
#include <chrono>
using namespace o2::framework;
namespace o2
{
namespace calibration
{
class VdAndExBCalibDevice : public o2::framework::Task
{
public:
VdAndExBCalibDevice(std::shared_ptr<o2::base::GRPGeomRequest> req) : mCCDBRequest(req) {}
void init(o2::framework::InitContext& ic) final
{
o2::base::GRPGeomHelper::instance().setRequest(mCCDBRequest);
auto slotL = ic.options().get<uint32_t>("sec-per-slot");
auto delay = ic.options().get<float>("max-delay");
mCalibrator = std::make_unique<o2::trd::CalibratorVdExB>();
mCalibrator->setSlotLengthInSeconds(slotL);
mCalibrator->setMaxSlotsDelay(delay);
if (ic.options().get<bool>("enable-root-output")) {
mCalibrator->createOutputFile();
}
}
void finaliseCCDB(o2::framework::ConcreteDataMatcher& matcher, void* obj) final
{
o2::base::GRPGeomHelper::instance().finaliseCCDB(matcher, obj);
}
void run(o2::framework::ProcessingContext& pc) final
{
const auto& tinfo = pc.services().get<o2::framework::TimingInfo>();
if (tinfo.globalRunNumberChanged) { // new run is starting
mRunStopRequested = false;
mCalibrator->retrievePrev(pc); // SOR initialization is performed here
}
if (mRunStopRequested) {
return;
}
o2::base::GRPGeomHelper::instance().checkUpdates(pc);
auto dataAngRes = pc.inputs().get<o2::trd::AngularResidHistos>("input");
o2::base::TFIDInfoHelper::fillTFIDInfo(pc, mCalibrator->getCurrentTFInfo());
LOG(detail) << "Processing TF " << mCalibrator->getCurrentTFInfo().tfCounter << " with " << dataAngRes.getNEntries() << " AngularResidHistos entries";
mCalibrator->process(dataAngRes);
if (pc.transitionState() == TransitionHandlingState::Requested) {
LOG(info) << "Run stop requested, finalizing";
mRunStopRequested = true;
mCalibrator->checkSlotsToFinalize(o2::calibration::INFINITE_TF);
mCalibrator->closeOutputFile();
}
sendOutput(pc.outputs());
}
void endOfStream(o2::framework::EndOfStreamContext& ec) final
{
if (mRunStopRequested) {
return;
}
mCalibrator->checkSlotsToFinalize(o2::calibration::INFINITE_TF);
mCalibrator->closeOutputFile();
sendOutput(ec.outputs());
}
void stop() final
{
mCalibrator->closeOutputFile();
}
private:
std::unique_ptr<o2::trd::CalibratorVdExB> mCalibrator;
std::shared_ptr<o2::base::GRPGeomRequest> mCCDBRequest;
bool mRunStopRequested = false; // flag that run was stopped (and the last output is sent)
//________________________________________________________________
void sendOutput(DataAllocator& output)
{
// extract CCDB infos and calibration objects, convert it to TMemFile and send them to the output
// TODO in principle, this routine is generic, can be moved to Utils.h
using clbUtils = o2::calibration::Utils;
const auto& payloadVec = mCalibrator->getCcdbObjectVector();
auto& infoVec = mCalibrator->getCcdbObjectInfoVector(); // use non-const version as we update it
assert(payloadVec.size() == infoVec.size());
for (uint32_t i = 0; i < payloadVec.size(); i++) {
auto& w = infoVec[i];
auto image = o2::ccdb::CcdbApi::createObjectImage(&payloadVec[i], &w);
LOG(info) << "Sending object " << w.getPath() << "/" << w.getFileName() << " of size " << image->size()
<< " bytes, valid for " << w.getStartValidityTimestamp() << " : " << w.getEndValidityTimestamp();
output.snapshot(Output{clbUtils::gDataOriginCDBPayload, "VDRIFTEXB", i}, *image.get()); // vector<char>
output.snapshot(Output{clbUtils::gDataOriginCDBWrapper, "VDRIFTEXB", i}, w); // root-serialized
}
if (payloadVec.size()) {
mCalibrator->initOutput(); // reset the outputs once they are already sent
}
}
};
} // namespace calibration
namespace framework
{
DataProcessorSpec getTRDVdAndExBCalibSpec()
{
using device = o2::calibration::VdAndExBCalibDevice;
using clbUtils = o2::calibration::Utils;
std::vector<OutputSpec> outputs;
outputs.emplace_back(ConcreteDataTypeMatcher{o2::calibration::Utils::gDataOriginCDBPayload, "VDRIFTEXB"}, Lifetime::Sporadic);
outputs.emplace_back(ConcreteDataTypeMatcher{o2::calibration::Utils::gDataOriginCDBWrapper, "VDRIFTEXB"}, Lifetime::Sporadic);
std::vector<InputSpec> inputs;
inputs.emplace_back("input", "TRD", "ANGRESHISTS");
inputs.emplace_back("calvdexb", "TRD", "CALVDRIFTEXB", 0, Lifetime::Condition, ccdbParamSpec("TRD/Calib/CalVdriftExB"));
auto ccdbRequest = std::make_shared<o2::base::GRPGeomRequest>(true, // orbitResetTime
true, // GRPECS=true
false, // GRPLHCIF
false, // GRPMagField
false, // askMatLUT
o2::base::GRPGeomRequest::None, // geometry
inputs);
return DataProcessorSpec{
"calib-vdexb-calibration",
inputs,
outputs,
AlgorithmSpec{adaptFromTask<device>(ccdbRequest)},
Options{
{"sec-per-slot", VariantType::UInt32, 900u, {"number of seconds per calibration time slot"}},
{"max-delay", VariantType::Float, 0.05f, {"number of slots in past to consider"}},
{"enable-root-output", VariantType::Bool, false, {"output tprofiles and fits to root file"}},
}};
}
} // namespace framework
} // namespace o2
#endif // O2_TRD_VDANDEXBCALIBSPEC_H