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 
8 
9 template<typename Object>
11  public:
13  EventSelector(pset),
14  src_(edm::Service<InputTagDistributorService>()->retrieve("src",pset)),
15  f_(pset.getParameter<std::string>("cut")),
16  //put this guy to 0 to do the check on "all" object in the collection
17  nFirst_(pset.getParameter<unsigned int>("nFirst"))
18  {
19  std::stringstream ss;
20  ss<<"string cut based selection on collection: "<<src_;
21  description_.push_back(ss.str());
22  ss.str("");
23  description_.push_back(std::string("selection cut is: ")+pset.getParameter<std::string>("cut"));
24  }
25 
26  bool select (const edm::Event& e) const{
28  e.getByLabel(src_, oH);
29  //reject events if not enough object in collection
30  // if ((nFirst_!=0) && (oH->size()<nFirst_)) return false;
31  unsigned int i=0;
32  for (;i!=oH->size();i++)
33  {
34  //stop doing the check if reaching too far in the collection
35  if ((nFirst_!=0) && (i>=nFirst_)) break;
36  const Object & o = (*oH)[i];
37  if (!f_(o)) return false;
38  }
39  return true;
40  }
41 
42  private:
45  unsigned int nFirst_;
46 };
47 
48 
49 template<typename Object, bool existenceMatter=true>
51  public:
53  EventSelector(pset),
54  src_(edm::Service<InputTagDistributorService>()->retrieve("src",pset))
55  {
56  std::vector<std::string> selection=pset.getParameter<std::vector<std::string > >("cut");
57  std::stringstream ss;
58  ss<<"string cut based selection on collection: "<<src_;
59  description_.push_back(ss.str()); ss.str("");
60  description_.push_back("selection cuts are:");
61  for (unsigned int i=0;i!=selection.size();i++)
62  if (selection[i]!="-"){
63  f_.push_back( new StringCutObjectSelector<Object>(selection[i]));
64  ss<<"["<<i<<"]: "<<selection[i];
65  description_.push_back(ss.str()); ss.str("");
66  }
67  else
68  {
69  f_.push_back(0);
70  ss<<"["<<i<<"]: no selection";
71  description_.push_back(ss.str()); ss.str("");
72  }
73  }
74  ~StringCutsEventSelector(){unsigned int i=0; for (;i!=f_.size();i++) if (f_[i]){ delete f_[i];f_[i]=0;}}
75 
76  bool select (const edm::Event& e) const{
78  e.getByLabel(src_, oH);
79  unsigned int i=0;
80  if (existenceMatter && oH->size()<f_.size()) return false;
81  for (;i!=f_.size();i++)
82  {
83  if (!existenceMatter && i==oH->size()) break;
84  if (!f_[i]) continue;
85  const Object & o = (*oH)[i];
86  if (!(*f_[i])(o)) return false;
87  }
88  return true;
89  }
90 
91  private:
93  std::vector<StringCutObjectSelector<Object> *> f_;
94 };
95 
96 #endif
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
std::vector< std::string > description_
Definition: EventSelector.h:31
bool select(const edm::Event &e) const
decision of the selector module
bool select(const edm::Event &e) const
decision of the selector module
std::vector< StringCutObjectSelector< Object > * > f_
tuple pset
Definition: CrabTask.py:85
StringCutObjectSelector< Object > f_
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:359
StringCutsEventSelector(const edm::ParameterSet &pset)
StringCutEventSelector(const edm::ParameterSet &pset)
A selector of events.
Definition: EventSelector.h:15