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{
35
36EntropyEncoderSpec::EntropyEncoderSpec(bool selIR) : mCTFCoder(o2::ctf::CTFCoderBase::OpType::Encoder), mSelIR(selIR)
37{
38 mTimer.Stop();
39 mTimer.Reset();
40}
41
43{
44 if (mCTFCoder.finaliseCCDB<CTF>(matcher, obj)) {
45 return;
46 }
47}
48
50{
51 mCTFCoder.init<CTF>(ic);
52}
53
55{
56 auto cput = mTimer.CpuTime();
57 mTimer.Start(false);
58 mCTFCoder.updateTimeDependentParams(pc, true);
60 std::vector<InputSpec>
61 filter = {
62 {"check", ConcreteDataTypeMatcher{header::gDataOriginMID, "DATA"}, Lifetime::Timeframe},
63 {"check", ConcreteDataTypeMatcher{header::gDataOriginMID, "DATAROF"}, Lifetime::Timeframe},
64 };
65 size_t insize = 0;
66 for (auto const& inputRef : InputRecordWalker(pc.inputs(), filter)) {
67 auto const* dh = framework::DataRefUtils::getHeader<o2::header::DataHeader*>(inputRef);
68 if (dh->subSpecification >= NEvTypes) {
69 throw std::runtime_error(fmt::format("SubSpecification={} does not match EvenTypes for {}", dh->subSpecification, dh->dataDescription.as<std::string>()));
70 }
71 if (DataRefUtils::match(inputRef, "cols")) {
72 tfData.colData[dh->subSpecification] = pc.inputs().get<gsl::span<o2::mid::ColumnData>>(inputRef);
73 insize += tfData.colData[dh->subSpecification].size() * sizeof(o2::mid::ColumnData);
74 }
75 if (DataRefUtils::match(inputRef, "rofs")) {
76 tfData.rofData[dh->subSpecification] = pc.inputs().get<gsl::span<o2::mid::ROFRecord>>(inputRef);
77 insize += tfData.rofData[dh->subSpecification].size() * sizeof(o2::mid::ROFRecord);
78 }
79 }
80 if (mSelIR) {
81 mCTFCoder.setSelectedIRFrames(pc.inputs().get<gsl::span<o2::dataformats::IRFrame>>("selIRFrames"));
82 }
83 // build references for looping over the data in BC increasing direction
84 tfData.buildReferences(mCTFCoder.getIRFramesSelector());
85
86 auto& buffer = pc.outputs().make<std::vector<o2::ctf::BufferType>>(Output{header::gDataOriginMID, "CTFDATA", 0});
87 auto iosize = mCTFCoder.encode(buffer, tfData);
88 pc.outputs().snapshot({"ctfrep", 0}, iosize);
89 iosize.rawIn = insize;
90 if (mSelIR) {
91 mCTFCoder.getIRFramesSelector().clear();
92 }
93 mTimer.Stop();
94 LOG(info) << iosize.asString() << " in " << mTimer.CpuTime() - cput << " s";
95}
96
98{
99 LOGF(info, "MID Entropy Encoding total timing: Cpu: %.3e Real: %.3e s in %d slots",
100 mTimer.CpuTime(), mTimer.RealTime(), mTimer.Counter() - 1);
101}
102
104{
105 std::vector<InputSpec> inputs;
106 inputs.emplace_back("rofs", ConcreteDataTypeMatcher(header::gDataOriginMID, "DATAROF"), Lifetime::Timeframe);
107 inputs.emplace_back("cols", ConcreteDataTypeMatcher(header::gDataOriginMID, "DATA"), Lifetime::Timeframe);
108 inputs.emplace_back("ctfdict", header::gDataOriginMID, "CTFDICT", 0, Lifetime::Condition, ccdbParamSpec("MID/Calib/CTFDictionaryTree"));
109 if (selIR) {
110 inputs.emplace_back("selIRFrames", "CTF", "SELIRFRAMES", 0, Lifetime::Timeframe);
111 }
112 return DataProcessorSpec{
113 "mid-entropy-encoder",
114 inputs,
115 Outputs{{header::gDataOriginMID, "CTFDATA", 0, Lifetime::Timeframe},
116 {{"ctfrep"}, header::gDataOriginMID, "CTFENCREP", 0, Lifetime::Timeframe}},
117 AlgorithmSpec{adaptFromTask<EntropyEncoderSpec>(selIR)},
118 Options{{"ctf-dict", VariantType::String, "ccdb", {"CTF dictionary: empty or ccdb=CCDB, none=no external dictionary otherwise: local filename"}},
119 {"irframe-margin-bwd", VariantType::UInt32, 0u, {"margin in BC to add to the IRFrame lower boundary when selection is requested"}},
120 {"irframe-margin-fwd", VariantType::UInt32, 0u, {"margin in BC to add to the IRFrame upper boundary when selection is requested"}},
121 {"mem-factor", VariantType::Float, 1.f, {"Memory allocation margin factor"}},
122 {"ans-version", VariantType::String, {"version of ans entropy coder implementation to use"}}}};
123}
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
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.
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
std::vector< OutputSpec > Outputs
framework::DataProcessorSpec getEntropyEncoderSpec(bool selIR=false)
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