ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitCommon/OptIO/src/OptInt.cc
Revision: 1.6
Committed: Tue Sep 22 07:54:34 2009 UTC (15 years, 7 months ago) by loizides
Content type: text/plain
Branch: MAIN
CVS Tags: Mit_032, Mit_031, Mit_025c_branch2, Mit_025c_branch1, Mit_030, Mit_029c, Mit_030_pre1, Mit_029a, Mit_029, Mit_029_pre1, Mit_028a, Mit_025c_branch0, Mit_028, Mit_027a, Mit_027, Mit_026, Mit_025e, Mit_025d, Mit_025c, Mit_025b, Mit_025a, Mit_025, Mit_025pre2, Mit_024b, Mit_025pre1, Mit_024a, Mit_024, Mit_023, Mit_022a, Mit_022, Mit_020d, TMit_020d, Mit_020c, Mit_021, Mit_021pre2, Mit_021pre1, Mit_020b, Mit_020a, Mit_020, Mit_020pre1, Mit_018, Mit_017, Mit_017pre3, Mit_017pre2, Mit_017pre1, V07-05-00, Mit_016, Mit_015b, Mit_015a, Mit_015, Mit_014e, Mit_014d, Mit_014c, Mit_014b, ConvRejection-10-06-09, Mit_014a, Mit_014, Mit_014pre3, Mit_014pre2, Mit_014pre1, Mit_013d, Mit_013c, Mit_013b, Mit_013a, Mit_013, Mit_013pre1, Mit_012i, Mit_012g, Mit_012f, Mit_012e, Mit_012d, Mit_012c, Mit_012b, Mit_012a, Mit_012, Mit_011a, Mit_008, HEAD
Branch point for: Mit_025c_branch
Changes since 1.5: +7 -6 lines
Log Message:
Improved compress/decompress to deal with larger buffer sizes.

File Contents

# Content
1 // $Id: OptInt.cc,v 1.5 2009/09/21 19:30:00 loizides Exp $
2
3 #include "MitCommon/OptIO/interface/OptInt.h"
4 #include <TROOT.h>
5 #include <TSystem.h>
6 #include <TError.h>
7 #include <TEnv.h>
8 #include <Riostream.h>
9
10 ClassImp(mithep::OptInt)
11
12 using namespace mithep;
13
14 extern "C" void R__SetZipMode(int zipmode);
15 extern "C" void R__myzip(int cxlevel, int *srcsize, char *src,
16 int *tgtsize, char *tgt, int *irep, int la);
17 extern "C" void R__myunzip(int *srcsize, char *src,
18 int *tgtsize, char *tgt, int *irep, int la);
19
20 extern int activated;
21 extern double lzipfrac;
22 extern double gzipfrac;
23 extern double bzipfrac;
24 extern double lzmafrac;
25 extern int myverbose;
26 extern int mystaticm;
27 extern int R__ZipMode;
28
29
30 //--------------------------------------------------------------------------------------------------
31 Int_t OptInt::Compress(Int_t srcsize, char *src, Int_t tgtsize, char *tgt, Int_t cl, Int_t method)
32 {
33 // Compress given buffer and return compressed size.
34
35 Int_t zm = R__ZipMode;
36 if (method>-1) {
37 R__SetZipMode(method);
38 }
39
40 Int_t size = 0;
41 R__myzip(cl, &srcsize, src, &tgtsize, tgt, &size, 1);
42 if (method>-1) {
43 R__SetZipMode(zm);
44 }
45
46 return size;
47 }
48
49 //--------------------------------------------------------------------------------------------------
50 Int_t OptInt::DeCompress(Int_t srcsize, char *src, Int_t tgtsize, char *tgt)
51 {
52 // Decompress given buffer and return decompressed size.
53
54 Int_t size = 0;
55 R__myunzip(&srcsize, src, &tgtsize, tgt, &size, 1);
56 return size;
57 }
58
59 //--------------------------------------------------------------------------------------------------
60 Bool_t OptInt::IsActivated()
61 {
62 // Return true if code was properly pre-loaded.
63
64 return (activated==123);
65 }
66
67 //--------------------------------------------------------------------------------------------------
68 void OptInt::SetAlgoFractions(Double_t lzo, Double_t gz, Double_t bz, Double_t lzma)
69 {
70 // Fraction of compression that must be reached to accept result of the "heavy"
71 // compression algorithms. Negative values turn off usage of the specific compression
72 // algorithm in ZipMode=99.
73
74 lzipfrac = lzo;
75 gzipfrac = gz;
76 bzipfrac = bz;
77 lzmafrac = lzma;
78 }
79
80 //--------------------------------------------------------------------------------------------------
81 void OptInt::SetBzipFraction(Double_t f)
82 {
83 // Set fraction for compression algorithm, see description of SetAlgoFractions.
84
85 bzipfrac = f;
86 }
87
88 //--------------------------------------------------------------------------------------------------
89 void OptInt::SetGzipFraction(Double_t f)
90 {
91 // Set fraction for compression algorithm, see description of SetAlgoFractions.
92
93 gzipfrac = f;
94 }
95
96 //--------------------------------------------------------------------------------------------------
97 void OptInt::SetLzmaFraction(Double_t f)
98 {
99 // Set fraction for compression algorithm, see description of SetAlgoFractions.
100
101 lzmafrac = f;
102 }
103
104 //--------------------------------------------------------------------------------------------------
105 void OptInt::SetLzoFraction(Double_t f)
106 {
107 // Set fraction for compression algorithm, see description of SetAlgoFractions.
108
109 lzipfrac = f;
110 }
111
112 //--------------------------------------------------------------------------------------------------
113 void OptInt::SetStaticMalloc(Bool_t b)
114 {
115 // Set flag to enable the usage of static rather than heap memory in the compression
116 // algorithm. No real increase in speed has been observed, therefore off by default.
117
118 mystaticm = b;
119 }
120
121 //--------------------------------------------------------------------------------------------------
122 void OptInt::SetVerbose(Int_t vl)
123 {
124 // Set verbosity level in the R__zip and R__unzip functions. Use 1 to only enable for
125 // writing, 2 only for reading and 10 for both.
126
127 myverbose = vl;
128 }
129
130 //--------------------------------------------------------------------------------------------------
131 void OptInt::SetZipMode(Int_t zipmode)
132 {
133 // Set ZipMode to be used in R__zip. Supported values range from 1 to 5, where
134 // 1 == gzip (http://www.gzip.org/, standard in ROOT)
135 // 2 == bzip2 (http://www.bzip.org/)
136 // 3 == lzo (http://www.oberhumer.com/opensource/lzo/)
137 // 4 == rle (http://bcl.comli.eu/)
138 // 5 == lzma (http://www.7-zip.org/sdk.html)
139 // 99 == combination of 1 to 5.
140
141 R__SetZipMode(zipmode);
142 }