CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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
 This provides the interface for base classes to select objects. More...
 
bool operator() (const T &ref, edm::EventBase const &e, pat::strbitset &ret) final
 This provides an alternative signature that includes extra information. More...
 
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
 
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_type
cut_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_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 47 of file VersionedSelector.h.

Constructor & Destructor Documentation

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

Definition at line 49 of file VersionedSelector.h.

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

Definition at line 51 of file VersionedSelector.h.

References visDQMUpload::buf, edm::ParameterSet::dump(), Selector< T >::getBitTemplate(), edm::ParameterSet::getParameter(), mps_fire::i, VersionedSelector< T >::id_md5_, VersionedSelector< T >::initialize(), VersionedSelector< T >::md5_string_, VersionedSelector< T >::name_, Selector< T >::retInternal_, AlCaHLTBitMon_QueryRunRegistry::string, edm::ParameterSet::trackedPart(), and VersionedSelector< T >::validateParamsAreTracked().

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

Member Function Documentation

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

Definition at line 145 of file VersionedSelector.h.

References VersionedSelector< T >::bitmap_.

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

Definition at line 247 of file VersionedSelector.h.

References mergeVDriftHistosByStation::name, and AlCaHLTBitMon_QueryRunRegistry::string.

247  {
248  std::map<std::string, unsigned> names_to_index;
249  std::map<std::string, unsigned> cut_counter;
250  for (unsigned idx = 0; idx < cuts_.size(); ++idx) {
251  const std::string& name = cuts_[idx]->name();
252  if (!cut_counter.count(name))
253  cut_counter[name] = 0;
254  std::stringstream realname;
255  realname << name << "_" << cut_counter[name];
256  names_to_index.emplace(realname.str(), idx);
257  cut_counter[name]++;
258  }
259  return vid::CutFlowResult(name_, md5_string_, names_to_index, values_, bitmap_);
260 }
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 147 of file VersionedSelector.h.

References VersionedSelector< T >::cuts_.

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

Definition at line 143 of file VersionedSelector.h.

References VersionedSelector< T >::howfar_.

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

Definition at line 193 of file VersionedSelector.h.

References CINT_GUARD, HLT_FULL_cff::distance, Exception, get, edm::ParameterSet::getParameterSetVector(), mergeVDriftHistosByStation::name, push_back(), and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by VersionedSelector< T >::VersionedSelector().

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

Definition at line 134 of file VersionedSelector.h.

References VersionedSelector< T >::id_md5_.

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

Definition at line 139 of file VersionedSelector.h.

References VersionedSelector< T >::md5_string_.

Referenced by VIDSelectorBase.VIDSelectorBase::initialize().

139 { 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 
)
inlinefinalvirtual

This provides the interface for base classes to select objects.

Implements Selector< T >.

Definition at line 70 of file VersionedSelector.h.

References VersionedSelector< T >::bitmap_, VersionedSelector< T >::cut_indices_, VersionedSelector< T >::cuts_, Exception, VersionedSelector< T >::howfar_, mps_fire::i, Selector< T >::ignoreCut(), VersionedSelector< T >::initialized_, Selector< T >::passCut(), mps_fire::result, runTheMatrix::ret, Selector< T >::setIgnored(), groupFilesInBlocks::temp, relativeConstraints::value, and VersionedSelector< T >::values_.

Referenced by VersionedSelector< T >::operator()().

70  {
71  howfar_ = 0;
72  bitmap_ = 0;
73  values_.clear();
74  bool failed = false;
75  if (!initialized_) {
76  throw cms::Exception("CutNotInitialized") << "VersionedGsfElectronSelector not initialized!" << std::endl;
77  }
78  for (unsigned i = 0; i < cuts_.size(); ++i) {
80  const bool result = (*cuts_[i])(temp);
81  values_.push_back(cuts_[i]->value(temp));
82  if (result || this->ignoreCut(cut_indices_[i])) {
83  this->passCut(ret, cut_indices_[i]);
84  bitmap_ |= 1 << i;
85  if (!failed)
86  ++howfar_;
87  } else {
88  failed = true;
89  }
90  }
91  this->setIgnored(ret);
92  return (bool)ret;
93  }
tuple ret
prodAgent to be discontinued
std::vector< double > values_
void setIgnored(pat::strbitset &ret)
set ignored bits
Definition: Selector.h:181
std::vector< std::shared_ptr< candf::CandidateCut > > cuts_
tuple result
Definition: mps_fire.py:311
void passCut(pat::strbitset &ret, std::string const &s)
Passing cuts.
Definition: Selector.h:142
bool ignoreCut(std::string const &s) const
ignore the cut at index &quot;s&quot;
Definition: Selector.h:127
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 
)
inlinefinalvirtual

This provides an alternative signature that includes extra information.

Reimplemented from Selector< T >.

Definition at line 95 of file VersionedSelector.h.

References VersionedSelector< T >::cuts_, alignCSCRings::e, CutApplicatorWithEventContentBase::getEventContent(), mps_fire::i, VersionedSelector< T >::needs_event_content_, VersionedSelector< T >::operator()(), and runTheMatrix::ret.

95  {
96  // setup isolation needs
97  for (size_t i = 0, cutssize = cuts_.size(); i < cutssize; ++i) {
98  if (needs_event_content_[i]) {
100  needsEvent->getEventContent(e);
101  }
102  }
103  return this->operator()(ref, ret);
104  }
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
This provides the interface for base classes to select objects.
template<class T >
bool VersionedSelector< T >::operator() ( typename T::value_type const &  t)
inline

Definition at line 110 of file VersionedSelector.h.

References VersionedSelector< T >::operator()(), and groupFilesInBlocks::temp.

110  {
111  const T temp(&t, 0); // assuming T is edm::Ptr
112  return this->operator()(temp);
113  }
long double T
bool operator()(const T &ref, pat::strbitset &ret) final
This provides the interface for base classes to select objects.
template<class T >
bool VersionedSelector< T >::operator() ( typename T::value_type const &  t,
edm::EventBase const &  e 
)
inline

Definition at line 115 of file VersionedSelector.h.

References VersionedSelector< T >::operator()(), and groupFilesInBlocks::temp.

115  {
116  const T temp(&t, 0);
117  return this->operator()(temp, e);
118  }
long double T
bool operator()(const T &ref, pat::strbitset &ret) final
This provides the interface for base classes to select objects.
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 120 of file VersionedSelector.h.

References VersionedSelector< T >::operator()(), Selector< T >::retInternal_, pat::strbitset::set(), Selector< T >::setIgnored(), and submitPVValidationJobs::t.

120  {
121  this->retInternal_.set(false);
122  this->operator()(t, this->retInternal_);
123  this->setIgnored(this->retInternal_);
124  return (bool)this->retInternal_;
125  }
void setIgnored(pat::strbitset &ret)
set ignored bits
Definition: Selector.h:181
pat::strbitset retInternal_
internal ret if users don&#39;t care about return bits
Definition: Selector.h:242
strbitset & set(bool val=true)
set method of all bits
Definition: strbitset.h:126
bool operator()(const T &ref, pat::strbitset &ret) final
This provides the interface for base classes to select objects.
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 127 of file VersionedSelector.h.

References alignCSCRings::e, VersionedSelector< T >::operator()(), Selector< T >::retInternal_, pat::strbitset::set(), Selector< T >::setIgnored(), and submitPVValidationJobs::t.

127  {
128  this->retInternal_.set(false);
129  this->operator()(t, e, this->retInternal_);
130  this->setIgnored(this->retInternal_);
131  return (bool)this->retInternal_;
132  }
void setIgnored(pat::strbitset &ret)
set ignored bits
Definition: Selector.h:181
pat::strbitset retInternal_
internal ret if users don&#39;t care about return bits
Definition: Selector.h:242
strbitset & set(bool val=true)
set method of all bits
Definition: strbitset.h:126
bool operator()(const T &ref, pat::strbitset &ret) final
This provides the interface for base classes to select objects.
template<class T >
bool VersionedSelector< T >::operator== ( const VersionedSelector< T > &  other) const
inline

Definition at line 135 of file VersionedSelector.h.

References VersionedSelector< T >::id_md5_.

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

Definition at line 264 of file VersionedSelector.h.

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

264  {
265  for (size_t i = 0, cutssize = cuts_.size(); i < cutssize; ++i) {
266  if (needs_event_content_[i]) {
267  CutApplicatorWithEventContentBase* needsEvent = dynamic_cast<CutApplicatorWithEventContentBase*>(cuts_[i].get());
268  if (nullptr != needsEvent) {
269  needsEvent->setConsumes(cc);
270  } else {
271  throw cms::Exception("InvalidCutConfiguration") << "Cut: " << ((CutApplicatorBase*)cuts_[i].get())->name()
272  << " configured to consume event products but does not "
273  << " inherit from CutApplicatorWithEventContenBase "
274  << " please correct either your python or C++!";
275  }
276  }
277  }
278 }
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 163 of file VersionedSelector.h.

References edm::ParameterSet::copyFrom(), edm::ParameterSet::dump(), Exception, edm::ParameterSet::existsAs(), edm::ParameterSet::getParameterNames(), AlCaHLTBitMon_QueryRunRegistry::string, edm::ParameterSet::trackedPart(), and Types::untracked.

Referenced by VersionedSelector< T >::VersionedSelector().

163  {
164  edm::ParameterSet trackedPart = conf.trackedPart();
165  edm::ParameterSet confWithoutIsPOGApproved;
166  for (auto& paraName : conf.getParameterNames()) {
167  if (paraName != "isPOGApproved")
168  confWithoutIsPOGApproved.copyFrom(conf, paraName);
169  else if (conf.existsAs<bool>(paraName, true))
170  confWithoutIsPOGApproved.copyFrom(conf, paraName); //adding isPOGApproved if its a tracked bool
171  }
172  std::string tracked(conf.trackedPart().dump()), untracked(confWithoutIsPOGApproved.dump());
173  if (tracked != untracked) {
174  throw cms::Exception("InvalidConfiguration") << "VersionedSelector does not allow untracked parameters"
175  << " in the cutflow ParameterSet!";
176  }
177  }
bool existsAs(std::string const &parameterName, bool trackiness=true) const
checks if a parameter exists as a given type
Definition: ParameterSet.h:171
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
tuple untracked
Definition: Types.py:34

Member Data Documentation

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

Definition at line 183 of file VersionedSelector.h.

Referenced by VersionedSelector< T >::operator()().

template<class T >
std::vector<std::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

Definition at line 180 of file VersionedSelector.h.

Referenced by VersionedSelector< T >::operator()().

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

Definition at line 182 of file VersionedSelector.h.

Referenced by VersionedSelector< T >::operator()().

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

Definition at line 185 of file VersionedSelector.h.

Referenced by VersionedSelector< T >::operator()().