CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_7/src/PhysicsTools/MVATrainer/interface/SourceVariableSet.h

Go to the documentation of this file.
00001 #ifndef PhysicsTools_MVATrainer_SourceVariableSet_h
00002 #define PhysicsTools_MVATrainer_SourceVariableSet_h
00003 
00004 #include <cstddef>
00005 #include <vector>
00006 #include <algorithm>
00007 
00008 #include "PhysicsTools/MVAComputer/interface/AtomicId.h"
00009 
00010 namespace PhysicsTools {
00011 
00012 class SourceVariable;
00013 
00014 class SourceVariableSet {
00015     public:
00016         typedef std::size_t size_type;
00017 
00018         SourceVariableSet() {}
00019         ~SourceVariableSet() {}
00020 
00021         enum Magic {
00022                 kRegular = 0,
00023                 kTarget,
00024                 kWeight
00025         };
00026 
00027         SourceVariable *find(AtomicId name) const; SourceVariable
00028         *find(Magic magic) const;
00029 
00030         bool append(SourceVariable *var, Magic magic = kRegular,
00031                     int offset = -1);
00032         std::vector<SourceVariable*> get(bool withMagic = false) const;
00033         size_type size(bool withMagic = false) const
00034         {
00035                 if (withMagic)
00036                         return vars.size();
00037                 else
00038                         return std::count_if(vars.begin(), vars.end(),
00039                                              std::mem_fun_ref(&PosVar::noMagic));
00040         }
00041 
00042     private:
00043         struct PosVar {
00044                 unsigned int    pos;
00045                 SourceVariable  *var;
00046                 Magic           magic;
00047 
00048                 bool noMagic() const { return magic == kRegular; }
00049 
00050                 static bool VarNameLess(const PosVar &var, AtomicId name)
00051                 { return var.var->getName() < name; }
00052         };
00053 
00054         std::vector<PosVar>     vars;
00055 };
00056 
00057 } // namespace PhysicsTools
00058 
00059 #endif // PhysicsTools_MVATrainer_SourceVariable_h