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.

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 }

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

◆ getMatrix()

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

Definition at line 108 of file matrixSaver.cc.

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 }

References cms::cuda::assert(), beam_dqm_sourceclient-live_cfg::cerr, recoMuon::in, dtResolutionTest_cfi::inputFile, InefficientDoubleROC::inputFileName, and makeMuonMisalignmentScenario::matrix.

◆ getMatrixVector()

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

Definition at line 133 of file matrixSaver.cc.

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 }

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

◆ saveMatrix()

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

Definition at line 44 of file matrixSaver.cc.

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 }

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

◆ saveMatrixVector()

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

Definition at line 60 of file matrixSaver.cc.

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 }

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

◆ touch()

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

Definition at line 103 of file matrixSaver.cc.

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

References recoMuon::in, dtResolutionTest_cfi::inputFile, and InefficientDoubleROC::inputFileName.

mps_fire.i
i
Definition: mps_fire.py:355
makeMuonMisalignmentScenario.matrix
list matrix
Definition: makeMuonMisalignmentScenario.py:141
cms::cuda::assert
assert(be >=bs)
download_sqlite_cfg.outputFile
outputFile
Definition: download_sqlite_cfg.py:5
InefficientDoubleROC.inputFileName
inputFileName
Definition: InefficientDoubleROC.py:437
corrVsCorr.filename
filename
Definition: corrVsCorr.py:123
reco_skim_cfg_mod.outputFileName
outputFileName
Definition: reco_skim_cfg_mod.py:15
beam_dqm_sourceclient-live_cfg.cerr
cerr
Definition: beam_dqm_sourceclient-live_cfg.py:17
recoMuon::in
Definition: RecoMuonEnumerators.h:6
dtResolutionTest_cfi.inputFile
inputFile
Definition: dtResolutionTest_cfi.py:14
MillePedeFileConverter_cfg.out
out
Definition: MillePedeFileConverter_cfg.py:31