GooFit  v2.1.3
Abort.cpp
Go to the documentation of this file.
1 #include <goofit/Color.h>
2 #include <goofit/Error.h>
3 #include <goofit/PdfBase.h>
4 #include <goofit/detail/Abort.h>
5 #include <goofit/detail/Backtrace.h>
6 
7 namespace GooFit {
8 
9 void abort(std::string file, int line, std::string reason, const PdfBase *pdf) {
10  void *stackarray[20];
11 
12  std::cout << GooFit::reset << GooFit::red << "Abort called from " << file << " line " << line << " due to "
13  << reason << std::endl;
14 
15  if(pdf) {
16  std::vector<Variable> pars = pdf->getParameters();
17  std::cout << "Parameters of " << pdf->getName() << " : \n";
18 
19  for(const Variable &v : pars) {
20  if(0 > v.getIndex())
21  continue;
22 
23  std::cout << " " << v.getName() << " (" << v.getIndex() << ") :\t" << host_params[v.getIndex()]
24  << std::endl;
25  }
26  }
27 
28  std::cout << "Parameters (" << totalParams << ") :\n";
29 
30  for(int i = 0; i < totalParams; ++i) {
31  std::cout << host_params[i] << " ";
32  }
33 
34 #if Backtrace_FOUND
35  std::cout << GooFit::bold << std::endl;
36  // get void* pointers for all entries on the stack
37  int size = backtrace(stackarray, 20);
38  // print out all the frames to stderr
39  backtrace_symbols_fd(stackarray, size, 2);
40 #endif
41 
42  std::cout << GooFit::reset << std::flush;
43 
44  throw GooFit::GeneralError(reason);
45 }
46 
47 } // namespace GooFit
Thrown when a general error is encountered.
Definition: Error.h:10
void abort(std::string file, int line, std::string reason, const PdfBase *pdf=nullptr)
Smart abort that includes the file name and location, and prints a stack trace if possible...
Definition: Abort.cpp:9
constexpr rang::style const bold
Definition: Color.h:17
constexpr rang::fg const red
Definition: Color.h:9
constexpr rang::style const reset
Definition: Color.h:16
int totalParams
Definition: PdfBase.cpp:34
__host__ std::string getName() const
Definition: PdfBase.h:93
fptype host_params[maxParams]
Definition: PdfBase.cpp:30
virtual __host__ std::vector< Variable > getParameters() const
Definition: PdfBase.cpp:81