Project
Loading...
Searching...
No Matches
TPCCalibPadRawSpec.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_CALIBRATION_TPCCALIBPEDESTALSPEC_H
13#define O2_CALIBRATION_TPCCALIBPEDESTALSPEC_H
14
19
20#include <vector>
21#include <string>
22#include <chrono>
23#include <fmt/format.h>
24
25#include "Framework/Task.h"
27#include "Framework/Logger.h"
31
33#include "Headers/DataHeader.h"
34
43
44using namespace o2::framework;
46using namespace o2::tpc;
47
48namespace o2::tpc
49{
50
51enum class CalibRawType {
53 Pulser,
54 CE,
55};
56
57const std::unordered_map<std::string, CDBType> CalibRawTypeMap{
58 {"pedestal", CDBType::CalPedestalNoise},
59 {"pulser", CDBType::CalPulser},
60 {"ce", CDBType::CalCE},
61};
62
63template <class T>
65{
66 public:
67 TPCCalibPedestalDevice(CDBType calibType, uint32_t lane, const std::vector<int>& sectors, uint32_t publishAfterTFs, bool useDigitsAsInput) : mCalibType{calibType}, mLane{lane}, mSectors(sectors), mPublishAfter(publishAfterTFs), mUseDigits(useDigitsAsInput) {}
68
70 {
71 // set up ADC value filling
72 // TODO: clean up to not go via RawReaderCRUManager
73 mCalibration.init(); // initialize configuration via configKeyValues
74 mRawReader.createReader("");
75
76 mRawReader.setADCDataCallback([this](const PadROCPos& padROCPos, const CRU& cru, const gsl::span<const uint32_t> data) -> int {
77 const int timeBins = mCalibration.update(padROCPos, cru, data);
78 mCalibration.setNumberOfProcessedTimeBins(std::max(mCalibration.getNumberOfProcessedTimeBins(), size_t(timeBins)));
79 return timeBins;
80 });
81
82 mRawReader.setLinkZSCallback([this](int cru, int rowInSector, int padInRow, int timeBin, float adcValue) -> bool {
83 CRU cruID(cru);
84 mCalibration.updateROC(cruID.roc(), rowInSector - (rowInSector > 62) * 63, padInRow, timeBin, adcValue);
85 return true;
86 });
87
88 mMaxEvents = static_cast<uint32_t>(ic.options().get<int>("max-events"));
89 mUseOldSubspec = ic.options().get<bool>("use-old-subspec");
90 mForceQuit = ic.options().get<bool>("force-quit");
91 mResetAfterPublish = ic.options().get<bool>("reset-after-publish");
92 mDirectFileDump = ic.options().get<bool>("direct-file-dump");
93 mSyncOffsetReference = ic.options().get<uint32_t>("sync-offset-reference");
94 mDecoderType = ic.options().get<uint32_t>("decoder-type");
95 if (mUseOldSubspec) {
96 LOGP(info, "Using old subspecification (CruId << 16) | ((LinkId + 1) << (CruEndPoint == 1 ? 8 : 0))");
97 }
98 }
99
101 {
102 // in case the maximum number of events was reached don't do further processing
103 if (mReadyToQuit) {
104 return;
105 }
106
107 if (mUseDigits) {
108 std::array<std::vector<Digit>, Sector::MAXSECTOR> digits;
109 copyDigits(pc.inputs(), digits);
110 mCalibration.setDigits(&digits);
111 mCalibration.processEvent();
112 } else {
113 auto& reader = mRawReader.getReaders()[0];
114 calib_processing_helper::processRawData(pc.inputs(), reader, mUseOldSubspec, mSectors, nullptr, mSyncOffsetReference, mDecoderType);
115 mCalibration.endEvent();
116 mCalibration.endReader();
117 }
118
119 if (mCalibInfo.tfIDInfo.isDummy()) {
121 }
122
123 mCalibration.incrementNEvents();
124 const auto nTFs = mCalibration.getNumberOfProcessedEvents();
125 LOGP(info, "Number of processed TFs: {} ({})", nTFs, mMaxEvents);
126
127 if ((mPublishAfter && (nTFs % mPublishAfter) == 0)) {
128 LOGP(info, "Publishing after {} TFs", nTFs);
129 sendOutput(pc.outputs());
130 mCalibSent = false;
131 if (mResetAfterPublish) {
132 mCalibration.resetData();
133 mCalibInfo.tfIDInfo.tfCounter = -1U;
134 }
135 }
136
137 if (mMaxEvents && (nTFs >= mMaxEvents) && !mCalibSent) {
138 LOGP(info, "Maximm number of TFs reached ({}), no more processing will be done", mMaxEvents);
139 mReadyToQuit = true;
140 sendOutput(pc.outputs());
141 if (mForceQuit) {
142 pc.services().get<ControlService>().endOfStream();
143 pc.services().get<ControlService>().readyToQuit(QuitRequest::All);
144 } else {
145 // pc.services().get<ControlService>().readyToQuit(QuitRequest::Me);
146 }
147 }
148 }
149
151 {
152 LOGP(info, "endOfStream");
153 if (!mCalibSent) {
154 sendOutput(ec.outputs());
155 ec.services().get<ControlService>().readyToQuit(QuitRequest::Me);
156 }
157 }
158
159 private:
160 T mCalibration;
162 CDBType mCalibType;
163 CalibRawPartInfo mCalibInfo{};
164 uint32_t mMaxEvents{0};
165 uint32_t mPublishAfter{0};
166 uint32_t mLane{0};
167 uint32_t mSyncOffsetReference{144};
168 uint32_t mDecoderType{0};
169 std::vector<int> mSectors{};
170 bool mReadyToQuit{false};
171 bool mCalibSent{false};
172 bool mUseOldSubspec{false};
173 bool mUseDigits{false};
174 bool mForceQuit{false};
175 bool mDirectFileDump{false};
176 bool mResetAfterPublish{false};
177
178 //____________________________________________________________________________
179 void sendOutput(DataAllocator& output)
180 {
181 mCalibration.analyse();
182 const int type = int(mCalibType);
183 mCalibInfo.calibType = type;
184 auto& calibObject = mCalibration.getCalDets();
185 const auto& cdbType = CDBTypeMap.at(mCalibType);
186 const auto name = cdbType.substr(cdbType.rfind("/") + 1);
187 auto image = o2::utils::MemFileHelper::createFileImage(&calibObject, typeid(calibObject), name.data(), "data");
189 output.snapshot(Output{gDataOriginTPC, "CLBPART", subSpec}, *image.get());
190 output.snapshot(Output{gDataOriginTPC, "CLBPARTINFO", subSpec}, mCalibInfo);
191 dumpCalibData();
192 ++mCalibInfo.publishCycle;
193 mCalibSent = true;
194 }
195
196 //____________________________________________________________________________
197 void dumpCalibData()
198 {
199 if (mDirectFileDump && !mCalibSent) {
200 mCalibration.setDebugLevel();
201 const auto& cdbType = CDBTypeMap.at(mCalibType);
202 const auto name = cdbType.substr(cdbType.rfind("/") + 1);
203 LOGP(info, "Dumping output {} lane: {:02}, firsTF: {} cycle: {}.root", name, mLane, mCalibInfo.tfIDInfo.tfCounter, mCalibInfo.publishCycle);
204 mCalibration.dumpToFile(fmt::format("{}_{:02}_{}_{}.root", name, mLane, mCalibInfo.tfIDInfo.tfCounter, mCalibInfo.publishCycle));
205 }
206 }
207
208 void copyDigits(InputRecord& inputs, std::array<std::vector<Digit>, Sector::MAXSECTOR>& digits)
209 {
210 std::vector<InputSpec> filter = {
211 {"check", ConcreteDataTypeMatcher{"TPC", "DIGITS"}, Lifetime::Timeframe},
212 };
213 for (auto const& inputRef : InputRecordWalker(inputs)) {
214 auto const* sectorHeader = DataRefUtils::getHeader<o2::tpc::TPCSectorHeader*>(inputRef);
215 if (sectorHeader == nullptr) {
216 LOG(error) << "sector header missing on header stack for input on " << inputRef.spec->binding;
217 continue;
218 }
219 const int sector = sectorHeader->sector();
220 digits[sector] = inputs.get<std::vector<o2::tpc::Digit>>(inputRef);
221 }
222 }
223};
224
225template <typename... Args>
226AlgorithmSpec getRawDevice(CDBType calibType, Args... args)
227{
228 if (calibType == CDBType::CalPedestalNoise) {
229 return adaptFromTask<TPCCalibPedestalDevice<CalibPedestal>>(calibType, args...);
230 } else if (calibType == CDBType::CalPulser) {
231 return adaptFromTask<TPCCalibPedestalDevice<CalibPulser>>(calibType, args...);
232 } else if (calibType == CDBType::CalCE) {
233 return adaptFromTask<TPCCalibPedestalDevice<CalibPulser>>(calibType, args...);
234 } else {
235 return AlgorithmSpec{};
236 }
237};
238
239DataProcessorSpec getTPCCalibPadRawSpec(const std::string inputSpec, uint32_t ilane = 0, std::vector<int> sectors = {}, uint32_t publishAfterTFs = 0, CDBType rawType = CDBType::CalPedestalNoise)
240{
241 const bool useDigitsAsInput = inputSpec.find("DIGITS") != std::string::npos;
242
243 std::vector<o2::framework::OutputSpec> outputs;
244 outputs.emplace_back(ConcreteDataTypeMatcher{gDataOriginTPC, "CLBPART"}, Lifetime::Sporadic);
245 outputs.emplace_back(ConcreteDataTypeMatcher{gDataOriginTPC, "CLBPARTINFO"}, Lifetime::Sporadic);
246
247 AlgorithmSpec spec;
248
249 const auto id = fmt::format("calib-tpc-raw-{:02}", ilane);
250 return DataProcessorSpec{
251 id.data(),
252 select(inputSpec.data()),
253 outputs,
254 AlgorithmSpec{getRawDevice(rawType, ilane, sectors, publishAfterTFs, useDigitsAsInput)},
255 Options{
256 {"max-events", VariantType::Int, 0, {"maximum number of events to process"}},
257 {"use-old-subspec", VariantType::Bool, false, {"use old subsecifiation definition"}},
258 {"reset-after-publish", VariantType::Bool, false, {"reset calibration after publishing"}},
259 {"force-quit", VariantType::Bool, false, {"force quit after max-events have been reached"}},
260 {"direct-file-dump", VariantType::Bool, false, {"directly dump calibration to file"}},
261 {"sync-offset-reference", VariantType::UInt32, 144u, {"Reference BCs used for the global sync offset in the CRUs"}},
262 {"decoder-type", VariantType::UInt32, 1u, {"Decoder to use: 0 - TPC, 1 - GPU"}},
263 } // end Options
264 }; // end DataProcessorSpec
265}
266
267} // namespace o2::tpc
268
269#endif
Simple interface to the CDB manager.
A helper class to iteratate over all parts of all input routes.
void output(const std::map< std::string, ChannelStat > &channels)
Definition rawdump.cxx:197
A helper class to iteratate over all parts of all input routes.
The input API of the Data Processing Layer This class holds the inputs which are valid for processing...
decltype(auto) get(R binding, int part=0) const
const ROC roc() const
Definition CRU.h:61
Pad and row inside a ROC.
Definition PadROCPos.h:37
static constexpr int MAXSECTOR
Definition Sector.h:44
void init(o2::framework::InitContext &ic) final
TPCCalibPedestalDevice(CDBType calibType, uint32_t lane, const std::vector< int > &sectors, uint32_t publishAfterTFs, bool useDigitsAsInput)
void run(o2::framework::ProcessingContext &pc) final
void endOfStream(o2::framework::EndOfStreamContext &ec) final
This is invoked whenever we have an EndOfStream event.
RawReaderCRU & createReader(const std::string_view inputFileName, uint32_t numTimeBins=0, uint32_t link=0, uint32_t stream=0, uint32_t debugLevel=0, uint32_t verbosity=0, const std::string_view outputFilePrefix="")
create a new raw reader
auto & getReaders()
return vector of readers
void setLinkZSCallback(LinkZSCallback function)
set a callback function for decoded LinkZS data
void setADCDataCallback(ADCDataCallback function)
set a callback function
GLeglImageOES image
Definition glcorearb.h:4021
GLuint const GLchar * name
Definition glcorearb.h:781
GLint GLint GLsizei GLint GLenum GLenum type
Definition glcorearb.h:275
GLboolean * data
Definition glcorearb.h:298
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
Definition glcorearb.h:1308
constexpr o2::header::DataOrigin gDataOriginTPC
Definition DataHeader.h:576
Defining PrimaryVertex explicitly as messageable.
Definition TFIDInfo.h:20
std::vector< InputSpec > select(char const *matcher="")
uint64_t processRawData(o2::framework::InputRecord &inputs, std::unique_ptr< o2::tpc::rawreader::RawReaderCRU > &reader, bool useOldSubspec=false, const std::vector< int > &sectors={}, size_t *nerrors=nullptr, uint32_t syncOffsetReference=144, uint32_t decoderType=1, bool useTrigger=true, bool returnOnNoTrigger=false)
Global TPC definitions and constants.
Definition SimTraits.h:167
DataProcessorSpec getTPCCalibPadRawSpec(const std::string inputSpec, uint32_t ilane=0, std::vector< int > sectors={}, uint32_t publishAfterTFs=0, CDBType rawType=CDBType::CalPedestalNoise)
const std::unordered_map< CDBType, const std::string > CDBTypeMap
Storage name in CCDB for each calibration and parameter type.
Definition CDBTypes.h:94
const std::unordered_map< std::string, CDBType > CalibRawTypeMap
AlgorithmSpec getRawDevice(CDBType calibType, Args... args)
CDBType
Calibration and parameter types for CCDB.
Definition CDBTypes.h:26
@ CalPedestalNoise
Pedestal and Noise calibration.
@ CalPulser
Pulser calibration.
@ CalCE
Laser CE calibration.
static void fillTFIDInfo(o2::framework::ProcessingContext &pc, o2::dataformats::TFIDInfo &ti)
uint32_t SubSpecificationType
Definition DataHeader.h:620
dataformats::TFIDInfo tfIDInfo
static std::unique_ptr< FileImage > createFileImage(const TObject &obj, const std::string &fileName, const std::string &objName)
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"
std::vector< Digit > digits