Validation
EcalDigis
src
CollHandle.h
Go to the documentation of this file.
1
/*
2
*/
3
4
#ifndef EcalDigis_CollHandle_h
5
#define EcalDigis_CollHandle_h
6
7
#include "
FWCore/Utilities/interface/InputTag.h
"
8
#include "
FWCore/Framework/interface/Event.h
"
9
#include "
FWCore/Framework/interface/ConsumesCollector.h
"
10
#include "
FWCore/MessageLogger/interface/MessageLogger.h
"
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_
(),
36
currentColl_
(&
emptyColl_
),
37
notFoundAlreadyWarned_
(
false
),
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!"
;
73
notFoundAlreadyWarned_
=
true
;
74
}
75
currentColl_
= &
emptyColl_
;
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
:
99
const
edm::InputTag
tag_
;
100
101
/* EDM "Token" that is used in the actual data retrieval */
102
edm::EDGetTokenT<T>
token_
;
103
106
const
T
*
currentColl_
;
107
111
const
T
emptyColl_
;
112
115
bool
notFoundAlreadyWarned_
;
116
119
bool
failIfNotFound_
;
120
123
bool
notFoundWarn_
;
124
};
125
126
#endif
CollHandle::operator->
const T * operator->() const
Definition:
CollHandle.h:84
MessageLogger.h
funct::false
false
Definition:
Factorize.h:34
edm::EDGetTokenT
Definition:
EDGetToken.h:33
CollHandle::failIfNotFound_
bool failIfNotFound_
Definition:
CollHandle.h:119
edm::Handle
Definition:
AssociativeIterator.h:50
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:49
CollHandle::notFoundWarn_
bool notFoundWarn_
Definition:
CollHandle.h:123
edm::LogWarning
Definition:
MessageLogger.h:141
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:39
CollHandle::tag_
const edm::InputTag tag_
Definition:
CollHandle.h:99
CollHandle::tag
edm::InputTag tag() const
Definition:
CollHandle.h:91
Generated for CMSSW Reference Manual by
1.8.16