CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch12/src/CalibFormats/SiPixelObjects/src/PixelLTCConfig.cc

Go to the documentation of this file.
00001 //
00002 // This class reads the LTC configuration file
00003 //
00004 //
00005 //
00006  
00007 #include "CalibFormats/SiPixelObjects/interface/PixelLTCConfig.h"
00008 #include "CalibFormats/SiPixelObjects/interface/PixelTimeFormatter.h"
00009 #include <sstream>   
00010 #include <cassert>   
00011 #include <stdexcept>
00012 
00013 using namespace pos;
00014 using namespace std;
00015 
00016 PixelLTCConfig::PixelLTCConfig(vector< vector<string> > &tableMat):PixelConfigBase(" ", " ", " ")
00017 {
00018   std::string mthn = "[PixelLTCConfig::PixelLTCConfig()]\t\t\t    " ;
00019   std::map<std::string , int > colM;
00020   std::vector<std::string > colNames;
00033   colNames.push_back("CONFIG_KEY"       );
00034   colNames.push_back("KEY_TYPE"         );
00035   colNames.push_back("KEY_ALIAS"        );
00036   colNames.push_back("VERSION"          );
00037   colNames.push_back("KIND_OF_COND"     );
00038   colNames.push_back("LTC_OBJ_DATA_FILE");
00039   colNames.push_back("LTC_OBJ_DATA_CLOB");
00040 
00041   for(unsigned int c = 0 ; c < tableMat[0].size() ; c++)
00042     {
00043       for(unsigned int n=0; n<colNames.size(); n++)
00044         {
00045           if(tableMat[0][c] == colNames[n])
00046             {
00047               colM[colNames[n]] = c;
00048               break;
00049             }
00050         }
00051     }//end for
00052   for(unsigned int n=0; n<colNames.size(); n++)
00053     {
00054       if(colM.find(colNames[n]) == colM.end())
00055         {
00056           std::cerr << __LINE__ << "]\t" << mthn << "Couldn't find in the database the column with name " << colNames[n] << std::endl;
00057           assert(0);
00058         }
00059     }
00060   ltcConfigStream_ << tableMat[1][colM["LTC_OBJ_DATA_CLOB"]] ;
00061 //   cout << "[PixelTTCciConfig::PixelTTCciConfig()]\tRead: "<< endl<< ttcConfigStream_.str() << endl ;
00062 }
00063 
00064 PixelLTCConfig::PixelLTCConfig(std::string filename):
00065   PixelConfigBase(" "," "," "){
00066 
00067     std::string mthn = "[PixelLTCConfig::PixelLTCConfig()]\t\t\t    " ;
00068     std::ifstream in(filename.c_str());
00069 
00070     if (!in.good()){
00071         std::cout << __LINE__ << "]\t" << mthn << "Could not open: " << filename << std::endl;
00072         throw std::runtime_error("Failed to open file "+filename);
00073     }
00074     else {
00075         std::cout << __LINE__ << "]\t" << mthn << "Opened: "         << filename << std::endl;
00076     }
00077 
00078     //ltcConfigPath_ = filename;
00079     string line;
00080     while (!in.eof()) {
00081        getline (in,line);
00082        ltcConfigStream_ << line << endl;
00083     }
00084 
00085 } 
00086 
00087 void PixelLTCConfig::writeASCII(std::string dir) const {
00088 
00089   if (dir!="") dir+="/";
00090   std::string filename=dir+"LTCConfiguration.txt";
00091   std::ofstream out(filename.c_str());
00092 
00093   //std::ifstream in(ltcConfigPath_.c_str());
00094   //assert(in.good());
00095 
00096   string configstr = ltcConfigStream_.str();
00097 
00098   out << configstr << endl;
00099 
00100   out.close();
00101 
00102 }
00103 
00104 //=============================================================================================
00105 void PixelLTCConfig::writeXMLHeader(pos::PixelConfigKey key, 
00106                                     int version, 
00107                                     std::string path, 
00108                                     std::ofstream *outstream,
00109                                     std::ofstream *out1stream,
00110                                     std::ofstream *out2stream) const
00111 {
00112   std::string mthn = "[PixelLTCConfig::writeXMLHeader()]\t\t\t    " ;
00113   std::stringstream maskFullPath ;
00114 
00115   writeASCII(path) ;
00116 
00117   maskFullPath << path << "/Pixel_LtcParameters_" << PixelTimeFormatter::getmSecTime() << ".xml";
00118   std::cout << __LINE__ << "]\t" << mthn << "Writing to: " << maskFullPath.str() << std::endl ;
00119 
00120   outstream->open(maskFullPath.str().c_str()) ;
00121   
00122   *outstream << "<?xml version='1.0' encoding='UTF-8' standalone='yes'?>"                                 << std::endl ;
00123   *outstream << "<ROOT xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>"                            << std::endl ;
00124   *outstream << ""                                                                                        << std::endl ; 
00125   *outstream << " <HEADER>"                                                                               << std::endl ; 
00126   *outstream << "  <TYPE>"                                                                                << std::endl ; 
00127   *outstream << "   <EXTENSION_TABLE_NAME>PIXEL_LTC_PARAMETERS</EXTENSION_TABLE_NAME>"                    << std::endl ; 
00128   *outstream << "   <NAME>LTC Configuration Parameters</NAME>"                                            << std::endl ; 
00129   *outstream << "  </TYPE>"                                                                               << std::endl ; 
00130   *outstream << "  <RUN>"                                                                                 << std::endl ; 
00131   *outstream << "   <RUN_TYPE>LTC Configuration Parameters</RUN_TYPE>"                                    << std::endl ; 
00132   *outstream << "   <RUN_NUMBER>1</RUN_NUMBER>"                                                           << std::endl ; 
00133   *outstream << "   <RUN_BEGIN_TIMESTAMP>" << PixelTimeFormatter::getTime() << "</RUN_BEGIN_TIMESTAMP>"   << std::endl ; 
00134   *outstream << "   <LOCATION>CERN P5</LOCATION>"                                                         << std::endl ; 
00135   *outstream << "  </RUN>"                                                                                << std::endl ; 
00136   *outstream << " </HEADER>"                                                                              << std::endl ; 
00137   *outstream << ""                                                                                        << std::endl ; 
00138   *outstream << " <DATA_SET>"                                                                             << std::endl ;
00139   *outstream << ""                                                                                        << std::endl ;
00140   *outstream << "  <VERSION>"             << version      << "</VERSION>"                                 << std::endl ;
00141   *outstream << "  <COMMENT_DESCRIPTION>" << getComment() << "</COMMENT_DESCRIPTION>"                     << std::endl ;
00142   *outstream << "  <CREATED_BY_USER>"     << getAuthor()  << "</CREATED_BY_USER>"                         << std::endl ;
00143   *outstream << ""                                                                                        << std::endl ;
00144   *outstream << "  <PART>"                                                                                << std::endl ;
00145   *outstream << "   <NAME_LABEL>CMS-PIXEL-ROOT</NAME_LABEL>"                                              << std::endl ;      
00146   *outstream << "   <KIND_OF_PART>Detector ROOT</KIND_OF_PART>"                                           << std::endl ;         
00147   *outstream << "  </PART>"                                                                               << std::endl ;
00148 
00149 }
00150 
00151 //=============================================================================================
00152 void PixelLTCConfig::writeXML( std::ofstream *outstream,
00153                                std::ofstream *out1stream,
00154                                std::ofstream *out2stream) const 
00155 {
00156   std::string mthn = "[PixelLTCConfig::writeXML()]\t\t\t    " ;
00157 
00158   *outstream << " <DATA>"                                                                                 << std::endl ;
00159   *outstream << "  <LTC_OBJ_DATA_FILE>./LTCConfiguration.txt</LTC_OBJ_DATA_FILE>"                         << std::endl ;
00160   *outstream << " </DATA>"                                                                                << std::endl ;
00161 }
00162 
00163 //=============================================================================================
00164 void PixelLTCConfig::writeXMLTrailer(std::ofstream *outstream,
00165                                      std::ofstream *out1stream,
00166                                      std::ofstream *out2stream ) const 
00167 {
00168   std::string mthn = "[PixelLTCConfig::writeXMLTrailer()]\t\t\t    " ;
00169   
00170   *outstream << " </DATA_SET>"                                                                            << std::endl ;
00171   *outstream << "</ROOT>"                                                                                 << std::endl ;
00172   
00173   outstream->close() ;
00174   std::cout << __LINE__ << "]\t" << mthn << "Data written "                                               << std::endl ;
00175 
00176 }
00177 
00178    
00179