Skip to content

Commit

Permalink
General RefToBase to Ptr conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
nsmith- committed Nov 17, 2023
1 parent 7d99d30 commit 156bb7e
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions DataFormats/Common/interface/RefToBaseToPtr.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#ifndef DataFormats_Common_RefToPtr_h
#define DataFormats_Common_RefToPtr_h

/*----------------------------------------------------------------------
Ref: A function template for conversion from RefToBase to Ptr
----------------------------------------------------------------------*/
/*
----------------------------------------------------------------------*/

#include "DataFormats/Common/interface/RefToBase.h"
#include "DataFormats/Common/interface/Ptr.h"

namespace edm {
template <typename T>
Ptr<T> refToBaseToPtr(RefToBase<T> const& ref) {
if (ref.isNull()) {
return Ptr<T>();
}
if (ref.isTransient()) {
return Ptr<T>(ref.get(), ref.key());
} else {
//Another thread could change this value so get only once
EDProductGetter const* getter = ref.productGetter();
if (getter) {
return Ptr<T>(ref.id(), ref.key(), getter);
}
}
// If this is called in an iorule outside the framework, we cannot call
// ref.get() but since the Ptr will be able to get it later anyway, we can
// fill with a nullptr for now
return Ptr<T>(ref.id(), static_cast<const T*>(nullptr), ref.key());
}
} // namespace edm
#endif

0 comments on commit 156bb7e

Please sign in to comment.