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

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 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 &lt;T&gt;
Definition: Selector.h:24
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  constexpr unsigned length = MD5_DIGEST_LENGTH;
54  edm::ParameterSet trackedPart = conf.trackedPart();
55  name_ = conf.getParameter<std::string>("idName");
56  memset(id_md5_,0,length*sizeof(unsigned char));
57  std::string tracked(trackedPart.dump()), untracked(conf.dump());
58  if ( tracked != untracked ) {
59  throw cms::Exception("InvalidConfiguration")
60  << "VersionedSelector does not allow untracked parameters"
61  << " in the cutflow ParameterSet!";
62  }
63  // now setup the md5 and cute accessor functions
64  MD5((unsigned char*)tracked.c_str(), tracked.size(), id_md5_);
65  char buf[32];
66  for( unsigned i=0; i<MD5_DIGEST_LENGTH; ++i ){
67  sprintf(buf, "%02x", id_md5_[i]);
68  md5_string_.append( buf );
69  }
70  initialize(conf);
71  this->retInternal_ = this->getBitTemplate();
72  }
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 unsigned VersionedSelector< T >::bitMap ( ) const
inline

Definition at line 150 of file VersionedSelector.h.

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

Definition at line 239 of file VersionedSelector.h.

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

239  {
240  std::map<std::string,unsigned> names_to_index;
241  std::map<std::string,unsigned> cut_counter;
242  for( unsigned idx = 0; idx < cuts_.size(); ++idx ) {
243  const std::string& name = cuts_[idx]->name();
244  if( !cut_counter.count(name) ) cut_counter[name] = 0;
245  std::stringstream realname;
246  realname << name << "_" << cut_counter[name];
247  names_to_index.emplace(realname.str(),idx);
248  cut_counter[name]++;
249  }
250  return vid::CutFlowResult(name_,md5_string_,names_to_index,values_,bitmap_);
251 }
std::vector< double > values_
std::vector< std::shared_ptr< candf::CandidateCut > > cuts_
const std::string & name() const
tuple idx
DEBUGGING if hasattr(process,&quot;trackMonIterativeTracking2012&quot;): print &quot;trackMonIterativeTracking2012 D...
template<class T>
const size_t VersionedSelector< T >::cutFlowSize ( ) const
inline

Definition at line 152 of file VersionedSelector.h.

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

Definition at line 148 of file VersionedSelector.h.

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

Definition at line 175 of file VersionedSelector.h.

References CINT_GUARD, SurfaceDeformationFactory::create(), HLT_25ns14e33_v1_cff::distance, Exception, reco::get(), edm::ParameterSet::getParameterSetVector(), mergeVDriftHistosByStation::name, fwrapper::plugin, SHARED_PTR, and AlCaHLTBitMon_QueryRunRegistry::string.

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

175  {
176  if(initialized_) {
177  edm::LogWarning("VersionedPatElectronSelector")
178  << "ID was already initialized!";
179  return;
180  }
181  const std::vector<edm::ParameterSet>& cutflow =
182  conf.getParameterSetVector("cutFlow");
183  if( cutflow.size() == 0 ) {
184  throw cms::Exception("InvalidCutFlow")
185  << "You have supplied a null/empty cutflow to VersionedIDSelector,"
186  << " please add content to the cuflow and try again.";
187  }
188 
189  // this lets us keep track of cuts without knowing what they are :D
190  std::vector<edm::ParameterSet>::const_iterator cbegin(cutflow.begin()),
191  cend(cutflow.end());
192  std::vector<edm::ParameterSet>::const_iterator icut = cbegin;
193  std::map<std::string,unsigned> cut_counter;
194  for( ; icut != cend; ++icut ) {
195  const std::string& cname = icut->getParameter<std::string>("cutName");
196  const bool needsContent =
197  icut->getParameter<bool>("needsAdditionalProducts");
198  const bool ignored = icut->getParameter<bool>("isIgnored");
199  candf::CandidateCut* plugin = nullptr;
200  CINT_GUARD(plugin = CutApplicatorFactory::get()->create(cname,*icut));
201  if( plugin != nullptr ) {
202  cuts_.push_back(SHARED_PTR(candf::CandidateCut)(plugin));
203  } else {
204  throw cms::Exception("BadPluginName")
205  << "The requested cut: " << cname << " is not available!";
206  }
207  needs_event_content_.push_back(needsContent);
208  const std::string& name = plugin->name();
209  std::stringstream realname;
210  if( !cut_counter.count(name) ) cut_counter[name] = 0;
211  realname << name << "_" << cut_counter[name];
212  const std::string therealname = realname.str();
213  this->push_back(therealname);
214  this->set(therealname);
215  if(ignored) this->ignoreCut(therealname);
216  cut_counter[name]++;
217  }
218 
219  //have to loop again to set cut indices after all are filled
220  icut = cbegin;
221  cut_counter.clear();
222  for( ; icut != cend; ++icut ) {
223  std::stringstream realname;
224  const std::string& name = cuts_[std::distance(cbegin,icut)]->name();
225  if( !cut_counter.count(name) ) cut_counter[name] = 0;
226  realname << name << "_" << cut_counter[name];
227  cut_indices_.push_back(typename Selector<T>::index_type(&(this->bits_),realname.str()));
228  cut_counter[name]++;
229  }
230 
231  initialized_ = true;
232 }
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
#define SHARED_PTR(T)
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: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
#define CINT_GUARD(CODE)
std::vector< typename Selector< T >::index_type > cut_indices_
SurfaceDeformation * create(int type, const std::vector< double > &params)
T get(const Candidate &c)
Definition: component.h:55
template<class T>
const unsigned char* VersionedSelector< T >::md55Raw ( ) const
inline

Definition at line 139 of file VersionedSelector.h.

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

Definition at line 144 of file VersionedSelector.h.

Referenced by VIDSelectorBase.VIDSelectorBase::initialize().

144 { return md5_string_; }
template<class T>
const std::string& VersionedSelector< T >::name ( void  ) const
inline
template<class T>
virtual 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 74 of file VersionedSelector.h.

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

74  {
75  howfar_ = 0;
76  bitmap_ = 0;
77  values_.clear();
78  bool failed = false;
79  if( !initialized_ ) {
80  throw cms::Exception("CutNotInitialized")
81  << "VersionedGsfElectronSelector not initialized!" << std::endl;
82  }
83  for( unsigned i = 0; i < cuts_.size(); ++i ) {
85  const bool result = (*cuts_[i])(temp);
86  values_.push_back(cuts_[i]->value(temp));
87  if( result || this->ignoreCut(cut_indices_[i]) ) {
88  this->passCut(ret,cut_indices_[i]);
89  bitmap_ |= 1<<i;
90  if( !failed ) ++howfar_;
91  } else {
92  failed = true;
93  }
94  }
95  this->setIgnored(ret);
96  return (bool)ret;
97  }
int i
Definition: DBlmapReader.cc:9
std::vector< double > values_
void setIgnored(pat::strbitset &ret)
set ignored bits
Definition: Selector.h:224
std::vector< std::shared_ptr< candf::CandidateCut > > cuts_
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< typename Selector< T >::index_type > cut_indices_
template<class T>
virtual 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 99 of file VersionedSelector.h.

99  {
100  // setup isolation needs
101  for( size_t i = 0, cutssize = cuts_.size(); i < cutssize; ++i ) {
102  if( needs_event_content_[i] ) {
103  CutApplicatorWithEventContentBase* needsEvent =
104  static_cast<CutApplicatorWithEventContentBase*>(cuts_[i].get());
105  needsEvent->getEventContent(e);
106  }
107  }
108  return this->operator()(ref, ret);
109  }
virtual bool operator()(const T &ref, pat::strbitset &ret) overridefinal
This provides the interface for base classes to select objects.
int i
Definition: DBlmapReader.cc:9
std::vector< std::shared_ptr< candf::CandidateCut > > cuts_
std::vector< bool > needs_event_content_
virtual void getEventContent(const edm::EventBase &)=0
template<class T>
bool VersionedSelector< T >::operator() ( typename T::value_type const &  t)
inline

Definition at line 115 of file VersionedSelector.h.

115  {
116  const T temp(&t,0); // assuming T is edm::Ptr
117  return this->operator()(temp);
118  }
virtual bool operator()(const T &ref, pat::strbitset &ret) overridefinal
This provides the interface for base classes to select objects.
tuple t
Definition: tree.py:139
long double T
template<class T>
bool VersionedSelector< T >::operator() ( typename T::value_type const &  t,
edm::EventBase const &  e 
)
inline

Definition at line 120 of file VersionedSelector.h.

120  {
121  const T temp(&t,0);
122  return this->operator()(temp,e);
123  }
virtual bool operator()(const T &ref, pat::strbitset &ret) overridefinal
This provides the interface for base classes to select objects.
tuple t
Definition: tree.py:139
long double T
template<class T>
virtual bool VersionedSelector< T >::operator() ( T const &  t)
inlinefinaloverridevirtual

This provides an alternative signature without the second ret.

Reimplemented from Selector< T >.

Definition at line 125 of file VersionedSelector.h.

125  {
126  this->retInternal_.set(false);
127  this->operator()(t, this->retInternal_);
128  this->setIgnored(this->retInternal_);
129  return (bool)this->retInternal_;
130  }
virtual bool operator()(const T &ref, pat::strbitset &ret) overridefinal
This provides the interface for base classes to select objects.
tuple t
Definition: tree.py:139
void setIgnored(pat::strbitset &ret)
set ignored bits
Definition: Selector.h:224
pat::strbitset retInternal_
internal ret if users don&#39;t care about return bits
Definition: Selector.h:287
strbitset & set(bool val=true)
set method of all bits
Definition: strbitset.h:144
template<class T>
virtual bool VersionedSelector< T >::operator() ( T const &  t,
edm::EventBase const &  e 
)
inlinefinaloverridevirtual

This provides an alternative signature that includes extra information.

Reimplemented from Selector< T >.

Definition at line 132 of file VersionedSelector.h.

132  {
133  this->retInternal_.set(false);
134  this->operator()(t, e, this->retInternal_);
135  this->setIgnored(this->retInternal_);
136  return (bool)this->retInternal_;
137  }
virtual bool operator()(const T &ref, pat::strbitset &ret) overridefinal
This provides the interface for base classes to select objects.
tuple t
Definition: tree.py:139
void setIgnored(pat::strbitset &ret)
set ignored bits
Definition: Selector.h:224
pat::strbitset retInternal_
internal ret if users don&#39;t care about return bits
Definition: Selector.h:287
strbitset & set(bool val=true)
set method of all bits
Definition: strbitset.h:144
template<class T>
bool VersionedSelector< T >::operator== ( const VersionedSelector< T > &  other) const
inline

Definition at line 140 of file VersionedSelector.h.

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

Definition at line 255 of file VersionedSelector.h.

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

255  {
256  for( size_t i = 0, cutssize = cuts_.size(); i < cutssize; ++i ) {
257  if( needs_event_content_[i] ) {
258  CutApplicatorWithEventContentBase* needsEvent =
259  dynamic_cast<CutApplicatorWithEventContentBase*>(cuts_[i].get());
260  if( nullptr != needsEvent ) {
261  needsEvent->setConsumes(cc);
262  } else {
263  throw cms::Exception("InvalidCutConfiguration")
264  << "Cut: " << ((CutApplicatorBase*)cuts_[i].get())->name()
265  << " configured to consume event products but does not "
266  << " inherit from CutApplicatorWithEventContenBase "
267  << " please correct either your python or C++!";
268  }
269  }
270  }
271 }
int i
Definition: DBlmapReader.cc:9
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

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
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
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
template<class T>
std::vector<double> VersionedSelector< T >::values_
protected