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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
// -*- C++ -*-
//
// Package: CommonTools/RecoAlgos
// Class: BooleanFlagFilter
//
/**\class BooleanFlagFilter BooleanFlagFilter.cc CommonTools/RecoAlgos/plugins/BooleanFlagFilter.cc
Description: [one line class summary]
Implementation:
[Notes on implementation]
*/
//
// Original Author: Igor Volobouev
// Created: Fri, 20 Mar 2015 08:05:20 GMT
//
//
// system include files
#include <memory>
// user include files
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/global/EDFilter.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/MakerMacros.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
//
// class declaration
//
class BooleanFlagFilter : public edm::global::EDFilter<> {
public:
explicit BooleanFlagFilter(const edm::ParameterSet&);
private:
bool filter(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
// ----------member data ---------------------------
edm::EDGetTokenT<bool> inputToken_;
bool reverse_;
};
//
// constants, enums and typedefs
//
//
// static data member definitions
//
//
// constructors and destructor
//
BooleanFlagFilter::BooleanFlagFilter(const edm::ParameterSet& iConfig) {
//now do what ever initialization is needed
inputToken_ = consumes<bool>(iConfig.getParameter<edm::InputTag>("inputLabel"));
reverse_ = iConfig.getParameter<bool>("reverseDecision");
}
//
// member functions
//
// ------------ method called on each new Event ------------
bool BooleanFlagFilter::filter(edm::StreamID, edm::Event& iEvent, const edm::EventSetup& iSetup) const {
using namespace edm;
Handle<bool> pIn;
iEvent.getByToken(inputToken_, pIn);
if (!pIn.isValid()) {
throw edm::Exception(edm::errors::ProductNotFound) << " could not find requested flag\n";
return true;
}
bool result = *pIn;
if (reverse_)
result = !result;
return result;
}
//define this as a plug-in
DEFINE_FWK_MODULE(BooleanFlagFilter);
|