]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/BASE/AliHLTDataDeflaterSimple.h
correcting a typo in initialization
[u/mrichter/AliRoot.git] / HLT / BASE / AliHLTDataDeflaterSimple.h
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  */
30 class AliHLTDataDeflaterSimple : public AliHLTDataDeflater
31 {
32 public:
33   /// standard constructor
34   AliHLTDataDeflaterSimple();
35   /// destructor
36   ~AliHLTDataDeflaterSimple();
37
38   /// @class AliHLTDataDeflaterParameter definition of parameters
39   class AliHLTDataDeflaterParameter {
40   public:
41     AliHLTDataDeflaterParameter()
42       : fName(), fFullBitLength(0), fReducedBitLength(0)
43       , fMax(0), fMaxReduced(0)
44       , fMask(0), fMaskReduced(0)
45       , fValueCount(0), fBitCount(0) {}
46
47     AliHLTDataDeflaterParameter(const char* name, int length, int reduced)
48       : fName(name), fFullBitLength(length), fReducedBitLength(reduced)
49       , fMax((((AliHLTUInt64_t)0x1)<<length)-1), fMaxReduced((((AliHLTUInt64_t)0x1)<<reduced)-1)
50       , fMask(fMax), fMaskReduced(fMaxReduced) 
51       , fValueCount(0), fBitCount(0) {}
52
53     AliHLTDataDeflaterParameter(const AliHLTDataDeflaterParameter& src)
54       : fName(src.fName), fFullBitLength(src.fFullBitLength), fReducedBitLength(src.fReducedBitLength)
55       , fMax(src.fMax), fMaxReduced(src.fMaxReduced)
56       , fMask(src.fMask), fMaskReduced(src.fMaskReduced) 
57       , fValueCount(0), fBitCount(0) {}
58
59     AliHLTDataDeflaterParameter& operator=(const AliHLTDataDeflaterParameter& src) {
60       fName=src.fName; fFullBitLength=src.fFullBitLength; fReducedBitLength=src.fReducedBitLength;
61       fMax=src.fMax; fMaxReduced=src.fMaxReduced;
62       fMask=src.fMask; fMaskReduced=src.fMaskReduced;
63       fValueCount=src.fValueCount; fBitCount=src.fBitCount;
64       return *this;
65     }
66
67     ~AliHLTDataDeflaterParameter() {}
68
69     const char* GetName() const {return fName.c_str();}
70     AliHLTUInt64_t Value(const AliHLTUInt64_t& value) const {
71       return value>fMax?fMax:value;
72     }
73     AliHLTUInt32_t ValueLength(const AliHLTUInt64_t& value) const{
74       return value>fMaxReduced?fFullBitLength:fReducedBitLength;
75     }
76     AliHLTUInt32_t SwitchBit(const AliHLTUInt64_t& value) const {
77       return value>fMaxReduced;
78     }
79     const int& GetBitLength() const {return fFullBitLength;}
80     const int& GetReducedBitLength() const {return fReducedBitLength;}
81     const AliHLTUInt64_t& GetMax() const {return fMax;}
82     const AliHLTUInt64_t& GetMaxReduced() const {return fMaxReduced;}
83     const AliHLTUInt64_t& GetMask() const {return fMask;}
84     const AliHLTUInt64_t& GetReducedMask() const {return fMaskReduced;}
85
86     const AliHLTUInt32_t& GetBitCount() const {return fBitCount;}
87     const AliHLTUInt32_t& GetValueCount() const {return fValueCount;}
88     void IncrementBitCount(const AliHLTUInt64_t& value) {
89       fBitCount+=(value>fMaxReduced?fFullBitLength:fReducedBitLength)+1;
90       fValueCount++;
91     }
92     void ResetBitCount() {fValueCount=0; fBitCount=0;}
93     void Print(const char* option="") const;
94
95   private:
96     std::string fName; //!
97     int fFullBitLength; //!
98     int fReducedBitLength; //!
99     AliHLTUInt64_t fMax; //!
100     AliHLTUInt64_t fMaxReduced; //!
101     AliHLTUInt64_t fMask; //!
102     AliHLTUInt64_t fMaskReduced; //!
103     AliHLTUInt32_t fValueCount; //!
104     AliHLTUInt32_t fBitCount; //!
105   };
106
107   /// add a parameter definition to the configuration, return reference id
108   int AddParameterDefinition(const char* name, int bitLength, int reducedBitLength) {
109     fParameterDefinitions.push_back(AliHLTDataDeflaterParameter(name, bitLength, reducedBitLength));
110     return fParameterDefinitions.size()-1;
111   }
112
113   /// inherited from AliHLTDataDeflater: write bit pattern according to configuration
114   virtual bool OutputParameterBits( int parameterId, AliHLTUInt64_t const & value );
115
116   /// clear the object and reset pointer references
117   virtual void Clear(Option_t * /*option*/ ="");
118
119   /// print info
120   virtual void Print(Option_t *option="") const;
121
122   /// print info
123   virtual void Print(ostream& out, Option_t *option="") const;
124
125   /// DataDeflaterSimple has deflater version 1
126   virtual int GetDeflaterVersion() const {return 1;}
127
128  protected:
129  private:
130   vector<AliHLTDataDeflaterParameter> fParameterDefinitions; //!
131
132   ClassDef(AliHLTDataDeflaterSimple, 0)
133 };
134
135 ostream& operator<<(ostream &out, const AliHLTDataDeflaterSimple& me);
136
137 #endif