File indexing completed on 2024-04-06 11:58:14
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include "CalibFormats/SiPixelObjects/interface/PixelDACSettings.h"
0010 #include "CalibFormats/SiPixelObjects/interface/PixelROCDACSettings.h"
0011 #include "CalibFormats/SiPixelObjects/interface/PixelDACNames.h"
0012 #include "CalibFormats/SiPixelObjects/interface/PixelTimeFormatter.h"
0013 #include <fstream>
0014 #include <iostream>
0015 #include <ios>
0016 #include <cassert>
0017 #include <stdexcept>
0018 #include <map>
0019 #include <sstream>
0020 #include <sys/time.h>
0021 #include <cstdlib>
0022
0023 using namespace pos;
0024
0025 namespace {
0026 const bool readTemperatures = false;
0027
0028
0029 const int temperatureReg = 0x1;
0030 }
0031
0032 PixelDACSettings::PixelDACSettings(std::string filename) : PixelConfigBase("", "", "") {
0033 std::string mthn = "[PixelDACSettings::PixelDACSettings()]\t\t\t ";
0034
0035 if (filename[filename.size() - 1] == 't') {
0036 std::ifstream in(filename.c_str());
0037
0038 if (!in.good()) {
0039 std::cout << __LINE__ << "]\t" << mthn << "Could not open: " << filename << std::endl;
0040
0041 throw std::runtime_error("Failed to open file " + filename);
0042 } else {
0043
0044 }
0045
0046 dacsettings_.clear();
0047
0048 std::string tag;
0049
0050 in >> tag;
0051
0052 while (!in.eof()) {
0053 PixelROCName rocid(in);
0054
0055
0056
0057 PixelROCDACSettings tmp;
0058
0059 tmp.read(in, rocid);
0060
0061
0062 dacsettings_.push_back(tmp);
0063
0064 in >> tag;
0065
0066 assert(dacsettings_.size() < 100);
0067 }
0068
0069 in.close();
0070
0071 } else {
0072 std::ifstream in(filename.c_str(), std::ios::binary);
0073
0074 if (!in.good()) {
0075 std::cout << __LINE__ << "]\t" << mthn << "Could not open: " << filename << std::endl;
0076 assert(0);
0077 } else {
0078 std::cout << __LINE__ << "]\t" << mthn << "Opened: " << filename << std::endl;
0079 }
0080
0081 char nchar;
0082
0083 in.read(&nchar, 1);
0084
0085 std::string s1;
0086
0087
0088 for (int i = 0; i < nchar; i++) {
0089 char c;
0090 in >> c;
0091 s1.push_back(c);
0092 }
0093
0094
0095
0096 dacsettings_.clear();
0097
0098 while (!in.eof()) {
0099
0100
0101 PixelROCName rocid(s1);
0102
0103
0104
0105 PixelROCDACSettings tmp;
0106
0107 tmp.readBinary(in, rocid);
0108
0109 dacsettings_.push_back(tmp);
0110
0111 in.read(&nchar, 1);
0112
0113 s1.clear();
0114
0115 if (in.eof())
0116 continue;
0117
0118
0119 for (int i = 0; i < nchar; i++) {
0120 char c;
0121 in >> c;
0122 s1.push_back(c);
0123 }
0124 }
0125
0126 in.close();
0127 }
0128
0129
0130 }
0131
0132 PixelDACSettings::PixelDACSettings(PixelROCDACSettings& rocname) : PixelConfigBase("", "", "") {
0133 dacsettings_.push_back(rocname);
0134 }
0135
0136
0137 void PixelDACSettings::addROC(PixelROCDACSettings& rocname) { dacsettings_.push_back(rocname); }
0138
0139 PixelDACSettings::PixelDACSettings(std::vector<std::vector<std::string> >& tableMat) : PixelConfigBase("", "", "") {
0140
0141
0142
0143
0144
0145
0146
0147
0148
0149
0150
0151
0152
0153
0154
0155
0156
0157
0158
0159
0160
0161
0162
0163
0164
0165
0166
0167
0168
0169
0170
0171
0172
0173
0174
0175
0176
0177
0178
0179
0180
0181 std::vector<std::string> ins = tableMat[0];
0182 std::string mthn("[PixelDACSettings::PixelDACSettings()] ");
0183 std::string dacName;
0184 std::istringstream dbin;
0185
0186 int skipColumns = 0;
0187 std::map<std::string, int> colM;
0188 std::vector<std::string> colNames;
0189 std::map<std::string, std::string> nameTranslation;
0190
0191 colNames.push_back("CONFIG_KEY");
0192 colNames.push_back("KEY_TYPE");
0193 colNames.push_back("KEY_ALIAS");
0194 colNames.push_back("VERSION");
0195 colNames.push_back("KIND_OF_COND");
0196 colNames.push_back("ROC_NAME");
0197 colNames.push_back("VDD");
0198 colNames.push_back("VANA");
0199 colNames.push_back("VSF");
0200 colNames.push_back("VCOMP");
0201 colNames.push_back("VLEAK");
0202 colNames.push_back("VRGPR");
0203 colNames.push_back("VWLLPR");
0204 colNames.push_back("VRGSH");
0205 colNames.push_back("VWLLSH");
0206 colNames.push_back("VHLDDEL");
0207 colNames.push_back("VTRIM");
0208 colNames.push_back("VCTHR");
0209 colNames.push_back("VIBIAS_BUS");
0210 colNames.push_back("VIBIAS_SF");
0211 colNames.push_back("VOFFSETOP");
0212 colNames.push_back("VBIASOP");
0213 colNames.push_back("VOFFSETRO");
0214 colNames.push_back("VION");
0215 colNames.push_back("VIBIAS_PH");
0216 colNames.push_back("VIBIAS_DAC");
0217 colNames.push_back("VIBIAS_ROC");
0218 colNames.push_back("VICOLOR");
0219 colNames.push_back("VNPIX");
0220 colNames.push_back("VSUMCOL");
0221 colNames.push_back("VCAL");
0222 colNames.push_back("CALDEL");
0223 colNames.push_back("TEMPRANGE");
0224 colNames.push_back("WBC");
0225 colNames.push_back("CHIPCONTREG");
0226
0227 nameTranslation["VDD"] = k_DACName_Vdd;
0228 nameTranslation["VANA"] = k_DACName_Vana;
0229 nameTranslation["VSF"] = k_DACName_Vsf;
0230 nameTranslation["VCOMP"] = k_DACName_Vcomp;
0231 nameTranslation["VLEAK"] = k_DACName_Vleak;
0232 nameTranslation["VRGPR"] = k_DACName_VrgPr;
0233 nameTranslation["VWLLPR"] = k_DACName_VwllPr;
0234 nameTranslation["VRGSH"] = k_DACName_VrgSh;
0235 nameTranslation["VWLLSH"] = k_DACName_VwllSh;
0236 nameTranslation["VHLDDEL"] = k_DACName_VHldDel;
0237 nameTranslation["VTRIM"] = k_DACName_Vtrim;
0238 nameTranslation["VCTHR"] = k_DACName_VcThr;
0239 nameTranslation["VIBIAS_BUS"] = k_DACName_VIbias_bus;
0240 nameTranslation["VIBIAS_SF"] = k_DACName_VIbias_sf;
0241 nameTranslation["VOFFSETOP"] = k_DACName_VOffsetOp;
0242 nameTranslation["VBIASOP"] = k_DACName_VbiasOp;
0243 nameTranslation["VOFFSETRO"] = k_DACName_VOffsetRO;
0244 nameTranslation["VION"] = k_DACName_VIon;
0245 nameTranslation["VIBIAS_PH"] = k_DACName_VIbias_PH;
0246 nameTranslation["VIBIAS_DAC"] = k_DACName_VIbias_DAC;
0247 nameTranslation["VIBIAS_ROC"] = k_DACName_VIbias_roc;
0248 nameTranslation["VICOLOR"] = k_DACName_VIColOr;
0249 nameTranslation["VNPIX"] = k_DACName_Vnpix;
0250 nameTranslation["VSUMCOL"] = k_DACName_VsumCol;
0251 nameTranslation["VCAL"] = k_DACName_Vcal;
0252 nameTranslation["CALDEL"] = k_DACName_CalDel;
0253 nameTranslation["TEMPRANGE"] = k_DACName_TempRange;
0254 nameTranslation["WBC"] = k_DACName_WBC;
0255 nameTranslation["CHIPCONTREG"] = k_DACName_ChipContReg;
0256
0257
0258
0259 for (unsigned int c = skipColumns; c < ins.size(); c++) {
0260 for (unsigned int n = 0; n < colNames.size(); n++) {
0261 if (tableMat[0][c] == colNames[n]) {
0262 colM[colNames[n]] = c;
0263 break;
0264 }
0265 }
0266 }
0267 for (unsigned int n = skipColumns; n < colNames.size(); n++) {
0268 if (colM.find(colNames[n]) == colM.end()) {
0269 std::cerr << "[PixelDACSettings::PixelDACSettings()]\tCouldn't find in the database the column with name "
0270 << colNames[n] << std::endl;
0271 assert(0);
0272 }
0273 }
0274
0275 dacsettings_.clear();
0276
0277
0278
0279 for (unsigned int r = 1; r < tableMat.size(); r++) {
0280
0281
0282
0283
0284
0285
0286
0287
0288
0289 PixelROCName rocid(tableMat[r][colM["ROC_NAME"]]);
0290 PixelROCDACSettings tmp(rocid);
0291 std::ostringstream dacs("");
0292
0293 for (unsigned int n = skipColumns + 6; n < colNames.size(); n++) {
0294 dacs << nameTranslation[colNames[n]] << ": " << atoi(tableMat[r][colM[colNames[n]]].c_str()) << std::endl;
0295
0296
0297
0298
0299
0300 }
0301
0302 dbin.str(dacs.str());
0303 tmp.read(dbin, rocid);
0304 dacsettings_.push_back(tmp);
0305 }
0306
0307
0308
0309
0310
0311
0312
0313
0314
0315
0316
0317
0318
0319
0320
0321
0322
0323
0324
0325
0326
0327
0328
0329
0330
0331
0332
0333
0334
0335
0336
0337
0338
0339 }
0340
0341
0342 PixelROCDACSettings PixelDACSettings::getDACSettings(int ROCId) const { return dacsettings_[ROCId]; }
0343
0344 PixelROCDACSettings* PixelDACSettings::getDACSettings(PixelROCName name) {
0345 for (unsigned int i = 0; i < dacsettings_.size(); i++) {
0346 if (dacsettings_[i].getROCName() == name)
0347 return &(dacsettings_[i]);
0348 }
0349
0350 return nullptr;
0351 }
0352
0353 void PixelDACSettings::writeBinary(std::string filename) const {
0354 std::ofstream out(filename.c_str(), std::ios::binary);
0355
0356 for (unsigned int i = 0; i < dacsettings_.size(); i++) {
0357 dacsettings_[i].writeBinary(out);
0358 }
0359 }
0360
0361 void PixelDACSettings::writeASCII(std::string dir) const {
0362 std::string mthn = "[PixelDACSettings::writeASCII()]\t\t\t ";
0363 PixelModuleName module(dacsettings_[0].getROCName().rocname());
0364
0365 std::string filename = dir + "/ROC_DAC_module_" + module.modulename() + ".dat";
0366 std::cout << __LINE__ << "]\t" << mthn << "Writing to file " << filename << std::endl;
0367 std::ofstream out(filename.c_str());
0368
0369 for (unsigned int i = 0; i < dacsettings_.size(); i++) {
0370 dacsettings_[i].writeASCII(out);
0371 }
0372 }
0373
0374
0375 void PixelDACSettings::writeXMLHeader(pos::PixelConfigKey key,
0376 int version,
0377 std::string path,
0378 std::ofstream* outstream,
0379 std::ofstream* out1stream,
0380 std::ofstream* out2stream) const {
0381 std::string mthn = "[PixelDACSettings::writeXMLHeader()]\t\t\t ";
0382 std::stringstream fullPath;
0383
0384 fullPath << path << "/Pixel_RocDacSettings_" << PixelTimeFormatter::getmSecTime() << ".xml";
0385 std::cout << __LINE__ << "]\t" << mthn << "Writing to: " << fullPath.str() << std::endl;
0386
0387 outstream->open(fullPath.str().c_str());
0388
0389 *outstream << "<?xml version='1.0' encoding='UTF-8' standalone='yes'?>" << std::endl;
0390 *outstream << "<ROOT xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>" << std::endl;
0391 *outstream << "" << std::endl;
0392 *outstream << " <!-- " << mthn << "-->" << std::endl;
0393 *outstream << "" << std::endl;
0394 *outstream << " <HEADER>" << std::endl;
0395 *outstream << " <TYPE>" << std::endl;
0396 *outstream << " <EXTENSION_TABLE_NAME>ROC_DAC_SETTINGS_COL</EXTENSION_TABLE_NAME>" << std::endl;
0397 *outstream << " <NAME>ROC DAC Settings Col</NAME>" << std::endl;
0398 *outstream << " </TYPE>" << std::endl;
0399 *outstream << " <RUN>" << std::endl;
0400 *outstream << " <RUN_TYPE>ROC DAC Settings</RUN_TYPE>" << std::endl;
0401 *outstream << " <RUN_NUMBER>1</RUN_NUMBER>" << std::endl;
0402 *outstream << " <RUN_BEGIN_TIMESTAMP>" << PixelTimeFormatter::getTime() << "</RUN_BEGIN_TIMESTAMP>" << std::endl;
0403 *outstream << " <LOCATION>CERN P5</LOCATION>" << std::endl;
0404 *outstream << " </RUN>" << std::endl;
0405 *outstream << " </HEADER>" << std::endl;
0406 *outstream << "" << std::endl;
0407 *outstream << " <DATA_SET>" << std::endl;
0408 *outstream << " <VERSION>" << version << "</VERSION>" << std::endl;
0409 *outstream << " <COMMENT_DESCRIPTION>" << getComment() << "</COMMENT_DESCRIPTION>" << std::endl;
0410 *outstream << " <CREATED_BY_USER>" << getAuthor() << "</CREATED_BY_USER>" << std::endl;
0411 *outstream << " " << std::endl;
0412 *outstream << " <PART>" << std::endl;
0413 *outstream << " <NAME_LABEL>CMS-PIXEL-ROOT</NAME_LABEL>" << std::endl;
0414 *outstream << " <KIND_OF_PART>Detector ROOT</KIND_OF_PART>" << std::endl;
0415 *outstream << " </PART>" << std::endl;
0416 *outstream << " " << std::endl;
0417
0418 std::cout << __LINE__ << "]\t" << mthn << "Header written" << std::endl;
0419 }
0420
0421
0422 void PixelDACSettings::writeXML(std::ofstream* outstream, std::ofstream* out1stream, std::ofstream* out2stream) const {
0423 std::string mthn = "[PixelDACSettings::writeXML()]\t\t\t ";
0424
0425 for (unsigned int i = 0; i < dacsettings_.size(); i++) {
0426 dacsettings_[i].writeXML(outstream);
0427 }
0428 }
0429
0430
0431 void PixelDACSettings::writeXMLTrailer(std::ofstream* outstream,
0432 std::ofstream* out1stream,
0433 std::ofstream* out2stream) const {
0434 std::string mthn = "[PixelDACSettings::writeXMLTrailer()]\t\t\t ";
0435
0436 *outstream << " </DATA_SET>" << std::endl;
0437 *outstream << "</ROOT>" << std::endl;
0438
0439 outstream->close();
0440 std::cout << __LINE__ << "]\t" << mthn << "Data written" << std::endl;
0441 }
0442
0443
0444
0445
0446
0447
0448
0449
0450
0451
0452
0453
0454
0455
0456
0457
0458
0459
0460
0461
0462
0463
0464
0465
0466
0467
0468
0469
0470
0471
0472
0473
0474
0475
0476
0477
0478
0479
0480
0481
0482
0483
0484
0485
0486
0487
0488
0489
0490
0491
0492
0493
0494
0495
0496 void PixelDACSettings::generateConfiguration(PixelFECConfigInterface* pixelFEC,
0497 PixelNameTranslation* trans,
0498 PixelDetectorConfig* detconfig,
0499 bool HVon) const {
0500 bool bufferData = true;
0501
0502 std::vector<unsigned int> dacs;
0503
0504
0505
0506 for (unsigned int i = 0; i < dacsettings_.size(); i++) {
0507
0508 bool disableRoc = rocIsDisabled(detconfig, dacsettings_[i].getROCName());
0509
0510 dacsettings_[i].getDACs(dacs);
0511
0512 PixelHdwAddress theROC = *(trans->getHdwAddress(dacsettings_[i].getROCName()));
0513
0514
0515
0516
0517
0518
0519
0520
0521
0522
0523
0524
0525
0526 if (!HVon || disableRoc)
0527 dacs[11] = 0;
0528
0529 pixelFEC->setAllDAC(theROC, dacs, bufferData);
0530
0531
0532 pixelFEC->clrcal(
0533 theROC.mfec(), theROC.mfecchannel(), theROC.hubaddress(), theROC.portaddress(), theROC.rocid(), bufferData);
0534
0535 const bool kmeKLUDGE = false;
0536 if (kmeKLUDGE)
0537 {
0538 unsigned int col = 0;
0539
0540 {
0541 pixelFEC->calpix(theROC.mfec(),
0542 theROC.mfecchannel(),
0543 theROC.hubaddress(),
0544 theROC.portaddress(),
0545 theROC.rocid(),
0546 col,
0547 0,
0548 1,
0549 bufferData);
0550 }
0551 }
0552
0553
0554 for (int dcol = 0; dcol < 26; dcol++) {
0555 pixelFEC->dcolenable(theROC.mfec(),
0556 theROC.mfecchannel(),
0557 theROC.hubaddress(),
0558 theROC.portaddress(),
0559 theROC.rocid(),
0560 dcol,
0561 1,
0562 bufferData);
0563 }
0564
0565 if (!HVon || disableRoc) {
0566 int controlreg = dacsettings_[i].getControlRegister();
0567
0568 pixelFEC->progdac(theROC.mfec(),
0569 theROC.mfecchannel(),
0570 theROC.hubaddress(),
0571 theROC.portaddress(),
0572 theROC.rocid(),
0573 0xfd,
0574 controlreg | 0x2,
0575 bufferData);
0576 }
0577
0578
0579
0580 if (readTemperatures) {
0581
0582
0583 if ((theROC.mfec() == 1) && (theROC.mfecchannel() == 1) && (theROC.hubaddress() == 0) &&
0584 (theROC.portaddress() == 0) && (theROC.rocid()))
0585 std::cout << "ROC=" << dacsettings_[i].getROCName() << " ROC control reg to be set to: " << dacs[28]
0586 << " LastDAC=Temp " << temperatureReg << std::endl;
0587
0588 pixelFEC->progdac(theROC.mfec(),
0589 theROC.mfecchannel(),
0590 theROC.hubaddress(),
0591 theROC.portaddress(),
0592 theROC.rocid(),
0593 0x1B,
0594 temperatureReg,
0595 bufferData);
0596 } else {
0597
0598
0599 if ((theROC.mfec() == 1) && (theROC.mfecchannel() == 1) && (theROC.hubaddress() == 0) &&
0600 (theROC.portaddress() == 0) && (theROC.rocid()))
0601 std::cout << "ROC=" << dacsettings_[i].getROCName() << " ROC control reg to be set to: " << dacs[28]
0602 << " LastDAC=Vcal" << std::endl;
0603
0604 pixelFEC->progdac(theROC.mfec(),
0605 theROC.mfecchannel(),
0606 theROC.hubaddress(),
0607 theROC.portaddress(),
0608 theROC.rocid(),
0609 0x19,
0610 200,
0611 bufferData);
0612 }
0613
0614 }
0615
0616 if (bufferData) {
0617 pixelFEC->qbufsend();
0618 }
0619 }
0620
0621 void PixelDACSettings::setVcthrDisable(PixelFECConfigInterface* pixelFEC, PixelNameTranslation* trans) const {
0622
0623
0624
0625
0626
0627 bool bufferData = true;
0628
0629 std::vector<unsigned int> dacs;
0630
0631 for (unsigned int i = 0; i < dacsettings_.size(); i++) {
0632
0633 dacsettings_[i].getDACs(dacs);
0634 int controlreg = dacsettings_[i].getControlRegister();
0635
0636 PixelHdwAddress theROC = *(trans->getHdwAddress(dacsettings_[i].getROCName()));
0637
0638
0639 pixelFEC->progdac(theROC.mfec(),
0640 theROC.mfecchannel(),
0641 theROC.hubaddress(),
0642 theROC.portaddress(),
0643 theROC.rocid(),
0644 12,
0645 0,
0646 bufferData);
0647
0648
0649 pixelFEC->progdac(theROC.mfec(),
0650 theROC.mfecchannel(),
0651 theROC.hubaddress(),
0652 theROC.portaddress(),
0653 theROC.rocid(),
0654 0xfd,
0655 controlreg | 0x2,
0656 bufferData);
0657
0658
0659
0660 if (readTemperatures) {
0661
0662 pixelFEC->progdac(theROC.mfec(),
0663 theROC.mfecchannel(),
0664 theROC.hubaddress(),
0665 theROC.portaddress(),
0666 theROC.rocid(),
0667 0x1B,
0668 temperatureReg,
0669 bufferData);
0670 } else {
0671
0672 pixelFEC->progdac(theROC.mfec(),
0673 theROC.mfecchannel(),
0674 theROC.hubaddress(),
0675 theROC.portaddress(),
0676 theROC.rocid(),
0677 0x19,
0678 200,
0679 bufferData);
0680 }
0681 }
0682
0683 if (bufferData) {
0684 pixelFEC->qbufsend();
0685 }
0686 }
0687
0688 void PixelDACSettings::setVcthrEnable(PixelFECConfigInterface* pixelFEC,
0689 PixelNameTranslation* trans,
0690 PixelDetectorConfig* detconfig) const {
0691
0692
0693
0694 bool bufferData = true;
0695
0696 std::vector<unsigned int> dacs;
0697
0698 for (unsigned int i = 0; i < dacsettings_.size(); i++) {
0699
0700 bool disableRoc =
0701 rocIsDisabled(detconfig, dacsettings_[i].getROCName());
0702
0703
0704
0705
0706 if (!disableRoc) {
0707
0708 dacsettings_[i].getDACs(dacs);
0709 int controlreg = dacsettings_[i].getControlRegister();
0710
0711 PixelHdwAddress theROC = *(trans->getHdwAddress(dacsettings_[i].getROCName()));
0712
0713 pixelFEC->progdac(theROC.mfec(),
0714 theROC.mfecchannel(),
0715 theROC.hubaddress(),
0716 theROC.portaddress(),
0717 theROC.rocid(),
0718 12,
0719 dacs[11],
0720 bufferData);
0721
0722
0723
0724 pixelFEC->progdac(theROC.mfec(),
0725 theROC.mfecchannel(),
0726 theROC.hubaddress(),
0727 theROC.portaddress(),
0728 theROC.rocid(),
0729 0xfd,
0730 controlreg,
0731 bufferData);
0732
0733
0734
0735 if (readTemperatures) {
0736
0737 pixelFEC->progdac(theROC.mfec(),
0738 theROC.mfecchannel(),
0739 theROC.hubaddress(),
0740 theROC.portaddress(),
0741 theROC.rocid(),
0742 0x1B,
0743 temperatureReg,
0744 bufferData);
0745 } else {
0746
0747 pixelFEC->progdac(theROC.mfec(),
0748 theROC.mfecchannel(),
0749 theROC.hubaddress(),
0750 theROC.portaddress(),
0751 theROC.rocid(),
0752 0x19,
0753 200,
0754 bufferData);
0755 }
0756
0757 }
0758
0759 }
0760
0761 if (bufferData) {
0762 pixelFEC->qbufsend();
0763 }
0764 }
0765
0766 bool PixelDACSettings::rocIsDisabled(const PixelDetectorConfig* detconfig, const PixelROCName rocname) const {
0767 const std::map<PixelROCName, PixelROCStatus>& roclist = detconfig->getROCsList();
0768 const std::map<PixelROCName, PixelROCStatus>::const_iterator iroc = roclist.find(rocname);
0769 assert(iroc != roclist.end());
0770 PixelROCStatus thisROCstatus = iroc->second;
0771
0772 return thisROCstatus.get(PixelROCStatus::noAnalogSignal);
0773 }
0774
0775 std::ostream& operator<<(std::ostream& s, const PixelDACSettings& dacs) {
0776 s << dacs.getDACSettings(0) << std::endl;
0777
0778 return s;
0779 }