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:
15  StringCutEventSelector(pset, iC) {}
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")),
24  {
25  std::stringstream ss;
26  ss<<"string cut based selection on collection: "<<src_;
27  description_.push_back(ss.str());
28  ss.str("");
29  description_.push_back(std::string("selection cut is: ")+pset.getParameter<std::string>("cut"));
30  if (pset.exists("order"))
32  }
33 
34  bool select (const edm::Event& e) const override{
36  e.getByToken(srcToken_, oH);
37  std::vector<const Object*> copyToSort(oH->size());
38  for (uint i=0;i!=oH->size();++i) copyToSort[i]= &(*oH)[i];
39  if (order_)std::sort(copyToSort.begin(), copyToSort.end(), sortByStringFunction<Object>(order_));
40 
41  //reject events if not enough object in collection
42  // if ((nFirst_!=0) && (oH->size()<nFirst_)) return false;
43  unsigned int i=0;
44  unsigned int found=0;
45  for (;i!=oH->size();i++)
46  {
47  const Object & o = *(copyToSort[i]);
48  if (any){
49  if (f_(o)) ++found;
50  if (found>=nFirst_)
51  return true;
52  }
53  else{
54  //stop doing the check if reaching too far in the collection
55  if ((nFirst_!=0) && (i>=nFirst_)) break;
56  if (!f_(o)) return false;
57  }
58  }
59  return !any;
60  }
61 
62  private:
66  unsigned int nFirst_;
68 };
69 
70 
71 template<typename Object, bool existenceMatter=true>
73  public:
75  StringCutsEventSelector(pset, iC) {}
77  EventSelector(pset, iC),
78  src_(edm::Service<InputTagDistributorService>()->retrieve("src",pset)),
79  srcToken_(iC.consumes<edm::View<Object> >(src_)),
81  {
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()); ss.str("");
86  description_.push_back("selection cuts are:");
87  for (unsigned int i=0;i!=selection.size();i++)
88  if (selection[i]!="-"){
89  f_.push_back( new StringCutObjectSelector<Object>(selection[i]));
90  ss<<"["<<i<<"]: "<<selection[i];
91  description_.push_back(ss.str()); ss.str("");
92  }
93  else
94  {
95  f_.push_back(nullptr);
96  ss<<"["<<i<<"]: no selection";
97  description_.push_back(ss.str()); ss.str("");
98  }
99  if (pset.exists("order"))
101  }
103  unsigned int i=0;
104  for (;i!=f_.size();i++)
105  if (f_[i]){
106  delete f_[i];f_[i]=nullptr;
107  }
108  if (order_) delete order_;
109  }
110 
111  bool select (const edm::Event& e) const override{
113  e.getByToken(srcToken_, oH);
114  std::vector<const Object*> copyToSort(oH->size());
115  for (uint i=0;i!=oH->size();++i) copyToSort[i]= &(*oH)[i];
116  if (order_)std::sort(copyToSort.begin(), copyToSort.end(), sortByStringFunction<Object>(order_));
117 
118  unsigned int i=0;
119  if (existenceMatter && oH->size()<f_.size()) return false;
120  for (;i!=f_.size();i++)
121  {
122  if (!existenceMatter && i==oH->size()) break;
123  if (!f_[i]) continue;
124  const Object & o = *(copyToSort[i]);
125  if (!(*f_[i])(o)) return false;
126  }
127  return true;
128  }
129 
130  private:
133  std::vector<StringCutObjectSelector<Object> *> f_;
135 };
136 
137 #endif
bool select(const edm::Event &e) const override
decision of the selector module
T getParameter(std::string const &) const
bool select(const edm::Event &e) const override
decision of the selector module
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:579
bool any(const std::vector< T > &v, const T &what)
Definition: ECalSD.cc:37
selection
main part
Definition: corrVsCorr.py:99
bool exists(std::string const &parameterName) const
checks if a parameter exists
#define nullptr
StringCutsEventSelector(const edm::ParameterSet &pset, edm::ConsumesCollector &&iC)
StringCutEventSelector(const edm::ParameterSet &pset, edm::ConsumesCollector &&iC)
std::vector< StringCutObjectSelector< Object > * > f_
StringObjectFunction< Object > * order_
edm::EDGetTokenT< edm::View< Object > > srcToken_
edm::EDGetTokenT< edm::View< Object > > srcToken_
def uint(string)
A selector of events.
Definition: EventSelector.h:16
StringObjectFunction< Object > * order_
HLT enums.
StringCutObjectSelector< Object > f_
std::vector< std::string > description_
Definition: EventSelector.h:34
StringCutsEventSelector(const edm::ParameterSet &pset, edm::ConsumesCollector &iC)
StringCutEventSelector(const edm::ParameterSet &pset, edm::ConsumesCollector &iC)