CMS 3D CMS Logo

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

#include <MultiToken.h>

Public Member Functions

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

Private Member Functions

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

Private Attributes

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

Detailed Description

template<typename T>
class MultiTokenT< T >

Definition at line 30 of file MultiToken.h.

Constructor & Destructor Documentation

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

Definition at line 36 of file MultiToken.h.

37  : isMaster_(true)
38  {
39  for (auto&& tag : { tags... }) {
40  tokens_.push_back(cc.mayConsume<T>(pset.getParameter<edm::InputTag>(tag)));
41  }
42  goodIndex_ = std::make_shared<int>(-1);
43  }
T getParameter(std::string const &) const
EDGetTokenT< ProductType > mayConsume(edm::InputTag const &tag)
std::vector< edm::EDGetTokenT< T > > tokens_
Definition: MultiToken.h:164
const bool isMaster_
Definition: MultiToken.h:163
std::shared_ptr< int > goodIndex_
Definition: MultiToken.h:165
long double T
template<typename T>
template<typename S , typename... Tags>
MultiTokenT< T >::MultiTokenT ( MultiTokenT< S > &  master,
edm::ConsumesCollector &&  cc,
const edm::ParameterSet pset,
Tags &&...  tags 
)
inline

Definition at line 47 of file MultiToken.h.

48  : isMaster_(false)
50  {
51  for (auto&& tag : { tags... }) {
52  tokens_.push_back(cc.mayConsume<T>(pset.getParameter<edm::InputTag>(tag)));
53  }
54  }
T getParameter(std::string const &) const
EDGetTokenT< ProductType > mayConsume(edm::InputTag const &tag)
std::shared_ptr< int > getGoodTokenIndexPtr() const
Definition: MultiToken.h:140
std::vector< edm::EDGetTokenT< T > > tokens_
Definition: MultiToken.h:164
const bool isMaster_
Definition: MultiToken.h:163
std::shared_ptr< int > goodIndex_
Definition: MultiToken.h:165
long double T

Member Function Documentation

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

Definition at line 111 of file MultiToken.h.

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

112  {
113  // If we already know which token works, take that index
114  if (*goodIndex_ >= 0)
115  return tokens_[*goodIndex_];
116 
117  // If this is not a master MultiToken, just return what it got
118  if (!isMaster_) {
119  throw cms::Exception("MultiTokenTException") <<
120  "Trying to get a handle from a depending MultiToken before the master!";
121  }
122 
123  // Find which token is the good one by trying to get a handle
125  for (auto token:tokens_ ) {
126  iEvent.getByToken(token, handle);
127  if (handle.isValid()) {
128  return token;
129  }
130  }
131 
132  throw cms::Exception("MultiTokenTException") << "Neither token is valid!";
133  }
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:579
std::vector< edm::EDGetTokenT< T > > tokens_
Definition: MultiToken.h:164
const bool isMaster_
Definition: MultiToken.h:163
bool isValid() const
Definition: HandleBase.h:74
std::shared_ptr< int > goodIndex_
Definition: MultiToken.h:165
template<typename T>
int MultiTokenT< T >::getGoodTokenIndex ( ) const
inline

Definition at line 135 of file MultiToken.h.

Referenced by PhotonIDValueMapProducer::produce().

136  {
137  return *goodIndex_;
138  }
std::shared_ptr< int > goodIndex_
Definition: MultiToken.h:165
template<typename T>
std::shared_ptr<int> MultiTokenT< T >::getGoodTokenIndexPtr ( ) const
inline

Definition at line 140 of file MultiToken.h.

141  {
142  return goodIndex_;
143  }
std::shared_ptr< int > goodIndex_
Definition: MultiToken.h:165
template<typename T>
edm::Handle<T> MultiTokenT< T >::getHandle ( const edm::Event iEvent)
inline

Definition at line 57 of file MultiToken.h.

Referenced by ElectronMVANtuplizer::analyze().

58  {
60 
61  // If we already know which token works, take that one
62  if (*goodIndex_ >= 0) {
63  iEvent.getByToken(tokens_[*goodIndex_], handle);
64  return handle;
65  }
66 
67  if (!isMaster_) {
68  throw cms::Exception("MultiTokenTException") <<
69  "Trying to get a handle from a depending MultiToken before the master!";
70  }
71 
72  // If not, set the good token index parallel to getting the handle
73  handle = getInitialHandle(iEvent);
74 
75  if (*goodIndex_ == -1) {
76  *goodIndex_ = tokens_.size() - 1;
77  }
78  return handle;
79  }
edm::Handle< T > getInitialHandle(const edm::Event &iEvent)
Definition: MultiToken.h:147
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:579
std::vector< edm::EDGetTokenT< T > > tokens_
Definition: MultiToken.h:164
const bool isMaster_
Definition: MultiToken.h:163
std::shared_ptr< int > goodIndex_
Definition: MultiToken.h:165
template<typename T>
edm::Handle<T> MultiTokenT< T >::getInitialHandle ( const edm::Event iEvent)
inlineprivate

Definition at line 147 of file MultiToken.h.

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

148  {
149  // Try to retrieve the collection from the event. If we fail to
150  // retrieve the collection with one name, we next look for the one with
151  // the other name and so on.
153  for (size_t i = 0; i < tokens_.size(); ++i) {
154  iEvent.getByToken(tokens_[i], handle);
155  if (handle.isValid()) {
156  *goodIndex_ = i;
157  return handle;
158  }
159  }
160  return handle;
161  }
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:579
std::vector< edm::EDGetTokenT< T > > tokens_
Definition: MultiToken.h:164
bool isValid() const
Definition: HandleBase.h:74
std::shared_ptr< int > goodIndex_
Definition: MultiToken.h:165
template<typename T>
edm::Handle<T> MultiTokenT< T >::getValidHandle ( const edm::Event iEvent)
inline

Definition at line 83 of file MultiToken.h.

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

84  {
86 
87  // If we already know which token works, take that one
88  if (*goodIndex_ >= 0) {
89  iEvent.getByToken(tokens_[*goodIndex_], handle);
90  if (!handle.isValid())
91  throw cms::Exception("MultiTokenTException") <<
92  "Token gave valid handle in previously but not anymore!";
93  return handle;
94  }
95 
96  if (!isMaster_) {
97  throw cms::Exception("MultiTokenTException") <<
98  "Trying to get a handle from a depending MultiToken before the master!";
99  }
100 
101  // If not, set the good token index parallel to getting the handle
102  handle = getInitialHandle(iEvent);
103 
104  if (*goodIndex_ == -1) {
105  throw cms::Exception("MultiTokenTException") << "Neither handle is valid!";
106  }
107  return handle;
108  }
edm::Handle< T > getInitialHandle(const edm::Event &iEvent)
Definition: MultiToken.h:147
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:579
std::vector< edm::EDGetTokenT< T > > tokens_
Definition: MultiToken.h:164
const bool isMaster_
Definition: MultiToken.h:163
bool isValid() const
Definition: HandleBase.h:74
std::shared_ptr< int > goodIndex_
Definition: MultiToken.h:165

Member Data Documentation

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