16#define BOOST_TEST_MODULE Test CTFEntropyCoder class
17#define BOOST_TEST_MAIN
18#define BOOST_TEST_DYN_LINK
29#include <boost/test/unit_test.hpp>
30#include <boost/mp11.hpp>
44using source_types = boost::mp11::mp_list<uint8_t, int8_t, uint16_t, int16_t, uint32_t, int32_t>;
46template <
typename source_T>
52 if (mSourceMessage.empty()) {
55 const size_t draws = (
max -
min) + 1;
56 const double probability = 0.5;
57 std::binomial_distribution<int64_t> dist(draws, probability);
58 mSourceMessage.resize(messageSize);
59 std::generate(mSourceMessage.begin(), mSourceMessage.end(), [&dist, &mt,
min]() ->
source_T { return static_cast<int64_t>(dist(mt)) + min; });
65 inline constexpr auto&
get() const noexcept {
return mSourceMessage; };
70 std::vector<source_T> mSourceMessage{};
81 if constexpr (std::is_same_v<uint8_t, T>) {
82 return sourceMessage8u.get();
83 }
else if constexpr (std::is_same_v<int8_t, T>) {
84 return sourceMessage8.
get();
85 }
else if constexpr (std::is_same_v<uint16_t, T>) {
86 return sourceMessage16u.
get();
87 }
else if constexpr (std::is_same_v<int16_t, T>) {
88 return sourceMessage16.
get();
89 }
else if constexpr (std::is_same_v<uint32_t, T>) {
90 return sourceMessage32u.get();
91 }
else if constexpr (std::is_same_v<int32_t, T>) {
92 return sourceMessage32.
get();
94 throw std::runtime_error{
"unsupported source type"};
110template <
typename source_IT>
113 using source_type =
typename std::iterator_traits<source_IT>::value_type;
117 entropyCoder.makeEncoder();
122 LOGP(info,
"dataset[{},{}], coder[{},{}]",
metrics.getDatasetProperties().min,
metrics.getDatasetProperties().max, *
metrics.getCoderProperties().min, *
metrics.getCoderProperties().max);
128 auto encoderEnd = entropyCoder.encode(begin,
end, encodeBuffer.data(), encodeBuffer.data() + encodeBuffer.size());
129 [[maybe_unused]]
auto literalsEnd = entropyCoder.writeIncompressible(literalSymbolsBuffer.data(), literalSymbolsBuffer.data() + literalSymbolsBuffer.size());
130 auto dictEnd = entropyCoder.writeDictionary(dictBuffer.data(), dictBuffer.data() + dictBuffer.size());
132 const auto& coderProperties =
metrics.getCoderProperties();
134 *coderProperties.min, *coderProperties.max,
135 *coderProperties.renormingPrecisionBits));
136 std::vector<source_type> literals(entropyCoder.getNIncompressibleSamples());
138 const auto& datasetPropterties =
metrics.getDatasetProperties();
139 rans::unpack(literalSymbolsBuffer.data(), literals.size(), literals.data(),
140 datasetPropterties.alphabetRangeBits, datasetPropterties.min);
142 size_t messageLength = std::distance(begin,
end);
143 std::vector<source_type> sourceBuffer(messageLength, 0);
145 decoder.process(encoderEnd, sourceBuffer.data(), messageLength, entropyCoder.getNStreams(), literals.end());
147 BOOST_CHECK_EQUAL_COLLECTIONS(sourceBuffer.begin(), sourceBuffer.end(), begin,
end);
152 std::vector<source_T> testMessage{};
153 encodeInplace(testMessage.data(), testMessage.data() + testMessage.size());
159 encodeInplace(testMessage.data(), testMessage.data() + testMessage.size());
168template <
typename value_T,
size_t shift>
173 template <
typename iterA_T,
typename iterB_T>
174 inline value_T
operator()(iterA_T iterA, iterB_T iterB)
const
176 return *iterB + (
static_cast<value_T
>(*iterA) << shift);
179 template <
typename iterA_T,
typename iterB_T>
182 *iterA =
value >> shift;
183 *iterB =
value & ((0x1 << shift) - 0x1);
187template <
typename iterA_T,
typename iterB_T,
typename F>
236 template <
typename T>
239 if constexpr (std::is_same_v<uint8_t, T>) {
241 }
else if constexpr (std::is_same_v<int8_t, T>) {
243 }
else if constexpr (std::is_same_v<uint16_t, T>) {
245 }
else if constexpr (std::is_same_v<int16_t, T>) {
247 }
else if constexpr (std::is_same_v<uint32_t, T>) {
249 }
else if constexpr (std::is_same_v<int32_t, T>) {
252 throw std::runtime_error{
"unsupported encoder type"};
256 template <
typename T>
259 if constexpr (std::is_same_v<uint8_t, T>) {
261 }
else if constexpr (std::is_same_v<int8_t, T>) {
263 }
else if constexpr (std::is_same_v<uint16_t, T>) {
265 }
else if constexpr (std::is_same_v<int16_t, T>) {
267 }
else if constexpr (std::is_same_v<uint32_t, T>) {
269 }
else if constexpr (std::is_same_v<int32_t, T>) {
272 throw std::runtime_error{
"unsupported encoder type"};
294template <
typename source_IT>
297 using source_type =
typename std::iterator_traits<source_IT>::value_type;
301 const size_t sourceExtent = std::distance(begin,
end);
302 std::vector<buffer_type> encodeBuffer(entropyCoder.template computePayloadSizeEstimate<buffer_type>(sourceExtent), 0);
303 auto encoderEnd = entropyCoder.encode(begin,
end, encodeBuffer.data(), encodeBuffer.data() + encodeBuffer.size());
305 std::vector<buffer_type> literalSymbolsBuffer(entropyCoder.template computePackedIncompressibleSize<buffer_type>(), 0);
306 [[maybe_unused]]
auto literalsEnd = entropyCoder.writeIncompressible(literalSymbolsBuffer.data(), literalSymbolsBuffer.data() + literalSymbolsBuffer.size());
310 std::vector<source_type> literals((entropyCoder.getNIncompressibleSamples()));
312 rans::unpack(literalSymbolsBuffer.data(), literals.size(), literals.data(),
313 entropyCoder.getIncompressibleSymbolPackingBits(), entropyCoder.getIncompressibleSymbolOffset());
315 size_t messageLength = std::distance(begin,
end);
316 std::vector<source_type> sourceBuffer(messageLength, 0);
318 decoder.process(encoderEnd, sourceBuffer.data(), messageLength, entropyCoder.getEncoder().getNStreams(), literals.end());
320 BOOST_CHECK_EQUAL_COLLECTIONS(sourceBuffer.begin(), sourceBuffer.end(), begin,
end);
325 std::vector<source_T> testMessage{};
326 encodeExternal(testMessage.data(), testMessage.data() + testMessage.size());
332 encodeExternal(testMessage.data(), testMessage.data() + testMessage.size());
unsigned short int uint16_t
configStandalone Reconstruction rec_tpc multiplier for the combined cluster track error during track following area in cm for the search of for z only used if decrease removal by when above this local occupancy rowx Shift of TPC revert cluster flag edge bit distance to edge exceeds this ZOffset for secondary multiple of radius max P of electron K BB bands crossing max P of electron p BB bands crossing max P of electron d BB bands crossing max P of electron t BB bands crossing min accepted dEdxMaxTPC of the track Additive extra cluster error for Y2 if edge flag set Additive extra cluster error for Y2 if single set Additive extra cluster error for Y2 if or single set Additive extra cluster error for Z2 if or single set Extra errors to add to track when crossing depending on addErrorsCECrossing Inner portion of y range in sector that is not used in searching for extrapolated track candidates factor2YS for track merging factor2K for track merging Margin in cm of Y position when rejecting edge clusters based on uncorrected track Y Max fraction of shared clusters for tracklet Except pad from cluster finding if total number of charges in a fragment is above this Except pad from cluster finding if number of consecutive charges in a fragment is above this Threshold where a timebin is considered disabling the noisy pad check for that pad Treat signal above this minimum as saturated Smoothing factor for the exponential Highly Ionising Particle tail filter Number of timebins to use for the averaging Add additional custom track errors when crossing relative as fraction of Do N fit passes in final fit of< 0:reject at max -n hits") AddOptionRTC(rejectIFCLowRadiusCluster, uint8_t, 1, "", 0, "Reject clusters that get the IFC mask error during refit") AddOptionRTC(dEdxTruncLow, uint8_t, 2, "", 0, "Low truncation threshold, fraction of 128") AddOptionRTC(dEdxTruncHigh, uint8_t, 77, "", 0, "High truncation threshold, fraction of 128") AddOptionRTC(extrapolationTracking, int8_t, 1, "", 0, "Enable Extrapolation Tracking(prolong tracks to adjacent sectors to find short segments)") AddOptionRTC(disableRefitAttachment, uint8_t, 0, "", 0, "Bitmask to disable certain attachment steps during refit(1:attachment, 2:propagation, 4:loop following, 8:mirroring)") AddOptionRTC(rejectionStrategy, uint8_t, o2::gpu::GPUSettings::RejectionStrategyA, "", 0, "Enable rejection of TPC clusters for compression(0=no, 1=strategy A, 2=strategy B)") AddOptionRTC(mergeLoopersAfterburner, uint8_t, 1, "", 0, "Run afterburner for additional looper merging") AddOptionRTC(compressionTypeMask, uint8_t, o2::gpu::GPUSettings::CompressionFull, "", 0, "TPC Compression mode bits(1=truncate charge/width LSB, 2=differences, 4=track-model)") AddOptionRTC(compressionSortOrder, uint8_t, o2::gpu::GPUSettings::SortTime, "", 0, "Sort order of TPC compression(0=time, 1=pad, 2=Z-time-pad, 3=Z-pad-time, 4=no sorting(use incoming order))") AddOptionRTC(sigBitsCharge, uint8_t, 4, "", 0, "Number of significant bits for TPC cluster charge in compression mode 1") AddOptionRTC(sigBitsWidth, uint8_t, 3, "", 0, "Number of significant bits for TPC cluster width in compression mode 1") AddOptionRTC(dropLoopers, uint8_t, 0, "", 0, "Drop looping tracks starting from second loop") AddOptionRTC(mergerInterpolateErrors, uint8_t, 1, "", 0, "Use interpolation instead of extrapolation for chi2 based cluster rejection") AddOptionRTC(mergerInterpolateRejectAlsoOnCurrentPosition, uint8_t, 1, "", 0, "When using mergerInterpolateErrors, reject based on chi2 twice computed with interpolated and current track position starting from NDF > mergerNonInterpolateRejectMinNDF Merge tracks accross the central electrode Enable PID response Add sub threshold clusters in TPC dEdx computation OR mask of TPC flags that will reject the cluster in alternative dEdx Reject edge clusters based on uncorrected track Y during track fit Increase decrease removal by when on this number of pads from the edge h configStandalone Reconstruction rec_trd Max chi2 for TRD tracklets to be matched to a track Chi2 cut for strict matching mode Number of sigmas for ITS TPC track time error estimate Addition to search road around track prolongation along Y in cm Optimal tracklet rphi resolution in maximum chi2 per attached tracklet for TRD tracks take into account the full likelihood of the slope including exponential tails Tracks with less attached tracklets are discarded after the tracking Post trigger Pile up integration time in BCs fits all iterations but the last one in projections Use material lookup table for TPC refit Apply workarounds to avoid cyclic merge should not be needed tpc dyn configStandalone Processing proc_rtc Replace constant variables static by constexpr expressions Compile RTC in deterministic with NO_FAST_MATH flags and GPUCA_DETERMINISTIC_MODE define Use RTC to optimize GPU code h configStandalone Processing proc_rtctech Use a file lock to serialize access to the cache folder int32_t
Interfaces for BitPacking using librans.
constexpr size_t MessageSize
ExternalEncoderDecoderProxy()
const auto & getEncoder() const noexcept
const auto & getDecoder() const noexcept
value_T operator()(iterA_T iterA, iterB_T iterB) const
void operator()(iterA_T iterA, iterB_T iterB, value_T value) const
SourceMessageProxy()=default
const auto & getMessage() const noexcept
constexpr source_T getMin() const noexcept
constexpr auto & get() const noexcept
constexpr source_T getMax() const noexcept
SourceMessage(size_t messageSize, source_T max=std::numeric_limits< source_T >::max(), source_T min=std::numeric_limits< source_T >::min())
size_t getIncompressibleSize(double_t safetyFactor=1.2) const
size_t getCompressedDatasetSize(double_t safetyFactor=1.2) const
size_t getCompressedDictionarySize(double_t safetyFactor=2) const
static constexpr decltype(auto) fromRenormed(const RenormedHistogramConcept< container_T > &renormed)
static constexpr decltype(auto) fromRenormed(const RenormedDenseHistogram< source_T > &renormed)
static factory classes for building histograms, encoders and decoders.
GLsizei GLenum const void GLuint GLsizei GLfloat * metrics
GLsizei const GLfloat * value
public interface for building and renorming histograms from source data.
public interface for rANS iterators.
constexpr size_t pow2(size_t n) noexcept
decltype(makeDenseEncoder<>::fromRenormed(RenormedDenseHistogram< source_T >{})) denseEncoder_type
decltype(makeDecoder<>::fromRenormed(RenormedDenseHistogram< source_T >{})) defaultDecoder_type
void unpack(const input_T *__restrict inputBegin, size_t extent, output_IT outputBegin, size_t packingWidth, typename std::iterator_traits< output_IT >::value_type offset=static_cast< typename std::iterator_traits< output_IT >::value_type >(0))
RenormedDenseHistogram< source_T > readRenormedDictionary(buffer_IT begin, buffer_IT end, source_T min, source_T max, size_t renormingPrecision)
decltype(auto) renorm(histogram_T histogram, size_t newPrecision, RenormingPolicy renormingPolicy=RenormingPolicy::Auto, size_t lowProbabilityCutoffBits=0)
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
BOOST_AUTO_TEST_CASE(FlatHisto)
static decltype(auto) fromSamples(source_IT begin, source_IT end, typename std::iterator_traits< source_IT >::value_type min, typename std::iterator_traits< source_IT >::value_type max)
boost::mp11::mp_list< uint8_t, int8_t, uint16_t, int16_t, uint32_t, int32_t > source_types
ExternalEncoderDecoderProxy ExternalEncoders
void encodeInplace(source_IT begin, source_IT end)
void encodeExternal(source_IT begin, source_IT end)
const SourceMessageProxy MessageProxy
auto makeInputIterators(iterA_T iterA, iterB_T iterB, size_t nElements, F functor)
BOOST_AUTO_TEST_CASE_TEMPLATE(testInplaceEncoderEmpty, source_T, source_types)