CMS 3D CMS Logo

List of all members | Public Types | Public Member Functions | Protected Attributes
Selector< T > Class Template Referenceabstract

Functor that operates on <T> More...

#include "CommonTools/Utils/interface/Selector.h"

Inheritance diagram for Selector< T >:
VersionedSelector< T >

Public Types

typedef std::pair< index_type, size_t > cut_flow_item
 
typedef std::vector< cut_flow_itemcut_flow_map
 
typedef T data_type
 
typedef std::map< index_type, double > double_map
 
typedef pat::strbitset::index_type index_type
 
typedef std::map< index_type, int > int_map
 

Public Member Functions

void clear (index_type const &i)
 
void clear (std::string const &s)
 Turn off a given selection cut. More...
 
bool considerCut (index_type const &i) const
 
bool considerCut (std::string const &s) const
 consider the cut at index "s" More...
 
double cut (index_type const &i, double val) const
 Access the double cut values at index "s". More...
 
int cut (index_type const &i, int val) const
 Access the int cut values at index "s". More...
 
double cut (std::string s, double val) const
 Access the double cut values at index "s". More...
 
int cut (std::string s, int val) const
 Access the int cut values at index "s". More...
 
pat::strbitset getBitTemplate () const
 Get an empty bitset with the proper names. More...
 
double getPasses (index_type const &i) const
 
double getPasses (std::string const &s) const
 Return the number of passing cases. More...
 
bool ignoreCut (index_type const &i) const
 
bool ignoreCut (std::string const &s) const
 ignore the cut at index "s" More...
 
virtual bool operator() (T const &t)
 This provides an alternative signature without the second ret. More...
 
virtual bool operator() (T const &t, edm::EventBase const &e)
 This provides an alternative signature that includes extra information. More...
 
virtual bool operator() (T const &t, edm::EventBase const &e, pat::strbitset &ret)
 This provides an alternative signature that includes extra information. More...
 
virtual bool operator() (T const &t, pat::strbitset &ret)=0
 This provides the interface for base classes to select objects. More...
 
bool operator[] (index_type const &i) const
 
bool operator[] (std::string const &s) const
 
void passCut (pat::strbitset &ret, index_type const &i)
 
void passCut (pat::strbitset &ret, std::string const &s)
 Passing cuts. More...
 
void print (std::ostream &out) const
 Print the cut flow. More...
 
void printActiveCuts (std::ostream &out) const
 Print the cuts being considered. More...
 
virtual void push_back (std::string const &s)
 This is the registration of an individual cut string. More...
 
virtual void push_back (std::string const &s, double cut)
 This is the registration of an individual cut string, with a double cut value. More...
 
virtual void push_back (std::string const &s, int cut)
 This is the registration of an individual cut string, with an int cut value. More...
 
 Selector ()
 Constructor clears the bits. More...
 
void set (index_type const &i, bool val=true)
 
void set (index_type const &i, double cut, bool val=true)
 
void set (index_type const &i, int cut, bool val=true)
 
void set (std::string const &s, bool val=true)
 Set a given selection cut, on or off. More...
 
void set (std::string const &s, double cut, bool val=true)
 Set a given selection cut, on or off, and reset int cut value. More...
 
void set (std::string const &s, int cut, bool val=true)
 Set a given selection cut, on or off, and reset int cut value. More...
 
void setIgnored (pat::strbitset &ret)
 set ignored bits More...
 
void setIgnoredCuts (std::vector< std::string > const &bitsToIgnore)
 set the bits to ignore from a vector More...
 
virtual ~Selector ()
 

Protected Attributes

pat::strbitset bits_
 the bitset indexed by strings More...
 
cut_flow_map cutFlow_
 map of cut flows in "human" order More...
 
double_map doubleCuts_
 the double-value cut map More...
 
int_map intCuts_
 the int-value cut map More...
 
pat::strbitset retInternal_
 internal ret if users don't care about return bits More...
 

Detailed Description

template<class T>
class Selector< T >

Functor that operates on <T>

Implements a string-indexed bit_vector.

class template that implements an interface to Selector utilities. This allows the user to access individual cuts based on a string index. The user can then turn individual cuts on and off at will.

Author
Salvatore Rappoccio

Definition at line 22 of file Selector.h.

Member Typedef Documentation

◆ cut_flow_item

template<class T>
typedef std::pair<index_type, size_t> Selector< T >::cut_flow_item

Definition at line 26 of file Selector.h.

◆ cut_flow_map

template<class T>
typedef std::vector<cut_flow_item> Selector< T >::cut_flow_map

Definition at line 27 of file Selector.h.

◆ data_type

template<class T>
typedef T Selector< T >::data_type

Definition at line 24 of file Selector.h.

◆ double_map

template<class T>
typedef std::map<index_type, double> Selector< T >::double_map

Definition at line 29 of file Selector.h.

◆ index_type

template<class T>
typedef pat::strbitset::index_type Selector< T >::index_type

Definition at line 25 of file Selector.h.

◆ int_map

template<class T>
typedef std::map<index_type, int> Selector< T >::int_map

Definition at line 28 of file Selector.h.

Constructor & Destructor Documentation

◆ Selector()

template<class T>
Selector< T >::Selector ( )
inline

Constructor clears the bits.

Definition at line 32 of file Selector.h.

32  {
33  bits_.clear();
34  intCuts_.clear();
35  doubleCuts_.clear();
36  cutFlow_.clear();
38  }

◆ ~Selector()

template<class T>
virtual Selector< T >::~Selector ( )
inlinevirtual

Definition at line 39 of file Selector.h.

39 {}

Member Function Documentation

◆ clear() [1/2]

template<class T>
void Selector< T >::clear ( index_type const &  i)
inline

Definition at line 113 of file Selector.h.

113 { bits_[i] = false; }

◆ clear() [2/2]

template<class T>
void Selector< T >::clear ( std::string const &  s)
inline

Turn off a given selection cut.

Definition at line 111 of file Selector.h.

111 { clear(index_type(&bits_, s)); }

Referenced by Selector< edm::Ptr< reco::Photon > >::clear().

◆ considerCut() [1/2]

template<class T>
bool Selector< T >::considerCut ( index_type const &  i) const
inline

Definition at line 124 of file Selector.h.

124 { return bits_[i] == true; }

◆ considerCut() [2/2]

template<class T>
bool Selector< T >::considerCut ( std::string const &  s) const
inline

consider the cut at index "s"

Definition at line 123 of file Selector.h.

123 { return bits_[s] == true; }

Referenced by Selector< edm::Ptr< reco::Photon > >::print(), and Selector< edm::Ptr< reco::Photon > >::printActiveCuts().

◆ cut() [1/4]

template<class T>
double Selector< T >::cut ( index_type const &  i,
double  val 
) const
inline

Access the double cut values at index "s".

Definition at line 160 of file Selector.h.

160 { return doubleCuts_.find(i)->second; };

◆ cut() [2/4]

template<class T>
int Selector< T >::cut ( index_type const &  i,
int  val 
) const
inline

Access the int cut values at index "s".

Definition at line 158 of file Selector.h.

158 { return intCuts_.find(i)->second; };

Referenced by Selector< edm::Ptr< reco::Photon > >::push_back(), and Selector< edm::Ptr< reco::Photon > >::set().

◆ cut() [3/4]

template<class T>
double Selector< T >::cut ( std::string  s,
double  val 
) const
inline

Access the double cut values at index "s".

Definition at line 165 of file Selector.h.

165 { return cut(index_type(&bits_, s), val); };

Referenced by Selector< edm::Ptr< reco::Photon > >::cut().

◆ cut() [4/4]

template<class T>
int Selector< T >::cut ( std::string  s,
int  val 
) const
inline

Access the int cut values at index "s".

Definition at line 163 of file Selector.h.

163 { return cut(index_type(&bits_, s), val); };

Referenced by Selector< edm::Ptr< reco::Photon > >::cut().

◆ getBitTemplate()

template<class T>
pat::strbitset Selector< T >::getBitTemplate ( ) const
inline

Get an empty bitset with the proper names.

Definition at line 168 of file Selector.h.

168  {
170  ret.set(false);
171  for (cut_flow_map::const_iterator cutsBegin = cutFlow_.begin(), cutsEnd = cutFlow_.end(), icut = cutsBegin;
172  icut != cutsEnd;
173  ++icut) {
174  if (ignoreCut(icut->first))
175  ret[icut->first] = true;
176  }
177  return ret;
178  }

Referenced by SimpleJetFilter::filter(), WPlusJetsEventSelector::operator()(), Selector< edm::Ptr< reco::Photon > >::Selector(), and VersionedSelector< edm::Ptr< reco::Photon > >::VersionedSelector().

◆ getPasses() [1/2]

template<class T>
double Selector< T >::getPasses ( index_type const &  i) const
inline

Definition at line 228 of file Selector.h.

228  {
229  cut_flow_map::const_iterator found = cutFlow_.end();
230  for (cut_flow_map::const_iterator cutsBegin = cutFlow_.begin(), cutsEnd = cutFlow_.end(), icut = cutsBegin;
231  icut != cutsEnd && found == cutsEnd;
232  ++icut) {
233  if (icut->first == i) {
234  found = icut;
235  }
236  }
237  return found->second;
238  }

◆ getPasses() [2/2]

template<class T>
double Selector< T >::getPasses ( std::string const &  s) const
inline

Return the number of passing cases.

Definition at line 227 of file Selector.h.

227 { return getPasses(index_type(&bits_, s)); }

Referenced by Selector< edm::Ptr< reco::Photon > >::getPasses().

◆ ignoreCut() [1/2]

template<class T>
bool Selector< T >::ignoreCut ( index_type const &  i) const
inline

Definition at line 128 of file Selector.h.

128 { return bits_[i] == false; }

◆ ignoreCut() [2/2]

template<class T>
bool Selector< T >::ignoreCut ( std::string const &  s) const
inline

◆ operator()() [1/4]

template<class T>
virtual bool Selector< T >::operator() ( T const &  t)
inlinevirtual

◆ operator()() [2/4]

template<class T>
virtual bool Selector< T >::operator() ( T const &  t,
edm::EventBase const &  e 
)
inlinevirtual

◆ operator()() [3/4]

template<class T>
virtual bool Selector< T >::operator() ( T const &  t,
edm::EventBase const &  e,
pat::strbitset ret 
)
inlinevirtual

◆ operator()() [4/4]

template<class T>
virtual bool Selector< T >::operator() ( T const &  t,
pat::strbitset ret 
)
pure virtual

◆ operator[]() [1/2]

template<class T>
bool Selector< T >::operator[] ( index_type const &  i) const
inline

Definition at line 120 of file Selector.h.

120 { return bits_[i]; }

◆ operator[]() [2/2]

template<class T>
bool Selector< T >::operator[] ( std::string const &  s) const
inline

Access the selector cut at index "s". "true" means to consider the cut. "false" means to ignore the cut.

Definition at line 118 of file Selector.h.

118 { return bits_[s]; }

◆ passCut() [1/2]

template<class T>
void Selector< T >::passCut ( pat::strbitset ret,
index_type const &  i 
)
inline

Definition at line 144 of file Selector.h.

144  {
145  ret[i] = true;
146  cut_flow_map::iterator found = cutFlow_.end();
147  for (cut_flow_map::iterator cutsBegin = cutFlow_.begin(), cutsEnd = cutFlow_.end(), icut = cutsBegin;
148  icut != cutsEnd && found == cutsEnd;
149  ++icut) {
150  if (icut->first == i) {
151  found = icut;
152  }
153  }
154  ++(found->second);
155  }

◆ passCut() [2/2]

template<class T>
void Selector< T >::passCut ( pat::strbitset ret,
std::string const &  s 
)
inline

◆ print()

template<class T>
void Selector< T >::print ( std::ostream &  out) const
inline

Print the cut flow.

Definition at line 191 of file Selector.h.

191  {
192  for (cut_flow_map::const_iterator cutsBegin = cutFlow_.begin(), cutsEnd = cutFlow_.end(), icut = cutsBegin;
193  icut != cutsEnd;
194  ++icut) {
195  char buff[1000];
196  if (considerCut(icut->first)) {
197  sprintf(buff,
198  "%6lu : %20s %10lu",
199  static_cast<unsigned long>(icut - cutsBegin),
200  icut->first.str().c_str(),
201  static_cast<unsigned long>(icut->second));
202  } else {
203  sprintf(
204  buff, "%6lu : %20s %10s", static_cast<unsigned long>(icut - cutsBegin), icut->first.str().c_str(), "off");
205  }
206  out << buff << std::endl;
207  }
208  }

Referenced by WPlusJetsEventSelector::printSelectors().

◆ printActiveCuts()

template<class T>
void Selector< T >::printActiveCuts ( std::ostream &  out) const
inline

Print the cuts being considered.

Definition at line 211 of file Selector.h.

211  {
212  bool already_printed_one = false;
213  for (cut_flow_map::const_iterator cutsBegin = cutFlow_.begin(), cutsEnd = cutFlow_.end(), icut = cutsBegin;
214  icut != cutsEnd;
215  ++icut) {
216  if (considerCut(icut->first)) {
217  if (already_printed_one)
218  out << ", ";
219  out << icut->first;
220  already_printed_one = true;
221  }
222  }
223  out << std::endl;
224  }

◆ push_back() [1/3]

template<class T>
virtual void Selector< T >::push_back ( std::string const &  s)
inlinevirtual

This is the registration of an individual cut string.

Definition at line 42 of file Selector.h.

42  {
43  bits_.push_back(s);
44  index_type i(&bits_, s);
45  // don't need to check to see if the key is already there,
46  // bits_ does that.
47  cutFlow_.push_back(cut_flow_item(i, 0));
48  }

◆ push_back() [2/3]

template<class T>
virtual void Selector< T >::push_back ( std::string const &  s,
double  cut 
)
inlinevirtual

This is the registration of an individual cut string, with a double cut value.

Definition at line 61 of file Selector.h.

61  {
62  bits_.push_back(s);
63  index_type i(&bits_, s);
64  doubleCuts_[i] = cut;
65  // don't need to check to see if the key is already there,
66  // bits_ does that.
67  cutFlow_.push_back(cut_flow_item(i, 0));
68  }

◆ push_back() [3/3]

template<class T>
virtual void Selector< T >::push_back ( std::string const &  s,
int  cut 
)
inlinevirtual

This is the registration of an individual cut string, with an int cut value.

Definition at line 51 of file Selector.h.

51  {
52  bits_.push_back(s);
53  index_type i(&bits_, s);
54  intCuts_[i] = cut;
55  // don't need to check to see if the key is already there,
56  // bits_ does that.
57  cutFlow_.push_back(cut_flow_item(i, 0));
58  }

◆ set() [1/6]

template<class T>
void Selector< T >::set ( index_type const &  i,
bool  val = true 
)
inline

Definition at line 94 of file Selector.h.

94 { bits_[i] = val; }

◆ set() [2/6]

template<class T>
void Selector< T >::set ( index_type const &  i,
double  cut,
bool  val = true 
)
inline

Definition at line 105 of file Selector.h.

105  {
106  bits_[i] = val;
107  doubleCuts_[i] = cut;
108  }

◆ set() [3/6]

template<class T>
void Selector< T >::set ( index_type const &  i,
int  cut,
bool  val = true 
)
inline

Definition at line 98 of file Selector.h.

98  {
99  bits_[i] = val;
100  intCuts_[i] = cut;
101  }

◆ set() [4/6]

template<class T>
void Selector< T >::set ( std::string const &  s,
bool  val = true 
)
inline

Set a given selection cut, on or off.

Definition at line 93 of file Selector.h.

93 { set(index_type(&bits_, s), val); }

Referenced by pat::Flags::get(), Selector< edm::Ptr< reco::Photon > >::set(), and Selector< edm::Ptr< reco::Photon > >::setIgnoredCuts().

◆ set() [5/6]

template<class T>
void Selector< T >::set ( std::string const &  s,
double  cut,
bool  val = true 
)
inline

Set a given selection cut, on or off, and reset int cut value.

Definition at line 104 of file Selector.h.

104 { set(index_type(&bits_, s), cut); }

Referenced by Selector< edm::Ptr< reco::Photon > >::set().

◆ set() [6/6]

template<class T>
void Selector< T >::set ( std::string const &  s,
int  cut,
bool  val = true 
)
inline

Set a given selection cut, on or off, and reset int cut value.

Definition at line 97 of file Selector.h.

97 { set(index_type(&bits_, s), cut); }

Referenced by Selector< edm::Ptr< reco::Photon > >::set().

◆ setIgnored()

template<class T>
void Selector< T >::setIgnored ( pat::strbitset ret)
inline

set ignored bits

Definition at line 181 of file Selector.h.

181  {
182  for (cut_flow_map::const_iterator cutsBegin = cutFlow_.begin(), cutsEnd = cutFlow_.end(), icut = cutsBegin;
183  icut != cutsEnd;
184  ++icut) {
185  if (ignoreCut(icut->first))
186  ret[icut->first] = true;
187  }
188  }

Referenced by VersionedSelector< edm::Ptr< reco::Photon > >::operator()(), and Selector< edm::Ptr< reco::Photon > >::operator()().

◆ setIgnoredCuts()

template<class T>
void Selector< T >::setIgnoredCuts ( std::vector< std::string > const &  bitsToIgnore)
inline

set the bits to ignore from a vector

Definition at line 131 of file Selector.h.

131  {
132  for (std::vector<std::string>::const_iterator ignoreBegin = bitsToIgnore.begin(),
133  ignoreEnd = bitsToIgnore.end(),
134  ibit = ignoreBegin;
135  ibit != ignoreEnd;
136  ++ibit) {
137  set(*ibit, false);
138  }
139  }

Member Data Documentation

◆ bits_

template<class T>
pat::strbitset Selector< T >::bits_
protected

◆ cutFlow_

template<class T>
cut_flow_map Selector< T >::cutFlow_
protected

◆ doubleCuts_

template<class T>
double_map Selector< T >::doubleCuts_
protected

◆ intCuts_

template<class T>
int_map Selector< T >::intCuts_
protected

◆ retInternal_

template<class T>
pat::strbitset Selector< T >::retInternal_
protected
runTheMatrix.ret
ret
prodAgent to be discontinued
Definition: runTheMatrix.py:367
Selector::setIgnored
void setIgnored(pat::strbitset &ret)
set ignored bits
Definition: Selector.h:181
Selector::bits_
pat::strbitset bits_
the bitset indexed by strings
Definition: Selector.h:241
mps_fire.i
i
Definition: mps_fire.py:428
Selector::operator()
virtual bool operator()(T const &t, pat::strbitset &ret)=0
This provides the interface for base classes to select objects.
Selector::index_type
pat::strbitset::index_type index_type
Definition: Selector.h:25
pat::strbitset::set
strbitset & set(bool val=true)
set method of all bits
Definition: strbitset.h:126
Selector::retInternal_
pat::strbitset retInternal_
internal ret if users don't care about return bits
Definition: Selector.h:242
Selector::cut_flow_item
std::pair< index_type, size_t > cut_flow_item
Definition: Selector.h:26
Selector::ignoreCut
bool ignoreCut(std::string const &s) const
ignore the cut at index "s"
Definition: Selector.h:127
pat::strbitset::clear
void clear()
clear the bitset and map
Definition: strbitset.h:67
Selector::intCuts_
int_map intCuts_
the int-value cut map
Definition: Selector.h:243
Selector::doubleCuts_
double_map doubleCuts_
the double-value cut map
Definition: Selector.h:244
Selector::clear
void clear(std::string const &s)
Turn off a given selection cut.
Definition: Selector.h:111
Selector::getPasses
double getPasses(std::string const &s) const
Return the number of passing cases.
Definition: Selector.h:227
newFWLiteAna.found
found
Definition: newFWLiteAna.py:118
pat::strbitset::push_back
void push_back(std::string s)
Definition: strbitset.h:90
alignCSCRings.s
s
Definition: alignCSCRings.py:92
Selector::getBitTemplate
pat::strbitset getBitTemplate() const
Get an empty bitset with the proper names.
Definition: Selector.h:168
Selector::considerCut
bool considerCut(std::string const &s) const
consider the cut at index "s"
Definition: Selector.h:123
Selector::cutFlow_
cut_flow_map cutFlow_
map of cut flows in "human" order
Definition: Selector.h:245
Selector::passCut
void passCut(pat::strbitset &ret, std::string const &s)
Passing cuts.
Definition: Selector.h:142
pat::strbitset
Definition: strbitset.h:23
heppy_batch.val
val
Definition: heppy_batch.py:351
Selector::cut
int cut(index_type const &i, int val) const
Access the int cut values at index "s".
Definition: Selector.h:158
MillePedeFileConverter_cfg.out
out
Definition: MillePedeFileConverter_cfg.py:31
Selector::set
void set(std::string const &s, bool val=true)
Set a given selection cut, on or off.
Definition: Selector.h:93
submitPVValidationJobs.t
string t
Definition: submitPVValidationJobs.py:644
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37