CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
StringCutEventSelector.h
Go to the documentation of this file.
1 #ifndef _StringCutEventSelector
2 #define _StringCutEventSelector
3 
9 
10 template<typename Object>
12  public:
14  StringCutEventSelector(pset, iC) {}
16  EventSelector(pset, iC),
17  src_(edm::Service<InputTagDistributorService>()->retrieve("src",pset)),
18  srcToken_(iC.consumes<edm::View<Object> >(src_)),
19  f_(pset.getParameter<std::string>("cut")),
20  //put this guy to 0 to do the check on "all" object in the collection
21  nFirst_(pset.getParameter<unsigned int>("nFirst"))
22  {
23  std::stringstream ss;
24  ss<<"string cut based selection on collection: "<<src_;
25  description_.push_back(ss.str());
26  ss.str("");
27  description_.push_back(std::string("selection cut is: ")+pset.getParameter<std::string>("cut"));
28  }
29 
30  bool select (const edm::Event& e) const{
32  e.getByToken(srcToken_, oH);
33  //reject events if not enough object in collection
34  // if ((nFirst_!=0) && (oH->size()<nFirst_)) return false;
35  unsigned int i=0;
36  for (;i!=oH->size();i++)
37  {
38  //stop doing the check if reaching too far in the collection
39  if ((nFirst_!=0) && (i>=nFirst_)) break;
40  const Object & o = (*oH)[i];
41  if (!f_(o)) return false;
42  }
43  return true;
44  }
45 
46  private:
50  unsigned int nFirst_;
51 };
52 
53 
54 template<typename Object, bool existenceMatter=true>
56  public:
58  StringCutsEventSelector(pset, iC) {}
60  EventSelector(pset, iC),
61  src_(edm::Service<InputTagDistributorService>()->retrieve("src",pset)),
62  srcToken_(iC.consumes<edm::View<Object> >(src_))
63  {
64  std::vector<std::string> selection=pset.getParameter<std::vector<std::string > >("cut");
65  std::stringstream ss;
66  ss<<"string cut based selection on collection: "<<src_;
67  description_.push_back(ss.str()); ss.str("");
68  description_.push_back("selection cuts are:");
69  for (unsigned int i=0;i!=selection.size();i++)
70  if (selection[i]!="-"){
71  f_.push_back( new StringCutObjectSelector<Object>(selection[i]));
72  ss<<"["<<i<<"]: "<<selection[i];
73  description_.push_back(ss.str()); ss.str("");
74  }
75  else
76  {
77  f_.push_back(0);
78  ss<<"["<<i<<"]: no selection";
79  description_.push_back(ss.str()); ss.str("");
80  }
81  }
82  ~StringCutsEventSelector(){unsigned int i=0; for (;i!=f_.size();i++) if (f_[i]){ delete f_[i];f_[i]=0;}}
83 
84  bool select (const edm::Event& e) const{
86  e.getByToken(srcToken_, oH);
87  unsigned int i=0;
88  if (existenceMatter && oH->size()<f_.size()) return false;
89  for (;i!=f_.size();i++)
90  {
91  if (!existenceMatter && i==oH->size()) break;
92  if (!f_[i]) continue;
93  const Object & o = (*oH)[i];
94  if (!(*f_[i])(o)) return false;
95  }
96  return true;
97  }
98 
99  private:
102  std::vector<StringCutObjectSelector<Object> *> f_;
103 };
104 
105 #endif
edm::EDGetTokenT< edm::View< Object > > srcToken_
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
StringCutEventSelector(const edm::ParameterSet &pset, edm::ConsumesCollector &iC)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:434
bool select(const edm::Event &e) const
decision of the selector module
selection
main part
Definition: corrVsCorr.py:98
bool select(const edm::Event &e) const
decision of the selector module
StringCutsEventSelector(const edm::ParameterSet &pset, edm::ConsumesCollector &&iC)
std::vector< StringCutObjectSelector< Object > * > f_
StringCutEventSelector(const edm::ParameterSet &pset, edm::ConsumesCollector &&iC)
StringCutObjectSelector< Object > f_
edm::EDGetTokenT< edm::View< Object > > srcToken_
A selector of events.
Definition: EventSelector.h:16
std::vector< std::string > description_
Definition: EventSelector.h:34
StringCutsEventSelector(const edm::ParameterSet &pset, edm::ConsumesCollector &iC)