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::matrixSaver ( )

Definition at line 16 of file matrixSaver.cc.

16  {
17  // std::cout << "[matrixSaver][ctor] matrixSaver instance" << std::endl ;
18 }

◆ ~matrixSaver()

matrixSaver::~matrixSaver ( )

Definition at line 20 of file matrixSaver.cc.

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

Member Function Documentation

◆ getConcreteMatrixVector()

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

Definition at line 172 of file matrixSaver.cc.

References cms::cuda::assert(), mps_fire::i, recoMuon::in, makeListRunsInFiles::inputFile, and InefficientDoubleROC::inputFileName.

172  {
173  // open the output file
174  std::fstream inputFile(inputFileName.c_str(), std::ios::in);
175  assert(inputFile.fail() == false);
176 
177  // get the vector length
178  int numElem = 0;
179  inputFile >> numElem;
180 
181  // get the matrix dimensions
182  int numRow = 0;
183  int numCol = 0;
184  inputFile >> numRow;
185  inputFile >> numCol;
186 
187  //PG prepara il vector
188  std::vector<CLHEP::HepMatrix> matrixVector(numElem, CLHEP::HepMatrix(numRow, numCol, 0));
189 
190  //PG loop sugli elementi del vettore
191  for (int i = 0; i < numElem; ++i) {
192  //PG scarica su un oggetto concreto
193  inputFile >> matrixVector[i];
194  }
195 
196  return matrixVector;
197 }
assert(be >=bs)

◆ getMatrix()

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

Definition at line 108 of file matrixSaver.cc.

References cms::cuda::assert(), DMR_cfg::cerr, recoMuon::in, makeListRunsInFiles::inputFile, InefficientDoubleROC::inputFileName, and makeMuonMisalignmentScenario::matrix.

108  {
109  //PG open the output file
110  std::fstream inputFile(inputFileName.c_str(), std::ios::in);
111  if (inputFile.fail())
112  std::cerr << "file: " << inputFileName << std::endl;
113  assert(inputFile.fail() == false);
114 
115  //PG get the matrix dimensions
116  int numRow = 0;
117  int numCol = 0;
118  inputFile >> numRow;
119  inputFile >> numCol;
120 
121  //PG instantiate the matrix
122  CLHEP::HepGenMatrix *matrix;
123  if (numCol > 1)
124  matrix = new CLHEP::HepMatrix(numRow, numCol, 0);
125  else
126  matrix = new CLHEP::HepVector(numRow, 0);
127 
128  inputFile >> *matrix;
129 
130  return matrix;
131 }
assert(be >=bs)

◆ getMatrixVector()

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

Definition at line 133 of file matrixSaver.cc.

References cms::cuda::assert(), mps_fire::i, recoMuon::in, makeListRunsInFiles::inputFile, InefficientDoubleROC::inputFileName, and makeMuonMisalignmentScenario::matrix.

133  {
134  // open the output file
135  std::fstream inputFile(inputFileName.c_str(), std::ios::in);
136  assert(inputFile.fail() == false);
137 
138  // get the vector length
139  int numElem = 0;
140  inputFile >> numElem;
141 
142  // get the matrix dimensions
143  int numRow = 0;
144  int numCol = 0;
145  inputFile >> numRow;
146  inputFile >> numCol;
147 
148  //PG prepara il vector
149  std::vector<CLHEP::HepGenMatrix *> *matrixVector = new std::vector<CLHEP::HepGenMatrix *>(numElem);
150 
151  //PG loop sugli elementi del vettore
152  for (int i = 0; i < numElem; ++i) {
153  //PG definisce il puntatore
154  CLHEP::HepGenMatrix *matrix;
155  //PG attribuisce un oggetto concreto
156 
157  if (numCol > 1)
158  matrix = new CLHEP::HepMatrix(numRow, numCol, 0);
159  else
160  matrix = new CLHEP::HepVector(numRow, 0);
161 
162  //PG scarica su un oggetto concreto
163  inputFile >> *matrix;
164 
165  //PG riempie il vettore
166  (*matrixVector)[i] = matrix;
167  }
168 
169  return matrixVector;
170 }
assert(be >=bs)

◆ saveMatrix()

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

Definition at line 44 of file matrixSaver.cc.

References cms::cuda::assert(), MillePedeFileConverter_cfg::out, download_sqlite_cfg::outputFile, and makeListRunsInFiles::outputFileName.

44  {
45  // open the output file
46  std::fstream outputFile(outputFileName.c_str(), std::ios::out);
48 
49  int numRow = saveMe->num_row();
50  int numCol = saveMe->num_col();
51 
52  // write out the matrix dimensions
53  outputFile << numRow << '\t' << numCol << '\n';
54 
55  outputFile << saveMe;
56 
57  return 0;
58 }
assert(be >=bs)

◆ saveMatrixVector()

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

Definition at line 60 of file matrixSaver.cc.

References cms::cuda::assert(), corrVsCorr::filename, MillePedeFileConverter_cfg::out, and download_sqlite_cfg::outputFile.

60  {
61  typedef std::vector<CLHEP::HepGenMatrix *>::const_iterator const_iterator;
62  // open the output file
63  std::fstream outputFile(filename.c_str(), std::ios::out);
64  assert(outputFile.fail() == false);
65 
66  // save the number of elements of the vector
67  outputFile << saveMe.size() << '\n';
68 
69  // save the matrix sizes
70  outputFile << (*saveMe.begin())->num_row() << '\t' << (*saveMe.begin())->num_col() << '\n';
71 
72  // loop over the vector
73  for (const_iterator it = saveMe.begin(); it != saveMe.end(); ++it) {
74  outputFile << (*it);
75  } // loop over the vecor
76 
77  return 0;
78 }
assert(be >=bs)

◆ touch()

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