メインページ   モジュール   名前空間一覧   クラス階層   アルファベット順一覧   構成   ファイル一覧   構成メンバ   ファイルメンバ   関連ページ    

TCompressObjectFilter.cc

解説を見る。
00001 // =====================================================================
00002 //  $Id: TCompressObjectFilter.cc,v 1.9 2004/06/24 15:15:25 goiwai Exp $
00003 //  $Name: CLDAQ-1-14-03 $
00004 //  $Log: TCompressObjectFilter.cc,v $
00005 //  Revision 1.9  2004/06/24 15:15:25  goiwai
00006 //  たくさんの変更
00007 //  Tcout,Tcerr,Tlogをバッファ経由にした。
00008 //  何個かexternした。Tlog,Tcout,Tcerr,Tinfo...Tcritなど出力関係。
00009 //
00010 //  Revision 1.8  2004/03/07 16:52:34  goiwai
00011 //  __CLDAQ_ZLIB_USEプロプロセッサの位置をちょっとずらしただけです。
00012 //
00013 //  Revision 1.7  2004/03/07 10:30:32  goiwai
00014 //  ROOTに組みこむためのおまじないマクロを埋めこみました。
00015 //  全てにおいて完全に動作するわけではありません。
00016 //
00017 //  Revision 1.6  2004/01/19 23:01:17  goiwai
00018 //  Tsyslog.h => TSystemLoggin.hh
00019 //
00020 //  Revision 1.5  2003/12/06 10:50:44  goiwai
00021 //  可逆な圧縮フィルターです.
00022 //  手抜きの実装なのでまだファイルにしか対応していませんが,2倍以上速度性能
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


CLDAQ - a Class Library for DataAcQuisition (Version 1.14.3)
Go IWAI -- goiwai at users.sourceforge.jp