[35cdc46] | 1 | //FJSTARTHEADER
|
---|
| 2 | // $Id: Error.cc 3433 2014-07-23 08:17:03Z salam $
|
---|
[d7d2da3] | 3 | //
|
---|
[35cdc46] | 4 | // Copyright (c) 2005-2014, Matteo Cacciari, Gavin P. Salam and Gregory Soyez
|
---|
[d7d2da3] | 5 | //
|
---|
| 6 | //----------------------------------------------------------------------
|
---|
| 7 | // This file is part of FastJet.
|
---|
| 8 | //
|
---|
| 9 | // FastJet is free software; you can redistribute it and/or modify
|
---|
| 10 | // it under the terms of the GNU General Public License as published by
|
---|
| 11 | // the Free Software Foundation; either version 2 of the License, or
|
---|
| 12 | // (at your option) any later version.
|
---|
| 13 | //
|
---|
| 14 | // The algorithms that underlie FastJet have required considerable
|
---|
[35cdc46] | 15 | // development. They are described in the original FastJet paper,
|
---|
| 16 | // hep-ph/0512210 and in the manual, arXiv:1111.6097. If you use
|
---|
[d7d2da3] | 17 | // FastJet as part of work towards a scientific publication, please
|
---|
[35cdc46] | 18 | // quote the version you use and include a citation to the manual and
|
---|
| 19 | // optionally also to hep-ph/0512210.
|
---|
[d7d2da3] | 20 | //
|
---|
| 21 | // FastJet is distributed in the hope that it will be useful,
|
---|
| 22 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 23 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 24 | // GNU General Public License for more details.
|
---|
| 25 | //
|
---|
| 26 | // You should have received a copy of the GNU General Public License
|
---|
| 27 | // along with FastJet. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 28 | //----------------------------------------------------------------------
|
---|
[35cdc46] | 29 | //FJENDHEADER
|
---|
[d7d2da3] | 30 |
|
---|
| 31 | #include "fastjet/Error.hh"
|
---|
| 32 | #include "fastjet/config.h"
|
---|
| 33 | #include <sstream>
|
---|
| 34 |
|
---|
| 35 | // printing the stack would need execinfo
|
---|
| 36 | #ifdef FASTJET_HAVE_EXECINFO_H
|
---|
| 37 | #include <execinfo.h>
|
---|
| 38 | #include <cstdlib>
|
---|
| 39 | #endif
|
---|
| 40 |
|
---|
| 41 | FASTJET_BEGIN_NAMESPACE // defined in fastjet/internal/base.hh
|
---|
| 42 |
|
---|
| 43 | using namespace std;
|
---|
| 44 |
|
---|
| 45 | bool Error::_print_errors = true;
|
---|
| 46 | bool Error::_print_backtrace = false;
|
---|
| 47 | ostream * Error::_default_ostr = & cerr;
|
---|
| 48 |
|
---|
| 49 | Error::Error(const std::string & message_in) {
|
---|
| 50 | _message = message_in;
|
---|
| 51 | if (_print_errors && _default_ostr){
|
---|
| 52 | ostringstream oss;
|
---|
| 53 | oss << "fastjet::Error: "<< message_in << endl;
|
---|
| 54 |
|
---|
| 55 | // only print the stack if execinfo is available and stack enabled
|
---|
| 56 | #ifdef FASTJET_HAVE_EXECINFO_H
|
---|
| 57 | if (_print_backtrace){
|
---|
| 58 | void * array[10];
|
---|
| 59 | char ** messages;
|
---|
| 60 |
|
---|
| 61 | int size = backtrace(array, 10);
|
---|
| 62 | messages = backtrace_symbols(array, size);
|
---|
| 63 |
|
---|
| 64 | oss << "stack:" << endl;
|
---|
| 65 | for (int i = 1; i < size && messages != NULL; ++i){
|
---|
| 66 | oss << " #" << i << ": " << messages[i] << endl;
|
---|
| 67 | }
|
---|
| 68 | free(messages);
|
---|
| 69 | }
|
---|
| 70 | #endif
|
---|
| 71 |
|
---|
| 72 | *_default_ostr << oss.str();
|
---|
| 73 | // get something written to file even
|
---|
| 74 | // if the program aborts
|
---|
| 75 | _default_ostr->flush();
|
---|
| 76 |
|
---|
| 77 | // // output error message either to cerr or to the user-set stream
|
---|
| 78 | // if (_default_ostr) { *_default_ostr << oss.str();
|
---|
| 79 | // // get something written to file even
|
---|
| 80 | // // if the program aborts
|
---|
| 81 | // _default_ostr->flush(); }
|
---|
| 82 | // else { std::cerr << oss.str(); }
|
---|
| 83 |
|
---|
| 84 | }
|
---|
| 85 | }
|
---|
| 86 |
|
---|
| 87 | FASTJET_END_NAMESPACE
|
---|
| 88 |
|
---|