CMS 3D CMS Logo

EventSelectors.h
Go to the documentation of this file.
1 #ifndef PhysicsTools_FWLite_EventSelectors_h
2 #define PhysicsTools_FWLite_EventSelectors_h
3 // these includes are FWLite-safe
6 // these are from ROOT, so they're safe too
7 #include <TString.h>
8 #include <TNamed.h>
9 
10 #if !defined(__CINT__) && !defined(__MAKECINT__)
12 #endif
13 
14 namespace fwlite {
15  class EventSelector : public TNamed {
16  public:
17  EventSelector(const char *name = "", const char *title = "") : TNamed(name, title) {}
18  ~EventSelector() override {}
19  virtual bool accept(const fwlite::EventBase &ev) const = 0;
20  };
21 
22  class RunLumiSelector : public EventSelector {
23  public:
24  RunLumiSelector(const char *name = "", const char *title = "") : EventSelector(name, title) {}
25  RunLumiSelector(int run, int firstLumi = 0, int lastLumi = 9999999)
26  : EventSelector(TString::Format("run%d_lumi%d_%d", run, firstLumi, lastLumi),
27  TString::Format("Run %d, Lumi range [%d, %d]", run, firstLumi, lastLumi)) {
28  add(run, firstLumi, lastLumi);
29  }
30 
31  ~RunLumiSelector() override {}
32  bool accept(const fwlite::EventBase &ev) const override { return accept(ev.id().run(), ev.luminosityBlock()); }
33  void add(int run, int firstLumi = 0, int lastLumi = 9999999) {
34  runs.push_back(run);
35  firstLumis.push_back(firstLumi);
36  lastLumis.push_back(lastLumi);
37  }
38  void clear() {
39  runs.clear();
40  firstLumis.clear();
41  lastLumis.clear();
42  }
43  bool accept(int run, int luminosityBlock) const {
44  if (runs.empty())
45  return true;
46  for (int i = 0, n = runs.size(); i < n; ++i) {
47  if (runs[i] == run) {
48  if ((firstLumis[i] <= luminosityBlock) && (luminosityBlock <= lastLumis[i]))
49  return true;
50  }
51  }
52  return false;
53  }
54 
55  private:
56  std::vector<int> runs, firstLumis, lastLumis;
57  };
58 
59  template <typename Collection>
61  public:
63  const char *instance,
64  const char *process,
65  const char *cut,
66  int minNumber = 1,
67  int maxNumber = -1)
68  : label_(label),
70  min_(minNumber),
71  max_(maxNumber),
72  scanner(
73  new helper::ScannerBase(helper::Parser::elementType(edm::TypeWithDict(HandleT::TempWrapT::typeInfo())))) {
74  scanner->setCut(cut);
76  }
77  ~ObjectCountSelector() override { delete scanner; }
78  bool accept(const fwlite::EventBase &ev) const override {
79  int nfound = 0;
80  HandleT handle; // here, not as a datamember, otherwise CINT segfaults (!?)
81  handle.getByLabel(ev, label_.c_str(), instance_.c_str(), process_.c_str());
82  const Collection &vals = *handle;
83  for (size_t j = 0, n = vals.size(); j < n; ++j) {
84  if (scanner->test(&vals[j]))
85  nfound++;
86  }
87  return (nfound >= min_ && (max_ == -1 || nfound <= max_));
88  }
89  void setCut(const char *cut) { scanner->setCut(cut); }
90  void setMin(int minNumber) { min_ = minNumber; }
91  void setMax(int maxNumber) { max_ = maxNumber; }
92  void setIgnoreExceptions(bool ignoreThem = true) { scanner->setIgnoreExceptions(ignoreThem); }
93 
94  protected:
97  int min_, max_;
98  helper::ScannerBase *scanner; // has to be a pointer, otherwise CINT segfaults in setCut (!?)
99  // prevent copy c-tor and assignment
102  };
103 } // namespace fwlite
104 #endif // PhysicsTools_FWLite_EventSelectors_h
fwlite::ObjectCountSelector::process_
std::string process_
Definition: EventSelectors.h:96
fwlite::ObjectCountSelector::accept
bool accept(const fwlite::EventBase &ev) const override
Definition: EventSelectors.h:78
contentValuesCheck.nfound
nfound
Definition: contentValuesCheck.py:80
fwlite::RunLumiSelector::accept
bool accept(int run, int luminosityBlock) const
Definition: EventSelectors.h:43
fwlite::ObjectCountSelector::operator=
ObjectCountSelector & operator=(const fwlite::ObjectCountSelector< Collection > &other)
runGCPTkAlMap.title
string title
Definition: runGCPTkAlMap.py:94
mps_fire.i
i
Definition: mps_fire.py:428
fwlite::EventSelector
Definition: EventSelectors.h:15
Handle.h
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
TkAlMuonSelectors_cfi.cut
cut
Definition: TkAlMuonSelectors_cfi.py:5
helper::ScannerBase
Definition: ScannerHelpers.h:44
fwlite
Definition: TFileDirectory.h:16
patZpeak.handle
handle
Definition: patZpeak.py:23
edm
HLT enums.
Definition: AlignableModifier.h:19
fwlite::RunLumiSelector::clear
void clear()
Definition: EventSelectors.h:38
fwlite::EventSelector::~EventSelector
~EventSelector() override
Definition: EventSelectors.h:18
fwlite::RunLumiSelector::RunLumiSelector
RunLumiSelector(int run, int firstLumi=0, int lastLumi=9999999)
Definition: EventSelectors.h:25
analysisFilters_cff.maxNumber
maxNumber
Definition: analysisFilters_cff.py:61
fwlite::ObjectCountSelector::scanner
helper::ScannerBase * scanner
Definition: EventSelectors.h:98
BeamSpotPI::lastLumi
Definition: BeamSpotPayloadInspectorHelper.h:38
fwlite::RunLumiSelector::runs
std::vector< int > runs
Definition: EventSelectors.h:56
fwlite::Handle< Collection >
fwlite::ObjectCountSelector::setMax
void setMax(int maxNumber)
Definition: EventSelectors.h:91
fwlite::ObjectCountSelector::HandleT
fwlite::Handle< Collection > HandleT
Definition: EventSelectors.h:95
ScannerHelpers.h
trackingPlots.other
other
Definition: trackingPlots.py:1467
fwlite::ObjectCountSelector
Definition: EventSelectors.h:60
fwlite::RunLumiSelector::RunLumiSelector
RunLumiSelector(const char *name="", const char *title="")
Definition: EventSelectors.h:24
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
fwlite::ObjectCountSelector::min_
int min_
Definition: EventSelectors.h:97
fwlite::RunLumiSelector::lastLumis
std::vector< int > lastLumis
Definition: EventSelectors.h:56
LaserDQM_cfg.process
process
Definition: LaserDQM_cfg.py:3
fwlite::RunLumiSelector::firstLumis
std::vector< int > firstLumis
Definition: EventSelectors.h:56
fwlite::ObjectCountSelector::instance_
std::string instance_
Definition: EventSelectors.h:96
helper
Definition: helper.py:1
fwlite::ObjectCountSelector::~ObjectCountSelector
~ObjectCountSelector() override
Definition: EventSelectors.h:77
helper::ScannerBase::setCut
bool setCut(const char *cut)
Set the default cut that is applied to the events.
Definition: ScannerHelpers.cc:78
fwlite::ObjectCountSelector::setIgnoreExceptions
void setIgnoreExceptions(bool ignoreThem=true)
Definition: EventSelectors.h:92
fwlite::RunLumiSelector::add
void add(int run, int firstLumi=0, int lastLumi=9999999)
Definition: EventSelectors.h:33
fwlite::RunLumiSelector::~RunLumiSelector
~RunLumiSelector() override
Definition: EventSelectors.h:31
fwlite::EventSelector::accept
virtual bool accept(const fwlite::EventBase &ev) const =0
instance
static PFTauRenderPlugin instance
Definition: PFTauRenderPlugin.cc:70
fwlite::ObjectCountSelector::setMin
void setMin(int minNumber)
Definition: EventSelectors.h:90
fwlite::EventBase
Definition: EventBase.h:36
PA_ZEESkim_cff.minNumber
minNumber
Definition: PA_ZEESkim_cff.py:34
writedatasetfile.run
run
Definition: writedatasetfile.py:27
fwlite::RunLumiSelector
Definition: EventSelectors.h:22
Event.h
ev
bool ev
Definition: Hydjet2Hadronizer.cc:95
helper::ScannerBase::test
bool test(const void *obj, size_t icut=0) const
Definition: ScannerHelpers.cc:103
fwlite::RunLumiSelector::accept
bool accept(const fwlite::EventBase &ev) const override
Definition: EventSelectors.h:32
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
helper::ScannerBase::setIgnoreExceptions
void setIgnoreExceptions(bool ignoreThem)
Definition: ScannerHelpers.h:100
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
fwlite::ObjectCountSelector::label_
std::string label_
Definition: EventSelectors.h:96
fwlite::ObjectCountSelector::max_
int max_
Definition: EventSelectors.h:97
label
const char * label
Definition: PFTauDecayModeTools.cc:11
fwlite::EventSelector::EventSelector
EventSelector(const char *name="", const char *title="")
Definition: EventSelectors.h:17
fwlite::ObjectCountSelector::setCut
void setCut(const char *cut)
Definition: EventSelectors.h:89
fwlite::ObjectCountSelector::ObjectCountSelector
ObjectCountSelector(const char *label, const char *instance, const char *process, const char *cut, int minNumber=1, int maxNumber=-1)
Definition: EventSelectors.h:62