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 {
14 }
15 
17  const IndividualComputer &orig) :
18  label(orig.label)
19 {
20 }
21 
23 {
24 }
25 
27  const std::vector<std::string> &labels) :
28  computers(labels.size()),
29  cacheId(MVAComputerContainer::CacheId()),
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 }
42 
44 {
45 }
46 
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 }
57 
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 }
67 
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::auto_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 }
size
Write out results.
PhysicsTools::Calibration::MVAComputerContainer::CacheId cacheId
virtual const MVAComputer & find(const std::string &label) const
Definition: MVAComputer.cc:222
PhysicsTools::Calibration::MVAComputer::CacheId cacheId
bool update(const PhysicsTools::Calibration::MVAComputerContainer *calib)
GenericMVAComputerCache(const std::vector< std::string > &labels)
bool changed(CacheId old) const
Definition: MVAComputer.h:232
GenericMVAComputer const * getComputer(int index) const
virtual bool contains(const std::string &label) const
Definition: MVAComputer.cc:236
std::vector< IndividualComputer > computers