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
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
00065
00066 if ( _ifs -> IsEnd() && excess <= (Tint)Tsizeof(Tint) ) {
00067
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
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
00091
00092
00093
00094
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
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
00119
00120
00121
00122
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