Changeset 49234af in git for external/fastjet/Error.cc
- Timestamp:
- Dec 9, 2014, 1:27:13 PM (10 years ago)
- Branches:
- ImprovedOutputFile, Timing, dual_readout, llp, master
- Children:
- 37deb3b, 9e991f8
- Parents:
- f6b6ee7 (diff), e7e90df (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
external/fastjet/Error.cc
rf6b6ee7 r49234af 1 // STARTHEADER2 // $Id $1 //FJSTARTHEADER 2 // $Id: Error.cc 3695 2014-09-18 13:57:56Z cacciari $ 3 3 // 4 // Copyright (c) 2005-201 1, Matteo Cacciari, Gavin P. Salam and Gregory Soyez4 // Copyright (c) 2005-2014, Matteo Cacciari, Gavin P. Salam and Gregory Soyez 5 5 // 6 6 //---------------------------------------------------------------------- … … 13 13 // 14 14 // The algorithms that underlie FastJet have required considerable 15 // development and are described in hep-ph/0512210. If you use 15 // development. They are described in the original FastJet paper, 16 // hep-ph/0512210 and in the manual, arXiv:1111.6097. If you use 16 17 // FastJet as part of work towards a scientific publication, please 17 // include a citation to the FastJet paper. 18 // quote the version you use and include a citation to the manual and 19 // optionally also to hep-ph/0512210. 18 20 // 19 21 // FastJet is distributed in the hope that it will be useful, … … 25 27 // along with FastJet. If not, see <http://www.gnu.org/licenses/>. 26 28 //---------------------------------------------------------------------- 27 // ENDHEADER29 //FJENDHEADER 28 30 29 31 #include "fastjet/Error.hh" … … 31 33 #include <sstream> 32 34 35 #ifndef __FJCORE__ 33 36 // printing the stack would need execinfo 34 37 #ifdef FASTJET_HAVE_EXECINFO_H 35 38 #include <execinfo.h> 36 39 #include <cstdlib> 37 #endif 40 #ifdef FASTJET_HAVE_DEMANGLING_SUPPORT 41 #include <cstdio> 42 #include <cxxabi.h> 43 #endif // FASTJET_HAVE_DEMANGLING_SUPPORT 44 #endif // FASTJET_HAVE_EXECINFO_H 45 #endif // __FJCORE__ 38 46 39 47 FASTJET_BEGIN_NAMESPACE // defined in fastjet/internal/base.hh … … 44 52 bool Error::_print_backtrace = false; 45 53 ostream * Error::_default_ostr = & cerr; 54 #if (!defined(FASTJET_HAVE_EXECINFO_H)) || defined(__FJCORE__) 55 LimitedWarning Error::_execinfo_undefined; 56 #endif 46 57 58 //---------------------------------------------------------------------- 59 #ifndef __FJCORE__ 60 61 // demangling only is included, i.e. --enable-demangling is specified 62 // at configure time, execinfo.h is present and the GNU C++ ABI is 63 // supported 64 #if defined(FASTJET_HAVE_EXECINFO_H) && defined(FASTJET_HAVE_DEMANGLING_SUPPORT) 65 // demangle a given backtrace symbol 66 // 67 // Notes: 68 // - at the moment, only the symbol is parsed. 69 // - one can get the offset by using 70 // "%*[^(]%*[^_]%127[^+)]%64[+x0123456789abcdef]", symbol, offset 71 // and checking if sscanf returns 0, 1 or 2 72 // (offset includes the leading +) 73 // - Similarly one could exctract the address and try to convert it 74 // into a filename+line number like addr2line does but this seems 75 // to require exteral dependencies. If we want to go down that 76 // route, one could look into the inplementation o faddr2line(.c) 77 // and/or dladdr. 78 string Error::_demangle(const char* symbol) { 79 size_t size; 80 int status; 81 char temp[128]; 82 char* demangled; 83 // first, try to demangle a c++ name 84 // decryption: 85 // %*[^(] matches any number of characters different from "(" 86 // the * tells not to store in input var 87 // %*[^_] matches any number of characters different from "_" 88 // the * tells not to store in input var 89 // %127[^)+] matches at most 127 characters different from "+" 90 // match is stored 91 if (1 == sscanf(symbol, "%*[^(]%*[^_]%127[^)+]", temp)) { 92 //cout << symbol << " -> " << temp << endl; 93 if (NULL != (demangled = abi::__cxa_demangle(temp, NULL, &size, &status))) { 94 string result(demangled); 95 free(demangled); 96 return result; 97 } 98 } 99 //if that didn't work, try to get a regular c symbol 100 if (1 == sscanf(symbol, "%127s", temp)) { 101 return temp; 102 } 103 104 //if all else fails, just return the symbol 105 return symbol; 106 } 107 #endif // FASTJET_HAVE_DEMANGLING_SUPPORT && FASTJET_HAVE_EXECINFO_H 108 #endif // __FJCORE__ 109 110 111 //---------------------------------------------------------------------- 47 112 Error::Error(const std::string & message_in) { 48 113 _message = message_in; 114 49 115 if (_print_errors && _default_ostr){ 50 116 ostringstream oss; 51 117 oss << "fastjet::Error: "<< message_in << endl; 52 118 119 #ifndef __FJCORE__ 53 120 // only print the stack if execinfo is available and stack enabled 54 121 #ifdef FASTJET_HAVE_EXECINFO_H … … 62 129 oss << "stack:" << endl; 63 130 for (int i = 1; i < size && messages != NULL; ++i){ 131 #ifdef FASTJET_HAVE_DEMANGLING_SUPPORT 132 oss << " #" << i << ": " << _demangle(messages[i]) 133 << " [" << messages[i] << "]" << endl; 134 #else 64 135 oss << " #" << i << ": " << messages[i] << endl; 136 #endif 65 137 } 66 138 free(messages); 67 139 } 68 #endif 140 #endif // FASTJET_HAVE_EXECINFO_H 141 #endif // __FJCORE__ 69 142 70 143 *_default_ostr << oss.str(); … … 83 156 } 84 157 158 //---------------------------------------------------------------------- 159 void Error::set_print_backtrace(bool enabled) { 160 #if (!defined(FASTJET_HAVE_EXECINFO_H)) || defined(__FJCORE__) 161 if (enabled) { 162 _execinfo_undefined.warn("Error::set_print_backtrace(true) will not work with this build of FastJet"); 163 } 164 #endif 165 _print_backtrace = enabled; 166 } 167 85 168 FASTJET_END_NAMESPACE 86 169
Note:
See TracChangeset
for help on using the changeset viewer.