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 #12663

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
17 changes: 15 additions & 2 deletions IOPool/Input/src/RootDelayedReader.cc
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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_;
}; // class RootDelayedReader
//------------------------------------------------------------
}
Expand Down