CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch12/src/PhysicsTools/MVAComputer/interface/MVAComputerCache.h

Go to the documentation of this file.
00001 #ifndef PhysicsTools_MVAComputer_MVAComputerCache_h
00002 #define PhysicsTools_MVAComputer_MVAComputerCache_h
00003 // -*- C++ -*-
00004 //
00005 // Package:     MVAComputerCache
00006 // Class  :     MVAComputerCache
00007 //
00008 
00009 //
00010 // Author:      Christophe Saout <christophe.saout@cern.ch>
00011 // Created:     Sat Feb 23 15:38 CEST 2007
00012 // $Id: MVAComputerCache.h,v 1.1 2008/02/23 16:35:17 saout Exp $
00013 //
00014 
00015 #include <memory>
00016 
00017 #include "FWCore/Framework/interface/EventSetup.h"
00018 #include "FWCore/Framework/interface/ESHandle.h"
00019 #include "PhysicsTools/MVAComputer/interface/Calibration.h"
00020 #include "PhysicsTools/MVAComputer/interface/MVAComputer.h"
00021 
00022 namespace PhysicsTools {
00023 
00029 class MVAComputerCache {
00030     public:
00031         MVAComputerCache();
00032         ~MVAComputerCache();
00033 
00034         bool update(const Calibration::MVAComputer *computer);
00035         bool update(const Calibration::MVAComputerContainer *container,
00036                     const char *calib);
00037 
00038         template<class T>
00039         bool update(const edm::EventSetup &es)
00040         {
00041                 edm::ESHandle<Calibration::MVAComputer> handle;
00042                 es.get<T>().get(handle);
00043                 return update(handle.product());
00044         }
00045 
00046         template<class T>
00047         bool update(const edm::EventSetup &es, const char *calib)
00048         {
00049                 edm::ESHandle<Calibration::MVAComputerContainer> handle;
00050                 es.get<T>().get(handle);
00051                 return update(handle.product(), calib);
00052         }
00053 
00054         template<class T>
00055         bool update(const char *label, const edm::EventSetup &es)
00056         {
00057                 edm::ESHandle<Calibration::MVAComputer> handle;
00058                 es.get<T>().get(label, handle);
00059                 return update(handle.product());
00060         }
00061 
00062         template<class T>
00063         bool update(const char *label, const edm::EventSetup &es,
00064                     const char *calib)
00065         {
00066                 edm::ESHandle<Calibration::MVAComputerContainer> handle;
00067                 es.get<T>().get(label, handle);
00068                 return update(handle.product(), calib);
00069         }
00070 
00071         operator bool() const { return computer.get(); }
00072 
00073         MVAComputer &operator * () { return *computer; }
00074         const MVAComputer &operator * () const { return *computer; }
00075 
00076         MVAComputer *operator -> () { return computer.get(); }
00077         const MVAComputer *operator -> () const { return computer.get(); }
00078 
00079         MVAComputer *get() { return computer.get(); }
00080         const MVAComputer *get() const { return computer.get(); }
00081 
00082         std::auto_ptr<MVAComputer> release();
00083 
00084         void reset() { computer.reset(); }
00085 
00086     private:
00087         Calibration::MVAComputerContainer::CacheId      containerCacheId;
00088         Calibration::MVAComputer::CacheId               computerCacheId;
00089         std::auto_ptr<MVAComputer>                      computer;
00090 };
00091 
00092 } // namespace PhysicsTools
00093 
00094 #endif // PhysicsTools_MVAComputer_MVAComputerCache_h