17 #ifndef ROOFIT_ROOFITCORE_INC_ROOHELPERS_H_
18 #define ROOFIT_ROOFITCORE_INC_ROOHELPERS_H_
26 namespace RooHelpers {
29 class LocalChangeMsgLevel {
34 LocalChangeMsgLevel(RooFit::MsgLevel lvl = RooFit::DEBUG,
35 RooFit::MsgTopic extraTopics = static_cast<RooFit::MsgTopic>(0u)) {
36 auto& msg = RooMsgService::instance();
37 fOldKillBelow = msg.globalKillBelow();
38 msg.setGlobalKillBelow(lvl);
39 fOldConf = msg.getStream(0);
40 msg.getStream(0).minLevel = lvl;
41 msg.getStream(0).addTopic(extraTopics);
42 msg.setStreamStatus(0,
true);
45 ~LocalChangeMsgLevel() {
46 auto& msg = RooMsgService::instance();
47 msg.setGlobalKillBelow(fOldKillBelow);
48 msg.getStream(0) = fOldConf;
52 RooFit::MsgLevel fOldKillBelow;
53 RooMsgService::StreamConfig fOldConf;
59 class HijackMessageStream :
public std::ostringstream {
61 HijackMessageStream(RooFit::MsgLevel level, RooFit::MsgTopic topics,
const char* objectName =
nullptr);
63 virtual ~HijackMessageStream();
66 RooFit::MsgLevel _oldKillBelow;
67 std::vector<RooMsgService::StreamConfig> _oldConf;
72 std::vector<std::string> tokenise(
const std::string &str,
const std::string &delims);
76 class CachingError :
public std::exception {
78 CachingError(
const std::string& newMessage) :
82 _messages.push_back(newMessage);
85 CachingError(CachingError&& previous,
const std::string& newMessage) :
87 _messages{std::move(previous._messages)}
89 _messages.push_back(newMessage);
92 const char* what() const noexcept
override {
93 std::stringstream out;
94 out <<
"**Caching Error** in\n";
97 for (
auto it = _messages.rbegin(); it != _messages.rend(); ++it) {
98 std::string message = *it;
99 auto pos = message.find(
'\n', 0);
100 while (pos != std::string::npos) {
101 message.insert(pos+1, indent);
102 pos = (message.find(
'\n', pos+1));
105 out << indent << message <<
"\n";
111 std::string* ret =
new std::string(out.str());
118 std::vector<std::string> _messages;
122 class FormatPdfTree {
125 typename std::enable_if<std::is_base_of<RooAbsArg, T>::value>::type* =
nullptr >
126 FormatPdfTree& operator<<(
const T& arg) {
127 _stream << arg.ClassName() <<
"::" << arg.GetName() <<
" " << &arg <<
" ";
128 arg.printArgs(_stream);
133 typename std::enable_if< ! std::is_base_of<RooAbsArg, T>::value>::type* =
nullptr >
134 FormatPdfTree& operator<<(
const T& arg) {
139 operator std::string()
const {
140 return _stream.str();
143 std::ostream& stream() {
148 std::ostringstream _stream;
153 void checkRangeOfParameters(
const RooAbsReal* callingClass, std::initializer_list<const RooAbsReal*> pars,
154 double min = -std::numeric_limits<double>::max(),
double max = std::numeric_limits<double>::max(),
155 bool limitsInAllowedRange =
false, std::string extraMessage =
"");
159 class BatchInterfaceAccessor {
161 static void clearBatchMemory(RooAbsReal& theReal) {
162 theReal.clearBatchMemory();
165 static void checkBatchComputation(
const RooAbsReal& theReal, std::size_t evtNo,
166 const RooArgSet* normSet =
nullptr,
double relAccuracy = 1.E-13) {
167 theReal.checkBatchComputation(evtNo, normSet, relAccuracy);