CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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)
 
int 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 218 of file matrixSaver.cc.

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

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

148 {
149  //PG open the output file
150  std::fstream inputFile (inputFileName.c_str (), std::ios::in) ;
151  if (inputFile == NULL) std::cerr << "file: " << inputFileName << std::endl ;
152  assert (inputFile != NULL) ;
153 
154  //PG get the matrix dimensions
155  int numRow = 0 ;
156  int numCol = 0 ;
157  inputFile >> numRow ;
158  inputFile >> numCol ;
159 
160  //PG instantiate the matrix
161  CLHEP::HepGenMatrix * matrix ;
162  if (numCol > 1)
163  matrix = new CLHEP::HepMatrix (numRow, numCol, 0) ;
164  else
165  matrix = new CLHEP::HepVector (numRow, 0) ;
166 
167  inputFile >> *matrix ;
168 
169  return matrix ;
170 }
#define NULL
Definition: scimark2.h:8
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.

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

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 }
tuple out
Definition: dbtoconf.py:99
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.

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 != NULL) ;
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 }
#define NULL
Definition: scimark2.h:8
tuple out
Definition: dbtoconf.py:99
tuple filename
Definition: lut2db_cfg.py:20
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().