CMS 3D CMS Logo

StringCutEventSelector.h
Go to the documentation of this file.
1 #ifndef _StringCutEventSelector
2 #define _StringCutEventSelector
3 
11 
12 template<typename Object, bool any=false>
14  public:
16  StringCutEventSelector(pset, iC) {}
18  EventSelector(pset, iC),
19  src_(edm::Service<InputTagDistributorService>()->retrieve("src",pset)),
20  srcToken_(iC.consumes<edm::View<Object> >(src_)),
21  f_(pset.getParameter<std::string>("cut")),
22  //put this guy to 0 to do the check on "all" object in the collection
23  nFirst_(pset.getParameter<unsigned int>("nFirst")),
24  order_(0)
25  {
26  std::stringstream ss;
27  ss<<"string cut based selection on collection: "<<src_;
28  description_.push_back(ss.str());
29  ss.str("");
30  description_.push_back(std::string("selection cut is: ")+pset.getParameter<std::string>("cut"));
31  if (pset.exists("order"))
33  }
34 
35  bool select (const edm::Event& e) const{
37  e.getByToken(srcToken_, oH);
38  std::vector<const Object*> copyToSort(oH->size());
39  for (uint i=0;i!=oH->size();++i) copyToSort[i]= &(*oH)[i];
40  if (order_)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  {
48  const Object & o = *(copyToSort[i]);
49  if (any){
50  if (f_(o)) ++found;
51  if (found>=nFirst_)
52  return true;
53  }
54  else{
55  //stop doing the check if reaching too far in the collection
56  if ((nFirst_!=0) && (i>=nFirst_)) break;
57  if (!f_(o)) return false;
58  }
59  }
60  return !any;
61  }
62 
63  private:
67  unsigned int nFirst_;
69 };
70 
71 
72 template<typename Object, bool existenceMatter=true>
74  public:
76  StringCutsEventSelector(pset, iC) {}
78  EventSelector(pset, iC),
79  src_(edm::Service<InputTagDistributorService>()->retrieve("src",pset)),
80  srcToken_(iC.consumes<edm::View<Object> >(src_)),
81  order_(0)
82  {
83  std::vector<std::string> selection=pset.getParameter<std::vector<std::string > >("cut");
84  std::stringstream ss;
85  ss<<"string cut based selection on collection: "<<src_;
86  description_.push_back(ss.str()); ss.str("");
87  description_.push_back("selection cuts are:");
88  for (unsigned int i=0;i!=selection.size();i++)
89  if (selection[i]!="-"){
90  f_.push_back( new StringCutObjectSelector<Object>(selection[i]));
91  ss<<"["<<i<<"]: "<<selection[i];
92  description_.push_back(ss.str()); ss.str("");
93  }
94  else
95  {
96  f_.push_back(0);
97  ss<<"["<<i<<"]: no selection";
98  description_.push_back(ss.str()); ss.str("");
99  }
100  if (pset.exists("order"))
102  }
104  unsigned int i=0;
105  for (;i!=f_.size();i++)
106  if (f_[i]){
107  delete f_[i];f_[i]=0;
108  }
109  if (order_) delete order_;
110  }
111 
112  bool select (const edm::Event& e) const{
114  e.getByToken(srcToken_, oH);
115  std::vector<const Object*> copyToSort(oH->size());
116  for (uint i=0;i!=oH->size();++i) copyToSort[i]= &(*oH)[i];
117  if (order_)std::sort(copyToSort.begin(), copyToSort.end(), sortByStringFunction<Object>(order_));
118 
119  unsigned int i=0;
120  if (existenceMatter && oH->size()<f_.size()) return false;
121  for (;i!=f_.size();i++)
122  {
123  if (!existenceMatter && i==oH->size()) break;
124  if (!f_[i]) continue;
125  const Object & o = *(copyToSort[i]);
126  if (!(*f_[i])(o)) return false;
127  }
128  return true;
129  }
130 
131  private:
134  std::vector<StringCutObjectSelector<Object> *> f_;
136 };
137 
138 #endif
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:457
bool any(const std::vector< T > &v, const T &what)
Definition: ECalSD.cc:34
selection
main part
Definition: corrVsCorr.py:98
bool exists(std::string const &parameterName) const
checks if a parameter exists
bool select(const edm::Event &e) const
decision of the selector module
bool select(const edm::Event &e) const
decision of the selector module
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_
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)