CMS 3D CMS Logo

List of all members | Classes | Public Member Functions | Private Attributes
GenericMVAComputerCache Class Reference

#include <GenericMVAComputerCache.h>

Classes

struct  IndividualComputer
 

Public Member Functions

 GenericMVAComputerCache (const std::vector< std::string > &labels)
 
const GenericMVAComputergetComputer (int index) const
 
bool isEmpty () const
 
bool update (const PhysicsTools::Calibration::MVAComputerContainer *calib)
 
 ~GenericMVAComputerCache ()
 

Private Attributes

PhysicsTools::Calibration::MVAComputerContainer::CacheId cacheId
 
std::vector< IndividualComputercomputers
 
bool empty
 
std::string errorUpdatingLabel
 
bool initialized
 

Detailed Description

Definition at line 12 of file GenericMVAComputerCache.h.

Constructor & Destructor Documentation

◆ GenericMVAComputerCache()

GenericMVAComputerCache::GenericMVAComputerCache ( const std::vector< std::string > &  labels)

Definition at line 19 of file GenericMVAComputerCache.cc.

20  : computers(labels.size()),
22  initialized(false),
23  empty(true),
25  std::vector<IndividualComputer>::iterator computer = computers.begin();
26  for (std::vector<std::string>::const_iterator iter = labels.begin(); iter != labels.end(); iter++) {
27  computer->label = *iter;
28  computer->cacheId = MVAComputer::CacheId();
29  computer++;
30  }
31 }

References HLT_FULL_cff::computer, computers, and SummaryClient_cfi::labels.

◆ ~GenericMVAComputerCache()

GenericMVAComputerCache::~GenericMVAComputerCache ( )

Definition at line 33 of file GenericMVAComputerCache.cc.

33 {}

Member Function Documentation

◆ getComputer()

const GenericMVAComputer * GenericMVAComputerCache::getComputer ( int  index) const

Definition at line 35 of file GenericMVAComputerCache.cc.

35  {
36  if (!errorUpdatingLabel.empty()) {
37  throw cms::Exception("MVAComputerCalibration")
38  << "GenericMVAComputerCache::getComputer Error occurred during update.\n"
39  << "Calibration record " << errorUpdatingLabel << " not found in MVAComputerContainer." << std::endl;
40  }
41  return index >= 0 ? computers[index].computer.get() : nullptr;
42 }

References computers, errorUpdatingLabel, and Exception.

Referenced by GenericMVAJetTagComputer::discriminator().

◆ isEmpty()

bool GenericMVAComputerCache::isEmpty ( void  ) const

Definition at line 44 of file GenericMVAComputerCache.cc.

44  {
45  if (!errorUpdatingLabel.empty()) {
46  throw cms::Exception("MVAComputerCalibration")
47  << "GenericMVAComputerCache::isEmpty Error occurred during update.\n"
48  << "Calibration record " << errorUpdatingLabel << " not found in MVAComputerContainer." << std::endl;
49  }
50  return empty;
51 }

References empty, errorUpdatingLabel, and Exception.

Referenced by plotting.Plot::clone().

◆ update()

bool GenericMVAComputerCache::update ( const PhysicsTools::Calibration::MVAComputerContainer calib)

Definition at line 53 of file GenericMVAComputerCache.cc.

53  {
54  // check container for changes
55  if (initialized && !calib->changed(cacheId))
56  return false;
57 
58  empty = true;
59 
60  bool changed = false;
61  for (std::vector<IndividualComputer>::iterator iter = computers.begin(); iter != computers.end(); iter++) {
62  // empty labels means we don't want a computer
63  if (iter->label.empty())
64  continue;
65 
66  // Delay throwing if the label cannot be found until getComputer is called
67  // Sometimes this cache is updated and never used.
68  if (!calib->contains(iter->label)) {
69  errorUpdatingLabel = iter->label;
70  continue;
71  }
72 
73  const MVAComputer *computerCalib = &calib->find(iter->label);
74  if (!computerCalib) {
75  iter->computer.reset();
76  continue;
77  }
78 
79  // check container content for changes
80  if (iter->computer.get() && !computerCalib->changed(iter->cacheId)) {
81  empty = false;
82  continue;
83  }
84 
85  // drop old computer
86  iter->computer.reset();
87 
88  if (!computerCalib)
89  continue;
90 
91  // instantiate new MVAComputer with uptodate calibration
92  iter->computer = std::make_unique<GenericMVAComputer>(computerCalib);
93 
94  iter->cacheId = computerCalib->getCacheId();
95 
96  changed = true;
97  empty = false;
98  }
99 
100  cacheId = calib->getCacheId();
101  initialized = true;
102 
103  return changed;
104 }

References cacheId, PhysicsTools::Calibration::MVAComputer::changed(), computers, empty, errorUpdatingLabel, PhysicsTools::Calibration::MVAComputer::getCacheId(), and initialized.

Referenced by progressbar.ProgressBar::__next__(), MatrixUtil.Matrix::__setitem__(), MatrixUtil.Steps::__setitem__(), progressbar.ProgressBar::finish(), GenericMVAJetTagComputer::initialize(), and MatrixUtil.Steps::overwrite().

Member Data Documentation

◆ cacheId

PhysicsTools::Calibration::MVAComputerContainer::CacheId GenericMVAComputerCache::cacheId
private

Definition at line 35 of file GenericMVAComputerCache.h.

Referenced by update().

◆ computers

std::vector<IndividualComputer> GenericMVAComputerCache::computers
private

Definition at line 34 of file GenericMVAComputerCache.h.

Referenced by GenericMVAComputerCache(), getComputer(), and update().

◆ empty

bool GenericMVAComputerCache::empty
private

◆ errorUpdatingLabel

std::string GenericMVAComputerCache::errorUpdatingLabel
private

Definition at line 38 of file GenericMVAComputerCache.h.

Referenced by getComputer(), isEmpty(), and update().

◆ initialized

bool GenericMVAComputerCache::initialized
private

Definition at line 36 of file GenericMVAComputerCache.h.

Referenced by update().

SummaryClient_cfi.labels
labels
Definition: SummaryClient_cfi.py:61
PhysicsTools::Calibration::MVAComputer::getCacheId
CacheId getCacheId() const
Definition: MVAComputer.h:234
PhysicsTools::Calibration::MVAComputerContainer::CacheId
unsigned int CacheId
Definition: MVAComputer.h:262
PhysicsTools::Calibration::MVAComputer::changed
bool changed(CacheId old) const
Definition: MVAComputer.h:235
GenericMVAComputerCache::errorUpdatingLabel
std::string errorUpdatingLabel
Definition: GenericMVAComputerCache.h:38
GenericMVAComputerCache::empty
bool empty
Definition: GenericMVAComputerCache.h:37
calib
Definition: CalibElectron.h:12
PhysicsTools::Calibration::MVAComputer::CacheId
unsigned int CacheId
Definition: MVAComputer.h:233
PhysicsTools::Calibration::MVAComputer
Definition: MVAComputer.h:221
GenericMVAComputerCache::computers
std::vector< IndividualComputer > computers
Definition: GenericMVAComputerCache.h:34
Exception
Definition: hltDiff.cc:245
GenericMVAComputerCache::initialized
bool initialized
Definition: GenericMVAComputerCache.h:36
AlignmentPI::index
index
Definition: AlignmentPayloadInspectorHelper.h:46
HLT_FULL_cff.computer
computer
Definition: HLT_FULL_cff.py:52057
GenericMVAComputerCache::cacheId
PhysicsTools::Calibration::MVAComputerContainer::CacheId cacheId
Definition: GenericMVAComputerCache.h:35