Skip to content

Commit

Permalink
Merge pull request #853 from Dr15Jones/updateRootHandlers
Browse files Browse the repository at this point in the history
Threaded framework cleanups -- Make InitRootHandlers safe for the threaded framework
  • Loading branch information
ktf committed Sep 18, 2013
2 parents d5362cb + 258c234 commit 728746a
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 28 deletions.
25 changes: 9 additions & 16 deletions FWCore/Services/src/InitRootHandlers.cc
Expand Up @@ -35,8 +35,10 @@ namespace {
kSysError,
kFatal
};

static thread_local bool s_ignoreWarnings = false;

void RootErrorHandlerImpl(int level, char const* location, char const* message, bool ignoreWarnings) {
void RootErrorHandlerImpl(int level, char const* location, char const* message) {

bool die = false;

Expand All @@ -51,7 +53,7 @@ namespace {
} else if (level >= kError) {
el_severity = SeverityLevel::kError;
} else if (level >= kWarning) {
el_severity = ignoreWarnings ? SeverityLevel::kInfo : SeverityLevel::kWarning;
el_severity = s_ignoreWarnings ? SeverityLevel::kInfo : SeverityLevel::kWarning;
}

// Adapt C-strings to std::strings
Expand Down Expand Up @@ -157,11 +159,7 @@ namespace {
}

void RootErrorHandler(int level, bool, char const* location, char const* message) {
RootErrorHandlerImpl(level, location, message, false);
}

void RootErrorHandlerWithoutWarnings(int level, bool, char const* location, char const* message) {
RootErrorHandlerImpl(level, location, message, true);
RootErrorHandlerImpl(level, location, message);
}

extern "C" {
Expand Down Expand Up @@ -279,18 +277,13 @@ namespace edm {
}

void
InitRootHandlers::disableErrorHandler_() {
SetErrorHandler(DefaultErrorHandler);
}

void
InitRootHandlers::enableErrorHandler_() {
SetErrorHandler(RootErrorHandler);
InitRootHandlers::enableWarnings_() {
s_ignoreWarnings =false;
}

void
InitRootHandlers::enableErrorHandlerWithoutWarnings_() {
SetErrorHandler(RootErrorHandlerWithoutWarnings);
InitRootHandlers::ignoreWarnings_() {
s_ignoreWarnings = true;
}

} // end of namespace service
Expand Down
5 changes: 2 additions & 3 deletions FWCore/Services/src/InitRootHandlers.h
Expand Up @@ -17,9 +17,8 @@ namespace edm {
static void fillDescriptions(ConfigurationDescriptions& descriptions);

private:
virtual void disableErrorHandler_();
virtual void enableErrorHandler_();
virtual void enableErrorHandlerWithoutWarnings_();
virtual void enableWarnings_() override;
virtual void ignoreWarnings_() override;
bool unloadSigHandler_;
bool resetErrHandler_;
bool autoLibraryLoader_;
Expand Down
26 changes: 20 additions & 6 deletions FWCore/Utilities/interface/RootHandlers.h
Expand Up @@ -3,16 +3,30 @@

namespace edm {
class RootHandlers {
private:
struct WarningSentry {
WarningSentry(RootHandlers* iHandler): m_handler(iHandler){
m_handler->ignoreWarnings_();
};
~WarningSentry() {
m_handler->enableWarnings_();
}
RootHandlers* m_handler;
};
friend struct edm::RootHandlers::WarningSentry;

public:
RootHandlers () {}
virtual ~RootHandlers () {}
void disableErrorHandler() {disableErrorHandler_();}
void enableErrorHandler() {enableErrorHandler_();}
void enableErrorHandlerWithoutWarnings() {enableErrorHandlerWithoutWarnings_();}

template<typename F>
void ignoreWarningsWhileDoing(F iFunc) {
WarningSentry sentry(this);
iFunc();
}
private:
virtual void disableErrorHandler_() = 0;
virtual void enableErrorHandler_() = 0;
virtual void enableErrorHandlerWithoutWarnings_() = 0;
virtual void enableWarnings_() = 0;
virtual void ignoreWarnings_() = 0;
};
} // end of namespace edm

Expand Down
4 changes: 1 addition & 3 deletions IOPool/Output/src/RootOutputTree.cc
Expand Up @@ -195,9 +195,7 @@ namespace edm {
}
tree_->SetEntries(tree_->GetEntries() + in->GetEntries());
Service<RootHandlers> rootHandler;
rootHandler->enableErrorHandlerWithoutWarnings();
cloner.Exec();
rootHandler->enableErrorHandler();
rootHandler->ignoreWarningsWhileDoing([&cloner] { cloner.Exec(); });
if(mustRemoveSomeAuxs) {
for(std::map<Int_t, TBranch *>::const_iterator it = auxIndexes.begin(), itEnd = auxIndexes.end();
it != itEnd; ++it) {
Expand Down

0 comments on commit 728746a

Please sign in to comment.