CMS 3D CMS Logo

List of all members | Public Member Functions | Protected Attributes | Static Private Member Functions | 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 unsigned bitMap () const
 
vid::CutFlowResult cutFlowResult () const
 
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) final
 
bool operator() (const T &ref, edm::EventBase const &e, pat::strbitset &ret) final
 
bool operator() (typename T::value_type const &t)
 
bool operator() (typename T::value_type const &t, edm::EventBase const &e)
 
bool operator() (T const &t) final
 This provides an alternative signature without the second ret. More...
 
bool operator() (T const &t, edm::EventBase const &e) final
 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, pat::strbitset &ret)=0
 This provides the interface for base classes to select objects. More...
 
virtual bool operator() (T const &t, edm::EventBase const &e, pat::strbitset &ret)
 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

unsigned bitmap_
 
std::vector< typename Selector< T >::index_typecut_indices_
 
std::vector< std::shared_ptr< candf::CandidateCut > > cuts_
 
unsigned howfar_
 
bool initialized_
 
std::vector< bool > needs_event_content_
 
std::vector< double > values_
 
- 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...
 

Static Private Member Functions

static void validateParamsAreTracked (const edm::ParameterSet &conf)
 

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::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
 

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 46 of file VersionedSelector.h.

Constructor & Destructor Documentation

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

Definition at line 48 of file VersionedSelector.h.

48 : Selector<T>(), initialized_(false) {}
Functor that operates on <T>
Definition: Selector.h:23
template<class T>
VersionedSelector< T >::VersionedSelector ( const edm::ParameterSet conf)
inline

Definition at line 50 of file VersionedSelector.h.

50  :
51  Selector<T>(),
52  initialized_(false) {
53 
55 
56  name_ = conf.getParameter<std::string>("idName");
57 
58  // now setup the md5 and cute accessor functions
59  constexpr unsigned length = MD5_DIGEST_LENGTH;
60  std::string tracked(conf.trackedPart().dump());
61  memset(id_md5_,0,length*sizeof(unsigned char));
62  MD5((unsigned char*)tracked.c_str(), tracked.size(), id_md5_);
63  char buf[32];
64  for( unsigned i=0; i<MD5_DIGEST_LENGTH; ++i ){
65  sprintf(buf, "%02x", id_md5_[i]);
66  md5_string_.append( buf );
67  }
68  initialize(conf);
69  this->retInternal_ = this->getBitTemplate();
70  }
T getParameter(std::string const &) const
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:285
ParameterSet trackedPart() const
void initialize(const edm::ParameterSet &)
Functor that operates on <T>
Definition: Selector.h:23
pat::strbitset getBitTemplate() const
Get an empty bitset with the proper names.
Definition: Selector.h:210
unsigned char id_md5_[MD5_DIGEST_LENGTH]
static void validateParamsAreTracked(const edm::ParameterSet &conf)
#define constexpr

Member Function Documentation

template<class T>
const unsigned VersionedSelector< T >::bitMap ( ) const
inline

Definition at line 148 of file VersionedSelector.h.

148 { return bitmap_; }
template<class T >
vid::CutFlowResult VersionedSelector< T >::cutFlowResult ( ) const

Definition at line 255 of file VersionedSelector.h.

References training_settings::idx, dataset::name, and AlCaHLTBitMon_QueryRunRegistry::string.

255  {
256  std::map<std::string,unsigned> names_to_index;
257  std::map<std::string,unsigned> cut_counter;
258  for( unsigned idx = 0; idx < cuts_.size(); ++idx ) {
259  const std::string& name = cuts_[idx]->name();
260  if( !cut_counter.count(name) ) cut_counter[name] = 0;
261  std::stringstream realname;
262  realname << name << "_" << cut_counter[name];
263  names_to_index.emplace(realname.str(),idx);
264  cut_counter[name]++;
265  }
266  return vid::CutFlowResult(name_,md5_string_,names_to_index,values_,bitmap_);
267 }
std::vector< double > values_
std::vector< std::shared_ptr< candf::CandidateCut > > cuts_
const std::string & name() const
template<class T>
const size_t VersionedSelector< T >::cutFlowSize ( ) const
inline

Definition at line 150 of file VersionedSelector.h.

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

Definition at line 146 of file VersionedSelector.h.

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

Definition at line 197 of file VersionedSelector.h.

References CINT_GUARD, SoftLeptonByDistance_cfi::distance, Exception, reco::get(), edm::ParameterSet::getParameterSetVector(), dataset::name, and AlCaHLTBitMon_QueryRunRegistry::string.

197  {
198  if(initialized_) {
199  edm::LogWarning("VersionedPatElectronSelector")
200  << "ID was already initialized!";
201  return;
202  }
203  const std::vector<edm::ParameterSet>& cutflow =
204  conf.getParameterSetVector("cutFlow");
205  if( cutflow.empty() ) {
206  throw cms::Exception("InvalidCutFlow")
207  << "You have supplied a null/empty cutflow to VersionedIDSelector,"
208  << " please add content to the cuflow and try again.";
209  }
210 
211  // this lets us keep track of cuts without knowing what they are :D
212  std::vector<edm::ParameterSet>::const_iterator cbegin(cutflow.begin()),
213  cend(cutflow.end());
214  std::vector<edm::ParameterSet>::const_iterator icut = cbegin;
215  std::map<std::string,unsigned> cut_counter;
216  std::vector<std::string> ignored_cuts;
217  for( ; icut != cend; ++icut ) {
218  std::stringstream realname;
219  const std::string& name = icut->getParameter<std::string>("cutName");
220  if( !cut_counter.count(name) ) cut_counter[name] = 0;
221  realname << name << "_" << cut_counter[name];
222  const bool needsContent =
223  icut->getParameter<bool>("needsAdditionalProducts");
224  const bool ignored = icut->getParameter<bool>("isIgnored");
225  CINT_GUARD(cuts_.emplace_back(CutApplicatorFactory::get()->create(name,*icut)));
226  needs_event_content_.push_back(needsContent);
227  const std::string therealname = realname.str();
228  this->push_back(therealname);
229  this->set(therealname);
230  if(ignored) ignored_cuts.push_back(therealname);
231  cut_counter[name]++;
232  }
233  this->setIgnoredCuts(ignored_cuts);
234 
235  //have to loop again to set cut indices after all are filled
236  icut = cbegin;
237  cut_counter.clear();
238  for( ; icut != cend; ++icut ) {
239  std::stringstream realname;
240  const std::string& name = cuts_[std::distance(cbegin,icut)]->name();
241  if( !cut_counter.count(name) ) cut_counter[name] = 0;
242  realname << name << "_" << cut_counter[name];
243  cut_indices_.push_back(typename Selector<T>::index_type(&(this->bits_),realname.str()));
244  cut_counter[name]++;
245  }
246 
247  initialized_ = true;
248 }
VParameterSet const & getParameterSetVector(std::string const &name) const
std::vector< std::shared_ptr< candf::CandidateCut > > cuts_
std::vector< bool > needs_event_content_
const std::string & name() const
pat::strbitset bits_
the bitset indexed by strings
Definition: Selector.h:284
virtual void push_back(std::string const &s)
This is the registration of an individual cut string.
Definition: Selector.h:44
#define CINT_GUARD(CODE)
void setIgnoredCuts(std::vector< std::string > const &bitsToIgnore)
set the bits to ignore from a vector
Definition: Selector.h:165
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 137 of file VersionedSelector.h.

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

Definition at line 142 of file VersionedSelector.h.

Referenced by VIDSelectorBase.VIDSelectorBase::initialize().

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

Definition at line 72 of file VersionedSelector.h.

72  {
73  howfar_ = 0;
74  bitmap_ = 0;
75  values_.clear();
76  bool failed = false;
77  if( !initialized_ ) {
78  throw cms::Exception("CutNotInitialized")
79  << "VersionedGsfElectronSelector not initialized!" << std::endl;
80  }
81  for( unsigned i = 0; i < cuts_.size(); ++i ) {
83  const bool result = (*cuts_[i])(temp);
84  values_.push_back(cuts_[i]->value(temp));
85  if( result || this->ignoreCut(cut_indices_[i]) ) {
86  this->passCut(ret,cut_indices_[i]);
87  bitmap_ |= 1<<i;
88  if( !failed ) ++howfar_;
89  } else {
90  failed = true;
91  }
92  }
93  this->setIgnored(ret);
94  return (bool)ret;
95  }
std::vector< double > values_
void setIgnored(pat::strbitset &ret)
set ignored bits
Definition: Selector.h:222
std::vector< std::shared_ptr< candf::CandidateCut > > cuts_
void passCut(pat::strbitset &ret, std::string const &s)
Passing cuts.
Definition: Selector.h:174
bool ignoreCut(std::string const &s) const
ignore the cut at index "s"
Definition: Selector.h:157
std::vector< typename Selector< T >::index_type > cut_indices_
template<class T>
bool VersionedSelector< T >::operator() ( const T ref,
edm::EventBase const &  e,
pat::strbitset ret 
)
inlinefinal

Definition at line 97 of file VersionedSelector.h.

97  {
98  // setup isolation needs
99  for( size_t i = 0, cutssize = cuts_.size(); i < cutssize; ++i ) {
100  if( needs_event_content_[i] ) {
101  CutApplicatorWithEventContentBase* needsEvent =
102  static_cast<CutApplicatorWithEventContentBase*>(cuts_[i].get());
103  needsEvent->getEventContent(e);
104  }
105  }
106  return this->operator()(ref, ret);
107  }
std::vector< std::shared_ptr< candf::CandidateCut > > cuts_
std::vector< bool > needs_event_content_
virtual void getEventContent(const edm::EventBase &)=0
bool operator()(const T &ref, pat::strbitset &ret) final
template<class T>
bool VersionedSelector< T >::operator() ( typename T::value_type const &  t)
inline

Definition at line 113 of file VersionedSelector.h.

113  {
114  const T temp(&t,0); // assuming T is edm::Ptr
115  return this->operator()(temp);
116  }
long double T
bool operator()(const T &ref, pat::strbitset &ret) final
template<class T>
bool VersionedSelector< T >::operator() ( typename T::value_type const &  t,
edm::EventBase const &  e 
)
inline

Definition at line 118 of file VersionedSelector.h.

118  {
119  const T temp(&t,0);
120  return this->operator()(temp,e);
121  }
long double T
bool operator()(const T &ref, pat::strbitset &ret) final
template<class T>
bool VersionedSelector< T >::operator() ( T const &  t)
inlinefinalvirtual

This provides an alternative signature without the second ret.

Reimplemented from Selector< T >.

Definition at line 123 of file VersionedSelector.h.

123  {
124  this->retInternal_.set(false);
125  this->operator()(t, this->retInternal_);
126  this->setIgnored(this->retInternal_);
127  return (bool)this->retInternal_;
128  }
void setIgnored(pat::strbitset &ret)
set ignored bits
Definition: Selector.h:222
pat::strbitset retInternal_
internal ret if users don&#39;t care about return bits
Definition: Selector.h:285
strbitset & set(bool val=true)
set method of all bits
Definition: strbitset.h:144
bool operator()(const T &ref, pat::strbitset &ret) final
template<class T>
bool VersionedSelector< T >::operator() ( T const &  t,
edm::EventBase const &  e 
)
inlinefinalvirtual

This provides an alternative signature that includes extra information.

Reimplemented from Selector< T >.

Definition at line 130 of file VersionedSelector.h.

130  {
131  this->retInternal_.set(false);
132  this->operator()(t, e, this->retInternal_);
133  this->setIgnored(this->retInternal_);
134  return (bool)this->retInternal_;
135  }
void setIgnored(pat::strbitset &ret)
set ignored bits
Definition: Selector.h:222
pat::strbitset retInternal_
internal ret if users don&#39;t care about return bits
Definition: Selector.h:285
strbitset & set(bool val=true)
set method of all bits
Definition: strbitset.h:144
bool operator()(const T &ref, pat::strbitset &ret) final
template<class T>
bool VersionedSelector< T >::operator== ( const VersionedSelector< T > &  other) const
inline

Definition at line 138 of file VersionedSelector.h.

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

Definition at line 271 of file VersionedSelector.h.

References Exception, mps_fire::i, dataset::name, and CutApplicatorWithEventContentBase::setConsumes().

271  {
272  for( size_t i = 0, cutssize = cuts_.size(); i < cutssize; ++i ) {
273  if( needs_event_content_[i] ) {
274  CutApplicatorWithEventContentBase* needsEvent =
275  dynamic_cast<CutApplicatorWithEventContentBase*>(cuts_[i].get());
276  if( nullptr != needsEvent ) {
277  needsEvent->setConsumes(cc);
278  } else {
279  throw cms::Exception("InvalidCutConfiguration")
280  << "Cut: " << ((CutApplicatorBase*)cuts_[i].get())->name()
281  << " configured to consume event products but does not "
282  << " inherit from CutApplicatorWithEventContenBase "
283  << " please correct either your python or C++!";
284  }
285  }
286  }
287 }
std::vector< std::shared_ptr< candf::CandidateCut > > cuts_
std::vector< bool > needs_event_content_
const std::string & name() const
virtual void setConsumes(edm::ConsumesCollector &)=0
template<class T>
static void VersionedSelector< T >::validateParamsAreTracked ( const edm::ParameterSet conf)
inlinestaticprivate

Definition at line 166 of file VersionedSelector.h.

166  {
167  edm::ParameterSet trackedPart = conf.trackedPart();
168  edm::ParameterSet confWithoutIsPOGApproved;
169  for(auto& paraName : conf.getParameterNames()){
170  if(paraName != "isPOGApproved") confWithoutIsPOGApproved.copyFrom(conf,paraName);
171  else if(conf.existsAs<bool>(paraName,true)) confWithoutIsPOGApproved.copyFrom(conf,paraName); //adding isPOGApproved if its a tracked bool
172  }
173  std::string tracked(conf.trackedPart().dump()), untracked(confWithoutIsPOGApproved.dump());
174  if ( tracked != untracked ) {
175  throw cms::Exception("InvalidConfiguration")
176  << "VersionedSelector does not allow untracked parameters"
177  << " in the cutflow ParameterSet!";
178  }
179  }
bool existsAs(std::string const &parameterName, bool trackiness=true) const
checks if a parameter exists as a given type
Definition: ParameterSet.h:161
std::string dump(unsigned int indent=0) const
ParameterSet trackedPart() const
void copyFrom(ParameterSet const &from, std::string const &name)
std::vector< std::string > getParameterNames() const

Member Data Documentation

template<class T>
unsigned VersionedSelector< T >::bitmap_
protected

Definition at line 187 of file VersionedSelector.h.

template<class T>
std::vector<typename Selector<T>::index_type> VersionedSelector< T >::cut_indices_
protected

Definition at line 186 of file VersionedSelector.h.

template<class T>
std::vector<std::shared_ptr< candf::CandidateCut > > VersionedSelector< T >::cuts_
protected

Definition at line 184 of file VersionedSelector.h.

template<class T>
unsigned VersionedSelector< T >::howfar_
protected

Definition at line 187 of file VersionedSelector.h.

template<class T>
unsigned char VersionedSelector< T >::id_md5_[MD5_DIGEST_LENGTH]
private
template<class T>
bool VersionedSelector< T >::initialized_
protected

Definition at line 183 of file VersionedSelector.h.

template<class T>
std::string VersionedSelector< T >::md5_string_
private

Definition at line 192 of file VersionedSelector.h.

template<class T>
std::string VersionedSelector< T >::name_
private

Definition at line 192 of file VersionedSelector.h.

template<class T>
std::vector<bool> VersionedSelector< T >::needs_event_content_
protected

Definition at line 185 of file VersionedSelector.h.

template<class T>
std::vector<double> VersionedSelector< T >::values_
protected

Definition at line 188 of file VersionedSelector.h.