Project
Loading...
Searching...
No Matches
entropy-encoder-workflow.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
19#include "Framework/Task.h"
20#include "MCHCTF/CTFCoder.h"
21#include <TStopwatch.h>
22#include <vector>
23
24using namespace o2::framework;
25
26namespace o2
27{
28namespace mch
29{
30
32{
33 public:
34 EntropyEncoderSpec(bool selIR);
35 ~EntropyEncoderSpec() 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::mch::CTFCoder mCTFCoder;
43 bool mSelIR = false;
44 TStopwatch mTimer;
45};
46
47EntropyEncoderSpec::EntropyEncoderSpec(bool selIR) : mCTFCoder(o2::ctf::CTFCoderBase::OpType::Encoder), mSelIR(selIR)
48{
49 mTimer.Stop();
50 mTimer.Reset();
51}
52
54{
55 if (mCTFCoder.finaliseCCDB<CTF>(matcher, obj)) {
56 return;
57 }
58}
59
61{
62 mCTFCoder.init<CTF>(ic);
63}
64
66{
67 auto cput = mTimer.CpuTime();
68 mTimer.Start(false);
69 mCTFCoder.updateTimeDependentParams(pc, true);
70 auto rofs = pc.inputs().get<gsl::span<o2::mch::ROFRecord>>("rofs", 0);
71 auto digits = pc.inputs().get<gsl::span<o2::mch::Digit>>("digits", 0);
72 if (mSelIR) {
73 mCTFCoder.setSelectedIRFrames(pc.inputs().get<gsl::span<o2::dataformats::IRFrame>>("selIRFrames"));
74 }
75 auto& buffer = pc.outputs().make<std::vector<o2::ctf::BufferType>>(Output{"MCH", "CTFDATA", 0});
76 auto iosize = mCTFCoder.encode(buffer, rofs, digits);
77 pc.outputs().snapshot({"ctfrep", 0}, iosize);
78 mTimer.Stop();
79 LOG(info) << iosize.asString() << " in " << mTimer.CpuTime() - cput << " s";
80}
81
83{
84 LOGF(info, "MCH Entropy Encoding total timing: Cpu: %.3e Real: %.3e s in %d slots",
85 mTimer.CpuTime(), mTimer.RealTime(), mTimer.Counter() - 1);
86}
87
89{
90 std::vector<InputSpec> inputs;
91 inputs.emplace_back("rofs", "MCH", "DIGITROFS", 0, Lifetime::Timeframe);
92 inputs.emplace_back("digits", "MCH", "DIGITS", 0, Lifetime::Timeframe);
93 inputs.emplace_back("ctfdict", "MCH", "CTFDICT", 0, Lifetime::Condition, ccdbParamSpec("MCH/Calib/CTFDictionaryTree"));
94 if (selIR) {
95 inputs.emplace_back("selIRFrames", "CTF", "SELIRFRAMES", 0, Lifetime::Timeframe);
96 }
97 return DataProcessorSpec{
99 inputs,
100 Outputs{{"MCH", "CTFDATA", 0, Lifetime::Timeframe},
101 {{"ctfrep"}, "MCH", "CTFENCREP", 0, Lifetime::Timeframe}},
102 AlgorithmSpec{adaptFromTask<EntropyEncoderSpec>(selIR)},
103 Options{{"ctf-dict", VariantType::String, "ccdb", {"CTF dictionary: empty or ccdb=CCDB, none=no external dictionary otherwise: local filename"}},
104 {"irframe-margin-bwd", VariantType::UInt32, 0u, {"margin in BC to add to the IRFrame lower boundary when selection is requested"}},
105 {"irframe-margin-fwd", VariantType::UInt32, 0u, {"margin in BC to add to the IRFrame upper boundary when selection is requested"}},
106 {"mem-factor", VariantType::Float, 1.f, {"Memory allocation margin factor"}},
107 {"ans-version", VariantType::String, {"version of ans entropy coder implementation to use"}}}};
108}
109
110} // namespace mch
111} // namespace o2
112
113// ------------------------------------------------------------------
114
115// we need to add workflow options before including Framework/runDataProcessing
116void customize(std::vector<o2::framework::ConfigParamSpec>& workflowOptions)
117{
118 // option allowing to set parameters
119 std::vector<ConfigParamSpec> options{
120 ConfigParamSpec{"configKeyValues", VariantType::String, "", {"Semicolon separated key=value strings"}},
121 ConfigParamSpec{"select-ir-frames", VariantType::Bool, false, {"Subscribe and filter according to external IR Frames"}}};
122
123 std::swap(workflowOptions, options);
124}
125
126// ------------------------------------------------------------------
127
129
131{
132 WorkflowSpec wf;
133 // Update the (declared) parameters if changed from the command line
134 o2::conf::ConfigurableParam::updateFromString(cfgc.options().get<std::string>("configKeyValues"));
135 bool selIR = cfgc.options().get<bool>("select-ir-frames");
136 wf.emplace_back(o2::mch::getEntropyEncoderSpec("mch-entropy-encoder", selIR));
137 return wf;
138}
class for entropy encoding/decoding of MCH digit data
void customize(std::vector< o2::framework::ConfigParamSpec > &workflowOptions)
WorkflowSpec defineDataProcessing(ConfigContext const &cfgc)
const char * specName
static void updateFromString(std::string const &)
void updateTimeDependentParams(o2::framework::ProcessingContext &pc, bool askTree=false)
void init(o2::framework::InitContext &ic)
void setSelectedIRFrames(const SPAN &sp)
bool finaliseCCDB(o2::framework::ConcreteDataMatcher &matcher, void *obj)
ConfigParamRegistry & options() const
void snapshot(const Output &spec, T const &object)
decltype(auto) make(const Output &spec, Args... args)
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.
o2::ctf::CTFIOSize encode(VEC &buff, const gsl::span< const ROFRecord > &rofData, const gsl::span< const Digit > &digData)
entropy-encode data to buffer with CTF
Definition CTFCoder.h:65
void finaliseCCDB(o2::framework::ConcreteDataMatcher &matcher, void *obj) final
void init(o2::framework::InitContext &ic) final
void run(o2::framework::ProcessingContext &pc) final
~EntropyEncoderSpec() override=default
void endOfStream(o2::framework::EndOfStreamContext &ec) final
This is invoked whenever we have an EndOfStream event.
GLuint buffer
Definition glcorearb.h:655
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< DataProcessorSpec > WorkflowSpec
std::vector< ConfigParamSpec > Options
std::vector< OutputSpec > Outputs
DataProcessorSpec getEntropyEncoderSpec(const char *specName, bool selIR)
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
wrapper for the Entropy-encoded clusters of the TF
Definition CTF.h:40
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"
std::vector< Digit > digits