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

Constructor & Destructor Documentation

◆ VersionedSelector() [1/2]

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

Definition at line 48 of file VersionedSelector.h.

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

◆ VersionedSelector() [2/2]

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

Definition at line 50 of file VersionedSelector.h.

50  : Selector<T>(), initialized_(false) {
52 
53  name_ = conf.getParameter<std::string>("idName");
54 
55  // now setup the md5 and cute accessor functions
56  constexpr unsigned length = MD5_DIGEST_LENGTH;
57  std::string tracked(conf.trackedPart().dump());
58  memset(id_md5_, 0, length * sizeof(unsigned char));
59  MD5((unsigned char*)tracked.c_str(), tracked.size(), id_md5_);
60  char buf[32];
61  for (unsigned i = 0; i < MD5_DIGEST_LENGTH; ++i) {
62  sprintf(buf, "%02x", id_md5_[i]);
63  md5_string_.append(buf);
64  }
65  initialize(conf);
66  this->retInternal_ = this->getBitTemplate();
67  }

Member Function Documentation

◆ bitMap()

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

Definition at line 144 of file VersionedSelector.h.

144 { return bitmap_; }

◆ cutFlowResult()

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

Definition at line 246 of file VersionedSelector.h.

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

◆ cutFlowSize()

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

Definition at line 146 of file VersionedSelector.h.

146 { return cuts_.size(); }

◆ howFarInCutFlow()

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

Definition at line 142 of file VersionedSelector.h.

142 { return howfar_; }

◆ initialize()

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

Definition at line 192 of file VersionedSelector.h.

192  {
193  if (initialized_) {
194  edm::LogWarning("VersionedPatElectronSelector") << "ID was already initialized!";
195  return;
196  }
197  const std::vector<edm::ParameterSet>& cutflow = conf.getParameterSetVector("cutFlow");
198  if (cutflow.empty()) {
199  throw cms::Exception("InvalidCutFlow") << "You have supplied a null/empty cutflow to VersionedIDSelector,"
200  << " please add content to the cuflow and try again.";
201  }
202 
203  // this lets us keep track of cuts without knowing what they are :D
204  std::vector<edm::ParameterSet>::const_iterator cbegin(cutflow.begin()), cend(cutflow.end());
205  std::vector<edm::ParameterSet>::const_iterator icut = cbegin;
206  std::map<std::string, unsigned> cut_counter;
207  std::vector<std::string> ignored_cuts;
208  for (; icut != cend; ++icut) {
209  std::stringstream realname;
210  const std::string& name = icut->getParameter<std::string>("cutName");
211  if (!cut_counter.count(name))
212  cut_counter[name] = 0;
213  realname << name << "_" << cut_counter[name];
214  const bool needsContent = icut->getParameter<bool>("needsAdditionalProducts");
215  const bool ignored = icut->getParameter<bool>("isIgnored");
216  CINT_GUARD(cuts_.emplace_back(CutApplicatorFactory::get()->create(name, *icut)));
217  needs_event_content_.push_back(needsContent);
218  const std::string therealname = realname.str();
219  this->push_back(therealname);
220  this->set(therealname);
221  if (ignored)
222  ignored_cuts.push_back(therealname);
223  cut_counter[name]++;
224  }
225  this->setIgnoredCuts(ignored_cuts);
226 
227  //have to loop again to set cut indices after all are filled
228  icut = cbegin;
229  cut_counter.clear();
230  for (; icut != cend; ++icut) {
231  std::stringstream realname;
232  const std::string& name = cuts_[std::distance(cbegin, icut)]->name();
233  if (!cut_counter.count(name))
234  cut_counter[name] = 0;
235  realname << name << "_" << cut_counter[name];
236  cut_indices_.push_back(typename Selector<T>::index_type(&(this->bits_), realname.str()));
237  cut_counter[name]++;
238  }
239 
240  initialized_ = true;
241 }

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

◆ md55Raw()

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

Definition at line 133 of file VersionedSelector.h.

133 { return id_md5_; }

◆ md5String()

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

Definition at line 138 of file VersionedSelector.h.

138 { 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 94 of file VersionedSelector.h.

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

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

69  {
70  howfar_ = 0;
71  bitmap_ = 0;
72  values_.clear();
73  bool failed = false;
74  if (!initialized_) {
75  throw cms::Exception("CutNotInitialized") << "VersionedGsfElectronSelector not initialized!" << std::endl;
76  }
77  for (unsigned i = 0; i < cuts_.size(); ++i) {
79  const bool result = (*cuts_[i])(temp);
80  values_.push_back(cuts_[i]->value(temp));
81  if (result || this->ignoreCut(cut_indices_[i])) {
82  this->passCut(ret, cut_indices_[i]);
83  bitmap_ |= 1 << i;
84  if (!failed)
85  ++howfar_;
86  } else {
87  failed = true;
88  }
89  }
90  this->setIgnored(ret);
91  return (bool)ret;
92  }

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

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

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

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

◆ operator()() [5/6]

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

Definition at line 109 of file VersionedSelector.h.

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

◆ operator()() [6/6]

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

Definition at line 114 of file VersionedSelector.h.

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

◆ operator==()

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

Definition at line 134 of file VersionedSelector.h.

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

◆ setConsumes()

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

Definition at line 263 of file VersionedSelector.h.

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

◆ validateParamsAreTracked()

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

Definition at line 162 of file VersionedSelector.h.

162  {
163  edm::ParameterSet trackedPart = conf.trackedPart();
164  edm::ParameterSet confWithoutIsPOGApproved;
165  for (auto& paraName : conf.getParameterNames()) {
166  if (paraName != "isPOGApproved")
167  confWithoutIsPOGApproved.copyFrom(conf, paraName);
168  else if (conf.existsAs<bool>(paraName, true))
169  confWithoutIsPOGApproved.copyFrom(conf, paraName); //adding isPOGApproved if its a tracked bool
170  }
171  std::string tracked(conf.trackedPart().dump()), untracked(confWithoutIsPOGApproved.dump());
172  if (tracked != untracked) {
173  throw cms::Exception("InvalidConfiguration") << "VersionedSelector does not allow untracked parameters"
174  << " in the cutflow ParameterSet!";
175  }
176  }

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:355
edm::ParameterSet::copyFrom
void copyFrom(ParameterSet const &from, std::string const &name)
Definition: ParameterSet.cc:437
VersionedSelector::operator()
bool operator()(const T &ref, pat::strbitset &ret) final
This provides the interface for base classes to select objects.
Definition: VersionedSelector.h:69
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:355
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:184
pat::strbitset::index_type
Definition: strbitset.h:25
runEdmFileComparison.failed
failed
Definition: runEdmFileComparison.py:225
HLT_2018_cff.distance
distance
Definition: HLT_2018_cff.py:6417
VersionedSelector::cuts_
std::vector< std::shared_ptr< candf::CandidateCut > > cuts_
Definition: VersionedSelector.h:180
VersionedSelector::name
const std::string & name() const
Definition: VersionedSelector.h:140
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:160
CINT_GUARD
#define CINT_GUARD(CODE)
Definition: VersionedSelector.h:17
groupFilesInBlocks.temp
list temp
Definition: groupFilesInBlocks.py:142
training_settings.idx
idx
Definition: training_settings.py:16
vid::CutFlowResult
Definition: VIDCutFlowResult.h:41
VersionedSelector::needs_event_content_
std::vector< bool > needs_event_content_
Definition: VersionedSelector.h:181
VersionedSelector::name_
std::string name_
Definition: VersionedSelector.h:188
VersionedSelector::initialized_
bool initialized_
Definition: VersionedSelector.h:179
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:825
CutApplicatorWithEventContentBase::setConsumes
virtual void setConsumes(edm::ConsumesCollector &)=0
trackingPlots.other
other
Definition: trackingPlots.py:1465
OrderedSet.t
t
Definition: OrderedSet.py:90
CutApplicatorWithEventContentBase::getEventContent
virtual void getEventContent(const edm::EventBase &)=0
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
VersionedSelector::initialize
void initialize(const edm::ParameterSet &)
Definition: VersionedSelector.h:192
edm::LogWarning
Definition: MessageLogger.h:141
Selector::getBitTemplate
pat::strbitset getBitTemplate() const
Get an empty bitset with the proper names.
Definition: Selector.h:168
edm::ParameterSet
Definition: ParameterSet.h:36
VersionedSelector::md5_string_
std::string md5_string_
Definition: VersionedSelector.h:188
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:656
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:154
edm::Ptr< Candidate >
CutApplicatorBase
Definition: CutApplicatorBase.h:45
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
T
long double T
Definition: Basic3DVectorLD.h:48
relativeConstraints.value
value
Definition: relativeConstraints.py:53
Exception
Definition: hltDiff.cc:246
VersionedSelector::id_md5_
unsigned char id_md5_[MD5_DIGEST_LENGTH]
Definition: VersionedSelector.h:187
edm::ParameterSet::trackedPart
ParameterSet trackedPart() const
Definition: ParameterSet.cc:679
Types.untracked
untracked
Definition: Types.py:35
edm::ParameterSet::getParameterSetVector
VParameterSet const & getParameterSetVector(std::string const &name) const
Definition: ParameterSet.cc:2153
VersionedSelector::cut_indices_
std::vector< typename Selector< T >::index_type > cut_indices_
Definition: VersionedSelector.h:182
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:303
VersionedSelector::validateParamsAreTracked
static void validateParamsAreTracked(const edm::ParameterSet &conf)
Definition: VersionedSelector.h:162
VersionedSelector::howfar_
unsigned howfar_
Definition: VersionedSelector.h:183
CutApplicatorWithEventContentBase
Definition: CutApplicatorWithEventContentBase.h:19
VersionedSelector::bitmap_
unsigned bitmap_
Definition: VersionedSelector.h:183
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37