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

Do not call TTree cache after an exception happens #12658

Merged
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
17 changes: 15 additions & 2 deletions IOPool/Input/src/RootDelayedReader.cc
Expand Up @@ -11,6 +11,8 @@

#include "IOPool/Common/interface/getWrapperBasePtr.h"

#include "FWCore/Utilities/interface/EDMException.h"

#include "TBranch.h"
#include "TClass.h"

Expand Down Expand Up @@ -40,6 +42,9 @@ namespace edm {

std::unique_ptr<WrapperBase>
RootDelayedReader::getProduct_(BranchKey const& k, EDProductGetter const* ep) const {
if (lastException_) {
throw *lastException_;
}
iterator iter = branchIter(k);
if (!found(iter)) {
if (nextReader_) {
Expand All @@ -59,6 +64,9 @@ namespace edm {
}

setRefCoreStreamer(ep);
//make code exception safe
std::shared_ptr<void> refCoreStreamerGuard(nullptr,[](void*){ setRefCoreStreamer(false);
;});
TClass* cp = branchInfo.classCache_;
if(nullptr == cp) {
branchInfo.classCache_ = TClass::GetClass(branchInfo.branchDescription_.wrappedName().c_str());
Expand All @@ -68,12 +76,17 @@ namespace edm {
void* p = cp->New();
std::unique_ptr<WrapperBase> edp = getWrapperBasePtr(p, branchInfo.offsetToWrapperBase_);
br->SetAddress(&p);
tree_.getEntry(br, tree_.entryNumberForIndex(ep->transitionIndex()));
try{
tree_.getEntry(br, tree_.entryNumberForIndex(ep->transitionIndex()));
} catch(const edm::Exception& exception) {
lastException_ = std::make_unique<Exception>(exception);
lastException_->addContext("Rethrowing an exception that happened on a different thread.");
throw exception;
}
if(tree_.branchType() == InEvent) {
// CMS-THREADING For the primary input source calls to this function need to be serialized
InputFile::reportReadBranch(inputType_, std::string(br->GetName()));
}
setRefCoreStreamer(false);
return edp;
}
}
5 changes: 5 additions & 0 deletions IOPool/Input/src/RootDelayedReader.h
Expand Up @@ -21,6 +21,7 @@ namespace edm {
class InputFile;
class RootTree;
class SharedResourcesAcquirer;
class Exception;

//------------------------------------------------------------
// Class RootDelayedReader: pretends to support file reading.
Expand Down Expand Up @@ -60,6 +61,10 @@ namespace edm {
std::unique_ptr<SharedResourcesAcquirer> resourceAcquirer_;
InputType inputType_;
TClass* wrapperBaseTClass_;
//If a fatal exception happens we need to make a copy so we can
// rethrow that exception on other threads. This avoids TTree
// non-exception safety problems on later calls to TTree.
mutable std::unique_ptr<Exception> lastException_;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this marked as mutable? Is assignment to std::unique_ptr atomic?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All calls to RootDelayedReader are already serialized by the framework.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sigh. I guess that'll do for now then.

}; // class RootDelayedReader
//------------------------------------------------------------
}
Expand Down