// TSusage.cc -- Illustration of using the basic features of // ThreadSafeErrorLogger mechanism with just 1 thread. // // This example program is in two logical pieces: // // First we show the user code -- many physicist users could contribute // code of this nature, using errlog in the manner shown. // // Then we show the framework code that would support this. // // This code is VERY similar to basicUsage.cc // Look for // <------ *** to see the modifications // ----------------- // Physicsists' Code // ----------------- #include "TSusage.h" // <------ *** #include "ErrorLogger/ThreadSafeErrorLog.h" // <------ *** void DoPhysics::operator()( Event & event ) { // THIS METHOD IS WHERE ALL THE PHYSICS CALCULATION WOULD GO. if ( event.data == 1 ) { errlog( ELerror, "Format Test" ) << "abcde" << "FGHIJ" << "klmno" << endmsg; errlog( ELerror, "Format Test" ) << "12345678901234567890" << endmsg; } errlog( ELsuccess, "An Event" ) << "data = " << event.data << endmsg; if ( event.data == 9 ) { errlog( ELerror, "Ninth Event" ) << endmsg; } // I don't like event number 9. int sum = 0; for (int i = 1; i <= event.data; i++) { sum += i*(event.data+i); if (sum > 100) { errlog( ELwarning, "Big Sum" ); errlog << "event " << event.data; errlog << " i = " << i; errlog << " sum = " << sum << endmsg; break; } } errlog (ELsuccess, "Event Finished") << "event # " << event.data << endmsg; if ( event.data > 12 ) { errlog( ELabort, "> Twelve Events" ) << endmsg; } // I REALLY don't like event 13! } // DoPhysics::operator()(event) // --------------- // Framework Code // --------------- #include "TSusage.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 "ZMutility/iostream" USING( std::cout ) Module::Module( const std::string & name ) { errlog.setModule(name); // <------ *** } BrainDeadMutex::BrainDeadMutex() { // <------ *** cout << "\n -- LOCK -- LOCK -- LOCK -- LOCK -- LOCK -- \n"; } // <------ *** BrainDeadMutex::~BrainDeadMutex() { // <------ *** cout << " -- UNLOCK -- UNLOCK -- UNLOCK -- UNLOCK -- \n\n";}// <------ *** int main() { // Exactly as in basicUsage! ELadministrator * logger = ELadministrator::instance(); // instantiate a logger object ELoutput logfileD( "TSusage.errlog" ); // make an ELdestination ELdestControl logfile ( logger->attach(logfileD) ); // tell logger about it logfile.setThreshold ( ELsuccess ); // ignore messages below // ELsucess ELoutput outputD( cout ); // another ELdestination ELdestControl output ( logger->attach(outputD) ); // tell logger about it output.setThreshold ( ELerror ); // ignore messages below // ELerror ELstatistics statsD( cout ); // a statistics dest ELdestControl stats ( logger->attach(statsD) ); // tell logger about it // The following is a list of the modules in this program: DoPhysics doPhysics( "PHYSICS CODE" ); // There is only one module in this illustration. int n; for ( n = 1; n < 20; ++n ) { Event event( n ); doPhysics( event ); if (n%4 == 0) { stats.summary( output, "Error Statistics So Far" ); } } // We won't get this far because the 13-th event will log an error with // severity ELabort. // Because statsD was given an argument of cout when constructed, one // last summary will be sent to cout when the job terminates. cout << "REAL BAD PROBLEM -- SHOULD NOT HAVE COMPLETED FOR LOOP!\n"; return 0; } // main()