Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
ValueChecking.h
Go to the documentation of this file.
1/*
2 * ValueChecking.h
3 *
4 * Created on: 03.08.2020
5 * Author: shageboeck
6 */
7
8#ifndef ROOFIT_ROOFITCORE_INC_VALUECHECKING_H_
9#define ROOFIT_ROOFITCORE_INC_VALUECHECKING_H_
10
11#include <TSystem.h>
12
13#include <exception>
14#include <vector>
15#include <string>
16#include <sstream>
17
18class CachingError : public std::exception {
19 public:
20 CachingError(const std::string& newMessage) :
21 std::exception(),
22 _messages()
23 {
24 _messages.push_back(newMessage);
25 }
26
27 CachingError(CachingError&& previous, const std::string& newMessage) :
28 std::exception(),
29 _messages{std::move(previous._messages)}
30 {
31 _messages.push_back(newMessage);
32 }
33
34 const char* what() const noexcept override {
35 std::stringstream out;
36 out << "**Computation/caching error** in\n";
37
38 std::string indent;
39 for (auto it = _messages.rbegin(); it != _messages.rend(); ++it) {
40 std::string message = *it;
41 auto pos = message.find('\n', 0);
42 while (pos != std::string::npos) {
43 message.insert(pos+1, indent);
44 pos = (message.find('\n', pos+1));
45 }
46
47 out << indent << message << "\n";
48 indent += " ";
49 }
50
51 out << std::endl;
52
53 std::string* ret = new std::string(out.str()); //Make it survive this method
54
55 return ret->c_str();
56 }
57
58
59 private:
60 std::vector<std::string> _messages;
61};
62
63
65 public:
66 template <class T,
67 typename std::enable_if<std::is_base_of<RooAbsArg, T>::value>::type* = nullptr >
68 FormatPdfTree& operator<<(const T& arg) {
69 _stream << arg.ClassName() << "::" << arg.GetName() << " " << &arg << " ";
70 arg.printArgs(_stream);
71 return *this;
72 }
73
74 template <class T,
75 typename std::enable_if< ! std::is_base_of<RooAbsArg, T>::value>::type* = nullptr >
76 FormatPdfTree& operator<<(const T& arg) {
77 _stream << arg;
78 return *this;
79 }
80
81 operator std::string() const {
82 return _stream.str();
83 }
84
85 std::ostream& stream() {
86 return _stream;
87 }
88
89 private:
90 std::ostringstream _stream;
91};
92
93
94
95#endif /* ROOFIT_ROOFITCORE_INC_VALUECHECKING_H_ */
static void indent(ostringstream &buf, int indent_level)
int type
Definition TGX11.cxx:121
const char * what() const noexcept override
CachingError(CachingError &&previous, const std::string &newMessage)
CachingError(const std::string &newMessage)
std::vector< std::string > _messages
std::ostringstream _stream
std::ostream & stream()
FormatPdfTree & operator<<(const T &arg)