CMS 3D CMS Logo

CollHandle.h
Go to the documentation of this file.
1 /*
2  */
3 
4 #ifndef EcalDigis_CollHandle_h
5 #define EcalDigis_CollHandle_h
6 
11 
24 template <class T>
25 class CollHandle {
26  //constructor(s) and destructor(s)
27 public:
33  CollHandle(const edm::InputTag& tag, bool failIfNotFound = true, bool notFoundWarn = true)
34  : tag_(tag),
35  token_(),
38  failIfNotFound_(failIfNotFound),
39  notFoundWarn_(notFoundWarn) {}
40 
41  //method(s)
42 public:
43  /*
44  Receives the "ConsumesCollector" from the EDAnalyzer and declares the usage
45  of the collection, as well as storing the token for it.
46  */
47 
48  void setToken(edm::ConsumesCollector& collector) { token_ = collector.consumes<T>(tag_); }
49 
58  void read(const edm::Event& event) {
59  // try{
60  edm::Handle<T> hColl;
61  event.getByToken(token_, hColl);
62 
63  //If we must be tolerant to product absence, then
64  //we must check validaty before calling Handle::operator*
65  //to prevent exception throw:
66  if (!failIfNotFound_ // product-not-found tolerant mode
67  && !hColl.isValid()) { // and the product was not found
68  if (notFoundWarn_ && !notFoundAlreadyWarned_) { //warning logged only once
69  edm::LogWarning("ProductNotFound") << tag_
70  << " product "
71  "of type '"
72  << typeid(T).name() << "' was not found!";
74  }
76  } else {
77  currentColl_ = &(*hColl);
78  }
79  }
80 
84  const T* operator->() const { return currentColl_; }
85 
89  const T& operator*() const { return *currentColl_; }
90 
91  edm::InputTag tag() const { return tag_; }
92 
93 private:
94  //attribute(s)
95 protected:
96 private:
100 
101  /* EDM "Token" that is used in the actual data retrieval */
103 
106  const T* currentColl_;
107 
111  const T emptyColl_;
112 
116 
120 
124 };
125 
126 #endif
CollHandle::operator->
const T * operator->() const
Definition: CollHandle.h:84
MessageLogger.h
funct::false
false
Definition: Factorize.h:29
edm::EDGetTokenT
Definition: EDGetToken.h:33
CollHandle::failIfNotFound_
bool failIfNotFound_
Definition: CollHandle.h:119
edm::Handle
Definition: AssociativeIterator.h:50
edm::LogWarning
Log< level::Warning, false > LogWarning
Definition: MessageLogger.h:122
CollHandle::notFoundAlreadyWarned_
bool notFoundAlreadyWarned_
Definition: CollHandle.h:115
CollHandle::emptyColl_
const T emptyColl_
Definition: CollHandle.h:111
edm::ConsumesCollector::consumes
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
Definition: ConsumesCollector.h:55
CollHandle::notFoundWarn_
bool notFoundWarn_
Definition: CollHandle.h:123
CollHandle::currentColl_
const T * currentColl_
Definition: CollHandle.h:106
Event.h
CollHandle::token_
edm::EDGetTokenT< T > token_
Definition: CollHandle.h:102
CollHandle
Definition: CollHandle.h:25
InputTag.h
CollHandle::operator*
const T & operator*() const
Definition: CollHandle.h:89
T
long double T
Definition: Basic3DVectorLD.h:48
CollHandle::read
void read(const edm::Event &event)
Definition: CollHandle.h:58
CollHandle::setToken
void setToken(edm::ConsumesCollector &collector)
Definition: CollHandle.h:48
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
CollHandle::CollHandle
CollHandle(const edm::InputTag &tag, bool failIfNotFound=true, bool notFoundWarn=true)
Definition: CollHandle.h:33
ConsumesCollector.h
edm::HandleBase::isValid
bool isValid() const
Definition: HandleBase.h:70
event
Definition: event.py:1
edm::Event
Definition: Event.h:73
edm::InputTag
Definition: InputTag.h:15
edm::ConsumesCollector
Definition: ConsumesCollector.h:45
CollHandle::tag_
const edm::InputTag tag_
Definition: CollHandle.h:99
CollHandle::tag
edm::InputTag tag() const
Definition: CollHandle.h:91