ROOT  6.06/09
Reference Guide
RooMsgService.h
Go to the documentation of this file.
1 /*****************************************************************************
2  * Project: RooFit *
3  * Package: RooFitCore *
4  * File: $Id: RooMsgService.h,v 1.2 2007/07/13 21:50:24 wouter Exp $
5  * Authors: *
6  * WV, Wouter Verkerke, UC Santa Barbara, verkerke@slac.stanford.edu *
7  * DK, David Kirkby, UC Irvine, dkirkby@uci.edu *
8  * *
9  * Copyright (c) 2000-2005, Regents of the University of California *
10  * and Stanford University. All rights reserved. *
11  * *
12  * Redistribution and use in source and binary forms, *
13  * with or without modification, are permitted according to the terms *
14  * listed in LICENSE (http://roofit.sourceforge.net/license.txt) *
15  *****************************************************************************/
16 #ifndef ROO_MSG_SERVICE
17 #define ROO_MSG_SERVICE
18 
19 #include "Riosfwd.h"
20 #include <assert.h>
21 #include "TObject.h"
22 #include <string>
23 #include <vector>
24 #include <stack>
25 #include <map>
26 #include "RooCmdArg.h"
27 #include "RooGlobalFunc.h"
28 class RooAbsArg ;
29 class RooWorkspace ;
30 
31 // Shortcut definitions
32 #define coutI(a) RooMsgService::instance().log(this,RooFit::INFO,RooFit::a)
33 #define coutP(a) RooMsgService::instance().log(this,RooFit::PROGRESS,RooFit::a)
34 #define coutW(a) RooMsgService::instance().log(this,RooFit::WARNING,RooFit::a)
35 #define coutE(a) RooMsgService::instance().log(this,RooFit::ERROR,RooFit::a)
36 #define coutF(a) RooMsgService::instance().log(this,RooFit::FATAL,RooFit::a)
37 
38 #define ccoutD(a) RooMsgService::instance().log(this,RooFit::DEBUG,RooFit::a,kTRUE)
39 #define ccoutI(a) RooMsgService::instance().log(this,RooFit::INFO,RooFit::a,kTRUE)
40 #define ccoutP(a) RooMsgService::instance().log(this,RooFit::PROGRESS,RooFit::a,kTRUE)
41 #define ccoutW(a) RooMsgService::instance().log(this,RooFit::WARNING,RooFit::a,kTRUE)
42 #define ccoutE(a) RooMsgService::instance().log(this,RooFit::ERROR,RooFit::a,kTRUE)
43 #define ccoutF(a) RooMsgService::instance().log(this,RooFit::FATAL,RooFit::a,kTRUE)
44 
45 #define oocoutI(o,a) RooMsgService::instance().log(o,RooFit::INFO,RooFit::a)
46 #define oocoutP(o,a) RooMsgService::instance().log(o,RooFit::PROGRESS,RooFit::a)
47 #define oocoutW(o,a) RooMsgService::instance().log(o,RooFit::WARNING,RooFit::a)
48 #define oocoutE(o,a) RooMsgService::instance().log(o,RooFit::ERROR,RooFit::a)
49 #define oocoutF(o,a) RooMsgService::instance().log(o,RooFit::FATAL,RooFit::a)
50 
51 #define ooccoutD(o,a) RooMsgService::instance().log(o,RooFit::DEBUG,RooFit::a,kTRUE)
52 #define ooccoutI(o,a) RooMsgService::instance().log(o,RooFit::INFO,RooFit::a,kTRUE)
53 #define ooccoutP(o,a) RooMsgService::instance().log(o,RooFit::PROGRESS,RooFit::a,kTRUE)
54 #define ooccoutW(o,a) RooMsgService::instance().log(o,RooFit::WARNING,RooFit::a,kTRUE)
55 #define ooccoutE(o,a) RooMsgService::instance().log(o,RooFit::ERROR,RooFit::a,kTRUE)
56 #define ooccoutF(o,a) RooMsgService::instance().log(o,RooFit::FATAL,RooFit::a,kTRUE)
57 
58 #ifndef _WIN32
59 #define ANYDEBUG (RooMsgService::_debugCount>0)
60 #else
61 #define ANYDEBUG (RooMsgService::anyDebug())
62 #endif
63 
64 #define dologD(a) (ANYDEBUG && RooMsgService::instance().isActive(this,RooFit::a,RooFit::DEBUG))
65 #define dologI(a) (RooMsgService::instance().isActive(this,RooFit::a,RooFit::INFO))
66 #define dologP(a) (RooMsgService::instance().isActive(this,RooFit::a,RooFit::PROGRESS))
67 #define dologW(a) (RooMsgService::instance().isActive(this,RooFit::a,RooFit::WARNING))
68 #define dologE(a) (RooMsgService::instance().isActive(this,RooFit::a,RooFit::ERROR))
69 #define dologF(a) (RooMsgService::instance().isActive(this,RooFit::a,RooFit::FATAL))
70 
71 #define oodologD(o,a) (ANYDEBUG && RooMsgService::instance().isActive(o,RooFit::a,RooFit::DEBUG))
72 #define oodologI(o,a) (RooMsgService::instance().isActive(o,RooFit::a,RooFit::INFO))
73 #define oodologP(o,a) (RooMsgService::instance().isActive(o,RooFit::a,RooFit::PROGRESS))
74 #define oodologW(o,a) (RooMsgService::instance().isActive(o,RooFit::a,RooFit::WARNING))
75 #define oodologE(o,a) (RooMsgService::instance().isActive(o,RooFit::a,RooFit::ERROR))
76 #define oodologF(o,a) (RooMsgService::instance().isActive(o,RooFit::a,RooFit::FATAL))
77 
78 // Shortcuts definitions with conditional execution of print expression -- USE WITH CAUTION
79 
80 #define cxcoutD(a) if (ANYDEBUG && RooMsgService::instance().isActive(this,RooFit::a,RooFit::DEBUG)) RooMsgService::instance().log(this,RooFit::DEBUG,RooFit::a)
81 #define ccxcoutD(a) if (ANYDEBUG && RooMsgService::instance().isActive(this,RooFit::a,RooFit::DEBUG)) RooMsgService::instance().log(this,RooFit::DEBUG,RooFit::a,kTRUE)
82 #define oocxcoutD(o,a) if (ANYDEBUG && RooMsgService::instance().isActive(o,RooFit::a,RooFit::DEBUG)) RooMsgService::instance().log(o,RooFit::DEBUG,RooFit::a)
83 #define ooccxcoutD(o,a) if (ANYDEBUG && RooMsgService::instance().isActive(o,RooFit::a,RooFit::DEBUG)) RooMsgService::instance().log(o,RooFit::DEBUG,RooFit::a,kTRUE)
84 #define cxcoutI(a) if (RooMsgService::instance().isActive(this,RooFit::a,RooFit::INFO)) RooMsgService::instance().log(this,RooFit::INFO,RooFit::a)
85 #define ccxcoutI(a) if (RooMsgService::instance().isActive(this,RooFit::a,RooFit::INFO)) RooMsgService::instance().log(this,RooFit::INFO,RooFit::a,kTRUE)
86 #define oocxcoutI(o,a) if (RooMsgService::instance().isActive(o,RooFit::a,RooFit::INFO)) RooMsgService::instance().log(o,RooFit::INFO,RooFit::a)
87 #define ooccxcoutI(o,a) if (RooMsgService::instance().isActive(o,RooFit::a,RooFit::INFO)) RooMsgService::instance().log(o,RooFit::INFO,RooFit::a,kTRUE)
88 #define cxcoutP(a) if (RooMsgService::instance().isActive(this,RooFit::a,RooFit::PROGRESS)) RooMsgService::instance().log(this,RooFit::INFO,RooFit::a)
89 #define ccxcoutP(a) if (RooMsgService::instance().isActive(this,RooFit::a,RooFit::PROGRESS)) RooMsgService::instance().log(this,RooFit::INFO,RooFit::a,kTRUE)
90 #define oocxcoutP(o,a) if (RooMsgService::instance().isActive(o,RooFit::a,RooFit::PROGRESS)) RooMsgService::instance().log(o,RooFit::INFO,RooFit::a)
91 #define ooccxcoutP(o,a) if (RooMsgService::instance().isActive(o,RooFit::a,RooFit::PROGRESS)) RooMsgService::instance().log(o,RooFit::INFO,RooFit::a,kTRUE)
92 #define cxcoutW(a) if (RooMsgService::instance().isActive(this,RooFit::a,RooFit::WARNING)) RooMsgService::instance().log(this,RooFit::WARNING,RooFit::a)
93 #define ccxcoutW(a) if (RooMsgService::instance().isActive(this,RooFit::a,RooFit::WARNING)) RooMsgService::instance().log(this,RooFit::WARNING,RooFit::a,kTRUE)
94 #define oocxcoutW(o,a) if (RooMsgService::instance().isActive(o,RooFit::a,RooFit::WARNING)) RooMsgService::instance().log(o,RooFit::WARNING,RooFit::a)
95 #define ooccxcoutW(o,a) if (RooMsgService::instance().isActive(o,RooFit::a,RooFit::WARNING)) RooMsgService::instance().log(o,RooFit::WARNING,RooFit::a,kTRUE)
96 #define cxcoutE(a) if (RooMsgService::instance().isActive(this,RooFit::a,RooFit::ERROR)) RooMsgService::instance().log(this,RooFit::ERROR,RooFit::a)
97 #define ccxcoutE(a) if (RooMsgService::instance().isActive(this,RooFit::a,RooFit::ERROR)) RooMsgService::instance().log(this,RooFit::ERROR,RooFit::a,kTRUE)
98 #define oocxcoutE(o,a) if (RooMsgService::instance().isActive(o,RooFit::a,RooFit::ERROR)) RooMsgService::instance().log(to,RooFit::ERROR,RooFit::a)
99 #define ooccxcoutE(o,a) if (RooMsgService::instance().isActive(o,RooFit::a,RooFit::ERROR)) RooMsgService::instance().log(o,RooFit::ERROR,RooFit::a,kTRUE)
100 #define cxcoutF(a) if (RooMsgService::instance().isActive(this,RooFit::a,RooFit::FATAL)) RooMsgService::instance().log(this,RooFit::FATAL,RooFit::a)
101 #define ccxcoutF(a) if (RooMsgService::instance().isActive(this,RooFit::a,RooFit::FATAL)) RooMsgService::instance().log(this,RooFit::FATAL,RooFit::a,kTRUE)
102 #define oocxcoutF(o,a) if (RooMsgService::instance().isActive(o,RooFit::a,RooFit::FATAL)) RooMsgService::instance().log(o,RooFit::FATAL,RooFit::a)
103 #define ooccxcoutF(o,a) if (RooMsgService::instance().isActive(o,RooFit::a,RooFit::FATAL)) RooMsgService::instance().log(o,RooFit::FATAL,RooFit::a,kTRUE)
104 
105 class RooMsgService : public TObject {
106 public:
107 
108  virtual ~RooMsgService() ;
109 
110  struct StreamConfig {
111  public:
112 
113  void addTopic(RooFit::MsgTopic newTopic) {
114  topic |= newTopic ;
115  }
116 
117  void removeTopic(RooFit::MsgTopic oldTopic) {
118  topic &= ~oldTopic ;
119  }
120 
121 
122  friend class RooMsgService ;
123 
124  Bool_t match(RooFit::MsgLevel level, RooFit::MsgTopic facility, const RooAbsArg* obj) ;
125  Bool_t match(RooFit::MsgLevel level, RooFit::MsgTopic facility, const TObject* obj) ;
126 
129 
132  std::string objectName ;
133  std::string className ;
134  std::string baseClassName ;
135  std::string tagName ;
138 
139  std::ostream* os ;
140 
141  } ;
142 
143  // Access to instance
144  static RooMsgService& instance() ;
145  static Bool_t anyDebug() ;
146 
147  // User interface -- Add or delete reporting streams ;
148  Int_t addStream(RooFit::MsgLevel level, const RooCmdArg& arg1=RooCmdArg(), const RooCmdArg& arg2=RooCmdArg(), const RooCmdArg& arg3=RooCmdArg(),
149  const RooCmdArg& arg4=RooCmdArg(), const RooCmdArg& arg5=RooCmdArg(), const RooCmdArg& arg6=RooCmdArg());
150  void deleteStream(Int_t id) ;
152 
153  Int_t numStreams() const { return _streams.size() ; }
154  void setStreamStatus(Int_t id, Bool_t active) ;
155  Bool_t getStreamStatus(Int_t id) const ;
156 
157  void reset() { cleanup() ; }
158 
161 
162  void Print(Option_t *options= 0) const ;
163  void showPid(Bool_t flag) { _showPid = flag ; }
164 
165  // Back end -- Send message or check if particular logging configuration is active
166  std::ostream& log(const RooAbsArg* self, RooFit::MsgLevel level, RooFit::MsgTopic facility, Bool_t forceSkipPrefix=kFALSE) ;
167  std::ostream& log(const TObject* self, RooFit::MsgLevel level, RooFit::MsgTopic facility, Bool_t forceSkipPrefix=kFALSE) ;
168  Bool_t isActive(const RooAbsArg* self, RooFit::MsgTopic facility, RooFit::MsgLevel level) ;
169  Bool_t isActive(const TObject* self, RooFit::MsgTopic facility, RooFit::MsgLevel level) ;
170 
172  std::map<int,std::string> _levelNames ;
173  std::map<int,std::string> _topicNames ;
174 
175  static void cleanup() ;
176 
177  // Print level support for RooFit-related messages that are not routed through RooMsgService (such as Minuit printouts)
178  Bool_t silentMode() const { return _silentMode ; }
179  void setSilentMode(Bool_t flag) { _silentMode = flag ; }
180 
181  Int_t errorCount() const { return _errorCount ; }
182  void clearErrorCount() { _errorCount = 0 ; }
183 
184  void saveState() ;
185  void restoreState() ;
186 
188 
189  Int_t& debugCode() { return _debugCode ; }
190 
191 protected:
192 
193  Int_t activeStream(const RooAbsArg* self, RooFit::MsgTopic facility, RooFit::MsgLevel level) ;
194  Int_t activeStream(const TObject* self, RooFit::MsgTopic facility, RooFit::MsgLevel level) ;
195 
196  std::vector<StreamConfig> _streams ;
197  std::stack<std::vector<StreamConfig> > _streamsSaved ;
198  std::ostream* _devnull ;
199 
200  std::map<std::string,std::ostream*> _files ;
203 
206 
208 
209  // Private ctor -- singleton class
210  RooMsgService() ;
211  RooMsgService(const RooMsgService&) ;
212 
214 
216 
218 
219  ClassDef(RooMsgService,0) // RooFit Message Service Singleton class
220 };
221 
222 extern RooMsgService* gMsgService ;
223 
224 #endif
Bool_t getStreamStatus(Int_t id) const
Get activation status of stream with given unique ID.
RooMsgService * gMsgService
void addTopic(RooFit::MsgTopic newTopic)
Int_t errorCount() const
const char Option_t
Definition: RtypesCore.h:62
std::ostream * _devnull
std::map< int, std::string > _topicNames
static Bool_t anyDebug()
Returns true if any debug level stream is active.
void deleteStream(Int_t id)
Delete stream with given unique ID code.
Bool_t isActive(const RooAbsArg *self, RooFit::MsgTopic facility, RooFit::MsgLevel level)
Check if logging is active for given object/topic/RooFit::MsgLevel combination.
int Int_t
Definition: RtypesCore.h:41
StreamConfig & getStream(Int_t id)
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kFALSE
Definition: Rtypes.h:92
void removeTopic(RooFit::MsgTopic oldTopic)
void clearErrorCount()
static RooMsgService & instance()
Return reference to singleton instance.
std::ostream & log(const RooAbsArg *self, RooFit::MsgLevel level, RooFit::MsgTopic facility, Bool_t forceSkipPrefix=kFALSE)
Log error message associated with RooAbsArg object self at given level and topic. ...
void setStreamStatus(Int_t id, Bool_t active)
(De)Activate stream with given unique ID
#define ClassDef(name, id)
Definition: Rtypes.h:254
static void cleanup()
Cleanup function called by atexit() handler installed by RooSentinel to delete all global object upon...
RooMsgService()
Constructor.
static RooMsgService * _instance
void saveState()
Save current state of message service.
XFontStruct * id
Definition: TGX11.cxx:108
RooFit::MsgLevel _globMinLevel
short Color_t
Definition: RtypesCore.h:79
static Int_t _debugCount
RooFit::MsgLevel globalKillBelow() const
Int_t numStreams() const
Int_t & debugCode()
std::vector< StreamConfig > _streams
RooWorkspace * _debugWorkspace
void setGlobalKillBelow(RooFit::MsgLevel level)
std::stack< std::vector< StreamConfig > > _streamsSaved
Int_t addStream(RooFit::MsgLevel level, const RooCmdArg &arg1=RooCmdArg(), const RooCmdArg &arg2=RooCmdArg(), const RooCmdArg &arg3=RooCmdArg(), const RooCmdArg &arg4=RooCmdArg(), const RooCmdArg &arg5=RooCmdArg(), const RooCmdArg &arg6=RooCmdArg())
Add a message logging stream for message with given RooFit::MsgLevel or higher (i.e.
void setSilentMode(Bool_t flag)
Int_t activeStream(const RooAbsArg *self, RooFit::MsgTopic facility, RooFit::MsgLevel level)
Find appropriate logging stream for message from given object with given topic and message level...
virtual ~RooMsgService()
Destructor.
Mother of all ROOT objects.
Definition: TObject.h:58
Bool_t match(RooFit::MsgLevel level, RooFit::MsgTopic facility, const RooAbsArg *obj)
Determine if message from given object at given level on given topic is logged.
Bool_t _silentMode
std::map< std::string, std::ostream * > _files
RooAbsArg is the common abstract base class for objects that represent a value (of arbitrary type) an...
Definition: RooAbsArg.h:66
RooWorkspace * debugWorkspace()
void Print(Option_t *options=0) const
Print configuration of message service.
RooFit::MsgLevel _lastMsgLevel
TObject * obj
void showPid(Bool_t flag)
std::map< int, std::string > _levelNames
void restoreState()
Restore last saved state of message service.
Bool_t silentMode() const