CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_0/src/CalibFormats/SiPixelObjects/src/PixelTTCciConfig.cc

Go to the documentation of this file.
00001 //
00002 // This class reads the TTC configuration file
00003 //
00004 //
00005 //
00006  
00007 #include "CalibFormats/SiPixelObjects/interface/PixelTTCciConfig.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 PixelTTCciConfig::PixelTTCciConfig(vector< vector<string> > &tableMat):PixelConfigBase(" ", " ", " ")
00017 {
00018   std::map<std::string , int > colM;
00019   std::vector<std::string > colNames;
00032   colNames.push_back("CONFIG_KEY"       );
00033   colNames.push_back("KEY_TYPE"         );
00034   colNames.push_back("KEY_ALIAS"        );
00035   colNames.push_back("VERSION"          );
00036   colNames.push_back("KIND_OF_COND"     );
00037   colNames.push_back("TTC_OBJ_DATA_FILE");
00038   colNames.push_back("TTC_OBJ_DATA_CLOB");
00039 
00040   for(unsigned int c = 0 ; c < tableMat[0].size() ; c++)
00041     {
00042       for(unsigned int n=0; n<colNames.size(); n++)
00043         {
00044           if(tableMat[0][c] == colNames[n])
00045             {
00046               colM[colNames[n]] = c;
00047               break;
00048             }
00049         }
00050     }//end for
00051   for(unsigned int n=0; n<colNames.size(); n++)
00052     {
00053       if(colM.find(colNames[n]) == colM.end())
00054         {
00055           std::cerr << "[PixelTTCciConfig::PixelTTCciConfig()]\tCouldn't find in the database the column with name " << colNames[n] << std::endl;
00056           assert(0);
00057         }
00058     }
00059   ttcConfigStream_ << tableMat[1][colM["TTC_OBJ_DATA_CLOB"]] ;
00060 //   cout << "[PixelTTCciConfig::PixelTTCciConfig()]\tRead: "<< endl<< ttcConfigStream_.str() << endl ;
00061 }
00062 
00063 PixelTTCciConfig::PixelTTCciConfig(std::string filename):
00064   PixelConfigBase(" "," "," "){
00065 
00066     std::string mthn ="]\t[PixelTKFECConfig::PixelTKFECConfig()]\t\t\t    " ;
00067     std::ifstream in(filename.c_str());
00068 
00069     if (!in.good()){
00070         std::cout << __LINE__ << mthn << "Could not open: " << filename << std::endl;
00071         throw std::runtime_error("Failed to open file "+filename);
00072     }
00073     else {
00074         std::cout << __LINE__ << mthn << "Opened : "        << filename << std::endl;
00075     }
00076 
00077     //ttcConfigPath_ = filename;
00078     string line;
00079     while (!in.eof()) {
00080        getline (in,line);
00081        ttcConfigStream_ << line << endl;
00082     }
00083 
00084 } 
00085 
00086 void PixelTTCciConfig::writeASCII(std::string dir) const {
00087 
00088   
00089   if (dir!="") dir+="/";
00090   std::string filename=dir+"TTCciConfiguration.txt";
00091   std::ofstream out(filename.c_str());
00092 
00093   //std::ifstream in(ttcConfigPath_.c_str());
00094   //assert(in.good());
00095 
00096   string configstr = ttcConfigStream_.str();
00097 
00098   out << configstr << endl;
00099 
00100   out.close();
00101 
00102 }
00103 
00104 //=============================================================================================
00105 void PixelTTCciConfig::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 = "[PixelTTCciConfig::writeXMLHeader()]\t\t\t    " ;
00113   std::stringstream maskFullPath ;
00114 
00115   writeASCII(path) ;
00116 
00117   maskFullPath << path << "/Pixel_TtcParameters_" << PixelTimeFormatter::getmSecTime() << ".xml";
00118   std::cout << 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='https://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_TTC_PARAMETERS</EXTENSION_TABLE_NAME>"                    << std::endl ; 
00128   *outstream << "   <NAME>TTC Configuration Parameters</NAME>"                                            << std::endl ; 
00129   *outstream << "  </TYPE>"                                                                               << std::endl ; 
00130   *outstream << "  <RUN>"                                                                                 << std::endl ; 
00131   *outstream << "   <RUN_TYPE>TTC 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 PixelTTCciConfig::writeXML( std::ofstream *outstream,
00153                                  std::ofstream *out1stream,
00154                                  std::ofstream *out2stream) const 
00155 {
00156   std::string mthn = "[PixelTTCciConfig::writeXML()]\t\t\t    " ;
00157 
00158   *outstream << " "                                                                                       << std::endl ;
00159   *outstream << "  <DATA>"                                                                                << std::endl ;
00160   *outstream << "   <TTC_OBJ_DATA_FILE>TTCciConfiguration.txt</TTC_OBJ_DATA_FILE>"                        << std::endl ;
00161   *outstream << "  </DATA>"                                                                               << std::endl ;
00162   *outstream << " "                                                                                       << std::endl ;
00163 }
00164 
00165 //=============================================================================================
00166 void PixelTTCciConfig::writeXMLTrailer(std::ofstream *outstream,
00167                                        std::ofstream *out1stream,
00168                                        std::ofstream *out2stream ) const 
00169 {
00170   std::string mthn = "[PixelTTCciConfig::writeXMLTrailer()]\t\t\t    " ;
00171   
00172   *outstream << " "                                                                                       << std::endl ;
00173   *outstream << " </DATA_SET>"                                                                            << std::endl ;
00174   *outstream << "</ROOT>"                                                                                 << std::endl ;
00175   
00176   outstream->close() ;
00177   std::cout << mthn << "Data written "                                                                    << std::endl ;
00178 
00179 }
00180