CMS 3D CMS Logo

List of all members | Public Member Functions
matrixSaver Class Reference

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

#include <matrixSaver.h>

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)
 
bool touch (std::string inputFileName)
 
 ~matrixSaver ()
 

Detailed Description

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

Definition at line 22 of file matrixSaver.h.

Constructor & Destructor Documentation

matrixSaver::matrixSaver ( )

Definition at line 16 of file matrixSaver.cc.

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

Definition at line 22 of file matrixSaver.cc.

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

Member Function Documentation

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

Definition at line 217 of file matrixSaver.cc.

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

218 {
219  // open the output file
220  std::fstream inputFile (inputFileName.c_str (), std::ios::in) ;
221  assert(inputFile.fail() == false);
222 
223  // get the vector length
224  int numElem = 0 ;
225  inputFile >> numElem ;
226 
227  // get the matrix dimensions
228  int numRow = 0 ;
229  int numCol = 0 ;
230  inputFile >> numRow ;
231  inputFile >> numCol ;
232 
233  //PG prepara il vector
234  std::vector<CLHEP::HepMatrix> matrixVector (
235  numElem,
236  CLHEP::HepMatrix (numRow,numCol,0)
237  ) ;
238 
239  //PG loop sugli elementi del vettore
240  for (int i=0 ; i<numElem ; ++i)
241  {
242 
243  //PG scarica su un oggetto concreto
244  inputFile >> matrixVector[i] ;
245 
246  }
247 
248  return matrixVector ;
249 }
int i
Definition: DBlmapReader.cc:9
CLHEP::HepGenMatrix * matrixSaver::getMatrix ( std::string  inputFileName)

Definition at line 146 of file matrixSaver.cc.

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

Referenced by getSavedMatrix().

147 {
148  //PG open the output file
149  std::fstream inputFile (inputFileName.c_str (), std::ios::in) ;
150  if (inputFile.fail()) std::cerr << "file: " << inputFileName << std::endl ;
151  assert(inputFile.fail() == false);
152 
153  //PG get the matrix dimensions
154  int numRow = 0 ;
155  int numCol = 0 ;
156  inputFile >> numRow ;
157  inputFile >> numCol ;
158 
159  //PG instantiate the matrix
160  CLHEP::HepGenMatrix * matrix ;
161  if (numCol > 1)
162  matrix = new CLHEP::HepMatrix (numRow, numCol, 0) ;
163  else
164  matrix = new CLHEP::HepVector (numRow, 0) ;
165 
166  inputFile >> *matrix ;
167 
168  return matrix ;
169 }
std::vector< CLHEP::HepGenMatrix * > * matrixSaver::getMatrixVector ( std::string  inputFileName)

Definition at line 173 of file matrixSaver.cc.

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

174 {
175  // open the output file
176  std::fstream inputFile (inputFileName.c_str (), std::ios::in) ;
177  assert(inputFile.fail() == false);
178 
179  // get the vector length
180  int numElem = 0 ;
181  inputFile >> numElem ;
182 
183  // get the matrix dimensions
184  int numRow = 0 ;
185  int numCol = 0 ;
186  inputFile >> numRow ;
187  inputFile >> numCol ;
188 
189  //PG prepara il vector
190  std::vector<CLHEP::HepGenMatrix*>* matrixVector =
191  new std::vector<CLHEP::HepGenMatrix*> (numElem) ;
192 
193  //PG loop sugli elementi del vettore
194  for (int i=0 ; i<numElem ; ++i)
195  {
196  //PG definisce il puntatore
197  CLHEP::HepGenMatrix * matrix ;
198  //PG attribuisce un oggetto concreto
199 
200  if (numCol > 1)
201  matrix = new CLHEP::HepMatrix (numRow, numCol, 0) ;
202  else
203  matrix = new CLHEP::HepVector (numRow, 0) ;
204 
205  //PG scarica su un oggetto concreto
206  inputFile >> *matrix ;
207 
208  //PG riempie il vettore
209  (*matrixVector)[i] = matrix ;
210  }
211 
212  return matrixVector ;
213 }
int i
Definition: DBlmapReader.cc:9
int matrixSaver::saveMatrix ( std::string  outputFileName,
const CLHEP::HepGenMatrix *  saveMe 
)

Definition at line 58 of file matrixSaver.cc.

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

60 {
61  // open the output file
62  std::fstream outputFile (outputFileName.c_str (), std::ios::out) ;
63  assert (outputFile) ;
64 
65  int numRow = saveMe->num_row () ;
66  int numCol = saveMe->num_col () ;
67 
68  // write out the matrix dimensions
69  outputFile << numRow << '\t'
70  << numCol << '\n' ;
71 
72  outputFile << saveMe ;
73 
74  return 0 ;
75 
76 }
int matrixSaver::saveMatrixVector ( std::string  outputFileName,
const std::vector< CLHEP::HepGenMatrix * > &  saveMe 
)

Definition at line 80 of file matrixSaver.cc.

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

82 {
83  typedef std::vector<CLHEP::HepGenMatrix*>::const_iterator const_iterator ;
84  // open the output file
85  std::fstream outputFile (filename.c_str (), std::ios::out) ;
86  assert(outputFile.fail() == false) ;
87 
88  // save the number of elements of the vector
89  outputFile << saveMe.size ()
90  << '\n' ;
91 
92  // save the matrix sizes
93  outputFile << (*saveMe.begin ())->num_row ()
94  << '\t'
95  << (*saveMe.begin ())->num_col ()
96  << '\n' ;
97 
98  // loop over the vector
99  for (const_iterator it = saveMe.begin () ;
100  it != saveMe.end () ;
101  ++it)
102  {
103  outputFile << (*it) ;
104  } // loop over the vecor
105 
106  return 0 ;
107 }
bool matrixSaver::touch ( std::string  inputFileName)

Definition at line 137 of file matrixSaver.cc.

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

Referenced by getSavedMatrix().