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
00030
00031
00032 #include "TOutputObjectSharedMemory.hh"
00033 #include "TStreamableObject.hh"
00034 #include "TOutputObjectFilter.hh"
00035
00036 TOutputObjectSharedMemory::TOutputObjectSharedMemory( Tint memsize, Tint maxevt )
00037 : TObjectSharedMemory( memsize, maxevt ),
00038 TOutputObjectStream( tSharedMemoryStream )
00039 {
00040 signal( SIGINT, TOutputObjectSharedMemory::catchSignal );
00041 signal( SIGSEGV, TOutputObjectSharedMemory::catchSignal );
00042 }
00043
00044 TOutputObjectSharedMemory::TOutputObjectSharedMemory( TOutputObjectFilter* filter, Tint memsize, Tint maxevt )
00045 : TObjectSharedMemory( memsize, maxevt ),
00046 TOutputObjectStream( filter, tSharedMemoryStream )
00047 {
00048 signal( SIGINT, TOutputObjectSharedMemory::catchSignal );
00049 signal( SIGSEGV, TOutputObjectSharedMemory::catchSignal );
00050 }
00051
00052 TOutputObjectSharedMemory::~TOutputObjectSharedMemory()
00053 {
00054 Detach();
00055 Remove();
00056 }
00057
00058 Tint TOutputObjectSharedMemory::Write( TStreamableObject& object )
00059 {
00060 if ( HasFilter() ) {
00061 return theObjectFilter -> Filtering( object, this );
00062 }
00063
00064 SetReadable( Tfalse );
00065
00066 theLastDataSize = theDataSize;
00067 theDataSize = 0;
00068
00069 if ( theCurrentPositionOfMemorySpace == theMaxEvent - 1 ) {
00070
00071 theAddress = theBaseAddress;
00072 theCurrentPositionOfMemorySpace = 0;
00073 }
00074
00075 theDataSize = object.Record( this );
00076
00077 if ( theDataSize > 0 ) {
00078 theCurrentPositionOfMemorySpace ++;
00079 }
00080
00081
00082
00083 SetReadable( Ttrue );
00084 theTotalDataSize += theDataSize;
00085 return theDataSize;
00086 }
00087
00088 Tvoid TOutputObjectSharedMemory::catchSignal( Tint sigid )
00089 {
00090 Tstring head = "TOutputObjectSharedMemory::catchSignal: ";
00091 Tcout << head << "get signal " << sigid << "." << Tendl;
00092 Tcout << head << "detach/remove IPC resources." << Tendl;
00093 TObjectSharedMemory::GetObjectSharedMemory() -> Detach();
00094 TObjectSharedMemory::GetObjectSharedMemory() -> Remove();
00095
00096
00097
00098
00099
00100
00101
00102
00103 Tcout << head << "terminate by force." << Tendl;
00104 exit( EXIT_SUCCESS );
00105
00106 return;
00107 }
00108
00109 #ifdef __CLDAQ_ROOT_DLL
00110 ClassImp(TOutputObjectSharedMemory)
00111 #endif