CMS 3D CMS Logo

IndirectHolder.h
Go to the documentation of this file.
1 #ifndef DataFormats_Common_IndirectHolder_h
2 #define DataFormats_Common_IndirectHolder_h
7 
8 #include <memory>
9 
10 namespace edm {
11  template <typename T>
12  class RefToBase;
13 
14  namespace reftobase {
15 
16  template <typename T>
18  class RefVectorHolderBase;
19  class RefHolderBase;
20 
21  //------------------------------------------------------------------
22  // Class template IndirectHolder<T>
23  //------------------------------------------------------------------
24 
25  template <typename T>
26  class IndirectHolder : public BaseHolder<T> {
27  public:
28  // It may be better to use unique_ptr<RefHolderBase> in
29  // this constructor, so that the cloning can be avoided. I'm not
30  // sure if use of unique_ptr here causes any troubles elsewhere.
31  IndirectHolder() : BaseHolder<T>(), helper_(nullptr) {}
32  IndirectHolder(std::shared_ptr<RefHolderBase> p);
33  template <typename U>
34  IndirectHolder(std::unique_ptr<U> p) : helper_(p.release()) {}
37  void swap(IndirectHolder& other);
38  ~IndirectHolder() override;
39 
40  BaseHolder<T>* clone() const override;
41  T const* getPtr() const override;
42  ProductID id() const override;
43  size_t key() const override;
44  bool isEqualTo(BaseHolder<T> const& rhs) const override;
45 
46  bool fillRefIfMyTypeMatches(RefHolderBase& fillme, std::string& msg) const override;
47  std::unique_ptr<RefHolderBase> holder() const override;
48  std::unique_ptr<BaseVectorHolder<T> > makeVectorHolder() const override;
49  EDProductGetter const* productGetter() const override;
50 
53  bool isAvailable() const override { return helper_->isAvailable(); }
54 
55  bool isTransient() const override { return helper_->isTransient(); }
56 
57  //Used by ROOT storage
59 
60  private:
61  friend class RefToBase<T>;
62  friend class IndirectVectorHolder<T>;
64  };
65  //------------------------------------------------------------------
66  // Implementation of IndirectHolder<T>
67  //------------------------------------------------------------------
68  template <typename T>
69  inline IndirectHolder<T>::IndirectHolder(std::shared_ptr<RefHolderBase> p) : BaseHolder<T>(), helper_(p->clone()) {}
70 
71  template <typename T>
74 
75  template <typename T>
77  this->BaseHolder<T>::swap(other);
78  std::swap(helper_, other.helper_);
79  }
80 
81  template <typename T>
83  IndirectHolder temp(rhs);
84  swap(temp);
85  return *this;
86  }
87 
88  template <typename T>
90  delete helper_;
91  }
92 
93  template <typename T>
95  return new IndirectHolder<T>(*this);
96  }
97 
98  template <typename T>
99  T const* IndirectHolder<T>::getPtr() const {
100  return helper_->template getPtr<T>();
101  }
102 
103  template <typename T>
105  return helper_->id();
106  }
107 
108  template <typename T>
109  size_t IndirectHolder<T>::key() const {
110  return helper_->key();
111  }
112 
113  template <typename T>
115  return helper_->productGetter();
116  }
117 
118  template <typename T>
120  IndirectHolder const* h = dynamic_cast<IndirectHolder const*>(&rhs);
121  return h && helper_->isEqualTo(*h->helper_);
122  }
123 
124  template <typename T>
126  return helper_->fillRefIfMyTypeMatches(fillme, msg);
127  }
128 
129  template <typename T>
130  std::unique_ptr<RefHolderBase> IndirectHolder<T>::holder() const {
131  return std::unique_ptr<RefHolderBase>(helper_->clone());
132  }
133 
134  // Free swap function
135  template <typename T>
136  inline void swap(IndirectHolder<T>& lhs, IndirectHolder<T>& rhs) {
137  lhs.swap(rhs);
138  }
139  } // namespace reftobase
140 
141 } // namespace edm
142 
145 
146 namespace edm {
147  namespace reftobase {
148  template <typename T>
149  std::unique_ptr<BaseVectorHolder<T> > IndirectHolder<T>::makeVectorHolder() const {
150  std::unique_ptr<RefVectorHolderBase> p = helper_->makeVectorHolder();
151  std::shared_ptr<RefVectorHolderBase> sp(p.release());
152  return std::unique_ptr<BaseVectorHolder<T> >(new IndirectVectorHolder<T>(sp));
153  }
154  } // namespace reftobase
155 } // namespace edm
156 
157 #endif
edm::reftobase::IndirectHolder::swap
void swap(IndirectHolder &other)
Definition: IndirectHolder.h:76
edm::reftobase::IndirectHolder::productGetter
EDProductGetter const * productGetter() const override
Definition: IndirectHolder.h:114
RefVectorHolderBase.h
edm
HLT enums.
Definition: AlignableModifier.h:19
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
edm::reftobase::IndirectHolder::getPtr
T const * getPtr() const override
Definition: IndirectHolder.h:99
IndirectVectorHolder.h
edm::reftobase::RefVectorHolderBase
Definition: RefVectorHolderBase.h:13
mps_check.msg
tuple msg
Definition: mps_check.py:285
edm::reftobase::IndirectHolder::isTransient
bool isTransient() const override
Definition: IndirectHolder.h:55
groupFilesInBlocks.temp
list temp
Definition: groupFilesInBlocks.py:142
edm::reftobase::RefHolderBase::isAvailable
virtual bool isAvailable() const =0
edm::reftobase::IndirectHolder::fillRefIfMyTypeMatches
bool fillRefIfMyTypeMatches(RefHolderBase &fillme, std::string &msg) const override
Definition: IndirectHolder.h:125
edm::reftobase::IndirectHolder::isAvailable
bool isAvailable() const override
Definition: IndirectHolder.h:53
edm::reftobase::RefHolderBase
Definition: RefHolderBase.h:17
edm::reftobase::IndirectHolder::~IndirectHolder
~IndirectHolder() override
Definition: IndirectHolder.h:89
edm::EDProductGetter
Definition: EDProductGetter.h:41
std::swap
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
Definition: DataFrameContainer.h:209
edm::reftobase::IndirectHolder::makeVectorHolder
std::unique_ptr< BaseVectorHolder< T > > makeVectorHolder() const override
Definition: IndirectHolder.h:149
ProductID.h
edm::reftobase::BaseHolder
Definition: BaseHolder.h:29
trackingPlots.other
other
Definition: trackingPlots.py:1467
edm::reftobase::IndirectHolder::isEqualTo
bool isEqualTo(BaseHolder< T > const &rhs) const override
Definition: IndirectHolder.h:119
CMS_CLASS_VERSION
#define CMS_CLASS_VERSION(_version_)
Definition: CMS_CLASS_VERSION.h:30
h
edm::reftobase::BaseHolder::swap
void swap(BaseHolder &)
Definition: BaseHolder.h:105
edm::reftobase::IndirectHolder::operator=
IndirectHolder & operator=(IndirectHolder const &rhs)
Definition: IndirectHolder.h:82
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::reftobase::IndirectVectorHolder
Definition: IndirectHolder.h:17
fetchall_from_DQM_v2.release
release
Definition: fetchall_from_DQM_v2.py:92
edm::reftobase::IndirectHolder::helper_
RefHolderBase * helper_
Definition: IndirectHolder.h:63
RefHolderBase.h
BaseHolder.h
RefToBase
edm::reftobase::IndirectHolder::IndirectHolder
IndirectHolder()
Definition: IndirectHolder.h:31
svgfig.template
def template(fileName, svg, replaceme="REPLACEME")
Definition: svgfig.py:521
edm::reftobase::IndirectHolder::IndirectHolder
IndirectHolder(std::unique_ptr< U > p)
Definition: IndirectHolder.h:34
edm::reftobase::IndirectHolder
Definition: EDProductfwd.h:48
edm::reftobase::swap
void swap(BaseHolder< T > &lhs, BaseHolder< T > &rhs)
Definition: BaseHolder.h:111
edm::reftobase::IndirectHolder::id
ProductID id() const override
Definition: IndirectHolder.h:104
std
Definition: JetResolutionObject.h:76
CMS_CLASS_VERSION.h
T
long double T
Definition: Basic3DVectorLD.h:48
edm::reftobase::RefHolderBase::isTransient
virtual bool isTransient() const =0
edm::RefToBase
Definition: AssociativeIterator.h:54
edm::reftobase::IndirectHolder::holder
std::unique_ptr< RefHolderBase > holder() const override
Definition: IndirectHolder.h:130
edm::reftobase::IndirectHolder::key
size_t key() const override
Definition: IndirectHolder.h:109
edm::reftobase::IndirectHolder::clone
BaseHolder< T > * clone() const override
Definition: IndirectHolder.h:94
edm::ProductID
Definition: ProductID.h:27
edm::ProductID::id
ProductIndex id() const
Definition: ProductID.h:35