Project
Loading...
Searching...
No Matches
FITCalibrator.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_FITCALIBRATOR_H
13#define O2_FITCALIBRATOR_H
14
20#include "CCDB/CcdbObjectInfo.h"
23#include "Rtypes.h"
24#include <type_traits>
25#include <vector>
26
27namespace o2::fit
28{
29
30template <typename TimeSlotStorageType, typename CalibrationObjectType>
31class FITCalibrator final : public o2::calibration::TimeSlotCalibration<TimeSlotStorageType>
32{
33
34 // probably will be set via run parameter
35 static constexpr unsigned int DEFAULT_MIN_ENTRIES = 1000;
36 using CalibObjWithInfoType = std::pair<o2::ccdb::CcdbObjectInfo, std::unique_ptr<std::vector<char>>>;
37 using TFType = o2::calibration::TFType;
39
40 public:
41 explicit FITCalibrator(unsigned int minimumEntries = DEFAULT_MIN_ENTRIES) : mMinEntries(minimumEntries) // should be removed in future
42 {
43 LOG(debug) << "FITCalibrator ";
44 }
45 ~FITCalibrator() final = default;
46
47 [[nodiscard]] bool isCalibrationObjectReadyToSend() const { return !mStoredCalibrationObjects.empty(); }
48 [[nodiscard]] const std::vector<std::pair<o2::ccdb::CcdbObjectInfo, std::unique_ptr<std::vector<char>>>>& getStoredCalibrationObjects() const { return mStoredCalibrationObjects; }
49
50 bool hasEnoughData(const Slot& slot) const final
51 {
52 LOG(info) << "FIT_CALIBRATOR_TYPE::hasEnoughData";
53 return slot.getContainer()->hasEnoughEntries();
54 }
55
56 void initOutput() final
57 {
58 LOG(info) << "FIT_CALIBRATOR_TYPE::initOutput";
59 mStoredCalibrationObjects.clear();
60 }
61
62 void finalizeSlot(Slot& slot) final
63 {
64 static std::map<std::string, std::string> md;
65 auto* container = slot.getContainer();
66 const auto startValidity = slot.getStartTimeMS() - o2::ccdb::CcdbObjectInfo::SECOND * 10;
67 const auto endValidity = slot.getEndTimeMS() + o2::ccdb::CcdbObjectInfo::MONTH;
68 LOGP(info, "!!!! {}<=TF<={}, startValidity: {} endValidity: {}", slot.getTFStart(), slot.getTFEnd(), startValidity, endValidity);
69 auto calibrationObject = container->generateCalibrationObject(startValidity, endValidity, mExtraInfo);
70 std::vector<CalibObjWithInfoType> preparedCalibObjects;
71 preparedCalibObjects.emplace_back(doSerializationAndPrepareObjectInfo(calibrationObject, startValidity, endValidity));
72 mStoredCalibrationObjects.insert(mStoredCalibrationObjects.end(),
73 std::make_move_iterator(preparedCalibObjects.begin()),
74 std::make_move_iterator(preparedCalibObjects.end()));
75 }
76
78 bool front, TFType tstart, TFType tend) final
79 {
80 LOG(info) << "FIT_CALIBRATOR_TYPE::emplaceNewSlot "
81 << " start " << tstart << " end " << tend;
83 auto& slot = front ? cont.emplace_front(tstart, tend) : cont.emplace_back(tstart, tend);
84 slot.setContainer(std::make_unique<TimeSlotStorageType>(mMinEntries));
85 return slot;
86 }
87
88 CalibObjWithInfoType doSerializationAndPrepareObjectInfo(const CalibrationObjectType& calibrationObject, long starting, long stopping)
89 {
90 std::map<std::string, std::string> metaData;
91 CalibObjWithInfoType result;
92 auto clName = o2::utils::MemFileHelper::getClassName(calibrationObject);
93 auto flName = o2::ccdb::CcdbApi::generateFileName(clName);
94 LOG(info) << " clName " << clName << " flName " << flName;
95 result.first = o2::ccdb::CcdbObjectInfo(CalibrationObjectType::getObjectPath(), clName, flName, metaData, starting, stopping);
96 result.second = o2::ccdb::CcdbApi::createObjectImage(&calibrationObject, &result.first);
97 LOG(info) << "doSerializationAndPrepareObjectInfo"
98 << " start " << starting << " end " << stopping;
99 return result;
100 }
101 void setExtraInfo(const std::string& extraInfo)
102 {
103 mExtraInfo = extraInfo;
104 }
105
106 private:
107 std::vector<CalibObjWithInfoType> mStoredCalibrationObjects{};
108 const unsigned int mMinEntries;
109 std::string mExtraInfo;
110};
111
112} // namespace o2::fit
113
114#endif // O2_FITCALIBRATOR_H
Utils and constants for calibration and related workflows.
std::ostringstream debug
static std::string generateFileName(const std::string &inp)
Definition CcdbApi.cxx:798
static std::unique_ptr< std::vector< char > > createObjectImage(const T *obj, CcdbObjectInfo *info=nullptr)
Definition CcdbApi.h:103
static constexpr long MONTH
static constexpr long SECOND
void finalizeSlot(Slot &slot) final
bool isCalibrationObjectReadyToSend() const
Slot & emplaceNewSlot(bool front, TFType tstart, TFType tend) final
~FITCalibrator() final=default
FITCalibrator(unsigned int minimumEntries=DEFAULT_MIN_ENTRIES)
bool hasEnoughData(const Slot &slot) const final
const std::vector< std::pair< o2::ccdb::CcdbObjectInfo, std::unique_ptr< std::vector< char > > > > & getStoredCalibrationObjects() const
CalibObjWithInfoType doSerializationAndPrepareObjectInfo(const CalibrationObjectType &calibrationObject, long starting, long stopping)
void setExtraInfo(const std::string &extraInfo)
GLuint64EXT * result
Definition glcorearb.h:5662
uint32_t TFType
Definition TimeSlot.h:29
static std::string getClassName(const T &obj)
get the class name of the object
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"