]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/BASE/AliHLTDataDeflaterSimple.h
Merge branch 'TPCdev' of https://git.cern.ch/reps/AliRoot into TPCdev
[u/mrichter/AliRoot.git] / HLT / BASE / AliHLTDataDeflaterSimple.h
CommitLineData
80fb7693 1//-*- Mode: C++ -*-
2// $Id$
3#ifndef ALIHLTDATADEFLATERSIMPLE_H
4#define ALIHLTDATADEFLATERSIMPLE_H
5//* This file is property of and copyright by the ALICE HLT Project *
6//* ALICE Experiment at CERN, All rights reserved. *
7//* See cxx source for full Copyright notice *
8
9/// @file AliHLTDataDeflaterSimple.h
10/// @author Matthias Richter
11/// @date 2011-08-10
12/// @brief Data deflater class storing only necessary bits
13/// @note Code original from AliHLTTPCCompModelDeflater
14
15#include "AliHLTDataDeflater.h"
16#include <vector>
17#include <string>
18
19/**
20 * @class AliHLTDataDeflaterSimple
21 * Simple deflater implementation storing frequent values below a
22 * maximum value with a reduced bit number and others with the full
23 * number of bits. The reduced value is indicated by a preceeding '0'
24 * and the full bit by '1'. The algorithm can be applied to data with an
25 * occurrence distribution peaking close to zero and having less frequent
26 * occurrence at higher values.
27 *
28 * @ingroup alihlt_base
29 */
30class AliHLTDataDeflaterSimple : public AliHLTDataDeflater
31{
32public:
33 /// standard constructor
34 AliHLTDataDeflaterSimple();
35 /// destructor
36 ~AliHLTDataDeflaterSimple();
37
ebf7a8e8
TB
38 /// @class AliHLTDataDeflaterParameter
39 // definition of parameters
80fb7693 40 class AliHLTDataDeflaterParameter {
41 public:
42 AliHLTDataDeflaterParameter()
43 : fName(), fFullBitLength(0), fReducedBitLength(0)
44 , fMax(0), fMaxReduced(0)
45 , fMask(0), fMaskReduced(0)
46 , fValueCount(0), fBitCount(0) {}
47
48 AliHLTDataDeflaterParameter(const char* name, int length, int reduced)
49 : fName(name), fFullBitLength(length), fReducedBitLength(reduced)
276ca921 50 , fMax((((AliHLTUInt64_t)0x1)<<length)-1), fMaxReduced((((AliHLTUInt64_t)0x1)<<reduced)-1)
a6968cb3 51 , fMask(fMax), fMaskReduced(fMaxReduced)
80fb7693 52 , fValueCount(0), fBitCount(0) {}
53
54 AliHLTDataDeflaterParameter(const AliHLTDataDeflaterParameter& src)
55 : fName(src.fName), fFullBitLength(src.fFullBitLength), fReducedBitLength(src.fReducedBitLength)
56 , fMax(src.fMax), fMaxReduced(src.fMaxReduced)
57 , fMask(src.fMask), fMaskReduced(src.fMaskReduced)
58 , fValueCount(0), fBitCount(0) {}
59
60 AliHLTDataDeflaterParameter& operator=(const AliHLTDataDeflaterParameter& src) {
5c8ae5fb 61 if (this==&src) return *this;
80fb7693 62 fName=src.fName; fFullBitLength=src.fFullBitLength; fReducedBitLength=src.fReducedBitLength;
63 fMax=src.fMax; fMaxReduced=src.fMaxReduced;
64 fMask=src.fMask; fMaskReduced=src.fMaskReduced;
65 fValueCount=src.fValueCount; fBitCount=src.fBitCount;
66 return *this;
67 }
68
69 ~AliHLTDataDeflaterParameter() {}
70
71 const char* GetName() const {return fName.c_str();}
72 AliHLTUInt64_t Value(const AliHLTUInt64_t& value) const {
73 return value>fMax?fMax:value;
74 }
75 AliHLTUInt32_t ValueLength(const AliHLTUInt64_t& value) const{
76 return value>fMaxReduced?fFullBitLength:fReducedBitLength;
77 }
78 AliHLTUInt32_t SwitchBit(const AliHLTUInt64_t& value) const {
79 return value>fMaxReduced;
80 }
81 const int& GetBitLength() const {return fFullBitLength;}
82 const int& GetReducedBitLength() const {return fReducedBitLength;}
83 const AliHLTUInt64_t& GetMax() const {return fMax;}
84 const AliHLTUInt64_t& GetMaxReduced() const {return fMaxReduced;}
85 const AliHLTUInt64_t& GetMask() const {return fMask;}
86 const AliHLTUInt64_t& GetReducedMask() const {return fMaskReduced;}
87
88 const AliHLTUInt32_t& GetBitCount() const {return fBitCount;}
89 const AliHLTUInt32_t& GetValueCount() const {return fValueCount;}
90 void IncrementBitCount(const AliHLTUInt64_t& value) {
91 fBitCount+=(value>fMaxReduced?fFullBitLength:fReducedBitLength)+1;
92 fValueCount++;
93 }
94 void ResetBitCount() {fValueCount=0; fBitCount=0;}
95 void Print(const char* option="") const;
96
97 private:
98 std::string fName; //!
99 int fFullBitLength; //!
100 int fReducedBitLength; //!
101 AliHLTUInt64_t fMax; //!
102 AliHLTUInt64_t fMaxReduced; //!
103 AliHLTUInt64_t fMask; //!
104 AliHLTUInt64_t fMaskReduced; //!
105 AliHLTUInt32_t fValueCount; //!
106 AliHLTUInt32_t fBitCount; //!
107 };
108
109 /// add a parameter definition to the configuration, return reference id
a0d59d54 110 int AddParameterDefinition(const char* name, int bitLength, int reducedBitLength);
111
80fb7693 112 /// inherited from AliHLTDataDeflater: write bit pattern according to configuration
113 virtual bool OutputParameterBits( int parameterId, AliHLTUInt64_t const & value );
114
115 /// clear the object and reset pointer references
116 virtual void Clear(Option_t * /*option*/ ="");
117
118 /// print info
119 virtual void Print(Option_t *option="") const;
120
121 /// print info
122 virtual void Print(ostream& out, Option_t *option="") const;
123
f95bc7cd 124 /// DataDeflaterSimple has deflater version 1
125 virtual int GetDeflaterVersion() const {return 1;}
126
80fb7693 127 protected:
128 private:
a0d59d54 129 /// copy constructor prohibited
130 AliHLTDataDeflaterSimple(const AliHLTDataDeflaterSimple&);
131 /// assignment operator prohibited
132 AliHLTDataDeflaterSimple& operator=(const AliHLTDataDeflaterSimple&);
133
80fb7693 134 vector<AliHLTDataDeflaterParameter> fParameterDefinitions; //!
135
136 ClassDef(AliHLTDataDeflaterSimple, 0)
137};
138
139ostream& operator<<(ostream &out, const AliHLTDataDeflaterSimple& me);
140
141#endif