// FIlterModule.cc -- Illustration of using the filterModule and // excludeModule features of ErrorLogger // // ----------------- // Physicsists' Code // ----------------- #include "FilterModule.h" #include "ErrorLogger/ErrorLog.h" // This is the only ErrorLogger-related include the user normally needs. void DoPhysics1::operator()( Event & event ) { errlog( ELerror, "An Event [-1-]" ) << "data = " << event.data << endmsg; } // DoPhysics1::operator()(event) void DoPhysics2::operator()( Event & event ) { errlog( ELerror, "An Event [-2-]" ) << "data = " << event.data << endmsg; } // DoPhysics2::operator()(event) void DoPhysics3::operator()( Event & event ) { errlog( ELerror, "An Event [-3-]" ) << "data = " << event.data << endmsg; } // DoPhysics3::operator()(event) // --------------- // Framework Code // --------------- // The framework would normally include some framework.h, plus Event.h, // Module.h, and the headers for any physicist classes like DoPhysics. // In our illustration these are all in basicUsage.h. // These are the ErrorLogger classes used by the typical framework: #include "ErrorLogger/ELadministrator.h" #include "ErrorLogger/ELdestControl.h" #include "ErrorLogger/ELoutput.h" #include "ErrorLogger/ELstatistics.h" #include "ErrorLogger/ELerrorList.h" #include #include "ZMutility/iostream" USING( std::cout ) Module::Module( const std::string & name ) { errlog.setModule( name ); } int main() { ELadministrator * logger = ELadministrator::instance(); // instantiate a logger object ELoutput logfile1D( "filter1.errlog" ); ELdestControl logfile1 ( logger->attach(logfile1D) ); logfile1.filterModule("PHYSICS 1"); ELoutput output23D( "filter23.errlog" ); ELdestControl output23 ( logger->attach(output23D) ); output23.excludeModule("PHYSICS 1"); ELstatistics stats2D( cout ); ELdestControl stats2 ( logger->attach(stats2D) ); stats2.filterModule("PHYSICS 2"); ELstatistics stats12D( cout ); ELdestControl stats12 ( logger->attach(stats12D) ); stats12.excludeModule("PHYSICS 3"); std::list elist3; std::list elist13; ELerrorList list3D( elist3); ELdestControl list3 ( logger->attach(list3D) ); list3.filterModule("PHYSICS 3"); ELerrorList list13D( elist13); ELdestControl list13 ( logger->attach(list13D) ); list13.excludeModule("PHYSICS 2"); // The following is a list of the modules in this program: DoPhysics1 doPhysics1( "PHYSICS 1" ); DoPhysics2 doPhysics2( "PHYSICS 2" ); DoPhysics3 doPhysics3( "PHYSICS 3" ); int n; for ( n = 1; n <= 5; ++n ) { Event event( n ); doPhysics1( event ); doPhysics2( event ); doPhysics2( event ); doPhysics3( event ); doPhysics3( event ); doPhysics3( event ); doPhysics3( event ); } cout << " elist3.size() = " << elist3.size() << "(should be 20)\n"; cout << " elist13.size() = " << elist13.size() << "(should be 25)\n"; std::list::const_iterator e; cout << "elist3\n\n"; for ( e = elist3.begin(); e != elist3.end(); ++e ) { cout << "Module: " << e->xid().module << "\n"; } cout << "elist13\n\n"; for ( e = elist13.begin(); e != elist13.end(); ++e ) { cout << "Module: " << e->xid().module << "\n"; } return 0; } // main()