ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitCommon/OptIO/src/OptInt.cc
Revision: 1.5
Committed: Mon Sep 21 19:30:00 2009 UTC (15 years, 7 months ago) by loizides
Content type: text/plain
Branch: MAIN
Changes since 1.4: +35 -1 lines
Log Message:
Provided independent access to compress/decompress functions.

File Contents

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