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