Back to home page

Project CMSSW displayed by LXR

 
 

    


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

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