Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:27:49

0001 #ifndef FWCore_Framework_WillGetIfMatch_h
0002 #define FWCore_Framework_WillGetIfMatch_h
0003 
0004 /** \class edm::WillGetIfMatch
0005 
0006 This is intended to be used only by the class GetterOfProducts.
0007 See comments in the file GetterOfProducts.h.
0008 
0009 \author W. David Dagenhart, created 6 August, 2012
0010 
0011 */
0012 
0013 #include <functional>
0014 #include "DataFormats/Provenance/interface/BranchDescription.h"
0015 #include "FWCore/Framework/interface/EDConsumerBase.h"
0016 #include "FWCore/Utilities/interface/InputTag.h"
0017 #include "FWCore/Utilities/interface/EDGetToken.h"
0018 
0019 namespace edm {
0020 
0021   template <typename T>
0022   class WillGetIfMatch {
0023   public:
0024     template <typename U>
0025     WillGetIfMatch(U const& match, EDConsumerBase* module) : match_(match), module_(module) {}
0026 
0027     EDGetTokenT<T> operator()(BranchDescription const& branchDescription) {
0028       if (match_(branchDescription)) {
0029         auto transition = branchDescription.branchType();
0030         edm::InputTag tag{
0031             branchDescription.moduleLabel(), branchDescription.productInstanceName(), branchDescription.processName()};
0032         if (transition == edm::InEvent) {
0033           return module_->template consumes<T>(tag);
0034         } else if (transition == edm::InLumi) {
0035           return module_->template consumes<T, edm::InLumi>(tag);
0036         } else if (transition == edm::InRun) {
0037           return module_->template consumes<T, edm::InRun>(tag);
0038         } else if (transition == edm::InProcess) {
0039           return module_->template consumes<T, edm::InProcess>(tag);
0040         }
0041       }
0042       return EDGetTokenT<T>{};
0043     }
0044 
0045   private:
0046     std::function<bool(BranchDescription const&)> match_;
0047     EDConsumerBase* module_;
0048   };
0049 }  // namespace edm
0050 #endif