// SampleModuleA.cc // // This is part of the principal sample of how to use the ErrorLogger // mechanism in a realistic setting. // // The overall structure assumed is that some programmer(s) provide a // "framework" including the main program, various setups and event-flow // controls, and so forth. Then each group of physicists provide "modules" // (or, in D0 language, "packages") which do steps of physics calculation -- // the framework will pass an event from package to package. // // This sample is composed of five files: // SampleFramework // SampleModule // SampleEvent // SampleModuleA contains the physics code written by group A to act // as module A. This has just one .h and one .cc file, // though actual physics code would probably have // files for each indiviedual subroutine. // SampleModuleB // #include "SampleModuleA.h" SampleModuleA::SampleModuleA ( const std::string & name ) : SampleModule(name) { } void SampleModuleA::invoke ( Event & event ) { // This module chooses to set the subroutine before each subroutine is // called. This puts no burden on code that issues an error message, but // it does involve one extra method called even when no errors occur. // There is another option, illustrated in SampleModuleB. errlog.setSubroutine ("trackSeeds"); trackSeeds (event); errlog.setSubroutine ("roadTracks"); roadTracks (event); errlog.setSubroutine ("assignHits"); assignHits (event); errlog.setSubroutine ("A::invoke"); errlog ( ELsuccess, "Module A Finished" ) << endmsg; } void SampleModuleA::trackSeeds ( Event & event ) { // Do something to the event ... event.datum += 10; // Sometimes there is an error detected at this stage ... if ( (event.datum % 13) == 5 ) { errlog (ELerror, "Can't find seeds") << "datum =" << event.datum << endmsg; } } // trackSeeds() void SampleModuleA::roadTracks ( Event & event ) { // Do something to the event ... event.datum += 20; // Sometimes we need to issue a warning ... if ( (event.datum % 1000) >= 950 ) { errlog (ELwarning, "Multiple Roads") << "road index =" << event.datum%1000 << endmsg; } } // roadTracks void SampleModuleA::assignHits ( Event & event ) { // Do something to the event ... event.datum *= 2; // For some events, something happens that is so bad we want to skip // all the remaining modules. We do that by issuing this error message: if ( (event.datum % 17) == 0 ) { errlog (ELnextEvent, "Divisible by 17") << "datum =" << event.datum << endmsg; } } // assignHits