CMS 3D CMS Logo

PixelDelay25Calib.cc
Go to the documentation of this file.
1 //
2 // This class manages data and files used
3 // in the Delay25 calibration
4 //
5 //
6 //
7 //
8 
11 #include <iostream>
12 #include <cassert>
13 #include <map>
14 #include <sstream>
15 
16 using namespace pos;
17 
18 using namespace std;
19 
20 PixelDelay25Calib::PixelDelay25Calib(vector<vector<string> > &tableMat)
21  : PixelCalibBase(), PixelConfigBase("", "", "") {
22  std::string mthn = "[PixelDelay25Calib::PixelDelay25Calib()]\t\t\t ";
23  std::map<std::string, int> colM;
24  std::vector<std::string> colNames;
39  colNames.push_back("CONFIG_KEY");
40  colNames.push_back("KEY_TYPE");
41  colNames.push_back("KEY_ALIAS");
42  colNames.push_back("VERSION");
43  colNames.push_back("KIND_OF_COND");
44  colNames.push_back("CALIB_TYPE");
45  colNames.push_back("CALIB_OBJ_DATA_FILE");
46  colNames.push_back("CALIB_OBJ_DATA_CLOB");
47 
48  for (unsigned int c = 0; c < tableMat[0].size(); c++) {
49  for (unsigned int n = 0; n < colNames.size(); n++) {
50  if (tableMat[0][c] == colNames[n]) {
51  colM[colNames[n]] = c;
52  break;
53  }
54  }
55  } //end for
56  for (unsigned int n = 0; n < colNames.size(); n++) {
57  if (colM.find(colNames[n]) == colM.end()) {
58  std::cerr << "[[PixelDelay25Calib::PixelDelay25Calib()]\tCouldn't find in the database the column with name "
59  << colNames[n] << std::endl;
60  assert(0);
61  }
62  }
63 
64  std::istringstream in;
65  in.str(tableMat[1][colM["CALIB_OBJ_DATA_CLOB"]]);
66 
67  //Read initial SDa and RDa values, ranges,
68  //and grid step size from file
69 
71 
72  in >> tmp;
73 
74  assert(tmp == "Mode:");
75  in >> mode_;
76 
77  in >> tmp;
78 
79  assert(tmp == "Portcards:");
80  in >> tmp;
81  if (tmp == "All") {
82  allPortcards_ = true;
83  } else {
84  allPortcards_ = false;
85  }
86  while (tmp != "AllModules:") {
87  portcardNames_.insert(tmp);
88  in >> tmp;
89  }
90 
91  assert(tmp == "AllModules:");
92  in >> allModules_;
93 
94  in >> tmp;
95 
96  assert(tmp == "OrigSDa:");
97  in >> origSDa_;
98 
99  in >> tmp;
100 
101  assert(tmp == "OrigRDa:");
102  in >> origRDa_;
103 
104  in >> tmp;
105 
106  assert(tmp == "Range:");
107  in >> range_;
108 
109  in >> tmp;
110 
111  assert(tmp == "GridSize:");
112  in >> gridSize_;
113 
114  in >> tmp;
115  assert(tmp == "Tests:");
116  in >> numTests_;
117 
118  in >> tmp;
119  if (tmp == "Commands:") {
120  in >> commands_;
121  } else {
122  commands_ = 0;
123  }
124 
125  //Number of steps in the grid
126  gridSteps_ = range_ / gridSize_;
127 
128  // Added by Dario as a temporary patch for Debbie (this will disappear in the future)
129  calibFileContent_ = in.str();
130  //cout << __LINE__ << "] " << __PRETTY_FUNCTION__ << "\tcalibFileContent_\n " << calibFileContent_ << endl ;
131  // End of temporary patch
132 }
133 
134 PixelDelay25Calib::PixelDelay25Calib(std::string filename) : PixelCalibBase(), PixelConfigBase("", "", "") {
135  std::string mthn = "[PixelDelay25Calib::PixelDelay25Calib()]\t\t\t ";
136 
137  std::ifstream in(filename.c_str());
138 
139  if (!in.good()) {
140  std::cout << __LINE__ << "]\t" << mthn << "Could not open: " << filename << std::endl;
141  assert(0);
142  } else {
143  std::cout << __LINE__ << "]\t" << mthn << "Opened: " << filename << std::endl;
144  }
145 
146  //Read initial SDa and RDa values, ranges,
147  //and grid step size from file
148 
150 
151  in >> tmp;
152 
153  assert(tmp == "Mode:");
154  in >> mode_;
155 
156  //cout << __LINE__ << "]\t" << mthn << "mode_="<<mode_<<endl;
157 
158  in >> tmp;
159 
160  assert(tmp == "Portcards:");
161  in >> tmp;
162  if (tmp == "All") {
163  allPortcards_ = true;
164  } else {
165  allPortcards_ = false;
166  }
167  while (tmp != "AllModules:") {
168  portcardNames_.insert(tmp);
169  in >> tmp;
170  }
171 
172  assert(tmp == "AllModules:");
173  in >> allModules_;
174 
175  in >> tmp;
176 
177  assert(tmp == "OrigSDa:");
178  in >> origSDa_;
179 
180  in >> tmp;
181 
182  assert(tmp == "OrigRDa:");
183  in >> origRDa_;
184 
185  in >> tmp;
186 
187  assert(tmp == "Range:");
188  in >> range_;
189 
190  in >> tmp;
191 
192  assert(tmp == "GridSize:");
193  in >> gridSize_;
194 
195  in >> tmp;
196  assert(tmp == "Tests:");
197  in >> numTests_;
198 
199  in >> tmp;
200  if (tmp == "Commands:") {
201  in >> commands_;
202  } else {
203  commands_ = 0;
204  }
205 
206  in.close();
207 
208  //Number of steps in the grid
209  gridSteps_ = range_ / gridSize_;
210 
211  // Added by Dario as a temporary patch for Debbie (this will disappear in the future)
212  std::ifstream inTmp(filename.c_str());
213  calibFileContent_ = "";
214  while (!inTmp.eof()) {
215  std::string tmpString;
216  getline(inTmp, tmpString);
217  calibFileContent_ += tmpString + "\n";
218  //cout << __LINE__ << "]\t" << "[PixelCalibConfiguration::~PixelCalibConfiguration()]\t\t" << calibFileContent_ << endl ;
219  }
220  inTmp.close();
221  // End of temporary patch
222 }
223 
224 PixelDelay25Calib::~PixelDelay25Calib() {}
225 
227  if (!path.empty())
228  path += "/";
229  graph_ = path + "graph_" + portcardName + "_" + moduleName + ".dat";
230  graphout_.open(graph_.c_str());
231  return;
232 }
233 
235  graphout_ << "Portcard: " << portcardName << endl;
236  graphout_ << "Module: " << moduleName << endl;
237  graphout_ << "SDaOrigin: " << origSDa_ << endl;
238  graphout_ << "RDaOrigin: " << origRDa_ << endl;
239  graphout_ << "SDaRange: " << range_ << endl;
240  graphout_ << "RDaRange: " << range_ << endl;
241  graphout_ << "GridSize: " << gridSize_ << endl;
242  graphout_ << "Tests: " << numTests_ << endl;
243  return;
244 }
245 
247  graphout_ << tmp << endl;
248  return;
249 }
250 
251 void PixelDelay25Calib::writeFiles(int currentSDa, int currentRDa, int number) {
252  graphout_ << currentSDa << " " << currentRDa << " " << number << endl;
253  return;
254 }
255 
257  graphout_.close();
258  return;
259 }
260 
262  //FIXME this is not tested for all the use cases...
263 
264  if (!dir.empty())
265  dir += "/";
266  std::string filename = dir + "delay25.dat";
267  std::ofstream out(filename.c_str());
268 
269  out << "Mode: " << mode_ << endl;
270 
271  out << "Portcards:" << endl;
272 
273  std::set<std::string>::const_iterator i = portcardNames_.begin();
274  while (i != portcardNames_.end()) {
275  out << *i << endl;
276  ++i;
277  }
278 
279  out << "AllModules:" << endl;
280  if (allModules_) {
281  out << "1" << endl;
282  } else {
283  out << "0" << endl;
284  }
285 
286  out << "OrigSDa:" << endl;
287  out << origSDa_ << endl;
288 
289  out << "OrigRDa:" << endl;
290  out << origRDa_ << endl;
291 
292  out << "Range:" << endl;
293  out << range_ << endl;
294 
295  out << "GridSize:" << endl;
296  out << gridSize_ << endl;
297 
298  out << "Tests:" << endl;
299  out << numTests_ << endl;
300 
301  out << "Commands:" << endl;
302  out << commands_ << endl;
303 
304  out.close();
305 }
306 
307 //=============================================================================================
309  int version,
311  std::ofstream *outstream,
312  std::ofstream *out1stream,
313  std::ofstream *out2stream) const {
314  std::string mthn = "[PixelDelay25Calib::writeXMLHeader()]\t\t\t ";
315  std::stringstream maskFullPath;
316 
317  writeASCII(path);
318 
319  maskFullPath << path << "/PixelCalib_Test_" << PixelTimeFormatter::getmSecTime() << ".xml";
320  std::cout << __LINE__ << "]\t" << mthn << "Writing to: " << maskFullPath.str() << std::endl;
321 
322  outstream->open(maskFullPath.str().c_str());
323 
324  *outstream << "<?xml version='1.0' encoding='UTF-8' standalone='yes'?>" << std::endl;
325  *outstream << "<ROOT xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>" << std::endl;
326  *outstream << "" << std::endl;
327  *outstream << " <!-- " << mthn << "-->" << std::endl;
328  *outstream << "" << std::endl;
329  *outstream << " <HEADER>" << std::endl;
330  *outstream << " <TYPE>" << std::endl;
331  *outstream << " <EXTENSION_TABLE_NAME>PIXEL_CALIB_CLOB</EXTENSION_TABLE_NAME>" << std::endl;
332  *outstream << " <NAME>Calibration Object Clob</NAME>" << std::endl;
333  *outstream << " </TYPE>" << std::endl;
334  *outstream << " <RUN>" << std::endl;
335  *outstream << " <RUN_TYPE>delay25</RUN_TYPE>" << std::endl;
336  *outstream << " <RUN_NUMBER>1</RUN_NUMBER>" << std::endl;
337  *outstream << " <RUN_BEGIN_TIMESTAMP>" << PixelTimeFormatter::getTime() << "</RUN_BEGIN_TIMESTAMP>" << std::endl;
338  *outstream << " <LOCATION>CERN P5</LOCATION>" << std::endl;
339  *outstream << " </RUN>" << std::endl;
340  *outstream << " </HEADER>" << std::endl;
341  *outstream << "" << std::endl;
342  *outstream << " <DATA_SET>" << std::endl;
343  *outstream << "" << std::endl;
344  *outstream << " <VERSION>" << version << "</VERSION>" << std::endl;
345  *outstream << " <COMMENT_DESCRIPTION>" << getComment() << "</COMMENT_DESCRIPTION>" << std::endl;
346  *outstream << " <CREATED_BY_USER>" << getAuthor() << "</CREATED_BY_USER>" << std::endl;
347  *outstream << "" << std::endl;
348  *outstream << " <PART>" << std::endl;
349  *outstream << " <NAME_LABEL>CMS-PIXEL-ROOT</NAME_LABEL>" << std::endl;
350  *outstream << " <KIND_OF_PART>Detector ROOT</KIND_OF_PART>" << std::endl;
351  *outstream << " </PART>" << std::endl;
352 }
353 
354 //=============================================================================================
355 void PixelDelay25Calib::writeXML(std::ofstream *outstream, std::ofstream *out1stream, std::ofstream *out2stream) const {
356  std::string mthn = "[PixelDelay25Calib::writeXML()]\t\t\t ";
357 
358  std::cout << __LINE__ << "]\t" << mthn << "Writing.." << std::endl;
359 
360  *outstream << " " << std::endl;
361  *outstream << " <DATA>" << std::endl;
362  *outstream << " <CALIB_OBJ_DATA_FILE>./delay25.dat</CALIB_OBJ_DATA_FILE>" << std::endl;
363  *outstream << " <CALIB_TYPE>delay25</CALIB_TYPE>" << std::endl;
364  *outstream << " </DATA>" << std::endl;
365  *outstream << " " << std::endl;
366 }
367 
368 //=============================================================================================
369 void PixelDelay25Calib::writeXMLTrailer(std::ofstream *outstream,
370  std::ofstream *out1stream,
371  std::ofstream *out2stream) const {
372  std::string mthn = "[PixelDelay25Calib::writeXMLTrailer()]\t\t\t ";
373 
374  *outstream << " </DATA_SET>" << std::endl;
375  *outstream << "</ROOT>" << std::endl;
376 
377  outstream->close();
378  std::cout << __LINE__ << "]\t" << mthn << "Data written " << std::endl;
379 }
This file contains the base class for "pixel configuration data" management.
void writeXMLHeader(pos::PixelConfigKey key, int version, std::string path, std::ofstream *out, std::ofstream *out1=nullptr, std::ofstream *out2=nullptr) const override
std::set< std::string > portcardNames_
void writeSettings(std::string portcardName, std::string moduleName)
std::string getComment() const
void writeFiles(std::string tmp)
assert(be >=bs)
static std::string getmSecTime(void)
static std::string getTime(void)
This class provides utility methods to manipulate ASCII formatted timestamps.
PixelDelay25Calib(std::string)
void writeXMLTrailer(std::ofstream *out, std::ofstream *out1=nullptr, std::ofstream *out2=nullptr) const override
This class implements..
void openFiles(std::string portcardName, std::string moduleName, std::string path="")
This class manages data and files used in the Delay25 calibration.
void writeASCII(std::string dir="") const override
std::string getAuthor() const
void writeXML(pos::PixelConfigKey key, int version, std::string path) const override
tmp
align.sh
Definition: createJobs.py:716