Project
Loading...
Searching...
No Matches
FITMergeIntegrateClusterSpec.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
16
19#include "Framework/Task.h"
22#include "CCDB/CcdbApi.h"
26
27using namespace o2::framework;
28
29namespace o2
30{
31namespace fit
32{
33
34template <typename DataT>
36{
37 using DataTStruct = typename DataDescriptionFITCurrents<DataT>::DataTStruct; // datatype for the struct containing T0 or V0
38
39 public:
41 FITMergeIntegrateClusters(std::shared_ptr<o2::base::GRPGeomRequest> req) : mCCDBRequest(req){};
42
44 {
46 mCalibrator = std::make_unique<o2::calibration::IntegratedClusterCalibrator<DataTStruct>>();
47 const auto slotLength = ic.options().get<uint32_t>("tf-per-slot");
48 const auto maxDelay = ic.options().get<uint32_t>("max-delay");
49 const auto debug = ic.options().get<bool>("debug");
50 mCalibrator->setSlotLength(slotLength);
51 mCalibrator->setMaxSlotsDelay(maxDelay);
52 mCalibrator->setDebug(debug);
53 mCalibFileDir = ic.options().get<std::string>("output-dir");
54 if (mCalibFileDir != "/dev/null") {
55 mCalibFileDir = o2::utils::Str::rectifyDirectory(mCalibFileDir);
56 }
57 mMetaFileDir = ic.options().get<std::string>("meta-output-dir");
58 if (mMetaFileDir != "/dev/null") {
59 mMetaFileDir = o2::utils::Str::rectifyDirectory(mMetaFileDir);
60 }
61 mDumpCalibData = ic.options().get<bool>("dump-calib-data");
62 }
63
64 void run(ProcessingContext& pc) final
65 {
67 o2::base::TFIDInfoHelper::fillTFIDInfo(pc, mCalibrator->getCurrentTFInfo());
68
69 // set data taking context only once
70 if (mSetDataTakingCont) {
71 mDataTakingContext = pc.services().get<DataTakingContext>();
72 mSetDataTakingCont = false;
73 }
74
75 // accumulate the currents
76 const auto currents = pc.inputs().get<DataTStruct*>(pc.inputs().get("ifitc"));
77 mCalibrator->process(mCalibrator->getCurrentTFInfo().tfCounter, *currents);
78
79 LOGP(debug, "Created {} objects for TF {} and time stamp {}", mCalibrator->getTFinterval().size(), mCalibrator->getCurrentTFInfo().tfCounter, mCalibrator->getCurrentTFInfo().creation);
80 if (mCalibrator->hasCalibrationData()) {
81 sendOutput(pc.outputs());
82 }
83 }
84
86 {
87 LOGP(info, "Finalizing calibration. Dumping all objects");
88 // just write everything out
89 for (int i = 0; i < mCalibrator->getNSlots(); ++i) {
90 mCalibrator->finalizeSlot(mCalibrator->getSlot(i));
91 }
92 sendOutput(eos.outputs());
93 }
94
96
97 private:
98 std::unique_ptr<o2::calibration::IntegratedClusterCalibrator<DataTStruct>> mCalibrator;
99 std::shared_ptr<o2::base::GRPGeomRequest> mCCDBRequest;
100 std::string mMetaFileDir{};
101 std::string mCalibFileDir{};
102 o2::framework::DataTakingContext mDataTakingContext{};
103 bool mSetDataTakingCont{true};
104 bool mDumpCalibData{false};
105
106 void sendOutput(DataAllocator& output)
107 {
108 using FitType = DataDescriptionFITCurrents<DataT>;
109 auto calibrations = std::move(*mCalibrator).getCalibs();
110 const auto& intervals = mCalibrator->getTimeIntervals();
111 assert(calibrations.size() == intervals.size());
112 for (unsigned int i = 0; i < calibrations.size(); i++) {
113 const auto& object = calibrations[i];
114 o2::ccdb::CcdbObjectInfo info(FitType::getCCDBPath(), std::string{}, std::string{}, std::map<std::string, std::string>{}, intervals[i].first, intervals[i].second);
115 auto image = o2::ccdb::CcdbApi::createObjectImage(&object, &info);
116 LOGP(info, "Sending object {} / {} of size {} bytes, valid for {} : {} ", info.getPath(), info.getFileName(), image->size(), info.getStartValidityTimestamp(), info.getEndValidityTimestamp());
117 output.snapshot(Output{o2::calibration::Utils::gDataOriginCDBPayload, FitType::getDataDescriptionCCDB(), i}, *image.get());
118 output.snapshot(Output{o2::calibration::Utils::gDataOriginCDBWrapper, FitType::getDataDescriptionCCDB(), i}, info);
119
120 if (mDumpCalibData && mCalibFileDir != "/dev/null") {
121 std::string calibFName = fmt::format("i{}c_cal_data_{}_{}.root", FitType::getName(), info.getStartValidityTimestamp(), info.getEndValidityTimestamp());
122 try {
123 std::ofstream calFile(fmt::format("{}{}", mCalibFileDir, calibFName), std::ios::out | std::ios::binary);
124 calFile.write(image->data(), image->size());
125 calFile.close();
126 } catch (std::exception const& e) {
127 LOG(error) << "Failed to store calibration data file " << calibFName << ", reason: " << e.what();
128 }
129
130 if (mMetaFileDir != "/dev/null") {
132 calMetaData.fillFileData(calibFName);
133 calMetaData.setDataTakingContext(mDataTakingContext);
134 calMetaData.type = "calib";
135 calMetaData.priority = "low";
136 auto metaFileNameTmp = fmt::format("{}{}.tmp", mMetaFileDir, calibFName);
137 auto metaFileName = fmt::format("{}{}.done", mMetaFileDir, calibFName);
138 try {
139 std::ofstream metaFileOut(metaFileNameTmp);
140 metaFileOut << calMetaData;
141 metaFileOut.close();
142 std::filesystem::rename(metaFileNameTmp, metaFileName);
143 } catch (std::exception const& e) {
144 LOG(error) << "Failed to store CTF meta data file " << metaFileName << ", reason: " << e.what();
145 }
146 }
147 }
148 }
149 mCalibrator->initOutput(); // empty the outputs after they are send
150 }
151};
152
153template <typename DataT>
155{
156 using FitType = DataDescriptionFITCurrents<DataT>;
157 std::vector<InputSpec> inputs;
158 inputs.emplace_back("ifitc", FitType::getDataOrigin(), FitType::getDataDescriptionFITC(), 0, Lifetime::Sporadic);
159
160 auto ccdbRequest = std::make_shared<o2::base::GRPGeomRequest>(true, // orbitResetTime
161 true, // GRPECS=true for nHBF per TF
162 false, // GRPLHCIF
163 false, // GRPMagField
164 false, // askMatLUT
166 inputs);
167
168 std::vector<OutputSpec> outputs;
169 outputs.emplace_back(ConcreteDataTypeMatcher{o2::calibration::Utils::gDataOriginCDBPayload, FitType::getDataDescriptionCCDB()}, Lifetime::Sporadic);
170 outputs.emplace_back(ConcreteDataTypeMatcher{o2::calibration::Utils::gDataOriginCDBWrapper, FitType::getDataDescriptionCCDB()}, Lifetime::Sporadic);
171
172 return DataProcessorSpec{
173 fmt::format("{}-merge-integrated-clusters", FitType::getName()),
174 inputs,
175 outputs,
176 AlgorithmSpec{adaptFromTask<FITMergeIntegrateClusters<DataT>>(ccdbRequest)},
177 Options{
178 {"debug", VariantType::Bool, false, {"Write debug output files"}},
179 {"tf-per-slot", VariantType::UInt32, 1000u, {"number of TFs per calibration time slot"}},
180 {"max-delay", VariantType::UInt32, 3u, {"number of slots in past to consider"}},
181 {"output-dir", VariantType::String, "none", {"calibration files output directory, must exist"}},
182 {"meta-output-dir", VariantType::String, "/dev/null", {"calibration metadata output directory, must exist (if not /dev/null)"}},
183 {"dump-calib-data", VariantType::Bool, false, {"Dump integrated current calibration data to file"}}}};
184}
185
186} // namespace fit
187} // end namespace o2
Utils and constants for calibration and related workflows.
int32_t i
Helper for geometry and GRP related CCDB requests.
calibrator class for accumulating integrated clusters
void output(const std::map< std::string, ChannelStat > &channels)
Definition rawdump.cxx:197
std::ostringstream debug
void checkUpdates(o2::framework::ProcessingContext &pc)
bool finaliseCCDB(o2::framework::ConcreteDataMatcher &matcher, void *obj)
static GRPGeomHelper & instance()
void setRequest(std::shared_ptr< GRPGeomRequest > req)
static std::unique_ptr< std::vector< char > > createObjectImage(const T *obj, CcdbObjectInfo *info=nullptr)
Definition CcdbApi.h:103
void init(framework::InitContext &ic) final
void run(ProcessingContext &pc) final
void finaliseCCDB(o2::framework::ConcreteDataMatcher &matcher, void *obj) final
void endOfStream(EndOfStreamContext &eos) final
This is invoked whenever we have an EndOfStream event.
FITMergeIntegrateClusters(std::shared_ptr< o2::base::GRPGeomRequest > req)
\construcor
GLeglImageOES image
Definition glcorearb.h:4021
o2::framework::DataProcessorSpec getFITMergeIntegrateClusterSpec()
Defining PrimaryVertex explicitly as messageable.
Definition TFIDInfo.h:20
std::vector< ConfigParamSpec > Options
TFitResultPtr fit(const size_t nBins, const T *arr, const T xMin, const T xMax, TF1 &func, std::string_view option="")
Definition fit.h:59
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
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
bool fillFileData(const std::string &fname, bool fillmd5=false, const std::string &tmpEnding="")
void setDataTakingContext(const o2::framework::DataTakingContext &dtc)
static std::string rectifyDirectory(const std::string_view p)
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"