LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
GFException.h
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 */
23 #ifndef GFEXCEPTION_H
24 #define GFEXCEPTION_H
25 
26 #include <exception>
27 #include <stdexcept>
28 #include <string>
29 #include <vector>
30 #include <iostream>
31 #include <sstream>
32 #include <ios> // std::ios::fmtflags
33 #include <iomanip> // std::setw()
34 
35 #include "TObject.h"
36 #include "TMatrixT.h"
37 #include "TVector3.h"
38 
51 {
52  private:
53 
54  static bool fQuiet;
55 
56  std::string fExcString;
57  int fLine;
58  std::string fFile;
59 
60  std::string fNumbersLabel;
61  std::string fMatricesLabel;
62  std::vector<double> fNumbers;
63  std::vector< TMatrixT<Double_t> > fMatrices;
64 
65  bool fFatal;
66 
67  public:
76  GFException(std::string, int, std::string);
77  virtual ~GFException() throw();
78 
80  GFException& setFatal (bool b = true) { fFatal=b; return *this; }
82  bool isFatal (){return fFatal;}
84  GFException& setNumbers (std::string, const std::vector<double>&);
86  GFException& setMatrices(std::string, const std::vector< TMatrixT<Double_t> >&);
87 
89  void info();
90 
92  virtual const char* what() const throw();
93 
94  std::string getExcString(){return fExcString;}
95 
96  static void quiet(bool b=true){fQuiet=b;}
97 
98 };
99 
100 
101 namespace genf {
102 //------------------------------------------------------------------------------
104 template <class ROOTOBJ>
106 void PrintROOTobject(std::ostream&, const ROOTOBJ&);
107 
108 template <>
109 void PrintROOTobject(std::ostream&, const TVector3& v);
110 
111 template <typename T>
112 void PrintROOTmatrix(std::ostream& out, const TMatrixT<T>& m);
114 
115 
117 template <class ROOTOBJ>
118 std::string ROOTobjectToString(const ROOTOBJ& obj)
119  { std::ostringstream sstr; PrintROOTobject(sstr, obj); return sstr.str(); }
120 
121 
122 } // namespace genf
123 
124 
125 //------------------------------------------------------------------------------
126 // template definitions
127 //
128 template <class ROOTOBJ>
129 void genf::PrintROOTobject(std::ostream&, const ROOTOBJ& obj) { obj.Print(); }
130 
131 template <typename T>
132 void genf::PrintROOTmatrix(std::ostream& out, const TMatrixT<T>& m) {
133 
134  constexpr std::streamsize fw = 11;
135  constexpr std::streamsize ifw = 4 + (fw & 1);
136  const Int_t rb = m.GetRowLwb(), cb = m.GetColLwb();
137 
138  const Int_t R = m.GetNrows(), C = m.GetNcols();
139  out << R << "x" << C << " matrix is as follows";
140 
141  std::streamsize swidth = out.width(4);
142  std::ios::fmtflags sflags = out.flags();
143  out.unsetf(std::ios_base::floatfield); // out << std::defaultfloat;
144 
145  // header: column number
146  std::string index_pad((fw-ifw)/2, ' ');
147  out << "\n" << std::string(ifw, ' ') << " |";
148  for (Int_t c = 0; c < C; ++c)
149  out << index_pad << std::setw(ifw) << (cb + c) << index_pad << "|";
150 
151  // dashed line
152  out << "\n" << std::string((C+1) * (fw+1), '-');
153 
154  // content, row by row
155  for (Int_t r = 0; r < R; ++r) {
156  // header: row number
157  out << "\n" << std::setw(ifw) << (rb + r) << " |";
158  for (Int_t c = 0; c < C; ++c) out << std::setw(fw) << m(rb + r, cb + c) << " ";
159  } // for r
160  out << "\n\n";
161 
162  // restore the stream features
163  out.flags(sflags);
164  out.width(swidth);
165 } // genf::PrintROOTmatrix<TMatrixT<T>>()
166 
167 
168 #endif
169 
GFException & setNumbers(std::string, const std::vector< double > &)
set list of numbers with description
Definition: GFException.cxx:32
std::string fNumbersLabel
Definition: GFException.h:60
std::vector< TMatrixT< Double_t > > fMatrices
Definition: GFException.h:63
Generic Interface to magnetic fields in GENFIT.
void PrintROOTmatrix(std::ostream &out, const TMatrixT< T > &m)
Small utility functions which print some ROOT objects into an output stream.
Definition: GFException.h:132
virtual const char * what() const
standard error message handling for exceptions. use like "std::cerr << e.what();" ...
Definition: GFException.cxx:46
std::string fMatricesLabel
Definition: GFException.h:61
static void quiet(bool b=true)
Definition: GFException.h:96
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:265
void PrintROOTobject(std::ostream &, const TVector3 &v)
Small utility functions which print some ROOT objects into an output stream.
Definition: GFException.cxx:86
bool isFatal()
get fatal flag.
Definition: GFException.h:82
Double_t R
std::string fFile
Definition: GFException.h:58
std::string getExcString()
Definition: GFException.h:94
GFException & setMatrices(std::string, const std::vector< TMatrixT< Double_t > > &)
set list of matrices with description
Definition: GFException.cxx:39
std::string ROOTobjectToString(const ROOTOBJ &obj)
Shortcut to write one ROOT object into a string.
Definition: GFException.h:118
void info()
print information in the exception object
Definition: GFException.cxx:56
Exception class for error handling in GENFIT (provides storage for diagnostic information) ...
Definition: GFException.h:50
GFException(std::string, int, std::string)
Initializing constructor.
Definition: GFException.cxx:26
std::vector< double > fNumbers
Definition: GFException.h:62
virtual ~GFException()
Definition: GFException.cxx:29
void PrintROOTobject(std::ostream &, const ROOTOBJ &)
Small utility functions which print some ROOT objects into an output stream.
Definition: GFException.h:129
GFException & setFatal(bool b=true)
set fatal flag. if this is true, the fit stops for this current track repr.
Definition: GFException.h:80
std::string fExcString
Definition: GFException.h:56
static bool fQuiet
Definition: GFException.h:54
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33