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

TDecompressObjectFilter.cc

解説を見る。
00001 // =====================================================================
00002 //  $Id: TDecompressObjectFilter.cc,v 1.6 2004/06/24 15:15:25 goiwai Exp $
00003 //  $Name: CLDAQ-1-14-03 $
00004 //  $Log: TDecompressObjectFilter.cc,v $
00005 //  Revision 1.6  2004/06/24 15:15:25  goiwai
00006 //  たくさんの変更
00007 //  Tcout,Tcerr,Tlogをバッファ経由にした。
00008 //  何個かexternした。Tlog,Tcout,Tcerr,Tinfo...Tcritなど出力関係。
00009 //
00010 //  Revision 1.5  2004/03/07 16:52:34  goiwai
00011 //  __CLDAQ_ZLIB_USEプロプロセッサの位置をちょっとずらしただけです。
00012 //
00013 //  Revision 1.4  2004/03/07 10:30:32  goiwai
00014 //  ROOTに組みこむためのおまじないマクロを埋めこみました。
00015 //  全てにおいて完全に動作するわけではありません。
00016 //
00017 //  Revision 1.3  2004/01/19 23:01:17  goiwai
00018 //  Tsyslog.h => TSystemLoggin.hh
00019 //
00020 //  Revision 1.2  2003/12/07 08:17:24  goiwai
00021 //  ファイルの終端間際でデコードに失敗するバグを修整しました.
00022 //
00023 //  Revision 1.1  2003/12/06 10:48:38  goiwai
00024 //  可逆な圧縮フィルタです.
00025 //  手抜きの実装なので,まだファイルにしか対応していませんが,2倍以上速度性
00026 //  能が向上します.
00027 //
00028 // =====================================================================
00029 #ifdef __CLDAQ_ZLIB_USE
00030 #include "TDecompressObjectFilter.hh"
00031 #include "TStreamableObject.hh"
00032 #include "TInputObjectStream.hh"
00033 #include "TOutputObjectStream.hh"
00034 #include "TObjectStream.hh"
00035 #include "TInputObjectFile.hh"
00036 #include "TDataRecord.hh"
00037 
00038 static const Tint _maxbuf = 0x80000;
00039 static Tbyte _buf[_maxbuf];
00040 static TInputObjectFile* _ifs = 0;
00041 
00042 TDecompressObjectFilter::TDecompressObjectFilter()
00043   : TInputObjectFilter(), theDecoder()
00044 {;}
00045 
00046 TDecompressObjectFilter::~TDecompressObjectFilter()
00047 {;}
00048 
00049 Tint TDecompressObjectFilter::Filtering( TStreamableObject& object, TInputObjectStream* stream )
00050 {
00051   _ifs = (TInputObjectFile*)stream;
00052   Tvoid* staticbuffer = _buf;
00053 
00054   Tint totaldatasize = _ifs -> GetTotalDataSize();
00055   Tint nread = 0;
00056   _ifs -> SetLastDataSize( _ifs -> GetDataSize() );
00057   _ifs -> SetDataSize( nread );
00058 
00059 
00060   static const Tint buflen = 0xff;
00061   static Tbyte buffer[buflen];
00062   static Tint excess = 0;
00063   static Tint lastrecord = 0;
00064   //Tint lastinflated = excess + lastrecord;
00065 
00066   if ( _ifs -> IsEnd() && excess <= (Tint)Tsizeof(Tint) ) {
00067     //Tinfo << "EXCESS: " << excess << Tendl;
00068     return 0;
00069   }
00070 
00071 
00072   // 高速化手法みたいな
00073   if ( excess > 0 ) {
00074     Tvoid* p = _buf;
00075     ((Tbyte*)p) += lastrecord;
00076     memcpy(staticbuffer,p,excess);
00077     ((Tbyte*)staticbuffer) += excess;
00078   }
00079 
00080 
00081   // 先頭の 4バイト分だけを inflate オブジェクトサイズを読みますです
00082   Tint inflated = excess;
00083   while ( inflated < (Tint)Tsizeof(Tint) ) {
00084     Tint gcount = fread(buffer,Tsizeof(Tbyte),buflen,_ifs->GetFileStream());
00085     if ( gcount == 0 ) {
00086       if ( _ifs -> IsEnd() ) {
00087         return 0;
00088       }
00089       
00090       //CLDAQ_DEBUG("");
00091       //Tcout << "DEBUG: " << _ifs->GetTotalDataSize() << Tendl;
00092       //Tcout << "DEBUG: " << excess << Tendl;
00093       //Tcout << "DEBUG: " << inflated << Tendl;
00094       //Tcout << "DEBUG: " << lastrecord << Tendl;
00095       Tcerr << "READ ERROR in " << buflen << " BYTE READ" << Tendl;
00096 
00097       break;
00098     }
00099     nread += gcount;
00100     theDecoder.Decompress(buffer,gcount);
00101     Tbyte* p = (Tbyte*)theDecoder.GetInflatedData();
00102     Tint s = theDecoder.GetSizeOfInflatedData();
00103     inflated += s;
00104     memcpy(staticbuffer,p,s);
00105     ((Tbyte*)staticbuffer) += s;
00106   }
00107 
00108 
00109 
00110   // オブジェクトサイズ分だけを inflate
00111   Tint recordsize = *( (Tint*)_buf );
00112   while ( inflated < recordsize ) {
00113     Tint gcount = fread(buffer,Tsizeof(Tbyte),buflen,_ifs->GetFileStream());
00114     if ( gcount == 0 ) {
00115       if ( _ifs -> IsEnd() ) {
00116         return 0;
00117       }
00118 //       CLDAQ_DEBUG("");
00119 //       Tcout << "DEBUG: " << _ifs->GetTotalDataSize() << Tendl;
00120 //       Tcout << "DEBUG: " << excess << Tendl;
00121 //       Tcout << "DEBUG: " << inflated << Tendl;
00122 //       Tcout << "DEBUG: " << lastrecord << Tendl;
00123       Tcerr << "READ ERROR in " << buflen << " BYTE READ" << Tendl;
00124       break;
00125     }
00126     nread += gcount;
00127     theDecoder.Decompress(buffer,gcount);
00128     Tbyte* p = (Tbyte*)theDecoder.GetInflatedData();
00129     Tint s = theDecoder.GetSizeOfInflatedData();
00130     inflated += s;
00131     memcpy(staticbuffer,p,s);
00132     ((Tbyte*)staticbuffer) += s;
00133   }
00134 
00135 
00136   Tobject_t objecttype = object.GetObjectType();
00137   Tint datasize = 0;
00138   TDataRecord record;
00139   TDataSection section;
00140   TDataSegment segment;
00141   TDataElement element;
00142   switch ( objecttype ) {
00143     case tObjectDataRecord:
00144       datasize = record.Deserialize( _buf );
00145       *( (TDataRecord*)&object ) = record;
00146       break;
00147     case tObjectDataSection:
00148       datasize = section.Deserialize( _buf );
00149       *( (TDataSection*)&object ) = section;
00150       break;
00151     case tObjectDataSegment:
00152       datasize = segment.Deserialize( _buf );
00153       *( (TDataSegment*)&object ) = segment;
00154       break;
00155     case tObjectDataElement:
00156       datasize = element.Deserialize( _buf );
00157       *( (TDataElement*)&object ) = element;
00158       break;
00159     default:
00160       break;
00161   }
00162 
00163   excess = inflated - recordsize;
00164   lastrecord = recordsize;
00165 
00166 
00167   _ifs -> SetDataSize( nread );
00168   _ifs -> SetTotalDataSize( totaldatasize + nread );
00169 
00170   return datasize;
00171 }
00172 
00173 Tvoid TDecompressObjectFilter::Initialize( TInputObjectStream* stream )
00174 {
00175   Tstream_t streamtype = stream -> GetStreamType();
00176   if ( streamtype != tFileStream ) {
00177     Tcout << "Not TFileStream" << Tendl;
00178     exit( EXIT_SUCCESS );
00179   }
00180   return;
00181 }
00182 
00183 Tvoid TDecompressObjectFilter::Finalize( TInputObjectStream* stream )
00184 {
00185   return;
00186 }
00187 
00188 #ifdef __CLDAQ_ROOT_DLL
00189     ClassImp(TDecompressObjectFilter)
00190 #endif
00191 
00192 #endif


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