File indexing completed on 2024-04-06 11:58:17
0001
0002
0003
0004
0005
0006
0007 #include "CalibFormats/SiPixelObjects/interface/PixelTKFECConfig.h"
0008 #include "CalibFormats/SiPixelObjects/interface/PixelTimeFormatter.h"
0009 #include <fstream>
0010 #include <sstream>
0011 #include <map>
0012 #include <cassert>
0013 #include <stdexcept>
0014
0015 using namespace pos;
0016 using namespace std;
0017
0018 PixelTKFECConfig::PixelTKFECConfig(std::vector<std::vector<std::string> > &tableMat) : PixelConfigBase(" ", " ", " ") {
0019 std::map<std::string, int> colM;
0020 std::vector<std::string> colNames;
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040 colNames.push_back("CONFIG_KEY");
0041 colNames.push_back("KEY_TYPE");
0042 colNames.push_back("KEY_ALIAS");
0043 colNames.push_back("VERSION");
0044 colNames.push_back("KIND_OF_COND");
0045 colNames.push_back("TRKFEC_NAME");
0046 colNames.push_back("CRATE_LABEL");
0047 colNames.push_back("CRATE_NUMBER");
0048 colNames.push_back("TYPE");
0049 colNames.push_back("SLOT_NUMBER");
0050 colNames.push_back("VME_ADDR");
0051 colNames.push_back("I2CSPEED");
0052
0053 for (unsigned int c = 0; c < tableMat[0].size(); c++) {
0054 for (unsigned int n = 0; n < colNames.size(); n++) {
0055 if (tableMat[0][c] == colNames[n]) {
0056 colM[colNames[n]] = c;
0057 break;
0058 }
0059 }
0060 }
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072 for (unsigned int r = 1; r < tableMat.size(); r++)
0073 {
0074 std::string TKFECID = tableMat[r][colM["TRKFEC_NAME"]];
0075 unsigned int crate = atoi(tableMat[r][colM["CRATE_NUMBER"]].c_str());
0076 std::string type = "VME";
0077 unsigned int address = strtoul(tableMat[r][colM["VME_ADDR"]].c_str(), nullptr, 16);
0078 PixelTKFECParameters tmp;
0079 tmp.setTKFECParameters(TKFECID, crate, type, address);
0080 TKFECconfig_.push_back(tmp);
0081
0082 }
0083 }
0084
0085
0086
0087 PixelTKFECConfig::PixelTKFECConfig(std::string filename) : PixelConfigBase(" ", " ", " ") {
0088 std::string mthn = "]\t[PixelTKFECConfig::PixelTKFECConfig()]\t\t\t ";
0089 std::ifstream in(filename.c_str());
0090
0091 if (!in.good()) {
0092 std::cout << __LINE__ << mthn << "Could not open: " << filename << std::endl;
0093 throw std::runtime_error("Failed to open file " + filename);
0094 } else {
0095 std::cout << __LINE__ << mthn << "Opened: " << filename << std::endl;
0096 }
0097
0098 std::string dummy;
0099
0100 getline(in, dummy);
0101
0102 do {
0103 std::string TKFECID;
0104 unsigned int crate;
0105 std::string type;
0106 unsigned int address;
0107
0108 in >> TKFECID >> std::dec >> crate >> type;
0109 if (type == "VME" || type == "PCI") {
0110 in >> std::hex >> address >> std::dec;
0111 } else
0112 {
0113 address = strtoul(type.c_str(), nullptr, 16);
0114 type = "VME";
0115 }
0116
0117 if (!in.eof()) {
0118
0119
0120
0121 PixelTKFECParameters tmp;
0122
0123 tmp.setTKFECParameters(TKFECID, crate, type, address);
0124
0125 TKFECconfig_.push_back(tmp);
0126 }
0127
0128 } while (!in.eof());
0129 in.close();
0130 }
0131
0132 PixelTKFECConfig::~PixelTKFECConfig() {}
0133
0134 void PixelTKFECConfig::writeASCII(std::string dir) const {
0135 if (!dir.empty())
0136 dir += "/";
0137 string filename = dir + "tkfecconfig.dat";
0138
0139 ofstream out(filename.c_str());
0140 if (!out.good()) {
0141 cout << "Could not open file:" << filename << endl;
0142 assert(0);
0143 }
0144
0145 out << "#TKFEC ID crate VME/PCI slot/address" << endl;
0146 for (unsigned int i = 0; i < TKFECconfig_.size(); i++) {
0147 out << TKFECconfig_[i].getTKFECID() << " " << TKFECconfig_[i].getCrate() << " ";
0148 if (TKFECconfig_[i].getType() == "PCI") {
0149 out << "PCI ";
0150 } else {
0151 out << " ";
0152 }
0153 out << "0x" << hex << TKFECconfig_[i].getAddress() << dec << endl;
0154 }
0155 out.close();
0156 }
0157
0158
0159
0160
0161
0162
0163
0164
0165
0166
0167 unsigned int PixelTKFECConfig::getNTKFECBoards() const { return TKFECconfig_.size(); }
0168
0169 std::string PixelTKFECConfig::getTKFECID(unsigned int i) const {
0170 assert(i < TKFECconfig_.size());
0171 return TKFECconfig_[i].getTKFECID();
0172 }
0173
0174 unsigned int PixelTKFECConfig::getCrate(unsigned int i) const {
0175 assert(i < TKFECconfig_.size());
0176 return TKFECconfig_[i].getCrate();
0177 }
0178
0179 std::string PixelTKFECConfig::getType(unsigned int i) const {
0180 assert(i < TKFECconfig_.size());
0181 return TKFECconfig_[i].getType();
0182 }
0183
0184 unsigned int PixelTKFECConfig::getAddress(unsigned int i) const {
0185 assert(i < TKFECconfig_.size());
0186 return TKFECconfig_[i].getAddress();
0187 }
0188
0189 unsigned int PixelTKFECConfig::crateFromTKFECID(std::string TKFECID) const {
0190 for (unsigned int i = 0; i < TKFECconfig_.size(); i++) {
0191 if (TKFECconfig_[i].getTKFECID() == TKFECID)
0192 return TKFECconfig_[i].getCrate();
0193 }
0194
0195 std::cout << "Could not find TKFEC ID:" << TKFECID << std::endl;
0196
0197 assert(0);
0198
0199 return 0;
0200 }
0201
0202 std::string PixelTKFECConfig::typeFromTKFECID(std::string TKFECID) const {
0203 for (unsigned int i = 0; i < TKFECconfig_.size(); i++) {
0204 if (TKFECconfig_[i].getTKFECID() == TKFECID)
0205 return TKFECconfig_[i].getType();
0206 }
0207
0208 std::cout << "Could not find TKFEC ID:" << TKFECID << std::endl;
0209
0210 assert(0);
0211
0212 return nullptr;
0213 }
0214
0215 unsigned int PixelTKFECConfig::addressFromTKFECID(std::string TKFECID) const {
0216 for (unsigned int i = 0; i < TKFECconfig_.size(); i++) {
0217 if (TKFECconfig_[i].getTKFECID() == TKFECID)
0218 return TKFECconfig_[i].getAddress();
0219 }
0220
0221 std::cout << "Could not find TKFEC ID:" << TKFECID << std::endl;
0222
0223 assert(0);
0224
0225 return 0;
0226 }
0227
0228
0229 void PixelTKFECConfig::writeXMLHeader(pos::PixelConfigKey key,
0230 int version,
0231 std::string path,
0232 std::ofstream *outstream,
0233 std::ofstream *out1stream,
0234 std::ofstream *out2stream) const {
0235 std::string mthn = "[PixelTKFECConfig::writeXMLHeader()]\t\t\t ";
0236 std::stringstream maskFullPath;
0237
0238 maskFullPath << path << "/Pixel_TrackerFecParameters_" << PixelTimeFormatter::getmSecTime() << ".xml";
0239 std::cout << mthn << "Writing to: " << maskFullPath.str() << std::endl;
0240
0241 outstream->open(maskFullPath.str().c_str());
0242
0243 *outstream << "<?xml version='1.0' encoding='UTF-8' standalone='yes'?>" << std::endl;
0244 *outstream << "<ROOT xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>" << std::endl;
0245 *outstream << "" << std::endl;
0246 *outstream << " <HEADER>" << std::endl;
0247 *outstream << " <TYPE>" << std::endl;
0248 *outstream << " <EXTENSION_TABLE_NAME>TRACKER_FEC_PARAMETERS</EXTENSION_TABLE_NAME>" << std::endl;
0249 *outstream << " <NAME>Tracker FEC Parameters</NAME>" << std::endl;
0250 *outstream << " </TYPE>" << std::endl;
0251 *outstream << " <RUN>" << std::endl;
0252 *outstream << " <RUN_TYPE>Tracker FEC Parameters</RUN_TYPE>" << std::endl;
0253 *outstream << " <RUN_NUMBER>1</RUN_NUMBER>" << std::endl;
0254 *outstream << " <RUN_BEGIN_TIMESTAMP>" << PixelTimeFormatter::getTime() << "</RUN_BEGIN_TIMESTAMP>" << std::endl;
0255 *outstream << " <LOCATION>CERN P5</LOCATION>" << std::endl;
0256 *outstream << " </RUN>" << std::endl;
0257 *outstream << " </HEADER>" << std::endl;
0258 *outstream << "" << std::endl;
0259 *outstream << " <DATA_SET>" << std::endl;
0260 *outstream << "" << std::endl;
0261 *outstream << " <VERSION>" << version << "</VERSION>" << std::endl;
0262 *outstream << " <COMMENT_DESCRIPTION>" << getComment() << "</COMMENT_DESCRIPTION>" << std::endl;
0263 *outstream << " <CREATED_BY_USER>" << getAuthor() << "</CREATED_BY_USER>" << std::endl;
0264 *outstream << "" << std::endl;
0265 *outstream << " <PART>" << std::endl;
0266 *outstream << " <NAME_LABEL>CMS-PIXEL-ROOT</NAME_LABEL>" << std::endl;
0267 *outstream << " <KIND_OF_PART>Detector ROOT</KIND_OF_PART>" << std::endl;
0268 *outstream << " </PART>" << std::endl;
0269 }
0270
0271
0272 void PixelTKFECConfig::writeXML(std::ofstream *outstream, std::ofstream *out1stream, std::ofstream *out2stream) const {
0273 std::string mthn = "[PixelTKFECConfig::writeXML()]\t\t\t ";
0274
0275 for (unsigned int i = 0; i < TKFECconfig_.size(); i++) {
0276 *outstream << " <DATA>" << std::endl;
0277 *outstream << " <TRKFEC_NAME>" << TKFECconfig_[i].getTKFECID() << "</TRKFEC_NAME>" << std::endl;
0278 *outstream << " <CRATE_NUMBER>" << TKFECconfig_[i].getCrate() << "</CRATE_NUMBER>" << std::endl;
0279 *outstream << " <VME_ADDR>"
0280 << "0x" << hex << TKFECconfig_[i].getAddress() << dec << "</VME_ADDR>" << std::endl;
0281 *outstream << " </DATA>" << std::endl;
0282 }
0283 }
0284
0285
0286 void PixelTKFECConfig::writeXMLTrailer(std::ofstream *outstream,
0287 std::ofstream *out1stream,
0288 std::ofstream *out2stream) const {
0289 std::string mthn = "[PixelTKFECConfig::writeXMLTrailer()]\t\t\t ";
0290
0291 *outstream << " </DATA_SET>" << std::endl;
0292 *outstream << "</ROOT>" << std::endl;
0293
0294 outstream->close();
0295 std::cout << mthn << "Data written " << std::endl;
0296 }