Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RooHelpers.h
Go to the documentation of this file.
1// Author: Stephan Hageboeck, CERN 01/2019
2
3/*****************************************************************************
4 * RooFit
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-2019, 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
17#ifndef ROOFIT_ROOFITCORE_INC_ROOHELPERS_H_
18#define ROOFIT_ROOFITCORE_INC_ROOHELPERS_H_
19
20#include "RooMsgService.h"
21#include "RooAbsArg.h"
22#include "RooAbsReal.h"
23
24#include <sstream>
25#include <vector>
26#include <string>
27#include <utility>
28
29
30namespace RooHelpers {
31
32/// Switches the message service to a different level while the instance is alive.
33/// Can also temporarily activate / deactivate message topics.
34/// Use as
35/// ~~~{.cpp}
36/// RooHelpers::LocalChangeMessageLevel changeMsgLvl(RooFit::WARNING);
37/// [ statements that normally generate a lot of output ]
38/// ~~~
40 public:
41 /// Change message level (and topics) while this object is alive, reset when it goes out of scope.
42 /// \param[in] lvl The desired message level. Defaults to verbose.
43 /// \param[in] extraTopics Extra topics to be switched on. These will only switched on in the last stream to prevent all streams are printing.
44 /// \param[in] removeTopics Message topics to be switched off
45 /// \param[in] overrideExternalLevel Override the user message level.
47 unsigned int extraTopics = 0u,
48 unsigned int removeTopics = 0u,
49 bool overrideExternalLevel = true);
50
52
53 private:
55 std::vector<RooMsgService::StreamConfig> fOldConf;
56 int fExtraStream{-1};
57};
58
59
60/// Wrap an object into a TObject. Sometimes needed to avoid reinterpret_cast or enable RTTI.
61template<typename T>
62struct WrapIntoTObject : public TObject {
63 WrapIntoTObject(T& obj) : _payload(&obj) { }
65};
66
67
68/// Hijacks all messages with given level and topic (and optionally object name) while alive.
69/// Use this like an ostringstream afterwards. The messages can e.g. be retrieved using `str()`.
70/// Useful for unit tests / debugging.
72 public:
73 HijackMessageStream(RooFit::MsgLevel level, RooFit::MsgTopic topics, const char* objectName = nullptr);
74 template<typename T>
75 const HijackMessageStream& operator<<(const T& v) const {
76 _str << v;
77 return *this;
78 }
79 std::string str() { return _str.str(); }
80 std::ostringstream& stream() { return _str; };
82
83 private:
84 std::ostringstream _str;
86 std::vector<RooMsgService::StreamConfig> _oldConf;
88};
89
90
91std::vector<std::string> tokenise(const std::string &str, const std::string &delims, bool returnEmptyToken = true);
92
93
94/// Check if the parameters have a range, and warn if the range extends below / above the set limits.
95void checkRangeOfParameters(const RooAbsReal* callingClass, std::initializer_list<const RooAbsReal*> pars,
96 double min = -std::numeric_limits<double>::max(), double max = std::numeric_limits<double>::max(),
97 bool limitsInAllowedRange = false, std::string extraMessage = "");
98
99
100/// Disable all caches for sub-branches in an expression tree.
101/// This is helpful when an expression with cached sub-branches needs to be integrated numerically.
103 /// Inhibit all dirty-state propagation, and assume every node as dirty.
104 /// \param[in] oldState Restore this state when going out of scope.
105 DisableCachingRAII(bool oldState):
106 _oldState(oldState) {
108 }
109
112 }
114};
115
116
117std::pair<double, double> getRangeOrBinningInterval(RooAbsArg const* arg, const char* rangeName);
118
119
120}
121
122
123
124#endif /* ROOFIT_ROOFITCORE_INC_ROOHELPERS_H_ */
RooAbsArg is the common abstract base class for objects that represent a value and a "shape" in RooFi...
Definition RooAbsArg.h:72
static void setDirtyInhibit(Bool_t flag)
Control global dirty inhibit mode.
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
Definition RooAbsReal.h:61
Hijacks all messages with given level and topic (and optionally object name) while alive.
Definition RooHelpers.h:71
std::ostringstream & stream()
Definition RooHelpers.h:80
RooFit::MsgLevel _oldKillBelow
Definition RooHelpers.h:85
std::vector< RooMsgService::StreamConfig > _oldConf
Definition RooHelpers.h:86
const HijackMessageStream & operator<<(const T &v) const
Definition RooHelpers.h:75
Switches the message service to a different level while the instance is alive.
Definition RooHelpers.h:39
RooFit::MsgLevel fOldKillBelow
Definition RooHelpers.h:54
std::vector< RooMsgService::StreamConfig > fOldConf
Definition RooHelpers.h:55
Mother of all ROOT objects.
Definition TObject.h:37
MsgLevel
Verbosity level for RooMsgService::StreamConfig in RooMsgService.
MsgTopic
Topics for a RooMsgService::StreamConfig in RooMsgService.
std::vector< std::string > tokenise(const std::string &str, const std::string &delims, bool returnEmptyToken=true)
Tokenise the string by splitting at the characters in delims.
void checkRangeOfParameters(const RooAbsReal *callingClass, std::initializer_list< const RooAbsReal * > pars, double min=-std::numeric_limits< double >::max(), double max=std::numeric_limits< double >::max(), bool limitsInAllowedRange=false, std::string extraMessage="")
Check if the parameters have a range, and warn if the range extends below / above the set limits.
std::pair< double, double > getRangeOrBinningInterval(RooAbsArg const *arg, const char *rangeName)
Get the lower and upper bound of parameter range if arg can be casted to RooAbsRealLValue.
Disable all caches for sub-branches in an expression tree.
Definition RooHelpers.h:102
DisableCachingRAII(bool oldState)
Inhibit all dirty-state propagation, and assume every node as dirty.
Definition RooHelpers.h:105
Wrap an object into a TObject. Sometimes needed to avoid reinterpret_cast or enable RTTI.
Definition RooHelpers.h:62