12#ifndef O2_CALIBRATION_TPCCALIBPEDESTALSPEC_H
13#define O2_CALIBRATION_TPCCALIBPEDESTALSPEC_H
23#include <fmt/format.h>
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) {}
77 const int timeBins = mCalibration.update(padROCPos, cru,
data);
78 mCalibration.setNumberOfProcessedTimeBins(std::max(mCalibration.getNumberOfProcessedTimeBins(),
size_t(timeBins)));
82 mRawReader.
setLinkZSCallback([
this](
int cru,
int rowInSector,
int padInRow,
int timeBin,
float adcValue) ->
bool {
84 mCalibration.updateROC(cruID.
roc(), rowInSector - (rowInSector > 62) * 63, padInRow, timeBin, adcValue);
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");
96 LOGP(info,
"Using old subspecification (CruId << 16) | ((LinkId + 1) << (CruEndPoint == 1 ? 8 : 0))");
109 copyDigits(pc.inputs(),
digits);
110 mCalibration.setDigits(&
digits);
111 mCalibration.processEvent();
115 mCalibration.endEvent();
116 mCalibration.endReader();
123 mCalibration.incrementNEvents();
124 const auto nTFs = mCalibration.getNumberOfProcessedEvents();
125 LOGP(info,
"Number of processed TFs: {} ({})", nTFs, mMaxEvents);
127 if ((mPublishAfter && (nTFs % mPublishAfter) == 0)) {
128 LOGP(info,
"Publishing after {} TFs", nTFs);
129 sendOutput(pc.outputs());
131 if (mResetAfterPublish) {
132 mCalibration.resetData();
137 if (mMaxEvents && (nTFs >= mMaxEvents) && !mCalibSent) {
138 LOGP(info,
"Maximm number of TFs reached ({}), no more processing will be done", mMaxEvents);
140 sendOutput(pc.outputs());
143 pc.services().get<
ControlService>().readyToQuit(QuitRequest::All);
152 LOGP(info,
"endOfStream");
154 sendOutput(ec.outputs());
164 uint32_t mMaxEvents{0};
165 uint32_t mPublishAfter{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};
181 mCalibration.analyse();
182 const int type =
int(mCalibType);
184 auto& calibObject = mCalibration.getCalDets();
185 const auto& cdbType =
CDBTypeMap.at(mCalibType);
186 const auto name = cdbType.substr(cdbType.rfind(
"/") + 1);
199 if (mDirectFileDump && !mCalibSent) {
200 mCalibration.setDebugLevel();
201 const auto& cdbType =
CDBTypeMap.at(mCalibType);
202 const auto name = cdbType.substr(cdbType.rfind(
"/") + 1);
210 std::vector<InputSpec>
filter = {
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;
219 const int sector = sectorHeader->sector();
220 digits[sector] = inputs.
get<std::vector<o2::tpc::Digit>>(inputRef);
225template <
typename... Args>
229 return adaptFromTask<TPCCalibPedestalDevice<CalibPedestal>>(calibType, args...);
231 return adaptFromTask<TPCCalibPedestalDevice<CalibPulser>>(calibType, args...);
233 return adaptFromTask<TPCCalibPedestalDevice<CalibPulser>>(calibType, args...);
241 const bool useDigitsAsInput = inputSpec.find(
"DIGITS") != std::string::npos;
243 std::vector<o2::framework::OutputSpec> outputs;
249 const auto id = fmt::format(
"calib-tpc-raw-{:02}", ilane);
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"}},
Simple interface to the CDB manager.
Pad and row inside a ROC.
static constexpr int MAXSECTOR
void init(o2::framework::InitContext &ic) final
TPCCalibPedestalDevice(CDBType calibType, uint32_t lane, const std::vector< int > §ors, 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
GLuint const GLchar * name
GLint GLint GLsizei GLint GLenum GLenum type
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
constexpr o2::header::DataOrigin gDataOriginTPC
Defining PrimaryVertex explicitly as messageable.
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 > §ors={}, size_t *nerrors=nullptr, uint32_t syncOffsetReference=144, uint32_t decoderType=1, bool useTrigger=true, bool returnOnNoTrigger=false)
Global TPC definitions and constants.
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.
const std::unordered_map< std::string, CDBType > CalibRawTypeMap
AlgorithmSpec getRawDevice(CDBType calibType, Args... args)
CDBType
Calibration and parameter types for CCDB.
@ CalPedestalNoise
Pedestal and Noise calibration.
@ CalPulser
Pulser calibration.
@ CalCE
Laser CE calibration.
static void fillTFIDInfo(o2::framework::ProcessingContext &pc, o2::dataformats::TFIDInfo &ti)
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