CMS 3D CMS Logo

RefHolder_.h
Go to the documentation of this file.
1 #ifndef DataFormats_Common_RefHolder__h
2 #define DataFormats_Common_RefHolder__h
4 
8 #include <memory>
9 #include <typeinfo>
10 
11 namespace edm {
12  namespace reftobase {
13  //------------------------------------------------------------------
14  // Class template RefHolder<REF>
15  //------------------------------------------------------------------
16 
17  template <class REF>
18  class RefHolder : public RefHolderBase {
19  public:
20  RefHolder();
21  explicit RefHolder(REF const& ref);
22  void swap(RefHolder& other);
23  ~RefHolder() override;
24  RefHolderBase* clone() const override;
25 
26  ProductID id() const override;
27  size_t key() const override;
28  bool isEqualTo(RefHolderBase const& rhs) const override;
29  bool fillRefIfMyTypeMatches(RefHolderBase& fillme, std::string& msg) const override;
30  REF const& getRef() const;
31  void setRef(REF const& r);
32  std::unique_ptr<RefVectorHolderBase> makeVectorHolder() const override;
33  EDProductGetter const* productGetter() const override;
34 
37  bool isAvailable() const override { return ref_.isAvailable(); }
38 
39  bool isTransient() const override { return ref_.isTransient(); }
40 
41  //Needed for ROOT storage
43  private:
44  void const* pointerToType(std::type_info const& iToType) const override;
45  REF ref_;
46  };
47 
48  //------------------------------------------------------------------
49  // Implementation of RefHolder<REF>
50  //------------------------------------------------------------------
51 
52  template <class REF>
54 
55  template <class REF>
56  RefHolder<REF>::RefHolder(REF const& ref) : RefHolderBase(), ref_(ref) {}
57 
58  template <class REF>
60 
61  template <class REF>
63  return new RefHolder(ref_);
64  }
65 
66  template <class REF>
68  return ref_.id();
69  }
70 
71  template <class REF>
72  bool RefHolder<REF>::isEqualTo(RefHolderBase const& rhs) const {
73  RefHolder const* h(dynamic_cast<RefHolder const*>(&rhs));
74  return h && (getRef() == h->getRef());
75  }
76 
77  template <class REF>
79  RefHolder* h = dynamic_cast<RefHolder*>(&fillme);
80  bool conversion_worked = (h != nullptr);
81  if (conversion_worked)
82  h->setRef(ref_);
83  else
84  msg = typeid(REF).name();
85  return conversion_worked;
86  }
87 
88  template <class REF>
89  inline REF const& RefHolder<REF>::getRef() const {
90  return ref_;
91  }
92 
93  template <class REF>
95  return ref_.productGetter();
96  }
97 
98  template <class REF>
100  std::swap(ref_, other.ref_);
101  }
102 
103  template <class REF>
104  inline void RefHolder<REF>::setRef(REF const& r) {
105  ref_ = r;
106  }
107 
108  template <class REF>
109  void const* RefHolder<REF>::pointerToType(std::type_info const& iToType) const {
110  typedef typename REF::value_type contained_type;
111  if (iToType == typeid(contained_type)) {
112  return ref_.get();
113  }
114  return pointerToBase(iToType, ref_.get());
115  }
116  } // namespace reftobase
117 } // namespace edm
118 
119 #endif
edm::reftobase::RefHolder::makeVectorHolder
std::unique_ptr< RefVectorHolderBase > makeVectorHolder() const override
Definition: RefHolder.h:14
edm::reftobase::RefHolder::~RefHolder
~RefHolder() override
Definition: RefHolder_.h:59
edm
HLT enums.
Definition: AlignableModifier.h:19
h
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
Definition: L1TUtmAlgorithmRcd.h:4
edm::reftobase::RefHolderBase::RefHolderBase
RefHolderBase()
Definition: RefHolder.cc:6
OffsetToBase.h
mps_check.msg
tuple msg
Definition: mps_check.py:285
watchdog.const
const
Definition: watchdog.py:83
edm::reftobase::RefHolder::isAvailable
bool isAvailable() const override
Definition: RefHolder_.h:37
edm::reftobase::RefHolderBase
Definition: RefHolderBase.h:17
edm::pointerToBase
void const * pointerToBase(std::type_info const &baseTypeInfo, T const *address)
Definition: OffsetToBase.h:47
edm::reftobase::RefHolder::clone
RefHolderBase * clone() const override
Definition: RefHolder_.h:62
edm::EDProductGetter
Definition: EDProductGetter.h:32
edm::reftobase::RefHolder::getRef
REF const & getRef() const
Definition: RefHolder_.h:89
std::swap
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
Definition: DataFrameContainer.h:209
edm::reftobase::RefHolder::pointerToType
void const * pointerToType(std::type_info const &iToType) const override
Definition: RefHolder_.h:109
ProductID.h
edm::reftobase::RefHolder::setRef
void setRef(REF const &r)
Definition: RefHolder_.h:104
trackingPlots.other
other
Definition: trackingPlots.py:1465
edm::reftobase::RefHolder::RefHolder
RefHolder()
Definition: RefHolder_.h:53
CMS_CLASS_VERSION
#define CMS_CLASS_VERSION(_version_)
Definition: CMS_CLASS_VERSION.h:30
h
edm::reftobase::RefHolder::fillRefIfMyTypeMatches
bool fillRefIfMyTypeMatches(RefHolderBase &fillme, std::string &msg) const override
Definition: RefHolder_.h:78
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
EDProductGetter
edm::getRef
helper::MatcherGetRef< C >::ref_type getRef(const Handle< C > &c, size_t k)
Definition: getRef.h:28
RefHolderBase.h
edm::reftobase::RefHolder::isEqualTo
bool isEqualTo(RefHolderBase const &rhs) const override
Definition: RefHolder_.h:72
edm::reftobase::RefHolder::isTransient
bool isTransient() const override
Definition: RefHolder_.h:39
edm::reftobase::RefHolder::productGetter
EDProductGetter const * productGetter() const override
Definition: RefHolder_.h:94
reco::JetExtendedAssociation::value_type
Container::value_type value_type
Definition: JetExtendedAssociation.h:30
svgfig.template
def template(fileName, svg, replaceme="REPLACEME")
Definition: svgfig.py:521
edm::reftobase::RefHolder
Definition: EDProductfwd.h:50
edm::reftobase::RefHolder::id
ProductID id() const override
Definition: RefHolder_.h:67
edm::reftobase::RefHolder::swap
void swap(RefHolder &other)
Definition: RefHolder_.h:99
alignCSCRings.r
r
Definition: alignCSCRings.py:93
edm::reftobase::RefHolder::key
size_t key() const override
Definition: RefHolder.h:26
std
Definition: JetResolutionObject.h:76
CMS_CLASS_VERSION.h
edm::reftobase::RefHolder::ref_
REF ref_
Definition: RefHolder_.h:45
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
edm::ProductID
Definition: ProductID.h:27
edm::ProductID::id
ProductIndex id() const
Definition: ProductID.h:35