|
//____________________________________________________________________ // // BRAHMS Analysis Module Class // // A standard Physics analysis Module should be derived from // this base class. This ensure that the general framework // is capable of accessing these in a common and general way. // The methods (member functions) consists of a general set for // all modules; but the user if free to add specific ones for // specific needs. Ideas for this has been taken from the // CDF/E802 Analysis Control as well as from the BABAR framework. // The initial version is derived from the ROOT base classes, // It should be relatively simple to re-write it using non-root // container classes etc. // // Author : Flemming Videbaek // Created: 27/12/97 // Version: 1.0 // // The standard methods defined for a module are: // ---------------------------------------------- // // Init() // This methods finishes the initialisation of the module, that // is after all user parameters for the module has been // set. This message is sent once per job. External // parameters should be referenced at this time. // A method intended to be used for modules that cannot be // completely initialized by the constrcutor and needs // additional setups. It is the responsibility of the user // modules to give out warnings if the init has not been // called. // // Book() // Book histograms if defined in the DefineHistograms() method, // The booking method ensures that the histograms are added to the // list of known histograms. // // Begin() // Send at run initialisation time. That is once per run. This // method can for example update references to external // parameters, such as database entries and so on. // // Event(BrEventNode* , BrEventNode*) // A module may use both nodes. The normal convention is that // the first node is input i.e. module should look for // dataobjects in this node, The second node may be // empty. Normal use is to add dataobjects to this. The main // program/shell will control the vent nodes. All data objects // added to the node will be owned by the node. Thus the node // will delete at end of event. // // End() // Send at the end of a run. This should flush histograms, // etc. specific for this run to disk and so on. Also, one may // need to tidy up some stuff before the next Begin. // // Finish() // Send at end of a job. This should do the final write of data // to permanent store and so on. // // // Flow in a module: // ----------------- // // +-------------------+ // | Set up job things | // +-------------------+ // | // +--------------------+ // | Initialize job | // | [BrModule::Init()] | // +--------------------+ // | // no o------------------------o // +-<---| More runs to process ? |---<----------+ // | o------------------------o | // | | yes | // | +---------------------+ +-------------------+ // | | Initialize for run | | Finish run | // | | [BrModule::Begin()] | | [BrModule::End()] | // | +---------------------+ +-------------------+ // | | | // | o-------------------------o no | // | +--| More events to process? |-->----------+ // | | o-------------------------o // | ^ | yes // | | +---------------------+ // | +----| Process event | // | | [BrModule::Event()] | // | +---------------------+ // | // | // +----------------------+ // | Finish job | // | [BrModule::Finish()] | // +----------------------+ // // // Error handling and state information: // ------------------------------------- // // A few methods are avaliable for communicating the status of the // module. // // Stop(<location>, <format string>, ...) // Flag this module as having not being able to fullfil it's // requirements. That is, the module pipeline should stop after // this module. Note, sending this message in Init() will stop the // current job altogether, and in Begin() will stop that run loop // altogether. If verbose flag is greater then, or equal to // kShowStop, then also output message. If this failure makes the // total number of failures for this module exceed the stop limit // (as set by BrModule::SetStopLimit), then promote this stop to a // Failure (see BrModule::Failure). // // Failure(<location>, <format string>, ...) // Flag this module as having failed. If verbose flag is greater // then, or equal to kShowFailure, then also output message. If // this failure makes the total number of failures for this module // exceed the failure limit (as set by BrModule::SetFailureLimit), // then promote this failure to a Abort (see // BrModule::Abort). Normally a Failure should not stop the // event processing, but should stop the module from doing more // work. // // Abort<location>, <format string>, ...) // Flag this module as having failed misaerably, and output // message. A BrModuleContainer should always react to this by // stoping the module loop, since this flag means that something // is very VERY screwy. This should abort the event processing all // together. // // Notice that TObject::Warning, TObject::Error, and TObject::Fatal // are reserved for serious errors. // //____________________________________________________________________ // // $Id: BrModule.cxx,v 1.7 2002/03/12 11:50:14 cholm Exp $ // $Author: cholm $ // $Date: 2002/03/12 11:50:14 $ // // Update History: // FV March 28 ,1999 // Changed HistOn, HistOff, Dis/EnableHistograms to be non-virtual // functions. It is not not up to the user to modify this behaviou. // FV April 19,1999 // Added methods SetHistOn() , SetHistOff(), and SetHistBooked() // #ifndef BRAT_BrModule #include "BrModule.h" #endif #ifndef BRAT_BrModuleManager #include "BrModuleManager.h" #endif #ifndef ROOT_TClass #include "TClass.h" #endif #ifndef ROOT_TError #include "TError.h" #endif #if ROOT_VERSION_CODE >= ROOT_VERSION(3,0,1) #include "TStreamerInfo.h" #endif #ifndef ROOT_TDirectory #include "TDirectory.h" #endif #ifndef __IOSTREAM__ #include <iostream> #endif #ifndef __IOMANIP__ #include <iomanip> #endif //____________________________________________________________________ ClassImp(BrModule); //____________________________________________________________________ BrModule::BrModule() { // Vanilla constructor; Should not be called within the ROOT // environment. // fVerbose = 0; fHistograms = 0; fDebugLevel = 0; fCpuTime = 0; fHistOn = kFALSE; fHistBooked = kFALSE; fRequiredTableList = 0; fState = kSetup; fStatus = kOk; fStopCount = 0; fFailureCount = 0; fStopLimit = 2147483647; // The largest possible int fFailureLimit = 10; } //____________________________________________________________________ BrModule::BrModule(const Char_t *name, const Char_t *title) : TNamed(name, title) { // Constructor. This is the default constructor to use. The names of // the Modules can be used for navigation and identification. fVerbose = 0; fHistograms = 0; fDebugLevel = 0; fCpuTime = 0; fHistOn = kFALSE; fHistBooked = kFALSE; fRequiredTableList = 0; fState = kSetup; fStatus = kOk; fStopCount = 0; fFailureCount = 0; fStopLimit = 2147483647; // The largest possible int fFailureLimit = 10; // // Register Module with BrModuleManager // BrModuleManager* manager = BrModuleManager::Instance(); manager->AddModule(this); } //_________________________________________________________________ BrModule::~BrModule() { // // default destructor // Histograms are assumed to have been generated inside the // Book method and ownership set to the histogram list // if(fHistograms){ fHistograms->Delete(); delete fHistograms; } if(fRequiredTableList) delete fRequiredTableList; } //____________________________________________________________________ void BrModule::Event() { // Event method with no Data objects. // This method is called once per event. Debug(1, "Event()", "for %s", GetName()); } //____________________________________________________________________ void BrModule::Event(BrEventNode* inev, BrEventNode* outev) { // // Default Event method with in/out Data objects. In normal // application to be called once per event. Method should also be // overwritten in the concrete class. // This method is called once per event. // A dummy routine is supplied in case a module for some strange // reason is not called per event. // Debug(1, "Event(node,node)", "for %s", GetName()); } //_________________________________________________________________ void BrModule::Book() { // Booking method for Module class. // This method in turns calls the 'user overrrideen method // DefineHistograms' and adds all defined histograms to the // histogram list for the module. If the user wants to have these in // a specific root directory this should be setup in // DefineHistogram() method. Following Booking histogramming is // enabled. It can be turned on/off using the EnableHistograms() // DisableHistogram() // Once added to this list the histograms should be considerd owned // by Module. if(fHistograms){ Warning("Book","Histograms already booked for this module"); return; } TDirectory* oldGDir = gDirectory; fHistograms = new TList(); TObject *objfirst, *objlast; objlast = gDirectory->GetList()->Last(); // Call overloaded method from the derived class DefineHistograms(); if(objlast) objfirst = gDirectory->GetList()->After(objlast); else objfirst = gDirectory->GetList()->First(); if (objfirst && objfirst->IsA()->InheritsFrom("TDirectory")) { gDirectory->cd(objfirst->GetName()); objfirst = gDirectory->GetList()->First(); } while(objfirst) { fHistograms->Add(objfirst); objfirst = gDirectory->GetList()->After(objfirst); } fHistBooked = kTRUE; fHistOn = kTRUE; oldGDir->cd(); } //_________________________________________________________________ void BrModule::EnableHistograms() { // Enable use of histograms if(fHistBooked) fHistOn = kTRUE; else Warning("EnableHistograms","Booking has not been done"); } //_________________________________________________________________ void BrModule::DisableHistograms() { // Disable use of histograms if(fHistBooked) fHistOn = kFALSE; else Warning("DisableHistograms","Booking has not been done"); } //_________________________________________________________________ void BrModule::Print(Option_t* option) { // Information module. In the final implementation this MUST be // overwritten by the derived class. Here a default behaviour is // implemented. // // Options: // D show all the details // H show list of histograms // B DO NOT show basic information // // This non-const version is only kept for backward compatibility // with ROOT pre3. Will soon disappear! TString opt(option); opt.ToLower(); if (opt.Contains("b")) cout << "*************************************************" << endl << endl << " Module" << endl << " Class : " << IsA()->GetName()<< endl << " Name : " << GetName() << endl << " Title : " << GetTitle() << endl << endl << "-------------------------------------------------" << endl; if (opt.Contains("d")) { // Print all details cout << " Debug level: " << fDebugLevel << endl << " Verbosity: " << fVerbose << endl << " # of stops: " << fStopCount << "/" << fStopLimit << endl << " # of failures: " << fFailureCount << "/" << fFailureLimit << endl << " State: " << flush; switch (fState) { case kSetup: cout << "setup time" << endl; break; case kInit: cout << "Init time" << endl; break; case kBegin: cout << "Begin time" << endl; break; case kEvent: cout << "Event time" << endl; break; case kEnd: cout << "End time" << endl; break; case kFinish: cout << "Finish time" << endl; break; default: cout << "Unknown!!!" << endl; } cout << " Status: " << flush; switch (fStatus) { case kOk: cout << "everything's just dandy" << endl; break; case kStop: cout << "wants pipeline stoped" << endl; break; case kFailure: cout << "failed" << endl; break; case kAbort: cout << "failed miserably" << endl; break; default: cout << "Unknown!!!" << endl; } cout << " Histograms: " << (fHistOn ? "on" : "off") << " and " << (fHistBooked ? "booked" : "not booked") << endl << "-------------------------------------------------" << endl; } if (opt.Contains("h")) { cout << " Histograms: " << flush; if (!fHistOn || !fHistBooked) cout << "not on or booked" << endl; else { cout << endl; TIter next(fHistograms); TObject* o = 0; while ((o = next())) o->Print(option); } cout << "-------------------------------------------------" << endl; } } //_________________________________________________________________ void BrModule::Print(Option_t* option) const { // Information module. In the final implementation this MUST be // overwritten by the derived class. Here a default behaviour is // implemented. // // Options: // D show all the details // H show list of histograms // B show basic information (default) // E show event statistics // TString opt(option); opt.ToLower(); if (opt.Contains("b")) cout << "*************************************************" << endl << endl << " Module" << endl << " Class : " << IsA()->GetName()<< endl << " Name : " << GetName() << endl << " Title : " << GetTitle() << endl << endl << "-------------------------------------------------" << endl; if (opt.Contains("e")) cout << " Accumulated CPU time: " << setprecision(5) << setw(10) << fCpuTime << endl; if (opt.Contains("d")) { // Print all details cout << " Debug level: " << fDebugLevel << endl << " Verbosity: " << fVerbose << endl << " # of stops: " << fStopCount << "/" << fStopLimit << endl << " # of failures: " << fFailureCount << "/" << fFailureLimit << endl << " State: " << flush; switch (fState) { case kSetup: cout << "setup time" << endl; break; case kInit: cout << "Init time" << endl; break; case kBegin: cout << "Begin time" << endl; break; case kEvent: cout << "Event time" << endl; break; case kEnd: cout << "End time" << endl; break; case kFinish: cout << "Finish time" << endl; break; default: cout << "Unknown!!!" << endl; } cout << " Status: " << flush; switch (fStatus) { case kOk: cout << "everything's just dandy" << endl; break; case kStop: cout << "wants pipeline stoped" << endl; break; case kFailure: cout << "failed" << endl; break; case kAbort: cout << "failed miserably" << endl; break; default: cout << "Unknown!!!" << endl; } cout << " Histograms: " << (fHistOn ? "on" : "off") << " and " << (fHistBooked ? "booked" : "not booked") << endl << "-------------------------------------------------" << endl; } if (opt.Contains("h")) { cout << " Histograms: " << flush; if (!fHistOn || !fHistBooked) cout << "not on or booked" << endl; else { cout << endl; TIter next(fHistograms); TObject* o = 0; while ((o = next())) o->Print(option); } cout << "-------------------------------------------------" << endl; } } //_________________________________________________________________ void BrModule::SetRequiredData(Char_t* name) { // // Set the name of a required DataObject. The name will be stored in // a list. The intent is that the calling Event method can check against // the names (by calling a basSe Module member function which will search // the input Event and return a pointer to the object. // // CheckDataObjects(); // GetDataObject // Note none of this is implemented so far. // 2/17/98 // } //_________________________________________________________________ void BrModule::EventStatisticsStart() { // Start the timer for the statistics output fTimer.Stop(); fTimer.Start(); } //_________________________________________________________________ void BrModule::EventStatisticsEnd() { // Stop the timer for the statistics output fTimer.Stop(); fCpuTime += fTimer.CpuTime(); } //_________________________________________________________________ void BrModule::ListEventStatistics() { // List the event statistics from the timer. Presupposes that // EventStatisticsStart() and EventStatisticsEnd() has been called if (Verbose()) cout << "Accumulated CPU time in " << GetTitle() << " is " << setprecision(5) << setw(10) << fCpuTime<<endl; } //____________________________________________________________________ void BrModule::AddRequiredTable(TObject *tablename) { // Add a table to the list of requirted tables if (fRequiredTableList) fRequiredTableList->Add(tablename); } //_________________________________________________________________ void BrModule::Info(Int_t lvl, const char *location, const char *va_(fmt), ...) const { // Information print out, if the verbosity level is greater than or // equal to first argument lvl. Remaining arguments as in // TObject::Warning and similar if (fVerbose < lvl) return; va_list ap; va_start(ap, va_(fmt)); DoError(kInfo, location, va_(fmt), ap); va_end(ap); } //_________________________________________________________________ void BrModule::Debug(Int_t lvl, const char *location, const char *va_(fmt), ...) const { // Debug print out, if the debug level is greater than or // equal to first argument lvl. Remaining arguments as in // TObject::Warning and similar. Please note that the line is // prefixed with 'Info' and not debug - sorry, but we need our own // error handler to handle that properly. if (fDebugLevel < lvl) return; va_list ap; va_start(ap, va_(fmt)); DoError(kInfo, location, va_(fmt), ap); va_end(ap); } //____________________________________________________________________ void BrModule::Stop(const char *location, const char *va_(fmt), ...) const { // Flag this module as having not being able to fullfil it's // requirements. That is, the module pipeline should stop after this // module. Note, sending this message in Init() will stop the // current job altogether, and in Begin() will stop that run loop // altogether. If verbose flag is greater then, or equal to // kShowStop, then also output message. If this failure makes the // total number of failures for this module exceed the stop limit // (as set by BrModule::SetStopLimit), then promote this stop to // a Failure (see BrModule::Failure). // Increment failure counter fStopCount++; // if inside limits, set status to kFailure if(fStopCount < fStopLimit) { fStatus = kStop; // If verbosity is greater than or equal to kShowFailures, then // print the message if (fVerbose >= kShowStop) { va_list ap; va_start(ap, va_(fmt)); DoError(fStatus, location, va_(fmt), ap); va_end(ap); } } // If out side of limits, turn this Failure into a disaster. else Failure("Stop","Stop limits reached at %d", fStopCount); } //____________________________________________________________________ void BrModule::Failure(const char *location, const char *va_(fmt), ...) const { // Flag this module as having failed. If verbose flag is greater // then, or equal to kShowFailure, then also output message. If // this failure makes the total number of failures for this module // exceed the failure limit (as set by BrModule::SetFailureLimit), // then promote this failure to a Abort (see BrModule::Abort). // Increment failure counter fFailureCount++; // if inside limits, set status to kFailure if(fFailureCount < fFailureLimit) { fStatus = kFailure; // If verbosity is greater than or equal to kShowFailures, then // print the message if (fVerbose >= kShowFailures) { va_list ap; va_start(ap, va_(fmt)); DoError(fStatus, location, va_(fmt), ap); va_end(ap); } } // If out side of limits, turn this Failure into a disaster. else Abort("Failure","Failure limits reached at %d", fFailureCount); } //____________________________________________________________________ void BrModule::Abort(const char *location, const char *va_(fmt), ...) const { // Flag this module as having failed misaerably, and output // message. A BrModuleContainer should always react to this by // stoping the module loop, since this flag means that something is // very VERY screwy. fStatus = kAbort; va_list ap; va_start(ap, va_(fmt)); DoError(fStatus, location, va_(fmt), ap); va_end(ap); } // $Log: BrModule.cxx,v $ // Revision 1.7 2002/03/12 11:50:14 cholm // Changes Info messages in dummy Event methods to Debug messages. // // Revision 1.6 2001/12/14 15:31:52 cholm // Removed the Info(void) method, since it's been obsolted by Print(Option_t*) // for while now. Instead I've added the methods // Info(Int_t,const Char_t*, const Char_t*, ...) // Debug(Int_t,const Char_t*, const Char_t*, ...) // for printing information and debug messages to stderr. // // Revision 1.5 2001/08/21 16:07:23 cholm // Tidy up. // // Revision 1.4 2001/08/20 19:03:15 jens // Fixed bug in BrModule::Book. Now the function restores gDirectory when completed. // // Revision 1.3 2001/08/16 15:49:15 jens // // BrModule // As many decendants of BrModule create subdirectories for their histograms, the // BrModule::Book now checks if newly created object is TGDirectory and eventually // add histograms from there to fHistograms. // // Revision 1.2 2001/06/22 11:13:38 cholm // REmoved custom streamer - this class is not persistent // // Revision 1.1.1.1 2001/06/21 14:55:04 hagel // Initial revision of brat2 // // Revision 1.29 2001/06/16 17:40:46 videbaek // Added a ModuleManager. This class will contain a complete list // of all module constructed in a session, and may be useful to // keep track of parameters etc. // The usage is complete transparent. If one has no intention of // using it all activity is in the constructor of any BrModule, that is it. // At present the manager only has one useful method Print that in turns // call the Print method for all Modules. // // Revision 1.28 2001/03/07 12:15:46 cholm // * Defined standard BrModule methods in BrIOModule. // * Add the (simple) class BrHistIOModule. // * BrAppOptionManager and BrAppOption classes changed to not use // BrExceptions. // * Added the method Int_t BrMainModule::Main() to do EVERYTHING. // * Made the method BrModule::Info() const obsolete in favour of // BrModule::Print(Option_t* option="B") const. Impact on other classes. // // Revision 1.27 2001/01/24 16:27:56 cholm // Corrected Streamer from hack (see previous log) to a more workable // solution. Now it's backward compatible with ROOT 2.25/03. Correction thanks // to Rene Brun. // // Revision 1.26 2001/01/23 16:32:31 cholm // Hack to make rootcint (CINT) ignore variadic arguments in BrException // classes. // fixed module stremaers. // // Revision 1.25 2001/01/22 19:58:28 cholm // Corrected const-ness of BrAppOption::Compare for old ROOT versions. // Fixed BrModule::Streamer to work with new ROOT. Changed the avaliable // module status values to kStop, kFailure, kAbort, and updated // BrModuleContainer and BrModule accordingly. Also renamed BrIOModule::fStatus // to BrIOModule::fIOStatus. BrEventIO uses Stop, Failure, and Abort now. // Also fix of BrEventIO::Streamer for ROOT 3.00/00+ // // Revision 1.24 2001/01/19 16:36:07 cholm // Updated BrAppOption for const'ness of compare. // Added state and status information to BrModule. A container may inspect // these react accordingly, for example by aborting the processing of the // current event, sequnce, run, job, etc. // // Revision 1.23 2000/11/23 01:30:39 brahmlib // Changed name/title types to const Char_t* instead of Char_t* in CTOR. // // Revision 1.22 2000/09/26 20:35:25 cholm // * Cleaned up BrModule e.g., d_Debug => fDebug // * Made BrModuleContainer a BrModule // * Added the class BrMainModule (singleton) for complex structuring of // modules in any application using BrModules // // Revision 1.21 2000/06/04 21:38:18 videbaek // Changed the BrModule class to have the warning and error counters being // mutable; thus can be used in a const method Warning and Error. // This should fix the problem reported by S.Sanders when compiling on LinuxPPC // and should be sound enough for application. // // Revision 1.20 2000/06/03 18:20:49 videbaek // Maded BrEbentIO derice from BrModule and related changes. // // Revision 1.19 2000/05/17 10:36:25 ouerdane // see top of file // // Revision 1.18 2000/02/04 15:51:25 videbaek // Changed formats. // // Revision 1.17 2000/01/28 17:16:17 alv // Fixed timing for first event // // Revision 1.16 1999/04/21 14:48:05 videbaek // Added Methods SetHistOn() .. see comments // Changed name of Tree from example.. // // Revision 1.15 1999/04/09 19:36:45 videbaek // Clean up code; add ListStatistics to container class // Improve include guards. // // Revision 1.14 1999/03/07 22:40:00 videbaek // Added Warning and warning limits for output // // Revision 1.13 1999/02/25 15:01:39 videbaek // Add a memeber function Warning at the BrModule level. This has a buildin limit counter // such that Warning will not go on for all events. // The code is copied for the TObject::Warning. // // Revision 1.12 1999/01/21 23:35:42 hagel // Changed #ifndef's in .cxx files for include files to reflect changes to // .h files according to BRAT convention. It should be noted that very few // of the .cxx source files have the protections. Should this be systematically // changed. // // Revision 1.11 1999/01/15 15:32:32 videbaek // Updates to volume files. // Added member histon to BrModule, and member function HistOn(). // Added BrMath as standard math library. // // Revision 1.10 1998/12/21 20:18:33 videbaek // Added magnet voluems. Additional features for Modules. // New BrMatch intended to replace TSonataMath. Some changes in // matrix routines. // // Revision 1.8 1998/10/09 19:28:44 videbaek // cosmetic changes // // Revision 1.7 1998/09/18 18:55:12 alv // Fixed double accumulation of CPU time in EventStatisticsEnd. // // Revision 1.6 1998/09/08 15:22:47 alv // Added include statement for TDirectory.h to declare gDirectory used in Book. // // Revision 1.5 1998/08/28 20:07:35 videbaek // Add Book // // Revision 1.4 1998/04/06 21:11:51 videbaek // Clean up and additions for Win95 // // Revision 1.3 1998/03/09 20:53:51 videbaek // Ensure that pointers are non-NULL before deleting // // Revision 1.2 1998/03/06 22:10:00 videbaek // Working update // // Revision 1.1.1.1 1998/03/04 21:32:48 brahmlib // Brat base |
||||||
This page automatically generated by script docBrat by Christian Holm |
Copyright ; 2002 BRAHMS Collaboration
<brahmlib@rcf.rhic.bnl.gov>
|