Logo ROOT  
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 "TObject.h"
20 #include <string>
21 #include <vector>
22 #include <stack>
23 #include <map>
24 #include "RooCmdArg.h"
25 #include "RooGlobalFunc.h"
26 class RooAbsArg ;
27 class RooWorkspace ;
28 
29 // Shortcut definitions
30 #define coutI(a) RooMsgService::instance().log(this,RooFit::INFO,RooFit::a)
31 #define coutP(a) RooMsgService::instance().log(this,RooFit::PROGRESS,RooFit::a)
32 #define coutW(a) RooMsgService::instance().log(this,RooFit::WARNING,RooFit::a)
33 #define coutE(a) RooMsgService::instance().log(this,RooFit::ERROR,RooFit::a)
34 #define coutF(a) RooMsgService::instance().log(this,RooFit::FATAL,RooFit::a)
35 
36 // Skip the message prefix
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 // Message from given object instead of "this"
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 // Message from given object instead of "this" and skip message prefix
52 #define ooccoutD(o,a) RooMsgService::instance().log(o,RooFit::DEBUG,RooFit::a,kTRUE)
53 #define ooccoutI(o,a) RooMsgService::instance().log(o,RooFit::INFO,RooFit::a,kTRUE)
54 #define ooccoutP(o,a) RooMsgService::instance().log(o,RooFit::PROGRESS,RooFit::a,kTRUE)
55 #define ooccoutW(o,a) RooMsgService::instance().log(o,RooFit::WARNING,RooFit::a,kTRUE)
56 #define ooccoutE(o,a) RooMsgService::instance().log(o,RooFit::ERROR,RooFit::a,kTRUE)
57 #define ooccoutF(o,a) RooMsgService::instance().log(o,RooFit::FATAL,RooFit::a,kTRUE)
58 
59 #ifndef _WIN32
60 #define ANYDEBUG (RooMsgService::_debugCount>0)
61 #else
62 #define ANYDEBUG (RooMsgService::anyDebug())
63 #endif
64 
65 #define dologD(a) (ANYDEBUG && RooMsgService::instance().isActive(this,RooFit::a,RooFit::DEBUG))
66 #define dologI(a) (RooMsgService::instance().isActive(this,RooFit::a,RooFit::INFO))
67 #define dologP(a) (RooMsgService::instance().isActive(this,RooFit::a,RooFit::PROGRESS))
68 #define dologW(a) (RooMsgService::instance().isActive(this,RooFit::a,RooFit::WARNING))
69 #define dologE(a) (RooMsgService::instance().isActive(this,RooFit::a,RooFit::ERROR))
70 #define dologF(a) (RooMsgService::instance().isActive(this,RooFit::a,RooFit::FATAL))
71 
72 #define oodologD(o,a) (ANYDEBUG && RooMsgService::instance().isActive(o,RooFit::a,RooFit::DEBUG))
73 #define oodologI(o,a) (RooMsgService::instance().isActive(o,RooFit::a,RooFit::INFO))
74 #define oodologP(o,a) (RooMsgService::instance().isActive(o,RooFit::a,RooFit::PROGRESS))
75 #define oodologW(o,a) (RooMsgService::instance().isActive(o,RooFit::a,RooFit::WARNING))
76 #define oodologE(o,a) (RooMsgService::instance().isActive(o,RooFit::a,RooFit::ERROR))
77 #define oodologF(o,a) (RooMsgService::instance().isActive(o,RooFit::a,RooFit::FATAL))
78 
79 // Shortcuts definitions with conditional execution of print expression -- USE WITH CAUTION
80 
81 #define cxcoutD(a) if (ANYDEBUG && RooMsgService::instance().isActive(this,RooFit::a,RooFit::DEBUG)) RooMsgService::instance().log(this,RooFit::DEBUG,RooFit::a)
82 #define ccxcoutD(a) if (ANYDEBUG && RooMsgService::instance().isActive(this,RooFit::a,RooFit::DEBUG)) RooMsgService::instance().log(this,RooFit::DEBUG,RooFit::a,kTRUE)
83 #define oocxcoutD(o,a) if (ANYDEBUG && RooMsgService::instance().isActive(o,RooFit::a,RooFit::DEBUG)) RooMsgService::instance().log(o,RooFit::DEBUG,RooFit::a)
84 #define ooccxcoutD(o,a) if (ANYDEBUG && RooMsgService::instance().isActive(o,RooFit::a,RooFit::DEBUG)) RooMsgService::instance().log(o,RooFit::DEBUG,RooFit::a,kTRUE)
85 #define cxcoutI(a) if (RooMsgService::instance().isActive(this,RooFit::a,RooFit::INFO)) RooMsgService::instance().log(this,RooFit::INFO,RooFit::a)
86 #define ccxcoutI(a) if (RooMsgService::instance().isActive(this,RooFit::a,RooFit::INFO)) RooMsgService::instance().log(this,RooFit::INFO,RooFit::a,kTRUE)
87 #define oocxcoutI(o,a) if (RooMsgService::instance().isActive(o,RooFit::a,RooFit::INFO)) RooMsgService::instance().log(o,RooFit::INFO,RooFit::a)
88 #define ooccxcoutI(o,a) if (RooMsgService::instance().isActive(o,RooFit::a,RooFit::INFO)) RooMsgService::instance().log(o,RooFit::INFO,RooFit::a,kTRUE)
89 #define cxcoutP(a) if (RooMsgService::instance().isActive(this,RooFit::a,RooFit::PROGRESS)) RooMsgService::instance().log(this,RooFit::PROGRESS,RooFit::a)
90 #define ccxcoutP(a) if (RooMsgService::instance().isActive(this,RooFit::a,RooFit::PROGRESS)) RooMsgService::instance().log(this,RooFit::PROGRESS,RooFit::a,kTRUE)
91 #define oocxcoutP(o,a) if (RooMsgService::instance().isActive(o,RooFit::a,RooFit::PROGRESS)) RooMsgService::instance().log(o,RooFit::PROGRESS,RooFit::a)
92 #define ooccxcoutP(o,a) if (RooMsgService::instance().isActive(o,RooFit::a,RooFit::PROGRESS)) RooMsgService::instance().log(o,RooFit::PROGRESS,RooFit::a,kTRUE)
93 #define cxcoutW(a) if (RooMsgService::instance().isActive(this,RooFit::a,RooFit::WARNING)) RooMsgService::instance().log(this,RooFit::WARNING,RooFit::a)
94 #define ccxcoutW(a) if (RooMsgService::instance().isActive(this,RooFit::a,RooFit::WARNING)) RooMsgService::instance().log(this,RooFit::WARNING,RooFit::a,kTRUE)
95 #define oocxcoutW(o,a) if (RooMsgService::instance().isActive(o,RooFit::a,RooFit::WARNING)) RooMsgService::instance().log(o,RooFit::WARNING,RooFit::a)
96 #define ooccxcoutW(o,a) if (RooMsgService::instance().isActive(o,RooFit::a,RooFit::WARNING)) RooMsgService::instance().log(o,RooFit::WARNING,RooFit::a,kTRUE)
97 #define cxcoutE(a) if (RooMsgService::instance().isActive(this,RooFit::a,RooFit::ERROR)) RooMsgService::instance().log(this,RooFit::ERROR,RooFit::a)
98 #define ccxcoutE(a) if (RooMsgService::instance().isActive(this,RooFit::a,RooFit::ERROR)) RooMsgService::instance().log(this,RooFit::ERROR,RooFit::a,kTRUE)
99 #define oocxcoutE(o,a) if (RooMsgService::instance().isActive(o,RooFit::a,RooFit::ERROR)) RooMsgService::instance().log(o,RooFit::ERROR,RooFit::a)
100 #define ooccxcoutE(o,a) if (RooMsgService::instance().isActive(o,RooFit::a,RooFit::ERROR)) RooMsgService::instance().log(o,RooFit::ERROR,RooFit::a,kTRUE)
101 #define cxcoutF(a) if (RooMsgService::instance().isActive(this,RooFit::a,RooFit::FATAL)) RooMsgService::instance().log(this,RooFit::FATAL,RooFit::a)
102 #define ccxcoutF(a) if (RooMsgService::instance().isActive(this,RooFit::a,RooFit::FATAL)) RooMsgService::instance().log(this,RooFit::FATAL,RooFit::a,kTRUE)
103 #define oocxcoutF(o,a) if (RooMsgService::instance().isActive(o,RooFit::a,RooFit::FATAL)) RooMsgService::instance().log(o,RooFit::FATAL,RooFit::a)
104 #define ooccxcoutF(o,a) if (RooMsgService::instance().isActive(o,RooFit::a,RooFit::FATAL)) RooMsgService::instance().log(o,RooFit::FATAL,RooFit::a,kTRUE)
105 
106 class RooMsgService : public TObject {
107 public:
108 
109  virtual ~RooMsgService() ;
110 
111  struct StreamConfig {
112  public:
113 
114  void addTopic(RooFit::MsgTopic newTopic) {
115  topic |= newTopic ;
116  }
117 
118  void removeTopic(RooFit::MsgTopic oldTopic) {
119  topic &= ~oldTopic ;
120  }
121 
122 
123  friend class RooMsgService ;
124 
125  Bool_t match(RooFit::MsgLevel level, RooFit::MsgTopic facility, const RooAbsArg* obj) ;
126  Bool_t match(RooFit::MsgLevel level, RooFit::MsgTopic facility, const TObject* obj) ;
127 
130 
133  std::string objectName ;
134  std::string className ;
135  std::string baseClassName ;
136  std::string tagName ;
139 
140  std::ostream* os ;
141 
142  } ;
143 
144  // Access to instance
145  static RooMsgService& instance();
146  static Bool_t anyDebug() ;
147 
148  // User interface -- Add or delete reporting streams ;
149  Int_t addStream(RooFit::MsgLevel level, const RooCmdArg& arg1=RooCmdArg(), const RooCmdArg& arg2=RooCmdArg(), const RooCmdArg& arg3=RooCmdArg(),
150  const RooCmdArg& arg4=RooCmdArg(), const RooCmdArg& arg5=RooCmdArg(), const RooCmdArg& arg6=RooCmdArg());
151  void deleteStream(Int_t id) ;
153 
154  Int_t numStreams() const { return _streams.size() ; }
155  void setStreamStatus(Int_t id, Bool_t active) ;
156  Bool_t getStreamStatus(Int_t id) const ;
157 
158  void reset();
159 
162 
163  void Print(Option_t *options= 0) const ;
164  void showPid(Bool_t flag) { _showPid = flag ; }
165 
166  // Back end -- Send message or check if particular logging configuration is active
167  std::ostream& log(const RooAbsArg* self, RooFit::MsgLevel level, RooFit::MsgTopic facility, Bool_t forceSkipPrefix=kFALSE) ;
168  std::ostream& log(const TObject* self, RooFit::MsgLevel level, RooFit::MsgTopic facility, Bool_t forceSkipPrefix=kFALSE) ;
169  Bool_t isActive(const RooAbsArg* self, RooFit::MsgTopic facility, RooFit::MsgLevel level) ;
170  Bool_t isActive(const TObject* self, RooFit::MsgTopic facility, RooFit::MsgLevel level) ;
171 
173  std::map<int,std::string> _levelNames ;
174  std::map<int,std::string> _topicNames ;
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 
216  ClassDef(RooMsgService,0) // RooFit Message Service Singleton class
217 };
218 
219 #endif
RooCmdArg
Definition: RooCmdArg.h:27
RooMsgService::_streams
std::vector< StreamConfig > _streams
Definition: RooMsgService.h:195
RooMsgService::deleteStream
void deleteStream(Int_t id)
Delete stream with given unique ID code.
Definition: RooMsgService.cxx:311
RooMsgService::isActive
Bool_t isActive(const RooAbsArg *self, RooFit::MsgTopic facility, RooFit::MsgLevel level)
Check if logging is active for given object/topic/RooFit::MsgLevel combination.
Definition: RooMsgService.cxx:395
RooMsgService::StreamConfig::addTopic
void addTopic(RooFit::MsgTopic newTopic)
Definition: RooMsgService.h:114
RooMsgService::setSilentMode
void setSilentMode(Bool_t flag)
Definition: RooMsgService.h:178
RooMsgService::numStreams
Int_t numStreams() const
Definition: RooMsgService.h:154
RooMsgService::setStreamStatus
void setStreamStatus(Int_t id, Bool_t active)
(De)Activate stream with given unique ID
Definition: RooMsgService.cxx:329
RooMsgService::StreamConfig::objectName
std::string objectName
Definition: RooMsgService.h:133
RooMsgService::StreamConfig::universal
Bool_t universal
Definition: RooMsgService.h:129
RooMsgService::~RooMsgService
virtual ~RooMsgService()
Destructor.
Definition: RooMsgService.cxx:139
Int_t
int Int_t
Definition: RtypesCore.h:45
RooMsgService::log
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.
Definition: RooMsgService.cxx:484
RooMsgService::StreamConfig::removeTopic
void removeTopic(RooFit::MsgTopic oldTopic)
Definition: RooMsgService.h:118
RooMsgService::getStream
StreamConfig & getStream(Int_t id)
Definition: RooMsgService.h:152
RooMsgService::_levelNames
std::map< int, std::string > _levelNames
Definition: RooMsgService.h:173
RooMsgService::restoreState
void restoreState()
Restore last saved state of message service.
Definition: RooMsgService.cxx:384
RooFit::MsgTopic
MsgTopic
Topics for a RooMsgService::StreamConfig in RooMsgService.
Definition: RooGlobalFunc.h:67
RooFit::MsgLevel
MsgLevel
Verbosity level for RooMsgService::StreamConfig in RooMsgService.
Definition: RooGlobalFunc.h:65
Bool_t
bool Bool_t
Definition: RtypesCore.h:63
Color_t
short Color_t
Definition: RtypesCore.h:83
bool
RooMsgService::clearErrorCount
void clearErrorCount()
Definition: RooMsgService.h:181
id
XFontStruct * id
Definition: TGX11.cxx:109
RooMsgService::getStreamStatus
Bool_t getStreamStatus(Int_t id) const
Get activation status of stream with given unique ID.
Definition: RooMsgService.cxx:349
RooMsgService::StreamConfig::match
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.
Definition: RooMsgService.cxx:443
RooMsgService::RooMsgService
RooMsgService()
Constructor.
Definition: RooMsgService.cxx:81
Option_t
const typedef char Option_t
Definition: RtypesCore.h:66
RooMsgService::silentMode
Bool_t silentMode() const
Definition: RooMsgService.h:177
RooMsgService::_globMinLevel
RooFit::MsgLevel _globMinLevel
Definition: RooMsgService.h:200
RooMsgService::saveState
void saveState()
Save current state of message service.
Definition: RooMsgService.cxx:374
kFALSE
const Bool_t kFALSE
Definition: RtypesCore.h:92
RooMsgService::_files
std::map< std::string, std::ostream * > _files
Definition: RooMsgService.h:199
RooMsgService::Print
void Print(Option_t *options=0) const
Print configuration of message service.
Definition: RooMsgService.cxx:551
RooMsgService::setGlobalKillBelow
void setGlobalKillBelow(RooFit::MsgLevel level)
Definition: RooMsgService.h:160
RooMsgService::addStream
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....
Definition: RooMsgService.cxx:201
RooMsgService::StreamConfig::minLevel
RooFit::MsgLevel minLevel
Definition: RooMsgService.h:131
RooMsgService::_showPid
Bool_t _showPid
Definition: RooMsgService.h:204
RooMsgService::_silentMode
Bool_t _silentMode
Definition: RooMsgService.h:203
RooMsgService::StreamConfig::prefix
Bool_t prefix
Definition: RooMsgService.h:138
RooCmdArg.h
RooMsgService::StreamConfig::topic
Int_t topic
Definition: RooMsgService.h:132
RooMsgService::StreamConfig::baseClassName
std::string baseClassName
Definition: RooMsgService.h:135
RooMsgService::_topicNames
std::map< int, std::string > _topicNames
Definition: RooMsgService.h:174
RooGlobalFunc.h
RooMsgService::StreamConfig::className
std::string className
Definition: RooMsgService.h:134
RooMsgService::StreamConfig::active
Bool_t active
Definition: RooMsgService.h:128
RooMsgService::showPid
void showPid(Bool_t flag)
Definition: RooMsgService.h:164
RooMsgService
Definition: RooMsgService.h:106
RooWorkspace
Definition: RooWorkspace.h:43
RooMsgService::errorCount
Int_t errorCount() const
Definition: RooMsgService.h:180
RooMsgService::_debugWorkspace
RooWorkspace * _debugWorkspace
Definition: RooMsgService.h:212
RooMsgService::_errorCount
Int_t _errorCount
Definition: RooMsgService.h:206
RooMsgService::_streamsSaved
std::stack< std::vector< StreamConfig > > _streamsSaved
Definition: RooMsgService.h:196
RooMsgService::debugCode
Int_t & debugCode()
Definition: RooMsgService.h:188
TObject.h
RooMsgService::_lastMsgLevel
RooFit::MsgLevel _lastMsgLevel
Definition: RooMsgService.h:201
TObject
Definition: TObject.h:37
ClassDef
#define ClassDef(name, id)
Definition: Rtypes.h:325
RooMsgService::_debugCount
static Int_t _debugCount
Definition: RooMsgService.h:172
RooMsgService::StreamConfig::os
std::ostream * os
Definition: RooMsgService.h:140
RooMsgService::_devnull
std::ostream * _devnull
Definition: RooMsgService.h:197
RooAbsArg
Definition: RooAbsArg.h:73
RooMsgService::debugWorkspace
RooWorkspace * debugWorkspace()
Definition: RooMsgService.cxx:168
RooMsgService::anyDebug
static Bool_t anyDebug()
Returns true if any debug level stream is active.
Definition: RooMsgService.cxx:159
RooMsgService::activeStream
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.
Definition: RooMsgService.cxx:413
RooMsgService::StreamConfig
Definition: RooMsgService.h:111
RooMsgService::StreamConfig::color
Color_t color
Definition: RooMsgService.h:137
RooMsgService::_debugCode
Int_t _debugCode
Definition: RooMsgService.h:214
RooMsgService::instance
static RooMsgService & instance()
Return reference to singleton instance.
Definition: RooMsgService.cxx:363
RooMsgService::globalKillBelow
RooFit::MsgLevel globalKillBelow() const
Definition: RooMsgService.h:161
RooMsgService::StreamConfig::tagName
std::string tagName
Definition: RooMsgService.h:136
RooMsgService::reset
void reset()
Definition: RooMsgService.cxx:113
int