CMS 3D CMS Logo

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