Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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 <RooCmdArg.h>
20#include <RooGlobalFunc.h>
21
22#include <TObject.h>
23
24#include <cstddef>
25#include <string>
26#include <vector>
27#include <stack>
28#include <map>
29
30class RooAbsArg ;
31class RooWorkspace ;
32
33// Shortcut definitions
34#define coutI(a) RooMsgService::instance().log(this,RooFit::INFO,RooFit::a)
35#define coutP(a) RooMsgService::instance().log(this,RooFit::PROGRESS,RooFit::a)
36#define coutW(a) RooMsgService::instance().log(this,RooFit::WARNING,RooFit::a)
37#define coutE(a) RooMsgService::instance().log(this,RooFit::ERROR,RooFit::a)
38#define coutF(a) RooMsgService::instance().log(this,RooFit::FATAL,RooFit::a)
39
40// Skip the message prefix
41#define ccoutD(a) RooMsgService::instance().log(this,RooFit::DEBUG,RooFit::a,true)
42#define ccoutI(a) RooMsgService::instance().log(this,RooFit::INFO,RooFit::a,true)
43#define ccoutP(a) RooMsgService::instance().log(this,RooFit::PROGRESS,RooFit::a,true)
44#define ccoutW(a) RooMsgService::instance().log(this,RooFit::WARNING,RooFit::a,true)
45#define ccoutE(a) RooMsgService::instance().log(this,RooFit::ERROR,RooFit::a,true)
46#define ccoutF(a) RooMsgService::instance().log(this,RooFit::FATAL,RooFit::a,true)
47
48// Message from given object instead of "this"
49#define oocoutI(o,a) RooMsgService::instance().log(o,RooFit::INFO,RooFit::a)
50#define oocoutP(o,a) RooMsgService::instance().log(o,RooFit::PROGRESS,RooFit::a)
51#define oocoutW(o,a) RooMsgService::instance().log(o,RooFit::WARNING,RooFit::a)
52#define oocoutE(o,a) RooMsgService::instance().log(o,RooFit::ERROR,RooFit::a)
53#define oocoutF(o,a) RooMsgService::instance().log(o,RooFit::FATAL,RooFit::a)
54
55// Message from given object instead of "this" and skip message prefix
56#define ooccoutD(o,a) RooMsgService::instance().log(o,RooFit::DEBUG,RooFit::a,true)
57#define ooccoutI(o,a) RooMsgService::instance().log(o,RooFit::INFO,RooFit::a,true)
58#define ooccoutP(o,a) RooMsgService::instance().log(o,RooFit::PROGRESS,RooFit::a,true)
59#define ooccoutW(o,a) RooMsgService::instance().log(o,RooFit::WARNING,RooFit::a,true)
60#define ooccoutE(o,a) RooMsgService::instance().log(o,RooFit::ERROR,RooFit::a,true)
61#define ooccoutF(o,a) RooMsgService::instance().log(o,RooFit::FATAL,RooFit::a,true)
62
63#ifndef _WIN32
64#define ANYDEBUG (RooMsgService::_debugCount>0)
65#else
66#define ANYDEBUG (RooMsgService::anyDebug())
67#endif
68
69#define dologD(a) (ANYDEBUG && RooMsgService::instance().isActive(this,RooFit::a,RooFit::DEBUG))
70#define dologI(a) (RooMsgService::instance().isActive(this,RooFit::a,RooFit::INFO))
71#define dologP(a) (RooMsgService::instance().isActive(this,RooFit::a,RooFit::PROGRESS))
72#define dologW(a) (RooMsgService::instance().isActive(this,RooFit::a,RooFit::WARNING))
73#define dologE(a) (RooMsgService::instance().isActive(this,RooFit::a,RooFit::ERROR))
74#define dologF(a) (RooMsgService::instance().isActive(this,RooFit::a,RooFit::FATAL))
75
76#define oodologD(o,a) (ANYDEBUG && RooMsgService::instance().isActive(o,RooFit::a,RooFit::DEBUG))
77#define oodologI(o,a) (RooMsgService::instance().isActive(o,RooFit::a,RooFit::INFO))
78#define oodologP(o,a) (RooMsgService::instance().isActive(o,RooFit::a,RooFit::PROGRESS))
79#define oodologW(o,a) (RooMsgService::instance().isActive(o,RooFit::a,RooFit::WARNING))
80#define oodologE(o,a) (RooMsgService::instance().isActive(o,RooFit::a,RooFit::ERROR))
81#define oodologF(o,a) (RooMsgService::instance().isActive(o,RooFit::a,RooFit::FATAL))
82
83// Shortcuts definitions with conditional execution of print expression -- USE WITH CAUTION
84
85#define cxcoutD(a) if (ANYDEBUG && RooMsgService::instance().isActive(this,RooFit::a,RooFit::DEBUG)) RooMsgService::instance().log(this,RooFit::DEBUG,RooFit::a)
86#define ccxcoutD(a) if (ANYDEBUG && RooMsgService::instance().isActive(this,RooFit::a,RooFit::DEBUG)) RooMsgService::instance().log(this,RooFit::DEBUG,RooFit::a,true)
87#define oocxcoutD(o,a) if (ANYDEBUG && RooMsgService::instance().isActive(o,RooFit::a,RooFit::DEBUG)) RooMsgService::instance().log(o,RooFit::DEBUG,RooFit::a)
88#define ooccxcoutD(o,a) if (ANYDEBUG && RooMsgService::instance().isActive(o,RooFit::a,RooFit::DEBUG)) RooMsgService::instance().log(o,RooFit::DEBUG,RooFit::a,true)
89#define cxcoutI(a) if (RooMsgService::instance().isActive(this,RooFit::a,RooFit::INFO)) RooMsgService::instance().log(this,RooFit::INFO,RooFit::a)
90#define ccxcoutI(a) if (RooMsgService::instance().isActive(this,RooFit::a,RooFit::INFO)) RooMsgService::instance().log(this,RooFit::INFO,RooFit::a,true)
91#define oocxcoutI(o,a) if (RooMsgService::instance().isActive(o,RooFit::a,RooFit::INFO)) RooMsgService::instance().log(o,RooFit::INFO,RooFit::a)
92#define ooccxcoutI(o,a) if (RooMsgService::instance().isActive(o,RooFit::a,RooFit::INFO)) RooMsgService::instance().log(o,RooFit::INFO,RooFit::a,true)
93#define cxcoutP(a) if (RooMsgService::instance().isActive(this,RooFit::a,RooFit::PROGRESS)) RooMsgService::instance().log(this,RooFit::PROGRESS,RooFit::a)
94#define ccxcoutP(a) if (RooMsgService::instance().isActive(this,RooFit::a,RooFit::PROGRESS)) RooMsgService::instance().log(this,RooFit::PROGRESS,RooFit::a,true)
95#define oocxcoutP(o,a) if (RooMsgService::instance().isActive(o,RooFit::a,RooFit::PROGRESS)) RooMsgService::instance().log(o,RooFit::PROGRESS,RooFit::a)
96#define ooccxcoutP(o,a) if (RooMsgService::instance().isActive(o,RooFit::a,RooFit::PROGRESS)) RooMsgService::instance().log(o,RooFit::PROGRESS,RooFit::a,true)
97#define cxcoutW(a) if (RooMsgService::instance().isActive(this,RooFit::a,RooFit::WARNING)) RooMsgService::instance().log(this,RooFit::WARNING,RooFit::a)
98#define ccxcoutW(a) if (RooMsgService::instance().isActive(this,RooFit::a,RooFit::WARNING)) RooMsgService::instance().log(this,RooFit::WARNING,RooFit::a,true)
99#define oocxcoutW(o,a) if (RooMsgService::instance().isActive(o,RooFit::a,RooFit::WARNING)) RooMsgService::instance().log(o,RooFit::WARNING,RooFit::a)
100#define ooccxcoutW(o,a) if (RooMsgService::instance().isActive(o,RooFit::a,RooFit::WARNING)) RooMsgService::instance().log(o,RooFit::WARNING,RooFit::a,true)
101#define cxcoutE(a) if (RooMsgService::instance().isActive(this,RooFit::a,RooFit::ERROR)) RooMsgService::instance().log(this,RooFit::ERROR,RooFit::a)
102#define ccxcoutE(a) if (RooMsgService::instance().isActive(this,RooFit::a,RooFit::ERROR)) RooMsgService::instance().log(this,RooFit::ERROR,RooFit::a,true)
103#define oocxcoutE(o,a) if (RooMsgService::instance().isActive(o,RooFit::a,RooFit::ERROR)) RooMsgService::instance().log(o,RooFit::ERROR,RooFit::a)
104#define ooccxcoutE(o,a) if (RooMsgService::instance().isActive(o,RooFit::a,RooFit::ERROR)) RooMsgService::instance().log(o,RooFit::ERROR,RooFit::a,true)
105#define cxcoutF(a) if (RooMsgService::instance().isActive(this,RooFit::a,RooFit::FATAL)) RooMsgService::instance().log(this,RooFit::FATAL,RooFit::a)
106#define ccxcoutF(a) if (RooMsgService::instance().isActive(this,RooFit::a,RooFit::FATAL)) RooMsgService::instance().log(this,RooFit::FATAL,RooFit::a,true)
107#define oocxcoutF(o,a) if (RooMsgService::instance().isActive(o,RooFit::a,RooFit::FATAL)) RooMsgService::instance().log(o,RooFit::FATAL,RooFit::a)
108#define ooccxcoutF(o,a) if (RooMsgService::instance().isActive(o,RooFit::a,RooFit::FATAL)) RooMsgService::instance().log(o,RooFit::FATAL,RooFit::a,true)
109
110class RooMsgService : public TObject {
111public:
112
113 ~RooMsgService() override ;
114
116 public:
117
118 void addTopic(RooFit::MsgTopic newTopic) {
119 topic |= newTopic ;
120 }
121
123 topic &= ~oldTopic ;
124 }
125
126
127 friend class RooMsgService ;
128
129 bool match(RooFit::MsgLevel level, RooFit::MsgTopic facility, const RooAbsArg* obj) ;
130 bool match(RooFit::MsgLevel level, RooFit::MsgTopic facility, const TObject* obj) ;
131
132 inline bool match(RooFit::MsgLevel level, RooFit::MsgTopic facility, std::nullptr_t obj)
133 {
134 return match(level, facility, static_cast<TObject const *>(obj));
135 }
136
137 bool active ;
139
142 std::string objectName ;
143 std::string className ;
144 std::string baseClassName ;
145 std::string tagName ;
147 bool prefix ;
148
149 std::ostream* os ;
150
151 } ;
152
153 // Access to instance
154 static RooMsgService& instance();
155 static bool anyDebug() ;
156
157 // User interface -- Add or delete reporting streams ;
158 Int_t addStream(RooFit::MsgLevel level, const RooCmdArg& arg1={}, const RooCmdArg& arg2={}, const RooCmdArg& arg3={},
159 const RooCmdArg& arg4={}, const RooCmdArg& arg5={}, const RooCmdArg& arg6={});
160 void deleteStream(Int_t id) ;
162
163 Int_t numStreams() const { return _streams.size() ; }
164 void setStreamStatus(Int_t id, bool active) ;
165 bool getStreamStatus(Int_t id) const ;
166
167 void reset();
168
171
172 void Print(Option_t *options= nullptr) const override ;
173 void showPid(bool flag) { _showPid = flag ; }
174
175 // Back end -- Send message or check if particular logging configuration is active
176 std::ostream& log(const RooAbsArg* self, RooFit::MsgLevel level, RooFit::MsgTopic facility, bool forceSkipPrefix=false) ;
177 std::ostream& log(const TObject* self, RooFit::MsgLevel level, RooFit::MsgTopic facility, bool forceSkipPrefix=false) ;
178 // Overload to resolve the ambiguity when passing a `nullptr`. Without this,
179 // one would have to explicitly cast the `nullptr` to TObject* or RooAbsArg*.
180 inline std::ostream& log(std::nullptr_t, RooFit::MsgLevel level, RooFit::MsgTopic facility, bool forceSkipPrefix=false) {
181 return log(static_cast<TObject*>(nullptr), level, facility, forceSkipPrefix);
182 }
183
184 /// Check if logging is active for given object/topic/RooFit::%MsgLevel combination.
185 template <class T>
186 bool isActive(T self, RooFit::MsgTopic topic, RooFit::MsgLevel level)
187 {
188 return activeStream(self, topic, level) >= 0;
189 }
190
192 std::map<int,std::string> _levelNames ;
193 std::map<int,std::string> _topicNames ;
194
195 // Print level support for RooFit-related messages that are not routed through RooMsgService (such as Minuit printouts)
196 bool silentMode() const { return _silentMode ; }
197 void setSilentMode(bool flag) { _silentMode = flag ; }
198
199 Int_t errorCount() const { return _errorCount ; }
201
202 void saveState() ;
203 void restoreState() ;
204
206
207 Int_t& debugCode() { return _debugCode ; }
208
209protected:
210
211 /// Find appropriate logging stream for message from given object with given topic and message level.
212 template <class T>
214 {
215 if (level < _globMinLevel)
216 return -1;
217 for (UInt_t i = 0; i < _streams.size(); i++) {
218 if (_streams[i].match(level, topic, self)) {
219 return i;
220 }
221 }
222 return -1;
223 }
224
225 std::vector<StreamConfig> _streams ;
226 std::stack<std::vector<StreamConfig> > _streamsSaved ;
227 std::unique_ptr<std::ofstream> _devnull ;
228
229 std::map<std::string,std::unique_ptr<std::ostream>> _files ;
232
234 bool _showPid ;
235
237
238 // Private constructor -- singleton class
239 RooMsgService() ;
241
242 std::unique_ptr<RooWorkspace> _debugWorkspace;
243
245
246 ClassDefOverride(RooMsgService,0) // RooFit Message Service Singleton class
247};
248
249#endif
short Color_t
Definition RtypesCore.h:92
const char Option_t
Definition RtypesCore.h:66
#define ClassDefOverride(name, id)
Definition Rtypes.h:341
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize id
Common abstract base class for objects that represent a value and a "shape" in RooFit.
Definition RooAbsArg.h:77
Named container for two doubles, two integers two object points and three string pointers that can be...
Definition RooCmdArg.h:26
Singleton class that organizes messages generated in RooFit.
std::vector< StreamConfig > _streams
void restoreState()
Restore last saved state of message service.
std::ostream & log(const RooAbsArg *self, RooFit::MsgLevel level, RooFit::MsgTopic facility, bool forceSkipPrefix=false)
Log error message associated with RooAbsArg object self at given level and topic.
Int_t activeStream(T self, RooFit::MsgTopic topic, RooFit::MsgLevel level)
Find appropriate logging stream for message from given object with given topic and message level.
static RooMsgService & instance()
Return reference to singleton instance.
static Int_t _debugCount
void clearErrorCount()
StreamConfig & getStream(Int_t id)
std::unique_ptr< RooWorkspace > _debugWorkspace
static bool anyDebug()
Returns true if any debug level stream is active.
void setGlobalKillBelow(RooFit::MsgLevel level)
RooFit::MsgLevel _globMinLevel
std::stack< std::vector< StreamConfig > > _streamsSaved
RooMsgService()
Constructor.
Int_t numStreams() const
RooWorkspace * debugWorkspace()
void Print(Option_t *options=nullptr) const override
Print configuration of message service.
void setStreamStatus(Int_t id, bool active)
(De)Activate stream with given unique ID
void saveState()
Save current state of message service.
Int_t addStream(RooFit::MsgLevel level, const RooCmdArg &arg1={}, const RooCmdArg &arg2={}, const RooCmdArg &arg3={}, const RooCmdArg &arg4={}, const RooCmdArg &arg5={}, const RooCmdArg &arg6={})
Add a message logging stream for message with given RooFit::MsgLevel or higher.
std::map< int, std::string > _topicNames
void setSilentMode(bool flag)
Int_t errorCount() const
bool silentMode() const
~RooMsgService() override
void showPid(bool flag)
std::ostream & log(std::nullptr_t, RooFit::MsgLevel level, RooFit::MsgTopic facility, bool forceSkipPrefix=false)
std::map< std::string, std::unique_ptr< std::ostream > > _files
bool getStreamStatus(Int_t id) const
Get activation status of stream with given unique ID.
bool isActive(T self, RooFit::MsgTopic topic, RooFit::MsgLevel level)
Check if logging is active for given object/topic/RooFit::MsgLevel combination.
RooMsgService(const RooMsgService &)
void deleteStream(Int_t id)
Delete stream with given unique ID code.
std::unique_ptr< std::ofstream > _devnull
std::map< int, std::string > _levelNames
Int_t & debugCode()
RooFit::MsgLevel globalKillBelow() const
RooFit::MsgLevel _lastMsgLevel
Persistable container for RooFit projects.
Mother of all ROOT objects.
Definition TObject.h:41
MsgLevel
Verbosity level for RooMsgService::StreamConfig in RooMsgService.
MsgTopic
Topics for a RooMsgService::StreamConfig in RooMsgService.
bool match(RooFit::MsgLevel level, RooFit::MsgTopic facility, const RooAbsArg *obj)
Determine if message from given object at given level on given topic is logged.
void addTopic(RooFit::MsgTopic newTopic)
void removeTopic(RooFit::MsgTopic oldTopic)
bool match(RooFit::MsgLevel level, RooFit::MsgTopic facility, std::nullptr_t obj)