CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups 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)
 
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.

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

Definition at line 20 of file matrixSaver.cc.

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

Member Function Documentation

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, and writeEcalDQMStatus::inputFile.

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)
CLHEP::HepGenMatrix * matrixSaver::getMatrix ( std::string  inputFileName)

Definition at line 108 of file matrixSaver.cc.

References cms::cuda::assert(), EcnaPython_AdcPeg12_S1_10_R170298_1_0_150_Dee0::cerr, recoMuon::in, writeEcalDQMStatus::inputFile, and makeMuonMisalignmentScenario::matrix.

Referenced by getSavedMatrix().

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)
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, writeEcalDQMStatus::inputFile, 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)
int matrixSaver::saveMatrix ( std::string  outputFileName,
const CLHEP::HepGenMatrix *  saveMe 
)

Definition at line 44 of file matrixSaver.cc.

References cms::cuda::assert(), submitPVResolutionJobs::out, and download_sqlite_cfg::outputFile.

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)
int matrixSaver::saveMatrixVector ( std::string  outputFileName,
const std::vector< CLHEP::HepGenMatrix * > &  saveMe 
)

Definition at line 60 of file matrixSaver.cc.

References cms::cuda::assert(), submitPVResolutionJobs::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)
tuple filename
Definition: lut2db_cfg.py:20
bool matrixSaver::touch ( std::string  inputFileName)

Definition at line 103 of file matrixSaver.cc.

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

Referenced by getSavedMatrix().

103  {
104  std::fstream inputFile(inputFileName.c_str(), std::ios::in);
105  return !inputFile.fail();
106 }