CMS 3D CMS Logo

SprCoordinateMapper.cc

Go to the documentation of this file.
00001 //$Id: SprCoordinateMapper.cc,v 1.1 2007/09/21 22:32:09 narsky Exp $
00002 
00003 #include "PhysicsTools/StatPatternRecognition/interface/SprExperiment.hh"
00004 #include "PhysicsTools/StatPatternRecognition/interface/SprCoordinateMapper.hh"
00005 #include "PhysicsTools/StatPatternRecognition/interface/SprPoint.hh"
00006 
00007 #include <cassert>
00008 #include <algorithm>
00009 
00010 using namespace std;
00011 
00012 
00013 SprCoordinateMapper* SprCoordinateMapper::createMapper(
00014                                       const std::vector<std::string>& from,
00015                                       const std::vector<std::string>& to)
00016 {
00017   vector<unsigned> mapper(from.size());
00018   for( int i=0;i<from.size();i++ ) {
00019     vector<string>::const_iterator found = find(to.begin(),to.end(),from[i]);
00020     if( found == to.end() ) {
00021       cerr << "Unable to find variable " << from[i].c_str()
00022            << " among data variables." << endl;
00023       return 0;
00024     }
00025     int d = found - to.begin();
00026     mapper[i] = d;
00027   }
00028   return SprCoordinateMapper::createMapper(mapper);
00029 }
00030 
00031 
00032 const SprPoint* SprCoordinateMapper::output(const SprPoint* input) 
00033 {
00034   // sanity check
00035   if( mapper_.empty() ) return input;
00036   
00037   // make new point and copy index+class
00038   SprPoint* p = new SprPoint;
00039   p->index_ = input->index_;
00040   p->class_ = input->class_;
00041   
00042   // copy vector elements
00043   this->map(input->x_,p->x_);
00044   
00045   // add to the cleanup list
00046   toDelete_.push_back(p);
00047   
00048   // exit
00049   return p;
00050 }
00051 
00052 
00053 void SprCoordinateMapper::map(const std::vector<double>& in,
00054                               std::vector<double>& out) const
00055 {
00056   out.clear();
00057   for( int i=0;i<mapper_.size();i++ ) {
00058     unsigned d = mapper_[i];
00059     assert( d < in.size() );
00060     out.push_back(in[d]);
00061   }
00062 }
00063 
00064 
00065 void SprCoordinateMapper::clear() 
00066 {
00067   for( int i=0;i<toDelete_.size();i++ ) delete toDelete_[i];
00068   toDelete_.clear();
00069 }

Generated on Tue Jun 9 17:42:02 2009 for CMSSW by  doxygen 1.5.4