//-------------------------------------------------------------------------- // File and Version Information: // $Id: APPLevel3FileOutputModule.cc, // v 1.15 1999/04/20 21:06:58 rico Exp $ // // Description: // Class APPFileOutputModule. This is the standard file output module // for the BaBar framework. It is currently incomplete. // // Environment: // Software developed for the BaBar Detector at the SLAC B-Factory. // // Author List: // David R. Quarrie Original Author // Bob Jacobsen Started AbsEvent dbio mods // Marc Turcotte Modified for new style begin/end // Marc Turcotte Modified for new style event. // Marc Turcotte Merged in R.Kapur's TK interface // Marc Turcotte Modified for FNAL sigs 6/24/98 // Mike Carew Added TL3B and TL3D Bank info // // Copyright Information: // Copyright (C) 1994, 1995 Lawrence Berkeley Laboratory // Copyright (C) 1998 University of Texas at Dallas // //------------------------------------------------------------------------ #include "Experiment/Experiment.hh" //----------------------- // This Class's Header -- //----------------------- #include "Level3Mods/APPLevel3FileOutputModule.hh" //------------- // C Headers -- //------------- #include #include //------------------------------- // Collaborating Class Headers -- //------------------------------- //#include "Framework/AppStream.hh" #include "Edm/MultiRootOutputFileStream.hh" #include "FrameMods/AppFileBasedStream.hh" #include "Framework/APPJob.hh" #include "FrameMods/AppFileOutputCommand.hh" #include "Framework/AppStopType.hh" #include "Framework/APPFramework.hh" #include "Framework/AppFrame.hh" #include "AbsEnv/AbsEnv.hh" #include "Edm/ConstEventIter.hh" #include "Edm/ConstHandle.hh" #include "Edm/Handle.hh" class AbsEvent; #include "Framework/APPList.hh" #include "Framework/APPListIterator.hh" using namespace std; static const char rcsid[] = "$Id: APPLevel3FileOutputModule.cc,v 1.21 2003/07/24 12:49:21 ksmcf Exp $"; // ---------------------------------------- // -- Public Function Member Definitions -- // ---------------------------------------- //---------------- // Constructors -- //---------------- APPLevel3FileOutputModule ::APPLevel3FileOutputModule( const char* const theName, const char* const theDescription, const int4 exeTag ) : APPLevel3GenericOutputModule( theName, theDescription, exeTag ) { // // establish output commands // commands( )->append( _outputCmd = new AppFileOutputCommand( "output", this ) ); } //-------------- // Destructor -- //-------------- APPLevel3FileOutputModule::~APPLevel3FileOutputModule( ) { if ( 0 != _outputCmd ) { delete _outputCmd; } } //-------------- // Operations -- //-------------- AppResult APPLevel3FileOutputModule::childBeginRun( AbsEvent* anEvent ) { // // childBeginRun no longer opens files (see newRunSection method) // // // taken from beginRun of FileOtuputModule // (destined for base class?) // //_oidKeepList.clear( ); //EventRecord::ConstIterator iDBUsedSetInfoList( anEvent, "DBUsedSetInfoList"); //if ( iDBUsedSetInfoList.is_valid( ) ) // { // _oidKeepList.push_back( iDBUsedSetInfoList->object_id() ); // } //// Make sure that certain begin run objects are saved //anEvent->setOutputOidKeepList( &_oidKeepList ); return AppResult::OK; } // // from FileOutputModule // AppResult APPLevel3FileOutputModule::terminateIOSystem( ) { errlog.setSubroutine("terminateIOSystem"); AppStream** theStream; bool status( true ); APPListIterator theIterator( *streams( ) ); while ( theStream = theIterator( ) ) { if ( (*theStream)->isEnabled( ) ) { status &= (*theStream)->terminate( ); } } if ( status ) { return AppResult::OK; } else { return AppResult::ERROR; } } // // from FileOutputModule // AppResult APPLevel3FileOutputModule::childInitIOSystem( ) { errlog.setSubroutine("childInitIOSystem"); AppStream** theStream; bool status( true ); APPListIterator theIterator( *streams( ) ); while ( theStream = theIterator( ) ) { if ( (*theStream)->isEnabled( ) && ! (*theStream)->isOpen( ) ) { status &= (*theStream)->configure( ); } } if ( status ) { return AppResult::OK; } else { return AppResult::ERROR; } } AppResult APPLevel3FileOutputModule::outputEvent( AbsEvent*& anEvent, const AppStopType& theDispatchStopType) { // // create the replacement LRIH bank // int noPartition = 0; createLevel3LRIH( noPartition , anEvent); // call childOutputEvent AppResult childResult = childOutputEvent( anEvent, theDispatchStopType ); if ( childResult != AppResult::OK ) return childResult; // check for repeated BOR/EOR events if ( theDispatchStopType == AppStopType::begin_run ) { if ( _sentBeginRun ) { errlog.setSubroutine("APPLevel3FileOutputModule::outputEvent"); errlog(ELinfo, "suppressing multiple BOR event") << endmsg; return AppResult::OK; // don't send repeated BOR events } else { _sentBeginRun = true; _sentEndRun = false; } } if ( theDispatchStopType == AppStopType::end_run ) { if ( _sentEndRun ) { errlog.setSubroutine("APPLevel3FileOutputModule::outputEvent"); errlog(ELinfo, "suppressing multiple EOR event") << endmsg; return AppResult::OK; // don't send repeated EOR events } else { _sentEndRun = true; _sentBeginRun = false; } } // // drop/keep objects according to passed streams // onlineDropKeep(anEvent); // check if error AND RESET ERROR STATUS!!! errorStatus theErrorStatus=errorEvent(true); if (theErrorStatus.first) errlog( ELinfo, "Event had a severe error in processing:") << theErrorStatus.second << endmsg; // // write event to files // (from APPStreamsOutputModule::outputEvent) // AppResult result = AppResult::OK; AppStream** theStream; APPListIterator theIterator( *streams( ) ); while ( theStream = theIterator( ) ) { if ( !(*theStream)->write( anEvent, theDispatchStopType ) ) { errlog( ELerror, "Failed to write to stream") << (*theStream)->name( ) << "This stream will now be closed and disabled." << endmsg; // Try to close it but this might fail too... (*theStream)->close( ); // This will allow us to continue for the other streams while ignoring // this one. (*theStream)->setEnabled( false ); result = AppResult::ERROR; } } if (childResult == AppResult::OK) return result; else return childResult; } const char * APPLevel3FileOutputModule::rcsId( ) const { return rcsid; }