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 fName=src.fName; fFullBitLength=src.fFullBitLength; fReducedBitLength=src.fReducedBitLength;
64 fMax=src.fMax; fMaxReduced=src.fMaxReduced;
65 fMask=src.fMask; fMaskReduced=src.fMaskReduced;
66 fValueCount=src.fValueCount; fBitCount=src.fBitCount;
70 ~AliHLTDataDeflaterParameter() {}
72 const char* GetName() const {return fName.c_str();}
73 AliHLTUInt64_t Value(const AliHLTUInt64_t& value) const {
74 return value>fMax?fMax:value;
76 AliHLTUInt32_t ValueLength(const AliHLTUInt64_t& value) const{
77 return value>fMaxReduced?fFullBitLength:fReducedBitLength;
79 AliHLTUInt32_t SwitchBit(const AliHLTUInt64_t& value) const {
80 return value>fMaxReduced;
82 const int& GetBitLength() const {return fFullBitLength;}
83 const int& GetReducedBitLength() const {return fReducedBitLength;}
84 const AliHLTUInt64_t& GetMax() const {return fMax;}
85 const AliHLTUInt64_t& GetMaxReduced() const {return fMaxReduced;}
86 const AliHLTUInt64_t& GetMask() const {return fMask;}
87 const AliHLTUInt64_t& GetReducedMask() const {return fMaskReduced;}
89 const AliHLTUInt32_t& GetBitCount() const {return fBitCount;}
90 const AliHLTUInt32_t& GetValueCount() const {return fValueCount;}
91 void IncrementBitCount(const AliHLTUInt64_t& value) {
92 fBitCount+=(value>fMaxReduced?fFullBitLength:fReducedBitLength)+1;
95 void ResetBitCount() {fValueCount=0; fBitCount=0;}
96 void Print(const char* option="") const;
99 std::string fName; //!
100 int fFullBitLength; //!
101 int fReducedBitLength; //!
102 AliHLTUInt64_t fMax; //!
103 AliHLTUInt64_t fMaxReduced; //!
104 AliHLTUInt64_t fMask; //!
105 AliHLTUInt64_t fMaskReduced; //!
106 AliHLTUInt32_t fValueCount; //!
107 AliHLTUInt32_t fBitCount; //!
110 /// add a parameter definition to the configuration, return reference id
111 int AddParameterDefinition(const char* name, int bitLength, int reducedBitLength);
113 /// add a histogram for deflater statistic of the corresponding parameter
114 int AddHistogram(TH1* h);
116 /// inherited from AliHLTDataDeflater: write bit pattern according to configuration
117 virtual bool OutputParameterBits( int parameterId, AliHLTUInt64_t const & value );
119 /// clear the object and reset pointer references
120 virtual void Clear(Option_t * /*option*/ ="");
123 virtual void Print(Option_t *option="") const;
126 virtual void Print(ostream& out, Option_t *option="") const;
128 /// safe statistics histograms to file
129 virtual void SaveAs(const char *filename="",Option_t *option="") const;
131 /// DataDeflaterSimple has deflater version 1
132 virtual int GetDeflaterVersion() const {return 1;}
134 static float CalcEntropy(TH1* histo, const char* option="", int mode=0);
138 /// copy constructor prohibited
139 AliHLTDataDeflaterSimple(const AliHLTDataDeflaterSimple&);
140 /// assignment operator prohibited
141 AliHLTDataDeflaterSimple& operator=(const AliHLTDataDeflaterSimple&);
143 vector<AliHLTDataDeflaterParameter> fParameterDefinitions; //!
145 TObjArray* fHistograms; //! list of histograms for parameters
147 ClassDef(AliHLTDataDeflaterSimple, 0)
150 ostream& operator<<(ostream &out, const AliHLTDataDeflaterSimple& me);