File indexing completed on 2024-04-06 11:58:16
0001
0002
0003
0004
0005
0006
0007
0008 #include "CalibFormats/SiPixelObjects/interface/PixelMaxVsf.h"
0009 #include "CalibFormats/SiPixelObjects/interface/PixelTimeFormatter.h"
0010 #include <fstream>
0011 #include <iostream>
0012 #include <sstream>
0013 #include <ios>
0014 #include <cassert>
0015 #include <cstdio>
0016 #include <stdexcept>
0017
0018 using namespace std;
0019 using namespace pos;
0020
0021 PixelMaxVsf::PixelMaxVsf(std::vector<std::vector<std::string> > &tableMat) : PixelConfigBase("", "", "") {
0022 std::string mthn = "[PixelMaxVsf::PixelMaxVsf()]\t\t\t\t ";
0023 std::map<std::string, int> colM;
0024 std::vector<std::string> colNames;
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038 colNames.push_back("CONFIG_KEY");
0039 colNames.push_back("KEY_TYPE");
0040 colNames.push_back("KEY_ALIAS");
0041 colNames.push_back("VERSION");
0042 colNames.push_back("KIND_OF_COND");
0043 colNames.push_back("ROC_NAME");
0044 colNames.push_back("MAXVSF");
0045
0046 for (unsigned int c = 0; c < tableMat[0].size(); c++) {
0047 for (unsigned int n = 0; n < colNames.size(); n++) {
0048 if (tableMat[0][c] == colNames[n]) {
0049 colM[colNames[n]] = c;
0050 break;
0051 }
0052 }
0053 }
0054 for (unsigned int n = 0; n < colNames.size(); n++) {
0055 if (colM.find(colNames[n]) == colM.end()) {
0056 std::cerr << __LINE__ << "]\t" << mthn << "Couldn't find in the database the column with name " << colNames[n]
0057 << std::endl;
0058 assert(0);
0059 }
0060 }
0061
0062 rocs_.clear();
0063
0064 for (unsigned int r = 1; r < tableMat.size(); r++)
0065 {
0066 PixelROCName roc(tableMat[r][colM["ROC_NAME"]]);
0067 unsigned int vsf;
0068 vsf = atoi(tableMat[r][colM["MAXVSF"]].c_str());
0069 rocs_[roc] = vsf;
0070 }
0071 }
0072
0073
0074
0075 PixelMaxVsf::PixelMaxVsf(std::string filename) : PixelConfigBase("", "", "") {
0076 std::string mthn = "[PixelMaxVsf::PixelMaxVsf()]\t\t\t\t ";
0077
0078 if (filename[filename.size() - 1] == 't') {
0079 std::ifstream in(filename.c_str());
0080
0081 if (!in.good()) {
0082 std::cout << __LINE__ << "]\t" << mthn << "Could not open: " << filename << std::endl;
0083 throw std::runtime_error("Failed to open file " + filename);
0084 } else {
0085 std::cout << __LINE__ << "]\t" << mthn << "Opened: " << filename << std::endl;
0086 }
0087
0088 if (in.eof()) {
0089 std::cout << __LINE__ << "]\t" << mthn << "eof before reading anything!" << std::endl;
0090 throw std::runtime_error("File appears to be empty: " + filename);
0091 }
0092
0093 rocs_.clear();
0094
0095 std::string rocname;
0096
0097 in >> rocname;
0098 while (!in.eof()) {
0099
0100 PixelROCName roc(rocname);
0101 unsigned int vsf;
0102 in >> vsf;
0103 rocs_[roc] = vsf;
0104 in >> rocname;
0105 }
0106 return;
0107 } else {
0108 assert(0);
0109 }
0110 }
0111
0112 bool PixelMaxVsf::getVsf(PixelROCName roc, unsigned int &Vsf) const {
0113 std::map<PixelROCName, unsigned int>::const_iterator itr = rocs_.find(roc);
0114
0115 if (itr == rocs_.end()) {
0116 return false;
0117 }
0118
0119 Vsf = itr->second;
0120
0121 return true;
0122 }
0123
0124 void PixelMaxVsf::setVsf(PixelROCName roc, unsigned int Vsf) { rocs_[roc] = Vsf; }
0125
0126 void PixelMaxVsf::writeASCII(std::string dir) const {
0127 std::string mthn = "[PixelMaxVsf::writeASCII()]\t\t\t\t ";
0128 if (!dir.empty())
0129 dir += "/";
0130 std::string filename = dir + "maxvsf.dat";
0131
0132 std::ofstream out(filename.c_str(), std::ios_base::out);
0133 if (!out) {
0134 std::cout << __LINE__ << "]\t" << mthn << "Could not open file " << filename << " for write" << std::endl;
0135 exit(1);
0136 }
0137
0138 std::map<PixelROCName, unsigned int>::const_iterator irocs = rocs_.begin();
0139 for (; irocs != rocs_.end(); ++irocs) {
0140 out << (irocs->first).rocname() << " " << irocs->second << endl;
0141 }
0142
0143 out.close();
0144 }
0145
0146
0147 void PixelMaxVsf::writeXMLHeader(pos::PixelConfigKey key,
0148 int version,
0149 std::string path,
0150 std::ofstream *outstream,
0151 std::ofstream *out1stream,
0152 std::ofstream *out2stream) const {
0153 std::string mthn = "[PixelMaxVsf::writeXMLHeader()]\t\t\t ";
0154 std::stringstream maskFullPath;
0155
0156 maskFullPath << path << "/Pixel_RocMaxVsf_" << PixelTimeFormatter::getmSecTime() << ".xml";
0157 std::cout << __LINE__ << "]\t" << mthn << "Writing to: " << maskFullPath.str() << std::endl;
0158
0159 outstream->open(maskFullPath.str().c_str());
0160
0161 *outstream << "<?xml version='1.0' encoding='UTF-8' standalone='yes'?>" << std::endl;
0162 *outstream << "<ROOT xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>" << std::endl;
0163 *outstream << "" << std::endl;
0164 *outstream << " <HEADER>" << std::endl;
0165 *outstream << " <TYPE>" << std::endl;
0166 *outstream << " <EXTENSION_TABLE_NAME>ROC_MAXVSF</EXTENSION_TABLE_NAME>" << std::endl;
0167 *outstream << " <NAME>ROC MaxVsf Setting</NAME>" << std::endl;
0168 *outstream << " </TYPE>" << std::endl;
0169 *outstream << " <RUN>" << std::endl;
0170 *outstream << " <RUN_TYPE>ROC MaxVsf Settings</RUN_TYPE>" << std::endl;
0171 *outstream << " <RUN_NUMBER>1</RUN_NUMBER>" << std::endl;
0172 *outstream << " <RUN_BEGIN_TIMESTAMP>" << PixelTimeFormatter::getTime() << "</RUN_BEGIN_TIMESTAMP>" << std::endl;
0173 *outstream << " <LOCATION>CERN P5</LOCATION>" << std::endl;
0174 *outstream << " </RUN>" << std::endl;
0175 *outstream << " </HEADER>" << std::endl;
0176 *outstream << "" << std::endl;
0177 *outstream << " <DATA_SET>" << std::endl;
0178 *outstream << "" << std::endl;
0179 *outstream << " <VERSION>" << version << "</VERSION>" << std::endl;
0180 *outstream << " <COMMENT_DESCRIPTION>" << getComment() << "</COMMENT_DESCRIPTION>" << std::endl;
0181 *outstream << " <CREATED_BY_USER>" << getAuthor() << "</CREATED_BY_USER>" << std::endl;
0182 *outstream << "" << std::endl;
0183 *outstream << " <PART>" << std::endl;
0184 *outstream << " <NAME_LABEL>CMS-PIXEL-ROOT</NAME_LABEL>" << std::endl;
0185 *outstream << " <KIND_OF_PART>Detector ROOT</KIND_OF_PART>" << std::endl;
0186 *outstream << " </PART>" << std::endl;
0187 }
0188
0189
0190 void PixelMaxVsf::writeXML(std::ofstream *outstream, std::ofstream *out1stream, std::ofstream *out2stream) const {
0191 std::string mthn = "[PixelMaxVsf::writeXML()]\t\t\t ";
0192
0193 std::map<PixelROCName, unsigned int>::const_iterator irocs = rocs_.begin();
0194 for (; irocs != rocs_.end(); ++irocs) {
0195 *outstream << " <DATA>" << std::endl;
0196 *outstream << " <ROC_NAME>" << (irocs->first).rocname() << "</ROC_NAME>" << std::endl;
0197 *outstream << " <MAXVSF>" << irocs->second << "</MAXVSF>" << std::endl;
0198 *outstream << " </DATA>" << std::endl;
0199 *outstream << std::endl;
0200 }
0201 }
0202
0203
0204 void PixelMaxVsf::writeXMLTrailer(std::ofstream *outstream,
0205 std::ofstream *out1stream,
0206 std::ofstream *out2stream) const {
0207 std::string mthn = "[PixelMaxVsf::writeXMLTrailer()]\t\t\t ";
0208
0209 *outstream << " </DATA_SET>" << std::endl;
0210 *outstream << "</ROOT>" << std::endl;
0211
0212 outstream->close();
0213 std::cout << __LINE__ << "]\t" << mthn << "Data written " << std::endl;
0214 }