File indexing completed on 2023-03-17 10:42:06
0001
0002
0003
0004
0005
0006
0007 #include "CalibFormats/SiPixelObjects/interface/PixelTTCciConfig.h"
0008 #include "CalibFormats/SiPixelObjects/interface/PixelTimeFormatter.h"
0009 #include <sstream>
0010 #include <cassert>
0011 #include <stdexcept>
0012
0013 using namespace pos;
0014 using namespace std;
0015
0016 PixelTTCciConfig::PixelTTCciConfig(vector<vector<string> > &tableMat) : PixelConfigBase(" ", " ", " ") {
0017 std::map<std::string, int> colM;
0018 std::vector<std::string> colNames;
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031 colNames.push_back("CONFIG_KEY");
0032 colNames.push_back("KEY_TYPE");
0033 colNames.push_back("KEY_ALIAS");
0034 colNames.push_back("VERSION");
0035 colNames.push_back("KIND_OF_COND");
0036 colNames.push_back("TTC_OBJ_DATA_FILE");
0037 colNames.push_back("TTC_OBJ_DATA_CLOB");
0038
0039 for (unsigned int c = 0; c < tableMat[0].size(); c++) {
0040 for (unsigned int n = 0; n < colNames.size(); n++) {
0041 if (tableMat[0][c] == colNames[n]) {
0042 colM[colNames[n]] = c;
0043 break;
0044 }
0045 }
0046 }
0047 for (unsigned int n = 0; n < colNames.size(); n++) {
0048 if (colM.find(colNames[n]) == colM.end()) {
0049 std::cerr << "[PixelTTCciConfig::PixelTTCciConfig()]\tCouldn't find in the database the column with name "
0050 << colNames[n] << std::endl;
0051 assert(0);
0052 }
0053 }
0054 ttcConfigStream_ << tableMat[1][colM["TTC_OBJ_DATA_CLOB"]];
0055
0056 }
0057
0058 PixelTTCciConfig::PixelTTCciConfig(std::string filename) : PixelConfigBase(" ", " ", " ") {
0059 std::string mthn = "]\t[PixelTKFECConfig::PixelTKFECConfig()]\t\t\t ";
0060 std::ifstream in(filename.c_str());
0061
0062 if (!in.good()) {
0063 std::cout << __LINE__ << mthn << "Could not open: " << filename << std::endl;
0064 throw std::runtime_error("Failed to open file " + filename);
0065 } else {
0066 std::cout << __LINE__ << mthn << "Opened : " << filename << std::endl;
0067 }
0068
0069
0070 string line;
0071 while (!in.eof()) {
0072 getline(in, line);
0073 ttcConfigStream_ << line << endl;
0074 }
0075 }
0076
0077 void PixelTTCciConfig::writeASCII(std::string dir) const {
0078 if (!dir.empty())
0079 dir += "/";
0080 std::string filename = dir + "TTCciConfiguration.txt";
0081 std::ofstream out(filename.c_str());
0082
0083
0084
0085
0086 string configstr = ttcConfigStream_.str();
0087
0088 out << configstr << endl;
0089
0090 out.close();
0091 }
0092
0093
0094 void PixelTTCciConfig::writeXMLHeader(pos::PixelConfigKey key,
0095 int version,
0096 std::string path,
0097 std::ofstream *outstream,
0098 std::ofstream *out1stream,
0099 std::ofstream *out2stream) const {
0100 std::string mthn = "[PixelTTCciConfig::writeXMLHeader()]\t\t\t ";
0101 std::stringstream maskFullPath;
0102
0103 writeASCII(path);
0104
0105 maskFullPath << path << "/Pixel_TtcParameters_" << PixelTimeFormatter::getmSecTime() << ".xml";
0106 std::cout << mthn << "Writing to: " << maskFullPath.str() << std::endl;
0107
0108 outstream->open(maskFullPath.str().c_str());
0109
0110 *outstream << "<?xml version='1.0' encoding='UTF-8' standalone='yes'?>" << std::endl;
0111 *outstream << "<ROOT xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>" << std::endl;
0112 *outstream << "" << std::endl;
0113 *outstream << " <HEADER>" << std::endl;
0114 *outstream << " <TYPE>" << std::endl;
0115 *outstream << " <EXTENSION_TABLE_NAME>PIXEL_TTC_PARAMETERS</EXTENSION_TABLE_NAME>" << std::endl;
0116 *outstream << " <NAME>TTC Configuration Parameters</NAME>" << std::endl;
0117 *outstream << " </TYPE>" << std::endl;
0118 *outstream << " <RUN>" << std::endl;
0119 *outstream << " <RUN_TYPE>TTC Configuration Parameters</RUN_TYPE>" << std::endl;
0120 *outstream << " <RUN_NUMBER>1</RUN_NUMBER>" << std::endl;
0121 *outstream << " <RUN_BEGIN_TIMESTAMP>" << PixelTimeFormatter::getTime() << "</RUN_BEGIN_TIMESTAMP>" << std::endl;
0122 *outstream << " <LOCATION>CERN P5</LOCATION>" << std::endl;
0123 *outstream << " </RUN>" << std::endl;
0124 *outstream << " </HEADER>" << std::endl;
0125 *outstream << "" << std::endl;
0126 *outstream << " <DATA_SET>" << std::endl;
0127 *outstream << "" << std::endl;
0128 *outstream << " <VERSION>" << version << "</VERSION>" << std::endl;
0129 *outstream << " <COMMENT_DESCRIPTION>" << getComment() << "</COMMENT_DESCRIPTION>" << std::endl;
0130 *outstream << " <CREATED_BY_USER>" << getAuthor() << "</CREATED_BY_USER>" << std::endl;
0131 *outstream << "" << std::endl;
0132 *outstream << " <PART>" << std::endl;
0133 *outstream << " <NAME_LABEL>CMS-PIXEL-ROOT</NAME_LABEL>" << std::endl;
0134 *outstream << " <KIND_OF_PART>Detector ROOT</KIND_OF_PART>" << std::endl;
0135 *outstream << " </PART>" << std::endl;
0136 }
0137
0138
0139 void PixelTTCciConfig::writeXML(std::ofstream *outstream, std::ofstream *out1stream, std::ofstream *out2stream) const {
0140 std::string mthn = "[PixelTTCciConfig::writeXML()]\t\t\t ";
0141
0142 *outstream << " " << std::endl;
0143 *outstream << " <DATA>" << std::endl;
0144 *outstream << " <TTC_OBJ_DATA_FILE>TTCciConfiguration.txt</TTC_OBJ_DATA_FILE>" << std::endl;
0145 *outstream << " </DATA>" << std::endl;
0146 *outstream << " " << std::endl;
0147 }
0148
0149
0150 void PixelTTCciConfig::writeXMLTrailer(std::ofstream *outstream,
0151 std::ofstream *out1stream,
0152 std::ofstream *out2stream) const {
0153 std::string mthn = "[PixelTTCciConfig::writeXMLTrailer()]\t\t\t ";
0154
0155 *outstream << " " << std::endl;
0156 *outstream << " </DATA_SET>" << std::endl;
0157 *outstream << "</ROOT>" << std::endl;
0158
0159 outstream->close();
0160 std::cout << mthn << "Data written " << std::endl;
0161 }