00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include "CalibFormats/SiPixelObjects/interface/PixelDACSettings.h"
00011 #include "CalibFormats/SiPixelObjects/interface/PixelROCDACSettings.h"
00012 #include "CalibFormats/SiPixelObjects/interface/PixelDACNames.h"
00013 #include "CalibFormats/SiPixelObjects/interface/PixelTimeFormatter.h"
00014 #include <fstream>
00015 #include <iostream>
00016 #include <ios>
00017 #include <assert.h>
00018 #include <map>
00019 #include <sstream>
00020 #include <sys/time.h>
00021
00022 using namespace pos;
00023
00024 PixelDACSettings::PixelDACSettings(std::string filename):
00025 PixelConfigBase("","",""){
00026
00027
00028 if (filename[filename.size()-1]=='t'){
00029
00030 std::ifstream in(filename.c_str());
00031
00032 if (!in.good()){
00033 std::cout << "Could not open:"<<filename<<std::endl;
00034 assert(0);
00035 }
00036 else {
00037
00038 }
00039
00040
00041 dacsettings_.clear();
00042
00043 std::string tag;
00044
00045 in >> tag;
00046
00047 while (!in.eof()){
00048
00049
00050 PixelROCName rocid(in);
00051
00052
00053
00054 PixelROCDACSettings tmp;
00055
00056 tmp.read(in,rocid);
00057
00058
00059 dacsettings_.push_back(tmp);
00060
00061 in >> tag;
00062
00063 assert(dacsettings_.size()<100);
00064
00065 }
00066
00067 in.close();
00068
00069 }
00070 else{
00071
00072 std::ifstream in(filename.c_str(),std::ios::binary);
00073
00074 if (!in.good()){
00075 std::cout << "Could not open:"<<filename<<std::endl;
00076 assert(0);
00077 }
00078 else {
00079 std::cout << "Opened:"<<filename<<std::endl;
00080 }
00081
00082 char nchar;
00083
00084 in.read(&nchar,1);
00085
00086 std::string s1;
00087
00088
00089 for(int i=0;i< nchar; i++){
00090 char c;
00091 in >>c;
00092 s1.push_back(c);
00093 }
00094
00095
00096
00097 dacsettings_.clear();
00098
00099
00100 while (!in.eof()){
00101
00102
00103
00104 PixelROCName rocid(s1);
00105
00106
00107
00108 PixelROCDACSettings tmp;
00109
00110 tmp.readBinary(in, rocid);
00111
00112 dacsettings_.push_back(tmp);
00113
00114
00115 in.read(&nchar,1);
00116
00117 s1.clear();
00118
00119 if (in.eof()) continue;
00120
00121
00122 for(int i=0;i< nchar; i++){
00123 char c;
00124 in >>c;
00125 s1.push_back(c);
00126 }
00127
00128
00129 }
00130
00131 in.close();
00132
00133
00134
00135 }
00136
00137
00138
00139
00140
00141 }
00142
00143 PixelDACSettings::PixelDACSettings(PixelROCDACSettings &rocname):
00144 PixelConfigBase("","","") {
00145 dacsettings_.push_back(rocname) ;
00146 }
00147
00148
00149 void PixelDACSettings::addROC(PixelROCDACSettings &rocname)
00150 {
00151 dacsettings_.push_back(rocname) ;
00152 }
00153
00154 PixelDACSettings::PixelDACSettings(std::vector< std::vector<std::string> > &tableMat): PixelConfigBase("","","")
00155 {
00156
00157
00158 std::vector< std::string > ins = tableMat[0];
00159 std::string mthn("[PixelDACSettings::PixelDACSettings()] ") ;
00160 std::string dacName;
00161 std::istringstream dbin ;
00162
00163 int skipColumns = 0 ;
00164 std::map<std::string , int > colM;
00165 std::vector<std::string > colNames;
00166 std::map<std::string, std::string> nameTranslation ;
00167
00168
00169
00170
00171 colNames.push_back("ROC_NAME");
00172
00173
00174
00175
00176 colNames.push_back("VDD");
00177 colNames.push_back("VANA");
00178 colNames.push_back("VSF");
00179 colNames.push_back("VCOMP");
00180 colNames.push_back("VLEAK");
00181 colNames.push_back("VRGPR");
00182 colNames.push_back("VWLLPR");
00183 colNames.push_back("VRGSH");
00184 colNames.push_back("VWLLSH");
00185 colNames.push_back("VHLDDEL");
00186 colNames.push_back("VTRIM");
00187 colNames.push_back("VCTHR");
00188 colNames.push_back("VIBIAS_BUS");
00189 colNames.push_back("VIBIAS_SF");
00190 colNames.push_back("VOFFSETOP");
00191 colNames.push_back("VBIASOP");
00192 colNames.push_back("VOFFSETRO");
00193 colNames.push_back("VION");
00194 colNames.push_back("VIBIAS_PH");
00195 colNames.push_back("VIBIAS_DAC");
00196 colNames.push_back("VIBIAS_ROC");
00197 colNames.push_back("VICOLOR");
00198 colNames.push_back("VNPIX");
00199 colNames.push_back("VSUMCOL");
00200 colNames.push_back("VCAL");
00201 colNames.push_back("CALDEL");
00202 colNames.push_back("TEMPRANGE");
00203 colNames.push_back("WBC");
00204 colNames.push_back("CHIPCONTREG");
00205
00206 nameTranslation["VDD"] = k_DACName_Vdd ;
00207 nameTranslation["VANA"] = k_DACName_Vana;
00208 nameTranslation["VSF"] = k_DACName_Vsf;
00209 nameTranslation["VCOMP"] = k_DACName_Vcomp;
00210 nameTranslation["VLEAK"] = k_DACName_Vleak;
00211 nameTranslation["VRGPR"] = k_DACName_VrgPr;
00212 nameTranslation["VWLLPR"] = k_DACName_VwllPr;
00213 nameTranslation["VRGSH"] = k_DACName_VrgSh;
00214 nameTranslation["VWLLSH"] = k_DACName_VwllSh;
00215 nameTranslation["VHLDDEL"] = k_DACName_VHldDel;
00216 nameTranslation["VTRIM"] = k_DACName_Vtrim;
00217 nameTranslation["VCTHR"] = k_DACName_VcThr;
00218 nameTranslation["VIBIAS_BUS"] = k_DACName_VIbias_bus;
00219 nameTranslation["VIBIAS_SF"] = k_DACName_VIbias_sf;
00220 nameTranslation["VOFFSETOP"] = k_DACName_VOffsetOp;
00221 nameTranslation["VBIASOP"] = k_DACName_VbiasOp;
00222 nameTranslation["VOFFSETRO"] = k_DACName_VOffsetRO;
00223 nameTranslation["VION"] = k_DACName_VIon;
00224 nameTranslation["VIBIAS_PH"] = k_DACName_VIbias_PH;
00225 nameTranslation["VIBIAS_DAC"] = k_DACName_VIbias_DAC;
00226 nameTranslation["VIBIAS_ROC"] = k_DACName_VIbias_roc;
00227 nameTranslation["VICOLOR"] = k_DACName_VIColOr;
00228 nameTranslation["VNPIX"] = k_DACName_Vnpix;
00229 nameTranslation["VSUMCOL"] = k_DACName_VsumCol;
00230 nameTranslation["VCAL"] = k_DACName_Vcal;
00231 nameTranslation["CALDEL"] = k_DACName_CalDel;
00232 nameTranslation["TEMPRANGE"] = k_DACName_TempRange;
00233 nameTranslation["WBC"] = k_DACName_WBC;
00234 nameTranslation["CHIPCONTREG"] = k_DACName_ChipContReg;
00235
00236
00237
00238 for(unsigned int c = skipColumns ; c < ins.size() ; c++){
00239 for(unsigned int n=0; n<colNames.size(); n++){
00240 if(tableMat[0][c] == colNames[n]){
00241 colM[colNames[n]] = c;
00242 break;
00243 }
00244 }
00245 }
00246 for(unsigned int n=skipColumns; n<colNames.size(); n++){
00247 if(colM.find(colNames[n]) == colM.end()){
00248 std::cerr << "[PixelDACSettings::PixelDACSettings()]\tCouldn't find in the database the column with name " << colNames[n] << std::endl;
00249 assert(0);
00250 }
00251 }
00252
00253
00254 dacsettings_.clear();
00255
00256
00257
00258 for(unsigned int r = 1 ; r < tableMat.size() ; r++){
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269 PixelROCName rocid(tableMat[r][colM["ROC_NAME"]]);
00270 PixelROCDACSettings tmp(rocid);
00271
00272 std::ostringstream dacs("") ;
00273 for(unsigned int n=skipColumns+1; n<colNames.size(); n++)
00274 {
00275 dacs << nameTranslation[colNames[n]] <<": "<< atoi(tableMat[r][colM[colNames[n]]].c_str()) << std::endl ;
00276
00277
00278
00279
00280
00281 }
00282
00283 dbin.str(dacs.str()) ;
00284 tmp.read(dbin, rocid) ;
00285 dacsettings_.push_back(tmp) ;
00286 }
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321 }
00322
00323
00324 PixelROCDACSettings PixelDACSettings::getDACSettings(int ROCId) const {
00325
00326 return dacsettings_[ROCId];
00327
00328 }
00329
00330 PixelROCDACSettings* PixelDACSettings::getDACSettings(PixelROCName name){
00331
00332 for(unsigned int i=0;i<dacsettings_.size();i++){
00333 if (dacsettings_[i].getROCName()==name) return &(dacsettings_[i]);
00334 }
00335
00336 return 0;
00337
00338 }
00339
00340 void PixelDACSettings::writeBinary(std::string filename) const {
00341
00342 std::ofstream out(filename.c_str(),std::ios::binary);
00343
00344 for(unsigned int i=0;i<dacsettings_.size();i++){
00345 dacsettings_[i].writeBinary(out);
00346 }
00347
00348 }
00349
00350
00351 void PixelDACSettings::writeASCII(std::string dir) const {
00352
00353 PixelModuleName module(dacsettings_[0].getROCName().rocname());
00354
00355 std::string filename=dir+"/ROC_DAC_module_"+module.modulename()+".dat";
00356 std::cout << "[PixelDACSettings::writeASCII()] Writing to file " << filename << std::endl ;
00357 std::ofstream out(filename.c_str());
00358
00359 for(unsigned int i=0;i<dacsettings_.size();i++){
00360 dacsettings_[i].writeASCII(out);
00361 }
00362
00363 }
00364
00365
00366 void PixelDACSettings::writeXMLHeader(pos::PixelConfigKey key, int version, std::string path, std::ofstream *out) const {
00367 std::string mthn = "[PixelDACSettings::writeXMLHeader()]\t\t\t " ;
00368 std::stringstream fullPath ;
00369
00370 fullPath << path << "/dacsettings.xml" ;
00371 std::cout << mthn << "Writing to: |" << fullPath.str() << "|" << std::endl ;
00372
00373 out->open(fullPath.str().c_str()) ;
00374
00375 *out << "<?xml version='1.0' encoding='UTF-8' standalone='yes'?>" << std::endl ;
00376 *out << "<ROOT xmlns:xsi='https://www.w3.org/2001/XMLSchema-instance'>" << std::endl ;
00377 *out << " <HEADER>" << std::endl ;
00378 *out << " <TYPE>" << std::endl ;
00379 *out << " <EXTENSION_TABLE_NAME>ROC_DAC_SETTINGS_COL</EXTENSION_TABLE_NAME>" << std::endl ;
00380 *out << " <NAME>ROC DAC Settings Col</NAME>" << std::endl ;
00381 *out << " </TYPE>" << std::endl ;
00382 *out << " <RUN>" << std::endl ;
00383 *out << " <RUN_TYPE>test</RUN_TYPE>" << std::endl ;
00384 *out << " <RUN_NUMBER>1</RUN_NUMBER>" << std::endl ;
00385 *out << " <RUN_BEGIN_TIMESTAMP>" << PixelTimeFormatter::getTime() << "</RUN_BEGIN_TIMESTAMP>" << std::endl ;
00386 *out << " <COMMENT_DESCRIPTION>Test of DAC Settings xml</COMMENT_DESCRIPTION>" << std::endl ;
00387 *out << " <LOCATION>CERN TAC</LOCATION>" << std::endl ;
00388 *out << " <INITIATED_BY_USER>Dario Menasce</INITIATED_BY_USER>" << std::endl ;
00389 *out << " </RUN>" << std::endl ;
00390 *out << " </HEADER>" << std::endl ;
00391 *out << "" << std::endl ;
00392 *out << " <DATA_SET>" << std::endl ;
00393 *out << " <VERSION>" << version << "</VERSION>" << std::endl ;
00394 *out << " " << std::endl ;
00395 *out << " <PART>" << std::endl ;
00396 *out << " <NAME_LABEL>CMS-PIXEL-ROOT</NAME_LABEL>" << std::endl ;
00397 *out << " <KIND_OF_PART>Detector ROOT</KIND_OF_PART>" << std::endl ;
00398 *out << " </PART>" << std::endl ;
00399 *out << " " << std::endl ;
00400
00401 std::cout << mthn << "Header written" << std::endl ;
00402 }
00403
00404
00405 void PixelDACSettings::writeXML( std::ofstream *out) const {
00406 std::string mthn = "[PixelDACSettings::writeXML()]\t\t\t " ;
00407
00408 for(unsigned int i=0;i<dacsettings_.size();i++){
00409 dacsettings_[i].writeXML(out);
00410 }
00411 }
00412
00413
00414 void PixelDACSettings::writeXMLTrailer(std::ofstream *out) const {
00415 std::string mthn = "[PixelDACSettings::writeXMLTrailer()]\t\t\t " ;
00416
00417 *out << " </DATA_SET>" << std::endl ;
00418 *out << "</ROOT>" << std::endl ;
00419
00420 std::cout << mthn << "Closing input stream" << std::endl ;
00421 out->close() ;
00422 std::cout << mthn << "Data written" << std::endl ;
00423 }
00424
00425
00426 void PixelDACSettings::writeXML(pos::PixelConfigKey key, int version, std::string path) const {
00427 std::string mthn = "[PixelDACSettings::writeXML()]\t\t\t " ;
00428 std::stringstream fullPath ;
00429
00430 PixelModuleName module(dacsettings_[0].getROCName().rocname());
00431 fullPath << path << "/dacsettings_" << module.modulename() << ".xml" ;
00432 std::cout << mthn << "Writing to: |" << fullPath.str() << "|" << std::endl ;
00433
00434
00435 std::ofstream out(fullPath.str().c_str()) ;
00436
00437 out << "<?xml version='1.0' encoding='UTF-8' standalone='yes'?>" << std::endl ;
00438 out << "<ROOT xmlns:xsi='https://www.w3.org/2001/XMLSchema-instance'>" << std::endl ;
00439 out << " <HEADER>" << std::endl ;
00440 out << " <TYPE>" << std::endl ;
00441 out << " <EXTENSION_TABLE_NAME>ROC_DAC_SETTINGS_COL</EXTENSION_TABLE_NAME>" << std::endl ;
00442 out << " <NAME>ROC DAC Settings Col</NAME>" << std::endl ;
00443 out << " </TYPE>" << std::endl ;
00444 out << " <RUN>" << std::endl ;
00445 out << " <RUN_TYPE>test</RUN_TYPE>" << std::endl ;
00446 out << " <RUN_NUMBER>1</RUN_NUMBER>" << std::endl ;
00447 out << " <RUN_BEGIN_TIMESTAMP>" << PixelTimeFormatter::getTime() << "</RUN_BEGIN_TIMESTAMP>" << std::endl ;
00448 out << " <COMMENT_DESCRIPTION>Test of DAC Settings xml</COMMENT_DESCRIPTION>" << std::endl ;
00449 out << " <LOCATION>CERN TAC</LOCATION>" << std::endl ;
00450 out << " <INITIATED_BY_USER>Dario Menasce</INITIATED_BY_USER>" << std::endl ;
00451 out << " </RUN>" << std::endl ;
00452 out << " </HEADER>" << std::endl ;
00453 out << "" << std::endl ;
00454 out << " <DATA_SET>" << std::endl ;
00455 out << " <VERSION>" << version << "</VERSION>" << std::endl ;
00456 out << " " << std::endl ;
00457 out << " <PART>" << std::endl ;
00458 out << " <NAME_LABEL>CMS-PIXEL-ROOT</NAME_LABEL>" << std::endl ;
00459 out << " <KIND_OF_PART>Detector ROOT</KIND_OF_PART>" << std::endl ;
00460 out << " </PART>" << std::endl ;
00461 out << " " << std::endl ;
00462
00463 for(unsigned int i=0;i<dacsettings_.size();i++){
00464
00465 }
00466
00467 out << " </DATA_SET>" << std::endl ;
00468 out << "</ROOT>" << std::endl ;
00469
00470 out.close() ;
00471 std::cout << mthn << "Data written" << std::endl ;
00472 }
00473
00474
00475 void PixelDACSettings::generateConfiguration(PixelFECConfigInterface* pixelFEC,
00476 PixelNameTranslation* trans) const{
00477
00478 bool bufferData=true;
00479
00480 std::vector<unsigned int> dacs;
00481
00482
00483
00484 for(unsigned int i=0;i<dacsettings_.size();i++){
00485
00486 dacsettings_[i].getDACs(dacs);
00487
00488 PixelHdwAddress theROC=*(trans->getHdwAddress(dacsettings_[i].getROCName()));
00489
00490
00491
00492 int controlreg=dacsettings_[i].getControlRegister();
00493
00494
00495 pixelFEC->progdac(theROC.mfec(),
00496 theROC.mfecchannel(),
00497 theROC.hubaddress(),
00498 theROC.portaddress(),
00499 theROC.rocid(),
00500 0xfd,
00501 controlreg,
00502 bufferData);
00503
00504 pixelFEC->setAllDAC(theROC,dacs,bufferData);
00505
00506
00507 pixelFEC->clrcal(theROC.mfec(),
00508 theROC.mfecchannel(),
00509 theROC.hubaddress(),
00510 theROC.portaddress(),
00511 theROC.rocid(),
00512 bufferData);
00513
00514
00515 for(int dcol=0;dcol<26;dcol++){
00516 pixelFEC->dcolenable(theROC.mfec(),
00517 theROC.mfecchannel(),
00518 theROC.hubaddress(),
00519 theROC.portaddress(),
00520 theROC.rocid(),
00521 dcol,
00522 1,
00523 bufferData);
00524 }
00525 }
00526
00527 if (bufferData) {
00528 pixelFEC->qbufsend();
00529 }
00530
00531 }
00532
00533
00534 std::ostream& operator<<(std::ostream& s, const PixelDACSettings& dacs){
00535
00536 s << dacs.getDACSettings(0) <<std::endl;
00537
00538 return s;
00539
00540 }
00541