// exitAndInt.cc -- Test of space after int and of setExitTreshold // // // 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. One // programmer sets up this framework to coordinate all code. The // framework controls things like which output destinations exist and // what sort of messages to pass to each destination. // // THIS FRAMEWORK IS A VERY MINIMAL EXAMPLE for illustration. // // A more realistic framework that one could start from for // customizing a framework for production is in frameworkExample.cc. // // ----------------- // Physicsists' Code // ----------------- #include "basicUsage.h" // Would normally include some framework.h; but in this example we // are keeping everything together in one .cc and one .h file. // // Would also include DoPhysics.h, but that is also in basicUsage.h. #include "ErrorLogger/ErrorLog.h" // This is the only ErrorLogger-related include the user normally needs. 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, "Number Sequence" ); for (int q=0; q < 10; q++) errlog << q; errlog << 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; } } if ( errlog.moduleName() != "PHYSICS CODE" ) { errlog( ELfatal, "Bad Module Name" ) << "Result of moduleName() is" << errlog.moduleName() << endmsg; } errlog (ELsuccess, "Event Finished") << "event #" << event.data << endmsg; if ( event.data == 10 ) { errlog( ELsevere2, "Ten Events" ) << endmsg; } // I don't like event 10 if ( event.data == 13 ) { errlog( ELabort, "Thirteen Events" ) << endmsg; } // I REALLY don't like event 13! } // DoPhysics::operator()(event) // --------------- // Framework Code // --------------- #include "basicUsage.h" // 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 "ZMutility/iostream" USING( std::cout ) bool doIsetSpace; Module::Module( const std::string & name ) { errlog.setModule( name ); if (doIsetSpace) errlog.setSpaceAfterInt(true); } int main(int argc, char*argv[]) { cout << "argc = " << argc << "\n"; bool space; bool exit; if (argc != 3) { space = true; exit = true; } else { cout << "argv[0]: " << argv[0] << "\n"; cout << "argv[1]: " << argv[1] << "\n"; cout << "argv[2]: " << argv[2] << "\n"; space = (*argv[1]=='1'); exit = (*argv[2]=='1'); } cout << "space: " << space << " exit: " << exit << "\n"; doIsetSpace = space; ELadministrator * logger = ELadministrator::instance(); // instantiate a logger object if (exit) logger->setExitThreshold(ELsevere2); ELoutput logfileD( "basicUsage.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 ); } // We won't get this far because the 13-th event will log an error with // severity ELabort or before that, ELsevere2 will cause an exit. // 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()