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

TInputObjectSharedMemory.cc

解説を見る。
00001 // =====================================================================
00002 //  $Id: TInputObjectSharedMemory.cc,v 1.5 2004/03/07 10:30:32 goiwai Exp $
00003 //  $Name: CLDAQ-1-14-03 $
00004 //  $Log: TInputObjectSharedMemory.cc,v $
00005 //  Revision 1.5  2004/03/07 10:30:32  goiwai
00006 //  ROOTに組みこむためのおまじないマクロを埋めこみました。
00007 //  全てにおいて完全に動作するわけではありません。
00008 //
00009 //  Revision 1.4  2003/12/06 10:56:19  goiwai
00010 //  フィルタ関連の修整と Read(),Write()の戻り値の修整です.
00011 //  Read()もWrite()も処理したレコードサイズを返します.
00012 //  フィルタがある場合も同様です.
00013 //  それぞれのストリームのDataSizeの扱いですが,これは扱ったレコードサイズ
00014 //  でなく扱ったファイルやソケットなどのサイズになります.レコードサイズと
00015 //  一致するとは限りません.
00016 //
00017 //  Revision 1.3  2003/10/06 17:02:42  goiwai
00018 //  *** empty log message ***
00019 //
00020 //  Revision 1.2  2003/07/30 16:19:30  goiwai
00021 //  ファイルにコミットログをつけることにしました.
00022 //
00023 // =====================================================================
00024 #include "TInputObjectSharedMemory.hh"
00025 #include "TStreamableObject.hh"
00026 #include "TInputObjectFilter.hh"
00027 #include "TDataRecord.hh"
00028 #include "TDataSection.hh"
00029 #include "TDataSegment.hh"
00030 #include "TDataElement.hh"
00031 
00032 TInputObjectSharedMemory::TInputObjectSharedMemory( Tint memsize, Tint maxevt )
00033   : TObjectSharedMemory( memsize, maxevt ), 
00034     TInputObjectStream( tSharedMemoryStream ),
00035     theReadSuccessFlag( Tfalse )
00036 {;}
00037 
00038 TInputObjectSharedMemory::TInputObjectSharedMemory( TInputObjectFilter* filter, Tint memsize, Tint maxevt )
00039   : TObjectSharedMemory( memsize, maxevt ), 
00040     TInputObjectStream( filter, tSharedMemoryStream ),
00041     theReadSuccessFlag( Tfalse )
00042 {;}
00043 
00044 TInputObjectSharedMemory::~TInputObjectSharedMemory()
00045 {;}
00046 
00047 Tint TInputObjectSharedMemory::Read( TStreamableObject& object )
00048 {
00049   if ( HasFilter() ) {
00050     return theObjectFilter -> Filtering( object, this );
00051   }
00052 
00053 
00054   theLastDataSize = theDataSize;
00055   theDataSize = 0;
00056 
00057   if ( IsReadable() == Tfalse ) {
00058     return theDataSize;
00059   }
00060 
00061   if ( theCurrentPositionOfMemorySpace == theMaxEvent - 1 ) {
00062     // return to top
00063     theAddress = theBaseAddress;
00064     theCurrentPositionOfMemorySpace = 0;
00065   }
00066     
00067 
00068 
00069 
00070   static Tobject_t objecttype = object.GetObjectType();
00071 
00072   Tvoid* begin = theAddress;
00073 
00074   switch ( objecttype ) {
00075     case tObjectDataRecord:
00076       *( (TDataRecord*)(&object) ) = getDataRecord();
00077       break;
00078     case tObjectDataSection:
00079       *( (TDataSection*)(&object) ) = getDataSection();
00080       break;
00081     case tObjectDataSegment:
00082       *( (TDataSegment*)(&object) ) = getDataSegment();
00083       break;
00084     case tObjectDataElement:
00085       *( (TDataElement*)(&object) ) = getDataElement();
00086       break;
00087     default:
00088       break;
00089   }
00090 
00091   if ( theReadSuccessFlag == Tfalse ) {
00092     theAddress = begin;
00093     theDataSize = 0;
00094   }
00095 
00096   if ( theDataSize > 0 )
00097     theCurrentPositionOfMemorySpace ++;
00098 
00099   theTotalDataSize += theDataSize;
00100   return theDataSize;
00101 }
00102 
00103 TDataRecord TInputObjectSharedMemory::getDataRecord()
00104 {
00105   Tint recsize;
00106   Tobject_t type;
00107   Tstring id;
00108   Tsize_t entries;
00109   TDataRecord record;
00110   readProperties( recsize, type, id, entries );
00111   if ( theReadSuccessFlag == Tfalse ) {
00112     return record;
00113   }
00114   record.SetID( id );
00115   record.SetObjectType( type );
00116 
00117   for ( Tsize_t i = 0; i < entries; i ++ ) {
00118     TDataSection section = getDataSection();
00119     if ( theReadSuccessFlag == Tfalse ) {
00120       break;
00121     } else {
00122       record.push_back( section );
00123     }
00124   }
00125 
00126   return record;
00127 }
00128 
00129 TDataSection TInputObjectSharedMemory::getDataSection()
00130 {
00131   Tint recsize;
00132   Tobject_t type;
00133   Tstring id;
00134   Tsize_t entries;
00135   TDataSection section;
00136   readProperties( recsize, type, id, entries );
00137   if ( theReadSuccessFlag == Tfalse ) {
00138     return section;
00139   }
00140   section.SetID( id );
00141   section.SetObjectType( type );
00142 
00143   for ( Tsize_t i = 0; i < entries; i ++ ) {
00144     TDataSegment segment = getDataSegment();
00145     if ( theReadSuccessFlag == Tfalse ) {
00146       break;
00147     } else {
00148       section.push_back( segment );
00149     }
00150   }
00151 
00152   return section;
00153 }
00154 
00155 TDataSegment TInputObjectSharedMemory::getDataSegment()
00156 {
00157   Tint recsize;
00158   Tobject_t type;
00159   Tstring id;
00160   Tsize_t entries;
00161   TDataSegment segment;
00162   readProperties( recsize, type, id, entries );
00163   if ( theReadSuccessFlag == Tfalse ) {
00164     return segment;
00165   }
00166   segment.SetID( id );
00167   segment.SetObjectType( type );
00168 
00169   for ( Tsize_t i = 0; i < entries; i ++ ) {
00170     TDataElement element = getDataElement();
00171     if ( theReadSuccessFlag == Tfalse ) {
00172       break;
00173     } else {
00174       segment.push_back( element );
00175     }
00176   }
00177 
00178   return segment;
00179 }
00180 
00181 TDataElement TInputObjectSharedMemory::getDataElement()
00182 {
00183   Tint recsize;
00184   Tobject_t otype;
00185   Tstring id;
00186   Telement_t etype;
00187   Tint nprvs;
00188   TDataElement element;
00189 
00190   // read object type
00191   recsize = *( (Tint*)theAddress );
00192   theDataSize += Tsizeof( Tint );
00193   ( (Tint*)theAddress ) ++;
00194 
00195 
00196   // read object type
00197   otype = *( (Tobject_t*)theAddress );
00198   theDataSize += Tsizeof( Tobject_t );
00199   ( (Tobject_t*)theAddress ) ++;
00200   element.SetObjectType( otype );
00201 
00202 
00203   // read object ID
00204   Tsize_t nchar;
00205   Tchar* charbuf = 0;
00206   nchar = *( (Tsize_t*)theAddress );
00207   theDataSize += Tsizeof( Tsize_t );
00208   ( (Tsize_t*)theAddress ) ++;
00209   charbuf = new Tchar[ nchar ];
00210   for ( Tsize_t i = 0; i < nchar; i ++ ) {
00211     charbuf[ i ] = *( (Tchar*)theAddress );
00212     theDataSize += Tsizeof( Tchar );
00213     ( (Tchar*)theAddress ) ++;
00214   }
00215   id = charbuf;
00216   delete [] charbuf;
00217   element.SetID( id );
00218 
00219 
00220   // read element type
00221   etype = *( (Telement_t*)theAddress );
00222   theDataSize += Tsizeof( Telement_t );
00223   ( (Telement_t*)theAddress ) ++;
00224   element.SetElementType( etype );
00225 
00226 
00227   // read number of primitives
00228   nprvs = *( (Tint*)theAddress );
00229   theDataSize += Tsizeof( Tint );
00230   ( (Tint*)theAddress ) ++;
00231   element.SetNumberOfPrimitives( nprvs );
00232 
00233 
00234   if ( otype == tObjectUnknown || id == TunknownID || etype == tTypeUnknown || nprvs == 0 ) {
00235     theReadSuccessFlag = Tfalse;
00236     return element;
00237   }
00238 
00239 
00240   Tstring* strbuf = 0;
00241   Tchar* cc = 0;
00242   Tint* ii = 0;
00243   TUint* ui = 0;
00244   Tdouble* dd = 0;
00245   TUshort* us = 0;
00246   Tshort* ss = 0;
00247   Tfloat* ff = 0;
00248   Tlong* ll = 0;
00249   TUlong* ul = 0;
00250 
00251   // read primitive data
00252   switch ( etype ) {
00253 
00254     case tTypeInt:
00255       ii = new Tint[ nprvs ];
00256       for ( Tint i = 0; i < nprvs; i ++ ) {
00257         // read int data
00258         ii[ i ] = *( (Tint*)theAddress );
00259         theDataSize += Tsizeof( Tint );
00260         ( (Tint*)theAddress ) ++;
00261       }
00262       element.FillData( ii, nprvs );
00263       delete [] ii;
00264       break;
00265 
00266 
00267     case tTypeUnsignedInt:
00268       ui = new TUint[ nprvs ];
00269       for ( Tint i = 0; i < nprvs; i ++ ) {
00270         // read int data
00271         ui[ i ] = *( (TUint*)theAddress );
00272         theDataSize += Tsizeof( TUint );
00273         ( (TUint*)theAddress ) ++;
00274       }
00275       element.FillData( ui, nprvs );
00276       delete [] ui;
00277       break;
00278 
00279 
00280     case tTypeWord:
00281     case tTypeUnsignedShort:
00282       us = new TUshort[ nprvs ];
00283       for ( Tint i = 0; i < nprvs; i ++ ) {
00284         // read ushort data
00285         us[ i ] = *( (TUshort*)theAddress );
00286         theDataSize += Tsizeof( TUshort );
00287         ( (TUshort*)theAddress ) ++;
00288       }
00289       element.FillData( us, nprvs );
00290       delete [] us;
00291       break;
00292 
00293     case tTypeDouble:
00294       dd = new Tdouble[ nprvs ];
00295       for ( Tint i = 0; i < nprvs; i ++ ) {
00296         // read double data
00297         dd[ i ] = *( (Tdouble*)theAddress );
00298         theDataSize += Tsizeof( Tdouble );
00299         ( (Tdouble*)theAddress ) ++;
00300       }
00301       element.FillData( dd, nprvs );
00302       delete [] dd;
00303       break;
00304 
00305     case tTypeFloat:
00306       ff = new Tfloat[ nprvs ];
00307       for ( Tint i = 0; i < nprvs; i ++ ) {
00308         // read double data
00309         ff[ i ] = *( (Tfloat*)theAddress );
00310         theDataSize += Tsizeof( Tfloat );
00311         ( (Tfloat*)theAddress ) ++;
00312       }
00313       element.FillData( ff, nprvs );
00314       delete [] ff;
00315       break;
00316 
00317     case tTypeShort:
00318       ss = new Tshort[ nprvs ];
00319       for ( Tint i = 0; i < nprvs; i ++ ) {
00320         // read short data
00321         ss[ i ] = *( (Tshort*)theAddress );
00322         theDataSize += Tsizeof( Tshort );
00323         ( (Tshort*)theAddress ) ++;
00324       }
00325       element.FillData( ss, nprvs );
00326       delete [] ss;
00327       break;
00328 
00329     case tTypeLong:
00330       ll = new Tlong[ nprvs ];
00331       for ( Tint i = 0; i < nprvs; i ++ ) {
00332         // read long data
00333         ll[ i ] = *( (Tlong*)theAddress );
00334         theDataSize += Tsizeof( Tlong );
00335         ( (Tlong*)theAddress ) ++;
00336       }
00337       element.FillData( ll, nprvs );
00338       delete [] ll;
00339       break;
00340 
00341     case tTypeUnsignedLong:
00342       ul = new TUlong[ nprvs ];
00343       for ( Tint i = 0; i < nprvs; i ++ ) {
00344         // read long data
00345         ul[ i ] = *( (TUlong*)theAddress );
00346         theDataSize += Tsizeof( TUlong );
00347         ( (TUlong*)theAddress ) ++;
00348       }
00349       element.FillData( ul, nprvs );
00350       delete [] ul;
00351       break;
00352 
00353     case tTypeString:
00354       strbuf = new Tstring[ nprvs ];
00355       for ( Tint i = 0; i < nprvs; i ++ ) {
00356 
00357         // read number of characters
00358         Tsize_t nchar;
00359         nchar = *( (Tsize_t*)theAddress );
00360         theDataSize += Tsizeof( Tsize_t );
00361         ( (Tsize_t*)theAddress ) ++;
00362 
00363         // read string
00364         cc = new Tchar[ nchar ];
00365         for ( Tsize_t j = 0; j < nchar; j ++ ) {
00366           cc[ j ] = *( (Tchar*)theAddress );
00367           theDataSize += Tsizeof( Tchar );
00368           ( (Tchar*)theAddress ) ++;
00369         }
00370 
00371         strbuf[ i ] = cc;
00372         delete [] cc;
00373       }
00374       element.FillData( strbuf, nprvs );
00375       delete [] strbuf;
00376       break;
00377 
00378     case tTypeUnknown:
00379     case tTypeObject:
00380     default:
00381       theReadSuccessFlag = Tfalse;
00382       return element;
00383   }
00384 
00385   return element;
00386 }
00387 
00388 Tvoid TInputObjectSharedMemory::readProperties( Tint& recsize, Tobject_t& type, Tstring& id, Tsize_t& entries )
00389 {
00390   // read record size
00391   recsize = *( (Tint*)theAddress );
00392   theDataSize += Tsizeof( Tint );
00393   ( (Tint*)theAddress ) ++;
00394 
00395 
00396   // read object type
00397   type = *( (Tobject_t*)theAddress );
00398   theDataSize += Tsizeof( Tobject_t );
00399   ( (Tobject_t*)theAddress ) ++;
00400 
00401 
00402   // read object ID
00403   Tsize_t nchar;
00404   Tchar* charbuf = 0;
00405   nchar = *( (Tsize_t*)theAddress );
00406   theDataSize += Tsizeof( Tsize_t );
00407   ( (Tsize_t*)theAddress ) ++;
00408   charbuf = new Tchar[ nchar ];
00409   for ( Tsize_t i = 0; i < nchar; i ++ ) {
00410     charbuf[ i ] = *( (Tchar*)theAddress );
00411     theDataSize += Tsizeof( Tchar );
00412     ( (Tchar*)theAddress ) ++;
00413   }
00414   id = charbuf;
00415   delete [] charbuf;
00416 
00417 
00418   // read number of entries
00419   entries = *( (Tsize_t*)theAddress );
00420   theDataSize += Tsizeof( Tsize_t );
00421   ( (Tsize_t*)theAddress ) ++;
00422 
00423 
00424   if ( type == tObjectUnknown || id == TunknownID || entries == 0 ) {
00425     theReadSuccessFlag = Tfalse;
00426     return;
00427   }
00428 
00429   theReadSuccessFlag = Ttrue;
00430 
00431   return;
00432 }
00433 
00434 #ifdef __CLDAQ_ROOT_DLL
00435     ClassImp(TInputObjectSharedMemory)
00436 #endif


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