Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:32:41

0001 #include <memory>
0002 
0003 #include "PhysicsTools/MVAComputer/interface/Calibration.h"
0004 #include "PhysicsTools/MVAComputer/interface/MVAComputer.h"
0005 #include "PhysicsTools/MVAComputer/interface/MVAComputerCache.h"
0006 
0007 namespace PhysicsTools {
0008 
0009   MVAComputerCache::MVAComputerCache()
0010       : containerCacheId(Calibration::MVAComputerContainer::CacheId()),
0011         computerCacheId(Calibration::MVAComputer::CacheId()) {}
0012 
0013   MVAComputerCache::~MVAComputerCache() {}
0014 
0015   bool MVAComputerCache::update(const Calibration::MVAComputer *computer) {
0016     if (!computer && !*this)
0017       return false;
0018     if (computer && !computer->changed(computerCacheId))
0019       return false;
0020 
0021     if (computer) {
0022       this->computer = std::make_unique<MVAComputer>(computer);
0023       computerCacheId = computer->getCacheId();
0024     } else {
0025       this->computer.reset();
0026       computerCacheId = Calibration::MVAComputer::CacheId();
0027     }
0028 
0029     containerCacheId = Calibration::MVAComputerContainer::CacheId();
0030     return true;
0031   }
0032 
0033   bool MVAComputerCache::update(const Calibration::MVAComputerContainer *container, const char *calib) {
0034     if (!container && !*this)
0035       return false;
0036     if (container && !container->changed(containerCacheId))
0037       return false;
0038 
0039     if (container) {
0040       const Calibration::MVAComputer *computer = &container->find(calib);
0041       bool result = update(computer);
0042       containerCacheId = container->getCacheId();
0043       return result;
0044     }
0045 
0046     this->computer.reset();
0047 
0048     computerCacheId = Calibration::MVAComputer::CacheId();
0049     containerCacheId = Calibration::MVAComputerContainer::CacheId();
0050     return true;
0051   }
0052 
0053   std::unique_ptr<MVAComputer> MVAComputerCache::release() {
0054     computerCacheId = Calibration::MVAComputer::CacheId();
0055     containerCacheId = Calibration::MVAComputerContainer::CacheId();
0056     return std::move(computer);
0057   }
0058 
0059 }  // namespace PhysicsTools