CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_9_patch3/src/PhysicsTools/MVATrainer/interface/MVATrainerLooper.h

Go to the documentation of this file.
00001 #ifndef PhysicsTools_MVATrainer_MVATrainerLooper_h
00002 #define PhysicsTools_MVATrainer_MVATrainerLooper_h
00003 
00004 #include <string>
00005 #include <vector>
00006 #include <memory>
00007 
00008 #include <boost/shared_ptr.hpp>
00009 
00010 #include "FWCore/Framework/interface/ESProducerLooper.h"
00011 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00012 
00013 #include "CondFormats/PhysicsToolsObjects/interface/MVAComputer.h"
00014 #include "PhysicsTools/MVATrainer/interface/MVATrainer.h"
00015 
00016 namespace PhysicsTools {
00017 
00018 class MVATrainerLooper : public edm::ESProducerLooper {
00019     public:
00020         MVATrainerLooper(const edm::ParameterSet &params);
00021         virtual ~MVATrainerLooper();
00022 
00023         virtual void startingNewLoop(unsigned int iteration);
00024         virtual Status duringLoop(const edm::Event &ev,
00025                                   const edm::EventSetup &es);
00026         virtual Status endOfLoop(const edm::EventSetup &es,
00027                                  unsigned int iteration);
00028 
00029         typedef boost::shared_ptr<Calibration::MVAComputer> TrainObject;
00030         typedef boost::shared_ptr<Calibration::MVAComputerContainer>
00031                                                         TrainContainer;
00032 
00033         template<class T>
00034         static inline bool isUntrained(const T *ptr);
00035 
00036     protected:
00037         class Trainer {
00038             public:
00039                 Trainer(const edm::ParameterSet &params);
00040                 virtual ~Trainer() {}
00041 
00042                 inline const MVATrainer *getTrainer() const
00043                 { return trainer.get(); }
00044                 inline const TrainObject getCalibration() const
00045                 { return trainCalib; }
00046 
00047             private:
00048                 friend class MVATrainerLooper;
00049 
00050                 std::auto_ptr<MVATrainer>       trainer;
00051                 TrainObject                     trainCalib;
00052         };
00053 
00054         class TrainerContainer {
00055             public:
00056                 ~TrainerContainer();
00057                 void clear();
00058 
00059                 typedef std::vector<Trainer*>::const_iterator const_iterator;
00060 
00061                 inline const_iterator begin() const { return content.begin(); }
00062                 inline const_iterator end() const { return content.end(); }
00063                 inline bool empty() const { return content.empty(); }
00064 
00065                 inline void add(Trainer *trainer)
00066                 { content.push_back(trainer); }
00067 
00068             private:
00069                 std::vector<Trainer*> content;
00070         };
00071 
00072         class UntrainedMVAComputer : public Calibration::MVAComputer {};
00073         class UntrainedMVAComputerContainer :
00074                                 public Calibration::MVAComputerContainer {};
00075 
00076         void addTrainer(Trainer *trainer) { trainers.add(trainer); }
00077 
00078         inline const TrainerContainer &getTrainers() const { return trainers; }
00079 
00080     private:
00081         TrainerContainer        trainers;
00082         bool dataProcessedInLoop;
00083 };
00084 
00085 template<> inline bool
00086 MVATrainerLooper::isUntrained(const Calibration::MVAComputer *ptr)
00087 { return dynamic_cast<const UntrainedMVAComputer*>(ptr) != 0; }
00088 
00089 template<> inline bool
00090 MVATrainerLooper::isUntrained(const Calibration::MVAComputerContainer *ptr)
00091 { return dynamic_cast<const UntrainedMVAComputerContainer*>(ptr) != 0; }
00092 
00093 } // namespace PhysicsTools
00094 
00095 #endif // PhysicsTools_MVATrainer_MVATrainerLooper_h