Project
Loading...
Searching...
No Matches
EntropyEncoderSpec.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
15
17
18#include <vector>
19#include <unordered_map>
23#include "Framework/DataRef.h"
25#include "Headers/DataHeader.h"
28
29using namespace o2::framework;
30
31namespace o2
32{
33namespace mid
34{
35EntropyEncoderSpec::EntropyEncoderSpec(bool selIR, const std::string& ctfdictOpt) : mCTFCoder(o2::ctf::CTFCoderBase::OpType::Encoder, ctfdictOpt), mSelIR(selIR)
36{
37 mTimer.Stop();
38 mTimer.Reset();
39}
40
42{
43 if (mCTFCoder.finaliseCCDB<CTF>(matcher, obj)) {
44 return;
45 }
46}
47
49{
50 mCTFCoder.init<CTF>(ic);
51}
52
54{
55 auto cput = mTimer.CpuTime();
56 mTimer.Start(false);
57 mCTFCoder.updateTimeDependentParams(pc, true);
59 std::vector<InputSpec>
60 filter = {
61 {"check", ConcreteDataTypeMatcher{header::gDataOriginMID, "DATA"}, Lifetime::Timeframe},
62 {"check", ConcreteDataTypeMatcher{header::gDataOriginMID, "DATAROF"}, Lifetime::Timeframe},
63 };
64 size_t insize = 0;
65 for (auto const& inputRef : InputRecordWalker(pc.inputs(), filter)) {
66 auto const* dh = framework::DataRefUtils::getHeader<o2::header::DataHeader*>(inputRef);
67 if (dh->subSpecification >= NEvTypes) {
68 throw std::runtime_error(fmt::format("SubSpecification={} does not match EvenTypes for {}", dh->subSpecification, dh->dataDescription.as<std::string>()));
69 }
70 if (DataRefUtils::match(inputRef, "cols")) {
71 tfData.colData[dh->subSpecification] = pc.inputs().get<gsl::span<o2::mid::ColumnData>>(inputRef);
72 insize += tfData.colData[dh->subSpecification].size() * sizeof(o2::mid::ColumnData);
73 }
74 if (DataRefUtils::match(inputRef, "rofs")) {
75 tfData.rofData[dh->subSpecification] = pc.inputs().get<gsl::span<o2::mid::ROFRecord>>(inputRef);
76 insize += tfData.rofData[dh->subSpecification].size() * sizeof(o2::mid::ROFRecord);
77 }
78 }
79 if (mSelIR) {
80 mCTFCoder.setSelectedIRFrames(pc.inputs().get<gsl::span<o2::dataformats::IRFrame>>("selIRFrames"));
81 }
82 // build references for looping over the data in BC increasing direction
83 tfData.buildReferences(mCTFCoder.getIRFramesSelector());
84
85 auto& buffer = pc.outputs().make<std::vector<o2::ctf::BufferType>>(Output{header::gDataOriginMID, "CTFDATA", 0});
86 auto iosize = mCTFCoder.encode(buffer, tfData);
87 pc.outputs().snapshot({"ctfrep", 0}, iosize);
88 iosize.rawIn = insize;
89 if (mSelIR) {
90 mCTFCoder.getIRFramesSelector().clear();
91 }
92 mTimer.Stop();
93 LOG(info) << iosize.asString() << " in " << mTimer.CpuTime() - cput << " s";
94}
95
97{
98 LOGF(info, "MID Entropy Encoding total timing: Cpu: %.3e Real: %.3e s in %d slots",
99 mTimer.CpuTime(), mTimer.RealTime(), mTimer.Counter() - 1);
100}
101
102DataProcessorSpec getEntropyEncoderSpec(bool selIR, const std::string& ctfdictOpt)
103{
104 std::vector<InputSpec> inputs;
105 inputs.emplace_back("rofs", ConcreteDataTypeMatcher(header::gDataOriginMID, "DATAROF"), Lifetime::Timeframe);
106 inputs.emplace_back("cols", ConcreteDataTypeMatcher(header::gDataOriginMID, "DATA"), Lifetime::Timeframe);
107
108 if (ctfdictOpt.empty() || ctfdictOpt == "ccdb") {
109 inputs.emplace_back("ctfdict", header::gDataOriginMID, "CTFDICT", 0, Lifetime::Condition, ccdbParamSpec("MID/Calib/CTFDictionaryTree"));
110 }
111 if (selIR) {
112 inputs.emplace_back("selIRFrames", "CTF", "SELIRFRAMES", 0, Lifetime::Timeframe);
113 }
114 return DataProcessorSpec{
115 "mid-entropy-encoder",
116 inputs,
117 Outputs{{header::gDataOriginMID, "CTFDATA", 0, Lifetime::Timeframe},
118 {{"ctfrep"}, header::gDataOriginMID, "CTFENCREP", 0, Lifetime::Timeframe}},
119 AlgorithmSpec{adaptFromTask<EntropyEncoderSpec>(selIR, ctfdictOpt)},
120 Options{{"irframe-margin-bwd", VariantType::UInt32, 0u, {"margin in BC to add to the IRFrame lower boundary when selection is requested"}},
121 {"irframe-margin-fwd", VariantType::UInt32, 0u, {"margin in BC to add to the IRFrame upper boundary when selection is requested"}},
122 {"mem-factor", VariantType::Float, 1.f, {"Memory allocation margin factor"}},
123 {"ans-version", VariantType::String, {"version of ans entropy coder implementation to use"}}}};
124}
125} // namespace mid
126} // namespace o2
Declarations for CTFCoderBase class (support of external dictionaries)
A helper class to iteratate over all parts of all input routes.
Convert MID data to CTF (EncodedBlocks)
Definition of the Names Generator class.
void updateTimeDependentParams(o2::framework::ProcessingContext &pc, bool askTree=false)
void init(o2::framework::InitContext &ic)
void setSelectedIRFrames(const SPAN &sp)
o2::utils::IRFrameSelector & getIRFramesSelector()
bool finaliseCCDB(o2::framework::ConcreteDataMatcher &matcher, void *obj)
void snapshot(const Output &spec, T const &object)
decltype(auto) make(const Output &spec, Args... args)
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.
o2::ctf::CTFIOSize encode(VEC &buff, const CTFHelper::TFData &tfData)
entropy-encode data to buffer with CTF
Definition CTFCoder.h:60
void endOfStream(o2::framework::EndOfStreamContext &ec) final
This is invoked whenever we have an EndOfStream event.
void run(o2::framework::ProcessingContext &pc) final
void init(o2::framework::InitContext &ic) final
void finaliseCCDB(o2::framework::ConcreteDataMatcher &matcher, void *obj) final
EntropyEncoderSpec(bool selIR, const std::string &ctfdictOpt="none")
GLuint buffer
Definition glcorearb.h:655
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
Definition glcorearb.h:1308
constexpr o2::header::DataOrigin gDataOriginMID
Definition DataHeader.h:573
Defining PrimaryVertex explicitly as messageable.
std::vector< ConfigParamSpec > ccdbParamSpec(std::string const &path, int runDependent, std::vector< CCDBMetadata > metadata={}, int qrate=0)
std::vector< ConfigParamSpec > Options
std::vector< OutputSpec > Outputs
framework::DataProcessorSpec getEntropyEncoderSpec(bool selIR=false, const std::string &ctfdictOpt="none")
create a processor spec
constexpr uint32_t NEvTypes
Definition ROFRecord.h:37
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
static bool match(DataRef const &ref, const char *binding)
wrapper for the Entropy-encoded clusters of the TF
Definition CTF.h:41
Column data structure for MID.
Definition ColumnData.h:29
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"
CTFHelper::TFData tfData