File indexing completed on 2025-01-31 02:19:22
0001 #ifndef FWCore_Framework_WillGetIfMatch_h
0002 #define FWCore_Framework_WillGetIfMatch_h
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #include <functional>
0014 #include "DataFormats/Provenance/interface/ProductDescription.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()(ProductDescription const& productDescription) {
0028 if (match_(productDescription)) {
0029 auto transition = productDescription.branchType();
0030 edm::InputTag tag{productDescription.moduleLabel(),
0031 productDescription.productInstanceName(),
0032 productDescription.processName()};
0033 if (transition == edm::InEvent) {
0034 return module_->template consumes<T>(tag);
0035 } else if (transition == edm::InLumi) {
0036 return module_->template consumes<T, edm::InLumi>(tag);
0037 } else if (transition == edm::InRun) {
0038 return module_->template consumes<T, edm::InRun>(tag);
0039 } else if (transition == edm::InProcess) {
0040 return module_->template consumes<T, edm::InProcess>(tag);
0041 }
0042 }
0043 return EDGetTokenT<T>{};
0044 }
0045
0046 private:
0047 std::function<bool(ProductDescription const&)> match_;
0048 EDConsumerBase* module_;
0049 };
0050 }
0051 #endif