Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

AIDA_TupleIterator.cpp

Go to the documentation of this file.
00001  /**********************************************************************
00002   *                                                                    *
00003   * Copyright (c) 2002 Lorenzo Moneta, CERN/IT                       *
00004   *                   <Lorenzo.Moneta.cern.ch>                       *
00005   *                                                                    *
00006   * This library is free software; you can redistribute it and/or      *
00007   * modify it under the terms of the GNU Lesser General Public         *
00008   * License as published by the Free Software Foundation; either       *
00009   * version 2.1 of the License, or (at your option) any later version. *
00010   *                                                                    *
00011   * This library is distributed in the hope that it will be useful,    *
00012   * but WITHOUT ANY WARRANTY; without even the implied warranty of     *
00013   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU   *
00014   * Lesser General Public License for more details.                    *
00015   *                                                                    *
00016   * You should have received a copy of the GNU Lesser General Public   *
00017   * License along with this library (see file COPYING); if not, write  *
00018   * to the Free Software Foundation, Inc., 59 Temple Place, Suite      *
00019   * 330, Boston, MA 02111-1307 USA, or contact the author.             *
00020   *                                                                    *
00021   **********************************************************************/
00022 
00023 // Implementation file for class AIDA_TupleIterator
00024 // 
00025 // Authors  : Lorenzo Moneta , Jakub Moscicki
00026 // Created  : Fri Oct  4 16:30:41 2002
00027 // 
00028 // Last update: Fri Oct  4 16:30:41 2002
00029 // 
00030 
00031 #include "AIDA_TupleIterator.h"
00032 #include "AIDA_Function_FML/AIDA_RangeSet.h"
00033 
00034 # include "AIDA/ITuple.h"
00035 # include "AIDA/IEvaluator.h"
00036 
00037 # include "FML/debug.h"
00038 
00039 
00040 namespace Anaphe  { 
00041   namespace AIDA_Fitter_FML { 
00042 
00043 
00044     AIDA_TupleIterator::AIDA_TupleIterator(const AIDA::ITuple& t, std::vector<std::string> & colNames) : 
00045       m_cols(colNames)
00046     { 
00047       m_tuple = const_cast<AIDA::ITuple * > (&t); 
00048       m_dim = colNames.size(); 
00049     }
00050 
00051     AIDA_TupleIterator::AIDA_TupleIterator(const AIDA::ITuple& t, std::vector<AIDA::IEvaluator * > &  evaluators)  
00052     { 
00053       m_tuple = const_cast<AIDA::ITuple * > (&t); 
00054       m_dim = evaluators.size();       
00055       m_evals = evaluators; 
00056     }
00057 
00058     AIDA_TupleIterator::~AIDA_TupleIterator() 
00059     {
00060     }
00061 
00062     AIDA_TupleIterator::AIDA_TupleIterator(const AIDA_TupleIterator &) 
00063     {
00064     }
00065 
00066     AIDA_TupleIterator & AIDA_TupleIterator::operator = (const AIDA_TupleIterator &rhs) 
00067     {
00068       if (this == &rhs) return *this;  // time saving self-test
00069       
00070       return *this;
00071     }
00072 
00073     // fill the data in the vector
00074 
00075     void AIDA_TupleIterator::fillData(const std::vector<Anaphe::AIDA_Function_FML::AIDA_RangeSet * > & ranges) 
00076     { 
00077       int n = ranges.size();
00078       if (n != m_dim) {
00079         INFO_MSG(" AIDA_TupleIterator::fillData  invalid dimension for rangeset - cannot feed data in FNL"); 
00080         return; 
00081       }
00082       if (!ranges[0]) { 
00083         INFO_MSG(" AIDA_TupleIterator::fillData  invalid rangeset - cannot feed data in FNL"); 
00084         return; 
00085       }
00086         
00087       std::auto_ptr<FML::DataVector> vptr (new FML::DataVector());
00088 
00089       std::vector<double> x(m_dim);
00090 
00091       int nCols = m_cols.size();
00092       int nEvals = m_evals.size(); 
00093 
00094       int nPoints = 0; 
00095       m_tuple->start(); 
00096       while (m_tuple->next() ) { 
00097         bool validPoint = false; 
00098 
00099         // case of columns 
00100         if (nCols == m_dim ) { 
00101           validPoint = true; 
00102           for(int i = 0; i<m_dim; ++i)
00103             { 
00104               int icol = m_tuple->findColumn(m_cols[i]); 
00105               std::string type = m_tuple->columnType(icol); 
00106               // use only float or double 
00107               if (type == "float" )   x[i] = m_tuple->getFloat(icol);  
00108               if (type == "double" )  x[i] = m_tuple->getDouble(icol);  
00109 
00110               validPoint = validPoint && ranges[i]->isInRange(x[i]);
00111             }
00112         }
00113         // case of evaluators 
00114         if (nEvals == m_dim) { 
00115           validPoint = true; 
00116           for(int i = 0; i<m_dim; ++i)
00117             { 
00118               x[i] = m_evals[i]->evaluateDouble(); 
00119 
00120               validPoint = validPoint && ranges[i]->isInRange(x[i]);
00121             }       
00122         }
00123         
00124         if (validPoint) {       
00125           vptr->push_back(x, 1, 0, 0);
00126           nPoints++; 
00127         }
00128 
00129       }
00130       // set the range (size is number of pointss !) - needed by FML
00131       vptr->setRange(FML::DataRange(nPoints) );
00132 
00133       setVector(vptr);
00134 
00135     }
00136 
00137   }     // end of namespace Anaphe::AIDA_Fitter_FML
00138 } 

Generated on Tue May 20 14:49:01 2003 for AIDA_Fitter_FML by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002