Project
Loading...
Searching...
No Matches
FITCalibrationDevice.h
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
12#ifndef O2_FITCALIBRATIONDEVICE_H
13#define O2_FITCALIBRATIONDEVICE_H
14
16#include "Framework/Task.h"
22#include <optional>
23#include <utility>
24#include <type_traits>
26
27namespace o2::fit
28{
29
30template <typename InputCalibrationInfoType, typename TimeSlotStorageType, typename CalibrationObjectType>
32{
33 // static constexpr const char* sDEFAULT_CCDB_URL = "http://localhost:8080";
34 static constexpr const char* sInputDataLabel = "calibData";
35 static constexpr const char* sOutputDataLabelCDBPayload = "cdbPayloadFIT";
36 static constexpr const char* sOutputDataLabelCDBWrapper = "cdbWrapperFIT";
37 static constexpr o2::header::DataDescription sOutputDataDescription = "FIT_CALIB";
39
40 public:
41 explicit FITCalibrationDevice(std::shared_ptr<o2::base::GRPGeomRequest> req = {}, const o2::header::DataDescription& dataDescription = sOutputDataDescription, const std::string& inputDataLabel = sInputDataLabel, const std::string& outputDataLabelCDBPayload = sOutputDataLabelCDBPayload, const std::string& outputDataLabelCDBWrapper = sOutputDataLabelCDBWrapper)
42 : mInputDataLabel(std::move(inputDataLabel)), mCCDBRequest(req), mOutputDataDescription(dataDescription), mOutputDataLabelCDBPayload(outputDataLabelCDBPayload), mOutputDataLabelCDBWrapper(outputDataLabelCDBWrapper) {}
43
44 void init(o2::framework::InitContext& context) final
45 {
47 auto slotL = context.options().get<uint32_t>("tf-per-slot");
48 auto delay = context.options().get<uint32_t>("max-delay");
49 const std::string extraInfo = context.options().get<std::string>("extra-info-per-slot");
50 mCalibrator = std::make_unique<CalibratorType>();
51
52 mCalibrator->setSlotLength(slotL);
53 mCalibrator->setMaxSlotsDelay(delay);
54 mCalibrator->setExtraInfo(extraInfo);
55 // o2::ccdb::BasicCCDBManager::instance().setURL(sDEFAULT_CCDB_URL);
56 }
57
59 {
61 auto data = context.inputs().get<gsl::span<InputCalibrationInfoType>>(mInputDataLabel);
62 o2::base::TFIDInfoHelper::fillTFIDInfo(context, mCalibrator->getCurrentTFInfo());
63 mCalibrator->process(data);
64
65 _sendCalibrationObjectIfSlotFinalized(context.outputs());
66 }
67
69 {
70
71 // nope, we have to check if we can finalize slot anyway - scenario with one batch
72 mCalibrator->checkSlotsToFinalize(o2::calibration::INFINITE_TF);
73 _sendCalibrationObjectIfSlotFinalized(context.outputs());
74 }
75
76 void finaliseCCDB(o2::framework::ConcreteDataMatcher& matcher, void* obj) final
77 {
79 }
80 void static prepareVecOutputSpec(std::vector<o2::framework::OutputSpec>& outputs, o2::header::DataDescription dataDescription)
81 {
82 outputs.emplace_back(o2::framework::ConcreteDataTypeMatcher{o2::calibration::Utils::gDataOriginCDBPayload, dataDescription}, o2::framework::Lifetime::Sporadic);
83 outputs.emplace_back(o2::framework::ConcreteDataTypeMatcher{o2::calibration::Utils::gDataOriginCDBWrapper, dataDescription}, o2::framework::Lifetime::Sporadic);
84 }
85
86 void static prepareVecInputSpec(std::vector<o2::framework::InputSpec>& inputs, o2::header::DataOrigin dataOrigin, o2::header::DataDescription dataDescription)
87 {
88 inputs.emplace_back(sInputDataLabel, dataOrigin, dataDescription, o2::framework::Lifetime::Sporadic);
89 }
90
91 private:
92 void _sendCalibrationObjectIfSlotFinalized(o2::framework::DataAllocator& outputs)
93 {
94 if (mCalibrator->isCalibrationObjectReadyToSend()) {
95 _sendOutputs(outputs);
96 }
97 }
98
99 void _sendOutputs(o2::framework::DataAllocator& outputs)
100 {
102 const auto& objectsToSend = mCalibrator->getStoredCalibrationObjects();
103
104 uint32_t iSendChannel = 0;
105 for (const auto& [ccdbInfo, calibObject] : objectsToSend) {
106 outputs.snapshot(o2::framework::Output{clbUtils::gDataOriginCDBPayload, mOutputDataDescription, iSendChannel}, *calibObject);
107 outputs.snapshot(o2::framework::Output{clbUtils::gDataOriginCDBWrapper, mOutputDataDescription, iSendChannel}, ccdbInfo);
108 LOG(info) << "_sendOutputs " << ccdbInfo.getStartValidityTimestamp();
109 ++iSendChannel;
110 }
111 mCalibrator->initOutput();
112 }
113
114 const std::string mInputDataLabel;
115 const std::string mOutputDataLabelCDBPayload;
116 const std::string mOutputDataLabelCDBWrapper;
117 const o2::header::DataDescription mOutputDataDescription;
118 std::unique_ptr<CalibratorType> mCalibrator;
119 std::shared_ptr<o2::base::GRPGeomRequest> mCCDBRequest;
120};
121
122} // namespace o2::fit
123#endif // O2_FITCALIBRATIONDEVICE_H
Helper for geometry and GRP related CCDB requests.
void checkUpdates(o2::framework::ProcessingContext &pc)
bool finaliseCCDB(o2::framework::ConcreteDataMatcher &matcher, void *obj)
static GRPGeomHelper & instance()
void setRequest(std::shared_ptr< GRPGeomRequest > req)
void init(o2::framework::InitContext &context) final
void run(o2::framework::ProcessingContext &context) final
void finaliseCCDB(o2::framework::ConcreteDataMatcher &matcher, void *obj) final
static void prepareVecInputSpec(std::vector< o2::framework::InputSpec > &inputs, o2::header::DataOrigin dataOrigin, o2::header::DataDescription dataDescription)
FITCalibrationDevice(std::shared_ptr< o2::base::GRPGeomRequest > req={}, const o2::header::DataDescription &dataDescription=sOutputDataDescription, const std::string &inputDataLabel=sInputDataLabel, const std::string &outputDataLabelCDBPayload=sOutputDataLabelCDBPayload, const std::string &outputDataLabelCDBWrapper=sOutputDataLabelCDBWrapper)
void endOfStream(o2::framework::EndOfStreamContext &context) final
This is invoked whenever we have an EndOfStream event.
static void prepareVecOutputSpec(std::vector< o2::framework::OutputSpec > &outputs, o2::header::DataDescription dataDescription)
void snapshot(const Output &spec, T const &object)
GLboolean * data
Definition glcorearb.h:298
constexpr TFType INFINITE_TF
Definition TimeSlot.h:30
Defining DataPointCompositeObject explicitly as copiable.
static void fillTFIDInfo(o2::framework::ProcessingContext &pc, o2::dataformats::TFIDInfo &ti)
static constexpr o2::header::DataOrigin gDataOriginCDBWrapper
Definition Utils.h:44
static constexpr o2::header::DataOrigin gDataOriginCDBPayload
Definition Utils.h:43
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"