// switchOstream -- test of the changeFIle() and related // ErrorLogger mechanisms. // // This example program is in two logical pieces, as per basicUsage: // // 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. // // ----------------- // Physicsists' Code // ----------------- #include "switchOstream.h" #include "ErrorLogger/ErrorLog.h" #include "ZMutility/iostream" #include "ZMutility/fstream" ZM_USING_NAMESPACE(zmel) void DoPhysics::operator()( Event & event ) { errlog(ELerror, "data output") << "Event " << event.data << endmsg; return; } // DoPhysics::operator()(event) // --------------- // Framework Code // --------------- #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 ); } void doWithEvent (Event & e, DoPhysics & doPhysics, int n) { e.data=n; doPhysics(e); } int main() { ELadministrator * logger = ELadministrator::instance(); // instantiate a logger object ELoutput outputD( cout ); // an 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 stats.setThreshold ( ELinfo ); // ignore messages below // ELinfo // Now the important destinations for the test: ELoutput logoddevenO( "ZZodd.errlog" ); ELdestControl logoddeven ( logger->attach(logoddevenO) ); logoddeven.setThreshold ( ELinfo ); std::ofstream * osp1 = new std::ofstream("ZZgroup1-5.errlog", std::ios::app); ELoutput loggroupsO( *osp1 ); ELdestControl loggroups ( logger->attach(loggroupsO) ); loggroups.setThreshold ( ELinfo ); // The following is a list of the modules in this program: DoPhysics doPhysics( "PHYSICS CODE" ); // There is only one module in this illustration. Event event(0); doWithEvent(event,doPhysics,1) ; logoddeven.changeFile("ZZeven.errlog"); doWithEvent(event,doPhysics,2) ; logoddeven.changeFile("ZZodd.errlog"); doWithEvent(event,doPhysics,3) ; logoddeven.changeFile("ZZeven.errlog"); doWithEvent(event,doPhysics,4) ; logoddeven.changeFile("ZZodd.errlog"); doWithEvent(event,doPhysics,5) ; std::ofstream * osp2 = new std::ofstream("ZZgroup6-10.errlog",std::ios::app); loggroups.changeFile(*osp2); logoddeven.changeFile("ZZeven.errlog"); doWithEvent(event,doPhysics,6) ; loggroups.flush(); // wont be able to tell if this had effect, but... logoddeven.changeFile("ZZodd.errlog"); doWithEvent(event,doPhysics,7) ; // testing the non-recommened mantra (which should work here anyway) std::ofstream * oseven = new std::ofstream( "ZZeven.errlog", std::ios::app ); logoddeven.changeFile ( *oseven ); doWithEvent(event,doPhysics,8) ; logoddeven.changeFile("ZZodd.errlog"); doWithEvent(event,doPhysics,9) ; logoddeven.changeFile("ZZeven.errlog"); doWithEvent(event,doPhysics,10) ; // testing the non-recommened mantra (which should work here anyway) loggroups.changeFile("ZZgroup1-5.errlog"); logoddeven.changeFile("ZZodd.errlog"); doWithEvent(event,doPhysics,11) ; logoddeven.changeFile("ZZeven.errlog"); doWithEvent(event,doPhysics,12) ; logoddeven.changeFile("ZZodd.errlog"); doWithEvent(event,doPhysics,13) ; logoddeven.changeFile("ZZeven.errlog"); doWithEvent(event,doPhysics,14) ; logoddeven.changeFile("ZZodd.errlog"); doWithEvent(event,doPhysics,15) ; loggroups.changeFile(*osp2); logoddeven.changeFile("ZZeven.errlog"); doWithEvent(event,doPhysics,16) ; logoddeven.changeFile("ZZodd.errlog"); doWithEvent(event,doPhysics,17) ; logoddeven.changeFile("ZZeven.errlog"); doWithEvent(event,doPhysics,18) ; logoddeven.changeFile("ZZodd.errlog"); doWithEvent(event,doPhysics,19) ; logoddeven.changeFile("ZZeven.errlog"); doWithEvent(event,doPhysics,20) ; (*osp2) << "deleting osp2 at the end\n"; delete osp2; (*oseven) << "deleting oseven at the end\n"; delete oseven; (*osp1) << "deleting osp1 at the end\n"; delete osp1; return 0; } // main()