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 26 of file GenericMVAComputerCache.cc.

References caloDeepCSVTagInfos_cfi::computer, and computers.

27  :
28  computers(labels.size()),
30  initialized(false),
31  empty(true),
33 {
34  std::vector<IndividualComputer>::iterator computer = computers.begin();
35  for(std::vector<std::string>::const_iterator iter = labels.begin();
36  iter != labels.end(); iter++) {
37  computer->label = *iter;
38  computer->cacheId = MVAComputer::CacheId();
39  computer++;
40  }
41 }
PhysicsTools::Calibration::MVAComputerContainer::CacheId cacheId
std::vector< IndividualComputer > computers
GenericMVAComputerCache::~GenericMVAComputerCache ( )

Definition at line 43 of file GenericMVAComputerCache.cc.

44 {
45 }

Member Function Documentation

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

Definition at line 47 of file GenericMVAComputerCache.cc.

References computers, errorUpdatingLabel, and Exception.

Referenced by GenericMVAJetTagComputer::discriminator().

48 {
49  if(!errorUpdatingLabel.empty()) {
50  throw cms::Exception("MVAComputerCalibration")
51  << "GenericMVAComputerCache::getComputer Error occurred during update.\n"
52  << "Calibration record " << errorUpdatingLabel
53  << " not found in MVAComputerContainer." << std::endl;
54  }
55  return index >= 0 ? computers[index].computer.get() : nullptr;
56 }
std::vector< IndividualComputer > computers
bool GenericMVAComputerCache::isEmpty ( void  ) const

Definition at line 58 of file GenericMVAComputerCache.cc.

References empty, errorUpdatingLabel, and Exception.

Referenced by plotting.Plot::clone().

58  {
59  if(!errorUpdatingLabel.empty()) {
60  throw cms::Exception("MVAComputerCalibration")
61  << "GenericMVAComputerCache::isEmpty Error occurred during update.\n"
62  << "Calibration record " << errorUpdatingLabel
63  << " not found in MVAComputerContainer." << std::endl;
64  }
65  return empty;
66 }
bool GenericMVAComputerCache::update ( const PhysicsTools::Calibration::MVAComputerContainer calib)

Definition at line 68 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().

69 {
70  // check container for changes
71  if (initialized && !calib->changed(cacheId))
72  return false;
73 
74  empty = true;
75 
76  bool changed = false;
77  for(std::vector<IndividualComputer>::iterator iter = computers.begin();
78  iter != computers.end(); iter++) {
79  // empty labels means we don't want a computer
80  if (iter->label.empty())
81  continue;
82 
83  // Delay throwing if the label cannot be found until getComputer is called
84  // Sometimes this cache is updated and never used.
85  if (!calib->contains(iter->label)) {
86  errorUpdatingLabel = iter->label;
87  continue;
88  }
89 
90  const MVAComputer *computerCalib = &calib->find(iter->label);
91  if (!computerCalib) {
92  iter->computer.reset();
93  continue;
94  }
95 
96  // check container content for changes
97  if (iter->computer.get() &&
98  !computerCalib->changed(iter->cacheId)) {
99  empty = false;
100  continue;
101  }
102 
103  // drop old computer
104  iter->computer.reset();
105 
106  if (!computerCalib)
107  continue;
108 
109  // instantiate new MVAComputer with uptodate calibration
110  iter->computer = std::unique_ptr<GenericMVAComputer>(
111  new GenericMVAComputer(computerCalib));
112 
113  iter->cacheId = computerCalib->getCacheId();
114 
115  changed = true;
116  empty = false;
117  }
118 
119  cacheId = calib->getCacheId();
120  initialized = true;
121 
122  return changed;
123 }
PhysicsTools::Calibration::MVAComputerContainer::CacheId cacheId
virtual const MVAComputer & find(const std::string &label) const
Definition: MVAComputer.cc:207
bool changed(CacheId old) const
Definition: MVAComputer.h:232
virtual bool contains(const std::string &label) const
Definition: MVAComputer.cc:221
std::vector< IndividualComputer > computers

Member Data Documentation

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

Definition at line 36 of file GenericMVAComputerCache.h.

Referenced by update().

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

Definition at line 35 of file GenericMVAComputerCache.h.

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

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

Definition at line 39 of file GenericMVAComputerCache.h.

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

bool GenericMVAComputerCache::initialized
private

Definition at line 37 of file GenericMVAComputerCache.h.

Referenced by update().