CMS 3D CMS Logo

Holder.h
Go to the documentation of this file.
1 
2 #ifndef DataFormats_Common_Holder_h
3 #define DataFormats_Common_Holder_h
7 #include <memory>
8 
9 namespace edm {
10  namespace reftobase {
11  //------------------------------------------------------------------
12  // Class template Holder<T,REF>
13  //------------------------------------------------------------------
14 
15  template <class T, class REF>
16  class Holder : public BaseHolder<T> {
17  public:
18  Holder();
19  Holder(Holder const& other);
20  explicit Holder(REF const& iRef);
21  Holder& operator=(Holder const& rhs);
22  void swap(Holder& other);
23  ~Holder() override;
24  BaseHolder<T>* clone() const override;
25 
26  T const* getPtr() const override;
27  ProductID id() const override;
28  size_t key() const override;
29  bool isEqualTo(BaseHolder<T> const& rhs) const override;
30  REF const& getRef() const;
31 
32  bool fillRefIfMyTypeMatches(RefHolderBase& fillme, std::string& msg) const override;
33 
34  std::unique_ptr<RefHolderBase> holder() const override {
35  return std::unique_ptr<RefHolderBase>(new RefHolder<REF>(ref_));
36  }
37  std::unique_ptr<BaseVectorHolder<T> > makeVectorHolder() const override;
38  EDProductGetter const* productGetter() const override;
39 
42  bool isAvailable() const override { return ref_.isAvailable(); }
43 
44  bool isTransient() const override { return ref_.isTransient(); }
45 
46  //Used by ROOT storage
48 
49  private:
50  REF ref_;
51  };
52 
53  //------------------------------------------------------------------
54  // Implementation of Holder<T,REF>
55  //------------------------------------------------------------------
56 
57  template <class T, class REF>
58  inline Holder<T, REF>::Holder() : BaseHolder<T>(), ref_() {}
59 
60  template <class T, class REF>
62 
63  template <class T, class REF>
64  inline Holder<T, REF>::Holder(REF const& r) : BaseHolder<T>(), ref_(r) {}
65 
66  template <class T, class REF>
68  Holder temp(rhs);
69  swap(temp);
70  return *this;
71  }
72 
73  template <class T, class REF>
75  std::swap(ref_, other.ref_);
76  }
77 
78  template <class T, class REF>
80 
81  template <class T, class REF>
83  return new Holder(*this);
84  }
85 
86  template <class T, class REF>
87  inline T const* Holder<T, REF>::getPtr() const {
88  return ref_.operator->();
89  }
90 
91  template <class T, class REF>
92  inline ProductID Holder<T, REF>::id() const {
93  return ref_.id();
94  }
95 
96  template <class T, class REF>
97  inline bool Holder<T, REF>::isEqualTo(BaseHolder<T> const& rhs) const {
98  Holder const* h = dynamic_cast<Holder const*>(&rhs);
99  return h && (getRef() == h->getRef());
100  // if (h == 0) return false;
101  // return getRef() == h->getRef();
102  }
103 
104  template <class T, class REF>
105  inline REF const& Holder<T, REF>::getRef() const {
106  return ref_;
107  }
108 
109  template <class T, class REF>
111  return ref_.productGetter();
112  }
113 
114  template <class T, class REF>
116  RefHolder<REF>* h = dynamic_cast<RefHolder<REF>*>(&fillme);
117  bool conversion_worked = (h != nullptr);
118 
119  if (conversion_worked)
120  h->setRef(ref_);
121  else
122  msg = typeid(REF).name();
123 
124  return conversion_worked;
125  }
126 
127  } // namespace reftobase
128 } // namespace edm
129 
132 
133 namespace edm {
134  namespace reftobase {
135 
136  template <typename T, typename REF>
137  std::unique_ptr<BaseVectorHolder<T> > Holder<T, REF>::makeVectorHolder() const {
138  typedef typename HolderToVectorTrait<T, REF>::type helper;
139  return helper::makeVectorHolder();
140  }
141  } // namespace reftobase
142 } // namespace edm
143 
145 
146 namespace edm {
147  namespace reftobase {
148 
149  template <class T, class REF>
150  inline size_t Holder<T, REF>::key() const {
151  typedef typename RefKeyTrait<REF>::type helper;
152  return helper::key(ref_);
153  }
154 
155  } // namespace reftobase
156 } // namespace edm
157 #endif
edm::reftobase::Holder::ref_
REF ref_
Definition: Holder.h:50
edm::reftobase::RefKey
Definition: RefKeyTrait.h:10
edm::reftobase::Holder::~Holder
~Holder() override
Definition: Holder.h:79
edm::reftobase::Holder::id
ProductID id() const override
Definition: Holder.h:92
edm::reftobase::Holder::makeVectorHolder
std::unique_ptr< BaseVectorHolder< T > > makeVectorHolder() const override
Definition: Holder.h:137
edm
HLT enums.
Definition: AlignableModifier.h:19
edm::reftobase::Holder::operator=
Holder & operator=(Holder const &rhs)
Definition: Holder.h:67
edm::reftobase::Holder::isTransient
bool isTransient() const override
Definition: Holder.h:44
edm::reftobase::Holder::Holder
Holder()
Definition: Holder.h:58
mps_check.msg
tuple msg
Definition: mps_check.py:285
edm::reftobase::Holder::holder
std::unique_ptr< RefHolderBase > holder() const override
Definition: Holder.h:34
groupFilesInBlocks.temp
list temp
Definition: groupFilesInBlocks.py:142
edm::reftobase::RefHolderBase
Definition: RefHolderBase.h:17
edm::EDProductGetter
Definition: EDProductGetter.h:32
std::swap
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
Definition: DataFrameContainer.h:209
edm::reftobase::Holder::swap
void swap(Holder &other)
Definition: Holder.h:74
RefKeyTrait.h
edm::reftobase::BaseHolder
Definition: BaseHolder.h:29
edm::reftobase::Holder::clone
BaseHolder< T > * clone() const override
Definition: Holder.h:82
trackingPlots.other
other
Definition: trackingPlots.py:1465
CMS_CLASS_VERSION
#define CMS_CLASS_VERSION(_version_)
Definition: CMS_CLASS_VERSION.h:30
h
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::getRef
helper::MatcherGetRef< C >::ref_type getRef(const Handle< C > &c, size_t k)
Definition: getRef.h:28
HolderToVectorTrait.h
edm::reftobase::Holder
Definition: EDProductfwd.h:45
RefHolder.h
helper
Definition: helper.py:1
BaseHolder.h
edm::reftobase::InvalidHolderToVector
Definition: HolderToVectorTrait.h:13
svgfig.template
def template(fileName, svg, replaceme="REPLACEME")
Definition: svgfig.py:521
edm::reftobase::Holder::getRef
REF const & getRef() const
Definition: Holder.h:105
edm::reftobase::Holder::key
size_t key() const override
Definition: Holder.h:150
edm::reftobase::RefHolder
Definition: EDProductfwd.h:50
alignCSCRings.r
r
Definition: alignCSCRings.py:93
edm::reftobase::swap
void swap(BaseHolder< T > &lhs, BaseHolder< T > &rhs)
Definition: BaseHolder.h:111
Ref.h
CMS_CLASS_VERSION.h
edm::reftobase::Holder::isEqualTo
bool isEqualTo(BaseHolder< T > const &rhs) const override
Definition: Holder.h:97
T
long double T
Definition: Basic3DVectorLD.h:48
edm::reftobase::Holder::getPtr
T const * getPtr() const override
Definition: Holder.h:87
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
edm::reftobase::Holder::productGetter
EDProductGetter const * productGetter() const override
Definition: Holder.h:110
edm::reftobase::Holder::isAvailable
bool isAvailable() const override
Definition: Holder.h:42
crabWrapper.key
key
Definition: crabWrapper.py:19
edm::ProductID
Definition: ProductID.h:27
edm::reftobase::Holder::fillRefIfMyTypeMatches
bool fillRefIfMyTypeMatches(RefHolderBase &fillme, std::string &msg) const override
Definition: Holder.h:115
edm::ProductID::id
ProductIndex id() const
Definition: ProductID.h:35