18 #include "Cintex/Cintex.h"
20 #include "Reflex/Type.h"
26 #include "TUnixSystem.h"
31 void RootErrorHandlerImpl(
int level,
char const* location,
char const*
message,
bool ignoreWarnings) {
39 if (level >= kFatal) {
41 }
else if (level >= kSysError) {
43 }
else if (level >=
kError) {
52 std::string el_location =
"@SUB=?";
53 if (location != 0) el_location = std::string(
"@SUB=")+std::string(location);
55 std::string el_message =
"?";
56 if (message != 0) el_message =
message;
64 std::string el_identifier =
"ROOT";
66 std::string precursor(
"class ");
67 size_t index1 = el_message.find(precursor);
68 if (index1 != std::string::npos) {
69 size_t index2 = index1 + precursor.length();
70 size_t index3 = el_message.find_first_of(
" :", index2);
71 if (index3 != std::string::npos) {
72 size_t substrlen = index3-index2;
74 el_identifier += el_message.substr(index2,substrlen);
77 index1 = el_location.find(
"::");
78 if (index1 != std::string::npos) {
80 el_identifier += el_location.substr(0, index1);
86 if ((el_location.find(
"TBranchElement::Fill") != std::string::npos)
87 && (el_message.find(
"fill branch") != std::string::npos)
88 && (el_message.find(
"address") != std::string::npos)
89 && (el_message.find(
"not set") != std::string::npos)) {
93 if ((el_message.find(
"Tree branches") != std::string::npos)
94 && (el_message.find(
"different numbers of entries") != std::string::npos)) {
101 if ((el_message.find(
"no dictionary for class") != std::string::npos) ||
102 (el_message.find(
"already in TClassTable") != std::string::npos) ||
103 (el_message.find(
"matrix not positive definite") != std::string::npos) ||
104 (el_message.find(
"not a TStreamerInfo object") != std::string::npos) ||
105 (el_location.find(
"Fit") != std::string::npos) ||
106 (el_location.find(
"TDecompChol::Solve") != std::string::npos) ||
107 (el_location.find(
"THistPainter::PaintInit") != std::string::npos) ||
108 (el_location.find(
"TUnixSystem::SetDisplay") != std::string::npos) ||
109 (el_location.find(
"TGClient::GetFontByName") != std::string::npos)) {
125 if (die && (el_location != std::string(
"@SUB=TUnixSystem::DispatchSignals"))) {
126 std::ostringstream sstr;
127 sstr <<
"Fatal Root Error: " << el_location <<
"\n" << el_message <<
'\n';
144 edm::LogInfo(
"Root_Information") << el_location << el_message ;
148 void RootErrorHandler(
int level,
bool,
char const* location,
char const* message) {
149 RootErrorHandlerImpl(level, location, message,
false);
152 void RootErrorHandlerWithoutWarnings(
int level,
bool,
char const* location,
char const* message) {
153 RootErrorHandlerImpl(level, location, message,
true);
157 void sig_dostack_then_abort(
int sig,siginfo_t*,
void*) {
159 const char* signalname =
"unknown";
162 signalname =
"bus error";
165 signalname =
"segmentation violation";
168 signalname =
"illegal instruction";
172 edm::LogError(
"FatalSystemSignal")<<
"A fatal system signal has occurred: "<<signalname;
173 std::cerr<<
"\n\nA fatal system signal has occurred: "<<signalname<<
"\n"
174 <<
"The following is the call stack containing the origin of the signal.\n"
175 <<
"NOTE:The first few functions on the stack are artifacts of processing the signal and can be ignored\n\n";
177 gSystem->StackTrace();
178 std::cerr<<
"\nA fatal system signal has occurred: "<<signalname<<
"\n";
189 unloadSigHandler_(pset.getUntrackedParameter<bool> (
"UnloadRootSigHandler")),
190 resetErrHandler_(pset.getUntrackedParameter<bool> (
"ResetRootErrHandler")),
191 autoLibraryLoader_(pset.getUntrackedParameter<bool> (
"AutoLibraryLoader")) {
195 gSystem->ResetSignal(kSigChild);
196 gSystem->ResetSignal(kSigBus);
197 gSystem->ResetSignal(kSigSegmentationViolation);
198 gSystem->ResetSignal(kSigIllegalInstruction);
199 gSystem->ResetSignal(kSigSystem);
200 gSystem->ResetSignal(kSigPipe);
201 gSystem->ResetSignal(kSigAlarm);
202 gSystem->ResetSignal(kSigUrgent);
203 gSystem->ResetSignal(kSigFloatingException);
204 gSystem->ResetSignal(kSigWindowChanged);
208 gSystem->ResetSignal(kSigBus);
209 gSystem->ResetSignal(kSigSegmentationViolation);
210 gSystem->ResetSignal(kSigIllegalInstruction);
219 SetErrorHandler(RootErrorHandler);
228 ROOT::Cintex::Cintex::Enable();
231 TTree::SetMaxTreeSize(kMaxLong64);
232 TH1::AddDirectory(kFALSE);
233 G__SetCatchException(0);
240 if (
ROOT::Reflex::Type()== Reflex::Type::ByName(
"std::vector<std::vector<unsigned int> >")) {
249 while(gROOT->GetListOfFiles()->GetSize()) {
250 TIter iter(gROOT->GetListOfFiles());
251 TFile*
f =
dynamic_cast<TFile*
>(iter.Next());
258 desc.
setComment(
"Centralized interface to ROOT.");
260 ->setComment(
"If True, signals are handled by this service, rather than by ROOT.");
262 ->setComment(
"If True, ROOT messages (e.g. errors, warnings) are handled by this service, rather than by ROOT.");
264 ->setComment(
"If True, enables automatic loading of data dictionaries.");
266 ->setComment(
"If True, do an abort when a signal occurs that causes a crash. If False, ROOT will do an exit which attempts to do a clean shutdown.");
267 descriptions.
add(
"InitRootHandlers", desc);
272 SetErrorHandler(DefaultErrorHandler);
277 SetErrorHandler(RootErrorHandler);
282 SetErrorHandler(RootErrorHandlerWithoutWarnings);
T getUntrackedParameter(std::string const &, T const &) const
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
virtual void enableErrorHandlerWithoutWarnings_()
void setRefCoreStreamer(bool resetAll=false)
void installCustomHandler(int signum, CFUNC func)
void setComment(std::string const &value)
static PluginCapabilities * get()
virtual void disableErrorHandler_()
InitRootHandlers(ParameterSet const &pset)
virtual ~InitRootHandlers()
void add(std::string const &label, ParameterSetDescription const &psetDescription)
void setStreamedProductStreamer()
virtual void enableErrorHandler_()
static void fillDescriptions(ConfigurationDescriptions &descriptions)
void load(const std::string &iName)
static void enable()
interface for TClass generators