00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifdef __CLDAQ_ZLIB_USE
00027 #include "TCompressObjectFilter.hh"
00028 #include "TStreamableObject.hh"
00029 #include "TOutputObjectStream.hh"
00030 #include "TObjectStream.hh"
00031 #include "TOutputObjectFile.hh"
00032
00033 static const Tint _maxbuf = 0x80000;
00034 static Tbyte _buf[_maxbuf];
00035 static TOutputObjectFile* _ofs = 0;
00036
00037 TCompressObjectFilter::TCompressObjectFilter()
00038 : TOutputObjectFilter(), theEncoder()
00039 {;}
00040
00041 TCompressObjectFilter::~TCompressObjectFilter()
00042 {;}
00043
00044 Tint TCompressObjectFilter::Filtering( TStreamableObject& object, TOutputObjectStream* stream )
00045 {
00046 _ofs = (TOutputObjectFile*)stream;
00047
00048 Tint totaldatasize = _ofs -> GetTotalDataSize();
00049 Tint nwrite = 0;
00050 _ofs -> SetLastDataSize( _ofs -> GetDataSize() );
00051 _ofs -> SetDataSize( nwrite );
00052
00053
00054 Tint recordsize = object.Serialize( _buf );
00055 if ( recordsize < _maxbuf && recordsize > 0 ) {
00056 theEncoder.Compress( _buf, recordsize );
00057 } else {
00058 Tcout << "MAX BUFFER SIZE: " << _maxbuf << Tendl;
00059 exit( EXIT_SUCCESS );
00060 }
00061
00062 Tvoid* p = theEncoder.GetDeflatedData();
00063 Tsize_t s = (Tsize_t)theEncoder.GetSizeOfDeflatedData();
00064 nwrite = fwrite( p, s, 1, _ofs -> GetFileStream() );
00065 if ( s != 0 && nwrite != 1 ) {
00066 Tcerr << "WRITE ERROR in " << s << " BYTE RECORD" << Tendl;
00067 }
00068
00069 Tint datasize = s * nwrite;
00070 _ofs -> SetDataSize( datasize );
00071 _ofs -> SetTotalDataSize( totaldatasize + datasize );
00072
00073 return recordsize;
00074 }
00075
00076 Tvoid TCompressObjectFilter::Initialize( TOutputObjectStream* stream )
00077 {
00078 Tstream_t streamtype = stream -> GetStreamType();
00079 if ( streamtype != tFileStream ) {
00080 Tcout << "Not TFileStream" << Tendl;
00081 exit( EXIT_SUCCESS );
00082 }
00083 return;
00084 }
00085
00086 Tvoid TCompressObjectFilter::Finalize( TOutputObjectStream* stream )
00087 {
00088 Tstream_t streamtype = stream -> GetStreamType();
00089 if ( streamtype != tFileStream ) {
00090 Tcout << "Not TFileStream" << Tendl;
00091 exit( EXIT_SUCCESS );
00092 }
00093
00094 _ofs = (TOutputObjectFile*)stream;
00095 if ( _ofs && !_ofs -> IsEnd() && !_ofs -> IsError() ) {
00096
00097 Tint totaldatasize = _ofs -> GetTotalDataSize();
00098 Tint nwrite = 0;
00099 _ofs -> SetLastDataSize( _ofs -> GetDataSize() );
00100 _ofs -> SetDataSize( nwrite );
00101
00102 theEncoder.Compress( 0, 0, Ttrue );
00103 Tvoid* p = theEncoder.GetDeflatedData();
00104 Tsize_t s = (Tsize_t)theEncoder.GetSizeOfDeflatedData();
00105 nwrite = fwrite( p, s, 1, _ofs -> GetFileStream() );
00106 if ( s != 0 && nwrite != 1 ) {
00107 Tcerr << "WRITE ERROR in " << s << " BYTE RECORD" << Tendl;
00108 }
00109
00110 Tint datasize = s * nwrite;
00111 _ofs -> SetDataSize( datasize );
00112 _ofs -> SetTotalDataSize( totaldatasize + datasize );
00113 }
00114
00115 return;
00116 }
00117
00118 #ifdef __CLDAQ_ROOT_DLL
00119 ClassImp(TCompressObjectFilter)
00120 #endif
00121
00122 #endif