forked from AliceO2Group/AliceO2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTOFDiagnosticCalibratorSpec.h
More file actions
139 lines (121 loc) · 5.88 KB
/
TOFDiagnosticCalibratorSpec.h
File metadata and controls
139 lines (121 loc) · 5.88 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
// 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_TOF_DIAGNOSTIC_CALIBRATOR_H
#define O2_TOF_DIAGNOSTIC_CALIBRATOR_H
/// @file TOFDiagnosticCalibratorSpec.h
/// @brief Device to stor in CCDB the diagnostic words from TOF
#include "TOFCalibration/TOFDiagnosticCalibrator.h"
#include "DetectorsCalibration/Utils.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 "DetectorsRaw/HBFUtils.h"
#include "DetectorsBase/GRPGeomHelper.h"
using namespace o2::framework;
namespace o2
{
namespace calibration
{
class TOFDiagnosticCalibDevice : public o2::framework::Task
{
public:
TOFDiagnosticCalibDevice(std::shared_ptr<o2::base::GRPGeomRequest> req, int runnumber = -1, int rowinMin = 100000) : mCCDBRequest(req), mRunNumber(runnumber), mMinROwin(rowinMin) {}
void init(o2::framework::InitContext& ic) final
{
o2::base::GRPGeomHelper::instance().setRequest(mCCDBRequest);
auto slotL = ic.options().get<uint32_t>("tf-per-slot");
auto delay = ic.options().get<uint32_t>("max-delay");
mCalibrator = std::make_unique<o2::tof::TOFDiagnosticCalibrator>();
mCalibrator->setSlotLength(slotL);
mCalibrator->setMaxSlotsDelay(delay);
mCalibrator->setRunNumber(mRunNumber);
mCalibrator->setMinROwin(mMinROwin);
}
void finaliseCCDB(o2::framework::ConcreteDataMatcher& matcher, void* obj) final
{
o2::base::GRPGeomHelper::instance().finaliseCCDB(matcher, obj);
}
void run(o2::framework::ProcessingContext& pc) final
{
o2::base::GRPGeomHelper::instance().checkUpdates(pc);
o2::base::TFIDInfoHelper::fillTFIDInfo(pc, mCalibrator->getCurrentTFInfo());
auto const data = pc.inputs().get<o2::tof::Diagnostic*>("input");
LOG(debug) << "Processing TF " << mCalibrator->getCurrentTFInfo().tfCounter;
mCalibrator->process<o2::tof::Diagnostic>(*data);
sendOutput(pc.outputs());
}
void endOfStream(o2::framework::EndOfStreamContext& ec) final
{
LOG(info) << "Finalizing calibration";
mCalibrator->checkSlotsToFinalize(o2::calibration::INFINITE_TF);
sendOutput(ec.outputs());
}
private:
std::unique_ptr<o2::tof::TOFDiagnosticCalibrator> mCalibrator;
std::shared_ptr<o2::base::GRPGeomRequest> mCCDBRequest;
int mRunNumber = -1;
int mMinROwin = 100000;
//________________________________________________________________
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->getDiagnosticVector();
auto& infoVec = mCalibrator->getDiagnosticInfoVector(); // 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{o2::calibration::Utils::gDataOriginCDBPayload, "TOF_Diagnostic", i}, *image.get()); // vector<char>
output.snapshot(Output{o2::calibration::Utils::gDataOriginCDBWrapper, "TOF_Diagnostic", i}, w); // root-serialized
}
if (payloadVec.size()) {
mCalibrator->initOutput(); // reset the outputs once they are already sent
}
}
};
} // namespace calibration
namespace framework
{
DataProcessorSpec getTOFDiagnosticCalibDeviceSpec(int runnumber, int rowinMin)
{
using device = o2::calibration::TOFDiagnosticCalibDevice;
using clbUtils = o2::calibration::Utils;
std::vector<OutputSpec> outputs;
outputs.emplace_back(ConcreteDataTypeMatcher{o2::calibration::Utils::gDataOriginCDBPayload, "TOF_Diagnostic"}, Lifetime::Sporadic);
outputs.emplace_back(ConcreteDataTypeMatcher{o2::calibration::Utils::gDataOriginCDBWrapper, "TOF_Diagnostic"}, Lifetime::Sporadic);
std::vector<InputSpec> inputs{{"input", "TOF", "DIAFREQ"}};
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{
"tof-diagnostic-calibration",
inputs,
outputs,
AlgorithmSpec{adaptFromTask<device>(ccdbRequest, runnumber, rowinMin)},
Options{
{"tf-per-slot", VariantType::UInt32, 5u, {"number of TFs per calibration time slot"}},
{"max-delay", VariantType::UInt32, 3u, {"number of slots in past to consider"}}}};
}
} // namespace framework
} // namespace o2
#endif