CMS 3D CMS Logo

matrixSaver Class Reference

save (read) HepMatrix to (from) text files More...

#include <Calibration/Tools/interface/matrixSaver.h>

List of all members.

Public Member Functions

std::vector< CLHEP::HepMatrix > getConcreteMatrixVector (std::string inputFileName)
CLHEP::HepGenMatrix * getMatrix (std::string inputFileName)
std::vector
< CLHEP::HepGenMatrix * > * 
getMatrixVector (std::string inputFileName)
 matrixSaver ()
int saveMatrix (std::string outputFileName, const CLHEP::HepGenMatrix *saveMe)
int saveMatrixVector (std::string outputFileName, const std::vector< CLHEP::HepGenMatrix * > &saveMe)
int touch (std::string inputFileName)
 ~matrixSaver ()


Detailed Description

save (read) HepMatrix to (from) text files

Date
2008/02/25 17:40:25
Revision
1.2
Id
matrixSaver.h,v 1.2 2008/02/25 17:40:25 malberti Exp
Author:
Author
malberti

Definition at line 26 of file matrixSaver.h.


Constructor & Destructor Documentation

matrixSaver::matrixSaver (  ) 

Definition at line 16 of file matrixSaver.cc.

00017 {
00018 //   std::cout << "[matrixSaver][ctor] matrixSaver instance" << std::endl ;
00019 }

matrixSaver::~matrixSaver (  ) 

Definition at line 22 of file matrixSaver.cc.

00023 {
00024 //   std::cout << "[matrixSaver][dtor] destroyed" << std::endl ;
00025 }


Member Function Documentation

std::vector< CLHEP::HepMatrix > matrixSaver::getConcreteMatrixVector ( std::string  inputFileName  ) 

Definition at line 218 of file matrixSaver.cc.

References i, in, outputToXml::inputFile, and NULL.

00219 {
00220      // open the output file
00221      std::fstream inputFile (inputFileName.c_str (), std::ios::in) ;
00222      assert (inputFile != NULL) ;
00223 
00224      // get the vector length
00225      int numElem = 0 ;
00226      inputFile >> numElem ;
00227      
00228      // get the matrix dimensions
00229      int numRow = 0 ;
00230      int numCol = 0 ;
00231      inputFile >> numRow ;
00232      inputFile >> numCol ;
00233 
00234      //PG prepara il vector
00235      std::vector<CLHEP::HepMatrix> matrixVector (
00236          numElem,
00237          CLHEP::HepMatrix (numRow,numCol,0)
00238        ) ;
00239      
00240      //PG loop sugli elementi del vettore
00241      for (int i=0 ; i<numElem ; ++i)
00242        {
00243           
00244           //PG scarica su un oggetto concreto
00245           inputFile >> matrixVector[i] ;
00246 
00247        }
00248 
00249      return matrixVector ;
00250 }

CLHEP::HepGenMatrix * matrixSaver::getMatrix ( std::string  inputFileName  ) 

Definition at line 147 of file matrixSaver.cc.

References TestMuL1L2Filter_cff::cerr, lat::endl(), in, outputToXml::inputFile, matrix, and NULL.

Referenced by getSavedMatrix().

00148 {
00149      //PG open the output file
00150      std::fstream inputFile (inputFileName.c_str (), std::ios::in) ;
00151      if (inputFile == NULL) std::cerr << "file: " << inputFileName << std::endl ;
00152      assert (inputFile != NULL) ;
00153 
00154      //PG get the matrix dimensions
00155      int numRow = 0 ;
00156      int numCol = 0 ;
00157      inputFile >> numRow ;
00158      inputFile >> numCol ;
00159 
00160      //PG instantiate the matrix
00161      CLHEP::HepGenMatrix * matrix ;
00162      if (numCol > 1)
00163              matrix = new CLHEP::HepMatrix (numRow, numCol, 0) ;
00164      else
00165              matrix = new CLHEP::HepVector (numRow, 0) ;
00166 
00167      inputFile >> *matrix ;
00168 
00169      return matrix ;
00170 }

std::vector< CLHEP::HepGenMatrix * > * matrixSaver::getMatrixVector ( std::string  inputFileName  ) 

Definition at line 174 of file matrixSaver.cc.

References i, in, outputToXml::inputFile, matrix, and NULL.

00175 {
00176      // open the output file
00177      std::fstream inputFile (inputFileName.c_str (), std::ios::in) ;
00178      assert (inputFile != NULL) ;
00179 
00180      // get the vector length
00181      int numElem = 0 ;
00182      inputFile >> numElem ;
00183      
00184      // get the matrix dimensions
00185      int numRow = 0 ;
00186      int numCol = 0 ;
00187      inputFile >> numRow ;
00188      inputFile >> numCol ;
00189 
00190      //PG prepara il vector
00191      std::vector<CLHEP::HepGenMatrix*>* matrixVector = 
00192        new std::vector<CLHEP::HepGenMatrix*> (numElem) ;
00193           
00194      //PG loop sugli elementi del vettore
00195      for (int i=0 ; i<numElem ; ++i)
00196        {
00197           //PG definisce il puntatore
00198           CLHEP::HepGenMatrix * matrix ;
00199           //PG attribuisce un oggetto concreto
00200 
00201           if (numCol > 1)
00202                   matrix = new CLHEP::HepMatrix (numRow, numCol, 0) ;
00203           else
00204                   matrix = new CLHEP::HepVector (numRow, 0) ;
00205           
00206           //PG scarica su un oggetto concreto
00207           inputFile >> *matrix ;
00208 
00209           //PG riempie il vettore
00210           (*matrixVector)[i] = matrix ;
00211        }
00212 
00213      return matrixVector ;
00214 }

int matrixSaver::saveMatrix ( std::string  outputFileName,
const CLHEP::HepGenMatrix *  saveMe 
)

Definition at line 58 of file matrixSaver.cc.

References out.

00060 {
00061    // open the output file
00062    std::fstream outputFile (outputFileName.c_str (), std::ios::out) ;
00063    assert (outputFile) ;
00064  
00065    int numRow = saveMe->num_row () ;
00066    int numCol = saveMe->num_col () ;
00067 
00068    // write out the matrix dimensions
00069    outputFile << numRow << '\t'
00070                   << numCol << '\n' ;
00071 
00072    outputFile << saveMe ;
00073 
00074    return 0 ;
00075 
00076 }

int matrixSaver::saveMatrixVector ( std::string  outputFileName,
const std::vector< CLHEP::HepGenMatrix * > &  saveMe 
)

Definition at line 80 of file matrixSaver.cc.

References it, NULL, and out.

00082 {
00083      typedef std::vector<CLHEP::HepGenMatrix*>::const_iterator const_iterator ;
00084      // open the output file
00085      std::fstream outputFile (filename.c_str (), std::ios::out) ;
00086      assert (outputFile != NULL) ;
00087 
00088      // save the number of elements of the vector
00089      outputFile << saveMe.size ()       
00090                 << '\n' ;
00091 
00092      // save the matrix sizes
00093      outputFile << (*saveMe.begin ())->num_row ()
00094                 << '\t'
00095                 << (*saveMe.begin ())->num_col ()
00096                 << '\n' ;
00097 
00098      // loop over the vector
00099      for (const_iterator it = saveMe.begin () ;
00100                it != saveMe.end () ;
00101                ++it)
00102        {
00103                outputFile << (*it) ;
00104        } // loop over the vecor
00105 
00106      return 0 ;
00107 }

int matrixSaver::touch ( std::string  inputFileName  ) 

Definition at line 138 of file matrixSaver.cc.

References in, outputToXml::inputFile, and NULL.

Referenced by getSavedMatrix().

00139 {
00140    std::fstream inputFile (inputFileName.c_str (), std::ios::in) ;
00141    return (inputFile != NULL) ;
00142 }


The documentation for this class was generated from the following files:
Generated on Tue Jun 9 18:28:04 2009 for CMSSW by  doxygen 1.5.4