Project
Loading...
Searching...
No Matches
EntropyDecoderSpec.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
13
14#include <vector>
15
22#include <TStopwatch.h>
23
24using namespace o2::framework;
25
26namespace o2
27{
28namespace trd
29{
30
32{
33 public:
35 ~EntropyDecoderSpec() override = default;
37 void init(o2::framework::InitContext& ic) final;
39 void finaliseCCDB(o2::framework::ConcreteDataMatcher& matcher, void* obj) final;
40
41 private:
42 o2::trd::CTFCoder mCTFCoder;
43 bool mCorrectLML0 = false;
44 TStopwatch mTimer;
45};
46
47EntropyDecoderSpec::EntropyDecoderSpec(int verbosity) : mCTFCoder(o2::ctf::CTFCoderBase::OpType::Decoder)
48{
49 mTimer.Stop();
50 mTimer.Reset();
51 mCTFCoder.setVerbosity(verbosity);
52 mCTFCoder.setSupportBCShifts(true);
53 mCTFCoder.setDictBinding("ctfdict_TRD");
54}
55
57{
58 static int bcshift = 0;
59
60 if (mCTFCoder.finaliseCCDB<CTF>(matcher, obj) && mCorrectLML0) {
61 // check if the LM_L0 shift was updated
62 const auto& trigOffsParam = o2::ctp::TriggerOffsetsParam::Instance();
63 if (bcshift != trigOffsParam.LM_L0) {
64 bcshift = trigOffsParam.LM_L0;
65 auto customShift = trigOffsParam.customOffset[o2::detectors::DetID::TRD];
66 LOGP(info, "Decoded IRs will be corrected by {} BCs (LM_L0 {} + custom {}), discarded if become prior to 1st orbit", -(bcshift - customShift), -bcshift, customShift);
67 mCTFCoder.setBCShift(bcshift - customShift);
68 }
69 return;
70 }
71}
72
74{
75 mCTFCoder.init<CTF>(ic);
76 mCorrectLML0 = ic.options().get<bool>("correct-trd-trigger-offset");
77
78 int checkBogus = ic.options().get<int>("bogus-trigger-rejection");
79 mCTFCoder.setCheckBogusTrig(checkBogus);
80 LOGP(info, "Bogus triggers rejection flag: {}", checkBogus);
81}
82
84{
85 auto cput = mTimer.CpuTime();
86 mTimer.Start(false);
87 o2::ctf::CTFIOSize iosize;
88
89 mCTFCoder.updateTimeDependentParams(pc, true);
90 auto buff = pc.inputs().get<gsl::span<o2::ctf::BufferType>>("ctf_TRD");
91
92 auto& triggers = pc.outputs().make<std::vector<TriggerRecord>>(OutputRef{"triggers"});
93 auto& tracklets = pc.outputs().make<std::vector<Tracklet64>>(OutputRef{"tracklets"});
94 auto& digits = pc.outputs().make<std::vector<Digit>>(OutputRef{"digits"});
95
96 // since the buff is const, we cannot use EncodedBlocks::relocate directly, instead we wrap its data to another flat object
97 if (buff.size()) {
98 const auto ctfImage = o2::trd::CTF::getImage(buff.data());
99 iosize = mCTFCoder.decode(ctfImage, triggers, tracklets, digits);
100 }
101 pc.outputs().snapshot({"ctfrep", 0}, iosize);
102 mTimer.Stop();
103 LOG(info) << "Decoded " << tracklets.size() << " TRD tracklets and " << digits.size() << " digits in " << triggers.size() << " triggers, (" << iosize.asString() << ") in " << mTimer.CpuTime() - cput << " s";
104}
105
107{
108 LOGF(info, "TRD Entropy Decoding total timing: Cpu: %.3e Real: %.3e s in %d slots",
109 mTimer.CpuTime(), mTimer.RealTime(), mTimer.Counter() - 1);
110}
111
113{
114 std::vector<OutputSpec> outputs{
115 OutputSpec{{"triggers"}, "TRD", "TRKTRGRD", 0, Lifetime::Timeframe},
116 OutputSpec{{"tracklets"}, "TRD", "TRACKLETS", 0, Lifetime::Timeframe},
117 OutputSpec{{"digits"}, "TRD", "DIGITS", 0, Lifetime::Timeframe},
118 OutputSpec{{"ctfrep"}, "TRD", "CTFDECREP", 0, Lifetime::Timeframe}};
119
120 std::vector<InputSpec> inputs;
121 inputs.emplace_back("ctf_TRD", "TRD", "CTFDATA", sspec, Lifetime::Timeframe);
122 inputs.emplace_back("ctfdict_TRD", "TRD", "CTFDICT", 0, Lifetime::Condition, ccdbParamSpec("TRD/Calib/CTFDictionaryTree"));
123 inputs.emplace_back("trigoffset", "CTP", "Trig_Offset", 0, Lifetime::Condition, ccdbParamSpec("CTP/Config/TriggerOffsets"));
124
125 return DataProcessorSpec{
126 "trd-entropy-decoder",
127 inputs,
128 outputs,
129 AlgorithmSpec{adaptFromTask<EntropyDecoderSpec>(verbosity)},
130 Options{{"ctf-dict", VariantType::String, "ccdb", {"CTF dictionary: empty or ccdb=CCDB, none=no external dictionary otherwise: local filename"}},
131 {"correct-trd-trigger-offset", VariantType::Bool, false, {"Correct decoded IR by TriggerOffsetsParam::LM_L0"}},
132 {"bogus-trigger-rejection", VariantType::Int, 10, {">0 : discard, warn N times, <0 : warn only, =0: no check for triggers with no tracklets or bogus IR"}},
133 {"ans-version", VariantType::String, {"version of ans entropy coder implementation to use"}}}};
134}
135
136} // namespace trd
137} // namespace o2
#define verbosity
class for entropy encoding/decoding of TRD data
Convert CTF (EncodedBlocks) to TRD digit/tracklets stream.
void setSupportBCShifts(bool v=true)
void updateTimeDependentParams(o2::framework::ProcessingContext &pc, bool askTree=false)
void setDictBinding(const std::string &s)
void init(o2::framework::InitContext &ic)
void setBCShift(int64_t n)
bool finaliseCCDB(o2::framework::ConcreteDataMatcher &matcher, void *obj)
static auto getImage(const void *newHead)
get const image of the container wrapper, with pointers in the image relocated to new head
static constexpr ID TRD
Definition DetID.h:65
void snapshot(const Output &spec, T const &object)
decltype(auto) make(const Output &spec, Args... args)
ConfigParamRegistry const & options()
Definition InitContext.h:33
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.
void setCheckBogusTrig(int v)
Definition CTFCoder.h:52
o2::ctf::CTFIOSize decode(const CTF::base &ec, VTRG &trigVec, VTRK &trkVec, VDIG &digVec)
entropy decode data from buffer with CTF
Definition CTFCoder.h:179
void run(o2::framework::ProcessingContext &pc) final
void endOfStream(o2::framework::EndOfStreamContext &ec) final
This is invoked whenever we have an EndOfStream event.
void finaliseCCDB(o2::framework::ConcreteDataMatcher &matcher, void *obj) final
void init(o2::framework::InitContext &ic) final
~EntropyDecoderSpec() override=default
Defining PrimaryVertex explicitly as messageable.
Definition TFIDInfo.h:20
std::vector< ConfigParamSpec > ccdbParamSpec(std::string const &path, int runDependent, std::vector< CCDBMetadata > metadata={}, int qrate=0)
std::vector< ConfigParamSpec > Options
framework::DataProcessorSpec getEntropyDecoderSpec(int verbosity, unsigned int sspec)
create a processor spec
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
std::string asString() const
Definition CTFIOSize.cxx:19
wrapper for the Entropy-encoded triggers and cells of the TF
Definition CTF.h:41
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"
auto * ctfImage
std::vector< Digit > digits
std::vector< Tracklet64 > tracklets