forked from AliceO2Group/AliceO2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEntropyDecoderSpec.cxx
More file actions
230 lines (210 loc) · 10.6 KB
/
Copy pathEntropyDecoderSpec.cxx
File metadata and controls
230 lines (210 loc) · 10.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.
/// @file EntropyDecoderSpec.cxx
#include <vector>
#include "Framework/ControlService.h"
#include "Framework/ConfigParamRegistry.h"
#include "Framework/CCDBParamSpec.h"
#include "DataFormatsITSMFT/CompCluster.h"
#include "ITSMFTWorkflow/EntropyDecoderSpec.h"
#include "ITSMFTReconstruction/ClustererParam.h"
#include "DetectorsCommonDataFormats/DetectorNameConf.h"
#include "DataFormatsITSMFT/DPLAlpideParam.h"
#include "DataFormatsITSMFT/PhysTrigger.h"
using namespace o2::framework;
namespace o2
{
namespace itsmft
{
template <int N>
std::string EntropyDecoderSpec<N>::getBinding(const std::string& name, int spec)
{
return fmt::format("{}_{}", name, spec);
}
template <int N>
EntropyDecoderSpec<N>::EntropyDecoderSpec(int verbosity, bool doStag, bool selectIRFrames, bool getDigits, const std::string& ctfdictOpt)
: mCTFCoder(o2::ctf::CTFCoderBase::OpType::Decoder, doStag, ctfdictOpt), mDoStaggering(doStag), mSelectIRFrames(selectIRFrames), mGetDigits(getDigits)
{
mTimer.Stop();
mTimer.Reset();
mCTFCoder.setVerbosity(verbosity);
mCTFCoder.setDictBinding(std::string("ctfdict_") + ID.getName());
}
template <int N>
void EntropyDecoderSpec<N>::init(o2::framework::InitContext& ic)
{
mCTFCoder.template init<CTF>(ic);
mMaskNoise = ic.options().get<bool>("mask-noise");
mUseClusterDictionary = !ic.options().get<bool>("ignore-cluster-dictionary");
}
template <int N>
void EntropyDecoderSpec<N>::run(ProcessingContext& pc)
{
if (pc.services().get<o2::framework::TimingInfo>().globalRunNumberChanged) {
mTimer.Reset();
}
auto cput = mTimer.CpuTime();
mTimer.Start(false);
o2::ctf::CTFIOSize iosize;
size_t ndigcl = 0, nrofs = 0;
updateTimeDependentParams(pc);
std::string nm = ID.getName();
uint32_t nLayers = mDoStaggering ? DPLAlpideParam<N>::getNLayers() : 1;
for (uint32_t iLayer = 0; iLayer < nLayers; iLayer++) {
auto buff = pc.inputs().get<gsl::span<o2::ctf::BufferType>>(getBinding(nm + "CTF", iLayer));
// since the buff is const, we cannot use EncodedBlocks::relocate directly, instead we wrap its data to another flat object
// const auto ctfImage = o2::itsmft::CTF::getImage(buff.data());
if (buff.size()) {
const auto& ctf = o2::itsmft::CTF::getImage(buff.data());
if (ctf.getHeader().maxStreams != nLayers) {
LOGP(fatal, "Number of streams {} in the CTF header is not equal to NLayers {} from AlpideParam in {}staggered mode",
ctf.getHeader().maxStreams, nLayers, mDoStaggering ? "" : "non-");
}
}
// this produces weird memory problems in unrelated devices, to be understood
// auto& trigs = pc.outputs().make<std::vector<o2::itsmft::PhysTrigger>>(OutputRef{"phystrig"}); // dummy output
auto& rofs = pc.outputs().make<std::vector<o2::itsmft::ROFRecord>>(OutputRef{nm + "ROframes", iLayer});
if (mGetDigits) {
auto& digits = pc.outputs().make<std::vector<o2::itsmft::Digit>>(OutputRef{nm + "Digits", iLayer});
if (buff.size()) {
iosize += mCTFCoder.decode(o2::itsmft::CTF::getImage(buff.data()), rofs, digits, mNoiseMap, mPattIdConverter);
}
ndigcl += digits.size();
nrofs += rofs.size();
} else {
auto& compcl = pc.outputs().make<std::vector<o2::itsmft::CompClusterExt>>(OutputRef{nm + "compClusters", iLayer});
auto& patterns = pc.outputs().make<std::vector<unsigned char>>(OutputRef{nm + "patterns", iLayer});
if (buff.size()) {
iosize += mCTFCoder.decode(o2::itsmft::CTF::getImage(buff.data()), rofs, compcl, patterns, mNoiseMap, mPattIdConverter);
}
ndigcl += compcl.size();
}
if (mSelectIRFrames) {
int nSelected{0};
/// mask ROF entries not matching with selected IRFrames
auto irFrames = pc.inputs().get<std::vector<o2::dataformats::IRFrame>>("selIRFrames");
for (auto& rof : rofs) {
bool masked = true;
for (const auto& irFrame : irFrames) {
const auto irStart = rof.getBCData(), irEnd = irStart + DPLAlpideParam<N>::Instance().getROFLengthInBC(iLayer);
o2::dataformats::IRFrame irROF(irStart, irEnd);
if (irFrame.isOutside(irROF) == o2::dataformats::IRFrame::Relation::Inside) {
++nSelected;
masked = false;
break;
}
}
if (masked) {
rof.setNEntries(0);
}
}
LOGP(info, "Selected {} out of {} rofs", nSelected, rofs.size());
}
}
pc.outputs().snapshot({nm + "ctfrep", 0}, iosize);
mTimer.Stop();
LOGP(info, "Decoded {} {} in {} ROFs of {} streams ({}) in {}staggerd mode in {} s", ndigcl, mGetDigits ? "digits" : "clusters",
nrofs, nLayers, iosize.asString(), mDoStaggering ? "" : "non-", mTimer.CpuTime() - cput);
}
template <int N>
void EntropyDecoderSpec<N>::endOfStream(EndOfStreamContext& ec)
{
LOGP(info, "{} Entropy Decoding total timing: Cpu: {:.3e} Real: {:.3e} s in {} slots",
Origin.as<std::string>(), mTimer.CpuTime(), mTimer.RealTime(), mTimer.Counter() - 1);
}
template <int N>
void EntropyDecoderSpec<N>::updateTimeDependentParams(ProcessingContext& pc)
{
std::string nm = ID.getName();
if (pc.services().get<o2::framework::TimingInfo>().globalRunNumberChanged) { // this params need to be queried only once
if (mMaskNoise) {
pc.inputs().get<o2::itsmft::NoiseMap*>(nm + "noise");
}
if (mGetDigits || mMaskNoise) {
pc.inputs().get<o2::itsmft::TopologyDictionary*>(nm + "cldict");
}
}
pc.inputs().get<o2::itsmft::DPLAlpideParam<N>*>(nm + "alppar");
mCTFCoder.updateTimeDependentParams(pc, true);
}
template <int N>
void EntropyDecoderSpec<N>::finaliseCCDB(o2::framework::ConcreteDataMatcher& matcher, void* obj)
{
if (matcher == ConcreteDataMatcher(Origin, "NOISEMAP", 0)) {
mNoiseMap = (o2::itsmft::NoiseMap*)obj;
LOG(info) << Origin.as<std::string>() << " noise map updated";
return;
}
if (matcher == ConcreteDataMatcher(Origin, "CLUSDICT", 0)) {
LOG(info) << Origin.as<std::string>() << " cluster dictionary updated" << (!mUseClusterDictionary ? " but its using is disabled" : "");
mPattIdConverter.setDictionary((const TopologyDictionary*)obj);
return;
}
if (matcher == ConcreteDataMatcher(Origin, "ALPIDEPARAM", 0)) {
LOG(info) << "Alpide param updated";
return;
}
if (mCTFCoder.template finaliseCCDB<CTF>(matcher, obj)) {
return;
}
}
template <int N>
DataProcessorSpec getEntropyDecoderSpec(int verbosity, bool doStag, bool getDigits, bool selectIRFrames, unsigned int sspec, const std::string& ctfdictOpt)
{
constexpr o2::header::DataOrigin Origin{N == o2::detectors::DetID::ITS ? o2::header::gDataOriginITS : o2::header::gDataOriginMFT};
constexpr o2::detectors::DetID ID{N == o2::detectors::DetID::ITS ? o2::detectors::DetID::ITS : o2::detectors::DetID::MFT};
uint32_t nLayers = doStag ? DPLAlpideParam<N>::getNLayers() : 1;
std::vector<InputSpec> inputs;
std::vector<OutputSpec> outputs;
// this produces weird memory problems in unrelated devices, to be understood
// outputs.emplace_back(OutputSpec{{"phystrig"}, Origin, "PHYSTRIG", 0, Lifetime::Timeframe});
std::string nm = ID.getName();
for (uint32_t iLayer = 0; iLayer < nLayers; ++iLayer) {
if (getDigits) {
outputs.emplace_back(OutputSpec{{nm + "Digits"}, Origin, "DIGITS", iLayer, Lifetime::Timeframe});
outputs.emplace_back(OutputSpec{{nm + "ROframes"}, Origin, "DIGITSROF", iLayer, Lifetime::Timeframe});
} else {
outputs.emplace_back(OutputSpec{{nm + "compClusters"}, Origin, "COMPCLUSTERS", iLayer, Lifetime::Timeframe});
outputs.emplace_back(OutputSpec{{nm + "ROframes"}, Origin, "CLUSTERSROF", iLayer, Lifetime::Timeframe});
outputs.emplace_back(OutputSpec{{nm + "patterns"}, Origin, "PATTERNS", iLayer, Lifetime::Timeframe});
}
inputs.emplace_back(EntropyDecoderSpec<N>::getBinding(nm + "CTF", iLayer), Origin, "CTFDATA", sspec * 100 + iLayer, Lifetime::Timeframe);
}
outputs.emplace_back(OutputSpec{{nm + "ctfrep"}, Origin, "CTFDECREP", 0, Lifetime::Timeframe});
inputs.emplace_back(nm + "alppar", Origin, "ALPIDEPARAM", 0, Lifetime::Condition, ccdbParamSpec(fmt::format("{}/Config/AlpideParam", Origin.as<std::string>())));
inputs.emplace_back(nm + "noise", Origin, "NOISEMAP", 0, Lifetime::Condition, ccdbParamSpec(fmt::format("{}/Calib/NoiseMap", Origin.as<std::string>())));
inputs.emplace_back(nm + "cldict", Origin, "CLUSDICT", 0, Lifetime::Condition, ccdbParamSpec(fmt::format("{}/Calib/ClusterDictionary", Origin.as<std::string>())));
if (ctfdictOpt.empty() || ctfdictOpt == "ccdb") {
inputs.emplace_back(std::string{"ctfdict_"} + ID.getName(), Origin, "CTFDICT", 0, Lifetime::Condition, ccdbParamSpec(fmt::format("{}/Calib/CTFDictionaryTree", Origin.as<std::string>())));
}
inputs.emplace_back("trigoffset", "CTP", "Trig_Offset", 0, Lifetime::Condition, ccdbParamSpec("CTP/Config/TriggerOffsets"));
if (selectIRFrames) {
inputs.emplace_back("selIRFrames", "CTF", "SELIRFRAMES", Lifetime::Timeframe);
}
return DataProcessorSpec{
Origin == o2::header::gDataOriginITS ? "its-entropy-decoder" : "mft-entropy-decoder",
inputs,
outputs,
AlgorithmSpec{adaptFromTask<EntropyDecoderSpec<N>>(verbosity, doStag, selectIRFrames, getDigits, ctfdictOpt)},
Options{{"mask-noise", VariantType::Bool, false, {"apply noise mask to digits or clusters (involves reclusterization)"}},
{"ignore-cluster-dictionary", VariantType::Bool, false, {"do not use cluster dictionary, always store explicit patterns"}},
{"ans-version", VariantType::String, {"version of ans entropy coder implementation to use"}}}};
}
framework::DataProcessorSpec getITSEntropyDecoderSpec(int verbosity, bool doStag, bool getDigits, bool selectIRFrames, unsigned int sspec, const std::string& ctfdictOpt)
{
return getEntropyDecoderSpec<o2::detectors::DetID::ITS>(verbosity, doStag, getDigits, selectIRFrames, sspec, ctfdictOpt);
}
framework::DataProcessorSpec getMFTEntropyDecoderSpec(int verbosity, bool doStag, bool getDigits, bool selectIRFrames, unsigned int sspec, const std::string& ctfdictOpt)
{
return getEntropyDecoderSpec<o2::detectors::DetID::MFT>(verbosity, doStag, getDigits, selectIRFrames, sspec, ctfdictOpt);
}
} // namespace itsmft
} // namespace o2