00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifdef __CLDAQ_ZLIB_USE
00020 #include "TDataDeflation.hh"
00021
00022 TDataDeflation::TDataDeflation( Tint bufsize, Tint level )
00023 : theDeflationStream(), theCompressionLevel( level ),
00024 theStatus( Z_OK ),
00025 theOutputBuffer( 0 ), theSizeOfOutputBuffer( bufsize ),
00026 theDeflatedData( 0 ), theSizeOfDeflatedData( -1 )
00027 {
00028 theDeflationStream.zalloc = Z_NULL;
00029 theDeflationStream.zfree = Z_NULL;
00030 theDeflationStream.opaque = Z_NULL;
00031
00032 theDeflationStream.next_in = Z_NULL;
00033 theDeflationStream.avail_in = 0;
00034 theDeflationStream.next_out = Z_NULL;
00035 theDeflationStream.avail_out = 0;
00036
00037 theStatus = deflateInit( &theDeflationStream, theCompressionLevel );
00038 if ( theStatus != Z_OK ) {
00039 Tcerr << "TDataDeflation::TDataDeflation: ";
00040 Tcerr << theDeflationStream.msg << ", status: " << theStatus << Tendl;
00041 }
00042
00043 SetOutputBuffer( theSizeOfOutputBuffer );
00044 }
00045
00046 TDataDeflation::TDataDeflation( const TDataDeflation& right )
00047 : theDeflationStream(), theCompressionLevel( right.theCompressionLevel ),
00048 theStatus( Z_OK ),
00049 theOutputBuffer( 0 ), theSizeOfOutputBuffer( right.theSizeOfOutputBuffer ),
00050 theDeflatedData( 0 ), theSizeOfDeflatedData( -1 )
00051 {
00052 theDeflationStream.zalloc = Z_NULL;
00053 theDeflationStream.zfree = Z_NULL;
00054 theDeflationStream.opaque = Z_NULL;
00055
00056 theDeflationStream.next_in = Z_NULL;
00057 theDeflationStream.avail_in = 0;
00058 theDeflationStream.next_out = Z_NULL;
00059 theDeflationStream.avail_out = 0;
00060
00061 theStatus = deflateInit( &theDeflationStream, theCompressionLevel );
00062 if ( theStatus != Z_OK ) {
00063 Tcerr << "TDataDeflation::TDataDeflation: ";
00064 Tcerr << theDeflationStream.msg << ", status: " << theStatus << Tendl;
00065 }
00066
00067 SetOutputBuffer( theSizeOfOutputBuffer );
00068 }
00069
00070 TDataDeflation::~TDataDeflation()
00071 {
00072 theStatus = deflateEnd( &theDeflationStream );
00073 if ( theStatus != Z_OK ) {
00074 Tcerr << "TDataDeflation::~TDataDeflation: ";
00075 Tcerr << theDeflationStream.msg << ", status: " << theStatus << Tendl;
00076 }
00077
00078 delete [] theOutputBuffer;
00079 }
00080
00081 const TDataDeflation& TDataDeflation::operator=( const TDataDeflation& right )
00082 {
00083 deflateCopy( &theDeflationStream,
00084 &((Tzstream&)(right.theDeflationStream)) );
00085 theStatus = right.theStatus;
00086 if ( theCompressionLevel != right.theCompressionLevel ) {
00087 SetCompressionLevel( right.theCompressionLevel );
00088 }
00089 theSizeOfOutputBuffer = right.theSizeOfOutputBuffer;
00090 delete [] (Tbyte*)theOutputBuffer;
00091 theOutputBuffer = new Tbyte[ theSizeOfOutputBuffer ];
00092 theDeflatedData = 0;
00093 theSizeOfDeflatedData = -1;
00094
00095 return *this;
00096 }
00097
00098 Tvoid TDataDeflation::Compress( Tvoid* input, Tint nbyte, Tbool islast )
00099 {
00100 static const Tstring head = "TDataDeflation::Compress: ";
00101
00102 theDeflationStream.next_in = (Tbyte*)input;
00103 theDeflationStream.avail_in = nbyte;
00104 theDeflationStream.next_out = theOutputBuffer;
00105 theDeflationStream.avail_out = theSizeOfOutputBuffer;
00106
00107 Tint flush;
00108 if ( islast ) {
00109 flush = Z_FINISH;
00110 } else {
00111 flush = Z_NO_FLUSH;
00112 }
00113
00114 theStatus = deflate( &theDeflationStream, flush );
00115
00116 theDeflatedData = theOutputBuffer;
00117 theSizeOfDeflatedData = theSizeOfOutputBuffer - theDeflationStream.avail_out;
00118
00119 return;
00120 }
00121
00122 Tvoid TDataDeflation::SetCompressionLevel( Tint level )
00123 {
00124 theCompressionLevel = level;
00125 theStatus = deflateParams( &theDeflationStream, theCompressionLevel, Z_DEFAULT_STRATEGY );
00126 if ( theStatus != Z_OK ) {
00127 Tcerr << "TDataDeflation::TDataDeflation: ";
00128 Tcerr << theDeflationStream.msg << ", status: " << theStatus << Tendl;
00129 }
00130 return;
00131 }
00132
00133 Tvoid TDataDeflation::SetOutputBuffer( Tint bufsize )
00134 {
00135 if ( theOutputBuffer ) {
00136 delete [] theOutputBuffer;
00137 }
00138 theOutputBuffer = new Tbyte[ bufsize ];
00139 return;
00140 }
00141
00142
00143 #ifdef __CLDAQ_ROOT_DLL
00144 ClassImp(TDataDeflation)
00145 #endif
00146
00147 #endif