CMS 3D CMS Logo

ProcOptional.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:     MVAComputer
00004 // Class  :     ProcOptional
00005 // 
00006 
00007 // Implementation:
00008 //     Variable processor to set empty input variables to a default value.
00009 //
00010 // Author:      Christophe Saout
00011 // Created:     Sat Apr 24 15:18 CEST 2007
00012 // $Id: ProcOptional.cc,v 1.3 2007/07/15 22:31:46 saout Exp $
00013 //
00014 
00015 #include "FWCore/Utilities/interface/Exception.h"
00016 
00017 #include "PhysicsTools/MVAComputer/interface/VarProcessor.h"
00018 #include "PhysicsTools/MVAComputer/interface/Calibration.h"
00019 
00020 using namespace PhysicsTools;
00021 
00022 namespace { // anonymous
00023 
00024 class ProcOptional : public VarProcessor {
00025     public:
00026         typedef VarProcessor::Registry::Registry<ProcOptional,
00027                                         Calibration::ProcOptional> Registry;
00028 
00029         ProcOptional(const char *name,
00030                      const Calibration::ProcOptional *calib,
00031                      const MVAComputer *computer);
00032         virtual ~ProcOptional() {}
00033 
00034         virtual void configure(ConfIterator iter, unsigned int n);
00035         virtual void eval(ValueIterator iter, unsigned int n) const;
00036 
00037     private:
00038         std::vector<double>     neutralPos;
00039 };
00040 
00041 static ProcOptional::Registry registry("ProcOptional");
00042 
00043 ProcOptional::ProcOptional(const char *name,
00044                           const Calibration::ProcOptional *calib,
00045                           const MVAComputer *computer) :
00046         VarProcessor(name, calib, computer),
00047         neutralPos(calib->neutralPos)
00048 {
00049 }
00050 
00051 void ProcOptional::configure(ConfIterator iter, unsigned int n)
00052 {
00053         if (n != neutralPos.size())
00054                 return;
00055 
00056         while(iter)
00057                 iter++(Variable::FLAG_OPTIONAL) << Variable::FLAG_NONE;
00058 }
00059 
00060 void ProcOptional::eval(ValueIterator iter, unsigned int n) const
00061 {
00062         for(std::vector<double>::const_iterator pos = neutralPos.begin();
00063             pos != neutralPos.end(); pos++, ++iter) {
00064                 switch(iter.size()) {
00065                     case 0:
00066                         iter(*pos);
00067                         break;
00068                     case 1:
00069                         iter(*iter);
00070                         break;
00071                     default:
00072                         throw cms::Exception("ProcOptionalError")
00073                                 << "Multiple input variables encountered."
00074                                 << std::endl;
00075                 }
00076         }
00077 }
00078 
00079 } // anonymous namespace

Generated on Tue Jun 9 17:41:30 2009 for CMSSW by  doxygen 1.5.4