]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/BASE/AliHLTDataDeflaterSimple.cxx
bugfix: printout using intermediate stringstream is not working, using cout directly...
[u/mrichter/AliRoot.git] / HLT / BASE / AliHLTDataDeflaterSimple.cxx
CommitLineData
80fb7693 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 */
32ClassImp(AliHLTDataDeflaterSimple)
33
34AliHLTDataDeflaterSimple::AliHLTDataDeflaterSimple()
35 : AliHLTDataDeflater()
36 , fParameterDefinitions()
37{
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}
44
45AliHLTDataDeflaterSimple::~AliHLTDataDeflaterSimple()
46{
47 // destructor
48 Clear();
49}
50
51bool AliHLTDataDeflaterSimple::OutputParameterBits( int memberId, AliHLTUInt64_t const & value )
52{
53 // write bit pattern of a member to the current byte and position
54 if (memberId>=(int)fParameterDefinitions.size()) return false;
55
56 AliHLTUInt32_t switchBit=fParameterDefinitions[memberId].SwitchBit(value); // 0 -> reduced, 1 -> full
57 AliHLTUInt64_t v=fParameterDefinitions[memberId].Value(value);
58 AliHLTUInt32_t length=fParameterDefinitions[memberId].ValueLength(value);
59 fParameterDefinitions[memberId].IncrementBitCount(value);
60
61 if (!OutputBit(switchBit)) return false;
62 return OutputBits(v, length);
63}
64
f95bc7cd 65void AliHLTDataDeflaterSimple::Clear(Option_t * option)
80fb7693 66{
67 // internal cleanup
f95bc7cd 68 for (vector<AliHLTDataDeflaterParameter>::iterator m=fParameterDefinitions.begin();
69 m!=fParameterDefinitions.end(); m++) {
70 m->ResetBitCount();
71 }
72 AliHLTDataDeflater::Clear(option);
80fb7693 73}
74
75void AliHLTDataDeflaterSimple::Print(Option_t *option) const
76{
77 // print info
78 Print(cout, option);
79}
80
81void AliHLTDataDeflaterSimple::Print(ostream& out, Option_t *option) const
82{
83 // print to stream
84 out << "AliHLTDataDeflaterSimple:" << endl;
85 AliHLTUInt64_t bitCount=0;
86 AliHLTUInt64_t fullSize=0;
87 for (vector<AliHLTDataDeflaterParameter>::const_iterator m=fParameterDefinitions.begin();
88 m!=fParameterDefinitions.end(); m++) {
89 cout << " "; m->Print(option);
90 bitCount+=m->GetBitCount();
91 fullSize+=m->GetValueCount()*m->GetBitLength();
92 }
93 out << " total: " << bitCount << "/" << fullSize << " " << (fullSize>0?float(bitCount)/fullSize:0.0) << endl;
94}
95
96void AliHLTDataDeflaterSimple::AliHLTDataDeflaterParameter::Print(const char* /*option*/) const
97{
98 // print info
99 cout << fName << " (" << fFullBitLength << "," << fReducedBitLength << "): "
100 << fValueCount << " entries "
101 << fBitCount << "/" << fFullBitLength*fValueCount;
102 if (fFullBitLength && fValueCount) {
103 cout << " " << float(fBitCount)/(fValueCount*fFullBitLength);
104 }
105 cout << endl;
106}
107
108ostream& operator<<(ostream &out, const AliHLTDataDeflaterSimple& me)
109{
110 me.Print(out);
111 return out;
112}