CMS 3D CMS Logo

GenericMVAComputerCache.cc
Go to the documentation of this file.
1 #include <string>
2 #include <vector>
3 #include <memory>
4 
9 
10 using namespace PhysicsTools::Calibration;
11 
13 
15  : label(orig.label) {}
16 
18 
20  : computers(labels.size()),
21  cacheId(MVAComputerContainer::CacheId()),
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 }
32 
34 
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 }
43 
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 }
52 
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 }
SummaryClient_cfi.labels
labels
Definition: SummaryClient_cfi.py:61
PhysicsTools::Calibration::MVAComputer::getCacheId
CacheId getCacheId() const
Definition: MVAComputer.h:234
funct::false
false
Definition: Factorize.h:34
GenericMVAComputerCache::isEmpty
bool isEmpty() const
Definition: GenericMVAComputerCache.cc:44
GenericMVAComputerCache::IndividualComputer::~IndividualComputer
~IndividualComputer()
Definition: GenericMVAComputerCache.cc:17
GenericMVAComputer
Definition: GenericMVAComputer.h:13
PhysicsTools::Calibration
Definition: Histogram.h:14
PhysicsTools::Calibration::MVAComputer::changed
bool changed(CacheId old) const
Definition: MVAComputer.h:235
GenericMVAComputerCache::errorUpdatingLabel
std::string errorUpdatingLabel
Definition: GenericMVAComputerCache.h:38
GenericMVAComputerCache::update
bool update(const PhysicsTools::Calibration::MVAComputerContainer *calib)
Definition: GenericMVAComputerCache.cc:53
GenericMVAComputerCache::empty
bool empty
Definition: GenericMVAComputerCache.h:37
GenericMVAComputerCache::getComputer
const GenericMVAComputer * getComputer(int index) const
Definition: GenericMVAComputerCache.cc:35
MVAComputer.h
calib
Definition: CalibElectron.h:12
PhysicsTools::Calibration::MVAComputer::CacheId
unsigned int CacheId
Definition: MVAComputer.h:233
funct::true
true
Definition: Factorize.h:173
PhysicsTools::Calibration::MVAComputer
Definition: MVAComputer.h:221
GenericMVAComputerCache::IndividualComputer::IndividualComputer
IndividualComputer()
Definition: GenericMVAComputerCache.cc:12
GenericMVAComputerCache::~GenericMVAComputerCache
~GenericMVAComputerCache()
Definition: GenericMVAComputerCache.cc:33
GenericMVAComputerCache::GenericMVAComputerCache
GenericMVAComputerCache(const std::vector< std::string > &labels)
Definition: GenericMVAComputerCache.cc:19
GenericMVAComputerCache::IndividualComputer
Definition: GenericMVAComputerCache.h:24
GenericMVAComputerCache::computers
std::vector< IndividualComputer > computers
Definition: GenericMVAComputerCache.h:34
Exception
Definition: hltDiff.cc:246
HLT_2018_cff.computer
computer
Definition: HLT_2018_cff.py:50520
PhysicsTools::Calibration::MVAComputerContainer
Definition: MVAComputer.h:250
GenericMVAComputerCache::initialized
bool initialized
Definition: GenericMVAComputerCache.h:36
Exception.h
AlignmentPI::index
index
Definition: AlignmentPayloadInspectorHelper.h:46
GenericMVAComputer.h
GenericMVAComputerCache.h
label
const char * label
Definition: PFTauDecayModeTools.cc:11
GenericMVAComputerCache::cacheId
PhysicsTools::Calibration::MVAComputerContainer::CacheId cacheId
Definition: GenericMVAComputerCache.h:35
findQualityFiles.size
size
Write out results.
Definition: findQualityFiles.py:443