Skip to content

Commit

Permalink
Implement support for Event::getByToken for a GenericHandle
Browse files Browse the repository at this point in the history
  • Loading branch information
fwyzard committed Jan 8, 2021
1 parent 46c2452 commit 5cffea5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
12 changes: 8 additions & 4 deletions FWCore/Framework/interface/GenericHandle.h
Expand Up @@ -125,12 +125,16 @@ namespace edm {

///Specialize the Event's getByLabel method to work with a Handle<GenericObject>
template <>
bool edm::Event::getByLabel<GenericObject>(std::string const& label,
std::string const& productInstanceName,
Handle<GenericObject>& result) const;
bool Event::getByLabel<GenericObject>(std::string const& label,
std::string const& productInstanceName,
Handle<GenericObject>& result) const;

template <>
bool edm::Event::getByLabel(edm::InputTag const& tag, Handle<GenericObject>& result) const;
bool Event::getByLabel<GenericObject>(InputTag const& tag, Handle<GenericObject>& result) const;

///Specialize the Event's getByToken method to work with a Handle<GenericObject>
template <>
bool Event::getByToken<GenericObject>(EDGetToken token, Handle<GenericObject>& result) const;

} // namespace edm
#endif
22 changes: 18 additions & 4 deletions FWCore/Framework/src/GenericHandle.cc
Expand Up @@ -44,9 +44,9 @@ namespace edm {

///Specialize the getByLabel method to work with a Handle<GenericObject>
template <>
bool edm::Event::getByLabel<GenericObject>(std::string const& label,
std::string const& productInstanceName,
Handle<GenericObject>& result) const {
bool Event::getByLabel<GenericObject>(std::string const& label,
std::string const& productInstanceName,
Handle<GenericObject>& result) const {
BasicHandle bh = provRecorder_.getByLabel_(
TypeID(result.type().typeInfo()), label, productInstanceName, std::string(), moduleCallingContext_);
convert_handle(std::move(bh), result); // throws on conversion error
Expand All @@ -58,7 +58,7 @@ namespace edm {
}

template <>
bool edm::Event::getByLabel<GenericObject>(edm::InputTag const& tag, Handle<GenericObject>& result) const {
bool Event::getByLabel<GenericObject>(InputTag const& tag, Handle<GenericObject>& result) const {
if (tag.process().empty()) {
return this->getByLabel(tag.label(), tag.instance(), result);
} else {
Expand All @@ -73,4 +73,18 @@ namespace edm {
return false;
}

///Specialize the Event's getByToken method to work with a Handle<GenericObject>
template <>
bool Event::getByToken<GenericObject>(EDGetToken token, Handle<GenericObject>& result) const {
result.clear();
BasicHandle bh =
provRecorder_.getByToken_(TypeID(result.type().typeInfo()), PRODUCT_TYPE, token, moduleCallingContext_);
convert_handle(std::move(bh), result); // throws on conversion error
if (UNLIKELY(result.failedToGet())) {
return false;
}
addToGotBranchIDs(*result.provenance());
return true;
}

} // namespace edm

0 comments on commit 5cffea5

Please sign in to comment.