CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Static Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes | Friends
edm::service::InitRootHandlers Class Reference

#include <InitRootHandlers.h>

Inheritance diagram for edm::service::InitRootHandlers:
edm::RootHandlers

Public Member Functions

 InitRootHandlers (ParameterSet const &pset, ActivityRegistry &iReg)
 
virtual ~InitRootHandlers ()
 
- Public Member Functions inherited from edm::RootHandlers
template<typename F >
void ignoreWarningsWhileDoing (F iFunc)
 
 RootHandlers ()
 
virtual ~RootHandlers ()
 

Static Public Member Functions

static void fillDescriptions (ConfigurationDescriptions &descriptions)
 

Private Member Functions

void cachePidInfo ()
 
void cachePidInfoHandler (unsigned int, unsigned int)
 
virtual void enableWarnings_ () override
 
virtual void ignoreWarnings_ () override
 
virtual void initializeThisThreadForUse () override
 
virtual void willBeUsingThreads () override
 

Static Private Member Functions

static char *const * getPstackArgv ()
 

Private Attributes

bool autoLibraryLoader_
 
bool loadAllDictionaries_
 
bool resetErrHandler_
 
std::shared_ptr< const void > sigBusHandler_
 
std::shared_ptr< const void > sigIllHandler_
 
std::shared_ptr< const void > sigSegvHandler_
 
bool unloadSigHandler_
 

Static Private Attributes

static char pidString_ [pidStringLength_] = {}
 
static const int pidStringLength_ = 200
 
static char *const pstackArgv_ [] = {pstackName, dashC, InitRootHandlers::pidString_, 0 }
 

Friends

int cmssw_stacktrace (void *)
 

Detailed Description

Definition at line 13 of file InitRootHandlers.h.

Constructor & Destructor Documentation

edm::service::InitRootHandlers::InitRootHandlers ( ParameterSet const &  pset,
ActivityRegistry iReg 
)
explicit

Definition at line 283 of file InitRootHandlers.cc.

References autoLibraryLoader_, cachePidInfo(), cachePidInfoHandler(), HLT_50ns_5e33_v3_cff::debugLevel, edm::dictionaryPlugInPrefix(), edmplugin::PluginCapabilities::get(), edm::ParameterSet::getUntrackedParameter(), edm::hasDictionary(), edm::installCustomHandler(), edmplugin::PluginCapabilities::load(), resetErrHandler_, edm::setRefCoreStreamer(), sigBusHandler_, sigIllHandler_, sigSegvHandler_, unloadSigHandler_, and edm::ActivityRegistry::watchPostForkReacquireResources().

284  : RootHandlers(),
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"))
289  {
290 
291  if(unloadSigHandler_) {
292  // Deactivate all the Root signal handlers and restore the system defaults
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);
303  } else if(pset.getUntrackedParameter<bool>("AbortOnSignal")){
304  cachePidInfo();
305 
306  //NOTE: ROOT can also be told to abort on these kinds of problems BUT
307  // it requires an TApplication to be instantiated which causes problems
308  gSystem->ResetSignal(kSigBus);
309  gSystem->ResetSignal(kSigSegmentationViolation);
310  gSystem->ResetSignal(kSigIllegalInstruction);
311  installCustomHandler(SIGBUS,sig_dostack_then_abort);
312  sigBusHandler_ = std::shared_ptr<const void>(nullptr,[](void*) {
313  installCustomHandler(SIGBUS,sig_abort);
314  });
315  installCustomHandler(SIGSEGV,sig_dostack_then_abort);
316  sigSegvHandler_ = std::shared_ptr<const void>(nullptr,[](void*) {
317  installCustomHandler(SIGSEGV,sig_abort);
318  });
319  installCustomHandler(SIGILL,sig_dostack_then_abort);
320  sigIllHandler_ = std::shared_ptr<const void>(nullptr,[](void*) {
321  installCustomHandler(SIGILL,sig_abort);
322  });
323  iReg.watchPostForkReacquireResources(this, &InitRootHandlers::cachePidInfoHandler);
324  }
325 
326  if(resetErrHandler_) {
327 
328  // Replace the Root error handler with one that uses the MessageLogger
329  SetErrorHandler(RootErrorHandler);
330  }
331 
332  // Enable automatic Root library loading.
333  if(autoLibraryLoader_) {
334  gInterpreter->SetClassAutoloading(1);
335  }
336 
337  // Set ROOT parameters.
338  TTree::SetMaxTreeSize(kMaxLong64);
339  TH1::AddDirectory(kFALSE);
340  //G__SetCatchException(0);
341 
342  // Set custom streamers
344 
345  // Load the library containing dictionaries for std:: classes, if not already loaded.
346  if (!hasDictionary(typeid(std::vector<std::vector<unsigned int> >))) {
347  edmplugin::PluginCapabilities::get()->load(dictionaryPlugInPrefix() + "std::vector<std::vector<unsigned int> >");
348  }
349 
350  int debugLevel = pset.getUntrackedParameter<int>("DebugLevel");
351  if(debugLevel >0) {
352  gDebug = debugLevel;
353  }
354  }
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
Definition: Activities.doc:12
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)
std::shared_ptr< const void > sigIllHandler_
static PluginCapabilities * get()
bool hasDictionary(std::type_info const &)
void load(const std::string &iName)
edm::service::InitRootHandlers::~InitRootHandlers ( )
virtual

Definition at line 356 of file InitRootHandlers.cc.

References f, and getGTfromDQMFile::obj.

356  {
357  // close all open ROOT files
358  TIter iter(gROOT->GetListOfFiles());
359  TObject *obj = nullptr;
360  while(nullptr != (obj = iter.Next())) {
361  TFile* f = dynamic_cast<TFile*>(obj);
362  if(f) {
363  // We get a new iterator each time,
364  // because closing a file can invalidate the iterator
365  f->Close();
366  iter = TIter(gROOT->GetListOfFiles());
367  }
368  }
369  }
double f[11][100]

Member Function Documentation

void edm::service::InitRootHandlers::cachePidInfo ( )
private

Definition at line 419 of file InitRootHandlers.cc.

References edm::errors::OtherCMS, pidString_, and pidStringLength_.

Referenced by cachePidInfoHandler(), and InitRootHandlers().

420  {
421  if (snprintf(pidString_, pidStringLength_-1, "gdb -quiet -p %d 2>&1 <<EOF |\n"
422  "set width 0\n"
423  "set height 0\n"
424  "set pagination no\n"
425  "thread apply all bt\n"
426  "EOF\n"
427  "/bin/sed -n -e 's/^\\((gdb) \\)*//' -e '/^#/p' -e '/^Thread/p'", getpid()) >= pidStringLength_)
428  {
429  std::ostringstream sstr;
430  sstr << "Unable to pre-allocate stacktrace handler information";
431  edm::Exception except(edm::errors::OtherCMS, sstr.str());
432  throw except;
433  }
434  }
static char pidString_[pidStringLength_]
void edm::service::InitRootHandlers::cachePidInfoHandler ( unsigned  int,
unsigned  int 
)
inlineprivate

Definition at line 30 of file InitRootHandlers.h.

References cachePidInfo().

Referenced by InitRootHandlers().

void edm::service::InitRootHandlers::enableWarnings_ ( )
overrideprivatevirtual

Implements edm::RootHandlers.

Definition at line 409 of file InitRootHandlers.cc.

409  {
410  s_ignoreWarnings =false;
411  }
void edm::service::InitRootHandlers::fillDescriptions ( ConfigurationDescriptions descriptions)
static

Definition at line 385 of file InitRootHandlers.cc.

References edm::ConfigurationDescriptions::add(), edm::ParameterSetDescription::addUntracked(), and edm::ParameterSetDescription::setComment().

385  {
387  desc.setComment("Centralized interface to ROOT.");
388  desc.addUntracked<bool>("UnloadRootSigHandler", false)
389  ->setComment("If True, signals are handled by this service, rather than by ROOT.");
390  desc.addUntracked<bool>("ResetRootErrHandler", true)
391  ->setComment("If True, ROOT messages (e.g. errors, warnings) are handled by this service, rather than by ROOT.");
392  desc.addUntracked<bool>("AutoLibraryLoader", true)
393  ->setComment("If True, enables automatic loading of data dictionaries.");
394  desc.addUntracked<bool>("LoadAllDictionaries",false)
395  ->setComment("If True, loads all ROOT dictionaries.");
396  desc.addUntracked<bool>("AbortOnSignal",true)
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.");
398  desc.addUntracked<int>("DebugLevel",0)
399  ->setComment("Sets ROOT's gDebug value.");
400  descriptions.add("InitRootHandlers", desc);
401  }
char *const * edm::service::InitRootHandlers::getPstackArgv ( )
staticprivate

Definition at line 404 of file InitRootHandlers.cc.

References pstackArgv_.

Referenced by edm::service::cmssw_stacktrace().

404  {
405  return pstackArgv_;
406  }
static char *const pstackArgv_[]
void edm::service::InitRootHandlers::ignoreWarnings_ ( )
overrideprivatevirtual

Implements edm::RootHandlers.

Definition at line 414 of file InitRootHandlers.cc.

414  {
415  s_ignoreWarnings = true;
416  }
void edm::service::InitRootHandlers::initializeThisThreadForUse ( )
overrideprivatevirtual

Implements edm::RootHandlers.

Definition at line 381 of file InitRootHandlers.cc.

381  {
382  static thread_local TThread guard;
383  }
void edm::service::InitRootHandlers::willBeUsingThreads ( )
overrideprivatevirtual

Implements edm::RootHandlers.

Definition at line 371 of file InitRootHandlers.cc.

371  {
372  //Tell Root we want to be multi-threaded
373  TThread::Initialize();
374  //When threading, also have to keep ROOT from logging all TObjects into a list
375  TObject::SetObjectStat(false);
376 
377  //Have to avoid having Streamers modify themselves after they have been used
378  TVirtualStreamerInfo::Optimize(false);
379  }

Friends And Related Function Documentation

int cmssw_stacktrace ( void *  )
friend

Member Data Documentation

bool edm::service::InitRootHandlers::autoLibraryLoader_
private

Definition at line 39 of file InitRootHandlers.h.

Referenced by InitRootHandlers().

bool edm::service::InitRootHandlers::loadAllDictionaries_
private

Definition at line 38 of file InitRootHandlers.h.

char edm::service::InitRootHandlers::pidString_ = {}
staticprivate

Definition at line 34 of file InitRootHandlers.h.

Referenced by cachePidInfo().

const int edm::service::InitRootHandlers::pidStringLength_ = 200
staticprivate

Definition at line 33 of file InitRootHandlers.h.

Referenced by cachePidInfo().

char *const edm::service::InitRootHandlers::pstackArgv_ = {pstackName, dashC, InitRootHandlers::pidString_, 0 }
staticprivate

Definition at line 35 of file InitRootHandlers.h.

Referenced by getPstackArgv().

bool edm::service::InitRootHandlers::resetErrHandler_
private

Definition at line 37 of file InitRootHandlers.h.

Referenced by InitRootHandlers().

std::shared_ptr<const void> edm::service::InitRootHandlers::sigBusHandler_
private

Definition at line 40 of file InitRootHandlers.h.

Referenced by InitRootHandlers().

std::shared_ptr<const void> edm::service::InitRootHandlers::sigIllHandler_
private

Definition at line 42 of file InitRootHandlers.h.

Referenced by InitRootHandlers().

std::shared_ptr<const void> edm::service::InitRootHandlers::sigSegvHandler_
private

Definition at line 41 of file InitRootHandlers.h.

Referenced by InitRootHandlers().

bool edm::service::InitRootHandlers::unloadSigHandler_
private

Definition at line 36 of file InitRootHandlers.h.

Referenced by InitRootHandlers().