// testELerrorList.cc -- Rudimentary use of ELerrorList mechanism: // // This example program is in three logical pieces: // // We show the framework code that would support operations. // // Then we show the user code -- many physicist users could contribute // code of this nature, using errlog in the manner shown. // // Then the framework chooses to examine the error list. // // Portions of the code relevant to the ELerrorList mechanism are // pointed out as follows: <<<---------------- // We base the example around BasicUsage, even though for illustration // purposes we will be skipping the physicist DoPhysics module. // // --------------- // Framework Code // --------------- #include "testELerrorList.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 testELerrorList.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 "ErrorLogger/ErrorObj.h" // <<<---------------- #include // <<<---------------- #include "ZMutility/iostream" USING( std::cout ) ZM_USING_NAMESPACE(zmel) Module::Module( const std::string & name ) { errlog.setModule( name ); } void extractErrorInfo (std::list &); // <<<---------------- // a frameworker-written routine to look at the // buffer of error objects, then reset it. // This is the context supplier: int eventN; // I am making this global just to make it available to the // ClientContext methods. #include "ZMutility/sstream" USING( std::ostringstream ) string ClientContext::summaryContext() const { ostringstream ev; ev << eventN << "/1"; return ev.str(); } string ClientContext::context() const { ostringstream ev; ev << " Run = 1; Event = " << eventN; return ev.str(); } string ClientContext::fullContext() const { return context(); } ClientContext::ClientContext ( ) { } ZM_COVARIANT_TYPE(ELcontextSupplier *, ClientContext *) ClientContext::clone() const { return new ClientContext( *this ); } int main() { ELadministrator * logger = ELadministrator::instance(); // instantiate a logger object ClientContext cctxt; logger->setContextSupplier(cctxt); logger->setProcess("CPU 3"); ErrorLog errlog ("main Module"); // instantiate an ErrorLog for messages from main ELoutput logfileD( "errorList.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 // Now instantiate the ELerrorList destination <<<------------------ std::list theList; ELerrorList bufferD ( theList ); ELdestControl buffer ( logger->attach(bufferD) ); buffer.setThreshold ( ELerror ); #ifdef NOT_HERE ELstatistics statsD( cout ); // a statistics dest ELdestControl stats ( logger->attach(statsD) ); // tell logger about it // Note that this would // be the LOCAL stats #endif // The following is a list of the modules in this program: DoPhysics doPhysics( "PHYSICS CODE" ); // There is only one module in this illustration. for ( eventN = 1; eventN < 17; ++eventN ) { Event event( eventN ); doPhysics( event ); extractErrorInfo ( theList ); } return 0; } // main() void extractErrorInfo (std::list & theList) { // <<<---------------- // a frameworker-written routine to look at the // buffer of error objects, then reset it. if (!theList.empty()) { cout << "******************************************\n\n"; cout << " One or more errors happened on this event\n\n"; std::list::const_iterator e; for ( e = theList.begin(); e != theList.end(); ++e ) { cout << " --------------------------------------\n\n"; cout << " mySerial = " << e->serial() << "\n"; cout << " myProcess = " << e->xid().process << "\n"; cout << " myModule = " << e->xid().module << "\n"; cout << " mySubroutine = " << e->xid().subroutine << "\n"; cout << " mySeverity = " << e->xid().severity << "\n"; cout << " myId = " << e->xid().id; cout << " myIdOverflow = " << e->idOverflow() << "\n"; cout << " myTimeStamp = " << e->timestamp() << "\n"; const ELlist_string & items = e->items(); ELlist_string::const_iterator item; for (item = items.begin(); item != items.end(); item++) { cout << " " << *item << "\n"; } } theList.clear(); } cout << "\n******************************************\n\n"; } // ----------------- // Physicsists' Code // ----------------- #include "testELerrorList.h" #include "ErrorLogger/ErrorLog.h" void DoPhysics::operator()( Event & event ) { // This is the same as per basicUsage, except the context is also set up. errlog( ELsuccess, "An Event" ) << "data = " << event.data << endmsg; if ( event.data == 9 ) { errlog( ELerror, "Ninth Event" ) << endmsg; } // I don't like event number 9. if ( event.data == 11 ) { errlog( ELerror2, "Eleventh Event" ) << "@SUB=DoPhys" << "and more info" << endmsg; errlog( ELerror, "Eleventh Event B" ) << "second message" << endmsg; } // I don't like event number 11 either. int sum = 0; for (int i = 1; i <= event.data; i++) { sum += i*(event.data+i); if (sum > 100) { errlog( ELerror, "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)