CMS 3D CMS Logo

PixelFEDTestDAC.cc
Go to the documentation of this file.
3 #include <cstring>
4 #include <cassert>
5 #include <map>
6 #include <sstream>
7 
8 using namespace std;
9 
10 using namespace pos;
11 
12 PixelFEDTestDAC::PixelFEDTestDAC(std::vector<std::vector<std::string> > &tableMat) {
13  std::string mthn = "[PixelFEDTestDAC::PixelFEDTestDAC()]\t\t\t ";
14  const unsigned long int UB = 200;
15  const unsigned long int B = 500;
16  const unsigned long int offset = 0;
17  vector<unsigned int> pulseTrain(256), pixelDCol(1), pixelPxl(2), pixelTBMHeader(3), pixelTBMTrailer(3);
18  unsigned int DCol, LorR, start = 15;
20  std::string::size_type loc1, loc2, loc3, loc4;
21  unsigned long int npos = std::string::npos;
22  int i;
23 
24  std::map<std::string, int> colM;
25  std::vector<std::string> colNames;
40  colNames.push_back("CONFIG_KEY");
41  colNames.push_back("KEY_TYPE");
42  colNames.push_back("KEY_ALIAS");
43  colNames.push_back("VERSION");
44  colNames.push_back("KIND_OF_COND");
45  colNames.push_back("CALIB_TYPE");
46  colNames.push_back("CALIB_OBJ_DATA_FILE");
47  colNames.push_back("CALIB_OBJ_DATA_CLOB");
48 
49  for (unsigned int c = 0; c < tableMat[0].size(); c++) {
50  for (unsigned int n = 0; n < colNames.size(); n++) {
51  if (tableMat[0][c] == colNames[n]) {
52  colM[colNames[n]] = c;
53  break;
54  }
55  }
56  } //end for
57  for (unsigned int n = 0; n < colNames.size(); n++) {
58  if (colM.find(colNames[n]) == colM.end()) {
59  std::cerr << __LINE__ << "]\t" << mthn << "Couldn't find in the database the column with name " << colNames[n]
60  << std::endl;
61  assert(0);
62  }
63  }
64 
65  std::istringstream fin;
66  fin.str(tableMat[1][colM["CALIB_OBJ_DATA_CLOB"]]);
67 
68  // Initialise the pulseTrain to offset+black
69  for (unsigned int i = 0; i < pulseTrain.size(); ++i) {
70  pulseTrain[i] = offset + B;
71  }
72 
73  i = start;
74 
75  getline(fin, line);
76  mode_ = line;
77  assert(mode_ == "EmulatedPhysics" || mode_ == "FEDBaselineWithTestDACs" || mode_ == "FEDAddressLevelWithTestDACs");
78 
79  while (!fin.eof()) {
80  getline(fin, line);
81 
82  if (line.find("TBMHeader") != npos) {
83  loc1 = line.find('(');
84  if (loc1 == npos) {
85  cout << __LINE__ << "]\t" << mthn << "'(' not found after TBMHeader.\n";
86  break;
87  }
88  loc2 = line.find(')', loc1 + 1);
89  if (loc2 == npos) {
90  cout << __LINE__ << "]\t" << mthn << "')' not found after TBMHeader.\n";
91  break;
92  }
93  int TBMHeader = atoi(line.substr(loc1 + 1, loc2 - loc1 - 1).c_str());
94 
95  pulseTrain[i] = UB;
96  ++i;
97  pulseTrain[i] = UB;
98  ++i;
99  pulseTrain[i] = UB;
100  ++i;
101  pulseTrain[i] = B;
102  ++i;
103 
104  pixelTBMHeader = decimalToBaseX(TBMHeader, 4, 4);
105 
106  pulseTrain[i] = levelEncoder(pixelTBMHeader[3]);
107  ++i;
108  pulseTrain[i] = levelEncoder(pixelTBMHeader[2]);
109  ++i;
110  pulseTrain[i] = levelEncoder(pixelTBMHeader[1]);
111  ++i;
112  pulseTrain[i] = levelEncoder(pixelTBMHeader[0]);
113  ++i;
114  } else if (line.find("ROCHeader") != std::string::npos) {
115  loc1 = line.find('(');
116  if (loc1 == npos) {
117  cout << __LINE__ << "]\t" << mthn << "'(' not found after ROCHeader.\n";
118  break;
119  }
120  loc2 = line.find(')', loc1 + 1);
121  if (loc2 == npos) {
122  cout << __LINE__ << "]\t" << mthn << "')' not found after ROCHeader.\n";
123  break;
124  }
125  int LastDAC = atoi(line.substr(loc1 + 1, loc2 - loc1 - 1).c_str());
126 
127  std::cout << "--------------" << std::endl;
128 
129  pulseTrain[i] = UB;
130  ++i;
131  pulseTrain[i] = B;
132  ++i;
133  pulseTrain[i] = levelEncoder(LastDAC);
134  ++i;
135  } else if (line.find("PixelHit") != std::string::npos) {
136  loc1 = line.find('(');
137  if (loc1 == npos) {
138  cout << __LINE__ << "]\t" << mthn << "'(' not found after PixelHit.\n";
139  break;
140  }
141  loc2 = line.find(',', loc1 + 1);
142  if (loc2 == npos) {
143  cout << __LINE__ << "]\t" << mthn << "',' not found after the first argument of PixelHit.\n";
144  break;
145  }
146  loc3 = line.find(',', loc2 + 1);
147  if (loc3 == npos) {
148  cout << __LINE__ << "]\t" << mthn << "'.' not found after the second argument of PixelHit.\n";
149  break;
150  }
151  loc4 = line.find(')', loc3 + 1);
152  if (loc4 == npos) {
153  cout << __LINE__ << "]\t" << mthn << "')' not found after the third argument of PixelHit.\n";
154  break;
155  }
156  int column = atoi(line.substr(loc1 + 1, loc2 - loc1 - 1).c_str());
157  int row = atoi(line.substr(loc2 + 1, loc3 - loc2 - 1).c_str());
158  int charge = atoi(line.substr(loc3 + 1, loc4 - loc3 - 1).c_str());
159 
160  DCol = int(column / 2);
161  LorR = int(column - DCol * 2);
162  pixelDCol = decimalToBaseX(DCol, 6, 2);
163  pixelPxl = decimalToBaseX((80 - row) * 2 + LorR, 6, 3);
164 
165  std::cout << "Pxl = " << pixelPxl[2] << pixelPxl[1] << pixelPxl[0] << ", DCol= " << pixelDCol[1] << pixelDCol[0]
166  << std::endl;
167 
168  pulseTrain[i] = levelEncoder(pixelDCol[1]);
169  ++i;
170  pulseTrain[i] = levelEncoder(pixelDCol[0]);
171  ++i;
172  pulseTrain[i] = levelEncoder(pixelPxl[2]);
173  ++i;
174  pulseTrain[i] = levelEncoder(pixelPxl[1]);
175  ++i;
176  pulseTrain[i] = levelEncoder(pixelPxl[0]);
177  ++i;
178  pulseTrain[i] = charge;
179  ++i;
180 
181  } else if (line.find("TBMTrailer") != std::string::npos) {
182  loc1 = line.find('(');
183  if (loc1 == npos) {
184  cout << __LINE__ << "]\t" << mthn << "'(' not found after TBMTrailer.\n";
185  break;
186  }
187  loc2 = line.find(')', loc1 + 1);
188  if (loc2 == npos) {
189  cout << __LINE__ << "]\t" << mthn << "')' not found after TBMTrailer.\n";
190  break;
191  }
192  int TBMTrailer = atoi(line.substr(loc1 + 1, loc2 - loc1 - 1).c_str());
193 
194  pulseTrain[i] = UB;
195  ++i;
196  pulseTrain[i] = UB;
197  ++i;
198  pulseTrain[i] = B;
199  ++i;
200  pulseTrain[i] = B;
201  ++i;
202 
203  pixelTBMTrailer = decimalToBaseX(TBMTrailer, 4, 4);
204  pulseTrain[i] = levelEncoder(pixelTBMTrailer[3]);
205  ++i;
206  pulseTrain[i] = levelEncoder(pixelTBMTrailer[2]);
207  ++i;
208  pulseTrain[i] = levelEncoder(pixelTBMTrailer[1]);
209  ++i;
210  pulseTrain[i] = levelEncoder(pixelTBMTrailer[0]);
211  ++i;
212  }
213  }
214  // fin.close();
215  dacs_ = pulseTrain;
216 }
217 
218 PixelFEDTestDAC::PixelFEDTestDAC(std::string filename) {
219  std::string mthn = "[PixelFEDTestDAC::PixelFEDTestDAC()]\t\t\t\t ";
220  const unsigned long int UB = 200;
221  const unsigned long int B = 500;
222  const unsigned long int offset = 0;
223  vector<unsigned int> pulseTrain(256), pixelDCol(1), pixelPxl(2), pixelTBMHeader(3), pixelTBMTrailer(3);
224  unsigned int DCol, LorR, start = 15;
226  std::string::size_type loc1, loc2, loc3, loc4;
227  unsigned long int npos = std::string::npos;
228  int i;
229 
230  // Initialise the pulseTrain to offset+black
231  for (unsigned int i = 0; i < pulseTrain.size(); ++i) {
232  pulseTrain[i] = offset + B;
233  }
234 
235  ifstream fin(filename.c_str());
236 
237  i = start;
238 
239  getline(fin, line);
240  mode_ = line;
241  assert(mode_ == "EmulatedPhysics" || mode_ == "FEDBaselineWithTestDACs" || mode_ == "FEDAddressLevelWithTestDACs");
242 
243  while (!fin.eof()) {
244  getline(fin, line);
245 
246  if (line.find("TBMHeader") != npos) {
247  loc1 = line.find('(');
248  if (loc1 == npos) {
249  cout << __LINE__ << "]\t" << mthn << "'(' not found after TBMHeader.\n";
250  break;
251  }
252  loc2 = line.find(')', loc1 + 1);
253  if (loc2 == npos) {
254  cout << __LINE__ << "]\t" << mthn << "')' not found after TBMHeader.\n";
255  break;
256  }
257  int TBMHeader = atoi(line.substr(loc1 + 1, loc2 - loc1 - 1).c_str());
258 
259  pulseTrain[i] = UB;
260  ++i;
261  pulseTrain[i] = UB;
262  ++i;
263  pulseTrain[i] = UB;
264  ++i;
265  pulseTrain[i] = B;
266  ++i;
267 
268  pixelTBMHeader = decimalToBaseX(TBMHeader, 4, 4);
269 
270  pulseTrain[i] = levelEncoder(pixelTBMHeader[3]);
271  ++i;
272  pulseTrain[i] = levelEncoder(pixelTBMHeader[2]);
273  ++i;
274  pulseTrain[i] = levelEncoder(pixelTBMHeader[1]);
275  ++i;
276  pulseTrain[i] = levelEncoder(pixelTBMHeader[0]);
277  ++i;
278  } else if (line.find("ROCHeader") != std::string::npos) {
279  loc1 = line.find('(');
280  if (loc1 == npos) {
281  cout << __LINE__ << "]\t" << mthn << "'(' not found after ROCHeader.\n";
282  break;
283  }
284  loc2 = line.find(')', loc1 + 1);
285  if (loc2 == npos) {
286  cout << __LINE__ << "]\t" << mthn << "')' not found after ROCHeader.\n";
287  break;
288  }
289  int LastDAC = atoi(line.substr(loc1 + 1, loc2 - loc1 - 1).c_str());
290 
291  std::cout << "--------------" << std::endl;
292 
293  pulseTrain[i] = UB;
294  ++i;
295  pulseTrain[i] = B;
296  ++i;
297  pulseTrain[i] = levelEncoder(LastDAC);
298  ++i;
299  } else if (line.find("PixelHit") != std::string::npos) {
300  loc1 = line.find('(');
301  if (loc1 == npos) {
302  cout << __LINE__ << "]\t" << mthn << "'(' not found after PixelHit.\n";
303  break;
304  }
305  loc2 = line.find(',', loc1 + 1);
306  if (loc2 == npos) {
307  cout << __LINE__ << "]\t" << mthn << "',' not found after the first argument of PixelHit.\n";
308  break;
309  }
310  loc3 = line.find(',', loc2 + 1);
311  if (loc3 == npos) {
312  cout << __LINE__ << "]\t" << mthn << "'.' not found after the second argument of PixelHit.\n";
313  break;
314  }
315  loc4 = line.find(')', loc3 + 1);
316  if (loc4 == npos) {
317  cout << __LINE__ << "]\t" << mthn << "')' not found after the third argument of PixelHit.\n";
318  break;
319  }
320  int column = atoi(line.substr(loc1 + 1, loc2 - loc1 - 1).c_str());
321  int row = atoi(line.substr(loc2 + 1, loc3 - loc2 - 1).c_str());
322  int charge = atoi(line.substr(loc3 + 1, loc4 - loc3 - 1).c_str());
323 
324  DCol = int(column / 2);
325  LorR = int(column - DCol * 2);
326  pixelDCol = decimalToBaseX(DCol, 6, 2);
327  pixelPxl = decimalToBaseX((80 - row) * 2 + LorR, 6, 3);
328 
329  std::cout << "Pxl = " << pixelPxl[2] << pixelPxl[1] << pixelPxl[0] << ", DCol= " << pixelDCol[1] << pixelDCol[0]
330  << std::endl;
331 
332  pulseTrain[i] = levelEncoder(pixelDCol[1]);
333  ++i;
334  pulseTrain[i] = levelEncoder(pixelDCol[0]);
335  ++i;
336  pulseTrain[i] = levelEncoder(pixelPxl[2]);
337  ++i;
338  pulseTrain[i] = levelEncoder(pixelPxl[1]);
339  ++i;
340  pulseTrain[i] = levelEncoder(pixelPxl[0]);
341  ++i;
342  pulseTrain[i] = charge;
343  ++i;
344 
345  } else if (line.find("TBMTrailer") != std::string::npos) {
346  loc1 = line.find('(');
347  if (loc1 == npos) {
348  cout << __LINE__ << "]\t" << mthn << "'(' not found after TBMTrailer.\n";
349  break;
350  }
351  loc2 = line.find(')', loc1 + 1);
352  if (loc2 == npos) {
353  cout << __LINE__ << "]\t" << mthn << "')' not found after TBMTrailer.\n";
354  break;
355  }
356  int TBMTrailer = atoi(line.substr(loc1 + 1, loc2 - loc1 - 1).c_str());
357 
358  pulseTrain[i] = UB;
359  ++i;
360  pulseTrain[i] = UB;
361  ++i;
362  pulseTrain[i] = B;
363  ++i;
364  pulseTrain[i] = B;
365  ++i;
366 
367  pixelTBMTrailer = decimalToBaseX(TBMTrailer, 4, 4);
368  pulseTrain[i] = levelEncoder(pixelTBMTrailer[3]);
369  ++i;
370  pulseTrain[i] = levelEncoder(pixelTBMTrailer[2]);
371  ++i;
372  pulseTrain[i] = levelEncoder(pixelTBMTrailer[1]);
373  ++i;
374  pulseTrain[i] = levelEncoder(pixelTBMTrailer[0]);
375  ++i;
376  }
377  }
378  fin.close();
379  dacs_ = pulseTrain;
380 }
381 
382 unsigned int PixelFEDTestDAC::levelEncoder(int level) {
383  unsigned int pulse;
384 
385  switch (level) {
386  case 0:
387  pulse = 450;
388  break;
389  case 1:
390  pulse = 500;
391  break;
392  case 2:
393  pulse = 550;
394  break;
395  case 3:
396  pulse = 600;
397  break;
398  case 4:
399  pulse = 650;
400  break;
401  case 5:
402  pulse = 700;
403  break;
404  default:
405  assert(0);
406  break;
407  }
408 
409  return pulse;
410 }
411 
412 vector<unsigned int> PixelFEDTestDAC::decimalToBaseX(unsigned int a, unsigned int x, unsigned int length) {
413  vector<unsigned int> ans(100, 0);
414  int i = 0;
415 
416  while (a > 0) {
417  ans[i] = a % x;
418  //ans.push_back(a%x);
419  a = a / x;
420  i += 1;
421  }
422 
423  if (length > 0)
424  ans.resize(length);
425  else
426  ans.resize(i);
427 
428  return ans;
429 }
430 
431 //=============================================================================================
432 void PixelFEDTestDAC::writeXMLHeader(pos::PixelConfigKey key,
433  int version,
435  std::ofstream *outstream,
436  std::ofstream *out1stream,
437  std::ofstream *out2stream) const {
438  std::string mthn = "[PixelFEDTestDAC::writeXMLHeader()]\t\t\t ";
439  std::stringstream maskFullPath;
440 
441  // writeASCII(path) ;
442 
443  maskFullPath << path << "/PixelCalib_Test_" << PixelTimeFormatter::getmSecTime() << ".xml";
444  std::cout << __LINE__ << "]\t" << mthn << "Writing to: " << maskFullPath.str() << std::endl;
445 
446  outstream->open(maskFullPath.str().c_str());
447 
448  *outstream << "<?xml version='1.0' encoding='UTF-8' standalone='yes'?>" << std::endl;
449  *outstream << "<ROOT xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>" << std::endl;
450  *outstream << "" << std::endl;
451  *outstream << " <HEADER>" << std::endl;
452  *outstream << " <TYPE>" << std::endl;
453  *outstream << " <EXTENSION_TABLE_NAME>PIXEL_CALIB_CLOB</EXTENSION_TABLE_NAME>" << std::endl;
454  *outstream << " <NAME>Calibration Object Clob</NAME>" << std::endl;
455  *outstream << " </TYPE>" << std::endl;
456  *outstream << " <RUN>" << std::endl;
457  *outstream << " <RUN_TYPE>PixelFEDTestDAC</RUN_TYPE>" << std::endl;
458  *outstream << " <RUN_NUMBER>1</RUN_NUMBER>" << std::endl;
459  *outstream << " <RUN_BEGIN_TIMESTAMP>" << PixelTimeFormatter::getTime() << "</RUN_BEGIN_TIMESTAMP>" << std::endl;
460  *outstream << " <LOCATION>CERN P5</LOCATION>" << std::endl;
461  *outstream << " </RUN>" << std::endl;
462  *outstream << " </HEADER>" << std::endl;
463  *outstream << "" << std::endl;
464  *outstream << " <DATA_SET>" << std::endl;
465  *outstream << "" << std::endl;
466  *outstream << " <VERSION>" << version << "</VERSION>" << std::endl;
467  *outstream << " <COMMENT_DESCRIPTION>No comment defined: this class does NOT inherit from "
468  "PixelCalibBase</COMMENT_DESCRIPTION>"
469  << std::endl;
470  *outstream << " <CREATED_BY_USER>Unknown user</CREATED_BY_USER>" << std::endl;
471  *outstream << "" << std::endl;
472  *outstream << " <PART>" << std::endl;
473  *outstream << " <NAME_LABEL>CMS-PIXEL-ROOT</NAME_LABEL>" << std::endl;
474  *outstream << " <KIND_OF_PART>Detector ROOT</KIND_OF_PART>" << std::endl;
475  *outstream << " </PART>" << std::endl;
476 }
477 
478 //=============================================================================================
479 void PixelFEDTestDAC::writeXML(std::ofstream *outstream, std::ofstream *out1stream, std::ofstream *out2stream) const {
480  std::string mthn = "[PixelFEDTestDAC::writeXML()]\t\t\t ";
481 
482  *outstream << " " << std::endl;
483  *outstream << " <DATA>" << std::endl;
484  *outstream << " <CALIB_OBJ_DATA_FILE>./fedtestdac.dat</CALIB_OBJ_DATA_FILE>" << std::endl;
485  *outstream << " <CALIB_TYPE>fedtestdac</CALIB_TYPE>" << std::endl;
486  *outstream << " </DATA>" << std::endl;
487  *outstream << " " << std::endl;
488 }
489 
490 //=============================================================================================
491 void PixelFEDTestDAC::writeXMLTrailer(std::ofstream *outstream,
492  std::ofstream *out1stream,
493  std::ofstream *out2stream) const {
494  std::string mthn = "[PixelFEDTestDAC::writeXMLTrailer()]\t\t\t ";
495 
496  *outstream << " </DATA_SET>" << std::endl;
497  *outstream << "</ROOT>" << std::endl;
498 
499  outstream->close();
500  std::cout << __LINE__ << "]\t" << mthn << "Data written " << std::endl;
501 }
Definition: start.py:1
Definition: APVGainStruct.h:7
assert(be >=bs)
uint16_t size_type
This class provides utility methods to manipulate ASCII formatted timestamps.
key
prepare the HTCondor submission files and eventually submit them
This class implements..
double pulse(double x, double y, double z, double t)
double a
Definition: hdecay.h:121
float x
This class implements..