CMS 3D CMS Logo

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

#include <GetterOfProducts.h>

Public Member Functions

edm::BranchType branchType () const
 
void fillHandles (edm::Event const &event, std::vector< edm::Handle< T >> &handles) const
 
void fillHandles (edm::LuminosityBlock const &lumi, std::vector< edm::Handle< T >> &handles) const
 
void fillHandles (edm::Run const &run, std::vector< edm::Handle< T >> &handles) const
 
 GetterOfProducts ()
 
template<typename U , typename M >
 GetterOfProducts (U const &match, M *module, edm::BranchType branchType=edm::InEvent)
 
void operator() (edm::BranchDescription const &branchDescription)
 
std::vector< edm::EDGetTokenT< T > > const & tokens () const
 

Private Attributes

edm::BranchType branchType_
 
std::function< EDGetTokenT< T >BranchDescription const &)> matcher_
 
std::shared_ptr< std::vector< edm::EDGetTokenT< T > > > tokens_
 

Detailed Description

template<typename T>
class edm::GetterOfProducts< T >

Intended to be used by EDProducers, EDFilters, and EDAnalyzers to get products from the Event, Run or LuminosityBlock. In most cases, the preferred method to get products is not to use this class. In most cases the preferred method is to use the function getByLabel with an InputTag that is configurable. But occasionally getByLabel will not work because one wants to select the product based on the data that is available in the event and not have to modify the configuration as the data content changes. A real example would be a module that collects HLT trigger information from products written by the many HLT filters. The number and labels of those products vary so much that it would not be reasonable to modify the configuration to get all of them each time a different HLT trigger table was used. This class handles that and similar cases.

This class is preferred over using getManyByType where it is possible to use it.

This method can select by type and branch type. There exists a predicate (in ProcessMatch.h) to also select on process name. It is possible to write other predicates which will select on anything in the BranchDescription. The selection is done during the initialization of the process. During this initialization a list of InputTags is filled with all matching products from the ProductRegistry. This list of InputTags is accessible to the module. In the future there are plans for modules to register the products they might get to the Framework which will allow it to optimize performance for parallel processing among other things.

The fillHandles functions will get a handle for each product on the list of InputTags that is actually present in the current Event, LuminosityBlock, or Run. Internally, this function uses getByLabel and benefits from performance optimizations of getByLabel.

Typically one would use this as follows:

Add these headers:

include "FWCore/Framework/interface/GetterOfProducts.h" include "FWCore/Framework/interface/ProcessMatch.h"

Add this data member:

edm::GetterOfProducts<YourDataType> getterOfProducts_;

Add these to the constructor (1st line is usually in the data member initializer list and the 2nd line in the body of the constructor)

getterOfProducts_(edm::ProcessMatch(processName_), this) {
callWhenNewProductsRegistered(getterOfProducts_);

Add this to the method called for each event:

std::vector<edm::Handle<YourDataType> > handles;
getterOfProducts_.fillHandles(event, handles);

And that is all you need in most cases. In the above example, "YourDataType" is the type of the product you want to get. There are some variants for special cases

Author
W. David Dagenhart, created 6 August, 2012

Definition at line 121 of file GetterOfProducts.h.

Constructor & Destructor Documentation

template<typename T>
edm::GetterOfProducts< T >::GetterOfProducts ( )
inline

Definition at line 123 of file GetterOfProducts.h.

template<typename T>
template<typename U , typename M >
edm::GetterOfProducts< T >::GetterOfProducts ( U const &  match,
M *  module,
edm::BranchType  branchType = edm::InEvent 
)
inline

Definition at line 126 of file GetterOfProducts.h.

127  : matcher_(WillGetIfMatch<T>(match, module)),
128  tokens_(new std::vector<edm::EDGetTokenT<T>>),
std::shared_ptr< std::vector< edm::EDGetTokenT< T > > > tokens_
edm::BranchType branchType_
std::function< EDGetTokenT< T >BranchDescription const &)> matcher_
edm::BranchType branchType() const
Definition: vlib.h:208
std::string match(BranchDescription const &a, BranchDescription const &b, std::string const &fileName)

Member Function Documentation

template<typename T>
edm::BranchType edm::GetterOfProducts< T >::branchType ( ) const
inline

Definition at line 181 of file GetterOfProducts.h.

181 { return branchType_; }
edm::BranchType branchType_
template<typename T>
void edm::GetterOfProducts< T >::fillHandles ( edm::Event const &  event,
std::vector< edm::Handle< T >> &  handles 
) const
inline

Definition at line 143 of file GetterOfProducts.h.

Referenced by TriggerSummaryProducerAOD::fillTriggerObjectCollections(), TriggerSummaryProducerRAW::produce(), and TriggerSummaryProducerAOD::produce().

143  {
144  handles.clear();
145  if (branchType_ == edm::InEvent) {
146  handles.reserve(tokens_->size());
148  for (auto const& token : *tokens_) {
149  if (auto handle = event.getHandle(token)) {
150  handles.push_back(handle);
151  }
152  }
153  }
154  }
std::shared_ptr< std::vector< edm::EDGetTokenT< T > > > tokens_
edm::BranchType branchType_
Definition: event.py:1
template<typename T>
void edm::GetterOfProducts< T >::fillHandles ( edm::LuminosityBlock const &  lumi,
std::vector< edm::Handle< T >> &  handles 
) const
inline

Definition at line 156 of file GetterOfProducts.h.

156  {
157  handles.clear();
158  if (branchType_ == edm::InLumi) {
159  handles.reserve(tokens_->size());
160  for (auto const& token : *tokens_) {
161  if (auto handle = lumi.getHandle(token)) {
162  handles.push_back(handle);
163  }
164  }
165  }
166  }
std::shared_ptr< std::vector< edm::EDGetTokenT< T > > > tokens_
edm::BranchType branchType_
template<typename T>
void edm::GetterOfProducts< T >::fillHandles ( edm::Run const &  run,
std::vector< edm::Handle< T >> &  handles 
) const
inline

Definition at line 168 of file GetterOfProducts.h.

168  {
169  handles.clear();
170  if (branchType_ == edm::InRun) {
171  handles.reserve(tokens_->size());
172  for (auto const& token : *tokens_) {
173  if (auto handle = run.getHandle(token)) {
174  handles.push_back(handle);
175  }
176  }
177  }
178  }
std::shared_ptr< std::vector< edm::EDGetTokenT< T > > > tokens_
edm::BranchType branchType_
template<typename T>
void edm::GetterOfProducts< T >::operator() ( edm::BranchDescription const &  branchDescription)
inline

Definition at line 131 of file GetterOfProducts.h.

131  {
132  if (branchDescription.dropped())
133  return;
134  if (branchDescription.branchType() == branchType_ &&
135  branchDescription.unwrappedTypeID() == edm::TypeID(typeid(T))) {
136  auto const& token = matcher_(branchDescription);
137  if (not token.isUninitialized()) {
138  tokens_->push_back(token);
139  }
140  }
141  }
std::shared_ptr< std::vector< edm::EDGetTokenT< T > > > tokens_
edm::BranchType branchType_
std::function< EDGetTokenT< T >BranchDescription const &)> matcher_
long double T
template<typename T>
std::vector<edm::EDGetTokenT<T> > const& edm::GetterOfProducts< T >::tokens ( ) const
inline

Definition at line 180 of file GetterOfProducts.h.

180 { return *tokens_; }
std::shared_ptr< std::vector< edm::EDGetTokenT< T > > > tokens_

Member Data Documentation

template<typename T>
edm::BranchType edm::GetterOfProducts< T >::branchType_
private
template<typename T>
std::function<EDGetTokenT<T>BranchDescription const&)> edm::GetterOfProducts< T >::matcher_
private
template<typename T>
std::shared_ptr<std::vector<edm::EDGetTokenT<T> > > edm::GetterOfProducts< T >::tokens_
private