Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:47:28

0001 //
0002 // This class specifies the settings on the TKPCIFEC
0003 // and the settings on the portcard
0004 //
0005 //
0006 //
0007 //
0008 
0009 #include "CalibFormats/SiPixelObjects/interface/PixelPortCardConfig.h"
0010 #include "CalibFormats/SiPixelObjects/interface/PixelPortCardSettingNames.h"
0011 #include "CalibFormats/SiPixelObjects/interface/PixelTimeFormatter.h"
0012 #include <fstream>
0013 #include <sstream>
0014 #include <iostream>
0015 #include <string>
0016 #include <vector>
0017 #include <cassert>
0018 #include <stdexcept>
0019 #include <set>
0020 
0021 using namespace std;
0022 using namespace pos::PortCardSettingNames;
0023 using namespace pos;
0024 
0025 //added by Umesh
0026 PixelPortCardConfig::PixelPortCardConfig(vector<vector<string> > &tableMat) : PixelConfigBase(" ", " ", " ") {
0027   string mthn = "]\t[PixelPortCardConfig::PixelPortCardConfig()]\t\t    ";
0028   map<string, int> colM;
0029   vector<string> colNames;
0030 
0031   /** 
0032       EXTENSION_TABLE_NAME: PIXEL_PORTCARD_SETTINGS (VIEW: CONF_KEY_PORTCARD_SETTINGS_V)
0033 
0034       CONFIG_KEY                NOT NULL VARCHAR2(80)
0035       KEY_TYPE                  NOT NULL VARCHAR2(80)
0036       KEY_ALIAS                 NOT NULL VARCHAR2(80)
0037       VERSION                        VARCHAR2(40)
0038       KIND_OF_COND              NOT NULL VARCHAR2(40)
0039       PORT_CARD                 NOT NULL VARCHAR2(200)
0040       TRKFEC                    NOT NULL VARCHAR2(200)
0041       RING                  NOT NULL NUMBER(38)
0042       CHANNEL                   NOT NULL NUMBER(38)
0043       CCU_ADDR                  NOT NULL NUMBER(38)
0044       I2C_CNTRL                      NUMBER(38)
0045       I2C_SPEED                 NOT NULL NUMBER(38)
0046       AOH_BIAS1                      NUMBER(38)
0047       AOH_BIAS2                      NUMBER(38)
0048       AOH_BIAS3                      NUMBER(38)
0049       AOH_BIAS4                      NUMBER(38)
0050       AOH_BIAS5                      NUMBER(38)
0051       AOH_BIAS6                      NUMBER(38)
0052       AOH_GAIN1                      NUMBER(38)
0053       AOH_GAIN2                      NUMBER(38)
0054       AOH_GAIN3                      NUMBER(38)
0055       AOH_GAIN4                      NUMBER(38)
0056       AOH_GAIN5                      NUMBER(38)
0057       AOH_GAIN6                      NUMBER(38)
0058       AOH1_BIAS1                     NUMBER(38)
0059       AOH1_BIAS2                     NUMBER(38)
0060       AOH1_BIAS3                     NUMBER(38)
0061       AOH1_BIAS4                     NUMBER(38)
0062       AOH1_BIAS5                     NUMBER(38)
0063       AOH1_BIAS6                     NUMBER(38)
0064       AOH1_GAIN1                     NUMBER(38)
0065       AOH1_GAIN2                     NUMBER(38)
0066       AOH1_GAIN3                     NUMBER(38)
0067       AOH1_GAIN4                     NUMBER(38)
0068       AOH1_GAIN5                     NUMBER(38)
0069       AOH1_GAIN6                     NUMBER(38)
0070       AOH2_BIAS1                     NUMBER(38)
0071       AOH2_BIAS2                     NUMBER(38)
0072       AOH2_BIAS3                     NUMBER(38)
0073       AOH2_BIAS4                     NUMBER(38)
0074       AOH2_BIAS5                     NUMBER(38)
0075       AOH2_BIAS6                     NUMBER(38)
0076       AOH2_GAIN1                     NUMBER(38)
0077       AOH2_GAIN2                     NUMBER(38)
0078       AOH2_GAIN3                     NUMBER(38)
0079       AOH2_GAIN4                     NUMBER(38)
0080       AOH2_GAIN5                     NUMBER(38)
0081       AOH2_GAIN6                     NUMBER(38)
0082       AOH3_BIAS1                     NUMBER(38)
0083       AOH3_BIAS2                     NUMBER(38)
0084       AOH3_BIAS3                     NUMBER(38)
0085       AOH3_BIAS4                     NUMBER(38)
0086       AOH3_BIAS5                     NUMBER(38)
0087       AOH3_BIAS6                     NUMBER(38)
0088       AOH3_GAIN1                     NUMBER(38)
0089       AOH3_GAIN2                     NUMBER(38)
0090       AOH3_GAIN3                     NUMBER(38)
0091       AOH3_GAIN4                     NUMBER(38)
0092       AOH3_GAIN5                     NUMBER(38)
0093       AOH3_GAIN6                     NUMBER(38)
0094       AOH4_BIAS1                     NUMBER(38)
0095       AOH4_BIAS2                     NUMBER(38)
0096       AOH4_BIAS3                     NUMBER(38)
0097       AOH4_BIAS4                     NUMBER(38)
0098       AOH4_BIAS5                     NUMBER(38)
0099       AOH4_BIAS6                     NUMBER(38)
0100       AOH4_GAIN1                     NUMBER(38)
0101       AOH4_GAIN2                     NUMBER(38)
0102       AOH4_GAIN3                     NUMBER(38)
0103       AOH4_GAIN4                     NUMBER(38)
0104       AOH4_GAIN5                     NUMBER(38)
0105       AOH4_GAIN6                     NUMBER(38)
0106       DELAY25_GCR               NOT NULL NUMBER(38)
0107       DELAY25_SCL               NOT NULL NUMBER(38)
0108       DELAY25_TRG               NOT NULL NUMBER(38)
0109       DELAY25_SDA               NOT NULL NUMBER(38)
0110       DELAY25_RCL               NOT NULL NUMBER(38)
0111       DELAY25_RDA               NOT NULL NUMBER(38)
0112       DOH_BIAS0                 NOT NULL NUMBER(38)
0113       DOH_BIAS1                 NOT NULL NUMBER(38)
0114       DOH_SEU_GAIN              NOT NULL NUMBER(38)
0115       PLL_CTR1                       NUMBER(38)
0116       PLL_CTR2                       NUMBER(38)
0117       PLL_CTR3                       NUMBER(38)
0118       PLL_CTR4                       NUMBER(38)
0119       PLL_CTR5                       NUMBER(38)
0120   */
0121 
0122   colNames.push_back("CONFIG_KEY");
0123   colNames.push_back("KEY_TYPE");
0124   colNames.push_back("KEY_ALIAS");
0125   colNames.push_back("VERSION");
0126   colNames.push_back("KIND_OF_COND");
0127   colNames.push_back("PORT_CARD");
0128   colNames.push_back("TRKFEC");
0129   colNames.push_back("RING");
0130   colNames.push_back("CHANNEL");
0131   colNames.push_back("CCU_ADDR");
0132   colNames.push_back("I2C_CNTRL");
0133   colNames.push_back("I2C_SPEED");
0134   colNames.push_back("AOH_BIAS1");
0135   colNames.push_back("AOH_BIAS2");
0136   colNames.push_back("AOH_BIAS3");
0137   colNames.push_back("AOH_BIAS4");
0138   colNames.push_back("AOH_BIAS5");
0139   colNames.push_back("AOH_BIAS6");
0140   colNames.push_back("AOH_GAIN1");
0141   colNames.push_back("AOH_GAIN2");
0142   colNames.push_back("AOH_GAIN3");
0143   colNames.push_back("AOH_GAIN4");
0144   colNames.push_back("AOH_GAIN5");
0145   colNames.push_back("AOH_GAIN6");
0146   colNames.push_back("AOH1_BIAS1");
0147   colNames.push_back("AOH1_BIAS2");
0148   colNames.push_back("AOH1_BIAS3");
0149   colNames.push_back("AOH1_BIAS4");
0150   colNames.push_back("AOH1_BIAS5");
0151   colNames.push_back("AOH1_BIAS6");
0152   colNames.push_back("AOH1_GAIN1");
0153   colNames.push_back("AOH1_GAIN2");
0154   colNames.push_back("AOH1_GAIN3");
0155   colNames.push_back("AOH1_GAIN4");
0156   colNames.push_back("AOH1_GAIN5");
0157   colNames.push_back("AOH1_GAIN6");
0158   colNames.push_back("AOH2_BIAS1");
0159   colNames.push_back("AOH2_BIAS2");
0160   colNames.push_back("AOH2_BIAS3");
0161   colNames.push_back("AOH2_BIAS4");
0162   colNames.push_back("AOH2_BIAS5");
0163   colNames.push_back("AOH2_BIAS6");
0164   colNames.push_back("AOH2_GAIN1");
0165   colNames.push_back("AOH2_GAIN2");
0166   colNames.push_back("AOH2_GAIN3");
0167   colNames.push_back("AOH2_GAIN4");
0168   colNames.push_back("AOH2_GAIN5");
0169   colNames.push_back("AOH2_GAIN6");
0170   colNames.push_back("AOH3_BIAS1");
0171   colNames.push_back("AOH3_BIAS2");
0172   colNames.push_back("AOH3_BIAS3");
0173   colNames.push_back("AOH3_BIAS4");
0174   colNames.push_back("AOH3_BIAS5");
0175   colNames.push_back("AOH3_BIAS6");
0176   colNames.push_back("AOH3_GAIN1");
0177   colNames.push_back("AOH3_GAIN2");
0178   colNames.push_back("AOH3_GAIN3");
0179   colNames.push_back("AOH3_GAIN4");
0180   colNames.push_back("AOH3_GAIN5");
0181   colNames.push_back("AOH3_GAIN6");
0182   colNames.push_back("AOH4_BIAS1");
0183   colNames.push_back("AOH4_BIAS2");
0184   colNames.push_back("AOH4_BIAS3");
0185   colNames.push_back("AOH4_BIAS4");
0186   colNames.push_back("AOH4_BIAS5");
0187   colNames.push_back("AOH4_BIAS6");
0188   colNames.push_back("AOH4_GAIN1");
0189   colNames.push_back("AOH4_GAIN2");
0190   colNames.push_back("AOH4_GAIN3");
0191   colNames.push_back("AOH4_GAIN4");
0192   colNames.push_back("AOH4_GAIN5");
0193   colNames.push_back("AOH4_GAIN6");
0194   colNames.push_back("DELAY25_GCR");
0195   colNames.push_back("DELAY25_SCL");
0196   colNames.push_back("DELAY25_TRG");
0197   colNames.push_back("DELAY25_SDA");
0198   colNames.push_back("DELAY25_RCL");
0199   colNames.push_back("DELAY25_RDA");
0200   colNames.push_back("DOH_BIAS0");
0201   colNames.push_back("DOH_BIAS1");
0202   colNames.push_back("DOH_SEU_GAIN");
0203   colNames.push_back("PLL_CTR1");
0204   colNames.push_back("PLL_CTR2");
0205   colNames.push_back("PLL_CTR3");
0206   colNames.push_back("PLL_CTR4");
0207   colNames.push_back("PLL_CTR5");
0208 
0209   //these are arbitrary integers that control the sort order
0210   unsigned int othercount = 100;
0211   unsigned int delay25count = 50;
0212   aohcount_ = 1000;
0213   unsigned int pllcount = 1;
0214 
0215   for (unsigned int c = 0; c < tableMat[0].size(); c++) {
0216     for (unsigned int n = 0; n < colNames.size(); n++) {
0217       if (tableMat[0][c] == colNames[n]) {
0218         colM[colNames[n]] = c;
0219         break;
0220       }
0221     }
0222   }  //end for
0223   for (unsigned int n = 0; n < colNames.size(); n++) {
0224     if (colM.find(colNames[n]) == colM.end()) {
0225       std::cerr << __LINE__ << mthn << "\tCouldn't find in the database the column with name " << colNames[n]
0226                 << std::endl;
0227       assert(0);
0228     }
0229   }
0230 
0231   portcardname_ = tableMat[1][colM["PORT_CARD"]];
0232   //  cout << __LINE__ << mthn << "Loading PortCard " << portcardname_ << endl ;
0233   if (portcardname_.find("FPix") != std::string::npos) {
0234     type_ = "fpix";
0235   } else if (portcardname_.find("BPix") != std::string::npos) {
0236     type_ = "bpix";
0237   }
0238   fillNameToAddress();
0239   fillDBToFileAddress();
0240 
0241   TKFECID_ = tableMat[1][colM["TRKFEC"]];
0242   ringAddress_ = atoi(tableMat[1][colM["RING"]].c_str());
0243   ccuAddress_ = atoi(tableMat[1][colM["CCU_ADDR"]].c_str());
0244   channelAddress_ = atoi(tableMat[1][colM["CHANNEL"]].c_str());
0245   i2cSpeed_ = atoi(tableMat[1][colM["I2C_SPEED"]].c_str());
0246   /*
0247   cout << __LINE__ << "]\t" << mthn << 
0248     "ringAddress_\t"    << ringAddress_     << endl <<
0249     "ccuAddress_\t"     << ccuAddress_      << endl <<
0250     "channelAddress_\t" << channelAddress_  << endl <<
0251     "i2cSpeed_\t"   << i2cSpeed_        << endl ;
0252  */
0253 
0254   for (unsigned int col = 0; col < tableMat[1].size(); col++)  //Goes to every column of the Matrix
0255   {
0256     std::string settingName;
0257     unsigned int i2c_address;
0258     unsigned int i2c_values;
0259 
0260     settingName = tableMat[0][col];
0261     i2c_values = atoi(tableMat[1][col].c_str());
0262 
0263     // Special handling for AOHX_GainY
0264     if (type_ == "fpix" && settingName.find("AOH_") != string::npos &&
0265         settingName.find("GAIN") != string::npos  // contains both "AOH_" and "Gain"
0266         && settingName.find("123") == string::npos &&
0267         settingName.find("456") == string::npos)  // does not contain "123" or "456"
0268     {
0269       setDataBaseAOHGain(settingName, i2c_values);
0270       //      cout << __LINE__ << "]\t" << mthn << "Setting " << settingName << "\tto value " << std::hex << i2c_values << std::dec << std::endl ;
0271     } else if (type_ == "bpix" && settingName.find("AOH") != string::npos &&
0272                settingName.find("GAIN") != string::npos     // contains both "AOH" and "Gain"
0273                && settingName.find("AOH_") == string::npos  // must not contain AOH_ 'cause this is for forward
0274                && settingName.find("123") == string::npos &&
0275                settingName.find("456") == string::npos)  // does not contain "123" or "456"
0276     {
0277       if (portcardname_.find("PRT2") != std::string::npos &&
0278           (settingName.find("AOH3_") != std::string::npos || settingName.find("AOH4_") != std::string::npos))
0279         continue;
0280       setDataBaseAOHGain(settingName, i2c_values);
0281       //      cout << __LINE__ << "]\t" << mthn << "Setting " << settingName << "\tto value " << std::hex << i2c_values << std::dec << std::endl ;
0282     }
0283     // FIXMR
0284     else if (settingName == k_PLL_CTR5)  // special handling
0285     {
0286       unsigned int last_CTR2 = 0x0;
0287       if (containsSetting(k_PLL_CTR2))
0288         last_CTR2 = getdeviceValuesForSetting(k_PLL_CTR2);
0289 
0290       device_.push_back(make_pair(getdeviceAddressForSetting(k_PLL_CTR2), new_PLL_CTR2_value(settingName, last_CTR2)));
0291       device_.push_back(make_pair(getdeviceAddressForSetting(k_PLL_CTR4or5), i2c_values));
0292 
0293       key_.push_back(pllcount++);  //these are arbitrary integers that control the sort order
0294       key_.push_back(pllcount++);
0295     }
0296     // FIXMR
0297     else  // no special handling for this name
0298     {
0299       if ((settingName.find("DELAY25_") != std::string::npos) || (settingName.find("_BIAS") != std::string::npos) ||
0300           (settingName.find("PLL_CTR2") != std::string::npos) || (settingName.find("PLL_CTR5") != std::string::npos) ||
0301           ((settingName.find("DOH_SEU_GAIN") != std::string::npos) && type_ == "bpix"))
0302       //Note that DOH_SEU_GAIN will be *ignored* for fpix
0303       {
0304         map<string, string>::iterator iter = nameDBtoFileConversion_.find(settingName);
0305         if (iter == nameDBtoFileConversion_.end())
0306           continue;
0307         map<string, unsigned int>::iterator foundName_itr = nameToAddress_.find(nameDBtoFileConversion_[settingName]);
0308 
0309         if (foundName_itr != nameToAddress_.end()) {
0310           if (portcardname_.find("PRT2") != std::string::npos &&
0311               (settingName.find("AOH3_") != std::string::npos || settingName.find("AOH4_") != std::string::npos))
0312             continue;
0313           i2c_address = foundName_itr->second;
0314         } else {
0315           i2c_address = strtoul(settingName.c_str(), nullptr, 16);  // convert string to integer using base 16
0316         }
0317         if (type_ == "fpix" &&
0318             (settingName.find("AOH1_") != std::string::npos || settingName.find("AOH2_") != std::string::npos ||
0319              settingName.find("AOH3_") != std::string::npos || settingName.find("AOH4_") != std::string::npos))
0320           continue;
0321 
0322         pair<unsigned int, unsigned int> p(i2c_address, i2c_values);
0323         /*
0324           cout << __LINE__ 
0325                << mthn << "Setting\t" 
0326            << "|"
0327            << settingName
0328            << "|->"
0329            << nameDBtoFileConversion_[settingName] 
0330            << "\twith pair:\t(" 
0331            << i2c_address
0332            << ","
0333            << i2c_values
0334            << ")"
0335            << endl ;
0336           */
0337         device_.push_back(p);
0338         if (settingName.find("AOH") != string::npos)
0339           key_.push_back(aohcount_++);
0340         else if (settingName.find("Delay25") != string::npos)
0341           key_.push_back(delay25count++);
0342         else if (settingName.find("PLL") != string::npos)
0343           key_.push_back(pllcount++);
0344         else
0345           key_.push_back(othercount++);
0346       }
0347     }
0348   }  // End of table columns
0349 
0350   sortDeviceList();
0351 }
0352 
0353 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
0354 PixelPortCardConfig::PixelPortCardConfig(std::string filename) : PixelConfigBase(" ", " ", " ") {
0355   string mthn = "[PixelPortCardConfig::PixelPortCardConfig()]\t\t    ";
0356   //std::cout << __LINE__ << "]\t" << mthn << "filename:"<<filename<<std::endl;
0357 
0358   size_t portcardpos = filename.find(std::string("portcard_"));
0359   //std::cout << __LINE__ << "]\t" << mthn << "portcardpos:"<<portcardpos<<std::endl;
0360   assert(portcardpos != (unsigned int)std::string::npos);
0361   size_t datpos = filename.find(std::string(".dat"));
0362   //std::cout << __LINE__ << "]\t" << mthn << "datpos:"<<datpos<<std::endl;
0363   assert(datpos != (unsigned int)std::string::npos);
0364   assert(datpos > portcardpos);
0365 
0366   portcardname_ = filename.substr(portcardpos + 9, datpos - portcardpos - 9);
0367 
0368   //std::cout << "Portcard name extracted from file name:"<<portcardname_<<std::endl;
0369 
0370   std::ifstream in(filename.c_str());
0371 
0372   if (!in.good()) {
0373     std::cout << __LINE__ << "]\t" << mthn << "Could not open: " << filename << std::endl;
0374     throw std::runtime_error("Failed to open file " + filename);
0375   } else {
0376     std::cout << __LINE__ << "]\t" << mthn << "Opened: " << filename << std::endl;
0377   }
0378 
0379   string dummy;
0380 
0381   in >> dummy;
0382   if (dummy == "Name:")  // check that port card name matches the file name
0383   {
0384     in >> dummy;
0385     assert(dummy == portcardname_);
0386     in >> dummy;
0387   }
0388   if (dummy == "Type:")  // read in the type, defaulting to "fpix" if not specified
0389   {
0390     in >> type_;
0391     assert(type_ == "fpix" || type_ == "bpix");
0392     in >> dummy;
0393   } else {
0394     type_ = "fpix";
0395   }
0396   fillNameToAddress();
0397   fillDBToFileAddress();
0398   assert(dummy == "TKFECID:");
0399   in >> TKFECID_;
0400   in >> dummy;
0401   assert(dummy == "ringAddress:");
0402   in >> std::hex >> ringAddress_;
0403   in >> dummy;
0404   assert(dummy == "ccuAddress:");
0405   in >> std::hex >> ccuAddress_;
0406   in >> dummy;
0407   assert(dummy == "channelAddress:");
0408   in >> std::hex >> channelAddress_;
0409   in >> dummy;
0410   assert(dummy == "i2cSpeed:");
0411   in >> std::hex >> i2cSpeed_;
0412 
0413   //std::cout << __LINE__ << "]\t" << mthn
0414   //          <<TKFECAddress_<<", "<<ringAddress_<<", "<<ccuAddress_<<", "<<channelAddress_<<", "<<i2cSpeed_<<std::endl;
0415 
0416   assert(!nameToAddress_.empty());
0417   do {
0418     std::string settingName;
0419     unsigned int i2c_address;
0420     unsigned int i2c_values;
0421 
0422     in >> settingName >> std::hex >> i2c_values >> std::dec;
0423     if (in.eof())
0424       break;
0425 
0426     if (settingName[settingName.size() - 1] == ':')
0427       settingName.resize(settingName.size() - 1);  // remove ':' from end of string, if it's there
0428 
0429     // Special handling for AOHX_GainY
0430     if (settingName.find("AOH") != string::npos &&
0431         settingName.find("Gain") != string::npos  // contains both "AOH" and "Gain"
0432         && settingName.find("123") == string::npos &&
0433         settingName.find("456") == string::npos)  // does not contain "123" or "456"
0434     {
0435       setAOHGain(settingName, i2c_values);
0436     } else if (settingName == k_PLL_CTR4 || settingName == k_PLL_CTR5)  // special handling
0437     {
0438       unsigned int last_CTR2 = 0x0;
0439       if (containsSetting(k_PLL_CTR2))
0440         last_CTR2 = getdeviceValuesForSetting(k_PLL_CTR2);
0441 
0442       device_.push_back(make_pair(getdeviceAddressForSetting(k_PLL_CTR2), new_PLL_CTR2_value(settingName, last_CTR2)));
0443       device_.push_back(make_pair(getdeviceAddressForSetting(k_PLL_CTR4or5), i2c_values));
0444     } else  // no special handling for this name
0445     {
0446       std::map<std::string, unsigned int>::iterator foundName_itr = nameToAddress_.find(settingName);
0447 
0448       if (foundName_itr != nameToAddress_.end()) {
0449         i2c_address = foundName_itr->second;
0450       } else {
0451         i2c_address = strtoul(settingName.c_str(), nullptr, 16);  // convert string to integer using base 16
0452       }
0453       pair<unsigned int, unsigned int> p(i2c_address, i2c_values);
0454       device_.push_back(p);
0455     }
0456   } while (!in.eof());
0457 
0458   in.close();
0459 }
0460 
0461 void PixelPortCardConfig::sortDeviceList() {
0462   std::set<pair<unsigned int, pair<unsigned int, unsigned int> > > sorted;
0463 
0464   for (unsigned int i = 0; i < device_.size(); i++) {
0465     //cout<<key_.at(i)<<"\t"<<device_.at(i).first<<"  "<<device_.at(i).second<<endl;
0466     sorted.insert(make_pair(key_.at(i), device_.at(i)));
0467   }
0468 
0469   //  cout<<" -=-=-=-= done with sorting -=-=-="<<endl;
0470   device_.clear();
0471   for (set<pair<unsigned int, pair<unsigned int, unsigned int> > >::iterator i = sorted.begin(); i != sorted.end();
0472        ++i) {
0473     device_.push_back(i->second);
0474   }
0475 
0476   //  for (unsigned int i=0; i<device_.size(); i++ ) {
0477   //    cout<<"  \t"<<device_.at(i).first<<"  "<<device_.at(i).second<<endl;
0478   //  }
0479 }
0480 
0481 unsigned int PixelPortCardConfig::new_PLL_CTR2_value(std::string CTR4or5, unsigned int last_CTR2) const {
0482   if (CTR4or5 == k_PLL_CTR4)
0483     return 0xdf & last_CTR2;
0484   else if (CTR4or5 == k_PLL_CTR5)
0485     return 0x20 | last_CTR2;
0486   else
0487     assert(0);
0488 }
0489 
0490 void PixelPortCardConfig::setAOHGain(std::string settingName, unsigned int value) {
0491   assert(settingName.find("AOH") != string::npos &&
0492          settingName.find("Gain") != string::npos  // contains both "AOH" and "Gain"
0493          && settingName.find("123") == string::npos &&
0494          settingName.find("456") == string::npos);  // does not contain "123" or "456"
0495 
0496   unsigned int i2c_address;
0497 
0498   // Get the i2c address of this AOH, and the channel on the AOH.
0499   string::size_type GainPosition = settingName.find("Gain");
0500   unsigned int whichAOH;
0501   if (settingName[GainPosition - 2] == 'H')
0502     whichAOH = 0;  // fpix
0503   else             // bpix
0504   {
0505     char whichAOHDigit[2] = {0, 0};
0506     whichAOHDigit[0] = settingName[GainPosition - 2];
0507     whichAOH = atoi(whichAOHDigit);
0508   }
0509   char digit[2] = {0, 0};
0510   digit[0] = settingName[GainPosition + 4];
0511   unsigned int channelOnAOH = atoi(digit);
0512   assert((type_ == "fpix" && whichAOH == 0) || (type_ == "bpix" && 1 <= whichAOH && whichAOH <= 4));
0513   assert(1 <= channelOnAOH && channelOnAOH <= 6);
0514 
0515   if (whichAOH == 0 && channelOnAOH <= 3)
0516     i2c_address = k_fpix_AOH_Gain123_address;
0517   else if (whichAOH == 0 && channelOnAOH >= 4)
0518     i2c_address = k_fpix_AOH_Gain456_address;
0519   else if (whichAOH == 1 && channelOnAOH <= 3)
0520     i2c_address = k_bpix_AOH1_Gain123_address;
0521   else if (whichAOH == 1 && channelOnAOH >= 4)
0522     i2c_address = k_bpix_AOH1_Gain456_address;
0523   else if (whichAOH == 2 && channelOnAOH <= 3)
0524     i2c_address = k_bpix_AOH2_Gain123_address;
0525   else if (whichAOH == 2 && channelOnAOH >= 4)
0526     i2c_address = k_bpix_AOH2_Gain456_address;
0527   else if (whichAOH == 3 && channelOnAOH <= 3)
0528     i2c_address = k_bpix_AOH3_Gain123_address;
0529   else if (whichAOH == 3 && channelOnAOH >= 4)
0530     i2c_address = k_bpix_AOH3_Gain456_address;
0531   else if (whichAOH == 4 && channelOnAOH <= 3)
0532     i2c_address = k_bpix_AOH4_Gain123_address;
0533   else if (whichAOH == 4 && channelOnAOH >= 4)
0534     i2c_address = k_bpix_AOH4_Gain456_address;
0535   else
0536     assert(0);
0537 
0538   // Search for this address in the previously-defined settings.
0539   bool foundOne = false;
0540   for (unsigned int i = 0; i < device_.size(); i++) {
0541     if (device_[i].first == i2c_address)  // Change this setting in all previous instances
0542     {
0543       foundOne = true;
0544       unsigned int oldValue = device_[i].second;
0545       if (channelOnAOH % 3 == 1)
0546         device_[i].second = (0x3c & oldValue) + ((value & 0x3) << 0);  // replace bits 0 and 1 with value
0547       else if (channelOnAOH % 3 == 2)
0548         device_[i].second = (0x33 & oldValue) + ((value & 0x3) << 2);  // replace bits 2 and 3 with value
0549       else if (channelOnAOH % 3 == 0)
0550         device_[i].second = (0x0f & oldValue) + ((value & 0x3) << 4);  // replace bits 4 and 5 with value
0551       else
0552         assert(0);
0553       //std::cout << "Changed setting "<< k_fpix_AOH_Gain123 <<"(address 0x"<<std::hex<<k_fpix_AOH_Gain123_address<<") from 0x"<<oldValue<<" to 0x"<< device_[i].second << std::dec <<"\n";
0554     }
0555   }
0556   if (foundOne)
0557     return;
0558   else  // If this was not set previously, add this setting with the other two gains set to zero.
0559   {
0560     unsigned int i2c_value;
0561     if (channelOnAOH % 3 == 1)
0562       i2c_value = ((value & 0x3) << 0);
0563     else if (channelOnAOH % 3 == 2)
0564       i2c_value = ((value & 0x3) << 2);
0565     else if (channelOnAOH % 3 == 0)
0566       i2c_value = ((value & 0x3) << 4);
0567     else
0568       assert(0);
0569 
0570     pair<unsigned int, unsigned int> p(i2c_address, i2c_value);
0571     device_.push_back(p);
0572     return;
0573   }
0574 }
0575 
0576 void PixelPortCardConfig::setDataBaseAOHGain(std::string settingName, unsigned int value) {
0577   unsigned int i2c_address;
0578 
0579   // Get the i2c address of this AOH, and the channel on the AOH.
0580   string::size_type GainPosition = settingName.find("GAIN");
0581   unsigned int whichAOH;
0582   if (type_ == "fpix") {
0583     whichAOH = 0;  // fpix
0584   } else           // bpix
0585   {
0586     char whichAOHDigit[2] = {0, 0};
0587     whichAOHDigit[0] = settingName[GainPosition - 2];
0588     whichAOH = atoi(whichAOHDigit);
0589   }
0590   char digit[2] = {0, 0};
0591   digit[0] = settingName[GainPosition + 4];
0592   unsigned int channelOnAOH = atoi(digit);
0593   assert((type_ == "fpix" && whichAOH == 0) || (type_ == "bpix" && 1 <= whichAOH && whichAOH <= 4));
0594   assert(1 <= channelOnAOH && channelOnAOH <= 6);
0595 
0596   if (whichAOH == 0 && channelOnAOH <= 3)
0597     i2c_address = k_fpix_AOH_Gain123_address;
0598   else if (whichAOH == 0 && channelOnAOH >= 4)
0599     i2c_address = k_fpix_AOH_Gain456_address;
0600   else if (whichAOH == 1 && channelOnAOH <= 3)
0601     i2c_address = k_bpix_AOH1_Gain123_address;
0602   else if (whichAOH == 1 && channelOnAOH >= 4)
0603     i2c_address = k_bpix_AOH1_Gain456_address;
0604   else if (whichAOH == 2 && channelOnAOH <= 3)
0605     i2c_address = k_bpix_AOH2_Gain123_address;
0606   else if (whichAOH == 2 && channelOnAOH >= 4)
0607     i2c_address = k_bpix_AOH2_Gain456_address;
0608   else if (whichAOH == 3 && channelOnAOH <= 3)
0609     i2c_address = k_bpix_AOH3_Gain123_address;
0610   else if (whichAOH == 3 && channelOnAOH >= 4)
0611     i2c_address = k_bpix_AOH3_Gain456_address;
0612   else if (whichAOH == 4 && channelOnAOH <= 3)
0613     i2c_address = k_bpix_AOH4_Gain123_address;
0614   else if (whichAOH == 4 && channelOnAOH >= 4)
0615     i2c_address = k_bpix_AOH4_Gain456_address;
0616   else
0617     assert(0);
0618 
0619   // Search for this address in the previously-defined settings.
0620   bool foundOne = false;
0621   for (unsigned int i = 0; i < device_.size(); i++) {
0622     if (device_[i].first == i2c_address)  // Change this setting in all previous instances
0623     {
0624       foundOne = true;
0625       unsigned int oldValue = device_[i].second;
0626       if (channelOnAOH % 3 == 1)
0627         device_[i].second = (0x3c & oldValue) + ((value & 0x3) << 0);  // replace bits 0 and 1 with value
0628       else if (channelOnAOH % 3 == 2)
0629         device_[i].second = (0x33 & oldValue) + ((value & 0x3) << 2);  // replace bits 2 and 3 with value
0630       else if (channelOnAOH % 3 == 0)
0631         device_[i].second = (0x0f & oldValue) + ((value & 0x3) << 4);  // replace bits 4 and 5 with value
0632       else
0633         assert(0);
0634       //std::cout << "Changed setting "<< k_fpix_AOH_Gain123 <<"(address 0x"<<std::hex<<k_fpix_AOH_Gain123_address<<") from 0x"<<oldValue<<" to 0x"<< device_[i].second << std::dec <<"\n";
0635     }
0636   }
0637   if (foundOne)
0638     return;
0639   else  // If this was not set previously, add this setting with the other two gains set to zero.
0640   {
0641     unsigned int i2c_value;
0642     if (channelOnAOH % 3 == 1)
0643       i2c_value = ((value & 0x3) << 0);
0644     else if (channelOnAOH % 3 == 2)
0645       i2c_value = ((value & 0x3) << 2);
0646     else if (channelOnAOH % 3 == 0)
0647       i2c_value = ((value & 0x3) << 4);
0648     else
0649       assert(0);
0650 
0651     pair<unsigned int, unsigned int> p(i2c_address, i2c_value);
0652     device_.push_back(p);
0653     key_.push_back(aohcount_++);
0654     return;
0655   }
0656 }
0657 
0658 void PixelPortCardConfig::fillNameToAddress() {
0659   if (!nameToAddress_.empty())
0660     return;
0661 
0662   if (type_ == "fpix") {
0663     nameToAddress_[PortCardSettingNames::k_AOH_Bias1] = PortCardSettingNames::k_fpix_AOH_Bias1_address;
0664     nameToAddress_[PortCardSettingNames::k_AOH_Bias2] = PortCardSettingNames::k_fpix_AOH_Bias2_address;
0665     nameToAddress_[PortCardSettingNames::k_AOH_Bias3] = PortCardSettingNames::k_fpix_AOH_Bias3_address;
0666     nameToAddress_[PortCardSettingNames::k_AOH_Bias4] = PortCardSettingNames::k_fpix_AOH_Bias4_address;
0667     nameToAddress_[PortCardSettingNames::k_AOH_Bias5] = PortCardSettingNames::k_fpix_AOH_Bias5_address;
0668     nameToAddress_[PortCardSettingNames::k_AOH_Bias6] = PortCardSettingNames::k_fpix_AOH_Bias6_address;
0669     nameToAddress_[PortCardSettingNames::k_AOH_Gain123] = PortCardSettingNames::k_fpix_AOH_Gain123_address;
0670     nameToAddress_[PortCardSettingNames::k_AOH_Gain456] = PortCardSettingNames::k_fpix_AOH_Gain456_address;
0671 
0672     nameToAddress_[PortCardSettingNames::k_PLL_CTR1] = PortCardSettingNames::k_fpix_PLL_CTR1_address;
0673     nameToAddress_[PortCardSettingNames::k_PLL_CTR2] = PortCardSettingNames::k_fpix_PLL_CTR2_address;
0674     nameToAddress_[PortCardSettingNames::k_PLL_CTR3] = PortCardSettingNames::k_fpix_PLL_CTR3_address;
0675     nameToAddress_[PortCardSettingNames::k_PLL_CTR4or5] = PortCardSettingNames::k_fpix_PLL_CTR4or5_address;
0676 
0677     nameToAddress_[PortCardSettingNames::k_Delay25_RDA] = PortCardSettingNames::k_fpix_Delay25_RDA_address;
0678     nameToAddress_[PortCardSettingNames::k_Delay25_RCL] = PortCardSettingNames::k_fpix_Delay25_RCL_address;
0679     nameToAddress_[PortCardSettingNames::k_Delay25_SDA] = PortCardSettingNames::k_fpix_Delay25_SDA_address;
0680     nameToAddress_[PortCardSettingNames::k_Delay25_TRG] = PortCardSettingNames::k_fpix_Delay25_TRG_address;
0681     nameToAddress_[PortCardSettingNames::k_Delay25_SCL] = PortCardSettingNames::k_fpix_Delay25_SCL_address;
0682     nameToAddress_[PortCardSettingNames::k_Delay25_GCR] = PortCardSettingNames::k_fpix_Delay25_GCR_address;
0683 
0684     nameToAddress_[PortCardSettingNames::k_DOH_Ch0Bias_CLK] = PortCardSettingNames::k_fpix_DOH_Ch0Bias_CLK_address;
0685     nameToAddress_[PortCardSettingNames::k_DOH_Dummy] = PortCardSettingNames::k_fpix_DOH_Dummy_address;
0686     nameToAddress_[PortCardSettingNames::k_DOH_Ch1Bias_Data] = PortCardSettingNames::k_fpix_DOH_Ch1Bias_Data_address;
0687     nameToAddress_[PortCardSettingNames::k_DOH_Gain_SEU] = PortCardSettingNames::k_fpix_DOH_Gain_SEU_address;
0688   } else if (type_ == "bpix") {
0689     nameToAddress_[PortCardSettingNames::k_AOH1_Bias1] = PortCardSettingNames::k_bpix_AOH1_Bias1_address;
0690     nameToAddress_[PortCardSettingNames::k_AOH1_Bias2] = PortCardSettingNames::k_bpix_AOH1_Bias2_address;
0691     nameToAddress_[PortCardSettingNames::k_AOH1_Bias3] = PortCardSettingNames::k_bpix_AOH1_Bias3_address;
0692     nameToAddress_[PortCardSettingNames::k_AOH1_Bias4] = PortCardSettingNames::k_bpix_AOH1_Bias4_address;
0693     nameToAddress_[PortCardSettingNames::k_AOH1_Bias5] = PortCardSettingNames::k_bpix_AOH1_Bias5_address;
0694     nameToAddress_[PortCardSettingNames::k_AOH1_Bias6] = PortCardSettingNames::k_bpix_AOH1_Bias6_address;
0695     nameToAddress_[PortCardSettingNames::k_AOH1_Gain123] = PortCardSettingNames::k_bpix_AOH1_Gain123_address;
0696     nameToAddress_[PortCardSettingNames::k_AOH1_Gain456] = PortCardSettingNames::k_bpix_AOH1_Gain456_address;
0697 
0698     nameToAddress_[PortCardSettingNames::k_AOH2_Bias1] = PortCardSettingNames::k_bpix_AOH2_Bias1_address;
0699     nameToAddress_[PortCardSettingNames::k_AOH2_Bias2] = PortCardSettingNames::k_bpix_AOH2_Bias2_address;
0700     nameToAddress_[PortCardSettingNames::k_AOH2_Bias3] = PortCardSettingNames::k_bpix_AOH2_Bias3_address;
0701     nameToAddress_[PortCardSettingNames::k_AOH2_Bias4] = PortCardSettingNames::k_bpix_AOH2_Bias4_address;
0702     nameToAddress_[PortCardSettingNames::k_AOH2_Bias5] = PortCardSettingNames::k_bpix_AOH2_Bias5_address;
0703     nameToAddress_[PortCardSettingNames::k_AOH2_Bias6] = PortCardSettingNames::k_bpix_AOH2_Bias6_address;
0704     nameToAddress_[PortCardSettingNames::k_AOH2_Gain123] = PortCardSettingNames::k_bpix_AOH2_Gain123_address;
0705     nameToAddress_[PortCardSettingNames::k_AOH2_Gain456] = PortCardSettingNames::k_bpix_AOH2_Gain456_address;
0706 
0707     nameToAddress_[PortCardSettingNames::k_AOH3_Bias1] = PortCardSettingNames::k_bpix_AOH3_Bias1_address;
0708     nameToAddress_[PortCardSettingNames::k_AOH3_Bias2] = PortCardSettingNames::k_bpix_AOH3_Bias2_address;
0709     nameToAddress_[PortCardSettingNames::k_AOH3_Bias3] = PortCardSettingNames::k_bpix_AOH3_Bias3_address;
0710     nameToAddress_[PortCardSettingNames::k_AOH3_Bias4] = PortCardSettingNames::k_bpix_AOH3_Bias4_address;
0711     nameToAddress_[PortCardSettingNames::k_AOH3_Bias5] = PortCardSettingNames::k_bpix_AOH3_Bias5_address;
0712     nameToAddress_[PortCardSettingNames::k_AOH3_Bias6] = PortCardSettingNames::k_bpix_AOH3_Bias6_address;
0713     nameToAddress_[PortCardSettingNames::k_AOH3_Gain123] = PortCardSettingNames::k_bpix_AOH3_Gain123_address;
0714     nameToAddress_[PortCardSettingNames::k_AOH3_Gain456] = PortCardSettingNames::k_bpix_AOH3_Gain456_address;
0715 
0716     nameToAddress_[PortCardSettingNames::k_AOH4_Bias1] = PortCardSettingNames::k_bpix_AOH4_Bias1_address;
0717     nameToAddress_[PortCardSettingNames::k_AOH4_Bias2] = PortCardSettingNames::k_bpix_AOH4_Bias2_address;
0718     nameToAddress_[PortCardSettingNames::k_AOH4_Bias3] = PortCardSettingNames::k_bpix_AOH4_Bias3_address;
0719     nameToAddress_[PortCardSettingNames::k_AOH4_Bias4] = PortCardSettingNames::k_bpix_AOH4_Bias4_address;
0720     nameToAddress_[PortCardSettingNames::k_AOH4_Bias5] = PortCardSettingNames::k_bpix_AOH4_Bias5_address;
0721     nameToAddress_[PortCardSettingNames::k_AOH4_Bias6] = PortCardSettingNames::k_bpix_AOH4_Bias6_address;
0722     nameToAddress_[PortCardSettingNames::k_AOH4_Gain123] = PortCardSettingNames::k_bpix_AOH4_Gain123_address;
0723     nameToAddress_[PortCardSettingNames::k_AOH4_Gain456] = PortCardSettingNames::k_bpix_AOH4_Gain456_address;
0724 
0725     nameToAddress_[PortCardSettingNames::k_PLL_CTR1] = PortCardSettingNames::k_bpix_PLL_CTR1_address;
0726     nameToAddress_[PortCardSettingNames::k_PLL_CTR2] = PortCardSettingNames::k_bpix_PLL_CTR2_address;
0727     nameToAddress_[PortCardSettingNames::k_PLL_CTR3] = PortCardSettingNames::k_bpix_PLL_CTR3_address;
0728     nameToAddress_[PortCardSettingNames::k_PLL_CTR4or5] = PortCardSettingNames::k_bpix_PLL_CTR4or5_address;
0729 
0730     nameToAddress_[PortCardSettingNames::k_Delay25_RDA] = PortCardSettingNames::k_bpix_Delay25_RDA_address;
0731     nameToAddress_[PortCardSettingNames::k_Delay25_RCL] = PortCardSettingNames::k_bpix_Delay25_RCL_address;
0732     nameToAddress_[PortCardSettingNames::k_Delay25_SDA] = PortCardSettingNames::k_bpix_Delay25_SDA_address;
0733     nameToAddress_[PortCardSettingNames::k_Delay25_TRG] = PortCardSettingNames::k_bpix_Delay25_TRG_address;
0734     nameToAddress_[PortCardSettingNames::k_Delay25_SCL] = PortCardSettingNames::k_bpix_Delay25_SCL_address;
0735     nameToAddress_[PortCardSettingNames::k_Delay25_GCR] = PortCardSettingNames::k_bpix_Delay25_GCR_address;
0736 
0737     nameToAddress_[PortCardSettingNames::k_DOH_Ch0Bias_CLK] = PortCardSettingNames::k_bpix_DOH_Ch0Bias_CLK_address;
0738     nameToAddress_[PortCardSettingNames::k_DOH_Dummy] = PortCardSettingNames::k_bpix_DOH_Dummy_address;
0739     nameToAddress_[PortCardSettingNames::k_DOH_Ch1Bias_Data] = PortCardSettingNames::k_bpix_DOH_Ch1Bias_Data_address;
0740     nameToAddress_[PortCardSettingNames::k_DOH_Gain_SEU] = PortCardSettingNames::k_bpix_DOH_Gain_SEU_address;
0741   } else
0742     assert(0);
0743 
0744   return;
0745 }
0746 
0747 void PixelPortCardConfig::fillDBToFileAddress() {
0748   if (type_ == "fpix") {
0749     //   nameDBtoFileConversion_["CONFIG_KEY_ID"         ] = ;
0750     //   nameDBtoFileConversion_["CONFIG_KEY"            ] = ;
0751     //   nameDBtoFileConversion_["VERSION"               ] = ;
0752     //   nameDBtoFileConversion_["CONDITION_DATA_SET_ID" ] = ;
0753     //   nameDBtoFileConversion_["KIND_OF_CONDITION_ID"  ] = ;
0754     //   nameDBtoFileConversion_["KIND_OF_COND"          ] = ;
0755     //   nameDBtoFileConversion_["SERIAL_NUMBER"         ] = ;
0756     //   nameDBtoFileConversion_["PORT_CARD_ID"          ] = ;
0757     //   nameDBtoFileConversion_["PORT_CARD"             ] = ;
0758     //   nameDBtoFileConversion_["TRKFEC_NAME"           ] = ;
0759     //   nameDBtoFileConversion_["RINGADDRESS"           ] = ;
0760     //   nameDBtoFileConversion_["CHANNELADDRESS"        ] = ;
0761     //   nameDBtoFileConversion_["CCUADDRESS"            ] = ;
0762     //   nameDBtoFileConversion_["I2C_CNTRL"             ] = ;
0763     //   nameDBtoFileConversion_["I2CSPEED"              ] = ;
0764     nameDBtoFileConversion_["AOH_BIAS1"] = k_AOH_Bias1;
0765     nameDBtoFileConversion_["AOH_BIAS2"] = k_AOH_Bias2;
0766     nameDBtoFileConversion_["AOH_BIAS3"] = k_AOH_Bias3;
0767     nameDBtoFileConversion_["AOH_BIAS4"] = k_AOH_Bias4;
0768     nameDBtoFileConversion_["AOH_BIAS5"] = k_AOH_Bias5;
0769     nameDBtoFileConversion_["AOH_BIAS6"] = k_AOH_Bias6;
0770     nameDBtoFileConversion_["AOH1_BIAS1"] = k_AOH1_Bias1;
0771     nameDBtoFileConversion_["AOH1_BIAS2"] = k_AOH1_Bias2;
0772     nameDBtoFileConversion_["AOH1_BIAS3"] = k_AOH1_Bias3;
0773     nameDBtoFileConversion_["AOH1_BIAS4"] = k_AOH1_Bias4;
0774     nameDBtoFileConversion_["AOH1_BIAS5"] = k_AOH1_Bias5;
0775     nameDBtoFileConversion_["AOH1_BIAS6"] = k_AOH1_Bias6;
0776     //       nameDBtoFileConversion_["AOH1_GAIN1"             ] = ;
0777     //       nameDBtoFileConversion_["AOH1_GAIN2"             ] = ;
0778     //       nameDBtoFileConversion_["AOH1_GAIN3"             ] = ;
0779     //       nameDBtoFileConversion_["AOH1_GAIN4"             ] = ;
0780     //       nameDBtoFileConversion_["AOH1_GAIN5"             ] = ;
0781     //       nameDBtoFileConversion_["AOH1_GAIN6"             ] = ;
0782     nameDBtoFileConversion_["AOH2_BIAS1"] = k_AOH2_Bias1;
0783     nameDBtoFileConversion_["AOH2_BIAS2"] = k_AOH2_Bias2;
0784     nameDBtoFileConversion_["AOH2_BIAS3"] = k_AOH2_Bias3;
0785     nameDBtoFileConversion_["AOH2_BIAS4"] = k_AOH2_Bias4;
0786     nameDBtoFileConversion_["AOH2_BIAS5"] = k_AOH2_Bias5;
0787     nameDBtoFileConversion_["AOH2_BIAS6"] = k_AOH2_Bias6;
0788     //       nameDBtoFileConversion_["AOH2_GAIN1"             ] = ;
0789     //       nameDBtoFileConversion_["AOH2_GAIN2"             ] = ;
0790     //       nameDBtoFileConversion_["AOH2_GAIN3"             ] = ;
0791     //       nameDBtoFileConversion_["AOH2_GAIN4"             ] = ;
0792     //       nameDBtoFileConversion_["AOH2_GAIN5"             ] = ;
0793     //       nameDBtoFileConversion_["AOH2_GAIN6"             ] = ;
0794     nameDBtoFileConversion_["AOH3_BIAS1"] = k_AOH3_Bias1;
0795     nameDBtoFileConversion_["AOH3_BIAS2"] = k_AOH3_Bias2;
0796     nameDBtoFileConversion_["AOH3_BIAS3"] = k_AOH3_Bias3;
0797     nameDBtoFileConversion_["AOH3_BIAS4"] = k_AOH3_Bias4;
0798     nameDBtoFileConversion_["AOH3_BIAS5"] = k_AOH3_Bias5;
0799     nameDBtoFileConversion_["AOH3_BIAS6"] = k_AOH3_Bias6;
0800     //       nameDBtoFileConversion_["AOH3_GAIN1"             ] = ;
0801     //       nameDBtoFileConversion_["AOH3_GAIN2"             ] = ;
0802     //       nameDBtoFileConversion_["AOH3_GAIN3"             ] = ;
0803     //       nameDBtoFileConversion_["AOH3_GAIN4"             ] = ;
0804     //       nameDBtoFileConversion_["AOH3_GAIN5"             ] = ;
0805     //       nameDBtoFileConversion_["AOH3_GAIN6"             ] = ;
0806     nameDBtoFileConversion_["AOH4_BIAS1"] = k_AOH4_Bias1;
0807     nameDBtoFileConversion_["AOH4_BIAS2"] = k_AOH4_Bias2;
0808     nameDBtoFileConversion_["AOH4_BIAS3"] = k_AOH4_Bias3;
0809     nameDBtoFileConversion_["AOH4_BIAS4"] = k_AOH4_Bias4;
0810     nameDBtoFileConversion_["AOH4_BIAS5"] = k_AOH4_Bias5;
0811     nameDBtoFileConversion_["AOH4_BIAS6"] = k_AOH4_Bias6;
0812     //       nameDBtoFileConversion_["AOH4_GAIN1"             ] = ;
0813     //       nameDBtoFileConversion_["AOH4_GAIN2"             ] = ;
0814     //       nameDBtoFileConversion_["AOH4_GAIN3"             ] = ;
0815     //       nameDBtoFileConversion_["AOH4_GAIN4"             ] = ;
0816     //       nameDBtoFileConversion_["AOH4_GAIN5"             ] = ;
0817     //       nameDBtoFileConversion_["AOH4_GAIN6"             ] = ;
0818     //       nameDBtoFileConversion_["AOH5_BIAS1"             ] = ;
0819     //       nameDBtoFileConversion_["AOH5_BIAS2"             ] = ;
0820     //       nameDBtoFileConversion_["AOH5_BIAS3"             ] = ;
0821     //       nameDBtoFileConversion_["AOH5_BIAS4"             ] = ;
0822     //       nameDBtoFileConversion_["AOH5_BIAS5"             ] = ;
0823     //       nameDBtoFileConversion_["AOH5_BIAS6"             ] = ;
0824     //       nameDBtoFileConversion_["AOH5_GAIN1"             ] = ;
0825     //       nameDBtoFileConversion_["AOH5_GAIN2"             ] = ;
0826     //       nameDBtoFileConversion_["AOH5_GAIN3"             ] = ;
0827     //       nameDBtoFileConversion_["AOH5_GAIN4"             ] = ;
0828     //       nameDBtoFileConversion_["AOH5_GAIN5"             ] = ;
0829     //       nameDBtoFileConversion_["AOH5_GAIN6"             ] = ;
0830     //       nameDBtoFileConversion_["AOH6_BIAS1"             ] = ;
0831     //       nameDBtoFileConversion_["AOH6_BIAS2"             ] = ;
0832     //       nameDBtoFileConversion_["AOH6_BIAS3"             ] = ;
0833     //       nameDBtoFileConversion_["AOH6_BIAS4"             ] = ;
0834     //       nameDBtoFileConversion_["AOH6_BIAS5"             ] = ;
0835     //       nameDBtoFileConversion_["AOH6_BIAS6"             ] = ;
0836     //       nameDBtoFileConversion_["AOH6_GAIN1"             ] = ;
0837     //       nameDBtoFileConversion_["AOH6_GAIN2"             ] = ;
0838     //       nameDBtoFileConversion_["AOH6_GAIN3"             ] = ;
0839     //       nameDBtoFileConversion_["AOH6_GAIN4"             ] = ;
0840     //       nameDBtoFileConversion_["AOH6_GAIN5"             ] = ;
0841     //       nameDBtoFileConversion_["AOH6_GAIN6"             ] = ;
0842     nameDBtoFileConversion_["DELAY25_GCR"] = k_Delay25_GCR;
0843     nameDBtoFileConversion_["DELAY25_SCL"] = k_Delay25_SCL;
0844     nameDBtoFileConversion_["DELAY25_TRG"] = k_Delay25_TRG;
0845     nameDBtoFileConversion_["DELAY25_SDA"] = k_Delay25_SDA;
0846     nameDBtoFileConversion_["DELAY25_RCL"] = k_Delay25_RCL;
0847     nameDBtoFileConversion_["DELAY25_RDA"] = k_Delay25_RDA;
0848     //   nameDBtoFileConversion_["DEL3_GCR"              ] = ;
0849     //   nameDBtoFileConversion_["DEL3_SCL"              ] = ;
0850     //   nameDBtoFileConversion_["DEL3_TRG"              ] = ;
0851     //   nameDBtoFileConversion_["DEL3_SDA"              ] = ;
0852     //   nameDBtoFileConversion_["DEL3_RCL"              ] = ;
0853     //   nameDBtoFileConversion_["DEL3_RDA"              ] = ;
0854     nameDBtoFileConversion_["DOH_BIAS0"] = k_DOH_Ch0Bias_CLK;
0855     nameDBtoFileConversion_["DOH_BIAS1"] = k_DOH_Ch1Bias_Data;
0856     nameDBtoFileConversion_["DOH_SEU_GAIN"] = k_DOH_Gain_SEU;
0857     //   nameDBtoFileConversion_["DOH3_BIAS0"            ] =  ;
0858     //   nameDBtoFileConversion_["DOH3_BIAS1"            ] =  ;
0859     //   nameDBtoFileConversion_["DOH3_SEU_GAIN"         ] =  ;
0860     nameDBtoFileConversion_["PLL_CTR1"] = k_PLL_CTR1;
0861     nameDBtoFileConversion_["PLL_CTR2"] = k_PLL_CTR2;
0862     nameDBtoFileConversion_["PLL_CTR3"] = k_PLL_CTR3;
0863     nameDBtoFileConversion_["PLL_CTR4"] = k_PLL_CTR4;
0864     nameDBtoFileConversion_["PLL_CTR5"] = k_PLL_CTR5;
0865     //   nameDBtoFileConversion_["PLL3_CTR1"             ] = ;
0866     //   nameDBtoFileConversion_["PLL3_CTR2"             ] = ;
0867     //   nameDBtoFileConversion_["PLL3_CTR3"             ] = ;
0868     //   nameDBtoFileConversion_["PLL3_CTR4_5"           ] = ;
0869   } else if (type_ == "bpix") {
0870     //   nameDBtoFileConversion_["CONFIG_KEY_ID"         ] = ;
0871     //   nameDBtoFileConversion_["CONFIG_KEY"            ] = ;
0872     //   nameDBtoFileConversion_["VERSION"               ] = ;
0873     //   nameDBtoFileConversion_["CONDITION_DATA_SET_ID" ] = ;
0874     //   nameDBtoFileConversion_["KIND_OF_CONDITION_ID"  ] = ;
0875     //   nameDBtoFileConversion_["KIND_OF_COND"          ] = ;
0876     //   nameDBtoFileConversion_["SERIAL_NUMBER"         ] = ;
0877     //   nameDBtoFileConversion_["PORT_CARD_ID"          ] = ;
0878     //   nameDBtoFileConversion_["PORT_CARD"             ] = ;
0879     //   nameDBtoFileConversion_["TRKFEC_NAME"           ] = ;
0880     //   nameDBtoFileConversion_["RINGADDRESS"           ] = ;
0881     //   nameDBtoFileConversion_["CHANNELADDRESS"        ] = ;
0882     //   nameDBtoFileConversion_["CCUADDRESS"            ] = ;
0883     //   nameDBtoFileConversion_["I2C_CNTRL"             ] = ;
0884     //   nameDBtoFileConversion_["I2CSPEED"              ] = ;
0885     nameDBtoFileConversion_["AOH1_BIAS1"] = k_AOH1_Bias1;
0886     nameDBtoFileConversion_["AOH1_BIAS2"] = k_AOH1_Bias2;
0887     nameDBtoFileConversion_["AOH1_BIAS3"] = k_AOH1_Bias3;
0888     nameDBtoFileConversion_["AOH1_BIAS4"] = k_AOH1_Bias4;
0889     nameDBtoFileConversion_["AOH1_BIAS5"] = k_AOH1_Bias5;
0890     nameDBtoFileConversion_["AOH1_BIAS6"] = k_AOH1_Bias6;
0891     //   nameDBtoFileConversion_["AOH1_GAIN1"            ] = ;
0892     //   nameDBtoFileConversion_["AOH1_GAIN2"            ] = ;
0893     //   nameDBtoFileConversion_["AOH1_GAIN3"            ] = ;
0894     //   nameDBtoFileConversion_["AOH1_GAIN4"            ] = ;
0895     //   nameDBtoFileConversion_["AOH1_GAIN5"            ] = ;
0896     //   nameDBtoFileConversion_["AOH1_GAIN6"            ] = ;
0897     nameDBtoFileConversion_["AOH2_BIAS1"] = k_AOH2_Bias1;
0898     nameDBtoFileConversion_["AOH2_BIAS2"] = k_AOH2_Bias2;
0899     nameDBtoFileConversion_["AOH2_BIAS3"] = k_AOH2_Bias3;
0900     nameDBtoFileConversion_["AOH2_BIAS4"] = k_AOH2_Bias4;
0901     nameDBtoFileConversion_["AOH2_BIAS5"] = k_AOH2_Bias5;
0902     nameDBtoFileConversion_["AOH2_BIAS6"] = k_AOH2_Bias6;
0903     //   nameDBtoFileConversion_["AOH2_GAIN1"            ] = ;
0904     //   nameDBtoFileConversion_["AOH2_GAIN2"            ] = ;
0905     //   nameDBtoFileConversion_["AOH2_GAIN3"            ] = ;
0906     //   nameDBtoFileConversion_["AOH2_GAIN4"            ] = ;
0907     //   nameDBtoFileConversion_["AOH2_GAIN5"            ] = ;
0908     //   nameDBtoFileConversion_["AOH2_GAIN6"            ] = ;
0909     nameDBtoFileConversion_["AOH3_BIAS1"] = k_AOH3_Bias1;
0910     nameDBtoFileConversion_["AOH3_BIAS2"] = k_AOH3_Bias2;
0911     nameDBtoFileConversion_["AOH3_BIAS3"] = k_AOH3_Bias3;
0912     nameDBtoFileConversion_["AOH3_BIAS4"] = k_AOH3_Bias4;
0913     nameDBtoFileConversion_["AOH3_BIAS5"] = k_AOH3_Bias5;
0914     nameDBtoFileConversion_["AOH3_BIAS6"] = k_AOH3_Bias6;
0915     //   nameDBtoFileConversion_["AOH3_GAIN1"            ] = ;
0916     //   nameDBtoFileConversion_["AOH3_GAIN2"            ] = ;
0917     //   nameDBtoFileConversion_["AOH3_GAIN3"            ] = ;
0918     //   nameDBtoFileConversion_["AOH3_GAIN4"            ] = ;
0919     //   nameDBtoFileConversion_["AOH3_GAIN5"            ] = ;
0920     //   nameDBtoFileConversion_["AOH3_GAIN6"            ] = ;
0921     nameDBtoFileConversion_["AOH4_BIAS1"] = k_AOH4_Bias1;
0922     nameDBtoFileConversion_["AOH4_BIAS2"] = k_AOH4_Bias2;
0923     nameDBtoFileConversion_["AOH4_BIAS3"] = k_AOH4_Bias3;
0924     nameDBtoFileConversion_["AOH4_BIAS4"] = k_AOH4_Bias4;
0925     nameDBtoFileConversion_["AOH4_BIAS5"] = k_AOH4_Bias5;
0926     nameDBtoFileConversion_["AOH4_BIAS6"] = k_AOH4_Bias6;
0927     //   nameDBtoFileConversion_["AOH4_GAIN1"            ] = ;
0928     //   nameDBtoFileConversion_["AOH4_GAIN2"            ] = ;
0929     //   nameDBtoFileConversion_["AOH4_GAIN3"            ] = ;
0930     //   nameDBtoFileConversion_["AOH4_GAIN4"            ] = ;
0931     //   nameDBtoFileConversion_["AOH4_GAIN5"            ] = ;
0932     //   nameDBtoFileConversion_["AOH4_GAIN6"            ] = ;
0933     //   nameDBtoFileConversion_["AOH5_BIAS1"            ] = ;
0934     //   nameDBtoFileConversion_["AOH5_BIAS2"            ] = ;
0935     //   nameDBtoFileConversion_["AOH5_BIAS3"            ] = ;
0936     //   nameDBtoFileConversion_["AOH5_BIAS4"            ] = ;
0937     //   nameDBtoFileConversion_["AOH5_BIAS5"            ] = ;
0938     //   nameDBtoFileConversion_["AOH5_BIAS6"            ] = ;
0939     //   nameDBtoFileConversion_["AOH5_GAIN1"            ] = ;
0940     //   nameDBtoFileConversion_["AOH5_GAIN2"            ] = ;
0941     //   nameDBtoFileConversion_["AOH5_GAIN3"            ] = ;
0942     //   nameDBtoFileConversion_["AOH5_GAIN4"            ] = ;
0943     //   nameDBtoFileConversion_["AOH5_GAIN5"            ] = ;
0944     //   nameDBtoFileConversion_["AOH5_GAIN6"            ] = ;
0945     //   nameDBtoFileConversion_["AOH6_BIAS1"            ] = ;
0946     //   nameDBtoFileConversion_["AOH6_BIAS2"            ] = ;
0947     //   nameDBtoFileConversion_["AOH6_BIAS3"            ] = ;
0948     //   nameDBtoFileConversion_["AOH6_BIAS4"            ] = ;
0949     //   nameDBtoFileConversion_["AOH6_BIAS5"            ] = ;
0950     //   nameDBtoFileConversion_["AOH6_BIAS6"            ] = ;
0951     //   nameDBtoFileConversion_["AOH6_GAIN1"            ] = ;
0952     //   nameDBtoFileConversion_["AOH6_GAIN2"            ] = ;
0953     //   nameDBtoFileConversion_["AOH6_GAIN3"            ] = ;
0954     //   nameDBtoFileConversion_["AOH6_GAIN4"            ] = ;
0955     //   nameDBtoFileConversion_["AOH6_GAIN5"            ] = ;
0956     //   nameDBtoFileConversion_["AOH6_GAIN6"            ] = ;
0957     nameDBtoFileConversion_["DELAY25_GCR"] = k_Delay25_GCR;
0958     nameDBtoFileConversion_["DELAY25_SCL"] = k_Delay25_SCL;
0959     nameDBtoFileConversion_["DELAY25_TRG"] = k_Delay25_TRG;
0960     nameDBtoFileConversion_["DELAY25_SDA"] = k_Delay25_SDA;
0961     nameDBtoFileConversion_["DELAY25_RCL"] = k_Delay25_RCL;
0962     nameDBtoFileConversion_["DELAY25_RDA"] = k_Delay25_RDA;
0963     //   nameDBtoFileConversion_["DEL3_GCR"              ] = ;
0964     //   nameDBtoFileConversion_["DEL3_SCL"              ] = ;
0965     //   nameDBtoFileConversion_["DEL3_TRG"              ] = ;
0966     //   nameDBtoFileConversion_["DEL3_SDA"              ] = ;
0967     //   nameDBtoFileConversion_["DEL3_RCL"              ] = ;
0968     //   nameDBtoFileConversion_["DEL3_RDA"              ] = ;
0969     nameDBtoFileConversion_["DOH_BIAS0"] = k_DOH_Ch0Bias_CLK;
0970     nameDBtoFileConversion_["DOH_BIAS1"] = k_DOH_Ch1Bias_Data;
0971     nameDBtoFileConversion_["DOH_SEU_GAIN"] = k_DOH_Gain_SEU;
0972     //   nameDBtoFileConversion_["DOH3_BIAS0"            ] =  ;
0973     //   nameDBtoFileConversion_["DOH3_BIAS1"            ] =  ;
0974     //   nameDBtoFileConversion_["DOH3_SEU_GAIN"         ] =  ;
0975     nameDBtoFileConversion_["PLL_CTR1"] = k_PLL_CTR1;
0976     nameDBtoFileConversion_["PLL_CTR2"] = k_PLL_CTR2;
0977     nameDBtoFileConversion_["PLL_CTR3"] = k_PLL_CTR3;
0978     nameDBtoFileConversion_["PLL_CTR4"] = k_PLL_CTR4;
0979     nameDBtoFileConversion_["PLL_CTR5"] = k_PLL_CTR5;
0980     //   nameDBtoFileConversion_["PLL3_CTR1"             ] = ;
0981     //   nameDBtoFileConversion_["PLL3_CTR2"             ] = ;
0982     //   nameDBtoFileConversion_["PLL3_CTR3"             ] = ;
0983     //   nameDBtoFileConversion_["PLL3_CTR4_5"           ] = ;
0984   }
0985 }
0986 
0987 void PixelPortCardConfig::writeASCII(std::string dir) const {
0988   std::string mthn = "[PixelPortCardConfig::writeASCII()]\t\t\t\t    ";
0989   if (!dir.empty())
0990     dir += "/";
0991   std::string filename = dir + "portcard_" + portcardname_ + ".dat";
0992 
0993   std::ofstream out(filename.c_str());
0994   if (!out.good()) {
0995     std::cout << __LINE__ << "]\t" << mthn << "Could not open file: " << filename.c_str() << std::endl;
0996     assert(0);
0997   }
0998 
0999   out << "Name: " << portcardname_ << std::endl;
1000   out << "Type: " << type_ << std::endl;
1001   out << "TKFECID: " << TKFECID_ << std::endl;
1002   out << "ringAddress: 0x" << std::hex << ringAddress_ << std::dec << std::endl;
1003   out << "ccuAddress: 0x" << std::hex << ccuAddress_ << std::dec << std::endl;
1004 
1005   out << "channelAddress: 0x" << std::hex << channelAddress_ << std::dec << std::endl;
1006 
1007   out << "i2cSpeed: 0x" << std::hex << i2cSpeed_ << std::dec << std::endl;
1008 
1009   bool found_PLL_CTR2 = false;
1010   unsigned int last_PLL_CTR2_value = 0x0;
1011   for (unsigned int i = 0; i < device_.size(); i++) {
1012     unsigned int deviceAddress = device_.at(i).first;
1013 
1014     // Special handling for AOH gains
1015     if ((type_ == "fpix" && deviceAddress == k_fpix_AOH_Gain123_address) ||
1016         (type_ == "fpix" && deviceAddress == k_fpix_AOH_Gain456_address) ||
1017         (type_ == "bpix" && deviceAddress == k_bpix_AOH1_Gain123_address) ||
1018         (type_ == "bpix" && deviceAddress == k_bpix_AOH1_Gain456_address) ||
1019         (type_ == "bpix" && deviceAddress == k_bpix_AOH2_Gain123_address) ||
1020         (type_ == "bpix" && deviceAddress == k_bpix_AOH2_Gain456_address) ||
1021         (type_ == "bpix" && deviceAddress == k_bpix_AOH3_Gain123_address) ||
1022         (type_ == "bpix" && deviceAddress == k_bpix_AOH3_Gain456_address) ||
1023         (type_ == "bpix" && deviceAddress == k_bpix_AOH4_Gain123_address) ||
1024         (type_ == "bpix" && deviceAddress == k_bpix_AOH4_Gain456_address)) {
1025       std::string whichAOHString;
1026       unsigned int zeroOrThree;
1027       if (type_ == "fpix" && deviceAddress == k_fpix_AOH_Gain123_address) {
1028         whichAOHString = "";
1029         zeroOrThree = 0;
1030       } else if (type_ == "fpix" && deviceAddress == k_fpix_AOH_Gain456_address) {
1031         whichAOHString = "";
1032         zeroOrThree = 3;
1033       } else if (type_ == "bpix" && deviceAddress == k_bpix_AOH1_Gain123_address) {
1034         whichAOHString = "1";
1035         zeroOrThree = 0;
1036       } else if (type_ == "bpix" && deviceAddress == k_bpix_AOH1_Gain456_address) {
1037         whichAOHString = "1";
1038         zeroOrThree = 3;
1039       } else if (type_ == "bpix" && deviceAddress == k_bpix_AOH2_Gain123_address) {
1040         whichAOHString = "2";
1041         zeroOrThree = 0;
1042       } else if (type_ == "bpix" && deviceAddress == k_bpix_AOH2_Gain456_address) {
1043         whichAOHString = "2";
1044         zeroOrThree = 3;
1045       } else if (type_ == "bpix" && deviceAddress == k_bpix_AOH3_Gain123_address) {
1046         whichAOHString = "3";
1047         zeroOrThree = 0;
1048       } else if (type_ == "bpix" && deviceAddress == k_bpix_AOH3_Gain456_address) {
1049         whichAOHString = "3";
1050         zeroOrThree = 3;
1051       } else if (type_ == "bpix" && deviceAddress == k_bpix_AOH4_Gain123_address) {
1052         whichAOHString = "4";
1053         zeroOrThree = 0;
1054       } else if (type_ == "bpix" && deviceAddress == k_bpix_AOH4_Gain456_address) {
1055         whichAOHString = "4";
1056         zeroOrThree = 3;
1057       } else
1058         assert(0);
1059 
1060       out << "AOH" << whichAOHString << "_Gain" << zeroOrThree + 1 << ": 0x" << (((device_[i].second) & 0x03) >> 0)
1061           << std::endl;  // output bits 0 & 1
1062       out << "AOH" << whichAOHString << "_Gain" << zeroOrThree + 2 << ": 0x" << (((device_[i].second) & 0x0c) >> 2)
1063           << std::endl;  // output bits 2 & 3
1064       out << "AOH" << whichAOHString << "_Gain" << zeroOrThree + 3 << ": 0x" << (((device_[i].second) & 0x30) >> 4)
1065           << std::endl;  // output bits 4 & 5
1066       continue;
1067     }
1068     // End of special handling
1069 
1070     // Check to see if there's a name corresponding to this address.
1071     std::string settingName = "";
1072     for (std::map<std::string, unsigned int>::const_iterator nameToAddress_itr = nameToAddress_.begin();
1073          nameToAddress_itr != nameToAddress_.end();
1074          ++nameToAddress_itr) {
1075       //       cout << "[PixelPortCardConfig::WriteASCII()]\tnameToAddress.first:  " << nameToAddress_itr->first  << endl ;
1076       //       cout << "[PixelPortCardConfig::WriteASCII()]\tnameToAddress.second: " << nameToAddress_itr->second << endl ;
1077       //       cout << "[PixelPortCardConfig::WriteASCII()]\tdeviceAddress:        " << deviceAddress             << endl ;
1078       if (nameToAddress_itr->second == deviceAddress) {
1079         settingName = nameToAddress_itr->first;
1080         break;
1081       }
1082       if (nameToAddress_itr == (--nameToAddress_.end())) {
1083         cout << "[PixelPortCardConfig::WriteASCII()]\tdeviceAddress:        " << deviceAddress << " NOT FOUND" << endl;
1084       }
1085     }
1086 
1087     // Special handling for PLL addresses.
1088     if (settingName == k_PLL_CTR2) {
1089       if (found_PLL_CTR2 && last_PLL_CTR2_value == device_.at(i).second)
1090         continue;  // don't save duplicate CTR2 settings
1091       found_PLL_CTR2 = true;
1092       last_PLL_CTR2_value = device_.at(i).second;
1093     }
1094     if (found_PLL_CTR2 && settingName == k_PLL_CTR4or5)  // change name to PLL_CTR4 or PLL_CTR5
1095     {
1096       if ((last_PLL_CTR2_value & 0x20) == 0x0)
1097         settingName = k_PLL_CTR4;
1098       else
1099         settingName = k_PLL_CTR5;
1100     }
1101     // end of special handling
1102 
1103     if (settingName.empty())
1104       out << "0x" << std::hex << device_.at(i).first << std::dec;
1105     else
1106       out << settingName << ":";
1107 
1108     out << " 0x" << std::hex << device_.at(i).second << std::dec << std::endl;
1109   }
1110 
1111   out.close();
1112 }
1113 
1114 unsigned int PixelPortCardConfig::getdevicesize() const { return device_.size(); }
1115 
1116 std::string PixelPortCardConfig::getTKFECID() const { return TKFECID_; }
1117 
1118 unsigned int PixelPortCardConfig::getringAddress() const { return ringAddress_; }
1119 
1120 unsigned int PixelPortCardConfig::getccuAddress() const { return ccuAddress_; }
1121 
1122 unsigned int PixelPortCardConfig::getchannelAddress() const { return channelAddress_; }
1123 
1124 unsigned int PixelPortCardConfig::geti2cSpeed() const { return i2cSpeed_; }
1125 
1126 std::string PixelPortCardConfig::gettype() const { return type_; }
1127 
1128 unsigned int PixelPortCardConfig::getdeviceAddress(unsigned int i) const {
1129   assert(i < device_.size());
1130   return device_[i].first;
1131 }
1132 
1133 unsigned int PixelPortCardConfig::getdeviceValues(unsigned int i) const {
1134   assert(i < device_.size());
1135   return device_[i].second;
1136 }
1137 
1138 void PixelPortCardConfig::setdeviceValues(unsigned int address, unsigned int value) {
1139   for (int i = device_.size() - 1; i >= 0;
1140        i--)  // Change only the last occurance of address, if there are more than one.
1141   {
1142     if (device_.at(i).first == address) {
1143       device_.at(i).second = value;
1144       return;
1145     }
1146   }
1147 
1148   // This address wasn't found in the list, so add it and its value.
1149   pair<unsigned int, unsigned int> p(address, value);
1150   device_.push_back(p);
1151 
1152   return;
1153 }
1154 
1155 void PixelPortCardConfig::setdeviceValues(std::string settingName, unsigned int value) {
1156   setdeviceValues(getdeviceAddressForSetting(settingName), value);
1157   return;
1158 }
1159 
1160 unsigned int PixelPortCardConfig::getdeviceAddressForSetting(std::string settingName) const {
1161   //std::cout << "[PixelPortCardConfig::getdeviceAddressForSetting()]\t    settingName: " << settingName<< std::endl ;
1162   std::map<std::string, unsigned int>::const_iterator foundName_itr = nameToAddress_.find(settingName);
1163   assert(foundName_itr != nameToAddress_.end());
1164   return foundName_itr->second;
1165 }
1166 
1167 unsigned int PixelPortCardConfig::getdeviceValuesForSetting(std::string settingName) const {
1168   return getdeviceValuesForAddress(getdeviceAddressForSetting(settingName));
1169 }
1170 
1171 unsigned int PixelPortCardConfig::getdeviceValuesForAddress(unsigned int address) const {
1172   for (int i = device_.size() - 1; i >= 0; i--)  // Get the last occurance of address, if there are more than one.
1173   {
1174     if (device_.at(i).first == address) {
1175       return device_.at(i).second;
1176     }
1177   }
1178   assert(0);  // didn't find this device
1179   return 0;
1180 }
1181 
1182 bool PixelPortCardConfig::containsDeviceAddress(unsigned int deviceAddress) const {
1183   for (std::vector<std::pair<unsigned int, unsigned int> >::const_iterator device_itr = device_.begin();
1184        device_itr != device_.end();
1185        ++device_itr) {
1186     if (device_itr->first == deviceAddress)
1187       return true;
1188   }
1189   return false;
1190 }
1191 
1192 unsigned int PixelPortCardConfig::AOHBiasAddressFromAOHNumber(unsigned int AOHNumber) const {
1193   std::string mthn = "[PixelPortCardConfig::AOHBiasAddressFromAOHNumber()]    ";
1194   if (type_ == "fpix") {
1195     if (AOHNumber == 1)
1196       return PortCardSettingNames::k_fpix_AOH_Bias1_address;
1197     else if (AOHNumber == 2)
1198       return PortCardSettingNames::k_fpix_AOH_Bias2_address;
1199     else if (AOHNumber == 3)
1200       return PortCardSettingNames::k_fpix_AOH_Bias3_address;
1201     else if (AOHNumber == 4)
1202       return PortCardSettingNames::k_fpix_AOH_Bias4_address;
1203     else if (AOHNumber == 5)
1204       return PortCardSettingNames::k_fpix_AOH_Bias5_address;
1205     else if (AOHNumber == 6)
1206       return PortCardSettingNames::k_fpix_AOH_Bias6_address;
1207     else {
1208       std::cout << __LINE__ << "]\t" << mthn
1209                 << "ERROR: For fpix, AOH number must be in the range 1-6, but the given AOH number was " << AOHNumber
1210                 << "." << std::endl;
1211       assert(0);
1212     }
1213   } else if (type_ == "bpix") {
1214     if (AOHNumber == 1)
1215       return PortCardSettingNames::k_bpix_AOH1_Bias1_address;
1216     else if (AOHNumber == 2)
1217       return PortCardSettingNames::k_bpix_AOH1_Bias2_address;
1218     else if (AOHNumber == 3)
1219       return PortCardSettingNames::k_bpix_AOH1_Bias3_address;
1220     else if (AOHNumber == 4)
1221       return PortCardSettingNames::k_bpix_AOH1_Bias4_address;
1222     else if (AOHNumber == 5)
1223       return PortCardSettingNames::k_bpix_AOH1_Bias5_address;
1224     else if (AOHNumber == 6)
1225       return PortCardSettingNames::k_bpix_AOH1_Bias6_address;
1226     else if (AOHNumber == 7)
1227       return PortCardSettingNames::k_bpix_AOH2_Bias1_address;
1228     else if (AOHNumber == 8)
1229       return PortCardSettingNames::k_bpix_AOH2_Bias2_address;
1230     else if (AOHNumber == 9)
1231       return PortCardSettingNames::k_bpix_AOH2_Bias3_address;
1232     else if (AOHNumber == 10)
1233       return PortCardSettingNames::k_bpix_AOH2_Bias4_address;
1234     else if (AOHNumber == 11)
1235       return PortCardSettingNames::k_bpix_AOH2_Bias5_address;
1236     else if (AOHNumber == 12)
1237       return PortCardSettingNames::k_bpix_AOH2_Bias6_address;
1238     else if (AOHNumber == 13)
1239       return PortCardSettingNames::k_bpix_AOH3_Bias1_address;
1240     else if (AOHNumber == 14)
1241       return PortCardSettingNames::k_bpix_AOH3_Bias2_address;
1242     else if (AOHNumber == 15)
1243       return PortCardSettingNames::k_bpix_AOH3_Bias3_address;
1244     else if (AOHNumber == 16)
1245       return PortCardSettingNames::k_bpix_AOH3_Bias4_address;
1246     else if (AOHNumber == 17)
1247       return PortCardSettingNames::k_bpix_AOH3_Bias5_address;
1248     else if (AOHNumber == 18)
1249       return PortCardSettingNames::k_bpix_AOH3_Bias6_address;
1250     else if (AOHNumber == 19)
1251       return PortCardSettingNames::k_bpix_AOH4_Bias1_address;
1252     else if (AOHNumber == 20)
1253       return PortCardSettingNames::k_bpix_AOH4_Bias2_address;
1254     else if (AOHNumber == 21)
1255       return PortCardSettingNames::k_bpix_AOH4_Bias3_address;
1256     else if (AOHNumber == 22)
1257       return PortCardSettingNames::k_bpix_AOH4_Bias4_address;
1258     else if (AOHNumber == 23)
1259       return PortCardSettingNames::k_bpix_AOH4_Bias5_address;
1260     else if (AOHNumber == 24)
1261       return PortCardSettingNames::k_bpix_AOH4_Bias6_address;
1262     else {
1263       std::cout << __LINE__ << "]\t" << mthn
1264                 << "ERROR: For bpix, AOH number must be in the range 1-24, but the given AOH number was " << AOHNumber
1265                 << "." << std::endl;
1266       assert(0);
1267     }
1268   } else
1269     assert(0);
1270 }
1271 
1272 std::string PixelPortCardConfig::AOHGainStringFromAOHNumber(unsigned int AOHNumber) const {
1273   std::string mthn = "[PixelPortCardConfig::AOHGainStringFromAOHNumber()]    ";
1274   if (type_ == "fpix") {
1275     if (AOHNumber == 1)
1276       return "AOH_Gain1";
1277     else if (AOHNumber == 2)
1278       return "AOH_Gain2";
1279     else if (AOHNumber == 3)
1280       return "AOH_Gain3";
1281     else if (AOHNumber == 4)
1282       return "AOH_Gain4";
1283     else if (AOHNumber == 5)
1284       return "AOH_Gain5";
1285     else if (AOHNumber == 6)
1286       return "AOH_Gain6";
1287     else {
1288       std::cout << __LINE__ << "]\t" << mthn
1289                 << "ERROR: For fpix, AOH number must be in the range 1-6, but the given AOH number was " << AOHNumber
1290                 << "." << std::endl;
1291       assert(0);
1292     }
1293   } else if (type_ == "bpix") {
1294     if (AOHNumber == 1)
1295       return "AOH1_Gain1";
1296     else if (AOHNumber == 2)
1297       return "AOH1_Gain2";
1298     else if (AOHNumber == 3)
1299       return "AOH1_Gain3";
1300     else if (AOHNumber == 4)
1301       return "AOH1_Gain4";
1302     else if (AOHNumber == 5)
1303       return "AOH1_Gain5";
1304     else if (AOHNumber == 6)
1305       return "AOH1_Gain6";
1306     else if (AOHNumber == 7)
1307       return "AOH2_Gain1";
1308     else if (AOHNumber == 8)
1309       return "AOH2_Gain2";
1310     else if (AOHNumber == 9)
1311       return "AOH2_Gain3";
1312     else if (AOHNumber == 10)
1313       return "AOH2_Gain4";
1314     else if (AOHNumber == 11)
1315       return "AOH2_Gain5";
1316     else if (AOHNumber == 12)
1317       return "AOH2_Gain6";
1318     else if (AOHNumber == 13)
1319       return "AOH3_Gain1";
1320     else if (AOHNumber == 14)
1321       return "AOH3_Gain2";
1322     else if (AOHNumber == 15)
1323       return "AOH3_Gain3";
1324     else if (AOHNumber == 16)
1325       return "AOH3_Gain4";
1326     else if (AOHNumber == 17)
1327       return "AOH3_Gain5";
1328     else if (AOHNumber == 18)
1329       return "AOH3_Gain6";
1330     else if (AOHNumber == 19)
1331       return "AOH4_Gain1";
1332     else if (AOHNumber == 20)
1333       return "AOH4_Gain2";
1334     else if (AOHNumber == 21)
1335       return "AOH4_Gain3";
1336     else if (AOHNumber == 22)
1337       return "AOH4_Gain4";
1338     else if (AOHNumber == 23)
1339       return "AOH4_Gain5";
1340     else if (AOHNumber == 24)
1341       return "AOH4_Gain6";
1342     else {
1343       std::cout << __LINE__ << "]\t" << mthn
1344                 << "ERROR: For bpix, AOH number must be in the range 1-24, but the given AOH number was " << AOHNumber
1345                 << "." << std::endl;
1346       assert(0);
1347     }
1348   } else
1349     assert(0);
1350 }
1351 
1352 unsigned int PixelPortCardConfig::AOHGainAddressFromAOHNumber(unsigned int AOHNumber) const {
1353   std::string mthn = "[PixelPortCardConfig::AOHGainAddressFromAOHNumber()]    ";
1354   unsigned int address;
1355   if (type_ == "fpix") {
1356     if (AOHNumber == 1)
1357       address = PortCardSettingNames::k_fpix_AOH_Gain123_address;
1358     else if (AOHNumber == 2)
1359       address = PortCardSettingNames::k_fpix_AOH_Gain123_address;
1360     else if (AOHNumber == 3)
1361       address = PortCardSettingNames::k_fpix_AOH_Gain123_address;
1362     else if (AOHNumber == 4)
1363       address = PortCardSettingNames::k_fpix_AOH_Gain456_address;
1364     else if (AOHNumber == 5)
1365       address = PortCardSettingNames::k_fpix_AOH_Gain456_address;
1366     else if (AOHNumber == 6)
1367       address = PortCardSettingNames::k_fpix_AOH_Gain456_address;
1368     else {
1369       std::cout << __LINE__ << "]\t" << mthn
1370                 << "ERROR: For fpix, AOH number must be in the range 1-6, but the given AOH number was " << AOHNumber
1371                 << "." << std::endl;
1372       assert(0);
1373     }
1374   } else if (type_ == "bpix") {
1375     if (AOHNumber == 1)
1376       address = PortCardSettingNames::k_bpix_AOH1_Gain123_address;
1377     else if (AOHNumber == 2)
1378       address = PortCardSettingNames::k_bpix_AOH1_Gain123_address;
1379     else if (AOHNumber == 3)
1380       address = PortCardSettingNames::k_bpix_AOH1_Gain123_address;
1381     else if (AOHNumber == 4)
1382       address = PortCardSettingNames::k_bpix_AOH1_Gain456_address;
1383     else if (AOHNumber == 5)
1384       address = PortCardSettingNames::k_bpix_AOH1_Gain456_address;
1385     else if (AOHNumber == 6)
1386       address = PortCardSettingNames::k_bpix_AOH1_Gain456_address;
1387     else if (AOHNumber == 7)
1388       address = PortCardSettingNames::k_bpix_AOH2_Gain123_address;
1389     else if (AOHNumber == 8)
1390       address = PortCardSettingNames::k_bpix_AOH2_Gain123_address;
1391     else if (AOHNumber == 9)
1392       address = PortCardSettingNames::k_bpix_AOH2_Gain123_address;
1393     else if (AOHNumber == 10)
1394       address = PortCardSettingNames::k_bpix_AOH2_Gain456_address;
1395     else if (AOHNumber == 11)
1396       address = PortCardSettingNames::k_bpix_AOH2_Gain456_address;
1397     else if (AOHNumber == 12)
1398       address = PortCardSettingNames::k_bpix_AOH2_Gain456_address;
1399     else if (AOHNumber == 13)
1400       address = PortCardSettingNames::k_bpix_AOH3_Gain123_address;
1401     else if (AOHNumber == 14)
1402       address = PortCardSettingNames::k_bpix_AOH3_Gain123_address;
1403     else if (AOHNumber == 15)
1404       address = PortCardSettingNames::k_bpix_AOH3_Gain123_address;
1405     else if (AOHNumber == 16)
1406       address = PortCardSettingNames::k_bpix_AOH3_Gain456_address;
1407     else if (AOHNumber == 17)
1408       address = PortCardSettingNames::k_bpix_AOH3_Gain456_address;
1409     else if (AOHNumber == 18)
1410       address = PortCardSettingNames::k_bpix_AOH3_Gain456_address;
1411     else if (AOHNumber == 19)
1412       address = PortCardSettingNames::k_bpix_AOH4_Gain123_address;
1413     else if (AOHNumber == 20)
1414       address = PortCardSettingNames::k_bpix_AOH4_Gain123_address;
1415     else if (AOHNumber == 21)
1416       address = PortCardSettingNames::k_bpix_AOH4_Gain123_address;
1417     else if (AOHNumber == 22)
1418       address = PortCardSettingNames::k_bpix_AOH4_Gain456_address;
1419     else if (AOHNumber == 23)
1420       address = PortCardSettingNames::k_bpix_AOH4_Gain456_address;
1421     else if (AOHNumber == 24)
1422       address = PortCardSettingNames::k_bpix_AOH4_Gain456_address;
1423     else {
1424       std::cout << __LINE__ << "]\t" << mthn
1425                 << "ERROR: For bpix, AOH number must be in the range 1-24, but the given AOH number was " << AOHNumber
1426                 << "." << std::endl;
1427       assert(0);
1428     }
1429   } else
1430     assert(0);
1431 
1432   return address;
1433 }
1434 
1435 unsigned int PixelPortCardConfig::getAOHGain(unsigned int AOHNumber) const {
1436   const unsigned int address = AOHGainAddressFromAOHNumber(AOHNumber);
1437   const unsigned int threeGainsValue = getdeviceValuesForAddress(address);
1438 
1439   if (AOHNumber % 3 == 1)
1440     return (((threeGainsValue)&0x03) >> 0);  // return bits 0 & 1
1441   if (AOHNumber % 3 == 2)
1442     return (((threeGainsValue)&0x0c) >> 2);  // return bits 2 & 3
1443   if (AOHNumber % 3 == 0)
1444     return (((threeGainsValue)&0x30) >> 4);  // return bits 4 & 5
1445 
1446   assert(0);
1447 }
1448 //=============================================================================================
1449 void PixelPortCardConfig::writeXMLHeader(pos::PixelConfigKey key,
1450                                          int version,
1451                                          std::string path,
1452                                          std::ofstream *outstream,
1453                                          std::ofstream *out1stream,
1454                                          std::ofstream *out2stream) const {
1455   std::string mthn = "[PixelPortCardConfig::writeXMLHeader()]\t\t\t    ";
1456   std::stringstream fullPath;
1457   fullPath << path << "/Pixel_PortCardSettings_" << PixelTimeFormatter::getmSecTime() << ".xml";
1458   std::cout << __LINE__ << "]\t" << mthn << "Writing to: " << fullPath.str() << std::endl;
1459 
1460   outstream->open(fullPath.str().c_str());
1461 
1462   *outstream << "<?xml version='1.0' encoding='UTF-8' standalone='yes'?>" << std::endl;
1463   *outstream << "<ROOT xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>" << std::endl;
1464   *outstream << " <HEADER>" << std::endl;
1465   *outstream << "  <TYPE>" << std::endl;
1466   *outstream << "   <EXTENSION_TABLE_NAME>PIXEL_PORTCARD_SETTINGS</EXTENSION_TABLE_NAME>" << std::endl;
1467   *outstream << "   <NAME>Pixel Port Card Settings</NAME>" << std::endl;
1468   *outstream << "  </TYPE>" << std::endl;
1469   *outstream << "  <RUN>" << std::endl;
1470   *outstream << "   <RUN_TYPE>Pixel Port Card Settings</RUN_TYPE>" << std::endl;
1471   *outstream << "   <RUN_NUMBER>1</RUN_NUMBER>" << std::endl;
1472   *outstream << "   <RUN_BEGIN_TIMESTAMP>" << pos::PixelTimeFormatter::getTime() << "</RUN_BEGIN_TIMESTAMP>"
1473              << std::endl;
1474   *outstream << "   <LOCATION>CERN P5</LOCATION>" << std::endl;
1475   *outstream << "  </RUN>" << std::endl;
1476   *outstream << " </HEADER>" << std::endl;
1477   *outstream << "" << std::endl;
1478   *outstream << " <DATA_SET>" << std::endl;
1479   *outstream << "  <PART>" << std::endl;
1480   *outstream << "   <NAME_LABEL>CMS-PIXEL-ROOT</NAME_LABEL>" << std::endl;
1481   *outstream << "   <KIND_OF_PART>Detector ROOT</KIND_OF_PART>" << std::endl;
1482   *outstream << "  </PART>" << std::endl;
1483   *outstream << "  <VERSION>" << version << "</VERSION>" << std::endl;
1484   *outstream << "  <COMMENT_DESCRIPTION>" << getComment() << "</COMMENT_DESCRIPTION>" << std::endl;
1485   *outstream << "  <CREATED_BY_USER>" << getAuthor() << "</CREATED_BY_USER>" << std::endl;
1486   *outstream << "" << std::endl;
1487 }
1488 
1489 //=============================================================================================
1490 void PixelPortCardConfig::writeXML(std::ofstream *outstream,
1491                                    std::ofstream *out1stream,
1492                                    std::ofstream *out2stream) const {
1493   std::string mthn = "[PixelPortCardConfig::writeXML()]\t\t\t    ";
1494 
1495   *outstream << "  <DATA>" << std::endl;
1496   *outstream << "   <PORT_CARD>" << portcardname_ << "</PORT_CARD>" << std::endl;
1497   *outstream << "   <TRKFEC>" << TKFECID_ << "</TRKFEC>" << std::endl;
1498   *outstream << "   <RING>" << ringAddress_ << "</RING>" << std::endl;
1499   *outstream << "   <CCU_ADDR>" << ccuAddress_ << "</CCU_ADDR>" << std::endl;
1500   *outstream << "   <CHANNEL>" << channelAddress_ << "</CHANNEL>" << std::endl;
1501   *outstream << "   <I2C_SPEED>" << i2cSpeed_ << "</I2C_SPEED>" << std::endl;
1502 
1503   bool found_PLL_CTR2 = false;
1504   unsigned int last_PLL_CTR2_value = 0x0;
1505   for (unsigned int i = 0; i < device_.size(); i++) {
1506     unsigned int deviceAddress = device_.at(i).first;
1507 
1508     // Special handling for AOH gains
1509     if ((type_ == "fpix" && deviceAddress == k_fpix_AOH_Gain123_address) ||
1510         (type_ == "fpix" && deviceAddress == k_fpix_AOH_Gain456_address) ||
1511         (type_ == "bpix" && deviceAddress == k_bpix_AOH1_Gain123_address) ||
1512         (type_ == "bpix" && deviceAddress == k_bpix_AOH1_Gain456_address) ||
1513         (type_ == "bpix" && deviceAddress == k_bpix_AOH2_Gain123_address) ||
1514         (type_ == "bpix" && deviceAddress == k_bpix_AOH2_Gain456_address) ||
1515         (type_ == "bpix" && deviceAddress == k_bpix_AOH3_Gain123_address) ||
1516         (type_ == "bpix" && deviceAddress == k_bpix_AOH3_Gain456_address) ||
1517         (type_ == "bpix" && deviceAddress == k_bpix_AOH4_Gain123_address) ||
1518         (type_ == "bpix" && deviceAddress == k_bpix_AOH4_Gain456_address)) {
1519       std::string whichAOHString;
1520       unsigned int zeroOrThree;
1521       if (type_ == "fpix" && deviceAddress == k_fpix_AOH_Gain123_address) {
1522         whichAOHString = "";
1523         zeroOrThree = 0;
1524       } else if (type_ == "fpix" && deviceAddress == k_fpix_AOH_Gain456_address) {
1525         whichAOHString = "";
1526         zeroOrThree = 3;
1527       } else if (type_ == "bpix" && deviceAddress == k_bpix_AOH1_Gain123_address) {
1528         whichAOHString = "1";
1529         zeroOrThree = 0;
1530       } else if (type_ == "bpix" && deviceAddress == k_bpix_AOH1_Gain456_address) {
1531         whichAOHString = "1";
1532         zeroOrThree = 3;
1533       } else if (type_ == "bpix" && deviceAddress == k_bpix_AOH2_Gain123_address) {
1534         whichAOHString = "2";
1535         zeroOrThree = 0;
1536       } else if (type_ == "bpix" && deviceAddress == k_bpix_AOH2_Gain456_address) {
1537         whichAOHString = "2";
1538         zeroOrThree = 3;
1539       } else if (type_ == "bpix" && deviceAddress == k_bpix_AOH3_Gain123_address) {
1540         whichAOHString = "3";
1541         zeroOrThree = 0;
1542       } else if (type_ == "bpix" && deviceAddress == k_bpix_AOH3_Gain456_address) {
1543         whichAOHString = "3";
1544         zeroOrThree = 3;
1545       } else if (type_ == "bpix" && deviceAddress == k_bpix_AOH4_Gain123_address) {
1546         whichAOHString = "4";
1547         zeroOrThree = 0;
1548       } else if (type_ == "bpix" && deviceAddress == k_bpix_AOH4_Gain456_address) {
1549         whichAOHString = "4";
1550         zeroOrThree = 3;
1551       } else
1552         assert(0);
1553 
1554       *outstream << "   <AOH" << whichAOHString << "_GAIN" << zeroOrThree + 1 << ">"
1555                  << (((device_[i].second) & 0x03) >> 0) << "</AOH" << whichAOHString << "_GAIN" << zeroOrThree + 1
1556                  << ">" << std::endl;  // output bits 0 & 1
1557       *outstream << "   <AOH" << whichAOHString << "_GAIN" << zeroOrThree + 2 << ">"
1558                  << (((device_[i].second) & 0x0c) >> 2) << "</AOH" << whichAOHString << "_GAIN" << zeroOrThree + 2
1559                  << ">" << std::endl;  // output bits 2 & 3
1560       *outstream << "   <AOH" << whichAOHString << "_GAIN" << zeroOrThree + 3 << ">"
1561                  << (((device_[i].second) & 0x30) >> 4) << "</AOH" << whichAOHString << "_GAIN" << zeroOrThree + 3
1562                  << ">" << std::endl;  // output bits 4 & 5
1563       continue;
1564     }
1565     // End of special handling
1566 
1567     // Check to see if there's a name corresponding to this address.
1568     std::string settingName = "";
1569     for (std::map<std::string, unsigned int>::const_iterator nameToAddress_itr = nameToAddress_.begin();
1570          nameToAddress_itr != nameToAddress_.end();
1571          ++nameToAddress_itr) {
1572       if (nameToAddress_itr->second == deviceAddress) {
1573         settingName = nameToAddress_itr->first;
1574         break;
1575       }
1576     }
1577     for (std::map<std::string, std::string>::const_iterator nameDBtoFileConversion_itr =
1578              nameDBtoFileConversion_.begin();
1579          nameDBtoFileConversion_itr != nameDBtoFileConversion_.end();
1580          ++nameDBtoFileConversion_itr) {
1581       if (nameDBtoFileConversion_itr->second.find(settingName) != std::string::npos) {
1582         settingName = nameDBtoFileConversion_itr->first;
1583         break;
1584       }
1585     }
1586 
1587     // Special handling for PLL addresses.
1588     if (settingName == k_PLL_CTR2) {
1589       if (found_PLL_CTR2 && last_PLL_CTR2_value == device_.at(i).second)
1590         continue;  // don't save duplicate CTR2 settings
1591       found_PLL_CTR2 = true;
1592       last_PLL_CTR2_value = device_.at(i).second;
1593     }
1594     if (found_PLL_CTR2 && settingName == k_PLL_CTR4or5)  // change name to PLL_CTR4 or PLL_CTR5
1595     {
1596       if ((last_PLL_CTR2_value & 0x20) == 0x0)
1597         settingName = k_PLL_CTR4;
1598       else
1599         settingName = k_PLL_CTR5;
1600     }
1601     // end of special handling
1602 
1603     if (settingName.empty())
1604       *outstream << device_.at(i).first;
1605     else
1606       *outstream << "   <" << settingName << ">";
1607 
1608     *outstream << device_.at(i).second << "</" << settingName << ">" << std::endl;
1609   }
1610 
1611   *outstream << "  </DATA>" << std::endl;
1612 }
1613 //=============================================================================================
1614 void PixelPortCardConfig::writeXMLTrailer(std::ofstream *outstream,
1615                                           std::ofstream *out1stream,
1616                                           std::ofstream *out2stream) const {
1617   std::string mthn = "[PixelPortCardConfig::writeXMLTrailer()]\t\t\t    ";
1618 
1619   *outstream << " </DATA_SET>" << std::endl;
1620   *outstream << "</ROOT> " << std::endl;
1621 
1622   outstream->close();
1623 }