-
Notifications
You must be signed in to change notification settings - Fork 4.4k
/
Copy pathWillGetIfMatch.h
48 lines (39 loc) · 1.51 KB
/
WillGetIfMatch.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#ifndef FWCore_Framework_WillGetIfMatch_h
#define FWCore_Framework_WillGetIfMatch_h
/** \class edm::WillGetIfMatch
This is intended to be used only by the class GetterOfProducts.
See comments in the file GetterOfProducts.h.
\author W. David Dagenhart, created 6 August, 2012
*/
#include <functional>
#include "DataFormats/Provenance/interface/BranchDescription.h"
#include "FWCore/Framework/interface/EDConsumerBase.h"
#include "FWCore/Utilities/interface/InputTag.h"
#include "FWCore/Utilities/interface/EDGetToken.h"
namespace edm {
template <typename T>
class WillGetIfMatch {
public:
template <typename U>
WillGetIfMatch(U const& match, EDConsumerBase* module) : match_(match), module_(module) {}
EDGetTokenT<T> operator()(BranchDescription const& branchDescription) {
if (match_(branchDescription)) {
auto transition = branchDescription.branchType();
edm::InputTag tag{
branchDescription.moduleLabel(), branchDescription.productInstanceName(), branchDescription.processName()};
if (transition == edm::InEvent) {
return module_->template consumes<T>(tag);
} else if (transition == edm::InLumi) {
return module_->template consumes<T, edm::InLumi>(tag);
} else if (transition == edm::InRun) {
return module_->template consumes<T, edm::InRun>(tag);
}
}
return EDGetTokenT<T>{};
}
private:
std::function<bool(BranchDescription const&)> match_;
EDConsumerBase* module_;
};
} // namespace edm
#endif