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, edm::EventBase const &e, pat::strbitset &ret) final
 This provides an alternative signature that includes extra information. More...
 
bool operator() (const T &ref, pat::strbitset &ret) final
 This provides the interface for base classes to select objects. More...
 
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() (typename T::value_type const &t)
 
bool operator() (typename T::value_type const &t, edm::EventBase const &e)
 
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 (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...
 
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

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

Constructor & Destructor Documentation

◆ VersionedSelector() [1/2]

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

Definition at line 49 of file VersionedSelector.h.

49 : Selector<T>(), initialized_(false) {}

◆ VersionedSelector() [2/2]

template<class T>
VersionedSelector< T >::VersionedSelector ( const edm::ParameterSet conf)
inline

Definition at line 51 of file VersionedSelector.h.

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  }

Member Function Documentation

◆ bitMap()

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

Definition at line 145 of file VersionedSelector.h.

145 { return bitmap_; }

◆ cutFlowResult()

template<class T >
vid::CutFlowResult VersionedSelector< T >::cutFlowResult ( ) const

Definition at line 247 of file VersionedSelector.h.

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 }

◆ cutFlowSize()

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

Definition at line 147 of file VersionedSelector.h.

147 { return cuts_.size(); }

◆ howFarInCutFlow()

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

Definition at line 143 of file VersionedSelector.h.

143 { return howfar_; }

◆ initialize()

template<class T >
void VersionedSelector< T >::initialize ( const edm::ParameterSet conf)

Definition at line 193 of file VersionedSelector.h.

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 }

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

◆ md55Raw()

template<class T>
const unsigned char* VersionedSelector< T >::md55Raw ( ) const
inline

Definition at line 134 of file VersionedSelector.h.

134 { return id_md5_; }

◆ md5String()

template<class T>
const std::string& VersionedSelector< T >::md5String ( ) const
inline

Definition at line 139 of file VersionedSelector.h.

139 { return md5_string_; }

Referenced by VIDSelectorBase.VIDSelectorBase::initialize().

◆ name()

template<class T>
const std::string& VersionedSelector< T >::name ( void  ) const
inline

◆ operator()() [1/6]

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.

95  {
96  // setup isolation needs
97  for (size_t i = 0, cutssize = cuts_.size(); i < cutssize; ++i) {
98  if (needs_event_content_[i]) {
99  CutApplicatorWithEventContentBase* needsEvent = static_cast<CutApplicatorWithEventContentBase*>(cuts_[i].get());
100  needsEvent->getEventContent(e);
101  }
102  }
103  return this->operator()(ref, ret);
104  }

◆ operator()() [2/6]

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.

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  }

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

◆ operator()() [3/6]

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.

120  {
121  this->retInternal_.set(false);
122  this->operator()(t, this->retInternal_);
123  this->setIgnored(this->retInternal_);
124  return (bool)this->retInternal_;
125  }

◆ operator()() [4/6]

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.

127  {
128  this->retInternal_.set(false);
129  this->operator()(t, e, this->retInternal_);
130  this->setIgnored(this->retInternal_);
131  return (bool)this->retInternal_;
132  }

◆ operator()() [5/6]

template<class T>
bool VersionedSelector< T >::operator() ( typename T::value_type const &  t)
inline

Definition at line 110 of file VersionedSelector.h.

110  {
111  const T temp(&t, 0); // assuming T is edm::Ptr
112  return this->operator()(temp);
113  }

◆ operator()() [6/6]

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.

115  {
116  const T temp(&t, 0);
117  return this->operator()(temp, e);
118  }

◆ operator==()

template<class T>
bool VersionedSelector< T >::operator== ( const VersionedSelector< T > &  other) const
inline

Definition at line 135 of file VersionedSelector.h.

135  {
136  constexpr unsigned length = MD5_DIGEST_LENGTH;
137  return (0 == memcmp(id_md5_, other.id_md5_, length * sizeof(unsigned char)));
138  }

◆ setConsumes()

template<class T >
void VersionedSelector< T >::setConsumes ( edm::ConsumesCollector  cc)

Definition at line 264 of file VersionedSelector.h.

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 }

◆ validateParamsAreTracked()

template<class T>
static void VersionedSelector< T >::validateParamsAreTracked ( const edm::ParameterSet conf)
inlinestaticprivate

Definition at line 163 of file VersionedSelector.h.

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  }

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

Member Data Documentation

◆ bitmap_

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

◆ cut_indices_

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

◆ cuts_

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

◆ howfar_

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

◆ id_md5_

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

◆ initialized_

template<class T>
bool VersionedSelector< T >::initialized_
protected

◆ md5_string_

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

◆ name_

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

◆ needs_event_content_

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

◆ values_

template<class T>
std::vector<double> VersionedSelector< T >::values_
protected
runTheMatrix.ret
ret
prodAgent to be discontinued
Definition: runTheMatrix.py:543
edm::ParameterSet::copyFrom
void copyFrom(ParameterSet const &from, std::string const &name)
Definition: ParameterSet.cc:444
VersionedSelector::operator()
bool operator()(const T &ref, pat::strbitset &ret) final
This provides the interface for base classes to select objects.
Definition: VersionedSelector.h:70
Selector::setIgnored
void setIgnored(pat::strbitset &ret)
set ignored bits
Definition: Selector.h:181
Selector
Functor that operates on <T>
Definition: Selector.h:22
Selector::bits_
pat::strbitset bits_
the bitset indexed by strings
Definition: Selector.h:241
mps_fire.i
i
Definition: mps_fire.py:428
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::ignoreCut
bool ignoreCut(std::string const &s) const
ignore the cut at index "s"
Definition: Selector.h:127
VersionedSelector::values_
std::vector< double > values_
Definition: VersionedSelector.h:185
pat::strbitset::index_type
Definition: strbitset.h:25
runEdmFileComparison.failed
failed
Definition: runEdmFileComparison.py:224
VersionedSelector::cuts_
std::vector< std::shared_ptr< candf::CandidateCut > > cuts_
Definition: VersionedSelector.h:181
VersionedSelector::name
const std::string & name() const
Definition: VersionedSelector.h:141
edm::ParameterSet::existsAs
bool existsAs(std::string const &parameterName, bool trackiness=true) const
checks if a parameter exists as a given type
Definition: ParameterSet.h:171
CINT_GUARD
#define CINT_GUARD(CODE)
Definition: VersionedSelector.h:17
groupFilesInBlocks.temp
list temp
Definition: groupFilesInBlocks.py:142
edm::LogWarning
Log< level::Warning, false > LogWarning
Definition: MessageLogger.h:122
vid::CutFlowResult
Definition: VIDCutFlowResult.h:41
VersionedSelector::needs_event_content_
std::vector< bool > needs_event_content_
Definition: VersionedSelector.h:182
heavyIonCSV_trainingSettings.idx
idx
Definition: heavyIonCSV_trainingSettings.py:5
VersionedSelector::name_
std::string name_
Definition: VersionedSelector.h:189
VersionedSelector::initialized_
bool initialized_
Definition: VersionedSelector.h:180
Selector::push_back
virtual void push_back(std::string const &s)
This is the registration of an individual cut string.
Definition: Selector.h:42
edm::ParameterSet::dump
std::string dump(unsigned int indent=0) const
Definition: ParameterSet.cc:832
CutApplicatorWithEventContentBase::setConsumes
virtual void setConsumes(edm::ConsumesCollector &)=0
trackingPlots.other
other
Definition: trackingPlots.py:1464
CutApplicatorWithEventContentBase::getEventContent
virtual void getEventContent(const edm::EventBase &)=0
VersionedSelector::initialize
void initialize(const edm::ParameterSet &)
Definition: VersionedSelector.h:193
Selector::getBitTemplate
pat::strbitset getBitTemplate() const
Get an empty bitset with the proper names.
Definition: Selector.h:168
edm::ParameterSet
Definition: ParameterSet.h:47
VersionedSelector::md5_string_
std::string md5_string_
Definition: VersionedSelector.h:189
Selector::passCut
void passCut(pat::strbitset &ret, std::string const &s)
Passing cuts.
Definition: Selector.h:142
edm::ParameterSet::getParameterNames
std::vector< std::string > getParameterNames() const
Definition: ParameterSet.cc:663
Selector::setIgnoredCuts
void setIgnoredCuts(std::vector< std::string > const &bitsToIgnore)
set the bits to ignore from a vector
Definition: Selector.h:131
get
#define get
cc
visDQMUpload.buf
buf
Definition: visDQMUpload.py:160
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::Ptr< Candidate >
CutApplicatorBase
Definition: CutApplicatorBase.h:45
T
long double T
Definition: Basic3DVectorLD.h:48
relativeConstraints.value
value
Definition: relativeConstraints.py:53
Exception
Definition: hltDiff.cc:245
VersionedSelector::id_md5_
unsigned char id_md5_[MD5_DIGEST_LENGTH]
Definition: VersionedSelector.h:188
edm::ParameterSet::trackedPart
ParameterSet trackedPart() const
Definition: ParameterSet.cc:686
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
Types.untracked
untracked
Definition: Types.py:34
edm::ParameterSet::getParameterSetVector
VParameterSet const & getParameterSetVector(std::string const &name) const
Definition: ParameterSet.cc:2160
VersionedSelector::cut_indices_
std::vector< typename Selector< T >::index_type > cut_indices_
Definition: VersionedSelector.h:183
Selector::set
void set(std::string const &s, bool val=true)
Set a given selection cut, on or off.
Definition: Selector.h:93
mps_fire.result
result
Definition: mps_fire.py:311
HLT_FULL_cff.distance
distance
Definition: HLT_FULL_cff.py:7746
submitPVValidationJobs.t
string t
Definition: submitPVValidationJobs.py:644
VersionedSelector::validateParamsAreTracked
static void validateParamsAreTracked(const edm::ParameterSet &conf)
Definition: VersionedSelector.h:163
VersionedSelector::howfar_
unsigned howfar_
Definition: VersionedSelector.h:184
CutApplicatorWithEventContentBase
Definition: CutApplicatorWithEventContentBase.h:19
VersionedSelector::bitmap_
unsigned bitmap_
Definition: VersionedSelector.h:184
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37