23 #include "TInterpreter.h"
26 #include "TUnixSystem.h"
28 #include "TVirtualStreamerInfo.h"
31 #include "TClassTable.h"
48 static thread_local
bool s_ignoreWarnings =
false;
50 static bool s_ignoreEverything =
false;
52 void RootErrorHandlerImpl(
int level,
char const* location,
char const*
message) {
60 if (level >= kFatal) {
61 el_severity = SeverityLevel::kFatal;
62 }
else if (level >= kSysError) {
63 el_severity = SeverityLevel::kSysError;
64 }
else if (level >=
kError) {
70 if(s_ignoreEverything) {
81 if (message != 0) el_message =
message;
92 size_t index1 = el_message.find(precursor);
93 if (index1 != std::string::npos) {
94 size_t index2 = index1 + precursor.length();
95 size_t index3 = el_message.find_first_of(
" :", index2);
96 if (index3 != std::string::npos) {
97 size_t substrlen = index3-index2;
99 el_identifier += el_message.substr(index2,substrlen);
102 index1 = el_location.find(
"::");
103 if (index1 != std::string::npos) {
104 el_identifier +=
"/";
105 el_identifier += el_location.substr(0, index1);
111 if ((el_location.find(
"TBranchElement::Fill") != std::string::npos)
112 && (el_message.find(
"fill branch") != std::string::npos)
113 && (el_message.find(
"address") != std::string::npos)
114 && (el_message.find(
"not set") != std::string::npos)) {
115 el_severity = SeverityLevel::kFatal;
118 if ((el_message.find(
"Tree branches") != std::string::npos)
119 && (el_message.find(
"different numbers of entries") != std::string::npos)) {
120 el_severity = SeverityLevel::kFatal;
126 if ((el_message.find(
"no dictionary for class") != std::string::npos) ||
127 (el_message.find(
"already in TClassTable") != std::string::npos) ||
128 (el_message.find(
"matrix not positive definite") != std::string::npos) ||
129 (el_message.find(
"not a TStreamerInfo object") != std::string::npos) ||
130 (el_message.find(
"Problems declaring payload") != std::string::npos) ||
131 (el_message.find(
"Announced number of args different from the real number of argument passed") != std::string::npos) ||
132 (el_location.find(
"Fit") != std::string::npos) ||
133 (el_location.find(
"TDecompChol::Solve") != std::string::npos) ||
134 (el_location.find(
"THistPainter::PaintInit") != std::string::npos) ||
135 (el_location.find(
"TUnixSystem::SetDisplay") != std::string::npos) ||
136 (el_location.find(
"TGClient::GetFontByName") != std::string::npos) ||
137 (el_message.find(
"nbins is <=0 - set to nbins = 1") != std::string::npos) ||
138 (el_message.find(
"nbinsy is <=0 - set to nbinsy = 1") != std::string::npos) ||
140 (el_location.find(
"CINTTypedefBuilder::Setup")!= std::string::npos) and
141 (el_message.find(
"possible entries are in use!") != std::string::npos))) {
157 if (die && (el_location !=
std::string(
"@SUB=TUnixSystem::DispatchSignals"))) {
158 std::ostringstream sstr;
159 sstr <<
"Fatal Root Error: " << el_location <<
"\n" << el_message <<
'\n';
162 except.clearMessage();
170 if (el_severity == SeverityLevel::kFatal) {
172 }
else if (el_severity == SeverityLevel::kSysError) {
179 edm::LogInfo(
"Root_Information") << el_location << el_message ;
183 void RootErrorHandler(
int level,
bool,
char const* location,
char const* message) {
184 RootErrorHandlerImpl(level, location, message);
189 static int full_cerr_write(
const char *
text)
191 const char *buffer =
text;
192 size_t count = strlen(text);
196 written =
write(2, buffer, count);
199 if (errno == EINTR) {
continue;}
200 else {
return -errno;}
208 void sig_dostack_then_abort(
int sig, siginfo_t*,
void*) {
210 const char* signalname =
"unknown";
213 signalname =
"bus error";
216 signalname =
"segmentation violation";
219 signalname =
"illegal instruction";
223 full_cerr_write(
"\n\nA fatal system signal has occurred: ");
224 full_cerr_write(signalname);
225 full_cerr_write(
"\nThe following is the call stack containing the origin of the signal.\n"
226 "NOTE:The first few functions on the stack are artifacts of processing the signal and can be ignored\n\n");
228 char child_stack[4*1024];
229 char *child_stack_ptr = child_stack + 4*1024;
239 if (child_stack_ptr) {}
244 full_cerr_write(
"(Attempt to perform stack dump failed.)\n");
249 if (waitpid(pid, &status, 0) == -1)
251 full_cerr_write(
"(Failed to wait on stack dump output.)\n");
255 full_cerr_write(
"\nA fatal system signal has occurred: ");
256 full_cerr_write(signalname);
257 full_cerr_write(
"\n");
261 void sig_abort(
int sig, siginfo_t*,
void*) {
273 execv(
"/bin/sh", argv);
285 unloadSigHandler_(pset.getUntrackedParameter<bool> (
"UnloadRootSigHandler")),
286 resetErrHandler_(pset.getUntrackedParameter<bool> (
"ResetRootErrHandler")),
287 loadAllDictionaries_(pset.getUntrackedParameter<bool>(
"LoadAllDictionaries")),
288 autoLibraryLoader_(loadAllDictionaries_
or pset.getUntrackedParameter<bool> (
"AutoLibraryLoader"))
293 gSystem->ResetSignal(kSigChild);
294 gSystem->ResetSignal(kSigBus);
295 gSystem->ResetSignal(kSigSegmentationViolation);
296 gSystem->ResetSignal(kSigIllegalInstruction);
297 gSystem->ResetSignal(kSigSystem);
298 gSystem->ResetSignal(kSigPipe);
299 gSystem->ResetSignal(kSigAlarm);
300 gSystem->ResetSignal(kSigUrgent);
301 gSystem->ResetSignal(kSigFloatingException);
302 gSystem->ResetSignal(kSigWindowChanged);
308 gSystem->ResetSignal(kSigBus);
309 gSystem->ResetSignal(kSigSegmentationViolation);
310 gSystem->ResetSignal(kSigIllegalInstruction);
329 SetErrorHandler(RootErrorHandler);
334 gInterpreter->SetClassAutoloading(1);
338 TTree::SetMaxTreeSize(kMaxLong64);
339 TH1::AddDirectory(kFALSE);
346 if (!
hasDictionary(
typeid(std::vector<std::vector<unsigned int> >))) {
358 TIter
iter(gROOT->GetListOfFiles());
359 TObject *
obj =
nullptr;
360 while(
nullptr != (obj =
iter.Next())) {
361 TFile*
f =
dynamic_cast<TFile*
>(
obj);
366 iter = TIter(gROOT->GetListOfFiles());
373 TThread::Initialize();
375 TObject::SetObjectStat(
false);
378 TVirtualStreamerInfo::Optimize(
false);
382 static thread_local TThread guard;
387 desc.
setComment(
"Centralized interface to ROOT.");
389 ->setComment(
"If True, signals are handled by this service, rather than by ROOT.");
391 ->setComment(
"If True, ROOT messages (e.g. errors, warnings) are handled by this service, rather than by ROOT.");
393 ->setComment(
"If True, enables automatic loading of data dictionaries.");
395 ->setComment(
"If True, loads all ROOT dictionaries.");
397 ->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.");
399 ->setComment(
"Sets ROOT's gDebug value.");
400 descriptions.
add(
"InitRootHandlers", desc);
410 s_ignoreWarnings =
false;
415 s_ignoreWarnings =
true;
424 "set pagination no\n"
425 "thread apply all bt\n"
427 "/bin/sed -n -e 's/^\\((gdb) \\)*//' -e '/^#/p' -e '/^Thread/p'", getpid()) >=
pidStringLength_)
429 std::ostringstream sstr;
430 sstr <<
"Unable to pre-allocate stacktrace handler information";
T getUntrackedParameter(std::string const &, T const &) const
virtual void enableWarnings_() override
static char *const pstackArgv_[]
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventIDconst &, edm::Timestampconst & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
void setRefCoreStreamer(bool resetAll=false)
std::string const & dictionaryPlugInPrefix()
void installCustomHandler(int signum, CFUNC func)
std::shared_ptr< const void > sigSegvHandler_
std::shared_ptr< const void > sigBusHandler_
void cachePidInfoHandler(unsigned int, unsigned int)
void setComment(std::string const &value)
static char pidString_[pidStringLength_]
static char *const * getPstackArgv()
std::shared_ptr< const void > sigIllHandler_
virtual void initializeThisThreadForUse() override
virtual void ignoreWarnings_() override
void addAdditionalInfo(std::string const &info)
static PluginCapabilities * get()
int cmssw_stacktrace(void *)
virtual ~InitRootHandlers()
InitRootHandlers(ParameterSet const &pset, ActivityRegistry &iReg)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
void watchPostForkReacquireResources(PostForkReacquireResources::slot_type const &iSlot)
virtual void willBeUsingThreads() override
static void fillDescriptions(ConfigurationDescriptions &descriptions)
static const int pidStringLength_
bool hasDictionary(std::type_info const &)
void load(const std::string &iName)