File indexing completed on 2023-03-17 11:02:08
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/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 }
0050 #endif