1 |
gpetrucc |
1.1 |
// these includes are FWLite-safe
|
2 |
|
|
#include "DataFormats/FWLite/interface/Handle.h"
|
3 |
|
|
#include "DataFormats/FWLite/interface/Event.h"
|
4 |
|
|
// these are from ROOT, so they're safe too
|
5 |
|
|
#include <TString.h>
|
6 |
|
|
#include <TNamed.h>
|
7 |
|
|
|
8 |
|
|
#if !defined(__CINT__) && !defined(__MAKECINT__)
|
9 |
|
|
#include "UserCode/GPetrucc/interface/fwliteHelpers.h"
|
10 |
|
|
#else
|
11 |
|
|
#ifndef UserCode_GPetrucc_CINT_load_library
|
12 |
|
|
#define UserCode_GPetrucc_CINT_load_library
|
13 |
|
|
// load the library that contains the dictionaries
|
14 |
|
|
int _load_UserCodeGPetrucc = gSystem->Load("libUserCodeGPetrucc.so");
|
15 |
|
|
#endif
|
16 |
|
|
#endif
|
17 |
|
|
|
18 |
|
|
namespace fwlite {
|
19 |
|
|
class EventSelector : public TNamed {
|
20 |
|
|
public:
|
21 |
|
|
EventSelector(const char *name="", const char *title="") : TNamed(name,title) {}
|
22 |
|
|
virtual ~EventSelector() {}
|
23 |
|
|
virtual bool accept(const fwlite::EventBase &ev) const = 0;
|
24 |
|
|
};
|
25 |
|
|
|
26 |
|
|
class RunLumiSelector : public EventSelector {
|
27 |
|
|
public:
|
28 |
|
|
RunLumiSelector(const char *name="", const char *title="") : EventSelector(name,title) {}
|
29 |
|
|
RunLumiSelector(int run, int firstLumi=0, int lastLumi = 9999999) :
|
30 |
|
|
EventSelector(TString::Format("run%d_lumi%d_%d", run, firstLumi, lastLumi),
|
31 |
|
|
TString::Format("Run %d, Lumi range [%d, %d]", run, firstLumi, lastLumi))
|
32 |
|
|
{ add(run, firstLumi, lastLumi); }
|
33 |
|
|
|
34 |
|
|
virtual ~RunLumiSelector() {}
|
35 |
|
|
virtual bool accept(const fwlite::EventBase &ev) const {
|
36 |
|
|
return accept(ev.id().run(), ev.luminosityBlock());
|
37 |
|
|
}
|
38 |
|
|
void add(int run, int firstLumi=0, int lastLumi = 9999999) {
|
39 |
|
|
runs.push_back(run);
|
40 |
|
|
firstLumis.push_back(firstLumi);
|
41 |
|
|
lastLumis.push_back(lastLumi);
|
42 |
|
|
}
|
43 |
|
|
void clear() {
|
44 |
|
|
runs.clear();
|
45 |
|
|
firstLumis.clear();
|
46 |
|
|
lastLumis.clear();
|
47 |
|
|
}
|
48 |
|
|
bool accept(int run, int luminosityBlock) const {
|
49 |
|
|
if (runs.empty()) return true;
|
50 |
|
|
for (int i = 0, n = runs.size(); i < n; ++i) {
|
51 |
|
|
if (runs[i] == run) {
|
52 |
|
|
if ((firstLumis[i] <= luminosityBlock) && (luminosityBlock <= lastLumis[i])) return true;
|
53 |
|
|
}
|
54 |
|
|
}
|
55 |
|
|
return false;
|
56 |
|
|
}
|
57 |
|
|
|
58 |
|
|
private:
|
59 |
|
|
std::vector<int> runs, firstLumis, lastLumis;
|
60 |
|
|
};
|
61 |
|
|
|
62 |
|
|
template<typename T>
|
63 |
|
|
class ObjectCountSelector : public EventSelector {
|
64 |
|
|
public:
|
65 |
|
|
ObjectCountSelector(const char *label, const char *instance, const char *process,
|
66 |
|
|
const char *cut, int minNumber=1, int maxNumber=-1) :
|
67 |
|
|
label_(label), instance_(instance),
|
68 |
|
|
min_(minNumber), max_(maxNumber),
|
69 |
|
|
scanner(new helper::ScannerBase(helper::Parser::elementType(Reflex::Type::ByTypeInfo(HandleT::TempWrapT::typeInfo()))))
|
70 |
|
|
{
|
71 |
|
|
scanner->setCut(cut);
|
72 |
gpetrucc |
1.2 |
scanner->setIgnoreExceptions(true);
|
73 |
gpetrucc |
1.1 |
}
|
74 |
|
|
~ObjectCountSelector() { delete scanner; }
|
75 |
|
|
virtual bool accept(const fwlite::EventBase &ev) const {
|
76 |
|
|
int nfound = 0;
|
77 |
|
|
HandleT handle; // here, not as a datamember, otherwise CINT segfaults (!?)
|
78 |
|
|
handle.getByLabel(ev, label_.c_str(), instance_.c_str(), process_.c_str());
|
79 |
|
|
const std::vector<T> & vals = *handle;
|
80 |
|
|
for (size_t j = 0, n = vals.size(); j < n; ++j) {
|
81 |
|
|
if (scanner->test(&vals[j])) nfound++;
|
82 |
|
|
}
|
83 |
|
|
return (nfound >= min_ && (max_ == -1 || nfound <= max_));
|
84 |
|
|
}
|
85 |
|
|
void setCut(const char *cut) { scanner->setCut(cut); }
|
86 |
|
|
void setMin(int minNumber) { min_ = minNumber; }
|
87 |
|
|
void setMax(int maxNumber) { max_ = maxNumber; }
|
88 |
gpetrucc |
1.2 |
void setIgnoreExceptions(bool ignoreThem=true) { scanner->setIgnoreExceptions(ignoreThem); }
|
89 |
|
|
protected:
|
90 |
gpetrucc |
1.1 |
typedef fwlite::Handle<std::vector<T> > HandleT;
|
91 |
|
|
std::string label_, instance_, process_;
|
92 |
|
|
int min_, max_;
|
93 |
|
|
helper::ScannerBase *scanner; // has to be a pointer, otherwise CINT segfaults in setCut (!?)
|
94 |
|
|
// prevent copy c-tor and assignment
|
95 |
|
|
ObjectCountSelector(const fwlite::ObjectCountSelector<T> &other) ;
|
96 |
|
|
ObjectCountSelector & operator=(const fwlite::ObjectCountSelector<T> &other) ;
|
97 |
|
|
};
|
98 |
|
|
}
|