CMS 3D CMS Logo

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

#include <MultiToken.h>

Public Member Functions

edm::EDGetTokenT< Tget (const edm::Event &iEvent) const
 
int getGoodTokenIndex () const
 
GoodIndexType getGoodTokenIndexPtr () const
 
edm::Handle< TgetHandle (const edm::Event &iEvent) const
 
edm::Handle< TgetValidHandle (const edm::Event &iEvent) const
 
template<typename... Tags>
 MultiTokenT (edm::ConsumesCollector &&cc, Tags...tags)
 
template<typename S , typename... Tags>
 MultiTokenT (const MultiTokenT< S > &master, edm::ConsumesCollector &&cc, Tags...tags)
 
template<typename... Tags>
 MultiTokenT (edm::ConsumesCollector &&cc, const edm::ParameterSet &pset, Tags &&...tags)
 
template<typename S , typename... Tags>
 MultiTokenT (const MultiTokenT< S > &master, edm::ConsumesCollector &&cc, const edm::ParameterSet &pset, Tags &&...tags)
 

Private Types

using GoodIndexType = std::shared_ptr< std::atomic< int >>
 

Private Member Functions

edm::Handle< TgetInitialHandle (const edm::Event &iEvent) const
 

Private Attributes

const GoodIndexType goodIndex_
 
const bool isMaster_
 
const std::vector< edm::EDGetTokenT< T > > tokens_
 

Detailed Description

template<typename T>
class MultiTokenT< T >

Definition at line 31 of file MultiToken.h.

Member Typedef Documentation

template<typename T>
using MultiTokenT< T >::GoodIndexType = std::shared_ptr<std::atomic<int>>
private

Definition at line 33 of file MultiToken.h.

Constructor & Destructor Documentation

template<typename T>
template<typename... Tags>
MultiTokenT< T >::MultiTokenT ( edm::ConsumesCollector &&  cc,
Tags...  tags 
)
inline

Definition at line 38 of file MultiToken.h.

39  : isMaster_(true)
40  , tokens_({cc.mayConsume<T>(edm::InputTag(tags))...})
41  , goodIndex_(std::make_shared<std::atomic<int>>(-1))
42  {}
const GoodIndexType goodIndex_
Definition: MultiToken.h:177
EDGetTokenT< ProductType > mayConsume(edm::InputTag const &tag)
const std::vector< edm::EDGetTokenT< T > > tokens_
Definition: MultiToken.h:176
const bool isMaster_
Definition: MultiToken.h:175
long double T
template<typename T>
template<typename S , typename... Tags>
MultiTokenT< T >::MultiTokenT ( const MultiTokenT< S > &  master,
edm::ConsumesCollector &&  cc,
Tags...  tags 
)
inline

Definition at line 46 of file MultiToken.h.

47  : isMaster_(false)
48  , tokens_({cc.mayConsume<T>(edm::InputTag(tags))...})
50  {}
const GoodIndexType goodIndex_
Definition: MultiToken.h:177
EDGetTokenT< ProductType > mayConsume(edm::InputTag const &tag)
const std::vector< edm::EDGetTokenT< T > > tokens_
Definition: MultiToken.h:176
const bool isMaster_
Definition: MultiToken.h:175
GoodIndexType getGoodTokenIndexPtr() const
Definition: MultiToken.h:152
long double T
template<typename T>
template<typename... Tags>
MultiTokenT< T >::MultiTokenT ( edm::ConsumesCollector &&  cc,
const edm::ParameterSet pset,
Tags &&...  tags 
)
inline

Definition at line 54 of file MultiToken.h.

55  : isMaster_(true)
56  , tokens_({cc.mayConsume<T>(pset.getParameter<edm::InputTag>(tags))...})
57  , goodIndex_(std::make_shared<std::atomic<int>>(-1))
58  {}
T getParameter(std::string const &) const
const GoodIndexType goodIndex_
Definition: MultiToken.h:177
EDGetTokenT< ProductType > mayConsume(edm::InputTag const &tag)
const std::vector< edm::EDGetTokenT< T > > tokens_
Definition: MultiToken.h:176
const bool isMaster_
Definition: MultiToken.h:175
long double T
template<typename T>
template<typename S , typename... Tags>
MultiTokenT< T >::MultiTokenT ( const MultiTokenT< S > &  master,
edm::ConsumesCollector &&  cc,
const edm::ParameterSet pset,
Tags &&...  tags 
)
inline

Definition at line 62 of file MultiToken.h.

63  : isMaster_(false)
64  , tokens_({cc.mayConsume<T>(pset.getParameter<edm::InputTag>(tags))...})
66  {}
T getParameter(std::string const &) const
const GoodIndexType goodIndex_
Definition: MultiToken.h:177
EDGetTokenT< ProductType > mayConsume(edm::InputTag const &tag)
const std::vector< edm::EDGetTokenT< T > > tokens_
Definition: MultiToken.h:176
const bool isMaster_
Definition: MultiToken.h:175
GoodIndexType getGoodTokenIndexPtr() const
Definition: MultiToken.h:152
long double T

Member Function Documentation

template<typename T>
edm::EDGetTokenT<T> MultiTokenT< T >::get ( const edm::Event iEvent) const
inline

Definition at line 123 of file MultiToken.h.

Referenced by Options.Options::__getitem__(), betterConfigParser.BetterConfigParser::__updateDict(), betterConfigParser.BetterConfigParser::getCompares(), betterConfigParser.BetterConfigParser::getGeneral(), and betterConfigParser.BetterConfigParser::getResultingSection().

124  {
125  // If we already know which token works, take that index
126  if (*goodIndex_ >= 0)
127  return tokens_[*goodIndex_];
128 
129  // If this is not a master MultiToken, just return what it got
130  if (!isMaster_) {
131  throw cms::Exception("MultiTokenTException") <<
132  "Trying to get a handle from a depending MultiToken before the master!";
133  }
134 
135  // Find which token is the good one by trying to get a handle
137  for (auto token:tokens_ ) {
138  iEvent.getByToken(token, handle);
139  if (handle.isValid()) {
140  return token;
141  }
142  }
143 
144  throw cms::Exception("MultiTokenTException") << "Neither token is valid!";
145  }
const GoodIndexType goodIndex_
Definition: MultiToken.h:177
const std::vector< edm::EDGetTokenT< T > > tokens_
Definition: MultiToken.h:176
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
const bool isMaster_
Definition: MultiToken.h:175
bool isValid() const
Definition: HandleBase.h:74
template<typename T>
int MultiTokenT< T >::getGoodTokenIndex ( ) const
inline

Definition at line 147 of file MultiToken.h.

Referenced by PhotonIDValueMapProducer::produce().

148  {
149  return *goodIndex_;
150  }
const GoodIndexType goodIndex_
Definition: MultiToken.h:177
template<typename T>
GoodIndexType MultiTokenT< T >::getGoodTokenIndexPtr ( ) const
inline

Definition at line 152 of file MultiToken.h.

153  {
154  return goodIndex_;
155  }
const GoodIndexType goodIndex_
Definition: MultiToken.h:177
template<typename T>
edm::Handle<T> MultiTokenT< T >::getHandle ( const edm::Event iEvent) const
inline

Definition at line 69 of file MultiToken.h.

Referenced by ElectronMVANtuplizer::analyze().

70  {
72 
73  // If we already know which token works, take that one
74  if (*goodIndex_ >= 0) {
75  iEvent.getByToken(tokens_[*goodIndex_], handle);
76  return handle;
77  }
78 
79  if (!isMaster_) {
80  throw cms::Exception("MultiTokenTException") <<
81  "Trying to get a handle from a depending MultiToken before the master!";
82  }
83 
84  // If not, set the good token index parallel to getting the handle
85  handle = getInitialHandle(iEvent);
86 
87  if (*goodIndex_ == -1) {
88  *goodIndex_ = tokens_.size() - 1;
89  }
90  return handle;
91  }
const GoodIndexType goodIndex_
Definition: MultiToken.h:177
const std::vector< edm::EDGetTokenT< T > > tokens_
Definition: MultiToken.h:176
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
const bool isMaster_
Definition: MultiToken.h:175
edm::Handle< T > getInitialHandle(const edm::Event &iEvent) const
Definition: MultiToken.h:159
template<typename T>
edm::Handle<T> MultiTokenT< T >::getInitialHandle ( const edm::Event iEvent) const
inlineprivate

Definition at line 159 of file MultiToken.h.

Referenced by MultiTokenT< edm::View< reco::GsfElectron > >::getHandle(), and MultiTokenT< edm::View< reco::GsfElectron > >::getValidHandle().

160  {
161  // Try to retrieve the collection from the event. If we fail to
162  // retrieve the collection with one name, we next look for the one with
163  // the other name and so on.
165  for (size_t i = 0; i < tokens_.size(); ++i) {
166  iEvent.getByToken(tokens_[i], handle);
167  if (handle.isValid()) {
168  *goodIndex_ = i;
169  return handle;
170  }
171  }
172  return handle;
173  }
const GoodIndexType goodIndex_
Definition: MultiToken.h:177
const std::vector< edm::EDGetTokenT< T > > tokens_
Definition: MultiToken.h:176
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
bool isValid() const
Definition: HandleBase.h:74
template<typename T>
edm::Handle<T> MultiTokenT< T >::getValidHandle ( const edm::Event iEvent) const
inline

Definition at line 95 of file MultiToken.h.

Referenced by ElectronMVANtuplizer::analyze(), PhotonMVANtuplizer::analyze(), ElectronIDValueMapProducer::produce(), MVAValueMapProducer< ParticleType >::produce(), and PhotonIDValueMapProducer::produce().

96  {
98 
99  // If we already know which token works, take that one
100  if (*goodIndex_ >= 0) {
101  iEvent.getByToken(tokens_[*goodIndex_], handle);
102  if (!handle.isValid())
103  throw cms::Exception("MultiTokenTException") <<
104  "Token gave valid handle previously but not anymore!";
105  return handle;
106  }
107 
108  if (!isMaster_) {
109  throw cms::Exception("MultiTokenTException") <<
110  "Trying to get a handle from a depending MultiToken before the master!";
111  }
112 
113  // If not, set the good token index parallel to getting the handle
114  handle = getInitialHandle(iEvent);
115 
116  if (*goodIndex_ == -1) {
117  throw cms::Exception("MultiTokenTException") << "Neither handle is valid!";
118  }
119  return handle;
120  }
const GoodIndexType goodIndex_
Definition: MultiToken.h:177
const std::vector< edm::EDGetTokenT< T > > tokens_
Definition: MultiToken.h:176
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
const bool isMaster_
Definition: MultiToken.h:175
bool isValid() const
Definition: HandleBase.h:74
edm::Handle< T > getInitialHandle(const edm::Event &iEvent) const
Definition: MultiToken.h:159

Member Data Documentation

template<typename T>
const GoodIndexType MultiTokenT< T >::goodIndex_
private
template<typename T>
const bool MultiTokenT< T >::isMaster_
private
template<typename T>
const std::vector<edm::EDGetTokenT<T> > MultiTokenT< T >::tokens_
private