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)
 
GenericMVAComputer const * getComputer (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 ( const std::vector< std::string > &  labels)

Definition at line 19 of file GenericMVAComputerCache.cc.

References HLT_2018_cff::computer, and computers.

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 }
PhysicsTools::Calibration::MVAComputerContainer::CacheId cacheId
std::vector< IndividualComputer > computers
GenericMVAComputerCache::~GenericMVAComputerCache ( )

Definition at line 33 of file GenericMVAComputerCache.cc.

33 {}

Member Function Documentation

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

Definition at line 35 of file GenericMVAComputerCache.cc.

References computers, errorUpdatingLabel, and Exception.

Referenced by GenericMVAJetTagComputer::discriminator().

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 }
std::vector< IndividualComputer > computers
bool GenericMVAComputerCache::isEmpty ( void  ) const

Definition at line 44 of file GenericMVAComputerCache.cc.

References empty, errorUpdatingLabel, and Exception.

Referenced by plotting.Plot::clone().

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 }
bool GenericMVAComputerCache::update ( const PhysicsTools::Calibration::MVAComputerContainer calib)

Definition at line 53 of file GenericMVAComputerCache.cc.

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

Referenced by progressbar.ProgressBar::__next__(), MatrixUtil.Matrix::__setitem__(), MatrixUtil.Steps::__setitem__(), Vispa.Gui.VispaWidget.VispaWidget::autosize(), Vispa.Views.LineDecayView.LineDecayContainer::createObject(), Vispa.Views.LineDecayView.LineDecayContainer::deselectAllObjects(), Vispa.Gui.VispaWidgetOwner.VispaWidgetOwner::deselectAllWidgets(), Vispa.Gui.VispaWidget.VispaWidget::enableAutosizing(), progressbar.ProgressBar::finish(), GenericMVAJetTagComputer::initialize(), Vispa.Gui.MenuWidget.MenuWidget::leaveEvent(), Vispa.Gui.VispaWidgetOwner.VispaWidgetOwner::mouseMoveEvent(), Vispa.Gui.MenuWidget.MenuWidget::mouseMoveEvent(), Vispa.Views.LineDecayView.LineDecayContainer::mouseMoveEvent(), Vispa.Gui.VispaWidgetOwner.VispaWidgetOwner::mouseReleaseEvent(), Vispa.Views.LineDecayView.LineDecayContainer::objectMoved(), MatrixUtil.Steps::overwrite(), Vispa.Views.LineDecayView.LineDecayContainer::removeObject(), Vispa.Gui.ConnectableWidget.ConnectableWidget::removePorts(), Vispa.Gui.FindDialog.FindDialog::reset(), Vispa.Gui.PortConnection.PointToPointConnection::select(), Vispa.Gui.VispaWidget.VispaWidget::select(), Vispa.Views.LineDecayView.LineDecayContainer::select(), Vispa.Gui.VispaWidget.VispaWidget::setText(), Vispa.Gui.VispaWidget.VispaWidget::setTitle(), Vispa.Gui.ZoomableWidget.ZoomableWidget::setZoom(), Vispa.Views.LineDecayView.LineDecayContainer::setZoom(), and Vispa.Gui.PortConnection.PointToPointConnection::updateConnection().

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::unique_ptr<GenericMVAComputer>(new 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 }
PhysicsTools::Calibration::MVAComputerContainer::CacheId cacheId
virtual const MVAComputer & find(const std::string &label) const
Definition: MVAComputer.cc:162
bool changed(CacheId old) const
Definition: MVAComputer.h:235
virtual bool contains(const std::string &label) const
Definition: MVAComputer.cc:175
std::vector< IndividualComputer > computers

Member Data Documentation

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

Definition at line 35 of file GenericMVAComputerCache.h.

Referenced by update().

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

Definition at line 34 of file GenericMVAComputerCache.h.

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

bool GenericMVAComputerCache::empty
private
std::string GenericMVAComputerCache::errorUpdatingLabel
private

Definition at line 38 of file GenericMVAComputerCache.h.

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

bool GenericMVAComputerCache::initialized
private

Definition at line 36 of file GenericMVAComputerCache.h.

Referenced by update().