Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 //
0002 // Implementation of the detector configuration
0003 //
0004 //
0005 //
0006 //
0007 
0008 #include "CalibFormats/SiPixelObjects/interface/PixelLowVoltageMap.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 PixelLowVoltageMap::PixelLowVoltageMap(std::vector<std::vector<std::string> > &tableMat) : PixelConfigBase("", "", "") {
0022   std::string mthn = "[PixelLowVoltageMap::PixelLowVoltageMap()] ";
0023   std::map<std::string, int> colM;
0024   std::vector<std::string> colNames;
0025   /*
0026   EXTENSION_TABLE_NAME: XDAQ_LOW_VOLTAGE_MAP  (VIEW: CONF_KEY_XDAQ_LOW_VOLTAGE_V) 
0027   
0028   CONFIG_KEY                    NOT NULL VARCHAR2(80)
0029   KEY_TYPE                  NOT NULL VARCHAR2(80)
0030   KEY_ALIAS                 NOT NULL VARCHAR2(80)
0031   VERSION                        VARCHAR2(40)
0032   KIND_OF_COND                  NOT NULL VARCHAR2(40)
0033   PANEL_NAME                    NOT NULL VARCHAR2(200)
0034   DATAPOINT                 NOT NULL VARCHAR2(200)
0035   LV_DIGITAL                    NOT NULL VARCHAR2(200)
0036   LV_ANALOG                 NOT NULL VARCHAR2(200)
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("PANEL_NAME");
0046   colNames.push_back("DATAPOINT");
0047   colNames.push_back("LV_DIGITAL");
0048   colNames.push_back("LV_ANALOG");
0049   /*
0050   colNames.push_back("CONFIG_KEY_ID"    );
0051   colNames.push_back("CONFG_KEY"    );
0052   colNames.push_back("VERSION"  );
0053   colNames.push_back("KIND_OF_COND" );
0054   colNames.push_back("RUN_TYPE" );
0055   colNames.push_back("RUN_NUMBER"   );
0056   colNames.push_back("PANEL_NAME"   );
0057   colNames.push_back("DATAPOINT"    );
0058   colNames.push_back("LV_DIGITAL"   );
0059   colNames.push_back("LV_ANALOG"    );
0060 */
0061 
0062   for (unsigned int c = 0; c < tableMat[0].size(); c++) {
0063     for (unsigned int n = 0; n < colNames.size(); n++) {
0064       if (tableMat[0][c] == colNames[n]) {
0065         colM[colNames[n]] = c;
0066         break;
0067       }
0068     }
0069   }  //end for
0070   for (unsigned int n = 0; n < colNames.size(); n++) {
0071     if (colM.find(colNames[n]) == colM.end()) {
0072       std::cerr << mthn << "Couldn't find in the database the column with name " << colNames[n] << std::endl;
0073       assert(0);
0074     }
0075   }
0076 
0077   std::string modulename;
0078   std::string dpNameBase;
0079   std::string ianaChannel;
0080   std::string idigiChannel;
0081   for (unsigned int r = 1; r < tableMat.size(); r++)  //Goes to every row of the Matrix
0082   {
0083     modulename = tableMat[r][colM["PANEL_NAME"]];
0084     dpNameBase = tableMat[r][colM["DATAPOINT"]];
0085     ianaChannel = tableMat[r][colM["LV_ANALOG"]];
0086     idigiChannel = tableMat[r][colM["LV_DIGITAL"]];
0087     PixelModuleName module(modulename);
0088     pair<string, string> channels(ianaChannel, idigiChannel);
0089     pair<string, pair<string, string> > dpName(dpNameBase, channels);
0090     dpNameMap_[module] = dpName;
0091   }
0092 }  //end constructor
0093 
0094 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
0095 
0096 PixelLowVoltageMap::PixelLowVoltageMap(std::string filename) : PixelConfigBase("", "", "") {
0097   std::string mthn = "[PixelLowVoltageMap::PixelLowVoltageMap()]\t\t\t    ";
0098 
0099   if (filename[filename.size() - 1] == 't') {
0100     std::ifstream in(filename.c_str());
0101 
0102     if (!in.good()) {
0103       std::cout << __LINE__ << "]\t" << mthn << "Could not open: " << filename << std::endl;
0104       throw std::runtime_error("Failed to open file " + filename);
0105     } else {
0106       std::cout << __LINE__ << "]\t" << mthn << "Opened: " << filename << std::endl;
0107     }
0108 
0109     if (in.eof()) {
0110       std::cout << __LINE__ << "]\t" << mthn << "eof before reading anything!" << std::endl;
0111       throw std::runtime_error("Failure when reading file; file seems to be empty: " + filename);
0112     }
0113 
0114     dpNameMap_.clear();
0115 
0116     std::string modulename;
0117     std::string dpNameBase;
0118     std::string ianaChannel;
0119     std::string idigiChannel;
0120 
0121     in >> modulename >> dpNameBase >> ianaChannel >> idigiChannel;
0122 
0123     while (!in.eof()) {
0124       cout << __LINE__ << "]\t" << mthn << "Read modulename: " << modulename << endl;
0125       PixelModuleName module(modulename);
0126       pair<string, string> channels(ianaChannel, idigiChannel);
0127       pair<string, pair<string, string> > dpName(dpNameBase, channels);
0128       dpNameMap_[module] = dpName;
0129       in >> modulename >> dpNameBase >> ianaChannel >> idigiChannel;
0130     }
0131 
0132   } else {
0133     assert(0);
0134   }
0135 }
0136 
0137 std::string PixelLowVoltageMap::dpNameIana(const PixelModuleName &module) const {
0138   std::string mthn = "[PixelLowVoltageMap::dpNameIana()]\t\t\t    ";
0139   std::map<PixelModuleName, pair<string, pair<string, string> > >::const_iterator i = dpNameMap_.find(module);
0140 
0141   if (i == dpNameMap_.end()) {
0142     cout << __LINE__ << "]\t" << mthn << "Could not find module: " << module << endl;
0143   }
0144 
0145   return i->second.first + "/" + i->second.second.first;
0146 }
0147 
0148 std::string PixelLowVoltageMap::dpNameIdigi(const PixelModuleName &module) const {
0149   std::string mthn = "[PixelLowVoltageMap::dpNameIdigi()]\t\t\t    ";
0150   std::map<PixelModuleName, pair<string, pair<string, string> > >::const_iterator i = dpNameMap_.find(module);
0151 
0152   if (i == dpNameMap_.end()) {
0153     cout << __LINE__ << "]\t" << mthn << "Could not find module: " << module << endl;
0154   }
0155 
0156   return i->second.first + "/" + i->second.second.second;
0157 }
0158 
0159 void PixelLowVoltageMap::writeASCII(std::string dir) const {
0160   std::string mthn = "[PixelLowVoltageMap::writeASCII()]\t\t\t    ";
0161   if (!dir.empty())
0162     dir += "/";
0163   std::string filename = dir + "lowvoltagemap.dat";
0164 
0165   std::ofstream out(filename.c_str(), std::ios_base::out);
0166   if (!out) {
0167     std::cout << __LINE__ << "]\t" << mthn << "Could not open file " << filename << " for write" << std::endl;
0168     exit(1);
0169   }
0170   std::map<PixelModuleName, pair<string, pair<string, string> > >::const_iterator imodule = dpNameMap_.begin();
0171 
0172   for (; imodule != dpNameMap_.end(); ++imodule) {
0173     out << imodule->first << " " << imodule->second.first << " " << imodule->second.second.first << " "
0174         << imodule->second.second.second << endl;
0175   }
0176 
0177   out.close();
0178 }
0179 
0180 //=============================================================================================
0181 void PixelLowVoltageMap::writeXMLHeader(pos::PixelConfigKey key,
0182                                         int version,
0183                                         std::string path,
0184                                         std::ofstream *outstream,
0185                                         std::ofstream *out1stream,
0186                                         std::ofstream *out2stream) const {
0187   std::string mthn = "[PixelLowVoltageMap::writeXMLHeader()]\t\t\t    ";
0188   std::stringstream maskFullPath;
0189 
0190   maskFullPath << path << "/XDAQLowVoltageMap_Test_" << PixelTimeFormatter::getmSecTime() << ".xml";
0191   std::cout << __LINE__ << "]\t" << mthn << "Writing to: " << maskFullPath.str() << std::endl;
0192 
0193   outstream->open(maskFullPath.str().c_str());
0194 
0195   *outstream << "<?xml version='1.0' encoding='UTF-8' standalone='yes'?>" << std::endl;
0196   *outstream << "<ROOT xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>" << std::endl;
0197   *outstream << "" << std::endl;
0198   *outstream << " <HEADER>" << std::endl;
0199   *outstream << "  <TYPE>" << std::endl;
0200   *outstream << "   <EXTENSION_TABLE_NAME>XDAQ_LOW_VOLTAGE_MAP</EXTENSION_TABLE_NAME>" << std::endl;
0201   *outstream << "   <NAME>XDAQ Low Voltage Map</NAME>" << std::endl;
0202   *outstream << "  </TYPE>" << std::endl;
0203   *outstream << "  <RUN>" << std::endl;
0204   *outstream << "   <RUN_TYPE>XDAQ Low Voltage Map</RUN_TYPE>" << std::endl;
0205   *outstream << "   <RUN_NUMBER>1</RUN_NUMBER>" << std::endl;
0206   *outstream << "   <RUN_BEGIN_TIMESTAMP>" << PixelTimeFormatter::getTime() << "</RUN_BEGIN_TIMESTAMP>" << std::endl;
0207   *outstream << "   <LOCATION>CERN P5</LOCATION>" << std::endl;
0208   *outstream << "  </RUN>" << std::endl;
0209   *outstream << " </HEADER>" << std::endl;
0210   *outstream << "" << std::endl;
0211   *outstream << " <DATA_SET>" << std::endl;
0212   *outstream << "" << std::endl;
0213   *outstream << "  <VERSION>" << version << "</VERSION>" << std::endl;
0214   *outstream << "  <COMMENT_DESCRIPTION>" << getComment() << "</COMMENT_DESCRIPTION>" << std::endl;
0215   *outstream << "  <CREATED_BY_USER>" << getAuthor() << "</CREATED_BY_USER>" << std::endl;
0216   *outstream << "" << std::endl;
0217   *outstream << "  <PART>" << std::endl;
0218   *outstream << "   <NAME_LABEL>CMS-PIXEL-ROOT</NAME_LABEL>" << std::endl;
0219   *outstream << "   <KIND_OF_PART>Detector ROOT</KIND_OF_PART>" << std::endl;
0220   *outstream << "  </PART>" << std::endl;
0221   *outstream << " " << std::endl;
0222 }
0223 
0224 //=============================================================================================
0225 void PixelLowVoltageMap::writeXML(std::ofstream *outstream,
0226                                   std::ofstream *out1stream,
0227                                   std::ofstream *out2stream) const {
0228   std::string mthn = "[PixelLowVoltageMap::writeXML()]\t\t\t    ";
0229 
0230   std::map<PixelModuleName, pair<string, pair<string, string> > >::const_iterator imodule = dpNameMap_.begin();
0231 
0232   for (; imodule != dpNameMap_.end(); ++imodule) {
0233     *outstream << "  <DATA>" << std::endl;
0234     *outstream << "   <PANEL_NAME>" << imodule->first << "</PANEL_NAME>" << std::endl;
0235     *outstream << "   <DATAPOINT>" << imodule->second.first << "</DATAPOINT>" << std::endl;
0236     *outstream << "   <LV_DIGITAL>" << imodule->second.second.first << "</LV_DIGITAL>" << std::endl;
0237     *outstream << "   <LV_ANALOG>" << imodule->second.second.second << "</LV_ANALOG>" << std::endl;
0238     *outstream << "  </DATA>" << std::endl;
0239     *outstream << "" << std::endl;
0240   }
0241 }
0242 
0243 //=============================================================================================
0244 void PixelLowVoltageMap::writeXMLTrailer(std::ofstream *outstream,
0245                                          std::ofstream *out1stream,
0246                                          std::ofstream *out2stream) const {
0247   std::string mthn = "[PixelLowVoltageMap::writeXMLTrailer()]\t\t\t    ";
0248 
0249   *outstream << " </DATA_SET>" << std::endl;
0250   *outstream << "</ROOT>" << std::endl;
0251 
0252   outstream->close();
0253   std::cout << __LINE__ << "]\t" << mthn << "Data written " << std::endl;
0254 }