CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_9_patch3/src/PhysicsTools/MVATrainer/src/SourceVariableSet.cc

Go to the documentation of this file.
00001 #include <iostream>
00002 #include <algorithm>
00003 #include <vector>
00004 
00005 #include "PhysicsTools/MVAComputer/interface/AtomicId.h"
00006 
00007 #include "PhysicsTools/MVATrainer/interface/SourceVariable.h"
00008 #include "PhysicsTools/MVATrainer/interface/SourceVariableSet.h"
00009 
00010 namespace PhysicsTools {
00011 
00012 bool SourceVariableSet::append(SourceVariable *var, Magic magic, int offset)
00013 {
00014         std::vector<PosVar>::iterator pos =
00015                         std::lower_bound(vars.begin(), vars.end(),
00016                                          var->getName(), PosVar::VarNameLess);
00017 
00018         if (pos != vars.end() && (pos->var == var ||
00019                                   (pos->var->getSource() == var->getSource() &&
00020                                    pos->var->getName() == var->getName())))
00021                 return true;
00022 
00023         PosVar item;
00024         item.pos = offset < 0 ? vars.size() : offset;
00025         item.var = var;
00026         item.magic = magic;
00027 
00028         vars.insert(pos, 1, item);
00029 
00030         return false;
00031 }
00032 
00033 SourceVariable *SourceVariableSet::find(AtomicId name) const
00034 {
00035         std::vector<PosVar>::const_iterator pos =
00036                         std::lower_bound(vars.begin(), vars.end(),
00037                                          name, PosVar::VarNameLess);
00038 
00039         if (pos == vars.end() || pos->var->getName() != name)
00040                 return 0;
00041 
00042         return pos->var;
00043 }
00044 
00045 SourceVariable *SourceVariableSet::find(Magic magic) const
00046 {
00047         for(std::vector<PosVar>::const_iterator pos = vars.begin();
00048             pos != vars.end(); ++pos)
00049                 if (pos->magic == magic)
00050                         return pos->var;
00051 
00052         return 0;
00053 }
00054 
00055 std::vector<SourceVariable*> SourceVariableSet::get(bool withMagic) const
00056 {
00057         std::vector<SourceVariable*> result(vars.size());
00058 
00059         for(std::vector<PosVar>::const_iterator iter = vars.begin();
00060             iter != vars.end(); iter++)
00061                 result[iter->pos] = iter->var;
00062 
00063         if (!withMagic) {
00064                 unsigned int pos = vars.size();
00065                 for(std::vector<PosVar>::const_iterator iter = vars.begin();
00066                     iter != vars.end(); iter++)
00067                         if (iter->magic != kRegular) {
00068                                 result.erase(result.begin() +
00069                                              (iter->pos - (iter->pos >= pos)));
00070                                 pos = iter->pos;
00071                         }
00072         }
00073 
00074         return result;
00075 }
00076 
00077 } // namespace PhysicsTools