Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make InitRootHandlers safe for the threaded framework #853

Merged
merged 1 commit into from Sep 18, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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