CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_7/src/RecoBTau/JetTagComputer/src/GenericMVAComputerCache.cc

Go to the documentation of this file.
00001 #include <string>
00002 #include <vector>
00003 #include <memory>
00004 
00005 #include "CondFormats/PhysicsToolsObjects/interface/MVAComputer.h"
00006 #include "RecoBTau/JetTagComputer/interface/GenericMVAComputer.h"
00007 #include "RecoBTau/JetTagComputer/interface/GenericMVAComputerCache.h"
00008 
00009 using namespace PhysicsTools::Calibration;
00010 
00011 inline GenericMVAComputerCache::IndividualComputer::IndividualComputer()
00012 {
00013 }
00014 
00015 inline GenericMVAComputerCache::IndividualComputer::IndividualComputer(
00016                                         const IndividualComputer &orig) :
00017         label(orig.label)
00018 {
00019 }
00020 
00021 inline GenericMVAComputerCache::IndividualComputer::~IndividualComputer()
00022 {
00023 }
00024 
00025 GenericMVAComputerCache::GenericMVAComputerCache(
00026                                 const std::vector<std::string> &labels) :
00027         computers(labels.size()),
00028         cacheId(MVAComputerContainer::CacheId()),
00029         initialized(false),
00030         empty(true)
00031 {
00032         std::vector<IndividualComputer>::iterator computer = computers.begin();
00033         for(std::vector<std::string>::const_iterator iter = labels.begin();
00034             iter != labels.end(); iter++) {
00035                 computer->label = *iter;
00036                 computer->cacheId = MVAComputer::CacheId();
00037                 computer++;
00038         }
00039 }
00040 
00041 GenericMVAComputerCache::~GenericMVAComputerCache()
00042 {
00043 }
00044 
00045 bool GenericMVAComputerCache::update(const MVAComputerContainer *calib)
00046 {
00047         // check container for changes
00048         if (initialized && !calib->changed(cacheId))
00049                 return false;
00050 
00051         empty = true;
00052 
00053         bool changed = false;
00054         for(std::vector<IndividualComputer>::iterator iter = computers.begin();
00055             iter != computers.end(); iter++) {
00056                 // empty labels means we don't want a computer
00057                 if (iter->label.empty())
00058                         continue;
00059 
00060                 const MVAComputer *computerCalib = &calib->find(iter->label);
00061                 if (!computerCalib) {
00062                         iter->computer.reset();
00063                         continue;
00064                 }
00065 
00066                 // check container content for changes
00067                 if (iter->computer.get() &&
00068                     !computerCalib->changed(iter->cacheId)) {
00069                         empty = false;
00070                         continue;
00071                 }
00072 
00073                 // drop old computer
00074                 iter->computer.reset();
00075 
00076                 if (!computerCalib)
00077                         continue;
00078 
00079                 // instantiate new MVAComputer with uptodate calibration
00080                 iter->computer = std::auto_ptr<GenericMVAComputer>(
00081                                         new GenericMVAComputer(computerCalib));
00082 
00083                 iter->cacheId = computerCalib->getCacheId();
00084 
00085                 changed = true;
00086                 empty = false;
00087         }
00088 
00089         cacheId = calib->getCacheId();
00090         initialized = true;
00091 
00092         return changed;
00093 }