CMS 3D CMS Logo

PixelDACSettings.cc
Go to the documentation of this file.
1 //
2 // This class provide a base class for the
3 // pixel ROC DAC data for the pixel FEC configuration
4 //
5 //
6 //
7 //
8 
9 
14 #include <fstream>
15 #include <iostream>
16 #include <ios>
17 #include <cassert>
18 #include <stdexcept>
19 #include <map>
20 #include <sstream>
21 #include <sys/time.h>
22 #include <cstdlib>
23 
24 using namespace pos;
25 
26 namespace {
27  const bool readTemperatures = false;
28  //const bool readTemperatures = true;
29  //const int temperatureReg = 0x9; // hardwire to fixed reference voltage 0x8 + 0x1
30  const int temperatureReg = 0x1; // hardwire to the usefull range, change to range 1, Marco's request, 25/10/11
31 }
32 
34  PixelConfigBase("","",""){
35 
36  std::string mthn = "[PixelDACSettings::PixelDACSettings()]\t\t\t " ;
37 
38  if (filename[filename.size()-1]=='t'){
39 
40  std::ifstream in(filename.c_str());
41 
42  if (!in.good()){
43  std::cout << __LINE__ << "]\t" << mthn << "Could not open: " << filename << std::endl;
44  // assert(0); //in case of failure, we don't want POS to die here
45  throw std::runtime_error("Failed to open file "+filename);
46  }
47  else {
48  // std::cout << "Opened:"<<filename<<std::endl;
49  }
50 
51 
52  dacsettings_.clear();
53 
55 
56  in >> tag;
57 
58  while (!in.eof()){
59 
60 
61  PixelROCName rocid(in);
62 
63  // std::cout << "[PixelDACSettings::PixelDACSettings()] DAC setting ROC id:"<<rocid<<std::endl;
64 
66 
67  tmp.read(in,rocid);
68 
69  // std::cout << "[PixelDACSettings::PixelDACSettings()] DACSetting: " << std::endl << tmp << std::endl ;
70  dacsettings_.push_back(tmp);
71 
72  in >> tag;
73 
74  assert(dacsettings_.size()<100);
75 
76  }
77 
78  in.close();
79 
80  }
81  else{
82 
83  std::ifstream in(filename.c_str(),std::ios::binary);
84 
85  if (!in.good()){
86  std::cout << __LINE__ << "]\t" << mthn << "Could not open: " << filename << std::endl;
87  assert(0);
88  }
89  else {
90  std::cout << __LINE__ << "]\t" << mthn << "Opened: " << filename << std::endl;
91  }
92 
93  char nchar;
94 
95  in.read(&nchar,1);
96 
97  std::string s1;
98 
99  //wrote these lines of code without ref. needs to be fixed
100  for(int i=0;i< nchar; i++){
101  char c;
102  in >>c;
103  s1.push_back(c);
104  }
105 
106  //std::cout << __LINE__ << "]\t" << mthn << "READ ROC name: " << s1 << std::endl;
107 
108  dacsettings_.clear();
109 
110 
111  while (!in.eof()){
112 
113  //std::cout << __LINE__ << "]\t" << mthn << "read s1 : " << s1 << std::endl;
114 
115  PixelROCName rocid(s1);
116 
117  //std::cout << __LINE__ << "]\t" << mthn << "read rocid: " << rocid << std::endl;
118 
120 
121  tmp.readBinary(in, rocid);
122 
123  dacsettings_.push_back(tmp);
124 
125 
126  in.read(&nchar,1);
127 
128  s1.clear();
129 
130  if (in.eof()) continue;
131 
132  //wrote these lines of code without ref. needs to be fixed
133  for(int i=0;i< nchar; i++){
134  char c;
135  in >>c;
136  s1.push_back(c);
137  }
138 
139 
140  }
141 
142  in.close();
143 
144 
145 
146  }
147 
148 
149  //std::cout << __LINE__ << "]\t" << mthn << "Read dac settings for "<<dacsettings_.size()<<" ROCs"<<std::endl;
150 
151 
152 }
153 // modified by MR on 10-01-2008 14:48:19
155  PixelConfigBase("","","") {
156  dacsettings_.push_back(rocname) ;
157 
158 }
159 
160 // modified by MR on 24-01-2008 14:27:35a
162 {
163  dacsettings_.push_back(rocname) ;
164 
165 }
166 
167 
168 PixelDACSettings::PixelDACSettings(std::vector< std::vector<std::string> > &tableMat): PixelConfigBase("","","")
169 {
170 
171 
172 
173 /*
174  EXTENSION_TABLE_NAME: ROC_DAC_SETTINGS_COL (VIEW: CONF_KEY_ROCDAC_COL_V)
175 
176  CONFIG_KEY NOT NULL VARCHAR2(80)
177  KEY_TYPE NOT NULL VARCHAR2(80)
178  KEY_ALIAS NOT NULL VARCHAR2(80)
179  VERSION VARCHAR2(40)
180  KIND_OF_COND NOT NULL VARCHAR2(40)
181  ROC_NAME VARCHAR2(200)
182  VDD NOT NULL NUMBER(38)
183  VANA NOT NULL NUMBER(38)
184  VSF NOT NULL NUMBER(38)
185  VCOMP NOT NULL NUMBER(38)
186  VLEAK NOT NULL NUMBER(38)
187  VRGPR NOT NULL NUMBER(38)
188  VWLLPR NOT NULL NUMBER(38)
189  VRGSH NOT NULL NUMBER(38)
190  VWLLSH NOT NULL NUMBER(38)
191  VHLDDEL NOT NULL NUMBER(38)
192  VTRIM NOT NULL NUMBER(38)
193  VCTHR NOT NULL NUMBER(38)
194  VIBIAS_BUS NOT NULL NUMBER(38)
195  VIBIAS_SF NOT NULL NUMBER(38)
196  VOFFSETOP NOT NULL NUMBER(38)
197  VBIASOP NOT NULL NUMBER(38)
198  VOFFSETRO NOT NULL NUMBER(38)
199  VION NOT NULL NUMBER(38)
200  VIBIAS_PH NOT NULL NUMBER(38)
201  VIBIAS_DAC NOT NULL NUMBER(38)
202  VIBIAS_ROC NOT NULL NUMBER(38)
203  VICOLOR NOT NULL NUMBER(38)
204  VNPIX NOT NULL NUMBER(38)
205  VSUMCOL NOT NULL NUMBER(38)
206  VCAL NOT NULL NUMBER(38)
207  CALDEL NOT NULL NUMBER(38)
208  TEMPRANGE NOT NULL NUMBER(38)
209  WBC NOT NULL NUMBER(38)
210  CHIPCONTREG NOT NULL NUMBER(38)
211 */
212 // std::multimap<std::string,std::pair<std::string,int > > pDSM;
213  // std::stringstream currentRocName;
214  std::vector< std::string > ins = tableMat[0];
215  std::string mthn("[PixelDACSettings::PixelDACSettings()] ") ;
216  std::string dacName;
217  std::istringstream dbin ;
218 // int dacValue;
219  int skipColumns = 0 ;
220  std::map<std::string , int > colM;
221  std::vector<std::string > colNames;
222  std::map<std::string, std::string> nameTranslation ;
223 
224  colNames.push_back("CONFIG_KEY" );
225  colNames.push_back("KEY_TYPE" );
226  colNames.push_back("KEY_ALIAS" );
227  colNames.push_back("VERSION" );
228  colNames.push_back("KIND_OF_COND");
229  colNames.push_back("ROC_NAME" );
230  colNames.push_back("VDD" );
231  colNames.push_back("VANA" );
232  colNames.push_back("VSF" );
233  colNames.push_back("VCOMP" );
234  colNames.push_back("VLEAK" );
235  colNames.push_back("VRGPR" );
236  colNames.push_back("VWLLPR" );
237  colNames.push_back("VRGSH" );
238  colNames.push_back("VWLLSH" );
239  colNames.push_back("VHLDDEL" );
240  colNames.push_back("VTRIM" );
241  colNames.push_back("VCTHR" );
242  colNames.push_back("VIBIAS_BUS" );
243  colNames.push_back("VIBIAS_SF" );
244  colNames.push_back("VOFFSETOP" );
245  colNames.push_back("VBIASOP" );
246  colNames.push_back("VOFFSETRO" );
247  colNames.push_back("VION" );
248  colNames.push_back("VIBIAS_PH" );
249  colNames.push_back("VIBIAS_DAC" );
250  colNames.push_back("VIBIAS_ROC" );
251  colNames.push_back("VICOLOR" );
252  colNames.push_back("VNPIX" );
253  colNames.push_back("VSUMCOL" );
254  colNames.push_back("VCAL" );
255  colNames.push_back("CALDEL" );
256  colNames.push_back("TEMPRANGE" );
257  colNames.push_back("WBC" );
258  colNames.push_back("CHIPCONTREG" );
259 
260  nameTranslation["VDD"] = k_DACName_Vdd ;
261  nameTranslation["VANA"] = k_DACName_Vana;
262  nameTranslation["VSF"] = k_DACName_Vsf;
263  nameTranslation["VCOMP"] = k_DACName_Vcomp;
264  nameTranslation["VLEAK"] = k_DACName_Vleak;
265  nameTranslation["VRGPR"] = k_DACName_VrgPr;
266  nameTranslation["VWLLPR"] = k_DACName_VwllPr;
267  nameTranslation["VRGSH"] = k_DACName_VrgSh;
268  nameTranslation["VWLLSH"] = k_DACName_VwllSh;
269  nameTranslation["VHLDDEL"] = k_DACName_VHldDel;
270  nameTranslation["VTRIM"] = k_DACName_Vtrim;
271  nameTranslation["VCTHR"] = k_DACName_VcThr;
272  nameTranslation["VIBIAS_BUS"] = k_DACName_VIbias_bus;
273  nameTranslation["VIBIAS_SF"] = k_DACName_VIbias_sf;
274  nameTranslation["VOFFSETOP"] = k_DACName_VOffsetOp;
275  nameTranslation["VBIASOP"] = k_DACName_VbiasOp;
276  nameTranslation["VOFFSETRO"] = k_DACName_VOffsetRO;
277  nameTranslation["VION"] = k_DACName_VIon;
278  nameTranslation["VIBIAS_PH"] = k_DACName_VIbias_PH;
279  nameTranslation["VIBIAS_DAC"] = k_DACName_VIbias_DAC;
280  nameTranslation["VIBIAS_ROC"] = k_DACName_VIbias_roc;
281  nameTranslation["VICOLOR"] = k_DACName_VIColOr;
282  nameTranslation["VNPIX"] = k_DACName_Vnpix;
283  nameTranslation["VSUMCOL"] = k_DACName_VsumCol;
284  nameTranslation["VCAL"] = k_DACName_Vcal;
285  nameTranslation["CALDEL"] = k_DACName_CalDel;
286  nameTranslation["TEMPRANGE"] = k_DACName_TempRange;
287  nameTranslation["WBC"] = k_DACName_WBC;
288  nameTranslation["CHIPCONTREG"] = k_DACName_ChipContReg;
289 
290  // modified by MR on 25-02-2008 10:00:45
291  // colM stores the index (referred to tableMat) where the specified dac setting is store!!!
292  for(unsigned int c = skipColumns ; c < ins.size() ; c++){
293  for(unsigned int n=0; n<colNames.size(); n++){
294  if(tableMat[0][c] == colNames[n]){
295  colM[colNames[n]] = c;
296  break;
297  }
298  }
299  }//end for
300  for(unsigned int n=skipColumns; n<colNames.size(); n++){
301  if(colM.find(colNames[n]) == colM.end()){
302  std::cerr << "[PixelDACSettings::PixelDACSettings()]\tCouldn't find in the database the column with name " << colNames[n] << std::endl;
303  assert(0);
304  }
305  }
306 
307 
308  dacsettings_.clear();
309 // struct timeval start_time ;
310 // struct timeval end_time ;
311 // gettimeofday(&start_time, (struct timezone *)0 );
312  for(unsigned int r = 1 ; r < tableMat.size() ; r++){ //Goes to every row of the Matrix
313  // currentRocName.str("");
314  // currentRocName << tableMat[r][colM["NAME"]] ;
315  //currentRocName << "FPix_BmI_D" << tableMat[r][colM["HDISK_POSN"]]
316  // << "_BLD" << tableMat[r][colM["BLD_POSN"]]
317  // << "_PNL" << tableMat[r][colM["PANEL_POSITION"]]
318  // << "_PLQ" << tableMat[r][colM["PLAQ_POS"]]
319  // << "_ROC" << tableMat[r][colM["ROC_POSN"]];
320 
321  // modified by MR on 25-02-2008 10:04:55
322  PixelROCName rocid(tableMat[r][colM["ROC_NAME"]]);
323  PixelROCDACSettings tmp(rocid);
324  std::ostringstream dacs("") ;
325  // +6 to get rid of the first 5 columns not pertaining DAC Settings...
326  for(unsigned int n=skipColumns+6; n<colNames.size(); n++)
327  {
328  dacs << nameTranslation[colNames[n]] <<": "<< atoi(tableMat[r][colM[colNames[n]]].c_str()) << std::endl ;
329  // dacName = colNames[n];
330  // dacValue = atoi(tableMat[r][colM[colNames[n]]].c_str());
331  // pDSM.insert(std::pair<std::string,std::pair<std::string,int> >(tableMat[r][colM["ROC_NAME"]],std::pair<std::string,int>(dacName,dacValue)));
332  // std::cout << "On " << tableMat[r][colM["ROC_NAME"]] << " DAC:\t" << dacName << " value:\t" << dacValue<< std::endl ;
333  // tmp.setDac(dacName, dacValue) ;
334  }
335 // tmp.setDACs(tmpDACs) ;
336  dbin.str(dacs.str()) ;
337  tmp.read(dbin, rocid) ;
338  dacsettings_.push_back(tmp) ;
339  }//end for r
340 // gettimeofday(&end_time, (struct timezone *)0 );
341 // int total_usecs = (end_time.tv_sec - start_time.tv_sec)*1000000 + (end_time.tv_usec - start_time.tv_usec);
342 // std::cout << mthn << "Time taken : " << total_usecs / 1000000. << " secs" << std::endl;
343 
344 // dacsettings_.clear();
345 // std::string currentRocName2 = "";
346 // for(std::multimap<std::string,std::pair<std::string,int> >::iterator tableMapIt=pDSM.begin(); tableMapIt!= pDSM.end(); tableMapIt++){
347 // if(currentRocName2 != tableMapIt->first){
348 // std::cout << tableMapIt->first << std::endl;
349 // std::cout << tableMapIt->second.first << std::endl;
350 // std::cout << tableMapIt->second.second << std::endl;
351 // currentRocName2 = tableMapIt->first;
352 // PixelROCName rocid(currentRocName2);
353 
354 // // std::cout << "DAC setting ROC id:"<<rocid<<std::endl;
355 
356 // PixelROCDACSettings tmp(rocid);
357 
358 // // tmp.read(in,rocid);
359 
360 // dacsettings_.push_back(tmp);
361 // }//end if
362 // dacsettings_[dacsettings_.size()-1].setDac(tableMapIt->second.first,tableMapIt->second.second);
363 // }//end for
364 
365 
366 // for(unsigned int w = 0 ; w < dacsettings_.size() ; w++)
367 // {
368 
369 // PixelROCDACSettings tmp2 = dacsettings_[w];
370 // // std::cout<<tmp2<<std::endl;
371 // }
372  // std::cout<<"Number of ROCs in the PixelDACSettings::PixelDACSettings(vector <vector<string> >):"<<dacsettings_.size()<<std::endl;
373  // std::cout << "[PixelDACSettings::PixelDACSettings(std::vector)] before end of constructor" << std::endl ;
374 }//end PDSMatrix constructor
375 //end added by Umesh
376 
378 
379  return dacsettings_[ROCId];
380 
381 }
382 
384 
385 
386  for(unsigned int i=0;i<dacsettings_.size();i++){
387  if (dacsettings_[i].getROCName()==name) return &(dacsettings_[i]);
388  }
389 
390  return nullptr;
391 
392 }
393 
395 
396  std::ofstream out(filename.c_str(),std::ios::binary);
397 
398  for(unsigned int i=0;i<dacsettings_.size();i++){
399  dacsettings_[i].writeBinary(out);
400  }
401 
402 }
403 
404 
406 
407  std::string mthn = "[PixelDACSettings::writeASCII()]\t\t\t " ;
408  PixelModuleName module(dacsettings_[0].getROCName().rocname());
409 
410  std::string filename=dir+"/ROC_DAC_module_"+module.modulename()+".dat";
411  std::cout << __LINE__ << "]\t" << mthn << "Writing to file " << filename << std::endl ;
412  std::ofstream out(filename.c_str());
413 
414  for(unsigned int i=0;i<dacsettings_.size();i++){
415  dacsettings_[i].writeASCII(out);
416  }
417 
418 }
419 
420 //=============================================================================================
422  int version,
423  std::string path,
424  std::ofstream *outstream,
425  std::ofstream *out1stream,
426  std::ofstream *out2stream) const {
427  std::string mthn = "[PixelDACSettings::writeXMLHeader()]\t\t\t " ;
428  std::stringstream fullPath ;
429 
430  fullPath << path << "/Pixel_RocDacSettings_" << PixelTimeFormatter::getmSecTime() << ".xml" ;
431  std::cout << __LINE__ << "]\t" << mthn << "Writing to: " << fullPath.str() << std::endl ;
432 
433  outstream->open(fullPath.str().c_str()) ;
434 
435  *outstream << "<?xml version='1.0' encoding='UTF-8' standalone='yes'?>" << std::endl ;
436  *outstream << "<ROOT xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>" << std::endl ;
437  *outstream << "" << std::endl ;
438  *outstream << " <!-- " << mthn << "-->" << std::endl ;
439  *outstream << "" << std::endl ;
440  *outstream << " <HEADER>" << std::endl ;
441  *outstream << " <TYPE>" << std::endl ;
442  *outstream << " <EXTENSION_TABLE_NAME>ROC_DAC_SETTINGS_COL</EXTENSION_TABLE_NAME>" << std::endl ;
443  *outstream << " <NAME>ROC DAC Settings Col</NAME>" << std::endl ;
444  *outstream << " </TYPE>" << std::endl ;
445  *outstream << " <RUN>" << std::endl ;
446  *outstream << " <RUN_TYPE>ROC DAC Settings</RUN_TYPE>" << std::endl ;
447  *outstream << " <RUN_NUMBER>1</RUN_NUMBER>" << std::endl ;
448  *outstream << " <RUN_BEGIN_TIMESTAMP>" << PixelTimeFormatter::getTime() << "</RUN_BEGIN_TIMESTAMP>" << std::endl ;
449  *outstream << " <LOCATION>CERN P5</LOCATION>" << std::endl ;
450  *outstream << " </RUN>" << std::endl ;
451  *outstream << " </HEADER>" << std::endl ;
452  *outstream << "" << std::endl ;
453  *outstream << " <DATA_SET>" << std::endl ;
454  *outstream << " <VERSION>" << version << "</VERSION>" << std::endl ;
455  *outstream << " <COMMENT_DESCRIPTION>" << getComment() << "</COMMENT_DESCRIPTION>" << std::endl ;
456  *outstream << " <CREATED_BY_USER>" << getAuthor() << "</CREATED_BY_USER>" << std::endl ;
457  *outstream << " " << std::endl ;
458  *outstream << " <PART>" << std::endl ;
459  *outstream << " <NAME_LABEL>CMS-PIXEL-ROOT</NAME_LABEL>" << std::endl ;
460  *outstream << " <KIND_OF_PART>Detector ROOT</KIND_OF_PART>" << std::endl ;
461  *outstream << " </PART>" << std::endl ;
462  *outstream << " " << std::endl ;
463 
464  std::cout << __LINE__ << "]\t" << mthn << "Header written" << std::endl ;
465 }
466 
467 //=============================================================================================
468 void PixelDACSettings::writeXML( std::ofstream *outstream,
469  std::ofstream *out1stream,
470  std::ofstream *out2stream) const {
471  std::string mthn = "[PixelDACSettings::writeXML()]\t\t\t " ;
472 
473  for(unsigned int i=0;i<dacsettings_.size();i++){
474  dacsettings_[i].writeXML(outstream);
475  }
476 }
477 
478 //=============================================================================================
479 void PixelDACSettings::writeXMLTrailer(std::ofstream *outstream,
480  std::ofstream *out1stream,
481  std::ofstream *out2stream) const {
482  std::string mthn = "[PixelDACSettings::writeXMLTrailer()]\t\t\t " ;
483 
484  *outstream << " </DATA_SET>" << std::endl ;
485  *outstream << "</ROOT>" << std::endl ;
486 
487  outstream->close() ;
488  std::cout << __LINE__ << "]\t" << mthn << "Data written" << std::endl ;
489 }
490 
491 /* O B S O L E T E -----
492 
493 //=============================================================================================
494 void PixelDACSettings::writeXML(pos::PixelConfigKey key, int version, std::string path) const {
495  std::string mthn = "[PixelDACSettings::writeXML()]\t\t\t " ;
496  std::stringstream fullPath ;
497 
498  PixelModuleName module(dacsettings_[0].getROCName().rocname());
499  fullPath << path << "/dacsettings_" << module.modulename() << ".xml" ;
500  std::cout << mthn << "Writing to: |" << fullPath.str() << "|" << std::endl ;
501 
502 
503  std::ofstream outstream(fullPath.str().c_str()) ;
504 
505  out << "<?xml version='1.0' encoding='UTF-8' standalone='yes'?>" << std::endl ;
506  out << "<ROOT xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>" << std::endl ;
507  out << " <HEADER>" << std::endl ;
508  out << " <TYPE>" << std::endl ;
509  out << " <EXTENSION_TABLE_NAME>ROC_DAC_SETTINGS_COL</EXTENSION_TABLE_NAME>" << std::endl ;
510  out << " <NAME>ROC DAC Settings Col</NAME>" << std::endl ;
511  out << " </TYPE>" << std::endl ;
512  out << " <RUN>" << std::endl ;
513  out << " <RUN_TYPE>test</RUN_TYPE>" << std::endl ;
514  out << " <RUN_NUMBER>1</RUN_NUMBER>" << std::endl ;
515  out << " <RUN_BEGIN_TIMESTAMP>" << PixelTimeFormatter::getTime() << "</RUN_BEGIN_TIMESTAMP>" << std::endl ;
516  out << " <COMMENT_DESCRIPTION>Test of DAC Settings xml</COMMENT_DESCRIPTION>" << std::endl ;
517  out << " <LOCATION>CERN TAC</LOCATION>" << std::endl ;
518  out << " <CREATED_BY_USER>Dario Menasce</CREATED_BY_USER>" << std::endl ;
519  out << " </RUN>" << std::endl ;
520  out << " </HEADER>" << std::endl ;
521  out << "" << std::endl ;
522  out << " <DATA_SET>" << std::endl ;
523  out << " <VERSION>" << version << "</VERSION>" << std::endl ;
524  out << " " << std::endl ;
525  out << " <PART>" << std::endl ;
526  out << " <NAME_LABEL>CMS-PIXEL-ROOT</NAME_LABEL>" << std::endl ;
527  out << " <KIND_OF_PART>Detector ROOT</KIND_OF_PART>" << std::endl ;
528  out << " </PART>" << std::endl ;
529  out << " " << std::endl ;
530 
531  for(unsigned int i=0;i<dacsettings_.size();i++){
532 // dacsettings_[i].writeXML(out, key, version, path);
533  }
534 
535  out << " </DATA_SET>" << std::endl ;
536  out << "</ROOT>" << std::endl ;
537 
538  out.close() ;
539  std::cout << mthn << "Data written" << std::endl ;
540 }
541 */
542 
543 //=============================================================================================
545  PixelNameTranslation* trans, PixelDetectorConfig* detconfig, bool HVon) const{
546 
547  bool bufferData=true;
548 
549  std::vector<unsigned int> dacs;
550 
551  //pixelFEC->fecDebug(1); //FIXME someday maybe don't want to take the time
552 
553  for(unsigned int i=0;i<dacsettings_.size();i++){ // loop over ROCs
554 
555  bool disableRoc = rocIsDisabled(detconfig, dacsettings_[i].getROCName());
556 
557  dacsettings_[i].getDACs(dacs);
558 
559  PixelHdwAddress theROC=*(trans->getHdwAddress(dacsettings_[i].getROCName()));
560 
561  //Need to set readout speed (40MHz) and Vcal range (0-1800 mV) and enable the chip
562 
563 
564 
565  // This is not needed. The ControlReg is programmed in setAllDAC(). d.k. 21.01.11
566 // pixelFEC->progdac(theROC.mfec(),
567 // theROC.mfecchannel(),
568 // theROC.hubaddress(),
569 // theROC.portaddress(),
570 // theROC.rocid(),
571 // 0xfd,
572 // controlreg,
573 // bufferData);
574 
575  if (!HVon || disableRoc) dacs[11]=0; //set Vcthr DAC to 0 (Vcthr is DAC 12=11+1)
576  // std::cout<<" ; setting VcThr to "<<dacs[11]<<std::endl; //for debugging
577  pixelFEC->setAllDAC(theROC,dacs,bufferData);
578 
579  // start with no pixels on for calibration
580  pixelFEC->clrcal(theROC.mfec(),
581  theROC.mfecchannel(),
582  theROC.hubaddress(),
583  theROC.portaddress(),
584  theROC.rocid(),
585  bufferData);
586 
587  const bool kmeKLUDGE=false;
588  if(kmeKLUDGE) //enable one pixel per ROC for calibration (all the time!)
589  {
590  unsigned int col=0;
591  //for(unsigned int col=0;col<52;col+=50) //try 0, 50
592  {
593  pixelFEC->calpix(theROC.mfec(),
594  theROC.mfecchannel(),
595  theROC.hubaddress(),
596  theROC.portaddress(),
597  theROC.rocid(),
598  col, //column
599  0, //row
600  1, //caldata
601  bufferData);
602  }
603  }
604 
605  // enable all the double columns
606  for(int dcol=0;dcol<26;dcol++){
607  pixelFEC->dcolenable(theROC.mfec(),
608  theROC.mfecchannel(),
609  theROC.hubaddress(),
610  theROC.portaddress(),
611  theROC.rocid(),
612  dcol,
613  1,
614  bufferData);
615  }
616 
617  if (!HVon || disableRoc) { //HV off
618  int controlreg=dacsettings_[i].getControlRegister();
619  // std::cout << "[PixelDACSettings::generateConfiguration] HV off! ROC control reg to be set to: " << (controlreg|0x2) <<std::endl;
620  pixelFEC->progdac(theROC.mfec(),
621  theROC.mfecchannel(),
622  theROC.hubaddress(),
623  theROC.portaddress(),
624  theROC.rocid(),
625  0xfd,
626  controlreg | 0x2, //=010 in binary. should disable the chip
627  bufferData);
628  } //HV off
629 
630 
631  // Now program (again) the temperature register to make sure it is the last one
632  // and appears in the LastDAC
633  if(readTemperatures) {
634  // std::cout<<"ROC="<<dacsettings_[i].getROCName()<<" ; VcThr set to "<<dacs[11]
635  // << " ROC control reg to be set to: " << dacs[28] <<" LastDAC=Temp"<<std::endl;
636  if( (theROC.mfec()==1) && (theROC.mfecchannel()==1) && (theROC.hubaddress()==0) &&
637  (theROC.portaddress()==0) && (theROC.rocid()) )
638  std::cout<<"ROC="<<dacsettings_[i].getROCName()<< " ROC control reg to be set to: "
639  << dacs[28] <<" LastDAC=Temp "<<temperatureReg<<std::endl;
640  //int temperatureReg = dacs[26]; // overwrite with the number from DB
641  pixelFEC->progdac(theROC.mfec(),
642  theROC.mfecchannel(),
643  theROC.hubaddress(),
644  theROC.portaddress(),
645  theROC.rocid(),
646  0x1B,
647  temperatureReg,bufferData);
648  } else {
649  // std::cout<<"ROC="<<dacsettings_[i].getROCName()<<" ; VcThr set to "<<dacs[11]
650  // << " ROC control reg to be set to: " << dacs[28] <<" LastDAC=Vcal"<<std::endl;
651  if( (theROC.mfec()==1) && (theROC.mfecchannel()==1) && (theROC.hubaddress()==0) &&
652  (theROC.portaddress()==0) && (theROC.rocid()) )
653  std::cout<<"ROC="<<dacsettings_[i].getROCName()
654  << " ROC control reg to be set to: " << dacs[28] <<" LastDAC=Vcal"<<std::endl;
655  // VCAL
656  pixelFEC->progdac(theROC.mfec(),
657  theROC.mfecchannel(),
658  theROC.hubaddress(),
659  theROC.portaddress(),
660  theROC.rocid(),
661  0x19,
662  200,
663  bufferData);
664  }
665 
666  } // end ROC loop
667 
668  if (bufferData) { // Send data to the FEC
669  pixelFEC->qbufsend();
670  }
671 
672 }
673 
675  //the point here is to set Vcthr to 0
676  //then disable the ROCs
677 
678  //note -- no need to look at the detconfig here, because we're going to disable everything no matter what
679 
680  bool bufferData=true;
681 
682  std::vector<unsigned int> dacs;
683 
684  for(unsigned int i=0;i<dacsettings_.size();i++){ //loop over the ROCs
685 
686  dacsettings_[i].getDACs(dacs);
687  int controlreg=dacsettings_[i].getControlRegister();
688 
689  PixelHdwAddress theROC=*(trans->getHdwAddress(dacsettings_[i].getROCName()));
690 
691  //std::cout<<"disabling ROC="<<dacsettings_[i].getROCName()<<std::endl;
692  pixelFEC->progdac(theROC.mfec(),
693  theROC.mfecchannel(),
694  theROC.hubaddress(),
695  theROC.portaddress(),
696  theROC.rocid(),
697  12, //12 == Vcthr
698  0, //set Vcthr to 0
699  bufferData);
700 
701  //this should disable the roc
702  pixelFEC->progdac(theROC.mfec(),
703  theROC.mfecchannel(),
704  theROC.hubaddress(),
705  theROC.portaddress(),
706  theROC.rocid(),
707  0xfd,
708  controlreg | 0x2,
709  bufferData);
710 
711  // Now program (again) the temperature register to make sure it is the last one
712  // and appears in the LastDAC
713  if(readTemperatures) {
714  //int temperatureReg = dacs[26]; // value from DB
715  pixelFEC->progdac(theROC.mfec(),
716  theROC.mfecchannel(),
717  theROC.hubaddress(),
718  theROC.portaddress(),
719  theROC.rocid(),
720  0x1B,
721  temperatureReg,
722  bufferData);
723  } else {
724  // VCAL
725  pixelFEC->progdac(theROC.mfec(),
726  theROC.mfecchannel(),
727  theROC.hubaddress(),
728  theROC.portaddress(),
729  theROC.rocid(),
730  0x19,
731  200,
732  bufferData);
733  }
734 
735  }
736 
737  if (bufferData) { //just copying the way it was done in the existing method
738  pixelFEC->qbufsend();
739  }
740 }
741 
743  //the point here is to set Vcthr to the nominal values
744  //then enable the ROCs
745 
746  bool bufferData=true;
747 
748  std::vector<unsigned int> dacs;
749 
750  for(unsigned int i=0;i<dacsettings_.size();i++){ //loop over the ROCs
751 
752  bool disableRoc = rocIsDisabled(detconfig, dacsettings_[i].getROCName()); //don't enable ROCs that are disabled in the detconfig
753 
754 
755  //std::cout<<"ROC="<<dacsettings_[i].getROCName()<<" ; VcThr set to "<<dacs[11]
756  // << " ; ROC control reg to be set to: " << controlreg <<std::endl;
757 
758  if (!disableRoc) { // Disable
759 
760  dacsettings_[i].getDACs(dacs);
761  int controlreg=dacsettings_[i].getControlRegister();
762 
763  PixelHdwAddress theROC=*(trans->getHdwAddress(dacsettings_[i].getROCName()));
764 
765  pixelFEC->progdac(theROC.mfec(),
766  theROC.mfecchannel(),
767  theROC.hubaddress(),
768  theROC.portaddress(),
769  theROC.rocid(),
770  12, //12 == Vcthr
771  dacs[11],
772  bufferData);
773 
774  //enable the roc (assuming controlreg was set for the roc to be enabled)
775 
776  pixelFEC->progdac(theROC.mfec(),
777  theROC.mfecchannel(),
778  theROC.hubaddress(),
779  theROC.portaddress(),
780  theROC.rocid(),
781  0xfd,
782  controlreg,
783  bufferData);
784 
785  // Now program (again) the temperature register to make sure it is the last one
786  // and appears in the LastDAC
787  if(readTemperatures) {
788  //int temperatureReg = dacs[26]; // value from DB
789  pixelFEC->progdac(theROC.mfec(),
790  theROC.mfecchannel(),
791  theROC.hubaddress(),
792  theROC.portaddress(),
793  theROC.rocid(),
794  0x1B,
795  temperatureReg,
796  bufferData);
797  } else {
798  // VCAL
799  pixelFEC->progdac(theROC.mfec(),
800  theROC.mfecchannel(),
801  theROC.hubaddress(),
802  theROC.portaddress(),
803  theROC.rocid(),
804  0x19,
805  200,
806  bufferData);
807  }
808 
809  } // end disable
810 
811  } // loop over ROCs
812 
813 
814  if (bufferData) { // Send data to FEC
815  pixelFEC->qbufsend();
816  }
817 
818 }
819 
820 bool PixelDACSettings::rocIsDisabled(const PixelDetectorConfig* detconfig, const PixelROCName rocname) const {
821 
822  const std::map<PixelROCName, PixelROCStatus> & roclist=detconfig->getROCsList();
823  const std::map<PixelROCName, PixelROCStatus>::const_iterator iroc = roclist.find(rocname);
824  assert(iroc != roclist.end()); // the roc name should always be found
825  PixelROCStatus thisROCstatus = iroc->second;
826 
827  return thisROCstatus.get(PixelROCStatus::noAnalogSignal);
828 
829 }
830 
831 std::ostream& operator<<(std::ostream& s, const PixelDACSettings& dacs){
832 
833  s << dacs.getDACSettings(0) <<std::endl;
834 
835  return s;
836 
837 }
838 
unsigned int mfec() const
const std::string k_DACName_VcThr
Definition: PixelDACNames.h:24
const std::string k_DACName_VrgPr
Definition: PixelDACNames.h:18
const PixelHdwAddress * getHdwAddress(const PixelROCName &aROC) const
PixelROCDACSettings getDACSettings(int ROCId) const
void addROC(PixelROCDACSettings &rocname)
virtual int clrcal(int mfec, int fecchannel, int hubaddress, int portaddress, int rocid, bool buffermode=false)=0
void writeXMLHeader(pos::PixelConfigKey key, int version, std::string path, std::ofstream *out, std::ofstream *out1=nullptr, std::ofstream *out2=nullptr) const override
This file contains the base class for "pixel configuration data" management.
const std::string k_DACName_ChipContReg
Definition: PixelDACNames.h:41
bool rocIsDisabled(const PixelDetectorConfig *detconfig, const PixelROCName rocname) const
virtual int progdac(int mfec, int fecchannel, int hubaddress, int portaddress, int rocid, int dacaddress, int dacvalue, bool buffermode=false)=0
const std::string k_DACName_Vsf
Definition: PixelDACNames.h:15
const std::string k_DACName_CalDel
Definition: PixelDACNames.h:38
const std::string k_DACName_TempRange
Definition: PixelDACNames.h:39
const std::string k_DACName_VIbias_sf
Definition: PixelDACNames.h:26
const std::string k_DACName_Vtrim
Definition: PixelDACNames.h:23
void writeXML(pos::PixelConfigKey key, int version, std::string path) const override
unsigned int portaddress() const
virtual int calpix(int mfec, int mfecchannel, int hubaddress, int portaddress, int rocid, int coladdr, int rowaddress, int caldata, bool buffermode=false)=0
const std::string k_DACName_VIbias_DAC
Definition: PixelDACNames.h:32
const std::string k_DACName_VwllSh
Definition: PixelDACNames.h:21
const std::string k_DACName_Vnpix
Definition: PixelDACNames.h:35
const std::string k_DACName_Vleak
Definition: PixelDACNames.h:17
virtual int dcolenable(int mfec, int mfecchannel, int hubaddress, int portaddress, int rocid, int dcol, int dcolstate, bool buffermode=false)=0
const std::string k_DACName_VIbias_PH
Definition: PixelDACNames.h:31
const std::string k_DACName_VOffsetRO
Definition: PixelDACNames.h:29
unsigned int rocid() const
bool get(ROCstatus stat) const
const std::string k_DACName_VIbias_bus
Definition: PixelDACNames.h:25
ins
Definition: cuy.py:314
int read(std::ifstream &in, const PixelROCName &rocid)
unsigned int mfecchannel() const
const std::string k_DACName_VIColOr
Definition: PixelDACNames.h:34
static std::string getmSecTime(void)
This class provide the data structure for the ROC DAC parameters.
const std::string k_DACName_VOffsetOp
Definition: PixelDACNames.h:27
void writeBinary(std::string filename) const
This class is responsible for manipulating the DACsettings of a ROC.
static std::string getTime(void)
std::string getComment() const
unsigned int hubaddress() const
This is the documentation about PixelDetectorConfig...
This class provides utility methods to manipulate ASCII formatted timestamps.
Store mfec, mfecchannel etc.
std::vector< PixelROCDACSettings > dacsettings_
std::string getAuthor() const
friend std::ostream & operator<<(std::ostream &s, const PixelDACSettings &mask)
const std::string k_DACName_VbiasOp
Definition: PixelDACNames.h:28
const std::string k_DACName_VIbias_roc
Definition: PixelDACNames.h:33
const std::string k_DACName_Vcal
Definition: PixelDACNames.h:37
virtual int qbufsend(void)=0
PixelDACSettings(std::string filename)
This class provide a base class for the pixel ROC dac data for the pixel FEC configuration.
const std::string k_DACName_VrgSh
Definition: PixelDACNames.h:20
This class implements..
const std::string k_DACName_VIon
Definition: PixelDACNames.h:30
const std::string k_DACName_Vcomp
Definition: PixelDACNames.h:16
std::string modulename() const
const std::string k_DACName_WBC
Definition: PixelDACNames.h:40
const std::string k_DACName_Vdd
Definition: PixelDACNames.h:13
const std::string k_DACName_VHldDel
Definition: PixelDACNames.h:22
void writeASCII(std::string dir) const override
This is the documentation about PixelNameTranslation...
const std::string k_DACName_VsumCol
Definition: PixelDACNames.h:36
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
This class implements..
This class implements..
Definition: PixelROCName.h:23
This class implements..
col
Definition: cuy.py:1010
int readBinary(std::ifstream &in, const PixelROCName &rocid)
void generateConfiguration(PixelFECConfigInterface *pixelFEC, PixelNameTranslation *trans, PixelDetectorConfig *detconfig, bool HVon=true) const
A dummy class with ALL public variables.
This class implements..
void setVcthrDisable(PixelFECConfigInterface *pixelFEC, PixelNameTranslation *trans) const
dbl *** dir
Definition: mlp_gen.cc:35
const std::map< PixelROCName, PixelROCStatus > & getROCsList() const
const std::string k_DACName_Vana
Definition: PixelDACNames.h:14
virtual void setAllDAC(const PixelHdwAddress &theROC, const std::vector< unsigned int > &dacs, const bool buffermode=false)=0
Definition: vlib.h:208
void setVcthrEnable(PixelFECConfigInterface *pixelFEC, PixelNameTranslation *trans, PixelDetectorConfig *detconfig) const
void writeXMLTrailer(std::ofstream *out, std::ofstream *out1=nullptr, std::ofstream *out2=nullptr) const override
const std::string k_DACName_VwllPr
Definition: PixelDACNames.h:19