Line data Source code
1 : // $Id$
2 :
3 : //**************************************************************************
4 : //* This file is property of and copyright by the ALICE HLT Project *
5 : //* ALICE Experiment at CERN, All rights reserved. *
6 : //* *
7 : //* Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no> *
8 : //* for The ALICE HLT Project. *
9 : //* *
10 : //* Permission to use, copy, modify and distribute this software and its *
11 : //* documentation strictly for non-commercial purposes is hereby granted *
12 : //* without fee, provided that the above copyright notice appears in all *
13 : //* copies and that both the copyright notice and this permission notice *
14 : //* appear in the supporting documentation. The authors make no claims *
15 : //* about the suitability of this software for any purpose. It is *
16 : //* provided "as is" without express or implied warranty. *
17 : //**************************************************************************
18 :
19 : /// @file AliHLTDataDeflaterSimple.cxx
20 : /// @author Matthias Richter
21 : /// @date 2011-08-10
22 : /// @brief Simple deflater implementation storing frequent values below a
23 : /// maximum value with a reduced bit number and others with the full
24 : /// number of bits.
25 :
26 : #include "AliHLTDataDeflaterSimple.h"
27 : #include <memory>
28 : #include <algorithm>
29 : #include <iostream>
30 :
31 : /** ROOT macro for the implementation of ROOT specific class methods */
32 126 : ClassImp(AliHLTDataDeflaterSimple)
33 :
34 : AliHLTDataDeflaterSimple::AliHLTDataDeflaterSimple()
35 0 : : AliHLTDataDeflater()
36 0 : , fParameterDefinitions()
37 0 : {
38 : // see header file for class documentation
39 : // or
40 : // refer to README to build package
41 : // or
42 : // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
43 0 : }
44 :
45 : AliHLTDataDeflaterSimple::~AliHLTDataDeflaterSimple()
46 0 : {
47 : // destructor
48 0 : Clear();
49 :
50 0 : }
51 :
52 : int AliHLTDataDeflaterSimple::AddParameterDefinition(const char* name, int bitLength, int reducedBitLength)
53 : {
54 : /// add a parameter definition to the configuration, return reference id
55 0 : fParameterDefinitions.push_back(AliHLTDataDeflaterParameter(name, bitLength, reducedBitLength));
56 0 : int memberId=fParameterDefinitions.size()-1;
57 0 : if (DoStatistics()) {
58 0 : AddHistogram(memberId, name, bitLength);
59 0 : }
60 0 : return memberId;
61 0 : }
62 :
63 : bool AliHLTDataDeflaterSimple::OutputParameterBits( int memberId, AliHLTUInt64_t const & value )
64 : {
65 : // write bit pattern of a member to the current byte and position
66 0 : if (memberId>=(int)fParameterDefinitions.size()) return false;
67 :
68 0 : AliHLTUInt32_t switchBit=fParameterDefinitions[memberId].SwitchBit(value); // 0 -> reduced, 1 -> full
69 0 : AliHLTUInt64_t v=fParameterDefinitions[memberId].Value(value);
70 0 : AliHLTUInt32_t length=fParameterDefinitions[memberId].ValueLength(value);
71 0 : fParameterDefinitions[memberId].IncrementBitCount(value);
72 :
73 0 : if (DoStatistics())
74 0 : FillStatistics(memberId, length, value);
75 :
76 0 : if (!OutputBit(switchBit)) return false;
77 0 : return OutputBits(v, length);
78 0 : }
79 :
80 : void AliHLTDataDeflaterSimple::Clear(Option_t * option)
81 : {
82 : // internal cleanup
83 : unsigned i=0;
84 0 : for (vector<AliHLTDataDeflaterParameter>::iterator m=fParameterDefinitions.begin();
85 0 : m!=fParameterDefinitions.end(); m++, i++) {
86 0 : m->ResetBitCount();
87 : }
88 0 : AliHLTDataDeflater::Clear(option);
89 0 : }
90 :
91 : void AliHLTDataDeflaterSimple::Print(Option_t *option) const
92 : {
93 : // print info
94 0 : Print(cout, option);
95 0 : }
96 :
97 : void AliHLTDataDeflaterSimple::Print(ostream& out, Option_t *option) const
98 : {
99 : // print to stream
100 0 : out << "AliHLTDataDeflaterSimple:" << endl;
101 : AliHLTUInt64_t bitCount=0;
102 : AliHLTUInt64_t fullSize=0;
103 0 : for (vector<AliHLTDataDeflaterParameter>::const_iterator m=fParameterDefinitions.begin();
104 0 : m!=fParameterDefinitions.end(); m++) {
105 0 : cout << " "; m->Print(option);
106 0 : bitCount+=m->GetBitCount();
107 0 : fullSize+=m->GetValueCount()*m->GetBitLength();
108 : }
109 0 : out << " total: " << bitCount << "/" << fullSize << " " << (fullSize>0?float(bitCount)/fullSize:0.0) << endl;
110 0 : }
111 :
112 : void AliHLTDataDeflaterSimple::AliHLTDataDeflaterParameter::Print(const char* /*option*/) const
113 : {
114 : // print info
115 0 : cout << fName << " (" << fFullBitLength << "," << fReducedBitLength << "): "
116 0 : << fValueCount << " entries "
117 0 : << fBitCount << "/" << fFullBitLength*fValueCount;
118 0 : if (fFullBitLength && fValueCount) {
119 0 : cout << " " << float(fBitCount)/(fValueCount*fFullBitLength);
120 0 : }
121 0 : cout << endl;
122 0 : }
123 :
124 : ostream& operator<<(ostream &out, const AliHLTDataDeflaterSimple& me)
125 : {
126 0 : me.Print(out);
127 0 : return out;
128 : }
|