#include <CollHandle.h>
Public Member Functions | |
CollHandle (const edm::InputTag &tag, bool failIfNotFound=true, bool notFoundWarn=true) | |
const T & | operator* () const |
const T * | operator-> () const |
void | read (const edm::Event &event) |
edm::InputTag | tag () const |
Private Attributes | |
const T * | currentColl_ |
const T | emptyColl_ |
bool | failIfNotFound_ |
bool | notFoundAlreadyWarned_ |
bool | notFoundWarn_ |
const edm::InputTag | tag_ |
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.
CollHandle< T >::CollHandle | ( | const edm::InputTag & | tag, |
bool | failIfNotFound = true , |
||
bool | notFoundWarn = true |
||
) | [inline] |
Constructs a CollHandle.
tag | InputTag identifying the data collection |
failIfNotFound | pass 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.
: tag_(tag), currentColl_(&emptyColl_), notFoundAlreadyWarned_(false), failIfNotFound_(failIfNotFound), notFoundWarn_(notFoundWarn){}
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 83 of file CollHandle.h.
{ return *currentColl_;}
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 78 of file CollHandle.h.
{ return currentColl_;}
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::getByLabel() 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.
event | the EDM event the collection must be retrieved from. |
Definition at line 51 of file CollHandle.h.
Referenced by EcalSelectiveReadoutValidation::readAllCollections().
{ // try{ edm::Handle<T> hColl; event.getByLabel(tag_, hColl); //If we must be tolerant to product absence, then //we must check validaty before calling Handle::operator* //to prevent exception throw: if(!failIfNotFound_ // product-not-found tolerant mode && !hColl.isValid()){// and the product was not found if(notFoundWarn_ && !notFoundAlreadyWarned_){//warning logged only once edm::LogWarning("ProductNotFound") << tag_ << " product " "of type '" << typeid(T).name() << "' was not found!"; notFoundAlreadyWarned_ = true; } currentColl_ = &emptyColl_; } else { currentColl_ = &(*hColl); } }
edm::InputTag CollHandle< T >::tag | ( | ) | const [inline] |
Definition at line 85 of file CollHandle.h.
{ return tag_; }
const T* CollHandle< T >::currentColl_ [private] |
Pointer to the last read collection, points to emptColl be default
Definition at line 98 of file CollHandle.h.
Referenced by CollHandle< EEDigiCollection >::operator*(), CollHandle< EEDigiCollection >::operator->(), and CollHandle< EEDigiCollection >::read().
const T CollHandle< T >::emptyColl_ [private] |
An empty collection used as default when the collection was not retrieved from the event.
Definition at line 103 of file CollHandle.h.
Referenced by CollHandle< EEDigiCollection >::read().
bool CollHandle< T >::failIfNotFound_ [private] |
Switch for collection absence toleration.
Definition at line 111 of file CollHandle.h.
Referenced by CollHandle< EEDigiCollection >::read().
bool CollHandle< T >::notFoundAlreadyWarned_ [private] |
Used to emit warn message in case of collection absence only once.
Definition at line 107 of file CollHandle.h.
Referenced by CollHandle< EEDigiCollection >::read().
bool CollHandle< T >::notFoundWarn_ [private] |
Switch for the warning in case of not found collection
Definition at line 115 of file CollHandle.h.
Referenced by CollHandle< EEDigiCollection >::read().
const edm::InputTag CollHandle< T >::tag_ [private] |
tag identifying the data collecion
Definition at line 94 of file CollHandle.h.
Referenced by CollHandle< EEDigiCollection >::read(), and CollHandle< EEDigiCollection >::tag().