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 *
9 /// @file AliHLTDataDeflaterSimple.h
10 /// @author Matthias Richter
12 /// @brief Data deflater class storing only necessary bits
13 /// @note Code original from AliHLTTPCCompModelDeflater
15 #include "AliHLTDataDeflater.h"
23 * @class AliHLTDataDeflaterSimple
24 * Simple deflater implementation storing frequent values below a
25 * maximum value with a reduced bit number and others with the full
26 * number of bits. The reduced value is indicated by a preceeding '0'
27 * and the full bit by '1'. The algorithm can be applied to data with an
28 * occurrence distribution peaking close to zero and having less frequent
29 * occurrence at higher values.
31 * @ingroup alihlt_base
33 class AliHLTDataDeflaterSimple : public AliHLTDataDeflater
36 /// standard constructor
37 AliHLTDataDeflaterSimple();
39 ~AliHLTDataDeflaterSimple();
41 /// @class AliHLTDataDeflaterParameter definition of parameters
42 class AliHLTDataDeflaterParameter {
44 AliHLTDataDeflaterParameter()
45 : fName(), fFullBitLength(0), fReducedBitLength(0)
46 , fMax(0), fMaxReduced(0)
47 , fMask(0), fMaskReduced(0)
48 , fValueCount(0), fBitCount(0) {}
50 AliHLTDataDeflaterParameter(const char* name, int length, int reduced)
51 : fName(name), fFullBitLength(length), fReducedBitLength(reduced)
52 , fMax((((AliHLTUInt64_t)0x1)<<length)-1), fMaxReduced((((AliHLTUInt64_t)0x1)<<reduced)-1)
53 , fMask(fMax), fMaskReduced(fMaxReduced)
54 , fValueCount(0), fBitCount(0) {}
56 AliHLTDataDeflaterParameter(const AliHLTDataDeflaterParameter& src)
57 : fName(src.fName), fFullBitLength(src.fFullBitLength), fReducedBitLength(src.fReducedBitLength)
58 , fMax(src.fMax), fMaxReduced(src.fMaxReduced)
59 , fMask(src.fMask), fMaskReduced(src.fMaskReduced)
60 , fValueCount(0), fBitCount(0) {}
62 AliHLTDataDeflaterParameter& operator=(const AliHLTDataDeflaterParameter& src) {
63 if (this==&src) return *this;
64 fName=src.fName; fFullBitLength=src.fFullBitLength; fReducedBitLength=src.fReducedBitLength;
65 fMax=src.fMax; fMaxReduced=src.fMaxReduced;
66 fMask=src.fMask; fMaskReduced=src.fMaskReduced;
67 fValueCount=src.fValueCount; fBitCount=src.fBitCount;
71 ~AliHLTDataDeflaterParameter() {}
73 const char* GetName() const {return fName.c_str();}
74 AliHLTUInt64_t Value(const AliHLTUInt64_t& value) const {
75 return value>fMax?fMax:value;
77 AliHLTUInt32_t ValueLength(const AliHLTUInt64_t& value) const{
78 return value>fMaxReduced?fFullBitLength:fReducedBitLength;
80 AliHLTUInt32_t SwitchBit(const AliHLTUInt64_t& value) const {
81 return value>fMaxReduced;
83 const int& GetBitLength() const {return fFullBitLength;}
84 const int& GetReducedBitLength() const {return fReducedBitLength;}
85 const AliHLTUInt64_t& GetMax() const {return fMax;}
86 const AliHLTUInt64_t& GetMaxReduced() const {return fMaxReduced;}
87 const AliHLTUInt64_t& GetMask() const {return fMask;}
88 const AliHLTUInt64_t& GetReducedMask() const {return fMaskReduced;}
90 const AliHLTUInt32_t& GetBitCount() const {return fBitCount;}
91 const AliHLTUInt32_t& GetValueCount() const {return fValueCount;}
92 void IncrementBitCount(const AliHLTUInt64_t& value) {
93 fBitCount+=(value>fMaxReduced?fFullBitLength:fReducedBitLength)+1;
96 void ResetBitCount() {fValueCount=0; fBitCount=0;}
97 void Print(const char* option="") const;
100 std::string fName; //!
101 int fFullBitLength; //!
102 int fReducedBitLength; //!
103 AliHLTUInt64_t fMax; //!
104 AliHLTUInt64_t fMaxReduced; //!
105 AliHLTUInt64_t fMask; //!
106 AliHLTUInt64_t fMaskReduced; //!
107 AliHLTUInt32_t fValueCount; //!
108 AliHLTUInt32_t fBitCount; //!
111 /// add a parameter definition to the configuration, return reference id
112 int AddParameterDefinition(const char* name, int bitLength, int reducedBitLength);
114 /// add a histogram for deflater statistic of the corresponding parameter
115 int AddHistogram(TH1* h);
117 /// inherited from AliHLTDataDeflater: write bit pattern according to configuration
118 virtual bool OutputParameterBits( int parameterId, AliHLTUInt64_t const & value );
120 /// clear the object and reset pointer references
121 virtual void Clear(Option_t * /*option*/ ="");
124 virtual void Print(Option_t *option="") const;
127 virtual void Print(ostream& out, Option_t *option="") const;
129 /// save data according to option
130 virtual void SaveAs(const char *filename="",Option_t *option="") const;
132 /// DataDeflaterSimple has deflater version 1
133 virtual int GetDeflaterVersion() const {return 1;}
135 static float CalcEntropy(TH1* histo, const char* option="", int mode=0);
139 /// copy constructor prohibited
140 AliHLTDataDeflaterSimple(const AliHLTDataDeflaterSimple&);
141 /// assignment operator prohibited
142 AliHLTDataDeflaterSimple& operator=(const AliHLTDataDeflaterSimple&);
144 vector<AliHLTDataDeflaterParameter> fParameterDefinitions; //!
146 TObjArray* fHistograms; //! list of histograms for parameters
148 ClassDef(AliHLTDataDeflaterSimple, 0)
151 ostream& operator<<(ostream &out, const AliHLTDataDeflaterSimple& me);