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{
31{
32 public:
33 EntropyEncoderSpec(bool selIR, const std::string& ctfdictOpt = "none");
34 ~EntropyEncoderSpec() override = default;
36 void init(o2::framework::InitContext& ic) final;
38 void finaliseCCDB(o2::framework::ConcreteDataMatcher& matcher, void* obj) final;
39
40 private:
41 o2::mch::CTFCoder mCTFCoder;
42 bool mSelIR = false;
43 TStopwatch mTimer;
44};
45
46EntropyEncoderSpec::EntropyEncoderSpec(bool selIR, const std::string& ctfdictOpt) : mCTFCoder(o2::ctf::CTFCoderBase::OpType::Encoder, ctfdictOpt), mSelIR(selIR)
47{
48 mTimer.Stop();
49 mTimer.Reset();
50}
51
53{
54 if (mCTFCoder.finaliseCCDB<CTF>(matcher, obj)) {
55 return;
56 }
57}
58
60{
61 mCTFCoder.init<CTF>(ic);
62}
63
65{
66 auto cput = mTimer.CpuTime();
67 mTimer.Start(false);
68 mCTFCoder.updateTimeDependentParams(pc, true);
69 auto rofs = pc.inputs().get<gsl::span<o2::mch::ROFRecord>>("rofs", 0);
70 auto digits = pc.inputs().get<gsl::span<o2::mch::Digit>>("digits", 0);
71 if (mSelIR) {
72 mCTFCoder.setSelectedIRFrames(pc.inputs().get<gsl::span<o2::dataformats::IRFrame>>("selIRFrames"));
73 }
74 auto& buffer = pc.outputs().make<std::vector<o2::ctf::BufferType>>(Output{"MCH", "CTFDATA", 0});
75 auto iosize = mCTFCoder.encode(buffer, rofs, digits);
76 pc.outputs().snapshot({"ctfrep", 0}, iosize);
77 mTimer.Stop();
78 LOG(info) << iosize.asString() << " in " << mTimer.CpuTime() - cput << " s";
79}
80
82{
83 LOGF(info, "MCH Entropy Encoding total timing: Cpu: %.3e Real: %.3e s in %d slots",
84 mTimer.CpuTime(), mTimer.RealTime(), mTimer.Counter() - 1);
85}
86
87DataProcessorSpec getEntropyEncoderSpec(const char* specName, bool selIR, const std::string& ctfdictOpt)
88{
89 std::vector<InputSpec> inputs;
90 inputs.emplace_back("rofs", "MCH", "DIGITROFS", 0, Lifetime::Timeframe);
91 inputs.emplace_back("digits", "MCH", "DIGITS", 0, Lifetime::Timeframe);
92
93 if (ctfdictOpt.empty() || ctfdictOpt == "ccdb") {
94 inputs.emplace_back("ctfdict", "MCH", "CTFDICT", 0, Lifetime::Condition, ccdbParamSpec("MCH/Calib/CTFDictionaryTree"));
95 }
96 if (selIR) {
97 inputs.emplace_back("selIRFrames", "CTF", "SELIRFRAMES", 0, Lifetime::Timeframe);
98 }
99 return DataProcessorSpec{
100 specName,
101 inputs,
102 Outputs{{"MCH", "CTFDATA", 0, Lifetime::Timeframe},
103 {{"ctfrep"}, "MCH", "CTFENCREP", 0, Lifetime::Timeframe}},
104 AlgorithmSpec{adaptFromTask<EntropyEncoderSpec>(selIR, ctfdictOpt)},
105 Options{{"irframe-margin-bwd", VariantType::UInt32, 0u, {"margin in BC to add to the IRFrame lower boundary when selection is requested"}},
106 {"irframe-margin-fwd", VariantType::UInt32, 0u, {"margin in BC to add to the IRFrame upper boundary when selection is requested"}},
107 {"mem-factor", VariantType::Float, 1.f, {"Memory allocation margin factor"}},
108 {"ans-version", VariantType::String, {"version of ans entropy coder implementation to use"}}}};
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{"ctf-dict", VariantType::String, "ccdb", {"CTF dictionary: empty or ccdb=CCDB, none=no external dictionary otherwise: local filename"}},
122 ConfigParamSpec{"select-ir-frames", VariantType::Bool, false, {"Subscribe and filter according to external IR Frames"}}};
123
124 std::swap(workflowOptions, options);
125}
126
127// ------------------------------------------------------------------
128
130
132{
133 WorkflowSpec wf;
134 // Update the (declared) parameters if changed from the command line
135 o2::conf::ConfigurableParam::updateFromString(cfgc.options().get<std::string>("configKeyValues"));
136 bool selIR = cfgc.options().get<bool>("select-ir-frames");
137 wf.emplace_back(o2::mch::getEntropyEncoderSpec("mch-entropy-encoder", selIR, cfgc.options().get<std::string>("ctf-dict")));
138 return wf;
139}
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
EntropyEncoderSpec(bool selIR, const std::string &ctfdictOpt="none")
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.
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, const std::string &ctfdictOpt)
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