CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ELadministrator.h
Go to the documentation of this file.
1 #ifndef MessageService_ELadministrator_h
2 #define MessageService_ELadministrator_h
3 
4 
5 // ----------------------------------------------------------------------
6 //
7 // ELadminstrator.h provides the singleton class that the framework uses to
8 // control logger behavior including attaching destinations.
9 // Includes the methods used by ErrorLog to evoke the logging
10 // behavior in the destinations owned by the ELadminstrator.
11 //
12 // ----------------------------------------------------------------------
13 //
14 // ELadministrator The singleton logger class. One does not instantiate
15 // an ELadministrator. Instead, do
16 // ELadministrator * logger = ELadministrator::instance();
17 // to get a pointer to the (unique) ELadministrator.
18 //
19 // Only the framework should use ELadministrator directly.
20 // Physicist users get at it indirectly through using an ErrorLog
21 // set up in their Module class.
22 //
23 // ELadminDestroyer A class whose sole purpose is the destruction of the
24 // ELadministrator when the program is over. Right now,
25 // we do not have anything that needs to be done when the
26 // ELadministrator (and thus the error logger) goes away;
27 // but since by not deleting the copies of ELdestination's
28 // that were attached we would be left with an apparent
29 // memory leak, we include a protected destructor which will
30 // clean up. ELadminDestroyer provides the only way for
31 // this destructor to be called.
32 //
33 // ----------------------------------------------------------------------
34 //
35 // 7/2/98 mf Created file.
36 // 2/29/00 mf Added method swapContextSupplier for ELrecv to use.
37 // 4/5/00 mf Added method swapProcess for same reason: ELrecv wants to
38 // be able to mock up the process and reset it afterward.
39 // 6/6/00 web Consolidate ELadministrator/X; adapt to consolidated
40 // ELcout/X.
41 // 6/14/00 web Declare classes before granting friendship.
42 // 6/4/01 mf Grant friedship to ELtsErrorLog
43 // 3/6/02 mf Items for recovering handles to attached destinations:
44 // the attachedDestinations map,
45 // an additional signature for attach(),
46 // and getELdestControl() method
47 // 3/17/04 mf exitThreshold and setExitThreshold
48 // 1/10/06 mf finish
49 //
50 // ----------------------------------------------------------------------
51 
53 
58 
59 #include "boost/shared_ptr.hpp"
60 
61 namespace edm {
62 namespace service {
63 
64 
65 // ----------------------------------------------------------------------
66 // Prerequisite classes:
67 // ----------------------------------------------------------------------
68 
69 class ELcontextSupplier;
70 class ELdestination;
71 class ELadminDestroyer;
72 class ErrorLog;
73 class ELtsErrorLog;
74 class ELcout;
75 
76 
77 // ----------------------------------------------------------------------
78 // ELadministrator:
79 // ----------------------------------------------------------------------
80 
81 class ELadministrator { // *** Destructable Singleton Pattern ***
82 
83  friend class ELadminDestroyer; // proper ELadministrator cleanup
84  friend class ErrorLog; // ELadministrator user behavior
85  friend class ELcout; // ELcout behavior
86  friend class ELtsErrorLog; // which walks sink list
87 
88 // *** Error Logger Functionality ***
89 
90 public:
91 
92  // --- birth via a surrogate:
93  //
94  static ELadministrator * instance(); // *** Singleton Pattern
95 
96  // --- get/set fundamental properties:
97  //
98  void setProcess( const ELstring & process );
100  void setContextSupplier( const ELcontextSupplier & supplier );
101  const ELcontextSupplier & getContextSupplier() const;
103  void setAbortThreshold( const ELseverityLevel & sev );
104  void setExitThreshold ( const ELseverityLevel & sev );
105 
106  // --- furnish/recall destinations:
107  //
108  ELdestControl attach( const ELdestination & sink );
109  ELdestControl attach( const ELdestination & sink, const ELstring & name );
110  bool getELdestControl ( const ELstring & name, ELdestControl & theControl );
111 
112  // --- handle severity information:
113  //
115  int severityCount( const ELseverityLevel & sev ) const;
116  int severityCount( const ELseverityLevel & from,
117  const ELseverityLevel & to ) const;
118  void resetSeverityCount( const ELseverityLevel & sev );
120  const ELseverityLevel & to );
121  void resetSeverityCount(); // reset all
122 
123  // --- apply the following actions to all attached destinations:
124  //
125  void setThresholds( const ELseverityLevel & sev );
126  void setLimits ( const ELstring & id, int limit );
127  void setLimits ( const ELseverityLevel & sev, int limit );
128  void setIntervals ( const ELstring & id, int interval );
129  void setIntervals ( const ELseverityLevel & sev, int interval );
130  void setTimespans ( const ELstring & id, int seconds );
131  void setTimespans ( const ELseverityLevel & sev, int seconds );
132  void wipe();
133  void finish();
134 
135 protected:
136  // --- member data accessors:
137  //
138  const ELstring & process() const;
139  ELcontextSupplier & context() const;
140  const ELseverityLevel & abortThreshold() const;
141  const ELseverityLevel & exitThreshold() const;
142  std::list<boost::shared_ptr<ELdestination> > & sinks();
143  const ELseverityLevel & highSeverity() const;
144  int severityCounts( int lev ) const;
145 
146  // --- actions on messages:
147  //
148  void finishMsg();
149  void clearMsg();
150 
151 protected:
152  // --- traditional birth/death, but disallowed to users:
153  //
154  ELadministrator();
155  virtual ~ELadministrator();
156 
157 private:
158  // --- reach the actual (single) ELadministrator's instantiation
159  // --- (the instance() method records the ELadminDestroyer object):
160  //
162 
163  // --- traditional member data:
164  //
166  boost::shared_ptr<ELcontextSupplier> context_;
169  std::list<boost::shared_ptr<ELdestination> > sinks_;
174 
175  std::map < ELstring, boost::shared_ptr<ELdestination> > attachedDestinations;
176 
177 }; // ELadministrator
178 
179 
180 // ----------------------------------------------------------------------
181 // ELadminDestroyer:
182 // ----------------------------------------------------------------------
183 
185 
186 public:
187  // --- birth/death:
188  //
189  ELadminDestroyer( ELadministrator * ad = 0 );
191 
192  // --- record our (single) self:
193  //
194  void setELadmin( ELadministrator * ad );
195 
196 private:
197  // --- member data:
198  //
199  ELadministrator * admin_; // keep track of our (single) self
200 
201 }; // ELadminDestroyer
202 
203 
204 // ----------------------------------------------------------------------
205 
206 
207 } // end of namespace service
208 } // end of namespace edm
209 
210 
211 #endif // MessageService_ELadministrator_h
const ELseverityLevel & highSeverity() const
void setProcess(const ELstring &process)
const ELcontextSupplier & getContextSupplier() const
ELstring swapProcess(const ELstring &process)
std::list< boost::shared_ptr< ELdestination > > & sinks()
int severityCounts_[ELseverityLevel::nLevels]
double seconds()
void setThresholds(const ELseverityLevel &sev)
tuple interval
Definition: MergeJob_cfg.py:20
std::map< ELstring, boost::shared_ptr< ELdestination > > attachedDestinations
ELadminDestroyer(ELadministrator *ad=0)
void setExitThreshold(const ELseverityLevel &sev)
const ELstring & process() const
void setIntervals(const ELstring &id, int interval)
void setLimits(const ELstring &id, int limit)
static ELadministrator * instance_
ELcontextSupplier & swapContextSupplier(ELcontextSupplier &cs)
void setTimespans(const ELstring &id, int seconds)
bool getELdestControl(const ELstring &name, ELdestControl &theControl)
boost::shared_ptr< ELcontextSupplier > context_
std::list< boost::shared_ptr< ELdestination > > sinks_
static std::string from(" from ")
void setAbortThreshold(const ELseverityLevel &sev)
static ELadministrator * instance()
void setContextSupplier(const ELcontextSupplier &supplier)
int severityCounts(int lev) const
int severityCount(const ELseverityLevel &sev) const
ELcontextSupplier & context() const
void setELadmin(ELadministrator *ad)
ELdestControl attach(const ELdestination &sink)
const ELseverityLevel & exitThreshold() const
std::string ELstring
Definition: ELstring.h:26
const ELseverityLevel & abortThreshold() const