Project
Loading...
Searching...
No Matches
RawDecoderSpec.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
12#include <string>
13#include <fairlogger/Logger.h>
24
25using namespace o2::ctp::reco_workflow;
26
28{
29 mDecodeinputs = ctx.options().get<bool>("ctpinputs-decoding");
30 mDecoder.setDecodeInps(mDecodeinputs);
31 mNTFToIntegrate = ctx.options().get<int>("ntf-to-average");
32 mVerbose = ctx.options().get<bool>("use-verbose-mode");
33 int maxerrors = ctx.options().get<int>("print-errors-num");
34 mDecoder.setVerbose(mVerbose);
35 mDecoder.setDoLumi(mDoLumi);
36 mDecoder.setDoDigits(mDoDigits);
37 mDecoder.setMAXErrors(maxerrors);
38 std::string lumiinp1 = ctx.options().get<std::string>("lumi-inp1");
39 std::string lumiinp2 = ctx.options().get<std::string>("lumi-inp2");
40 int inp1 = mDecoder.setLumiInp(1, lumiinp1);
41 int inp2 = mDecoder.setLumiInp(2, lumiinp2);
42 mOutputLumiInfo.inp1 = inp1;
43 mOutputLumiInfo.inp2 = inp2;
44 mMaxInputSize = ctx.options().get<int>("max-input-size");
45 mMaxInputSizeFatal = ctx.options().get<bool>("max-input-size-fatal");
46 LOG(info) << "CTP reco init done. Inputs decoding here:" << mDecodeinputs << " DoLumi:" << mDoLumi << " DoDigits:" << mDoDigits << " NTF:" << mNTFToIntegrate << " Lumi inputs:" << lumiinp1 << ":" << inp1 << " " << lumiinp2 << ":" << inp2 << " Max errors:" << maxerrors << " Max input size:" << mMaxInputSize << " MaxInputSizeFatal:" << mMaxInputSizeFatal;
47 // mOutputLumiInfo.printInputs();
48}
50{
51 auto& TFOrbits = mDecoder.getTFOrbits();
52 std::sort(TFOrbits.begin(), TFOrbits.end());
53 size_t l = TFOrbits.size();
54 uint32_t o0 = 0;
55 if (l) {
56 o0 = TFOrbits[0];
57 }
58 int nmiss = 0;
59 int nprt = 0;
60 std::cout << "Missing orbits:";
61 for (int i = 1; i < l; i++) {
62 if ((TFOrbits[i] - o0) > 0x20) {
63 if (nprt < 20) {
64 std::cout << " " << o0 << "-" << TFOrbits[i];
65 }
66 nmiss += (TFOrbits[i] - o0) / 0x20;
67 nprt++;
68 }
69 o0 = TFOrbits[i];
70 }
71 std::cout << std::endl;
72 std::cout << "Number of missing TF:" << nmiss << std::endl;
73 std::cout << "# of IR errors:" << mDecoder.getErrorIR() << " TCR errors:" << mDecoder.getErrorTCR() << std::endl;
74}
76{
78 mOutputDigits.clear();
79 std::map<o2::InteractionRecord, CTPDigit> digits;
83 // setUpDummyLink
84 auto& inputs = ctx.inputs();
85 auto dummyOutput = [&ctx, this]() {
86 if (this->mDoDigits) {
87 ctx.outputs().snapshot(o2::framework::Output{"CTP", "DIGITS", 0}, this->mOutputDigits);
88 }
89 if (this->mDoLumi) {
90 ctx.outputs().snapshot(o2::framework::Output{"CTP", "LUMI", 0}, this->mOutputLumiInfo);
91 }
92 };
93 // if we see requested data type input with 0xDEADBEEF subspec and 0 payload this means that the "delayed message"
94 // mechanism created it in absence of real data from upstream. Processor should send empty output to not block the workflow
95 {
96 static size_t contDeadBeef = 0; // number of times 0xDEADBEEF was seen continuously
97 std::vector<InputSpec> dummy{InputSpec{"dummy", o2::framework::ConcreteDataMatcher{"CTP", "RAWDATA", 0xDEADBEEF}}};
98 for (const auto& ref : o2::framework::InputRecordWalker(inputs, dummy)) {
99 const auto dh = o2::framework::DataRefUtils::getHeader<o2::header::DataHeader*>(ref);
101 if (payloadSize == 0) {
103 if (++contDeadBeef <= maxWarn) {
104 LOGP(alarm, "Found input [{}/{}/{:#x}] TF#{} 1st_orbit:{} Payload {} : assuming no payload for all links in this TF{}",
105 dh->dataOrigin.str, dh->dataDescription.str, dh->subSpecification, dh->tfCounter, dh->firstTForbit, payloadSize,
106 contDeadBeef == maxWarn ? fmt::format(". {} such inputs in row received, stopping reporting", contDeadBeef) : "");
107 }
108 dummyOutput();
109 return;
110 }
111 }
112 contDeadBeef = 0; // if good data, reset the counter
113 }
114 //
115 std::vector<LumiInfo> lumiPointsHBF1;
116 std::vector<InputSpec> filter{InputSpec{"filter", ConcreteDataTypeMatcher{"CTP", "RAWDATA"}, Lifetime::Timeframe}};
117 bool fatal_flag = 0;
118 if (mMaxInputSize > 0) {
119 size_t payloadSize = 0;
120 for (const auto& ref : o2::framework::InputRecordWalker(inputs, filter)) {
121 const auto dh = o2::framework::DataRefUtils::getHeader<o2::header::DataHeader*>(ref);
123 }
124 if (payloadSize > (size_t)mMaxInputSize) {
125 if (mMaxInputSizeFatal) {
126 fatal_flag = 1;
127 LOG(error) << "Input data size bigger than threshold: " << mMaxInputSize << " < " << payloadSize << " decoding TF and exiting.";
128 // LOG(fatal) << "Input data size:" << payloadSize; - fatal issued in decoder
129 } else {
130 LOG(error) << "Input data size:" << payloadSize << " sending dummy output";
131 dummyOutput();
132 return;
133 }
134 }
135 }
136 int ret = 0;
137 if (fatal_flag) {
138 ret = mDecoder.decodeRawFatal(inputs, filter);
139 } else {
140 ret = mDecoder.decodeRaw(inputs, filter, mOutputDigits, lumiPointsHBF1);
141 }
142 if (ret == 1) {
143 dummyOutput();
144 return;
145 }
146 if (mDoDigits) {
147 LOG(info) << "[CTPRawToDigitConverter - run] Writing " << mOutputDigits.size() << " digits. IR rejected:" << mDecoder.getIRRejected() << " TCR rejected:" << mDecoder.getTCRRejected();
148 ctx.outputs().snapshot(o2::framework::Output{"CTP", "DIGITS", 0}, mOutputDigits);
149 }
150 if (mDoLumi) {
151 uint32_t tfCountsT = 0;
152 uint32_t tfCountsV = 0;
153 for (auto const& lp : lumiPointsHBF1) {
154 tfCountsT += lp.counts;
155 tfCountsV += lp.countsFV0;
156 }
157 // LOG(info) << "Lumi rate:" << tfCounts/(128.*88e-6);
158 // FT0
159 mHistoryT.push_back(tfCountsT);
160 mCountsT += tfCountsT;
161 if (mHistoryT.size() <= mNTFToIntegrate) {
162 mNHBIntegratedT += lumiPointsHBF1.size();
163 } else {
164 mCountsT -= mHistoryT.front();
165 mHistoryT.pop_front();
166 }
167 // FV0
168 mHistoryV.push_back(tfCountsV);
169 mCountsV += tfCountsV;
170 if (mHistoryV.size() <= mNTFToIntegrate) {
171 mNHBIntegratedV += lumiPointsHBF1.size();
172 } else {
173 mCountsV -= mHistoryV.front();
174 mHistoryV.pop_front();
175 }
176 //
177 if (mNHBIntegratedT || mNHBIntegratedV) {
178 mOutputLumiInfo.orbit = lumiPointsHBF1[0].orbit;
179 }
180 mOutputLumiInfo.counts = mCountsT;
181
182 mOutputLumiInfo.countsFV0 = mCountsV;
183 mOutputLumiInfo.nHBFCounted = mNHBIntegratedT;
184 mOutputLumiInfo.nHBFCountedFV0 = mNHBIntegratedV;
185 if (mVerbose) {
186 mOutputLumiInfo.printInputs();
187 LOGP(info, "Orbit {}: {}/{} counts inp1/inp2 in {}/{} HBFs -> lumi_inp1 = {:.3e}+-{:.3e} lumi_inp2 = {:.3e}+-{:.3e}", mOutputLumiInfo.orbit, mCountsT, mCountsV, mNHBIntegratedT, mNHBIntegratedV, mOutputLumiInfo.getLumi(), mOutputLumiInfo.getLumiError(), mOutputLumiInfo.getLumiFV0(), mOutputLumiInfo.getLumiFV0Error());
188 }
189 ctx.outputs().snapshot(o2::framework::Output{"CTP", "LUMI", 0}, mOutputLumiInfo);
190 }
191}
193{
194 if (!digits && !lumi) {
195 throw std::runtime_error("all outputs were disabled");
196 }
197 std::vector<o2::framework::InputSpec> inputs;
198 inputs.emplace_back("TF", o2::framework::ConcreteDataTypeMatcher{"CTP", "RAWDATA"}, o2::framework::Lifetime::Timeframe);
199 if (askDISTSTF) {
200 inputs.emplace_back("stdDist", "FLP", "DISTSUBTIMEFRAME", 0, o2::framework::Lifetime::Timeframe);
201 }
202
203 std::vector<o2::framework::OutputSpec> outputs;
204 inputs.emplace_back("ctpconfig", "CTP", "CTPCONFIG", 0, o2::framework::Lifetime::Condition, o2::framework::ccdbParamSpec("CTP/Config/Config", 1));
205 inputs.emplace_back("trigoffset", "CTP", "Trig_Offset", 0, o2::framework::Lifetime::Condition, o2::framework::ccdbParamSpec("CTP/Config/TriggerOffsets"));
206 if (digits) {
207 outputs.emplace_back("CTP", "DIGITS", 0, o2::framework::Lifetime::Timeframe);
208 }
209 if (lumi) {
210 outputs.emplace_back("CTP", "LUMI", 0, o2::framework::Lifetime::Timeframe);
211 }
213 "ctp-raw-decoder",
214 inputs,
215 outputs,
216 o2::framework::AlgorithmSpec{o2::framework::adaptFromTask<o2::ctp::reco_workflow::RawDecoderSpec>(digits, lumi)},
218 {"ntf-to-average", o2::framework::VariantType::Int, 90, {"Time interval for averaging luminosity in units of TF"}},
219 {"print-errors-num", o2::framework::VariantType::Int, 3, {"Max number of errors to print"}},
220 {"lumi-inp1", o2::framework::VariantType::String, "TVX", {"The first input used for online lumi. Name in capital."}},
221 {"lumi-inp2", o2::framework::VariantType::String, "VBA", {"The second input used for online lumi. Name in capital."}},
222 {"use-verbose-mode", o2::framework::VariantType::Bool, false, {"Verbose logging"}},
223 {"max-input-size", o2::framework::VariantType::Int, 0, {"Do not process input if bigger than max size, 0 - do not check"}},
224 {"max-input-size-fatal", o2::framework::VariantType::Bool, false, {"If true issue fatal error otherwise error on;y"}},
225 {"ctpinputs-decoding", o2::framework::VariantType::Bool, false, {"Inputs alignment: true - raw decoder - has to be compatible with CTF decoder: allowed options: 10,01,00"}}}};
226}
228{
230 pc.inputs().get<o2::ctp::TriggerOffsetsParam*>("trigoffset");
231 const auto& trigOffsParam = o2::ctp::TriggerOffsetsParam::Instance();
232 LOG(info) << "updateing TroggerOffsetsParam: inputs L0_L1:" << trigOffsParam.L0_L1 << " classes L0_L1:" << trigOffsParam.L0_L1_classes;
233 const auto ctpcfg = pc.inputs().get<o2::ctp::CTPConfiguration*>("ctpconfig");
234 if (ctpcfg != nullptr) {
235 mDecoder.setCTPConfig(*ctpcfg);
236 LOG(info) << "ctpconfig for run done:" << mDecoder.getCTPConfig().getRunNumber();
237 }
238 }
239}
definition of CTPConfiguration and related CTP structures
int32_t i
A helper class to iteratate over all parts of all input routes.
uint32_t getTCRRejected() const
std::vector< uint32_t > & getTFOrbits()
void setCTPConfig(CTPConfiguration cfg)
int setLumiInp(int lumiinp, std::string inp)
void setDoDigits(bool digi)
int decodeRaw(o2::framework::InputRecord &inputs, std::vector< o2::framework::InputSpec > &filter, o2::pmr::vector< CTPDigit > &digits, std::vector< LumiInfo > &lumiPointsHBF1)
CTPConfiguration & getCTPConfig()
void setDecodeInps(bool decodeinps)
void setDoLumi(bool lumi)
int decodeRawFatal(o2::framework::InputRecord &inputs, std::vector< o2::framework::InputSpec > &filter)
uint32_t getIRRejected() const
void endOfStream(o2::framework::EndOfStreamContext &ec) final
This is invoked whenever we have an EndOfStream event.
void updateTimeDependentParams(framework::ProcessingContext &pc)
void init(framework::InitContext &ctx) final
Initializing the RawDecoderSpec.
void run(framework::ProcessingContext &ctx) final
Run conversion of raw data to cells.
void snapshot(const Output &spec, T const &object)
ConfigParamRegistry const & options()
Definition InitContext.h:33
A helper class to iteratate over all parts of all input routes.
decltype(auto) get(R binding, int part=0) const
DataAllocator & outputs()
The data allocator is used to allocate memory for the output data.
InputRecord & inputs()
The inputs associated with this processing context.
ServiceRegistryRef services()
The services registry associated with this processing context.
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
Definition glcorearb.h:1308
o2::framework::DataProcessorSpec getRawDecoderSpec(bool askSTFDist, bool digits, bool lumi)
Creating DataProcessorSpec for the CTP.
Lifetime
Possible Lifetime of objects being exchanged by the DPL.
Definition Lifetime.h:18
std::vector< ConfigParamSpec > ccdbParamSpec(std::string const &path, int runDependent, std::vector< CCDBMetadata > metadata={}, int qrate=0)
std::vector< ConfigParamSpec > Options
void printInputs() const
Definition LumiInfo.cxx:20
uint64_t countsFV0
Definition LumiInfo.h:29
uint64_t counts
Definition LumiInfo.h:28
uint32_t nHBFCounted
Definition LumiInfo.h:26
float getLumiFV0Error() const
Definition LumiInfo.h:36
uint32_t nHBFCountedFV0
Definition LumiInfo.h:27
float getLumiError() const
Definition LumiInfo.h:35
float getLumi() const
Definition LumiInfo.h:32
float getLumiFV0() const
Definition LumiInfo.h:33
uint32_t orbit
Definition LumiInfo.h:25
static o2::header::DataHeader::PayloadSizeType getPayloadSize(const DataRef &ref)
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"
LumiInfo lumi
std::vector< Digit > digits