CMS 3D CMS Logo

Public Member Functions

matrixSaver Class Reference

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

#include <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) CLHEP::HepMatrix to (from) text files

Date:
2009/05/27 11:37:33
Revision:
1.3
Id:
matrixSaver.h,v 1.3 2009/05/27 11:37:33 fabiocos Exp
Author:
Author:
fabiocos

Definition at line 26 of file matrixSaver.h.


Constructor & Destructor Documentation

matrixSaver::matrixSaver ( )

Definition at line 16 of file matrixSaver.cc.

{
//   std::cout << "[matrixSaver][ctor] matrixSaver instance" << std::endl ;
}
matrixSaver::~matrixSaver ( )

Definition at line 22 of file matrixSaver.cc.

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

Member Function Documentation

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

Definition at line 218 of file matrixSaver.cc.

References i, recoMuon::in, analyzePatCleaning_cfg::inputFile, and NULL.

{
     // open the output file
     std::fstream inputFile (inputFileName.c_str (), std::ios::in) ;
     assert (inputFile != NULL) ;

     // get the vector length
     int numElem = 0 ;
     inputFile >> numElem ;
     
     // get the matrix dimensions
     int numRow = 0 ;
     int numCol = 0 ;
     inputFile >> numRow ;
     inputFile >> numCol ;

     //PG prepara il vector
     std::vector<CLHEP::HepMatrix> matrixVector (
         numElem,
         CLHEP::HepMatrix (numRow,numCol,0)
       ) ;
     
     //PG loop sugli elementi del vettore
     for (int i=0 ; i<numElem ; ++i)
       {
          
          //PG scarica su un oggetto concreto
          inputFile >> matrixVector[i] ;

       }

     return matrixVector ;
}
CLHEP::HepGenMatrix * matrixSaver::getMatrix ( std::string  inputFileName)

Definition at line 147 of file matrixSaver.cc.

References dtNoiseDBValidation_cfg::cerr, recoMuon::in, analyzePatCleaning_cfg::inputFile, makeMuonMisalignmentScenario::matrix, and NULL.

Referenced by getSavedMatrix().

{
     //PG open the output file
     std::fstream inputFile (inputFileName.c_str (), std::ios::in) ;
     if (inputFile == NULL) std::cerr << "file: " << inputFileName << std::endl ;
     assert (inputFile != NULL) ;

     //PG get the matrix dimensions
     int numRow = 0 ;
     int numCol = 0 ;
     inputFile >> numRow ;
     inputFile >> numCol ;

     //PG instantiate the matrix
     CLHEP::HepGenMatrix * matrix ;
     if (numCol > 1)
             matrix = new CLHEP::HepMatrix (numRow, numCol, 0) ;
     else
             matrix = new CLHEP::HepVector (numRow, 0) ;

     inputFile >> *matrix ;

     return matrix ;
}
std::vector< CLHEP::HepGenMatrix * > * matrixSaver::getMatrixVector ( std::string  inputFileName)

Definition at line 174 of file matrixSaver.cc.

References i, recoMuon::in, analyzePatCleaning_cfg::inputFile, makeMuonMisalignmentScenario::matrix, and NULL.

{
     // open the output file
     std::fstream inputFile (inputFileName.c_str (), std::ios::in) ;
     assert (inputFile != NULL) ;

     // get the vector length
     int numElem = 0 ;
     inputFile >> numElem ;
     
     // get the matrix dimensions
     int numRow = 0 ;
     int numCol = 0 ;
     inputFile >> numRow ;
     inputFile >> numCol ;

     //PG prepara il vector
     std::vector<CLHEP::HepGenMatrix*>* matrixVector = 
       new std::vector<CLHEP::HepGenMatrix*> (numElem) ;
          
     //PG loop sugli elementi del vettore
     for (int i=0 ; i<numElem ; ++i)
       {
          //PG definisce il puntatore
          CLHEP::HepGenMatrix * matrix ;
          //PG attribuisce un oggetto concreto

          if (numCol > 1)
                  matrix = new CLHEP::HepMatrix (numRow, numCol, 0) ;
          else
                  matrix = new CLHEP::HepVector (numRow, 0) ;
          
          //PG scarica su un oggetto concreto
          inputFile >> *matrix ;

          //PG riempie il vettore
          (*matrixVector)[i] = matrix ;
       }

     return matrixVector ;
}
int matrixSaver::saveMatrix ( std::string  outputFileName,
const CLHEP::HepGenMatrix *  saveMe 
)

Definition at line 58 of file matrixSaver.cc.

References dbtoconf::out, and download_sqlite_cfg::outputFile.

{
   // open the output file
   std::fstream outputFile (outputFileName.c_str (), std::ios::out) ;
   assert (outputFile) ;
 
   int numRow = saveMe->num_row () ;
   int numCol = saveMe->num_col () ;

   // write out the matrix dimensions
   outputFile << numRow << '\t'
                  << numCol << '\n' ;

   outputFile << saveMe ;

   return 0 ;

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

Definition at line 80 of file matrixSaver.cc.

References NULL, dbtoconf::out, and download_sqlite_cfg::outputFile.

{
     typedef std::vector<CLHEP::HepGenMatrix*>::const_iterator const_iterator ;
     // open the output file
     std::fstream outputFile (filename.c_str (), std::ios::out) ;
     assert (outputFile != NULL) ;

     // save the number of elements of the vector
     outputFile << saveMe.size ()       
                << '\n' ;

     // save the matrix sizes
     outputFile << (*saveMe.begin ())->num_row ()
                << '\t'
                << (*saveMe.begin ())->num_col ()
                << '\n' ;

     // loop over the vector
     for (const_iterator it = saveMe.begin () ;
               it != saveMe.end () ;
               ++it)
       {
               outputFile << (*it) ;
       } // loop over the vecor

     return 0 ;
}
int matrixSaver::touch ( std::string  inputFileName)

Definition at line 138 of file matrixSaver.cc.

References recoMuon::in, analyzePatCleaning_cfg::inputFile, and NULL.

Referenced by getSavedMatrix().

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