CMS 3D CMS Logo

StringCutEventSelector.h
Go to the documentation of this file.
1 #ifndef _StringCutEventSelector
2 #define _StringCutEventSelector
3 
10 
11 template <typename Object, bool any = false>
13 public:
17  : EventSelector(pset, iC),
18  src_(edm::Service<InputTagDistributorService>()->retrieve("src", pset)),
19  srcToken_(iC.consumes<edm::View<Object> >(src_)),
20  f_(pset.getParameter<std::string>("cut")),
21  //put this guy to 0 to do the check on "all" object in the collection
22  nFirst_(pset.getParameter<unsigned int>("nFirst")),
23  order_(nullptr) {
24  std::stringstream ss;
25  ss << "string cut based selection on collection: " << src_;
26  description_.push_back(ss.str());
27  ss.str("");
28  description_.push_back(std::string("selection cut is: ") + pset.getParameter<std::string>("cut"));
29  if (pset.exists("order"))
30  order_ = new StringObjectFunction<Object>(pset.getParameter<std::string>("order"));
31  }
32 
33  bool select(const edm::Event& e) const override {
35  e.getByToken(srcToken_, oH);
36  std::vector<const Object*> copyToSort(oH->size());
37  for (uint i = 0; i != oH->size(); ++i)
38  copyToSort[i] = &(*oH)[i];
39  if (order_)
40  std::sort(copyToSort.begin(), copyToSort.end(), sortByStringFunction<Object>(order_));
41 
42  //reject events if not enough object in collection
43  // if ((nFirst_!=0) && (oH->size()<nFirst_)) return false;
44  unsigned int i = 0;
45  unsigned int found = 0;
46  for (; i != oH->size(); i++) {
47  const Object& o = *(copyToSort[i]);
48  if (any) {
49  if (f_(o))
50  ++found;
51  if (found >= nFirst_)
52  return true;
53  } else {
54  //stop doing the check if reaching too far in the collection
55  if ((nFirst_ != 0) && (i >= nFirst_))
56  break;
57  if (!f_(o))
58  return false;
59  }
60  }
61  return !any;
62  }
63 
64 private:
68  unsigned int nFirst_;
70 };
71 
72 template <typename Object, bool existenceMatter = true>
74 public:
78  : EventSelector(pset, iC),
79  src_(edm::Service<InputTagDistributorService>()->retrieve("src", pset)),
80  srcToken_(iC.consumes<edm::View<Object> >(src_)),
81  order_(nullptr) {
82  std::vector<std::string> selection = pset.getParameter<std::vector<std::string> >("cut");
83  std::stringstream ss;
84  ss << "string cut based selection on collection: " << src_;
85  description_.push_back(ss.str());
86  ss.str("");
87  description_.push_back("selection cuts are:");
88  for (unsigned int i = 0; i != selection.size(); i++)
89  if (selection[i] != "-") {
91  ss << "[" << i << "]: " << selection[i];
92  description_.push_back(ss.str());
93  ss.str("");
94  } else {
95  f_.push_back(nullptr);
96  ss << "[" << i << "]: no selection";
97  description_.push_back(ss.str());
98  ss.str("");
99  }
100  if (pset.exists("order"))
101  order_ = new StringObjectFunction<Object>(pset.getParameter<std::string>("order"));
102  }
104  unsigned int i = 0;
105  for (; i != f_.size(); i++)
106  if (f_[i]) {
107  delete f_[i];
108  f_[i] = nullptr;
109  }
110  if (order_)
111  delete order_;
112  }
113 
114  bool select(const edm::Event& e) const override {
116  e.getByToken(srcToken_, oH);
117  std::vector<const Object*> copyToSort(oH->size());
118  for (uint i = 0; i != oH->size(); ++i)
119  copyToSort[i] = &(*oH)[i];
120  if (order_)
121  std::sort(copyToSort.begin(), copyToSort.end(), sortByStringFunction<Object>(order_));
122 
123  unsigned int i = 0;
124  if (existenceMatter && oH->size() < f_.size())
125  return false;
126  for (; i != f_.size(); i++) {
127  if (!existenceMatter && i == oH->size())
128  break;
129  if (!f_[i])
130  continue;
131  const Object& o = *(copyToSort[i]);
132  if (!(*f_[i])(o))
133  return false;
134  }
135  return true;
136  }
137 
138 private:
141  std::vector<StringCutObjectSelector<Object>*> f_;
143 };
144 
145 #endif
StringCutsEventSelector::~StringCutsEventSelector
~StringCutsEventSelector() override
Definition: StringCutEventSelector.h:103
mps_fire.i
i
Definition: mps_fire.py:355
InputTagDistributorService
Definition: InputTagDistributor.h:39
StringObjectFunction< Object >
EventSelector.h
StringCutEventSelector
Definition: StringCutEventSelector.h:12
sistrip::View
View
Definition: ConstantsForView.h:26
edm::EDGetTokenT
Definition: EDGetToken.h:33
StringCutEventSelector::select
bool select(const edm::Event &e) const override
decision of the selector module
Definition: StringCutEventSelector.h:33
edm
HLT enums.
Definition: AlignableModifier.h:19
StringCutEventSelector::order_
StringObjectFunction< Object > * order_
Definition: StringCutEventSelector.h:69
StringCutsEventSelector::StringCutsEventSelector
StringCutsEventSelector(const edm::ParameterSet &pset, edm::ConsumesCollector &&iC)
Definition: StringCutEventSelector.h:75
newFWLiteAna.found
found
Definition: newFWLiteAna.py:118
edm::Handle
Definition: AssociativeIterator.h:50
parallelization.uint
uint
Definition: parallelization.py:124
EcalTangentSkim_cfg.o
o
Definition: EcalTangentSkim_cfg.py:36
EventSelector::description_
std::vector< std::string > description_
Definition: EventSelector.h:33
any
bool any(const std::vector< T > &v, const T &what)
Definition: ECalSD.cc:34
StringCutsEventSelector::select
bool select(const edm::Event &e) const override
decision of the selector module
Definition: StringCutEventSelector.h:114
StringCutEventSelector::srcToken_
edm::EDGetTokenT< edm::View< Object > > srcToken_
Definition: StringCutEventSelector.h:66
contentValuesCheck.ss
ss
Definition: contentValuesCheck.py:33
Service.h
corrVsCorr.selection
selection
main part
Definition: corrVsCorr.py:100
Service
sortByStringFunction
Definition: StringObjectFunction.h:34
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
StringCutsEventSelector::srcToken_
edm::EDGetTokenT< edm::View< Object > > srcToken_
Definition: StringCutEventSelector.h:140
edm::ParameterSet
Definition: ParameterSet.h:36
StringCutsEventSelector::order_
StringObjectFunction< Object > * order_
Definition: StringCutEventSelector.h:142
StringCutEventSelector::StringCutEventSelector
StringCutEventSelector(const edm::ParameterSet &pset, edm::ConsumesCollector &&iC)
Definition: StringCutEventSelector.h:14
StringCutsEventSelector
Definition: StringCutEventSelector.h:73
createfilelist.int
int
Definition: createfilelist.py:10
StringCutEventSelector::nFirst_
unsigned int nFirst_
Definition: StringCutEventSelector.h:68
StringCutsEventSelector::f_
std::vector< StringCutObjectSelector< Object > * > f_
Definition: StringCutEventSelector.h:141
StringCutEventSelector::StringCutEventSelector
StringCutEventSelector(const edm::ParameterSet &pset, edm::ConsumesCollector &iC)
Definition: StringCutEventSelector.h:16
InputTagDistributor.h
std
Definition: JetResolutionObject.h:76
StringCutObjectSelector.h
StringCutsEventSelector::StringCutsEventSelector
StringCutsEventSelector(const edm::ParameterSet &pset, edm::ConsumesCollector &iC)
Definition: StringCutEventSelector.h:77
StringCutEventSelector::src_
edm::InputTag src_
Definition: StringCutEventSelector.h:65
StringCutObjectSelector< Object >
StringCutsEventSelector::src_
edm::InputTag src_
Definition: StringCutEventSelector.h:139
EventSelector
A selector of events.
Definition: EventSelector.h:16
ConsumesCollector.h
edm::Event
Definition: Event.h:73
StringObjectFunction.h
edm::InputTag
Definition: InputTag.h:15
edm::ConsumesCollector
Definition: ConsumesCollector.h:39
muonDTDigis_cfi.pset
pset
Definition: muonDTDigis_cfi.py:27
StringCutEventSelector::f_
StringCutObjectSelector< Object > f_
Definition: StringCutEventSelector.h:67
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37