Logo ROOT  
Reference Guide
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 
18 class 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_ */
FormatPdfTree::operator<<
FormatPdfTree & operator<<(const T &arg)
Definition: ValueChecking.h:68
indent
static void indent(ostringstream &buf, int indent_level)
Definition: TClingCallFunc.cxx:87
CachingError
Definition: ValueChecking.h:18
FormatPdfTree::_stream
std::ostringstream _stream
Definition: ValueChecking.h:90
TSystem.h
FormatPdfTree
Definition: ValueChecking.h:64
FormatPdfTree::stream
std::ostream & stream()
Definition: ValueChecking.h:85
CachingError::_messages
std::vector< std::string > _messages
Definition: ValueChecking.h:60
CachingError::CachingError
CachingError(const std::string &newMessage)
Definition: ValueChecking.h:20
CachingError::what
const char * what() const noexcept override
Definition: ValueChecking.h:34
ROOT::Math::Chebyshev::T
double T(double x)
Definition: ChebyshevPol.h:34
type
int type
Definition: TGX11.cxx:121
CachingError::CachingError
CachingError(CachingError &&previous, const std::string &newMessage)
Definition: ValueChecking.h:27