LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
GFException.cxx
Go to the documentation of this file.
1 /* Copyright 2008-2010, Technische Universitaet Muenchen,
2  Authors: Christian Hoeppner & Sebastian Neubert
3 
4  This file is part of GENFIT.
5 
6  GENFIT is free software: you can redistribute it and/or modify
7  it under the terms of the GNU Lesser General Public License as published
8  by the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  GENFIT is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU Lesser General Public License for more details.
15 
16  You should have received a copy of the GNU Lesser General Public License
17  along with GENFIT. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #include "GFException.h"
21 
22 #include "TMath.h"
23 
24 #include <iostream>
25 
26 bool GFException::fQuiet = false;
27 
28 GFException::GFException(std::string _excString, int _line, std::string _file)
29  : fExcString(_excString), fLine(_line), fFile(_file), fFatal(false)
30 {
31  std::ostringstream returnStream;
32  returnStream << "GFException thrown with excString:\n"
33  << fExcString << "\nin line: " << fLine << " in file: " << fFile
34  << "\nwith fatal flag " << fFatal << '\n';
35  fExcString = returnStream.str();
36 }
37 
39 
40 GFException& GFException::setNumbers(std::string _numbersLabel, const std::vector<double>& _numbers)
41 {
42  fNumbersLabel = _numbersLabel;
43  fNumbers = _numbers;
44  return *this;
45 }
46 
47 GFException& GFException::setMatrices(std::string _matricesLabel,
48  const std::vector<TMatrixT<Double_t>>& _matrices)
49 {
50  fMatricesLabel = _matricesLabel;
51  fMatrices = _matrices;
52  return *this;
53 }
54 
55 const char* GFException::what() const noexcept
56 {
57  if (fQuiet) return "";
58  return fExcString.c_str();
59 }
60 
62 {
63  if (fQuiet) return;
64  if (fNumbers.size() == 0 && fMatrices.size() == 0) return; //do nothing
65  std::cout << "GFException Info Output" << std::endl;
66  std::cout << "===========================" << std::endl;
67  if (fNumbersLabel != "") {
68  std::cout << "Numbers Label String:" << std::endl;
69  std::cout << fNumbersLabel << std::endl;
70  }
71  if (fNumbers.size() > 0) {
72  std::cout << "---------------------------" << std::endl;
73  std::cout << "Numbers:" << std::endl;
74  for (unsigned int i = 0; i < fNumbers.size(); i++)
75  std::cout << fNumbers.at(i) << std::endl;
76  }
77  if (fMatricesLabel != "") {
78  std::cout << "---------------------------" << std::endl;
79  std::cout << "Matrices Label String:" << std::endl;
80  std::cout << fMatricesLabel << std::endl;
81  }
82  if (fMatrices.size() > 0) {
83  std::cout << "---------------------------" << std::endl;
84  std::cout << "Matrices:" << std::endl;
85  for (unsigned int i = 0; i < fMatrices.size(); i++)
86  fMatrices.at(i).Print();
87  }
88  std::cout << "===========================" << std::endl;
89 }
90 
91 //------------------------------------------------------------------------------
92 template <>
93 void genf::PrintROOTobject(std::ostream& out, const TVector3& v)
94 {
95  out << "(x,y,z)=(" << v.X() << "," << v.Y() << "," << v.Z()
96  << ")"
97  " (rho,theta,phi)=("
98  << v.Mag() << "," << (v.Theta() * TMath::RadToDeg()) << "," << (v.Phi() * TMath::RadToDeg())
99  << ")";
100 } // genf::PrintROOTobject<TVector3>()
GFException & setNumbers(std::string, const std::vector< double > &)
set list of numbers with description
Definition: GFException.cxx:40
std::string fNumbersLabel
Definition: GFException.h:55
std::string fMatricesLabel
Definition: GFException.h:56
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:289
std::string fFile
Definition: GFException.h:53
void info()
print information in the exception object
Definition: GFException.cxx:61
const char * what() const noexcept override
standard error message handling for exceptions. use like "std::cerr << e.what();" ...
Definition: GFException.cxx:55
GFException & setMatrices(std::string, const std::vector< TMatrixT< Double_t >> &)
set list of matrices with description
Definition: GFException.cxx:47
Exception class for error handling in GENFIT (provides storage for diagnostic information) ...
Definition: GFException.h:47
GFException(std::string, int, std::string)
Initializing constructor.
Definition: GFException.cxx:28
std::vector< double > fNumbers
Definition: GFException.h:57
virtual ~GFException()
Definition: GFException.cxx:38
void PrintROOTobject(std::ostream &, const ROOTOBJ &)
Small utility functions which print some ROOT objects into an output stream.
Definition: GFException.h:127
std::string fExcString
Definition: GFException.h:51
static bool fQuiet
Definition: GFException.h:49
std::vector< TMatrixT< Double_t > > fMatrices
Definition: GFException.h:58