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

Use threads with ROOT #1103

Merged
merged 5 commits into from
Oct 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion DataFormats/Common/interface/RefCoreStreamer.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ namespace edm {

void operator() (TBuffer &R__b, void *objp);

TClassStreamer* Generate() const;

private:
TClassRef cl_;
};
Expand All @@ -24,7 +26,8 @@ namespace edm {
explicit RefCoreWithIndexStreamer() : cl_("edm::RefCoreWithIndex"){}

void operator() (TBuffer &R__b, void *objp);


TClassStreamer* Generate() const;
private:
TClassRef cl_;
};
Expand Down
10 changes: 9 additions & 1 deletion DataFormats/Common/src/RefCoreStreamer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,15 @@ namespace edm {
}
}


TClassStreamer*
RefCoreStreamer::Generate() const {
return new RefCoreStreamer(*this);
}

TClassStreamer*
RefCoreWithIndexStreamer::Generate() const {
return new RefCoreWithIndexStreamer(*this);
}


void setRefCoreStreamer(bool resetAll) {
Expand Down
1 change: 1 addition & 0 deletions DataFormats/Streamer/interface/StreamedProductStreamer.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ namespace edm {

void operator() (TBuffer &R__b, void *objp);

TClassStreamer* Generate() const;
private:
TClassRef cl_;
};
Expand Down
5 changes: 5 additions & 0 deletions DataFormats/Streamer/src/StreamedProductStreamer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ namespace edm {
}
}
}

TClassStreamer*
StreamedProductStreamer::Generate() const {
return new StreamedProductStreamer(*this);
}

void
setStreamedProductStreamer() {
Expand Down
12 changes: 11 additions & 1 deletion FWCore/Framework/src/EventProcessor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
#include "FWCore/Utilities/interface/UnixSignalHandlers.h"
#include "FWCore/Utilities/interface/ExceptionCollector.h"
#include "FWCore/Utilities/interface/StreamID.h"
#include "FWCore/Utilities/interface/RootHandlers.h"

#include "MessageForSource.h"
#include "MessageForParent.h"
Expand Down Expand Up @@ -476,6 +477,11 @@ namespace edm {

//make the services available
ServiceRegistry::Operate operate(serviceToken_);

if(nStreams>1) {
edm::Service<RootHandlers> handler;
handler->willBeUsingThreads();
}

// intialize miscellaneous items
boost::shared_ptr<CommonParams> common(items.initMisc(*parameterSet));
Expand Down Expand Up @@ -1807,7 +1813,11 @@ namespace edm {
try {
// make the services available
ServiceRegistry::Operate operate(serviceToken_);

if(preallocations_.numberOfStreams()>1) {
edm::Service<RootHandlers> handler;
handler->initializeThisThreadForUse();
}

if(iStreamIndex==0) {
processEvent(0);
}
Expand Down
34 changes: 31 additions & 3 deletions FWCore/Services/src/InitRootHandlers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "TSystem.h"
#include "TUnixSystem.h"
#include "TTree.h"
#include "TThread.h"

namespace {
enum class SeverityLevel {
Expand Down Expand Up @@ -116,7 +117,10 @@ namespace {
(el_location.find("TDecompChol::Solve") != std::string::npos) ||
(el_location.find("THistPainter::PaintInit") != std::string::npos) ||
(el_location.find("TUnixSystem::SetDisplay") != std::string::npos) ||
(el_location.find("TGClient::GetFontByName") != std::string::npos)) {
(el_location.find("TGClient::GetFontByName") != std::string::npos) ||
(level < kError and
(el_location.find("CINTTypedefBuilder::Setup")!= std::string::npos) and
(el_message.find("possible entries are in use!") != std::string::npos))) {
el_severity = SeverityLevel::kInfo;
}

Expand Down Expand Up @@ -197,8 +201,10 @@ namespace edm {
: RootHandlers(),
unloadSigHandler_(pset.getUntrackedParameter<bool> ("UnloadRootSigHandler")),
resetErrHandler_(pset.getUntrackedParameter<bool> ("ResetRootErrHandler")),
autoLibraryLoader_(pset.getUntrackedParameter<bool> ("AutoLibraryLoader")) {

loadAllDictionaries_(pset.getUntrackedParameter<bool>("LoadAllDictionaries")),
autoLibraryLoader_(loadAllDictionaries_ or pset.getUntrackedParameter<bool> ("AutoLibraryLoader"))
{

if(unloadSigHandler_) {
// Deactivate all the Root signal handlers and restore the system defaults
gSystem->ResetSignal(kSigChild);
Expand Down Expand Up @@ -231,6 +237,9 @@ namespace edm {
// Enable automatic Root library loading.
if(autoLibraryLoader_) {
RootAutoLibraryLoader::enable();
if(loadAllDictionaries_) {
RootAutoLibraryLoader::loadAll();
}
}

// Enable Cintex.
Expand Down Expand Up @@ -261,6 +270,23 @@ namespace edm {
if(f) f->Close();
}
}

void InitRootHandlers::willBeUsingThreads() {
//Tell Root we want to be multi-threaded
TThread::Initialize();
//When threading, also have to keep ROOT from logging all TObjects into a list
TObject::SetObjectStat(false);
if(not this->autoLibraryLoader_) {
RootAutoLibraryLoader::enable();
}
if(not this->loadAllDictionaries_) {
RootAutoLibraryLoader::loadAll();
}
}

void InitRootHandlers::initializeThisThreadForUse() {
static thread_local TThread guard;
}

void InitRootHandlers::fillDescriptions(ConfigurationDescriptions& descriptions) {
ParameterSetDescription desc;
Expand All @@ -271,6 +297,8 @@ namespace edm {
->setComment("If True, ROOT messages (e.g. errors, warnings) are handled by this service, rather than by ROOT.");
desc.addUntracked<bool>("AutoLibraryLoader", true)
->setComment("If True, enables automatic loading of data dictionaries.");
desc.addUntracked<bool>("LoadAllDictionaries",false)
->setComment("If True, loads all ROOT dictionaries.");
desc.addUntracked<bool>("AbortOnSignal",true)
->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.");
descriptions.add("InitRootHandlers", desc);
Expand Down
4 changes: 4 additions & 0 deletions FWCore/Services/src/InitRootHandlers.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,12 @@ namespace edm {
private:
virtual void enableWarnings_() override;
virtual void ignoreWarnings_() override;
virtual void willBeUsingThreads() override;
virtual void initializeThisThreadForUse() override;

bool unloadSigHandler_;
bool resetErrHandler_;
bool loadAllDictionaries_;
bool autoLibraryLoader_;
};

Expand Down
8 changes: 7 additions & 1 deletion FWCore/Utilities/interface/RootHandlers.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define FWCore_Utilities_RootHandlers_h

namespace edm {
class EventProcessor;
class RootHandlers {
private:
struct WarningSentry {
Expand All @@ -14,6 +15,7 @@ namespace edm {
RootHandlers* m_handler;
};
friend struct edm::RootHandlers::WarningSentry;
friend class edm::EventProcessor;

public:
RootHandlers () {}
Expand All @@ -24,7 +26,11 @@ namespace edm {
WarningSentry sentry(this);
iFunc();
}
private:

private:
virtual void willBeUsingThreads() = 0;
virtual void initializeThisThreadForUse() = 0;

virtual void enableWarnings_() = 0;
virtual void ignoreWarnings_() = 0;
};
Expand Down