Logo ROOT   6.14/05
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 <assert.h>
20 #include "TObject.h"
21 #include <string>
22 #include <vector>
23 #include <stack>
24 #include <map>
25 #include "RooCmdArg.h"
26 #include "RooGlobalFunc.h"
27 class RooAbsArg ;
28 class RooWorkspace ;
29 
30 // Shortcut definitions
31 #define coutI(a) RooMsgService::instance().log(this,RooFit::INFO,RooFit::a)
32 #define coutP(a) RooMsgService::instance().log(this,RooFit::PROGRESS,RooFit::a)
33 #define coutW(a) RooMsgService::instance().log(this,RooFit::WARNING,RooFit::a)
34 #define coutE(a) RooMsgService::instance().log(this,RooFit::ERROR,RooFit::a)
35 #define coutF(a) RooMsgService::instance().log(this,RooFit::FATAL,RooFit::a)
36 
37 #define ccoutD(a) RooMsgService::instance().log(this,RooFit::DEBUG,RooFit::a,kTRUE)
38 #define ccoutI(a) RooMsgService::instance().log(this,RooFit::INFO,RooFit::a,kTRUE)
39 #define ccoutP(a) RooMsgService::instance().log(this,RooFit::PROGRESS,RooFit::a,kTRUE)
40 #define ccoutW(a) RooMsgService::instance().log(this,RooFit::WARNING,RooFit::a,kTRUE)
41 #define ccoutE(a) RooMsgService::instance().log(this,RooFit::ERROR,RooFit::a,kTRUE)
42 #define ccoutF(a) RooMsgService::instance().log(this,RooFit::FATAL,RooFit::a,kTRUE)
43 
44 #define oocoutI(o,a) RooMsgService::instance().log(o,RooFit::INFO,RooFit::a)
45 #define oocoutP(o,a) RooMsgService::instance().log(o,RooFit::PROGRESS,RooFit::a)
46 #define oocoutW(o,a) RooMsgService::instance().log(o,RooFit::WARNING,RooFit::a)
47 #define oocoutE(o,a) RooMsgService::instance().log(o,RooFit::ERROR,RooFit::a)
48 #define oocoutF(o,a) RooMsgService::instance().log(o,RooFit::FATAL,RooFit::a)
49 
50 #define ooccoutD(o,a) RooMsgService::instance().log(o,RooFit::DEBUG,RooFit::a,kTRUE)
51 #define ooccoutI(o,a) RooMsgService::instance().log(o,RooFit::INFO,RooFit::a,kTRUE)
52 #define ooccoutP(o,a) RooMsgService::instance().log(o,RooFit::PROGRESS,RooFit::a,kTRUE)
53 #define ooccoutW(o,a) RooMsgService::instance().log(o,RooFit::WARNING,RooFit::a,kTRUE)
54 #define ooccoutE(o,a) RooMsgService::instance().log(o,RooFit::ERROR,RooFit::a,kTRUE)
55 #define ooccoutF(o,a) RooMsgService::instance().log(o,RooFit::FATAL,RooFit::a,kTRUE)
56 
57 #ifndef _WIN32
58 #define ANYDEBUG (RooMsgService::_debugCount>0)
59 #else
60 #define ANYDEBUG (RooMsgService::anyDebug())
61 #endif
62 
63 #define dologD(a) (ANYDEBUG && RooMsgService::instance().isActive(this,RooFit::a,RooFit::DEBUG))
64 #define dologI(a) (RooMsgService::instance().isActive(this,RooFit::a,RooFit::INFO))
65 #define dologP(a) (RooMsgService::instance().isActive(this,RooFit::a,RooFit::PROGRESS))
66 #define dologW(a) (RooMsgService::instance().isActive(this,RooFit::a,RooFit::WARNING))
67 #define dologE(a) (RooMsgService::instance().isActive(this,RooFit::a,RooFit::ERROR))
68 #define dologF(a) (RooMsgService::instance().isActive(this,RooFit::a,RooFit::FATAL))
69 
70 #define oodologD(o,a) (ANYDEBUG && RooMsgService::instance().isActive(o,RooFit::a,RooFit::DEBUG))
71 #define oodologI(o,a) (RooMsgService::instance().isActive(o,RooFit::a,RooFit::INFO))
72 #define oodologP(o,a) (RooMsgService::instance().isActive(o,RooFit::a,RooFit::PROGRESS))
73 #define oodologW(o,a) (RooMsgService::instance().isActive(o,RooFit::a,RooFit::WARNING))
74 #define oodologE(o,a) (RooMsgService::instance().isActive(o,RooFit::a,RooFit::ERROR))
75 #define oodologF(o,a) (RooMsgService::instance().isActive(o,RooFit::a,RooFit::FATAL))
76 
77 // Shortcuts definitions with conditional execution of print expression -- USE WITH CAUTION
78 
79 #define cxcoutD(a) if (ANYDEBUG && RooMsgService::instance().isActive(this,RooFit::a,RooFit::DEBUG)) RooMsgService::instance().log(this,RooFit::DEBUG,RooFit::a)
80 #define ccxcoutD(a) if (ANYDEBUG && RooMsgService::instance().isActive(this,RooFit::a,RooFit::DEBUG)) RooMsgService::instance().log(this,RooFit::DEBUG,RooFit::a,kTRUE)
81 #define oocxcoutD(o,a) if (ANYDEBUG && RooMsgService::instance().isActive(o,RooFit::a,RooFit::DEBUG)) RooMsgService::instance().log(o,RooFit::DEBUG,RooFit::a)
82 #define ooccxcoutD(o,a) if (ANYDEBUG && RooMsgService::instance().isActive(o,RooFit::a,RooFit::DEBUG)) RooMsgService::instance().log(o,RooFit::DEBUG,RooFit::a,kTRUE)
83 #define cxcoutI(a) if (RooMsgService::instance().isActive(this,RooFit::a,RooFit::INFO)) RooMsgService::instance().log(this,RooFit::INFO,RooFit::a)
84 #define ccxcoutI(a) if (RooMsgService::instance().isActive(this,RooFit::a,RooFit::INFO)) RooMsgService::instance().log(this,RooFit::INFO,RooFit::a,kTRUE)
85 #define oocxcoutI(o,a) if (RooMsgService::instance().isActive(o,RooFit::a,RooFit::INFO)) RooMsgService::instance().log(o,RooFit::INFO,RooFit::a)
86 #define ooccxcoutI(o,a) if (RooMsgService::instance().isActive(o,RooFit::a,RooFit::INFO)) RooMsgService::instance().log(o,RooFit::INFO,RooFit::a,kTRUE)
87 #define cxcoutP(a) if (RooMsgService::instance().isActive(this,RooFit::a,RooFit::PROGRESS)) RooMsgService::instance().log(this,RooFit::INFO,RooFit::a)
88 #define ccxcoutP(a) if (RooMsgService::instance().isActive(this,RooFit::a,RooFit::PROGRESS)) RooMsgService::instance().log(this,RooFit::INFO,RooFit::a,kTRUE)
89 #define oocxcoutP(o,a) if (RooMsgService::instance().isActive(o,RooFit::a,RooFit::PROGRESS)) RooMsgService::instance().log(o,RooFit::INFO,RooFit::a)
90 #define ooccxcoutP(o,a) if (RooMsgService::instance().isActive(o,RooFit::a,RooFit::PROGRESS)) RooMsgService::instance().log(o,RooFit::INFO,RooFit::a,kTRUE)
91 #define cxcoutW(a) if (RooMsgService::instance().isActive(this,RooFit::a,RooFit::WARNING)) RooMsgService::instance().log(this,RooFit::WARNING,RooFit::a)
92 #define ccxcoutW(a) if (RooMsgService::instance().isActive(this,RooFit::a,RooFit::WARNING)) RooMsgService::instance().log(this,RooFit::WARNING,RooFit::a,kTRUE)
93 #define oocxcoutW(o,a) if (RooMsgService::instance().isActive(o,RooFit::a,RooFit::WARNING)) RooMsgService::instance().log(o,RooFit::WARNING,RooFit::a)
94 #define ooccxcoutW(o,a) if (RooMsgService::instance().isActive(o,RooFit::a,RooFit::WARNING)) RooMsgService::instance().log(o,RooFit::WARNING,RooFit::a,kTRUE)
95 #define cxcoutE(a) if (RooMsgService::instance().isActive(this,RooFit::a,RooFit::ERROR)) RooMsgService::instance().log(this,RooFit::ERROR,RooFit::a)
96 #define ccxcoutE(a) if (RooMsgService::instance().isActive(this,RooFit::a,RooFit::ERROR)) RooMsgService::instance().log(this,RooFit::ERROR,RooFit::a,kTRUE)
97 #define oocxcoutE(o,a) if (RooMsgService::instance().isActive(o,RooFit::a,RooFit::ERROR)) RooMsgService::instance().log(to,RooFit::ERROR,RooFit::a)
98 #define ooccxcoutE(o,a) if (RooMsgService::instance().isActive(o,RooFit::a,RooFit::ERROR)) RooMsgService::instance().log(o,RooFit::ERROR,RooFit::a,kTRUE)
99 #define cxcoutF(a) if (RooMsgService::instance().isActive(this,RooFit::a,RooFit::FATAL)) RooMsgService::instance().log(this,RooFit::FATAL,RooFit::a)
100 #define ccxcoutF(a) if (RooMsgService::instance().isActive(this,RooFit::a,RooFit::FATAL)) RooMsgService::instance().log(this,RooFit::FATAL,RooFit::a,kTRUE)
101 #define oocxcoutF(o,a) if (RooMsgService::instance().isActive(o,RooFit::a,RooFit::FATAL)) RooMsgService::instance().log(o,RooFit::FATAL,RooFit::a)
102 #define ooccxcoutF(o,a) if (RooMsgService::instance().isActive(o,RooFit::a,RooFit::FATAL)) RooMsgService::instance().log(o,RooFit::FATAL,RooFit::a,kTRUE)
103 
104 class RooMsgService : public TObject {
105 public:
106 
107  virtual ~RooMsgService() ;
108 
109  struct StreamConfig {
110  public:
111 
112  void addTopic(RooFit::MsgTopic newTopic) {
113  topic |= newTopic ;
114  }
115 
116  void removeTopic(RooFit::MsgTopic oldTopic) {
117  topic &= ~oldTopic ;
118  }
119 
120 
121  friend class RooMsgService ;
122 
123  Bool_t match(RooFit::MsgLevel level, RooFit::MsgTopic facility, const RooAbsArg* obj) ;
124  Bool_t match(RooFit::MsgLevel level, RooFit::MsgTopic facility, const TObject* obj) ;
125 
128 
131  std::string objectName ;
132  std::string className ;
133  std::string baseClassName ;
134  std::string tagName ;
137 
138  std::ostream* os ;
139 
140  } ;
141 
142  // Access to instance
143  static RooMsgService& instance() ;
144  static Bool_t anyDebug() ;
145 
146  // User interface -- Add or delete reporting streams ;
147  Int_t addStream(RooFit::MsgLevel level, const RooCmdArg& arg1=RooCmdArg(), const RooCmdArg& arg2=RooCmdArg(), const RooCmdArg& arg3=RooCmdArg(),
148  const RooCmdArg& arg4=RooCmdArg(), const RooCmdArg& arg5=RooCmdArg(), const RooCmdArg& arg6=RooCmdArg());
149  void deleteStream(Int_t id) ;
151 
152  Int_t numStreams() const { return _streams.size() ; }
153  void setStreamStatus(Int_t id, Bool_t active) ;
154  Bool_t getStreamStatus(Int_t id) const ;
155 
156  void reset() { cleanup() ; }
157 
160 
161  void Print(Option_t *options= 0) const ;
162  void showPid(Bool_t flag) { _showPid = flag ; }
163 
164  // Back end -- Send message or check if particular logging configuration is active
165  std::ostream& log(const RooAbsArg* self, RooFit::MsgLevel level, RooFit::MsgTopic facility, Bool_t forceSkipPrefix=kFALSE) ;
166  std::ostream& log(const TObject* self, RooFit::MsgLevel level, RooFit::MsgTopic facility, Bool_t forceSkipPrefix=kFALSE) ;
167  Bool_t isActive(const RooAbsArg* self, RooFit::MsgTopic facility, RooFit::MsgLevel level) ;
168  Bool_t isActive(const TObject* self, RooFit::MsgTopic facility, RooFit::MsgLevel level) ;
169 
171  std::map<int,std::string> _levelNames ;
172  std::map<int,std::string> _topicNames ;
173 
174  static void cleanup() ;
175 
176  // Print level support for RooFit-related messages that are not routed through RooMsgService (such as Minuit printouts)
177  Bool_t silentMode() const { return _silentMode ; }
178  void setSilentMode(Bool_t flag) { _silentMode = flag ; }
179 
180  Int_t errorCount() const { return _errorCount ; }
181  void clearErrorCount() { _errorCount = 0 ; }
182 
183  void saveState() ;
184  void restoreState() ;
185 
187 
188  Int_t& debugCode() { return _debugCode ; }
189 
190 protected:
191 
192  Int_t activeStream(const RooAbsArg* self, RooFit::MsgTopic facility, RooFit::MsgLevel level) ;
193  Int_t activeStream(const TObject* self, RooFit::MsgTopic facility, RooFit::MsgLevel level) ;
194 
195  std::vector<StreamConfig> _streams ;
196  std::stack<std::vector<StreamConfig> > _streamsSaved ;
197  std::ostream* _devnull ;
198 
199  std::map<std::string,std::ostream*> _files ;
202 
205 
207 
208  // Private ctor -- singleton class
209  RooMsgService() ;
210  RooMsgService(const RooMsgService&) ;
211 
213 
215 
217 
218  ClassDef(RooMsgService,0) // RooFit Message Service Singleton class
219 };
220 
221 extern RooMsgService* gMsgService ;
222 
223 #endif
RooMsgService * gMsgService
void addTopic(RooFit::MsgTopic newTopic)
const char Option_t
Definition: RtypesCore.h:62
RooFit::MsgLevel globalKillBelow() const
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
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. ...
Int_t numStreams() const
void setStreamStatus(Int_t id, Bool_t active)
(De)Activate stream with given unique ID
#define ClassDef(name, id)
Definition: Rtypes.h:320
Bool_t silentMode() const
static void cleanup()
Cleanup function called by atexit() handler installed by RooSentinel to delete all global object upon...
Bool_t getStreamStatus(Int_t id) const
Get activation status of stream with given unique ID.
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
Int_t & debugCode()
std::vector< StreamConfig > _streams
RooWorkspace * _debugWorkspace
The RooMsgService class is a singleton class that organizes informational, debugging, warning and errors messages generated by the RooFit core code.
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...
const Bool_t kFALSE
Definition: RtypesCore.h:88
virtual ~RooMsgService()
Destructor.
Int_t errorCount() const
void Print(Option_t *options=0) const
Print configuration of message service.
Mother of all ROOT objects.
Definition: TObject.h:37
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()
RooFit::MsgLevel _lastMsgLevel
void showPid(Bool_t flag)
std::map< int, std::string > _levelNames
The RooWorkspace is a persistable container for RooFit projects.
Definition: RooWorkspace.h:43
void restoreState()
Restore last saved state of message service.
RooCmdArg is a named container for two doubles, two integers two object points and three string point...
Definition: RooCmdArg.h:27