// FIlterModule.cc -- Illustration of using the ignoreModule and // respondToModule features of ErrorLogger // // ----------------- // Physicsists' Code // ----------------- #include "IgnoreModule.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( "respond.errlog" ); ELdestControl logfile1 ( logger->attach(logfile1D) ); ELoutput logfile2D( "ignore.errlog" ); ELdestControl logfile2 ( logger->attach(logfile2D) ); ELstatistics statsD( cout ); ELdestControl stats ( logger->attach(statsD) ); std::list elist; ELerrorList list1D( elist); ELdestControl list1 ( logger->attach(list1D) ); // 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 <= 9; ++n ) { Event event( n ); doPhysics1( event ); doPhysics2( event ); doPhysics3( event ); if ( n == 1 ) { logfile1.ignoreModule ("*"); logfile1.respondToModule ("PHYSICS 1"); logfile2.respondToModule ("*"); logfile2.ignoreModule ("PHYSICS 1"); stats.ignoreModule ("*"); stats.respondToModule ("PHYSICS 1"); list1.ignoreModule ("*"); } if ( n == 2 ) { logfile1.respondToModule ("PHYSICS 2"); logfile2.ignoreModule ("PHYSICS 2"); stats.respondToModule ("PHYSICS 2"); list1.respondToModule ("PHYSICS 1"); } if ( n == 3 ) { logfile1.respondToModule ("PHYSICS 3"); logfile2.ignoreModule ("PHYSICS 3"); stats.ignoreModule ("PHYSICS 2"); list1.respondToModule ("PHYSICS 2"); } if ( n == 4 ) { logfile1.ignoreModule ("PHYSICS 1"); logfile2.respondToModule ("PHYSICS 1"); stats.respondToModule("*"); list1.respondToModule ("PHYSICS 3"); } if ( n == 5 ) { logfile1.ignoreModule ("PHYSICS 2"); logfile2.respondToModule ("PHYSICS 2"); stats.ignoreModule("*"); list1.respondToModule ("*"); list1.ignoreModule ("PHYSICS 1"); } if ( n == 6 ) { logfile1.ignoreModule ("PHYSICS 3"); logfile2.respondToModule ("PHYSICS 3"); stats.respondToModule("PHYSICS 3"); list1.ignoreModule ("PHYSICS 2"); } if ( n == 7 ) { logfile1.respondToModule ("PHYSICS 1"); logfile1.respondToModule ("PHYSICS 2"); logfile1.respondToModule ("PHYSICS 3"); logfile1.ignoreModule ("*"); logfile1.respondToModule ("PHYSICS 1"); logfile2.ignoreModule ("PHYSICS 1"); logfile2.ignoreModule ("PHYSICS 2"); logfile2.ignoreModule ("PHYSICS 3"); logfile2.respondToModule ("*"); logfile2.ignoreModule ("PHYSICS 1"); stats.respondToModule("PHYSICS 2"); list1.respondToModule ("PHYSICS 1"); } if ( n == 8 ) { logfile1.respondToModule ("*"); logfile1.ignoreModule ("PHYSICS 1"); logfile2.ignoreModule ("*"); logfile2.respondToModule ("PHYSICS 1"); stats.respondToModule("PHYSICS 1"); list1.ignoreModule ("PHYSICS 1"); } } cout << " elist.size() = " << elist.size() << "(should be 15)\n"; std::list::const_iterator e; cout << "elist\n\n"; for ( e = elist.begin(); e != elist.end(); ++e ) { cout << "Module: " << e->xid().module << "\n"; } return 0; } // main()