Project
Loading...
Searching...
No Matches
TPCFactorizeIDCSpec.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
17#ifndef O2_TPCFACTORIZEIDCSPEC_H
18#define O2_TPCFACTORIZEIDCSPEC_H
19
20#include <vector>
21#include <fmt/format.h>
22#include <filesystem>
23#include "Framework/Task.h"
25#include "Framework/Logger.h"
30#include "Headers/DataHeader.h"
33#include "CCDB/CcdbApi.h"
35#include "TPCBase/CRU.h"
41
42using namespace o2::framework;
44using namespace o2::tpc;
45
46namespace o2::tpc
47{
48
50{
51 public:
52 TPCFactorizeIDCSpec(const std::vector<uint32_t>& crus, const unsigned int timeframes, const unsigned int timeframesDeltaIDC, std::array<unsigned char, Mapper::NREGIONS> groupPads,
53 std::array<unsigned char, Mapper::NREGIONS> groupRows, std::array<unsigned char, Mapper::NREGIONS> groupLastRowsThreshold,
54 std::array<unsigned char, Mapper::NREGIONS> groupLastPadsThreshold, const unsigned int groupPadsSectorEdges, const IDCDeltaCompression compression, const bool usePrecisetimeStamp, const bool sendOutputFFT, const bool sendCCDB, const int lane, const std::vector<o2::tpc::Side>& sides, const int nTFsBuffer)
55 : mCRUs{crus}, mIDCFactorization{timeframes, timeframesDeltaIDC, crus}, mIDCGrouping{groupPads, groupRows, groupLastRowsThreshold, groupLastPadsThreshold, groupPadsSectorEdges}, mCompressionDeltaIDC{compression}, mUsePrecisetimeStamp{usePrecisetimeStamp}, mSendOutFFT{sendOutputFFT}, mSendOutCCDB{sendCCDB}, mLaneId{lane}, mSides{sides}, mNTFsBuffer{nTFsBuffer} {};
56
58 {
59 mUpdateGroupingPar = mLaneId == 0 ? !(ic.options().get<bool>("update-not-grouping-parameter")) : false;
60 mIDCFactorization.setUsePadStatusMap(ic.options().get<bool>("enablePadStatusMap"));
61 mEnableWritingPadStatusMap = ic.options().get<bool>("enableWritingPadStatusMap");
62 mNOrbitsIDC = ic.options().get<int>("orbits-IDCs");
63 mDumpIDC0 = ic.options().get<bool>("dump-IDC0");
64 mDumpIDC1 = ic.options().get<bool>("dump-IDC1");
65 mDumpIDCDelta = ic.options().get<bool>("dump-IDCDelta");
66 mDumpIDCDeltaCalibData = ic.options().get<bool>("dump-IDCDelta-calib-data");
67 mDumpIDCs = ic.options().get<bool>("dump-IDCs");
68 mOffsetCCDB = ic.options().get<bool>("add-offset-for-CCDB-timestamp");
69 mDisableIDCDelta = ic.options().get<bool>("disable-IDCDelta");
70 mCalibFileDir = ic.options().get<std::string>("output-dir");
71 if (mCalibFileDir != "/dev/null") {
72 mCalibFileDir = o2::utils::Str::rectifyDirectory(mCalibFileDir);
73 }
74 mMetaFileDir = ic.options().get<std::string>("meta-output-dir");
75 if (mMetaFileDir != "/dev/null") {
76 mMetaFileDir = o2::utils::Str::rectifyDirectory(mMetaFileDir);
77 }
78
79 mStatusMapOffsSec = ic.options().get<float>("pad-status-map-offset");
80 mStatusMapOffsNSlot = ic.options().get<int>("pad-status-map-offset-nslots");
81 const std::string refGainMapFile = ic.options().get<std::string>("gainMapFile");
82 if (!refGainMapFile.empty()) {
83 LOGP(info, "Loading GainMap from file {}", refGainMapFile);
84 mIDCFactorization.setGainMap(refGainMapFile.data(), "GainMap");
85 }
86 }
87
89 {
90 // store precise timestamp and hbf per TF for look up later only once
91 if (mUsePrecisetimeStamp && pc.inputs().isValid("orbitreset")) {
92 mTFInfo = pc.inputs().get<dataformats::Pair<long, int>>("orbitreset");
93 if (pc.inputs().countValidInputs() == 1) {
94 return;
95 }
96 }
97
98 const auto currTF = processing_helpers::getCurrentTF(pc);
99 if ((mTFFirst == -1) && pc.inputs().isValid("firstTF")) {
100 mTFFirst = pc.inputs().get<long>("firstTF");
101 }
102
103 if (mTFFirst == -1) {
104 mTFFirst = currTF;
105 LOGP(warning, "firstTF not Found!!! Found valid inputs {}. Setting {} as first TF", pc.inputs().countValidInputs(), mTFFirst);
106 }
107
108 // set data taking context only once
109 if (mSetDataTakingCont) {
110 mDataTakingContext = pc.services().get<DataTakingContext>();
111 mSetDataTakingCont = false;
112 }
113
114 // set the run number only once
115 if (!mRun) {
117 }
118
119 const long relTF = (mTFFirst == -1) ? 0 : (currTF - mTFFirst) / mNTFsBuffer;
120
121 // set time stamp only once for each aggregation interval
122 if (mTimestampStart == 0) {
123 setTimeStampCCDB(relTF, pc);
124 }
125
126 // loop over input data
127 for (auto& ref : InputRecordWalker(pc.inputs(), mFilter)) {
128 ++mProcessedCRUs;
129 if ((relTF >= mIDCFactorization.getNTimeframes()) || (relTF < 0)) {
130 continue;
131 }
132
133 auto data = pc.inputs().get<std::vector<float>>(ref);
134 if (data.empty()) {
135 continue;
136 }
137
138 auto const* tpcCRUHeader = o2::framework::DataRefUtils::getHeader<o2::header::DataHeader*>(ref);
139 const unsigned int cru = tpcCRUHeader->subSpecification;
140 mIDCFactorization.setIDCs(std::move(data), cru, relTF);
141 }
142
143 if (mProcessedCRUs == mCRUs.size() * mIDCFactorization.getNTimeframes()) {
144 LOGP(info, "ProcessedTFs: {} currTF: {} relTF: {} OrbitResetTime: {} orbits per TF: {}", mProcessedCRUs / mCRUs.size(), currTF, relTF, mTFInfo.first, mTFInfo.second);
145 factorizeIDCs();
146 sendOutput(pc.outputs());
147 }
148 }
149
151 {
152 factorizeIDCs();
153 sendOutput(ec.outputs());
154 ec.services().get<ControlService>().readyToQuit(QuitRequest::Me);
155 }
156
164
165 // for CCDB
167 static constexpr header::DataDescription getDataDescriptionCCDBIDC0() { return header::DataDescription{"TPC_CalibIDC0"}; }
168 static constexpr header::DataDescription getDataDescriptionCCDBIDC1() { return header::DataDescription{"TPC_CalibIDC1"}; }
171
172 private:
173 const std::vector<uint32_t> mCRUs{};
174 unsigned int mProcessedCRUs{};
175 std::string mMetaFileDir{};
176 std::string mCalibFileDir{};
177 IDCFactorization mIDCFactorization;
179 const IDCDeltaCompression mCompressionDeltaIDC{};
180 const bool mUsePrecisetimeStamp{true};
181 const bool mSendOutFFT{false};
182 bool mSendOutCCDB{false};
183 long mTFFirst{-1};
184 bool mUpdateGroupingPar{true};
185 const int mLaneId{0};
186 std::vector<Side> mSides{};
187 const int mNTFsBuffer{1};
188 std::unique_ptr<CalDet<PadFlags>> mPadFlagsMap;
189 int mNOrbitsIDC{12};
190 bool mDumpIDC0{false};
191 bool mDumpIDC1{false};
192 bool mDumpIDCDelta{false};
193 bool mDumpIDCDeltaCalibData{false};
194 bool mDumpIDCs{false};
195 bool mOffsetCCDB{false};
196 bool mDisableIDCDelta{false};
198 bool mEnableWritingPadStatusMap{false};
199 o2::framework::DataTakingContext mDataTakingContext{};
200 bool mSetDataTakingCont{true};
201 long mTimestampStart{0};
202 uint64_t mRun{0};
203 float mStatusMapOffsSec = 0;
204 int mStatusMapOffsNSlot = 0;
205 const std::vector<InputSpec> mFilter = {{"idcagg", ConcreteDataTypeMatcher{gDataOriginTPC, TPCDistributeIDCSpec::getDataDescriptionIDC(mLaneId)}, Lifetime::Sporadic}};
206
207 void sendOutput(DataAllocator& output)
208 {
209 using timer = std::chrono::high_resolution_clock;
210 const auto offsetCCDB = mOffsetCCDB ? o2::ccdb::CcdbObjectInfo::HOUR : 0;
211 const long timeStampEnd = offsetCCDB + mTimestampStart + mNOrbitsIDC * mIDCFactorization.getNIntegrationIntervals() * o2::constants::lhc::LHCOrbitMUS * 0.001;
212 LOGP(info, "Setting time stamp range from {} to {} for writing to CCDB with an offset of {}", mTimestampStart, timeStampEnd, offsetCCDB);
213
214 // sending output to FFT
215 if (mSendOutFFT) {
216 for (const auto side : mSides) {
217 const unsigned int iSide = static_cast<unsigned int>(side);
218 LOGP(info, "Sending IDC1 for side {} of size {}", iSide, mIDCFactorization.getIDCOneVec(side).size());
220
221 // calculating mean of IDC0 for the IDC scalers
222 const float mean = o2::tpc::IDCCCDBHelper<float>::getMeanIDC0(side, mIDCFactorization.getIDCZero(side), mIDCFactorization.getPadStatusMapPtr());
223 LOGP(info, "Sending mean of: {}", mean);
225 }
226 output.snapshot(Output{gDataOriginTPC, getDataDescriptionTimeStamp()}, std::vector<long>{mTimestampStart, timeStampEnd});
228 output.snapshot(Output{gDataOriginTPC, getDataDescriptionLane()}, mLaneId);
229 }
230
231 if (mSendOutCCDB && (timeStampEnd > mTimestampStart)) {
232 for (int iSide = 0; iSide < mSides.size(); ++iSide) {
233 const Side side = mSides[iSide];
234 LOGP(info, "Writing IDCs to CCDB for Side {}", static_cast<int>(side));
235 const bool sideA = side == Side::A;
236
237 // write struct containing grouping parameters to access grouped IDCs to CCDB
238 if (mUpdateGroupingPar) {
239 ParameterIDCGroupCCDB object = mIDCGrouping.getIDCGroupHelperSector().getGroupingParameter();
241 auto image = o2::ccdb::CcdbApi::createObjectImage(&object, &ccdbInfo);
242 LOGP(info, "Sending object {} / {} of size {} bytes, valid for {} : {} ", ccdbInfo.getPath(), ccdbInfo.getFileName(), image->size(), ccdbInfo.getStartValidityTimestamp(), ccdbInfo.getEndValidityTimestamp());
245 mUpdateGroupingPar = false; // write grouping parameters only once
246 }
247
248 auto start = timer::now();
249 o2::ccdb::CcdbObjectInfo ccdbInfoIDC0(CDBTypeMap.at(sideA ? CDBType::CalIDC0A : CDBType::CalIDC0C), std::string{}, std::string{}, std::map<std::string, std::string>{}, mTimestampStart, timeStampEnd);
250 auto imageIDC0 = o2::ccdb::CcdbApi::createObjectImage(&mIDCFactorization.getIDCZero(side), &ccdbInfoIDC0);
251 LOGP(info, "Sending object {} / {} of size {} bytes, valid for {} : {} ", ccdbInfoIDC0.getPath(), ccdbInfoIDC0.getFileName(), imageIDC0->size(), ccdbInfoIDC0.getStartValidityTimestamp(), ccdbInfoIDC0.getEndValidityTimestamp());
254 auto stop = timer::now();
255 std::chrono::duration<float> time = stop - start;
256 float totalTime = time.count();
257 LOGP(info, "IDCZero CCDB time: {}", time.count());
258
259 start = timer::now();
260 o2::ccdb::CcdbObjectInfo ccdbInfoIDC1(CDBTypeMap.at(sideA ? CDBType::CalIDC1A : CDBType::CalIDC1C), std::string{}, std::string{}, std::map<std::string, std::string>{}, mTimestampStart, timeStampEnd);
261 auto imageIDC1 = o2::ccdb::CcdbApi::createObjectImage(&mIDCFactorization.getIDCOne(side), &ccdbInfoIDC1);
262 LOGP(info, "Sending object {} / {} of size {} bytes, valid for {} : {} ", ccdbInfoIDC1.getPath(), ccdbInfoIDC1.getFileName(), imageIDC1->size(), ccdbInfoIDC1.getStartValidityTimestamp(), ccdbInfoIDC1.getEndValidityTimestamp());
265 stop = timer::now();
266 time = stop - start;
267 LOGP(info, "IDC1 CCDB time: {}", time.count());
268 totalTime += time.count();
269
270 auto padStatusMap = mIDCFactorization.getPadStatusMap();
271 if (padStatusMap && iSide == 0) {
272 start = timer::now();
273
274 // store map in case it is no nullptr
275 if (mEnableWritingPadStatusMap) {
276 long timeStampEndOffsPad = 0;
277 if (mStatusMapOffsSec > 0) {
278 timeStampEndOffsPad = mStatusMapOffsSec * 1000;
279 } else if (mStatusMapOffsNSlot > 0) {
280 const long length = timeStampEnd - mTimestampStart;
281 timeStampEndOffsPad = mStatusMapOffsNSlot * length;
282 }
283
284 mPadFlagsMap = std::move(padStatusMap);
285 LOGP(info, "Writing pad status map to CCDB with an offset of {}.", timeStampEndOffsPad);
286 o2::ccdb::CcdbObjectInfo ccdbInfoPadFlags(CDBTypeMap.at(sideA ? CDBType::CalIDCPadStatusMapA : CDBType::CalIDCPadStatusMapC), std::string{}, std::string{}, std::map<std::string, std::string>{}, mTimestampStart, timeStampEnd + timeStampEndOffsPad);
287 auto imageFlagMap = o2::ccdb::CcdbApi::createObjectImage(mPadFlagsMap.get(), &ccdbInfoPadFlags);
288 LOGP(info, "Sending object {} / {} of size {} bytes, valid for {} : {} ", ccdbInfoPadFlags.getPath(), ccdbInfoPadFlags.getFileName(), imageFlagMap->size(), ccdbInfoPadFlags.getStartValidityTimestamp(), ccdbInfoPadFlags.getEndValidityTimestamp());
291 LOGP(info, "Pad status map written to CCDB");
292 stop = timer::now();
293 time = stop - start;
294 LOGP(info, "Pad status map CCDB time: {}", time.count());
295 totalTime += time.count();
296 }
297 stop = timer::now();
298 time = stop - start;
299 LOGP(info, "Pad status map CCDB time: {}", time.count());
300 totalTime += time.count();
301 }
302
303 if (!mDisableIDCDelta || mDumpIDCDeltaCalibData) {
304 start = timer::now();
305 for (unsigned int iChunk = 0; iChunk < mIDCFactorization.getNChunks(side); ++iChunk) {
306 auto startGrouping = timer::now();
307 mIDCGrouping.setIDCs(std::move(mIDCFactorization).getIDCDeltaUncompressed(iChunk, side), side);
308 mIDCGrouping.processIDCs(mIDCFactorization.getUsePadStatusMap() ? mPadFlagsMap.get() : nullptr);
309 auto stopGrouping = timer::now();
310 time = stopGrouping - startGrouping;
311 LOGP(info, "Averaging and grouping time: {}", time.count());
312
313 const long timeStampStartDelta = mTimestampStart + mNOrbitsIDC * mIDCFactorization.getNIntegrationIntervalsToChunk(iChunk) * o2::constants::lhc::LHCOrbitMUS * 0.001;
314 const long timeStampEndDelta = offsetCCDB + timeStampStartDelta + mNOrbitsIDC * mIDCFactorization.getNIntegrationIntervalsInChunk(iChunk) * o2::constants::lhc::LHCOrbitMUS * 0.001;
315 o2::ccdb::CcdbObjectInfo ccdbInfoIDCDelta(CDBTypeMap.at(sideA ? CDBType::CalIDCDeltaA : CDBType::CalIDCDeltaC), std::string{}, std::string{}, std::map<std::string, std::string>{}, timeStampStartDelta, timeStampEndDelta);
316
317 if (mDumpIDCDelta) {
318 mIDCGrouping.dumpToFile(fmt::format("{}DeltaAveraged_chunk{:02}_{:02}_side{}.root", getCurrentType(), iChunk, timeStampStartDelta, (int)side).data());
319 }
320
321 auto startCCDBIDCDelta = timer::now();
322 std::unique_ptr<std::vector<char>> imageIDCDelta;
323 switch (mCompressionDeltaIDC) {
325 default: {
326 using compType = unsigned short;
327 IDCDelta<compType> idcDelta = IDCDeltaCompressionHelper<compType>::getCompressedIDCs(mIDCGrouping.getIDCGroupData());
328 imageIDCDelta = o2::ccdb::CcdbApi::createObjectImage(&idcDelta, &ccdbInfoIDCDelta);
329 break;
330 }
332 using compType = unsigned char;
333 IDCDelta<compType> idcDelta = IDCDeltaCompressionHelper<compType>::getCompressedIDCs(mIDCGrouping.getIDCGroupData());
334 imageIDCDelta = o2::ccdb::CcdbApi::createObjectImage(&idcDelta, &ccdbInfoIDCDelta);
335 break;
336 }
338 IDCDelta<float> idcDelta = std::move(mIDCGrouping).getIDCGroupData();
339 imageIDCDelta = o2::ccdb::CcdbApi::createObjectImage(&idcDelta, &ccdbInfoIDCDelta);
340 break;
341 }
342
343 if (!mDisableIDCDelta) {
344 LOGP(info, "Sending object {} / {} of size {} bytes, valid for {} : {} ", ccdbInfoIDCDelta.getPath(), ccdbInfoIDCDelta.getFileName(), imageIDCDelta->size(), ccdbInfoIDCDelta.getStartValidityTimestamp(), ccdbInfoIDCDelta.getEndValidityTimestamp());
347 }
348
349 if (mDumpIDCDeltaCalibData && mCalibFileDir != "/dev/null") {
350 const std::string sideStr = sideA ? "A" : "C";
351 std::string calibFName = fmt::format("IDCDelta_side{}_cal_data_{}.root", sideStr, ccdbInfoIDCDelta.getStartValidityTimestamp());
352 try {
353 std::ofstream calFile(fmt::format("{}{}", mCalibFileDir, calibFName), std::ios::out | std::ios::binary);
354 calFile.write(imageIDCDelta->data(), imageIDCDelta->size());
355 calFile.close();
356 } catch (std::exception const& e) {
357 LOG(error) << "Failed to store IDC calibration data file " << calibFName << ", reason: " << e.what();
358 }
359
360 if (mMetaFileDir != "/dev/null") {
362 calMetaData.fillFileData(mCalibFileDir + calibFName);
363 calMetaData.setDataTakingContext(mDataTakingContext);
364 calMetaData.type = "calib";
365 calMetaData.priority = "low";
366 auto metaFileNameTmp = fmt::format("{}{}.tmp", mMetaFileDir, calibFName);
367 auto metaFileName = fmt::format("{}{}.done", mMetaFileDir, calibFName);
368 try {
369 std::ofstream metaFileOut(metaFileNameTmp);
370 metaFileOut << calMetaData;
371 metaFileOut.close();
372 std::filesystem::rename(metaFileNameTmp, metaFileName);
373 } catch (std::exception const& e) {
374 LOG(error) << "Failed to store CTF meta data file " << metaFileName << ", reason: " << e.what();
375 }
376 }
377 }
378
379 auto stopCCDBIDCDelta = timer::now();
380 time = stopCCDBIDCDelta - startCCDBIDCDelta;
381 LOGP(info, "Compression and CCDB object creation time: {}", time.count());
382 }
383
384 stop = timer::now();
385 time = stop - start;
386 LOGP(info, "IDCDelta CCDB time: {}", time.count());
387 }
388 totalTime += time.count();
389 LOGP(info, "CCDB object creation done. Total time: {}", totalTime);
390 }
391 }
392
393 // reseting aggregated IDCs. This is done for safety, but if all data is received in the next aggregation interval it isnt necessary... remove it?
394 LOGP(info, "Everything done! Clearing memory...");
395 mIDCFactorization.reset();
396 mTimestampStart = 0;
397 mTFFirst = -1;
398 mProcessedCRUs = 0; // reset processed TFs for next aggregation interval
399 LOGP(info, "Everything cleared. Waiting for new data to arrive.");
400 }
401
402 void setTimeStampCCDB(const long relTF, o2::framework::ProcessingContext& pc)
403 {
404 // return if the tf info is not set
405 if (mUsePrecisetimeStamp && !mTFInfo.second) {
406 return;
407 }
408 const auto& tinfo = pc.services().get<o2::framework::TimingInfo>();
409 const auto nOrbitsOffset = (relTF * mNTFsBuffer + (mNTFsBuffer - 1)) * mTFInfo.second; // offset to first orbit of IDCs of current orbit
410 mTimestampStart = mUsePrecisetimeStamp ? (mTFInfo.first + (tinfo.firstTForbit - nOrbitsOffset) * o2::constants::lhc::LHCOrbitMUS * 0.001) : tinfo.creation;
411 LOGP(info, "setting time stamp reset reference to: {}, at tfCounter: {}, firstTForbit: {}, NHBFPerTF: {}, relTF: {}, nOrbitsOffset: {}", mTFInfo.first, tinfo.tfCounter, tinfo.firstTForbit, mTFInfo.second, relTF, nOrbitsOffset);
412 }
413
414 void factorizeIDCs()
415 {
416 if (mDumpIDCs) {
417 LOGP(info, "dumping aggregated and factorized IDCs to file for mTFFirst {}", mTFFirst);
418 mIDCFactorization.setTimeStamp(mTimestampStart);
419 mIDCFactorization.setRun(mRun);
420 mIDCFactorization.dumpLargeObjectToFile(fmt::format("{}Factorized_TF_{:02}_TS_{}.root", getCurrentType(), mTFFirst, mTimestampStart).data());
421 }
422
423 const bool calcDeltas = mDumpIDCDeltaCalibData || !mDisableIDCDelta;
424 mIDCFactorization.factorizeIDCs(true, calcDeltas); // calculate DeltaIDC, 0D-IDC, 1D-IDC
425
426 if (mDumpIDC0) {
427 LOGP(info, "dumping IDC Zero to file");
428 for (auto side : mIDCFactorization.getSides()) {
429 const std::string outFileName = (side == Side::A) ? fmt::format("{}Zero_A_{:02}.root", getCurrentType(), mTFFirst) : fmt::format("{}Zero_C_{:02}.root", getCurrentType(), mTFFirst);
430 mIDCFactorization.dumpIDCZeroToFile(side, outFileName.data());
431 }
432 }
433
434 if (mDumpIDC1) {
435 LOGP(info, "dumping IDC1 to file");
436 for (auto side : mIDCFactorization.getSides()) {
437 const std::string outFileName = (side == Side::A) ? fmt::format("{}One_A_{:02}.root", getCurrentType(), mTFFirst) : fmt::format("{}One_C_{:02}.root", getCurrentType(), mTFFirst);
438 mIDCFactorization.dumpIDCOneToFile(side, outFileName.data());
439 }
440 }
441 }
442
443 std::string getCurrentType() const { return "IDC"; }
444};
445
446DataProcessorSpec getTPCFactorizeIDCSpec(const int lane, const std::vector<uint32_t>& crus, const unsigned int timeframes, const unsigned int timeframesDeltaIDC, const IDCDeltaCompression compression, const bool usePrecisetimeStamp, const bool sendOutputFFT, const bool sendCCDB, const int nTFsBuffer = 1)
447{
448 const auto sides = o2::tpc::IDCFactorization::getSides(crus);
449
450 std::vector<OutputSpec> outputSpecs;
451 if (sendCCDB) {
462 }
463
464 if (sendOutputFFT) {
465 for (auto side : sides) {
466 outputSpecs.emplace_back(ConcreteDataMatcher{gDataOriginTPC, TPCFactorizeIDCSpec::getDataDescriptionIDC1(), header::DataHeader::SubSpecificationType{side}}, Lifetime::Sporadic);
467 outputSpecs.emplace_back(ConcreteDataMatcher{gDataOriginTPC, TPCFactorizeIDCSpec::getDataDescriptionIDC0Mean(), header::DataHeader::SubSpecificationType{side}}, Lifetime::Sporadic);
468 }
469 outputSpecs.emplace_back(ConcreteDataMatcher{gDataOriginTPC, TPCFactorizeIDCSpec::getDataDescriptionTimeStamp(), header::DataHeader::SubSpecificationType{0}}, Lifetime::Sporadic);
470 outputSpecs.emplace_back(ConcreteDataMatcher{gDataOriginTPC, TPCFactorizeIDCSpec::getDataDescriptionIntervals(), header::DataHeader::SubSpecificationType{0}}, Lifetime::Sporadic);
471 outputSpecs.emplace_back(ConcreteDataMatcher{gDataOriginTPC, TPCFactorizeIDCSpec::getDataDescriptionLane(), header::DataHeader::SubSpecificationType{0}}, Lifetime::Sporadic);
472 }
473
474 std::vector<InputSpec> inputSpecs;
475 inputSpecs.emplace_back(InputSpec{"idcagg", ConcreteDataTypeMatcher{gDataOriginTPC, TPCDistributeIDCSpec::getDataDescriptionIDC(lane)}, Lifetime::Sporadic});
476 inputSpecs.emplace_back(InputSpec{"firstTF", gDataOriginTPC, TPCDistributeIDCSpec::getDataDescriptionIDCFirstTF(), header::DataHeader::SubSpecificationType{static_cast<unsigned int>(lane)}, Lifetime::Sporadic});
477 if (usePrecisetimeStamp) {
478 inputSpecs.emplace_back(InputSpec{"orbitreset", gDataOriginTPC, TPCDistributeIDCSpec::getDataDescriptionIDCOrbitReset(), header::DataHeader::SubSpecificationType{static_cast<unsigned int>(lane)}, Lifetime::Sporadic});
479 }
480
481 const auto& paramIDCGroup = ParameterIDCGroup::Instance();
482 std::array<unsigned char, Mapper::NREGIONS> groupPads{};
483 std::array<unsigned char, Mapper::NREGIONS> groupRows{};
484 std::array<unsigned char, Mapper::NREGIONS> groupLastRowsThreshold{};
485 std::array<unsigned char, Mapper::NREGIONS> groupLastPadsThreshold{};
486 std::copy(std::begin(paramIDCGroup.groupPads), std::end(paramIDCGroup.groupPads), std::begin(groupPads));
487 std::copy(std::begin(paramIDCGroup.groupRows), std::end(paramIDCGroup.groupRows), std::begin(groupRows));
488 std::copy(std::begin(paramIDCGroup.groupLastRowsThreshold), std::end(paramIDCGroup.groupLastRowsThreshold), std::begin(groupLastRowsThreshold));
489 std::copy(std::begin(paramIDCGroup.groupLastPadsThreshold), std::end(paramIDCGroup.groupLastPadsThreshold), std::begin(groupLastPadsThreshold));
490 const unsigned int groupPadsSectorEdges = paramIDCGroup.groupPadsSectorEdges;
491
492 const std::string type = "idc";
494 fmt::format("tpc-factorize-{}-{:02}", type, lane).data(),
495 inputSpecs,
496 outputSpecs,
497 AlgorithmSpec{adaptFromTask<TPCFactorizeIDCSpec>(crus, timeframes, timeframesDeltaIDC, groupPads, groupRows, groupLastRowsThreshold, groupLastPadsThreshold, groupPadsSectorEdges, compression, usePrecisetimeStamp, sendOutputFFT, sendCCDB, lane, sides, nTFsBuffer)},
498 Options{{"gainMapFile", VariantType::String, "", {"file to reference gain map, which will be used for correcting the cluster charge"}},
499 {"enablePadStatusMap", VariantType::Bool, false, {"Enabling the usage of the pad-by-pad status map during factorization."}},
500 {"enableWritingPadStatusMap", VariantType::Bool, false, {"Write the pad status map to CCDB."}},
501 {"orbits-IDCs", VariantType::Int, 12, {"Number of orbits over which the IDCs are integrated."}},
502 {"dump-IDCs", VariantType::Bool, false, {"Dump IDCs to file"}},
503 {"dump-IDC0", VariantType::Bool, false, {"Dump IDC0 to file"}},
504 {"dump-IDC1", VariantType::Bool, false, {"Dump IDC1 to file"}},
505 {"disable-IDCDelta", VariantType::Bool, false, {"Disable processing of IDCDelta and storage in the CCDB"}},
506 {"dump-IDCDelta", VariantType::Bool, false, {"Dump IDCDelta to file"}},
507 {"dump-IDCDelta-calib-data", VariantType::Bool, false, {"Dump IDCDelta as calibration data to file"}},
508 {"add-offset-for-CCDB-timestamp", VariantType::Bool, false, {"Add an offset of 1 hour for the validity range of the CCDB objects"}},
509 {"pad-status-map-offset", VariantType::Float, 0.f, {"Offset in seconds for timestamp of pad status map CCDB object (overwrites pad-status-map-offset-nslots)"}},
510 {"pad-status-map-offset-nslots", VariantType::Int, 0, {"Offset in slot length units for timestamp of pad status map CCDB object"}},
511 {"output-dir", VariantType::String, "none", {"calibration files output directory, must exist"}},
512 {"meta-output-dir", VariantType::String, "/dev/null", {"calibration metadata output directory, must exist (if not /dev/null)"}},
513 {"update-not-grouping-parameter", VariantType::Bool, false, {"Do NOT Update/Writing grouping parameters to CCDB."}}}}; // end DataProcessorSpec
514 spec.rank = lane;
515 return spec;
516}
517
518} // namespace o2::tpc
519
520#endif
Simple interface to the CDB manager.
Utils and constants for calibration and related workflows.
int16_t time
Definition RawEventData.h:4
class for averaging and grouping of IDCs
helper class for accessing IDCs from CCDB
class for aggregating IDCs for the full TPC (all sectors) and factorization of aggregated IDCs
void output(const std::map< std::string, ChannelStat > &channels)
Definition rawdump.cxx:197
Definition of the Names Generator class.
uint32_t side
Definition RawData.h:0
TPC aggregation of grouped IDCs and factorization.
static std::unique_ptr< std::vector< char > > createObjectImage(const T *obj, CcdbObjectInfo *info=nullptr)
Definition CcdbApi.h:103
static constexpr long HOUR
static constexpr long INFINITE_TIMESTAMP
A helper class to iteratate over all parts of all input routes.
ServiceRegistryRef services()
The services registry associated with this processing context.
virtual void stop()
This is invoked on stop.
Definition Task.h:53
void dumpToFile(const char *outFileName="IDCAverageGroup.root", const char *outName="IDCAverageGroup") const
void processIDCs(const CalDet< PadFlags > *padStatusFlags=nullptr)
static float getMeanIDC0(const Side side, const IDCZero &idcZero, const CalDet< PadFlags > *outlierMap)
static IDCDelta< DataT > getCompressedIDCs(const IDCDelta< float > &idcDeltaUncompressed)
void setGainMap(const char *inpFile, const char *mapName)
const std::vector< Side > & getSides() const
unsigned long getNIntegrationIntervals(const int cru) const
unsigned int getNTimeframes() const
void setRun(const int run)
void reset()
resetting aggregated IDCs
unsigned long getNIntegrationIntervalsInChunk(const unsigned int chunk) const
unsigned long getNIntegrationIntervalsToChunk(const unsigned int chunk) const
const std::vector< float > & getIDCOneVec(const o2::tpc::Side side) const
void factorizeIDCs(const bool norm, const bool calcDeltas)
void dumpIDCZeroToFile(const Side side, const char *outFileName="IDCZero.root", const char *outName="IDC0") const
dump the IDC0 to file
std::vector< unsigned int > getIntegrationIntervalsPerTF(const int cru=-1) const
unsigned int getNChunks(const Side side) const
void setIDCs(std::vector< float > &&idcs, const unsigned int cru, const unsigned int timeframe)
void dumpLargeObjectToFile(const char *outFileName="IDCFactorized.root", const char *outName="IDCFactorized") const
void setUsePadStatusMap(const bool usePadStatusMap)
setting the usage of the pad-by-pad status map during the factorization of the IDCs
CalDet< PadFlags > * getPadStatusMapPtr() const
const IDCZero & getIDCZero(const o2::tpc::Side side) const &
void dumpIDCOneToFile(const Side side, const char *outFileName="IDCOne.root", const char *outName="IDC1") const
dump the IDC1 to file
const IDCOne & getIDCOne(const o2::tpc::Side side) const
std::unique_ptr< CalDet< PadFlags > > getPadStatusMap()
void setTimeStamp(const long timeStamp)
static constexpr header::DataDescription getDataDescriptionIDCFirstTF()
static constexpr header::DataDescription getDataDescriptionIDCOrbitReset()
static header::DataDescription getDataDescriptionIDC(const unsigned int lane)
return data description for aggregated IDCs for given lane
static constexpr header::DataDescription getDataDescriptionCCDBIDCDelta()
static constexpr header::DataDescription getDataDescriptionCCDBGroupingPar()
static constexpr header::DataDescription getDataDescriptionIDC0()
static constexpr header::DataDescription getDataDescriptionTimeStamp()
TPCFactorizeIDCSpec(const std::vector< uint32_t > &crus, const unsigned int timeframes, const unsigned int timeframesDeltaIDC, std::array< unsigned char, Mapper::NREGIONS > groupPads, std::array< unsigned char, Mapper::NREGIONS > groupRows, std::array< unsigned char, Mapper::NREGIONS > groupLastRowsThreshold, std::array< unsigned char, Mapper::NREGIONS > groupLastPadsThreshold, const unsigned int groupPadsSectorEdges, const IDCDeltaCompression compression, const bool usePrecisetimeStamp, const bool sendOutputFFT, const bool sendCCDB, const int lane, const std::vector< o2::tpc::Side > &sides, const int nTFsBuffer)
static constexpr header::DataDescription getDataDescriptionLane()
static constexpr header::DataDescription getDataDescriptionIDC0Mean()
static constexpr header::DataDescription getDataDescriptionCCDBIDC1()
void run(o2::framework::ProcessingContext &pc) final
void init(o2::framework::InitContext &ic) final
static constexpr header::DataDescription getDataDescriptionCCDBIDCPadFlag()
static constexpr header::DataDescription getDataDescriptionIDC1()
static constexpr header::DataDescription getDataDescriptionIDCDelta()
static constexpr header::DataDescription getDataDescriptionCCDBIDC0()
void endOfStream(o2::framework::EndOfStreamContext &ec) final
This is invoked whenever we have an EndOfStream event.
static constexpr header::DataDescription getDataDescriptionIntervals()
GLsizei const GLchar *const * string
Definition glcorearb.h:809
GLeglImageOES image
Definition glcorearb.h:4021
GLint GLint GLsizei GLint GLenum GLenum type
Definition glcorearb.h:275
GLboolean * data
Definition glcorearb.h:298
GLuint GLsizei GLsizei * length
Definition glcorearb.h:790
GLuint start
Definition glcorearb.h:469
GLint ref
Definition glcorearb.h:291
GLint GLint GLsizei GLint GLenum format
Definition glcorearb.h:275
constexpr o2::header::DataOrigin gDataOriginTPC
Definition DataHeader.h:576
double mean(std::vector< double >::const_iterator first, std::vector< double >::const_iterator last)
constexpr double LHCOrbitMUS
Defining PrimaryVertex explicitly as messageable.
Definition TFIDInfo.h:20
std::vector< ConfigParamSpec > Options
uint32_t getCurrentTF(o2::framework::ProcessingContext &pc)
uint64_t getRunNumber(o2::framework::ProcessingContext &pc)
Global TPC definitions and constants.
Definition SimTraits.h:167
const std::unordered_map< CDBType, const std::string > CDBTypeMap
Storage name in CCDB for each calibration and parameter type.
Definition CDBTypes.h:94
Side
TPC readout sidE.
Definition Defs.h:35
@ A
Definition Defs.h:35
IDCDeltaCompression
IDC Delta IDC Compression types.
@ HIGH
high compression using char (data compression ratio ~5.5 when stored in CCDB)
@ NO
no compression using floats
@ MEDIUM
medium compression using short (data compression ratio 2 when stored in CCDB)
DataProcessorSpec getTPCFactorizeIDCSpec(const int lane, const std::vector< uint32_t > &crus, const unsigned int timeframes, const unsigned int timeframesDeltaIDC, const IDCDeltaCompression compression, const bool usePrecisetimeStamp, const bool sendOutputFFT, const bool sendCCDB, const int nTFsBuffer=1)
CDBType
Calibration and parameter types for CCDB.
Definition CDBTypes.h:26
@ CalIDCPadStatusMapA
Status map of the pads (dead etc. obatined from CalIDC0)
@ CalIDC0C
I_0(r,\phi) = <I(r,\phi,t)>_t.
@ CalIDCDeltaC
\Delta I(r,\phi,t) = I(r,\phi,t) / ( I_0(r,\phi) * I_1(t) )
@ CalIDC1A
I_1(t) = <I(r,\phi,t) / I_0(r,\phi)>_{r,\phi}.
@ CalIDCDeltaA
\Delta I(r,\phi,t) = I(r,\phi,t) / ( I_0(r,\phi) * I_1(t) )
@ CalIDC0A
I_0(r,\phi) = <I(r,\phi,t)>_t.
@ CalIDCGroupingParA
Parameters which were used for the averaging of the CalIDCDelta.
@ CalIDCPadStatusMapC
Status map of the pads (dead etc. obatined from CalIDC0)
@ CalIDC1C
I_1(t) = <I(r,\phi,t) / I_0(r,\phi)>_{r,\phi}.
Defining DataPointCompositeObject explicitly as copiable.
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)
uint32_t SubSpecificationType
Definition DataHeader.h:620
struct to access and set Delta IDCs
struct for storing the parameters for the grouping of IDCs to CCDB
static std::string rectifyDirectory(const std::string_view p)
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"