CMS 3D CMS Logo

ObjectSelectorBase.h
Go to the documentation of this file.
1 #ifndef RecoAlgos_ObjectSelectorBase_h
2 #define RecoAlgos_ObjectSelectorBase_h
3 
20 #include <utility>
21 #include <vector>
22 #include <memory>
23 #include <algorithm>
24 
25 template <typename Selector,
26  typename OutputCollection,
27  typename SizeSelector,
28  typename PostProcessor,
29  typename StoreManager,
30  typename Base,
31  typename Init>
32 class ObjectSelectorBase : public Base {
33 public:
35  // ObjectSelectorBase()=default;
37  : Base(cfg),
38  srcToken_(
39  this->template consumes<typename Selector::collection>(cfg.template getParameter<edm::InputTag>("src"))),
40  filter_(false),
41  throwOnMissing_(cfg.template getUntrackedParameter<bool>("throwOnMissing", true)),
42  selectorInit_(this->consumesCollector()),
43  selector_(cfg, this->consumesCollector()),
44  sizeSelector_(reco::modules::make<SizeSelector>(cfg)),
45  postProcessor_(cfg, this->consumesCollector()) {
46  const std::string filter("filter");
47  std::vector<std::string> bools = cfg.template getParameterNamesForType<bool>();
48  bool found = std::find(bools.begin(), bools.end(), filter) != bools.end();
49  if (found)
50  filter_ = cfg.template getParameter<bool>(filter);
51  postProcessor_.init(*this);
52  }
54  ~ObjectSelectorBase() override {}
55 
56 private:
58  bool filter(edm::Event& evt, const edm::EventSetup& es) override {
59  selectorInit_.init(selector_, evt, es);
61  if (!throwOnMissing_ && !source.isValid()) {
62  return !filter_;
63  }
65  StoreManager manager(source);
66  selector_.select(source, evt, es);
67  manager.cloneAndStore(selector_.begin(), selector_.end(), evt);
68  bool result = (!filter_ || sizeSelector_(manager.size()));
70  postProcessor_.process(filtered, evt);
71  return result;
72  }
76  bool filter_;
83  SizeSelector sizeSelector_;
85  PostProcessor postProcessor_;
86 };
87 
88 #endif
~ObjectSelectorBase() override
destructor
bool filter(edm::Event &evt, const edm::EventSetup &es) override
process one event
Init selectorInit_
Object collection selector.
S make(const edm::ParameterSet &cfg)
def Base(process)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:526
bool filter_
filter event
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
bool throwOnMissing_
trhow on missing
static const TGPicture * filtered(bool iBackgroundIsBlack)
def template(fileName, svg, replaceme="REPLACEME")
Definition: svgfig.py:521
ObjectSelectorBase(const edm::ParameterSet &cfg)
constructor
ROOT::VecOps::RVec< bool > bools
Definition: Resolutions.cc:5
Functor that operates on <T>
Definition: Selector.h:22
edm::EDGetTokenT< typename Selector::collection > srcToken_
source collection label
PostProcessor postProcessor_
post processor
fixed size matrix
HLT enums.
SizeSelector sizeSelector_
selected object collection size selector
static std::string const source
Definition: EdmProvDump.cc:49