CMS 3D CMS Logo

List of all members | Public Member Functions | Private Attributes
CollHandle< T > Class Template Reference

#include <CollHandle.h>

Public Member Functions

 CollHandle (const edm::InputTag &tag, bool failIfNotFound=true, bool notFoundWarn=true)
 
const Toperator* () const
 
const Toperator-> () const
 
void read (const edm::Event &event)
 
void setToken (edm::ConsumesCollector &collector)
 
edm::InputTag tag () const
 

Private Attributes

const TcurrentColl_
 
const T emptyColl_
 
bool failIfNotFound_
 
bool notFoundAlreadyWarned_
 
bool notFoundWarn_
 
const edm::InputTag tag_
 
edm::EDGetTokenT< Ttoken_
 

Detailed Description

template<class T>
class CollHandle< T >

Utilitity class for handling an EDM data collection. This class acts as a wrapper of the EDM collection.

An InputTag indentifying the collection is passed to the constructor. The collection is retrieved from the event by a call to the read() method. The CollHandle class instance can then be used as a pointer to the retrieved collection.

Absence of the collection from the event can be optionnaly tolerated: see failIfNotFound parameter of the CollHandle() constructor.

In case the collection was not (yet) retrieved from the collection, it acts as a pointers to an empty collection.

The templace parameter T specifies the type of the data collection.

Definition at line 25 of file CollHandle.h.

Constructor & Destructor Documentation

◆ CollHandle()

template<class T>
CollHandle< T >::CollHandle ( const edm::InputTag tag,
bool  failIfNotFound = true,
bool  notFoundWarn = true 
)
inline

Constructs a CollHandle.

Parameters
tagInputTag identifying the data collection
failIfNotFoundpass true if the absence of the collection in the event must be considered as an error. See read() method.

Definition at line 33 of file CollHandle.h.

34  : tag_(tag),
35  token_(),
38  failIfNotFound_(failIfNotFound),
39  notFoundWarn_(notFoundWarn) {}

Member Function Documentation

◆ operator*()

template<class T>
const T& CollHandle< T >::operator* ( void  ) const
inline

Gets the collection retrieved by read() method. If the collection was absent from the event an empty collection is returned.

Definition at line 89 of file CollHandle.h.

89 { return *currentColl_; }

◆ operator->()

template<class T>
const T* CollHandle< T >::operator-> ( ) const
inline

Accessor to a member of the collection retrieved by read method(). Considering h a CollHandle instance, h->f() is equivalent to (*h).f().

Definition at line 84 of file CollHandle.h.

84 { return currentColl_; }

◆ read()

template<class T>
void CollHandle< T >::read ( const edm::Event event)
inline

Retrieves the collection from the event. If failIfNotFound is true and the collection is not found, then an edm::Exception is thrown. For other case of exception throw see edm::Event::getByToken() method documentation. If failIfNotFound is false and the collection is not found, an empty collection is used; a warn message will be logged the first time the collection is not found.

Parameters
eventthe EDM event the collection must be retrieved from.

Definition at line 58 of file CollHandle.h.

58  {
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  }

Referenced by EcalSelectiveReadoutValidation::readAllCollections().

◆ setToken()

template<class T>
void CollHandle< T >::setToken ( edm::ConsumesCollector collector)
inline

Definition at line 48 of file CollHandle.h.

48 { token_ = collector.consumes<T>(tag_); }

Referenced by EcalSelectiveReadoutValidation::EcalSelectiveReadoutValidation().

◆ tag()

template<class T>
edm::InputTag CollHandle< T >::tag ( ) const
inline

Definition at line 91 of file CollHandle.h.

91 { return tag_; }

Member Data Documentation

◆ currentColl_

template<class T>
const T* CollHandle< T >::currentColl_
private

Pointer to the last read collection, points to emptColl be default

Definition at line 106 of file CollHandle.h.

Referenced by CollHandle< EEDigiCollection >::operator*(), CollHandle< EEDigiCollection >::operator->(), and CollHandle< EEDigiCollection >::read().

◆ emptyColl_

template<class T>
const T CollHandle< T >::emptyColl_
private

An empty collection used as default when the collection was not retrieved from the event.

Definition at line 111 of file CollHandle.h.

Referenced by CollHandle< EEDigiCollection >::read().

◆ failIfNotFound_

template<class T>
bool CollHandle< T >::failIfNotFound_
private

Switch for collection absence toleration.

Definition at line 119 of file CollHandle.h.

Referenced by CollHandle< EEDigiCollection >::read().

◆ notFoundAlreadyWarned_

template<class T>
bool CollHandle< T >::notFoundAlreadyWarned_
private

Used to emit warn message in case of collection absence only once.

Definition at line 115 of file CollHandle.h.

Referenced by CollHandle< EEDigiCollection >::read().

◆ notFoundWarn_

template<class T>
bool CollHandle< T >::notFoundWarn_
private

Switch for the warning in case of not found collection

Definition at line 123 of file CollHandle.h.

Referenced by CollHandle< EEDigiCollection >::read().

◆ tag_

template<class T>
const edm::InputTag CollHandle< T >::tag_
private

tag identifying the data collecion

Definition at line 99 of file CollHandle.h.

Referenced by CollHandle< EEDigiCollection >::read(), CollHandle< EEDigiCollection >::setToken(), and CollHandle< EEDigiCollection >::tag().

◆ token_

template<class T>
edm::EDGetTokenT<T> CollHandle< T >::token_
private
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
CollHandle::token_
edm::EDGetTokenT< T > token_
Definition: CollHandle.h:102
T
long double T
Definition: Basic3DVectorLD.h:48
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
edm::HandleBase::isValid
bool isValid() const
Definition: HandleBase.h:70
CollHandle::tag_
const edm::InputTag tag_
Definition: CollHandle.h:99
CollHandle::tag
edm::InputTag tag() const
Definition: CollHandle.h:91