]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/BASE/AliHLTDataDeflaterSimple.h
minor coverity defect: added protection for self-assignment
[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
a0d59d54 19class TObjArray;
20class TH1;
21
80fb7693 22/**
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.
30 *
31 * @ingroup alihlt_base
32 */
33class AliHLTDataDeflaterSimple : public AliHLTDataDeflater
34{
35public:
36 /// standard constructor
37 AliHLTDataDeflaterSimple();
38 /// destructor
39 ~AliHLTDataDeflaterSimple();
40
41 /// @class AliHLTDataDeflaterParameter definition of parameters
42 class AliHLTDataDeflaterParameter {
43 public:
44 AliHLTDataDeflaterParameter()
45 : fName(), fFullBitLength(0), fReducedBitLength(0)
46 , fMax(0), fMaxReduced(0)
47 , fMask(0), fMaskReduced(0)
48 , fValueCount(0), fBitCount(0) {}
49
50 AliHLTDataDeflaterParameter(const char* name, int length, int reduced)
51 : fName(name), fFullBitLength(length), fReducedBitLength(reduced)
276ca921 52 , fMax((((AliHLTUInt64_t)0x1)<<length)-1), fMaxReduced((((AliHLTUInt64_t)0x1)<<reduced)-1)
a6968cb3 53 , fMask(fMax), fMaskReduced(fMaxReduced)
80fb7693 54 , fValueCount(0), fBitCount(0) {}
55
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) {}
61
62 AliHLTDataDeflaterParameter& operator=(const AliHLTDataDeflaterParameter& src) {
5c8ae5fb 63 if (this==&src) return *this;
80fb7693 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;
68 return *this;
69 }
70
71 ~AliHLTDataDeflaterParameter() {}
72
73 const char* GetName() const {return fName.c_str();}
74 AliHLTUInt64_t Value(const AliHLTUInt64_t& value) const {
75 return value>fMax?fMax:value;
76 }
77 AliHLTUInt32_t ValueLength(const AliHLTUInt64_t& value) const{
78 return value>fMaxReduced?fFullBitLength:fReducedBitLength;
79 }
80 AliHLTUInt32_t SwitchBit(const AliHLTUInt64_t& value) const {
81 return value>fMaxReduced;
82 }
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;}
89
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;
94 fValueCount++;
95 }
96 void ResetBitCount() {fValueCount=0; fBitCount=0;}
97 void Print(const char* option="") const;
98
99 private:
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; //!
109 };
110
111 /// add a parameter definition to the configuration, return reference id
a0d59d54 112 int AddParameterDefinition(const char* name, int bitLength, int reducedBitLength);
113
114 /// add a histogram for deflater statistic of the corresponding parameter
115 int AddHistogram(TH1* h);
80fb7693 116
117 /// inherited from AliHLTDataDeflater: write bit pattern according to configuration
118 virtual bool OutputParameterBits( int parameterId, AliHLTUInt64_t const & value );
119
120 /// clear the object and reset pointer references
121 virtual void Clear(Option_t * /*option*/ ="");
122
123 /// print info
124 virtual void Print(Option_t *option="") const;
125
126 /// print info
127 virtual void Print(ostream& out, Option_t *option="") const;
128
02406b80 129 /// save data according to option
a0d59d54 130 virtual void SaveAs(const char *filename="",Option_t *option="") const;
131
f95bc7cd 132 /// DataDeflaterSimple has deflater version 1
133 virtual int GetDeflaterVersion() const {return 1;}
134
709053b2 135 static float CalcEntropy(TH1* histo, const char* option="", int mode=0);
136
80fb7693 137 protected:
138 private:
a0d59d54 139 /// copy constructor prohibited
140 AliHLTDataDeflaterSimple(const AliHLTDataDeflaterSimple&);
141 /// assignment operator prohibited
142 AliHLTDataDeflaterSimple& operator=(const AliHLTDataDeflaterSimple&);
143
80fb7693 144 vector<AliHLTDataDeflaterParameter> fParameterDefinitions; //!
145
a0d59d54 146 TObjArray* fHistograms; //! list of histograms for parameters
147
80fb7693 148 ClassDef(AliHLTDataDeflaterSimple, 0)
149};
150
151ostream& operator<<(ostream &out, const AliHLTDataDeflaterSimple& me);
152
153#endif