CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/src/FWCore/MessageService/interface/ELadministrator.h

Go to the documentation of this file.
00001 #ifndef MessageService_ELadministrator_h
00002 #define MessageService_ELadministrator_h
00003 
00004 
00005 // ----------------------------------------------------------------------
00006 //
00007 // ELadminstrator.h  provides the singleton class that the framework uses to
00008 //                   control logger behavior including attaching destinations.
00009 //              Includes the methods used by ErrorLog to evoke the logging
00010 //              behavior in the destinations owned by the ELadminstrator.
00011 //
00012 // ----------------------------------------------------------------------
00013 //
00014 // ELadministrator   The singleton logger class.  One does not instantiate
00015 //                   an ELadministrator.  Instead, do
00016 //                      ELadministrator * logger = ELadministrator::instance();
00017 //                   to get a pointer to the (unique) ELadministrator.
00018 //
00019 //      Only the framework should use ELadministrator directly.
00020 //      Physicist users get at it indirectly through using an ErrorLog
00021 //      set up in their Module class.
00022 //
00023 // ELadminDestroyer  A class whose sole purpose is the destruction of the
00024 //                   ELadministrator when the program is over.  Right now,
00025 //                   we do not have anything that needs to be done when the
00026 //                   ELadministrator (and thus the error logger) goes away;
00027 //                   but since by not deleting the copies of ELdestination's
00028 //                   that were attached we would be left with an apparent
00029 //                   memory leak, we include a protected destructor which will
00030 //                   clean up.  ELadminDestroyer provides the only way for
00031 //                   this destructor to be called.
00032 //
00033 // ----------------------------------------------------------------------
00034 //
00035 // 7/2/98 mf    Created file.
00036 // 2/29/00 mf   Added method swapContextSupplier for ELrecv to use.
00037 // 4/5/00 mf    Added method swapProcess for same reason:  ELrecv wants to
00038 //              be able to mock up the process and reset it afterward.
00039 // 6/6/00 web   Consolidate ELadministrator/X; adapt to consolidated
00040 //              ELcout/X.
00041 // 6/14/00 web  Declare classes before granting friendship.
00042 // 6/4/01  mf   Grant friedship to ELtsErrorLog
00043 // 3/6/02  mf   Items for recovering handles to attached destinations:
00044 //              the attachedDestinations map, 
00045 //              an additional signature for attach(), 
00046 //              and getELdestControl() method
00047 // 3/17/04 mf   exitThreshold and setExitThreshold
00048 // 1/10/06 mf   finish
00049 //
00050 // ----------------------------------------------------------------------
00051 
00052 #include "FWCore/MessageService/interface/ELdestControl.h"
00053 
00054 #include "FWCore/MessageLogger/interface/ELstring.h"
00055 #include "FWCore/MessageLogger/interface/ELlist.h"
00056 #include "FWCore/MessageLogger/interface/ELseverityLevel.h"
00057 #include "FWCore/MessageLogger/interface/ErrorObj.h"
00058 
00059 #include "boost/shared_ptr.hpp"
00060 
00061 namespace edm {       
00062 namespace service {       
00063 
00064 
00065 // ----------------------------------------------------------------------
00066 // Prerequisite classes:
00067 // ----------------------------------------------------------------------
00068 
00069 class ELcontextSupplier;
00070 class ELdestination;
00071 class ELadminDestroyer;
00072 class ErrorLog;
00073 class ELtsErrorLog;
00074 class ELcout;
00075 
00076 
00077 // ----------------------------------------------------------------------
00078 // ELadministrator:
00079 // ----------------------------------------------------------------------
00080 
00081 class ELadministrator  {        // *** Destructable Singleton Pattern ***
00082 
00083   friend class ELadminDestroyer;        // proper ELadministrator cleanup
00084   friend class ErrorLog;                // ELadministrator user behavior
00085   friend class ELcout;                  // ELcout behavior
00086   friend class ELtsErrorLog;            // which walks sink list
00087 
00088 // *** Error Logger Functionality ***
00089 
00090 public:
00091 
00092   // ---  birth via a surrogate:
00093   //
00094   static ELadministrator * instance();          // *** Singleton Pattern
00095 
00096   // ---  get/set fundamental properties:
00097   //
00098   void setProcess( const ELstring & process );
00099   ELstring swapProcess( const ELstring & process );
00100   void setContextSupplier( const ELcontextSupplier & supplier );
00101   const ELcontextSupplier & getContextSupplier() const;
00102   ELcontextSupplier & swapContextSupplier( ELcontextSupplier & cs );
00103   void setAbortThreshold( const ELseverityLevel & sev );
00104   void setExitThreshold ( const ELseverityLevel & sev );
00105 
00106   // ---  furnish/recall destinations:
00107   //
00108   ELdestControl attach( const ELdestination & sink );
00109   ELdestControl attach( const ELdestination & sink, const ELstring & name );
00110   bool getELdestControl ( const ELstring & name, ELdestControl & theControl );
00111 
00112   // ---  handle severity information:
00113   //
00114   ELseverityLevel  checkSeverity();
00115   int severityCount( const ELseverityLevel & sev ) const;
00116   int severityCount( const ELseverityLevel & from,
00117                      const ELseverityLevel & to ) const;
00118   void resetSeverityCount( const ELseverityLevel & sev );
00119   void resetSeverityCount( const ELseverityLevel & from,
00120                            const ELseverityLevel & to );
00121   void resetSeverityCount();                    // reset all
00122 
00123   // ---  apply the following actions to all attached destinations:
00124   //
00125   void setThresholds( const ELseverityLevel & sev );
00126   void setLimits    ( const ELstring        & id,  int limit    );
00127   void setLimits    ( const ELseverityLevel & sev, int limit    );
00128   void setIntervals ( const ELstring        & id,  int interval );
00129   void setIntervals ( const ELseverityLevel & sev, int interval );
00130   void setTimespans ( const ELstring        & id,  int seconds  );
00131   void setTimespans ( const ELseverityLevel & sev, int seconds  );
00132   void wipe();
00133   void finish();
00134   
00135 protected:
00136   // ---  member data accessors:
00137   //
00138   const ELstring              & process() const;
00139   ELcontextSupplier           & context() const;
00140   const ELseverityLevel       & abortThreshold() const;
00141   const ELseverityLevel       &  exitThreshold() const;
00142   std::list<boost::shared_ptr<ELdestination> >  & sinks();
00143   const ELseverityLevel       & highSeverity() const;
00144   int                           severityCounts( int lev ) const;
00145 
00146   // ---  actions on messages:
00147   //
00148   void finishMsg();
00149   void clearMsg();
00150 
00151 protected:
00152   // ---  traditional birth/death, but disallowed to users:
00153   //
00154   ELadministrator();
00155   virtual ~ELadministrator();
00156 
00157 private:
00158   // ---  reach the actual (single) ELadministrator's instantiation
00159   // ---  (the instance() method records the ELadminDestroyer object):
00160   //
00161   static ELadministrator* instance_;
00162 
00163   // ---  traditional member data:
00164   //
00165   ELstring                   process_;       
00166   boost::shared_ptr<ELcontextSupplier> context_;             
00167   ELseverityLevel            abortThreshold_; 
00168   ELseverityLevel            exitThreshold_; 
00169   std::list<boost::shared_ptr<ELdestination> > sinks_;          
00170   ELseverityLevel            highSeverity_;
00171   int                        severityCounts_[ ELseverityLevel::nLevels ];
00172   edm::ErrorObj              msg;
00173   bool                       msgIsActive;
00174 
00175   std::map < ELstring, boost::shared_ptr<ELdestination> > attachedDestinations;
00176 
00177 };  // ELadministrator
00178 
00179 
00180 // ----------------------------------------------------------------------
00181 // ELadminDestroyer:
00182 // ----------------------------------------------------------------------
00183 
00184 class ELadminDestroyer  {
00185 
00186 public:
00187   // ---  birth/death:
00188   //
00189   ELadminDestroyer( ELadministrator * ad = 0 );
00190  ~ELadminDestroyer();
00191 
00192   // ---  record our (single) self:
00193   //
00194   void setELadmin( ELadministrator * ad );
00195 
00196 private:
00197   // ---  member data:
00198   //
00199   ELadministrator * admin_;     // keep track of our (single) self
00200 
00201 };  // ELadminDestroyer
00202 
00203 
00204 // ----------------------------------------------------------------------
00205 
00206 
00207 }        // end of namespace service
00208 }        // end of namespace edm
00209 
00210 
00211 #endif  // MessageService_ELadministrator_h