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

Definition at line 19 of file GenericMVAComputerCache.cc.

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

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::~GenericMVAComputerCache ( )

Definition at line 33 of file GenericMVAComputerCache.cc.

33 {}

Member Function Documentation

◆ getComputer()

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

◆ isEmpty()

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 }

◆ update()

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

Definition at line 53 of file GenericMVAComputerCache.cc.

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().

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 }
PhysicsTools::Calibration::MVAComputerContainer::CacheId cacheId
bool changed(CacheId old) const
Definition: MVAComputer.h:236
std::vector< IndividualComputer > computers

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().