StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StMessMgr.h
1 
14 #ifndef ClassStMessMgr
15 #define ClassStMessMgr
16 
17 #ifdef __ROOT__
18 #include "Rtypes.h"
19 #endif
20 
21 #ifndef __CINT__
22 #ifdef LOGGERMESSAGE
23 #error An attempt to redefine the LOGGERMESSAGE macro
24 #else
25 # define LOGGERMESSAGE(MESSAGELEVEL) \
26  if (StMessMgr::CurrentMessager()->_NAME3_(is,MESSAGELEVEL,Enabled)()) \
27  StMessMgr::CurrentMessager()->MESSAGELEVEL("","O",__FUNCTION__, __LINE__)
28 
29 # define LOG_INFO LOGGERMESSAGE(Info)
30 # define LOG_WARN LOGGERMESSAGE(Warning)
31 # define LOG_ERROR LOGGERMESSAGE(Error)
32 # define LOG_FATAL LOGGERMESSAGE(Fatal)
33 # define LOG_DEBUG LOGGERMESSAGE(Debug)
34 # define LOG_QA LOGGERMESSAGE(QAInfo)
35 # define LOG_UCM LOGGERMESSAGE(UCMInfo)
36 
37 #define STAR_INFO(name) \
38  GetLogger(_QUITE_(name))->MESSAGELEVEL(__FUNCTION__, __LINE__)
39 
40 #define MSG_INFO(name) \
41  GetLogger(_QUITE_(name))->MESSAGELEVEL(__FUNCTION__, __LINE__)
42 #endif
43 #endif
44 
45 #ifndef __CINT__
46 #include "StarCallf77.h"
47 #define Message_ F77_NAME(message,MESSAGE)
48 #define Msg_Enable_ F77_NAME(msg_enable,MSG_ENABLE)
49 #define Msg_Enabled_ F77_NAME(msg_enabled,MSG_ENABLED)
50 #define Msg_Disable_ F77_NAME(msg_disable,MSG_DISABLE)
51 #define StMessage_ F77_NAME(stmessage,STMESSAGE)
52 #define StInfo_ F77_NAME(stinfo,STINFO)
53 #define StWarning_ F77_NAME(stwarning,STWARNING)
54 #define StError_ F77_NAME(sterror,STERROR)
55 #define StDebug_ F77_NAME(stdebug,STDEBUG)
56 #define QAInfo_ F77_NAME(qainfo,QAINFO)
57 #define UCMInfo_ F77_NAME(ucminfo,UCMINFO)
58 #define StInfoOpt_ F77_NAME(stinfoopt,STINFOOPT)
59 #define StWarningOpt_ F77_NAME(stwarningopt,STWARNINGOPT)
60 #define StErrorOpt_ F77_NAME(sterroropt,STERROROPT)
61 #define StDebugOpt_ F77_NAME(stdebugopt,STDEBUGOPT)
62 #define QAInfoOpt_ F77_NAME(qainfoopt,QAINFOOPT)
63 #define UCMInfoOpt_ F77_NAME(ucminfoopt,UCMINFOOPT)
64 #define StMessAddType_ F77_NAME(stmessaddtype,STMESSADDTYPE)
65 extern "C" {
66 void type_of_call Message_(const char* mess, int *lines, int *id, size_t len);
67 void type_of_call Msg_Enable_(const char* mess, size_t len);
68  int type_of_call Msg_Enabled_(const char* mess, int *id, size_t len);
69 void type_of_call Msg_Disable_(const char* mess, size_t len);
70 void type_of_call MessageOut(const char* msg);
71 void type_of_call StMessage_(const char* mess, const char* type,
72  const char* opt, size_t len1,
73  size_t len2, size_t len3);
74 void type_of_call StInfo_(const char* mess, size_t len);
75 void type_of_call StWarning_(const char* mess, size_t len);
76 void type_of_call StError_(const char* mess, size_t len);
77 void type_of_call StDebug_(const char* mess, size_t len);
78 void type_of_call QAInfo_(const char* mess, size_t len);
79 void type_of_call UCMInfo_(const char* mess, size_t len);
80 void type_of_call StInfoOpt_(const char* mess, const char* opt,
81  size_t len1, size_t len2);
82 void type_of_call StWarningOpt_(const char* mess, const char* opt,
83  size_t len1, size_t len2);
84 void type_of_call StErrorOpt_(const char* mess, const char* opt,
85  size_t len1, size_t len2);
86 void type_of_call StDebugOpt_(const char* mess, const char* opt,
87  size_t len1, size_t len2);
88 void type_of_call QAInfoOpt_(const char* mess, const char* opt,
89  size_t len1, size_t len2);
90 void type_of_call UCMInfoOpt_(const char* mess, const char* opt,
91  size_t len1, size_t len2);
92 void type_of_call StMessAddType_(const char* type, const char* text,
93  size_t len1, size_t len2);
94 }
95 #endif
96 
97 
98 
99 class StMessage;
100 
101 #ifndef ClassMessVec
102 class messVec;
103 #endif
104 
105 #include <Stsstream.h>
106 #include <Stiostream.h>
107 
108 class StMessMgr : public std::ostringstream {
109  friend ostream& operator<<(ostream& ,StMessage*);
110  friend ostream& operator++(StMessMgr&);
111  friend ostream& operator-(StMessMgr&);
112  friend ostream& operator--(StMessMgr&);
113  friend ostream& operator~(StMessMgr&);
114  friend class StBFChain;
115 
116  private:
117 
118  protected:
119  virtual void IgnoreRepeats() =0;
120  virtual void AllowRepeats() =0;
121  // fake operator= to follish the bug in the RootCint
122  StMessMgr& operator=(const StMessMgr&){ return *this;}
123  public:
124  enum ESTARMakerErrorLevels {
125  kAll=-5, kFatal, kError, kWarning, kInfo, kDefault, kDebug, kDebug2
126  };
127  StMessMgr();
128  StMessMgr(const StMessMgr&){;}
129  virtual ~StMessMgr(){;}
130 // operator <<
131 
132  virtual std::ostream& OperatorShift(std::ostream& os, StMessage* stm) = 0;
133 
134 // Generic Messages:
135  virtual std::ostringstream& Message(const char* mess="", const char* type="",
136  const char* opt=0,const char *sourceFileName=0, int lineNumber=-1)= 0;
137  virtual void Print() =0;
138  virtual int PrintList(messVec* list) =0;
139  virtual int PrintAll() =0;
140  virtual StMessage* FindMessage(const char* s1, const char s2[]="",
141  const char* s3="", const char* s4="", messVec* list=0) =0;
142  virtual messVec* FindMessageList(const char* s1, const char* s2="",
143  const char* s3="", const char* s4="", messVec* list=0) =0;
144  virtual int RemoveMessage(StMessage* mess) =0;
145  virtual int RemoveMessage(const char* s1, const char* s2="",
146  const char* s3="", const char* s4="") =0;
147  virtual void SetLimit(const char* str, int n=0) =0;
148  virtual int GetLimit(const char* str) =0;
149  virtual void ListLimits() =0;
150  virtual void RemoveLimit(const char* str) =0;
151  virtual void SetLevel(Int_t logLevel) =0;
152  virtual Int_t GetLevel(Int_t logLevel) const =0;
153  virtual const char *GetName() const = 0;
154  virtual void SwitchOff(const char* str) =0;
155  virtual void SwitchOn(const char* str) =0;
156  virtual void FixOn(const char* str) =0;
157  virtual void NoLimits() =0;
158  virtual void Summary(size_t nTerms=1) =0;
159  virtual void MemorySummary() =0;
160  virtual void MemoryOn() =0;
161  virtual void MemoryOff() =0;
162  virtual int AddType(const char* type, const char* text) =0;
163  virtual int ListTypes() =0;
164  virtual void Close() {} // Close the messenger streams
165 //Optimization
166  /*
167  * <p>If you are worried about speed, then you should write
168  * <pre>
169  * if(logger->isDebugEnabled()) {
170  * logger->debug("debug message");
171  * }
172  * </pre>
173  *
174  * <p>This way you will not incur the cost of parameter
175  * construction if debugging is disabled for <code>logger</code>. On
176  * the other hand, if the <code>logger
177  </code> is debug enabled, you
178  * will incur the cost of evaluating whether the logger is debug
179  * enabled twice. Once in <code>isDebugEnabled</code> and once in
180  * the <code>debug</code>. This is an insignificant overhead
181  * since evaluating a logger takes about 1%% of the time it
182  * takes to actually log.
183  *
184  * @return bool - <code>true</code> if this logger is debug
185  * enabled, <code>false</code> otherwise.
186  * */
187  virtual bool isDebugEnabled() const;
188  virtual bool isWarnEnabled() const;
189  virtual bool isWarningEnabled() const;
190  virtual bool isErrorEnabled() const;
191  virtual bool isInfoEnabled() const;
192  virtual bool isFatalEnabled() const;
193  virtual bool isEnabledFor() const;
194  virtual bool isQAInfoEnabled() const;
195  virtual bool isUCMInfoEnabled()const;
196 
197 
198 
199 // Manager factory
200 public:
201  static StMessMgr* CurrentMessager();
202  static StMessMgr* Instance();
203  static StMessMgr* Instance(const char *);
204  static StMessMgr* SetCurrentMessager(StMessMgr *mgr=0);
205 protected:
206  virtual StMessMgr* Instantiate();
207  virtual StMessMgr* Instantiate(const char *);
208 
209 public:
210 // Info Messages:
211  virtual std::ostringstream& Info(const char* mess="", const char* opt="O",const char *sourceFileName=0, int lineNumber=-1)=0;
212  virtual int PrintInfos() =0;
213  virtual const messVec* GetInfos() =0;
214  virtual StMessage* FindInfo(const char* s1, const char* s2="",
215  const char* s3="", const char* s4="") =0;
216  virtual messVec* FindInfoList(const char* s1, const char* s2="",
217  const char* s3="", const char* s4="") =0;
218 
219 // Warning Messages:
220  virtual std::ostringstream& Warning(const char* mess="", const char* opt="E",const char *sourceFileName=0, int lineNumber=-1)= 0;
221  virtual int PrintWarnings() =0;
222  virtual const messVec* GetWarnings() =0;
223  virtual StMessage* FindWarning(const char* s1, const char* s2="",
224  const char* s3="", const char* s4="") =0;
225  virtual messVec* FindWarningList(const char* s1, const char* s2="",
226  const char* s3="", const char* s4="") =0;
227 
228 // Error Messages:
229  virtual std::ostringstream& Error(const char* mess="", const char* opt="E",const char *sourceFileName=0, int lineNumber=-1) = 0;
230  virtual int PrintErrors() =0;
231  virtual const messVec* GetErrors() =0;
232  virtual StMessage* FindError(const char* s1, const char* s2="",
233  const char* s3="", const char* s4="") =0;
234  virtual messVec* FindErrorList(const char* s1, const char* s2="",
235  const char* s3="", const char* s4="") =0;
236 
237 // Debug Messages:
238  virtual std::ostringstream& Debug(const char* mess="", const char* opt="OT",const char *sourceFileName=0, int lineNumber=-1)= 0;
239  virtual int PrintDebug() =0;
240  virtual const messVec* GetDebugs() =0;
241  virtual StMessage* FindDebug(const char* s1, const char* s2="",
242  const char* s3="", const char* s4="") =0;
243  virtual messVec* FindDebugList(const char* s1, const char* s2="",
244  const char* s3="", const char* s4="") =0;
245 
246 // QAInfo Messages:
247  virtual std::ostringstream& QAInfo(const char* mess="", const char* opt="OS",const char *sourceFileName=0, int lineNumber=-1) = 0;
248  virtual int PrintQAInfo() =0;
249  virtual const messVec* GetQAInfos() =0;
250  virtual StMessage* FindQAInfo(const char* s1, const char* s2="",
251  const char* s3="", const char* s4="") =0;
252  virtual messVec* FindQAInfoList(const char* s1, const char* s2="",
253  const char* s3="", const char* s4="") =0;
254 
255 // UCMInfo Messages:
256  virtual std::ostringstream& UCMInfo(const char* mess="", const char* opt="OS",const char *sourceFileName=0, int lineNumber=-1) = 0;
257  virtual int PrintUCMInfo() =0;
258  virtual const messVec* GetUCMInfos() =0;
259  virtual StMessage* FindUCMInfo(const char* s1, const char* s2="",
260  const char* s3="", const char* s4="") =0;
261  virtual messVec* FindUCMInfoList(const char* s1, const char* s2="",
262  const char* s3="", const char* s4="") =0;
263 
264 // "As is" Messages:
265  virtual std::ostringstream& out(const char* mess="") = 0;
266  virtual std::ostringstream& err(const char* mess="") = 0;
267 
268  virtual void PrintInfo() =0;
269  // Fatal Messages:
270  virtual std::ostringstream& Fatal(const char* mess="", const char* opt="OT",const char *sourceFileName=0, int lineNumber=-1)= 0;
271 
272 #ifdef __ROOT__
273  ClassDef(StMessMgr,0)
274 #endif
275 };
276 
277 //______________________________________________________________________________
278 //
279 // StTurnLogger - an aux class to simply "save/restore the "current" logger
280 //______________________________________________________________________________
282 {
283  private:
284  StMessMgr* fMessager; // hold the messager to restore it at dtor
285  public:
286  StTurnLogger(StMessMgr* msg=0);
287  StTurnLogger(const StTurnLogger& push);
288  ~StTurnLogger();
289 };
290 
291 // Global pointers:
292 R__EXTERN StMessMgr* gMessMgr;
293 R__EXTERN StMessage* gMessage;
294 R__EXTERN StMessage* endm;
295 // R__EXTERN StMessMgr& gMess;
296 
297 //______________________________________________________________________________
298 inline StTurnLogger::StTurnLogger(StMessMgr* msg): fMessager(0)
299 {
300  if (msg) fMessager = StMessMgr::SetCurrentMessager(msg);
301 }
302 
303 //______________________________________________________________________________
304 inline StTurnLogger::StTurnLogger(const StTurnLogger& push) : fMessager(push.fMessager)
305 { ((StTurnLogger*)&push)->fMessager=0; }
306 
307 //______________________________________________________________________________
308 inline StTurnLogger::~StTurnLogger()
309 {if (fMessager) StMessMgr::SetCurrentMessager(fMessager);}
310 
311 
312 //______________________________________________________________________________
313 inline ostream& operator<<(ostream& os, StMessage* stm) {
314  return gMessMgr->OperatorShift(os,stm);
315 }
316 
317 //______________________________________________________________________________
318 inline ostream& operator++(StMessMgr&) {
319  return gMessMgr->Info();
320 }
321 //______________________________________________________________________________
322 inline ostream& operator--(StMessMgr&) {
323  return gMessMgr->Error();
324 }
325 //______________________________________________________________________________
326 inline ostream& operator~(StMessMgr&) {
327  return gMessMgr->out();
328 }
329 //______________________________________________________________________________
330 inline ostream& operator-(StMessMgr&) {
331  return gMessMgr->err();
332 }
333 
334 
335 
336 
337 #endif
338 
339 // $Id: StMessMgr.h,v 1.13 2009/06/22 22:36:02 fine Exp $
Definition: FJcore.h:367
virtual TDataSet * Instance() const
Definition: TDataSet.cxx:546
virtual Int_t Instantiate()
Maker-instantiation handler.
Definition: StBFChain.cxx:214
virtual const char * GetName() const
special overload
Definition: StMaker.cxx:237