42 #include <sys/types.h>
59 using namespace RooFit ;
61 ClassImp(RooMsgService);
63 Int_t RooMsgService::_debugCount = 0 ;
71 RooMsgService::RooMsgService()
73 _devnull =
new ofstream(
"/dev/null") ;
75 _levelNames[DEBUG]=
"DEBUG" ;
76 _levelNames[INFO]=
"INFO" ;
77 _levelNames[PROGRESS]=
"PROGRESS" ;
78 _levelNames[WARNING]=
"WARNING" ;
79 _levelNames[ERROR]=
"ERROR" ;
80 _levelNames[FATAL]=
"FATAL" ;
82 _topicNames[Generation]=
"Generation" ;
83 _topicNames[Minimization]=
"Minization" ;
84 _topicNames[Plotting]=
"Plotting" ;
85 _topicNames[Fitting]=
"Fitting" ;
86 _topicNames[Integration]=
"Integration" ;
87 _topicNames[LinkStateMgmt]=
"LinkStateMgmt" ;
88 _topicNames[Eval]=
"Eval" ;
89 _topicNames[Caching]=
"Caching" ;
90 _topicNames[Optimization]=
"Optimization" ;
91 _topicNames[ObjectHandling]=
"ObjectHandling" ;
92 _topicNames[InputArguments]=
"InputArguments" ;
93 _topicNames[Tracing]=
"Tracing" ;
94 _topicNames[Contents]=
"Contents" ;
95 _topicNames[DataHandling]=
"DataHandling" ;
96 _topicNames[NumIntegration]=
"NumericIntegration" ;
102 void RooMsgService::reset() {
103 _silentMode = kFALSE ;
105 _globMinLevel = DEBUG ;
106 _lastMsgLevel = DEBUG ;
108 delete _debugWorkspace;
109 _debugWorkspace =
nullptr;
112 for (
auto item : _files) {
119 addStream(RooFit::PROGRESS) ;
120 addStream(RooFit::INFO,Topic(RooFit::Eval|RooFit::Plotting|RooFit::Fitting|RooFit::Minimization|RooFit::Caching|RooFit::ObjectHandling|RooFit::NumIntegration|RooFit::InputArguments|RooFit::DataHandling)) ;
127 RooMsgService::~RooMsgService()
130 map<string,ostream*>::iterator iter = _files.begin() ;
131 for (; iter != _files.end() ; ++iter) {
132 delete iter->second ;
135 if (_debugWorkspace) {
136 delete _debugWorkspace ;
147 Bool_t RooMsgService::anyDebug()
149 return instance()._debugCount>0 ;
156 RooWorkspace* RooMsgService::debugWorkspace()
158 if (!_debugWorkspace) {
159 _debugWorkspace =
new RooWorkspace(
"wdebug") ;
161 return _debugWorkspace ;
189 Int_t RooMsgService::addStream(RooFit::MsgLevel level,
const RooCmdArg& arg1,
const RooCmdArg& arg2,
const RooCmdArg& arg3,
190 const RooCmdArg& arg4,
const RooCmdArg& arg5,
const RooCmdArg& arg6)
195 l.Add((TObject*)&arg1) ; l.Add((TObject*)&arg2) ;
196 l.Add((TObject*)&arg3) ; l.Add((TObject*)&arg4) ;
197 l.Add((TObject*)&arg5) ; l.Add((TObject*)&arg6) ;
200 RooCmdConfig pc(Form(
"RooMsgService::addReportingStream(%s)",GetName())) ;
201 pc.defineInt(
"prefix",
"Prefix",0,kTRUE) ;
202 pc.defineInt(
"color",
"Color",0,static_cast<Int_t>(kBlack)) ;
203 pc.defineInt(
"topic",
"Topic",0,0xFFFFF) ;
204 pc.defineString(
"objName",
"ObjectName",0,
"") ;
205 pc.defineString(
"className",
"ClassName",0,
"") ;
206 pc.defineString(
"baseClassName",
"BaseClassName",0,
"") ;
207 pc.defineString(
"tagName",
"LabelName",0,
"") ;
208 pc.defineString(
"outFile",
"OutputFile",0,
"") ;
209 pc.defineObject(
"outStream",
"OutputStream",0,0) ;
210 pc.defineMutex(
"OutputFile",
"OutputStream") ;
219 RooFit::MsgTopic topic = (RooFit::MsgTopic) pc.getInt(
"topic") ;
220 const char* objName = pc.getString(
"objName") ;
221 const char* className = pc.getString(
"className") ;
222 const char* baseClassName = pc.getString(
"baseClassName") ;
223 const char* tagName = pc.getString(
"tagName") ;
224 const char* outFile = pc.getString(
"outFile") ;
225 Bool_t prefix = pc.getInt(
"prefix") ;
226 Color_t color =
static_cast<Color_t
>(pc.getInt(
"color")) ;
227 ostream* os =
reinterpret_cast<ostream*
>(pc.getObject(
"outStream")) ;
230 StreamConfig newStream ;
233 newStream.active = kTRUE ;
234 newStream.minLevel = level ;
235 newStream.topic = topic ;
236 newStream.objectName = (objName ? objName :
"" ) ;
237 newStream.className = (className ? className :
"" ) ;
238 newStream.baseClassName = (baseClassName ? baseClassName :
"" ) ;
239 newStream.tagName = (tagName ? tagName :
"" ) ;
240 newStream.color = color ;
241 newStream.prefix = prefix ;
242 newStream.universal = (newStream.objectName==
"" && newStream.className==
"" && newStream.baseClassName==
"" && newStream.tagName==
"") ;
255 }
else if (
string(outFile).size()>0) {
258 ostream* os2 = _files[
"outFile"] ;
263 os2 =
new ofstream(outFile) ;
266 cout <<
"RooMsgService::addReportingStream ERROR: cannot open output log file " << outFile <<
" reverting stream to stdout" << endl ;
268 newStream.os = &cout ;
274 _files[
"outFile"] = os2 ;
282 newStream.os = &cout ;
288 _streams.push_back(newStream) ;
291 return _streams.size()-1 ;
299 void RooMsgService::deleteStream(Int_t
id)
301 vector<StreamConfig>::iterator iter = _streams.begin() ;
305 if (iter->minLevel==DEBUG) {
309 _streams.erase(iter) ;
317 void RooMsgService::setStreamStatus(Int_t
id, Bool_t flag)
319 if (id<0 || id>=static_cast<Int_t>(_streams.size())) {
320 cout <<
"RooMsgService::setStreamStatus() ERROR: invalid stream ID " <<
id << endl ;
325 if (_streams[
id].minLevel==DEBUG) {
326 _debugCount += flag ? 1 : -1 ;
329 _streams[id].active = flag ;
337 Bool_t RooMsgService::getStreamStatus(Int_t
id)
const
339 if (id<0 || id>= static_cast<Int_t>(_streams.size())) {
340 cout <<
"RooMsgService::getStreamStatus() ERROR: invalid stream ID " <<
id << endl ;
343 return _streams[id].active ;
351 RooMsgService& RooMsgService::instance()
353 static RooMsgService instance;
362 void RooMsgService::saveState()
364 _streamsSaved.push(_streams) ;
372 void RooMsgService::restoreState()
374 _streams = _streamsSaved.top() ;
375 _streamsSaved.pop() ;
383 Bool_t RooMsgService::isActive(
const RooAbsArg*
self, RooFit::MsgTopic topic, RooFit::MsgLevel level)
385 return (activeStream(
self,topic,level)>=0) ;
392 Bool_t RooMsgService::isActive(
const TObject*
self, RooFit::MsgTopic topic, RooFit::MsgLevel level)
394 return (activeStream(
self,topic,level)>=0) ;
401 Int_t RooMsgService::activeStream(
const RooAbsArg*
self, RooFit::MsgTopic topic, RooFit::MsgLevel level)
403 if (level<_globMinLevel)
return -1 ;
404 for (UInt_t i=0 ; i<_streams.size() ; i++) {
405 if (_streams[i].match(level,topic,
self)) {
416 Int_t RooMsgService::activeStream(
const TObject*
self, RooFit::MsgTopic topic, RooFit::MsgLevel level)
418 if (level<_globMinLevel)
return -1 ;
419 for (UInt_t i=0 ; i<_streams.size() ; i++) {
420 if (_streams[i].match(level,topic,
self)) {
431 Bool_t RooMsgService::StreamConfig::match(RooFit::MsgLevel level, RooFit::MsgTopic top,
const RooAbsArg* obj)
433 if (!active)
return kFALSE ;
434 if (level<minLevel)
return kFALSE ;
435 if (!(topic&top))
return kFALSE ;
437 if (universal)
return kTRUE ;
439 if (objectName.size()>0 && objectName != obj->GetName())
return kFALSE ;
440 if (className.size()>0 && className != obj->IsA()->GetName())
return kFALSE ;
441 if (baseClassName.size()>0 && !obj->IsA()->InheritsFrom(baseClassName.c_str()))
return kFALSE ;
442 if (tagName.size()>0 && !obj->getAttribute(tagName.c_str()))
return kFALSE ;
451 Bool_t RooMsgService::StreamConfig::match(RooFit::MsgLevel level, RooFit::MsgTopic top,
const TObject* obj)
453 if (!active)
return kFALSE ;
454 if (level<minLevel)
return kFALSE ;
455 if (!(topic&top))
return kFALSE ;
457 if (universal)
return kTRUE ;
459 if (objectName.size()>0 && objectName != obj->GetName())
return kFALSE ;
460 if (className.size()>0 && className != obj->IsA()->GetName())
return kFALSE ;
461 if (baseClassName.size()>0 && !obj->IsA()->InheritsFrom(baseClassName.c_str()))
return kFALSE ;
472 ostream& RooMsgService::log(
const RooAbsArg*
self, RooFit::MsgLevel level, RooFit::MsgTopic topic, Bool_t skipPrefix)
479 Int_t as = activeStream(
self,topic,level) ;
486 (*_streams[as].os).flush() ;
489 if (_lastMsgLevel==PROGRESS && level!=PROGRESS) {
490 (*_streams[as].os) << endl ;
492 _lastMsgLevel=level ;
494 if (_streams[as].prefix && !skipPrefix) {
496 (*_streams[as].os) <<
"pid" << gSystem->GetPid() <<
" " ;
498 (*_streams[as].os) <<
"[#" << as <<
"] " << _levelNames[level] <<
":" << _topicNames[topic] <<
" -- " ;
500 return (*_streams[as].os) ;
509 ostream& RooMsgService::log(
const TObject*
self, RooFit::MsgLevel level, RooFit::MsgTopic topic, Bool_t skipPrefix)
516 Int_t as = activeStream(
self,topic,level) ;
522 (*_streams[as].os).flush() ;
524 if (_streams[as].prefix && !skipPrefix) {
526 (*_streams[as].os) <<
"pid" << gSystem->GetPid() <<
" " ;
528 (*_streams[as].os) <<
"[#" << as <<
"] " << _levelNames[level] <<
":" << _topicNames[topic] <<
" -- " ;
530 return (*_streams[as].os) ;
539 void RooMsgService::Print(Option_t *options)
const
541 Bool_t activeOnly = kTRUE ;
542 if (TString(options).Contains(
"V") || TString(options).Contains(
"v")) {
543 activeOnly = kFALSE ;
546 cout << (activeOnly?
"Active Message streams":
"All Message streams") << endl ;
547 for (UInt_t i=0 ; i<_streams.size() ; i++) {
550 if (activeOnly && !_streams[i].active) {
555 map<int,string>::const_iterator is = _levelNames.find(_streams[i].minLevel) ;
556 cout <<
"[" << i <<
"] MinLevel = " << is->second ;
558 cout <<
" Topic = " ;
559 if (_streams[i].topic != 0xFFFFF) {
560 map<int,string>::const_iterator iter = _topicNames.begin() ;
561 while(iter!=_topicNames.end()) {
562 if (iter->first & _streams[i].topic) {
563 cout << iter->second <<
" " ;
572 if (_streams[i].objectName.size()>0) {
573 cout <<
" ObjectName = " << _streams[i].objectName ;
575 if (_streams[i].className.size()>0) {
576 cout <<
" ClassName = " << _streams[i].className ;
578 if (_streams[i].baseClassName.size()>0) {
579 cout <<
" BaseClassName = " << _streams[i].baseClassName ;
581 if (_streams[i].tagName.size()>0) {
582 cout <<
" TagLabel = " << _streams[i].tagName ;
586 if (!activeOnly && !_streams[i].active) {
587 cout <<
" (NOT ACTIVE)" ;