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 291 of file InitRootHandlers.cc.

References autoLibraryLoader_, cachePidInfo(), cachePidInfoHandler(), HLT_25ns14e33_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().

292  : RootHandlers(),
293  unloadSigHandler_(pset.getUntrackedParameter<bool> ("UnloadRootSigHandler")),
294  resetErrHandler_(pset.getUntrackedParameter<bool> ("ResetRootErrHandler")),
295  loadAllDictionaries_(pset.getUntrackedParameter<bool>("LoadAllDictionaries")),
296  autoLibraryLoader_(loadAllDictionaries_ or pset.getUntrackedParameter<bool> ("AutoLibraryLoader"))
297  {
298 
299  if(unloadSigHandler_) {
300  // Deactivate all the Root signal handlers and restore the system defaults
301  gSystem->ResetSignal(kSigChild);
302  gSystem->ResetSignal(kSigBus);
303  gSystem->ResetSignal(kSigSegmentationViolation);
304  gSystem->ResetSignal(kSigIllegalInstruction);
305  gSystem->ResetSignal(kSigSystem);
306  gSystem->ResetSignal(kSigPipe);
307  gSystem->ResetSignal(kSigAlarm);
308  gSystem->ResetSignal(kSigUrgent);
309  gSystem->ResetSignal(kSigFloatingException);
310  gSystem->ResetSignal(kSigWindowChanged);
311  } else if(pset.getUntrackedParameter<bool>("AbortOnSignal")){
312  cachePidInfo();
313 
314  //NOTE: ROOT can also be told to abort on these kinds of problems BUT
315  // it requires an TApplication to be instantiated which causes problems
316  gSystem->ResetSignal(kSigBus);
317  gSystem->ResetSignal(kSigSegmentationViolation);
318  gSystem->ResetSignal(kSigIllegalInstruction);
319  installCustomHandler(SIGBUS,sig_dostack_then_abort);
320  sigBusHandler_ = std::shared_ptr<const void>(nullptr,[](void*) {
321  installCustomHandler(SIGBUS,sig_abort);
322  });
323  installCustomHandler(SIGSEGV,sig_dostack_then_abort);
324  sigSegvHandler_ = std::shared_ptr<const void>(nullptr,[](void*) {
325  installCustomHandler(SIGSEGV,sig_abort);
326  });
327  installCustomHandler(SIGILL,sig_dostack_then_abort);
328  sigIllHandler_ = std::shared_ptr<const void>(nullptr,[](void*) {
329  installCustomHandler(SIGILL,sig_abort);
330  });
331  iReg.watchPostForkReacquireResources(this, &InitRootHandlers::cachePidInfoHandler);
332  }
333 
334  if(resetErrHandler_) {
335 
336  // Replace the Root error handler with one that uses the MessageLogger
337  SetErrorHandler(RootErrorHandler);
338  }
339 
340  // Enable automatic Root library loading.
341  if(autoLibraryLoader_) {
342  gInterpreter->SetClassAutoloading(1);
343  }
344 
345  // Set ROOT parameters.
346  TTree::SetMaxTreeSize(kMaxLong64);
347  TH1::AddDirectory(kFALSE);
348  //G__SetCatchException(0);
349 
350  // Set custom streamers
352 
353  // Load the library containing dictionaries for std:: classes, if not already loaded.
354  if (!hasDictionary(typeid(std::vector<std::vector<unsigned int> >))) {
355  edmplugin::PluginCapabilities::get()->load(dictionaryPlugInPrefix() + "std::vector<std::vector<unsigned int> >");
356  }
357 
358  int debugLevel = pset.getUntrackedParameter<int>("DebugLevel");
359  if(debugLevel >0) {
360  gDebug = debugLevel;
361  }
362  }
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 364 of file InitRootHandlers.cc.

References f, and getGTfromDQMFile::obj.

364  {
365  // close all open ROOT files
366  TIter iter(gROOT->GetListOfFiles());
367  TObject *obj = nullptr;
368  while(nullptr != (obj = iter.Next())) {
369  TFile* f = dynamic_cast<TFile*>(obj);
370  if(f) {
371  // We get a new iterator each time,
372  // because closing a file can invalidate the iterator
373  f->Close();
374  iter = TIter(gROOT->GetListOfFiles());
375  }
376  }
377  }
double f[11][100]

Member Function Documentation

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

Definition at line 427 of file InitRootHandlers.cc.

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

Referenced by cachePidInfoHandler(), and InitRootHandlers().

428  {
429  if (snprintf(pidString_, pidStringLength_-1, "gdb -quiet -p %d 2>&1 <<EOF |\n"
430  "set width 0\n"
431  "set height 0\n"
432  "set pagination no\n"
433  "thread apply all bt\n"
434  "EOF\n"
435  "/bin/sed -n -e 's/^\\((gdb) \\)*//' -e '/^#/p' -e '/^Thread/p'", getpid()) >= pidStringLength_)
436  {
437  std::ostringstream sstr;
438  sstr << "Unable to pre-allocate stacktrace handler information";
439  edm::Exception except(edm::errors::OtherCMS, sstr.str());
440  throw except;
441  }
442  }
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 417 of file InitRootHandlers.cc.

417  {
418  s_ignoreWarnings =false;
419  }
void edm::service::InitRootHandlers::fillDescriptions ( ConfigurationDescriptions descriptions)
static

Definition at line 393 of file InitRootHandlers.cc.

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

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

Definition at line 412 of file InitRootHandlers.cc.

References pstackArgv_.

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

412  {
413  return pstackArgv_;
414  }
static char *const pstackArgv_[]
void edm::service::InitRootHandlers::ignoreWarnings_ ( )
overrideprivatevirtual

Implements edm::RootHandlers.

Definition at line 422 of file InitRootHandlers.cc.

422  {
423  s_ignoreWarnings = true;
424  }
void edm::service::InitRootHandlers::initializeThisThreadForUse ( )
overrideprivatevirtual

Implements edm::RootHandlers.

Definition at line 389 of file InitRootHandlers.cc.

389  {
390  static thread_local TThread guard;
391  }
void edm::service::InitRootHandlers::willBeUsingThreads ( )
overrideprivatevirtual

Implements edm::RootHandlers.

Definition at line 379 of file InitRootHandlers.cc.

379  {
380  //Tell Root we want to be multi-threaded
381  TThread::Initialize();
382  //When threading, also have to keep ROOT from logging all TObjects into a list
383  TObject::SetObjectStat(false);
384 
385  //Have to avoid having Streamers modify themselves after they have been used
386  TVirtualStreamerInfo::Optimize(false);
387  }

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().