CMS 3D CMS Logo

Handle.h
Go to the documentation of this file.
1 #ifndef DataFormats_FWLite_Handle_h
2 #define DataFormats_FWLite_Handle_h
3 // -*- C++ -*-
4 //
5 // Package: FWLite
6 // Class : Handle
7 //
16 //
17 // Original Author: Chris Jones
18 // Created: Tue May 8 15:01:26 EDT 2007
19 //
20 
21 // system include files
22 
23 // user include files
24 namespace edm {
25  template <typename T>
26  class Wrapper;
27 }
28 
32 
33 // forward declarations
34 namespace fwlite {
35  class ErrorThrower;
36  class EventBase;
37 
38  template <class T>
39  class Handle {
40  public:
41  // this typedef is to avoid a Cint bug where calling
42  // edm::Wrapper<T>::typeInfo() fails for some types with
43  // very long expansions. First noticed for the expansion
44  // of reco::JetTracksAssociation::Container
46 
47  Handle() : data_(nullptr), errorThrower_(ErrorThrower::unsetErrorThrower()) {}
48  ~Handle() { delete errorThrower_; }
49 
50  Handle(const Handle<T>& iOther)
51  : data_(iOther.data_), errorThrower_(iOther.errorThrower_ ? iOther.errorThrower_->clone() : nullptr) {}
52 
53  const Handle<T>& operator=(const Handle<T>& iOther) {
54  Handle<T> temp(iOther);
55  swap(temp);
56  return *this;
57  }
58 
59  // ---------- const member functions ---------------------
60  bool isValid() const { return data_ != nullptr; }
61 
63  bool failedToGet() const { return errorThrower_ != nullptr; }
64 
65  T const* product() const {
66  check();
67  return data_;
68  }
69 
70  const T* ptr() const {
71  check();
72  return data_;
73  }
74  const T& ref() const {
75  check();
76  return *data_;
77  }
78 
79  const T* operator->() const {
80  check();
81  return data_;
82  }
83 
84  const T& operator*() const {
85  check();
86  return *data_;
87  }
88  // ---------- static member functions --------------------
89 
90  // ---------- member functions ---------------------------
91  /*
92  void getByBranchName(const fwlite::Event& iEvent, const char* iBranchName) {
93  iEvent.getByBranchName(edm::Wrapper<T>::typeInfo(), iBranchName, data_);
94  }
95  */
96 
97  // P can be Run, Event, or LuminosityBlock
98 
99  template <class P>
100  void getByLabel(const P& iP,
101  const char* iModuleLabel,
102  const char* iProductInstanceLabel = nullptr,
103  const char* iProcessLabel = nullptr) {
104  TempWrapT* temp;
105  void* pTemp = &temp;
106  iP.getByLabel(TempWrapT::typeInfo(), iModuleLabel, iProductInstanceLabel, iProcessLabel, pTemp);
107  delete errorThrower_;
108  errorThrower_ = nullptr;
109  if (nullptr == temp) {
111  TempWrapT::typeInfo(), iModuleLabel, iProductInstanceLabel, iProcessLabel);
112  return;
113  }
114  data_ = temp->product();
115  if (data_ == nullptr) {
117  TempWrapT::typeInfo(), iModuleLabel, iProductInstanceLabel, iProcessLabel);
118  }
119  }
120 
121  // void getByLabel(const fwlite::Event& iEvent,
122  // const char* iModuleLabel,
123  // const char* iProductInstanceLabel = nullptr,
124  // const char* iProcessLabel = nullptr) {
125  // TempWrapT* temp;
126  // void* pTemp = &temp;
127  // iEvent.getByLabel(TempWrapT::typeInfo(),
128  // iModuleLabel,
129  // iProductInstanceLabel,
130  // iProcessLabel,
131  // pTemp);
132  // delete errorThrower_;
133  // errorThrower_ = nullptr;
134  // if(nullptr == temp) {
135  // errorThrower_=ErrorThrower::errorThrowerBranchNotFoundException(TempWrapT::typeInfo(),
136  // iModuleLabel,
137  // iProductInstanceLabel,
138  // iProcessLabel);
139  // return;
140  // }
141  // data_ = temp->product();
142  // if(data_ == nullptr) {
143  // errorThrower_=ErrorThrower::errorThrowerProductNotFoundException(TempWrapT::typeInfo(),
144  // iModuleLabel,
145  // iProductInstanceLabel,
146  // iProcessLabel);
147  // }
148  // }
149  //
150  // void getByLabel(const fwlite::ChainEvent& iEvent,
151  // const char* iModuleLabel,
152  // const char* iProductInstanceLabel = nullptr,
153  // const char* iProcessLabel = nullptr) {
154  // TempWrapT* temp;
155  // void* pTemp = &temp;
156  // iEvent.getByLabel(TempWrapT::typeInfo(),
157  // iModuleLabel,
158  // iProductInstanceLabel,
159  // iProcessLabel,
160  // pTemp);
161  // delete errorThrower_;
162  // errorThrower_ = nullptr;
163  // if(nullptr == temp) {
164  // errorThrower_=ErrorThrower::errorThrowerBranchNotFoundException(TempWrapT::typeInfo(),
165  // iModuleLabel,
166  // iProductInstanceLabel,
167  // iProcessLabel);
168  // return;
169  // }
170  // data_ = temp->product();
171  // if(data_ == nullptr) {
172  // errorThrower_=ErrorThrower::errorThrowerProductNotFoundException(TempWrapT::typeInfo(),
173  // iModuleLabel,
174  // iProductInstanceLabel,
175  // iProcessLabel);
176  // }
177  // }
178  //
179  //
180  // void getByLabel(const fwlite::MultiChainEvent& iEvent,
181  // const char* iModuleLabel,
182  // const char* iProductInstanceLabel = nullptr,
183  // const char* iProcessLabel = nullptr) {
184  // TempWrapT* temp;
185  // void* pTemp = &temp;
186  // iEvent.getByLabel(TempWrapT::typeInfo(),
187  // iModuleLabel,
188  // iProductInstanceLabel,
189  // iProcessLabel,
190  // pTemp);
191  // if ( nullptr != errorThrower_ ) delete errorThrower_;
192  // errorThrower_ = nullptr;
193  // if(nullptr == temp) {
194  // errorThrower_=ErrorThrower::errorThrowerBranchNotFoundException(TempWrapT::typeInfo(),
195  // iModuleLabel,
196  // iProductInstanceLabel,
197  // iProcessLabel);
198  // return;
199  // }
200  // data_ = temp->product();
201  // if(data_ == nullptr) {
202  // errorThrower_=ErrorThrower::errorThrowerProductNotFoundException(TempWrapT::typeInfo(),
203  // iModuleLabel,
204  // iProductInstanceLabel,
205  // iProcessLabel);
206  // }
207  // }
208 
210  const char* iModuleLabel,
211  const char* iProductInstanceLabel = nullptr,
212  const char* iProcessLabel = nullptr) {
213  return iEvent.getBranchNameFor(TempWrapT::typeInfo(), iModuleLabel, iProductInstanceLabel, iProcessLabel);
214  }
215 
216  // const std::string getBranchNameFor(const fwlite::Event& iEvent,
217  // const char* iModuleLabel,
218  // const char* iProductInstanceLabel = nullptr,
219  // const char* iProcessLabel = nullptr) {
220  // return iEvent.getBranchNameFor(TempWrapT::typeInfo(),
221  // iModuleLabel,
222  // iProductInstanceLabel,
223  // iProcessLabel);
224  // }
225  //
226  // const std::string getBranchNameFor(const fwlite::ChainEvent& iEvent,
227  // const char* iModuleLabel,
228  // const char* iProductInstanceLabel = nullptr,
229  // const char* iProcessLabel = nullptr) {
230  // return iEvent.getBranchNameFor(TempWrapT::typeInfo(),
231  // iModuleLabel,
232  // iProductInstanceLabel,
233  // iProcessLabel);
234  // }
235  //
236  //
237  //
238  // const std::string getBranchNameFor(const fwlite::MultiChainEvent& iEvent,
239  // const char* iModuleLabel,
240  // const char* iProductInstanceLabel = nullptr,
241  // const char* iProcessLabel = nullptr) {
242  // return iEvent.getBranchNameFor(TempWrapT::typeInfo(),
243  // iModuleLabel,
244  // iProductInstanceLabel,
245  // iProcessLabel);
246  // }
247 
248  void swap(Handle<T>& iOther) {
249  const T* temp = data_;
250  data_ = iOther.data_;
251  iOther.data_ = temp;
252  ErrorThrower const* tempE = errorThrower_;
253  errorThrower_ = iOther.errorThrower_;
254  iOther.errorThrower_ = tempE;
255  }
256 
257  private:
258  void check() const {
259  if (errorThrower_) {
261  }
262  }
263 
264  // ---------- member data --------------------------------
265  const T* data_;
267  };
268 
269 } // namespace fwlite
270 
271 #endif
fwlite::Handle::~Handle
~Handle()
Definition: Handle.h:48
fwlite
Definition: TFileDirectory.h:16
fwlite::Handle::swap
void swap(Handle< T > &iOther)
Definition: Handle.h:248
edm
HLT enums.
Definition: AlignableModifier.h:19
fwlite::Handle::data_
const T * data_
Definition: Handle.h:265
fwlite::ErrorThrower::errorThrowerProductNotFoundException
static ErrorThrower * errorThrowerProductNotFoundException(const std::type_info &, const char *, const char *, const char *)
Definition: ErrorThrower.cc:125
groupFilesInBlocks.temp
list temp
Definition: groupFilesInBlocks.py:142
fwlite::Handle::check
void check() const
Definition: Handle.h:258
fwlite::Handle::Handle
Handle(const Handle< T > &iOther)
Definition: Handle.h:50
edm::Wrapper
Definition: Product.h:10
EventBase.h
fwlite::Handle
Definition: Handle.h:39
fwlite::Handle::Handle
Handle()
Definition: Handle.h:47
clone
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
Definition: eve_macros.cc:135
fwlite::ErrorThrower::throwIt
virtual void throwIt() const =0
fwlite::Handle::TempWrapT
edm::Wrapper< T > TempWrapT
Definition: Handle.h:45
ErrorThrower.h
fwlite::Handle::ref
const T & ref() const
Definition: Handle.h:74
fwlite::Handle::getBranchNameFor
const std::string getBranchNameFor(const fwlite::EventBase &iEvent, const char *iModuleLabel, const char *iProductInstanceLabel=nullptr, const char *iProcessLabel=nullptr)
Definition: Handle.h:209
iEvent
int iEvent
Definition: GenABIO.cc:224
edm::Wrapper::typeInfo
static std::type_info const & typeInfo()
Definition: Wrapper.h:43
fwlite::Handle::isValid
bool isValid() const
Definition: Handle.h:60
fwlite::ErrorThrower::errorThrowerBranchNotFoundException
static ErrorThrower * errorThrowerBranchNotFoundException(const std::type_info &, const char *, const char *, const char *)
Definition: ErrorThrower.cc:118
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
fwlite::ErrorThrower
Definition: ErrorThrower.h:28
fwlite::EventBase
Definition: EventBase.h:36
fwlite::Handle::getByLabel
void getByLabel(const P &iP, const char *iModuleLabel, const char *iProductInstanceLabel=nullptr, const char *iProcessLabel=nullptr)
Definition: Handle.h:100
fwlite::Handle::ptr
const T * ptr() const
Definition: Handle.h:70
ErrorThrower
fwlite::Handle::operator=
const Handle< T > & operator=(const Handle< T > &iOther)
Definition: Handle.h:53
Wrapper.h
T
long double T
Definition: Basic3DVectorLD.h:48
EventBase
fwlite::Handle::errorThrower_
ErrorThrower const * errorThrower_
Definition: Handle.h:266
fwlite::Handle::failedToGet
bool failedToGet() const
Returns true only if Handle was used in a 'get' call and the data could not be found.
Definition: Handle.h:63
fwlite::Handle::operator*
const T & operator*() const
Definition: Handle.h:84
fwlite::Handle::operator->
const T * operator->() const
Definition: Handle.h:79
P
std::pair< OmniClusterRef, TrackingParticleRef > P
Definition: BDHadronTrackMonitoringAnalyzer.cc:203
fwlite::Handle::product
T const * product() const
Definition: Handle.h:65