CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Protected Attributes | Private Attributes
VersionedSelector< T > Class Template Reference

cut-flow versioning info in the event provenance More...

#include "PhysicsTools/SelectorUtils/interface/VersionedSelector.h"

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

Public Member Functions

const size_t cutFlowSize () const
 
const unsigned howFarInCutFlow () const
 
void initialize (const edm::ParameterSet &)
 
const unsigned char * md55Raw () const
 
const std::string & md5String () const
 
const std::string & name () const
 
bool operator() (const T &ref, pat::strbitset &ret) overridefinal
 This provides the interface for base classes to select objects. More...
 
bool operator() (const T &ref, edm::EventBase const &e, pat::strbitset &ret) overridefinal
 This provides an alternative signature that includes extra information. More...
 
bool operator== (const VersionedSelector &other) const
 
void setConsumes (edm::ConsumesCollector)
 
 VersionedSelector ()
 
 VersionedSelector (const edm::ParameterSet &conf)
 
- Public Member Functions inherited from Selector< T >
void clear (std::string const &s)
 Turn off a given selection cut. More...
 
void clear (index_type const &i)
 
bool considerCut (std::string const &s) const
 consider the cut at index "s" More...
 
bool considerCut (index_type const &i) const
 
int cut (index_type const &i, int val) const
 Access the int cut values at index "s". More...
 
double cut (index_type const &i, 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...
 
double cut (std::string s, double val) const
 Access the double cut values at index "s". More...
 
pat::strbitset getBitTemplate () const
 Get an empty bitset with the proper names. More...
 
double getPasses (std::string const &s) const
 Return the number of passing cases. More...
 
double getPasses (index_type const &i) const
 
bool ignoreCut (std::string const &s) const
 ignore the cut at index "s" More...
 
bool ignoreCut (index_type const &i) const
 
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...
 
bool operator[] (std::string const &s) const
 
bool operator[] (index_type const &i) const
 
void passCut (pat::strbitset &ret, std::string const &s)
 Passing cuts. More...
 
void passCut (pat::strbitset &ret, index_type const &i)
 
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, int cut)
 This is the registration of an individual cut string, with an int cut value. 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...
 
 Selector ()
 Constructor clears the bits. More...
 
void set (std::string const &s, bool val=true)
 Set a given selection cut, on or off. More...
 
void set (index_type const &i, bool val=true)
 
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 set (index_type const &i, int cut, bool val=true)
 
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 (index_type const &i, double cut, bool val=true)
 
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

std::vector< typename Selector
< T >::index_type
cut_indices_
 
std::vector< boost::shared_ptr
< candf::CandidateCut > > 
cuts_
 
unsigned howfar_
 
bool initialized_
 
std::vector< bool > needs_event_content_
 
- Protected Attributes inherited from Selector< T >
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...
 

Private Attributes

unsigned char id_md5_ [MD5_DIGEST_LENGTH]
 
std::string md5_string_
 
std::string name_
 

Additional Inherited Members

- Public Types inherited from Selector< T >
typedef std::binary_function
< T, pat::strbitset, bool > 
base_type
 
typedef std::pair< index_type,
size_t > 
cut_flow_item
 
typedef std::vector
< cut_flow_item
cut_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
 

Detailed Description

template<class T>
class VersionedSelector< T >

cut-flow versioning info in the event provenance

class template to implement versioning for IDs that's available in the event provenance or available by hash-code in the event record

Author
Lindsey Gray

Definition at line 34 of file VersionedSelector.h.

Constructor & Destructor Documentation

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

Definition at line 36 of file VersionedSelector.h.

36 : Selector<T>(), initialized_(false) {}
Functor that operates on &lt;T&gt;
Definition: Selector.h:24
template<class T>
VersionedSelector< T >::VersionedSelector ( const edm::ParameterSet conf)
inline

Definition at line 38 of file VersionedSelector.h.

38  :
39  Selector<T>(),
40  initialized_(false) {
41  constexpr unsigned length = MD5_DIGEST_LENGTH;
42  edm::ParameterSet trackedPart = conf.trackedPart();
43  name_ = conf.getParameter<std::string>("idName");
44  memset(id_md5_,0,length*sizeof(unsigned char));
45  std::string tracked(trackedPart.dump()), untracked(conf.dump());
46  if ( tracked != untracked ) {
47  throw cms::Exception("InvalidConfiguration")
48  << "VersionedSelector does not allow untracked parameters"
49  << " in the configuration ParameterSet!";
50  }
51  // now setup the md5 and cute accessor functions
52  MD5((unsigned char*)tracked.c_str(), tracked.size(), id_md5_);
53  char buf[32];
54  for( unsigned i=0; i<MD5_DIGEST_LENGTH; ++i ){
55  sprintf(buf, "%02x", id_md5_[i]);
56  md5_string_.append( buf );
57  }
58  initialize(conf);
59  this->retInternal_ = this->getBitTemplate();
60  }
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
std::string dump(unsigned int indent=0) const
pat::strbitset retInternal_
internal ret if users don&#39;t care about return bits
Definition: Selector.h:287
#define constexpr
ParameterSet trackedPart() const
void initialize(const edm::ParameterSet &)
Functor that operates on &lt;T&gt;
Definition: Selector.h:24
pat::strbitset getBitTemplate() const
Get an empty bitset with the proper names.
Definition: Selector.h:212
unsigned char id_md5_[MD5_DIGEST_LENGTH]
tuple untracked
Definition: Types.py:27

Member Function Documentation

template<class T>
const size_t VersionedSelector< T >::cutFlowSize ( ) const
inline

Definition at line 118 of file VersionedSelector.h.

118 { return cuts_.size(); }
std::vector< boost::shared_ptr< candf::CandidateCut > > cuts_
template<class T>
const unsigned VersionedSelector< T >::howFarInCutFlow ( ) const
inline

Definition at line 116 of file VersionedSelector.h.

116 { return howfar_; }
template<class T >
void VersionedSelector< T >::initialize ( const edm::ParameterSet conf)

Definition at line 140 of file VersionedSelector.h.

References edm::hlt::Exception, reco::get(), edm::ParameterSet::getParameterSetVector(), mergeVDriftHistosByStation::name, fwrapper::plugin, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by VersionedSelector< edm::Ptr< reco::GsfElectron > >::VersionedSelector().

140  {
141  if(initialized_) {
142  edm::LogWarning("VersionedPatElectronSelector")
143  << "ID was already initialized!";
144  return;
145  }
146  const std::vector<edm::ParameterSet>& cutflow =
147  conf.getParameterSetVector("cutFlow");
148  if( cutflow.size() == 0 ) {
149  throw cms::Exception("InvalidCutFlow")
150  << "You have supplied a null/empty cutflow to VersionedIDSelector,"
151  << " please add content to the cuflow and try again.";
152  }
153  // this lets us keep track of cuts without knowing what they are :D
154  std::vector<edm::ParameterSet>::const_iterator cbegin(cutflow.begin()),
155  cend(cutflow.end());
156  std::vector<edm::ParameterSet>::const_iterator icut = cbegin;
157  for( ; icut != cend; ++icut ) {
158  const std::string& name = icut->getParameter<std::string>("cutName");
159  const bool needsContent =
160  icut->getParameter<bool>("needsAdditionalProducts");
161  const bool ignored = icut->getParameter<bool>("isIgnored");
163 #if !defined(__CINT__) && !defined(__MAKECINT__) && !defined(__REFLEX__)
164  CutApplicatorFactory::get()->create(name,*icut);
165 #else
166  nullptr;
167 #endif
168  if( plugin != nullptr ) {
169  cuts_.push_back(boost::shared_ptr<candf::CandidateCut>(plugin));
170  } else {
171  throw cms::Exception("BadPluginName")
172  << "The requested cut: " << name << " is not available!";
173  }
174  needs_event_content_.push_back(needsContent);
175  this->push_back(name);
176  this->set(name);
177  if(ignored) this->ignoreCut(name);
178  }
179  //have to loop again to set cut indices after all are filled
180  icut = cbegin;
181  for( ; icut != cend; ++icut ) {
182  const std::string& name = icut->getParameter<std::string>("cutName");
183  cut_indices_.push_back(typename Selector<T>::index_type(&(this->bits_),name));
184  }
185  initialized_ = true;
186 }
void set(std::string const &s, bool val=true)
Set a given selection cut, on or off.
Definition: Selector.h:105
VParameterSet const & getParameterSetVector(std::string const &name) const
auto_ptr< JetDefinition::Plugin > plugin
std::vector< bool > needs_event_content_
const std::string & name() const
pat::strbitset bits_
the bitset indexed by strings
Definition: Selector.h:286
bool ignoreCut(std::string const &s) const
ignore the cut at index &quot;s&quot;
Definition: Selector.h:159
virtual void push_back(std::string const &s)
This is the registration of an individual cut string.
Definition: Selector.h:46
std::vector< boost::shared_ptr< candf::CandidateCut > > cuts_
std::vector< typename Selector< T >::index_type > cut_indices_
T get(const Candidate &c)
Definition: component.h:55
template<class T>
const unsigned char* VersionedSelector< T >::md55Raw ( ) const
inline

Definition at line 107 of file VersionedSelector.h.

107 { return id_md5_; }
unsigned char id_md5_[MD5_DIGEST_LENGTH]
template<class T>
const std::string& VersionedSelector< T >::md5String ( ) const
inline

Definition at line 112 of file VersionedSelector.h.

112 { return md5_string_; }
template<class T>
const std::string& VersionedSelector< T >::name ( void  ) const
inline
template<class T>
bool VersionedSelector< T >::operator() ( const T t,
pat::strbitset ret 
)
inlinefinaloverridevirtual

This provides the interface for base classes to select objects.

Implements Selector< T >.

Definition at line 62 of file VersionedSelector.h.

Referenced by VersionedSelector< edm::Ptr< reco::GsfElectron > >::operator()().

66  {
67  howfar_ = 0;
68  bool failed = false;
69  if( !initialized_ ) {
70  throw cms::Exception("CutNotInitialized")
71  << "VersionedGsfElectronSelector not initialized!" << std::endl;
72  }
73  for( unsigned i = 0; i < cuts_.size(); ++i ) {
75  const bool result = (*cuts_[i])(temp);
76  if( result || this->ignoreCut(cut_indices_[i]) ) {
77  this->passCut(ret,cut_indices_[i]);
78  if( !failed ) ++howfar_;
79  } else {
80  failed = true;
81  }
82  }
83  this->setIgnored(ret);
84  return (bool)ret;
85  }
int i
Definition: DBlmapReader.cc:9
void setIgnored(pat::strbitset &ret)
set ignored bits
Definition: Selector.h:224
void passCut(pat::strbitset &ret, std::string const &s)
Passing cuts.
Definition: Selector.h:176
bool ignoreCut(std::string const &s) const
ignore the cut at index &quot;s&quot;
Definition: Selector.h:159
tuple result
Definition: query.py:137
std::vector< boost::shared_ptr< candf::CandidateCut > > cuts_
std::vector< typename Selector< T >::index_type > cut_indices_
template<class T>
bool VersionedSelector< T >::operator() ( const T t,
edm::EventBase const &  e,
pat::strbitset ret 
)
inlinefinaloverridevirtual

This provides an alternative signature that includes extra information.

Reimplemented from Selector< T >.

Definition at line 87 of file VersionedSelector.h.

91  {
92  // setup isolation needs
93  for( size_t i = 0, cutssize = cuts_.size(); i < cutssize; ++i ) {
94  if( needs_event_content_[i] ) {
96  static_cast<CutApplicatorWithEventContentBase*>(cuts_[i].get());
97  needsEvent->getEventContent(e);
98  }
99  }
100  return this->operator()(ref, ret);
101  }
int i
Definition: DBlmapReader.cc:9
bool operator()(const T &ref, pat::strbitset &ret) overridefinal
This provides the interface for base classes to select objects.
std::vector< bool > needs_event_content_
virtual void getEventContent(const edm::EventBase &)=0
std::vector< boost::shared_ptr< candf::CandidateCut > > cuts_
template<class T>
bool VersionedSelector< T >::operator== ( const VersionedSelector< T > &  other) const
inline

Definition at line 108 of file VersionedSelector.h.

108  {
109  constexpr unsigned length = MD5_DIGEST_LENGTH;
110  return ( 0 == memcmp(id_md5_,other.id_md5_,length*sizeof(unsigned char)) );
111  }
#define constexpr
unsigned char id_md5_[MD5_DIGEST_LENGTH]
template<class T >
void VersionedSelector< T >::setConsumes ( edm::ConsumesCollector  cc)

Definition at line 191 of file VersionedSelector.h.

References i, and CutApplicatorWithEventContentBase::setConsumes().

191  {
192  for( size_t i = 0, cutssize = cuts_.size(); i < cutssize; ++i ) {
193  if( needs_event_content_[i] ) {
194  CutApplicatorWithEventContentBase* needsEvent =
195  static_cast<CutApplicatorWithEventContentBase*>(cuts_[i].get());
196  needsEvent->setConsumes(cc);
197  }
198  }
199 }
int i
Definition: DBlmapReader.cc:9
std::vector< bool > needs_event_content_
std::vector< boost::shared_ptr< candf::CandidateCut > > cuts_
virtual void setConsumes(edm::ConsumesCollector &)=0

Member Data Documentation

template<class T>
std::vector<typename Selector<T>::index_type> VersionedSelector< T >::cut_indices_
protected
template<class T>
std::vector<boost::shared_ptr<candf::CandidateCut> > VersionedSelector< T >::cuts_
protected
template<class T>
unsigned VersionedSelector< T >::howfar_
protected
template<class T>
unsigned char VersionedSelector< T >::id_md5_[MD5_DIGEST_LENGTH]
private
template<class T>
bool VersionedSelector< T >::initialized_
protected
template<class T>
std::string VersionedSelector< T >::md5_string_
private
template<class T>
std::string VersionedSelector< T >::name_
private
template<class T>
std::vector<bool> VersionedSelector< T >::needs_event_content_
protected