Project
Loading...
Searching...
No Matches
TOFMergeIntegrateClusterSpec.cxx
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 tof
32{
33
35{
36 public:
38 TOFMergeIntegrateClusters(std::shared_ptr<o2::base::GRPGeomRequest> req) : mCCDBRequest(req){};
39
41 {
43 mCalibrator = std::make_unique<o2::calibration::IntegratedClusterCalibrator<ITOFC>>();
44 const auto slotLength = ic.options().get<uint32_t>("tf-per-slot");
45 const auto maxDelay = ic.options().get<uint32_t>("max-delay");
46 const auto debug = ic.options().get<bool>("debug");
47 mCalibrator->setSlotLength(slotLength);
48 mCalibrator->setMaxSlotsDelay(maxDelay);
49 mCalibrator->setDebug(debug);
50 mCalibFileDir = ic.options().get<std::string>("output-dir");
51 if (mCalibFileDir != "/dev/null") {
52 mCalibFileDir = o2::utils::Str::rectifyDirectory(mCalibFileDir);
53 }
54 mMetaFileDir = ic.options().get<std::string>("meta-output-dir");
55 if (mMetaFileDir != "/dev/null") {
56 mMetaFileDir = o2::utils::Str::rectifyDirectory(mMetaFileDir);
57 }
58 mDumpCalibData = ic.options().get<bool>("dump-calib-data");
59 }
60
61 void run(ProcessingContext& pc) final
62 {
64 o2::base::TFIDInfoHelper::fillTFIDInfo(pc, mCalibrator->getCurrentTFInfo());
65
66 // set data taking context only once
67 if (mSetDataTakingCont) {
68 mDataTakingContext = pc.services().get<DataTakingContext>();
69 mSetDataTakingCont = false;
70 }
71
72 ITOFC tofcurr;
73 tofcurr.mITOFCNCl = pc.inputs().get<std::vector<float>>(pc.inputs().get("itofcn"));
74 tofcurr.mITOFCQ = pc.inputs().get<std::vector<float>>(pc.inputs().get("itofcq"));
75
76 // accumulate the currents
77 mCalibrator->process(mCalibrator->getCurrentTFInfo().tfCounter, tofcurr);
78
79 LOGP(debug, "Created {} objects for TF {} and time stamp {}", mCalibrator->getTFinterval().size(), mCalibrator->getCurrentTFInfo().tfCounter, mCalibrator->getCurrentTFInfo().creation);
80
81 if (mCalibrator->hasCalibrationData()) {
82 sendOutput(pc.outputs());
83 }
84 }
85
87 {
88 LOGP(info, "Finalizing calibration. Dumping all objects");
89 // just write everything out
90 for (int i = 0; i < mCalibrator->getNSlots(); ++i) {
91 mCalibrator->finalizeSlot(mCalibrator->getSlot(i));
92 }
93 sendOutput(eos.outputs());
94 }
95
97
99
100 private:
101 std::unique_ptr<o2::calibration::IntegratedClusterCalibrator<ITOFC>> mCalibrator;
102 std::shared_ptr<o2::base::GRPGeomRequest> mCCDBRequest;
103 std::string mMetaFileDir{};
104 std::string mCalibFileDir{};
105 o2::framework::DataTakingContext mDataTakingContext{};
106 bool mSetDataTakingCont{true};
107 bool mDumpCalibData{false};
108
109 void sendOutput(DataAllocator& output)
110 {
111 auto calibrations = std::move(*mCalibrator).getCalibs();
112 const auto& intervals = mCalibrator->getTimeIntervals();
113 assert(calibrations.size() == intervals.size());
114 for (unsigned int i = 0; i < calibrations.size(); i++) {
115 const auto& object = calibrations[i];
116 o2::ccdb::CcdbObjectInfo info("TOF/Calib/ITOFC", std::string{}, std::string{}, std::map<std::string, std::string>{}, intervals[i].first, intervals[i].second);
117 auto image = o2::ccdb::CcdbApi::createObjectImage(&object, &info);
118 LOGP(info, "Sending object {} / {} of size {} bytes, valid for {} : {} ", info.getPath(), info.getFileName(), image->size(), info.getStartValidityTimestamp(), info.getEndValidityTimestamp());
121
122 if (mDumpCalibData && mCalibFileDir != "/dev/null") {
123 std::string calibFName = fmt::format("itofc_cal_data_{}_{}.root", info.getStartValidityTimestamp(), info.getEndValidityTimestamp());
124 try {
125 std::ofstream calFile(fmt::format("{}{}", mCalibFileDir, calibFName), std::ios::out | std::ios::binary);
126 calFile.write(image->data(), image->size());
127 calFile.close();
128 } catch (std::exception const& e) {
129 LOG(error) << "Failed to store ITOFC calibration data file " << calibFName << ", reason: " << e.what();
130 }
131
132 if (mMetaFileDir != "/dev/null") {
134 calMetaData.fillFileData(calibFName);
135 calMetaData.setDataTakingContext(mDataTakingContext);
136 calMetaData.type = "calib";
137 calMetaData.priority = "low";
138 auto metaFileNameTmp = fmt::format("{}{}.tmp", mMetaFileDir, calibFName);
139 auto metaFileName = fmt::format("{}{}.done", mMetaFileDir, calibFName);
140 try {
141 std::ofstream metaFileOut(metaFileNameTmp);
142 metaFileOut << calMetaData;
143 metaFileOut.close();
144 std::filesystem::rename(metaFileNameTmp, metaFileName);
145 } catch (std::exception const& e) {
146 LOG(error) << "Failed to store CTF meta data file " << metaFileName << ", reason: " << e.what();
147 }
148 }
149 }
150 }
151 mCalibrator->initOutput(); // empty the outputs after they are send
152 }
153};
154
156{
157 std::vector<InputSpec> inputs;
158 inputs.emplace_back("itofcn", o2::header::gDataOriginTOF, "ITOFCN", 0, Lifetime::Sporadic);
159 inputs.emplace_back("itofcq", o2::header::gDataOriginTOF, "ITOFCQ", 0, Lifetime::Sporadic);
160
161 auto ccdbRequest = std::make_shared<o2::base::GRPGeomRequest>(true, // orbitResetTime
162 true, // GRPECS=true for nHBF per TF
163 false, // GRPLHCIF
164 false, // GRPMagField
165 false, // askMatLUT
167 inputs);
168
169 std::vector<OutputSpec> outputs;
172
173 return DataProcessorSpec{
174 "tof-merge-integrated-clusters",
175 inputs,
176 outputs,
177 AlgorithmSpec{adaptFromTask<TOFMergeIntegrateClusters>(ccdbRequest)},
178 Options{
179 {"debug", VariantType::Bool, false, {"Write debug output files"}},
180 {"tf-per-slot", VariantType::UInt32, 1000u, {"number of TFs per calibration time slot"}},
181 {"max-delay", VariantType::UInt32, 3u, {"number of slots in past to consider"}},
182 {"output-dir", VariantType::String, "none", {"calibration files output directory, must exist"}},
183 {"meta-output-dir", VariantType::String, "/dev/null", {"calibration metadata output directory, must exist (if not /dev/null)"}},
184 {"dump-calib-data", VariantType::Bool, false, {"Dump ITOFC calibration data to file"}}}};
185}
186
187} // end namespace tof
188} // end namespace o2
Utils and constants for calibration and related workflows.
std::ostringstream debug
unsigned int uint32_t
int32_t i
Timeframe settings Average distance in cm of events merged into Randomize distance around average distance of merged events Simulate correct bunch interactions instead of placing only the average number of events A value[n] sets TFlen for[n] collisions in Number of bunches per trainsort Number of bunch trains Instantaneous interaction rate Do not simulate border Total number of collisions to be placed in the interior of all time Do not select random but walk over array of events in stride steps h Event generator settings h configStandalone Use CPU for GPU Force usage of the specified GPU device no CPU fallback Continue processing after an error First event to Number of events to Number of iterations to Number of iterations to Number of initial iterations excluded from const char e
Helper for geometry and GRP related CCDB requests.
char error[CURL_ERROR_SIZE]
calibrator class for accumulating integrated clusters
void output(const std::map< std::string, ChannelStat > &channels)
Definition rawdump.cxx:197
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:109
static constexpr header::DataDescription getDataDescriptionCCDB()
void finaliseCCDB(o2::framework::ConcreteDataMatcher &matcher, void *obj) final
void init(framework::InitContext &ic) final
void endOfStream(EndOfStreamContext &eos) final
This is invoked whenever we have an EndOfStream event.
TOFMergeIntegrateClusters(std::shared_ptr< o2::base::GRPGeomRequest > req)
\construcor
GLeglImageOES image
Definition glcorearb.h:4021
constexpr o2::header::DataOrigin gDataOriginTOF
Definition DataHeader.h:578
Defining ITS Vertex explicitly as messageable.
Definition Cartesian.h:288
o2::framework::DataProcessorSpec getTOFMergeIntegrateClusterSpec()
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)
struct containing the integrated TOF currents
std::vector< float > mITOFCNCl
integrated 1D TOF cluster currents
std::vector< float > mITOFCQ
integrated 1D TOF qTot currents
static std::string rectifyDirectory(const std::string_view p)
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"