CMS 3D CMS Logo

GenericMVAComputerCache.cc
Go to the documentation of this file.
1 #include <memory>
2 #include <string>
3 #include <vector>
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::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 }
size
Write out results.
PhysicsTools::Calibration::MVAComputerContainer::CacheId cacheId
bool changed(CacheId old) const
Definition: MVAComputer.h:236
GenericMVAComputer const * getComputer(int index) const
char const * label
bool update(const PhysicsTools::Calibration::MVAComputerContainer *calib)
GenericMVAComputerCache(const std::vector< std::string > &labels)
std::vector< IndividualComputer > computers