CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/CalibFormats/SiPixelObjects/src/PixelLowVoltageMap.cc

Go to the documentation of this file.
00001 //
00002 // Implementation of the detector configuration
00003 //
00004 //
00005 //
00006 //
00007 
00008 #include "CalibFormats/SiPixelObjects/interface/PixelLowVoltageMap.h"
00009 #include "CalibFormats/SiPixelObjects/interface/PixelTimeFormatter.h"
00010 #include <fstream>
00011 #include <iostream>
00012 #include <sstream>
00013 #include <ios>
00014 #include <assert.h>
00015 #include <stdio.h>
00016 #include <stdexcept>
00017 
00018 using namespace std;
00019 using namespace pos;
00020 
00021 
00022 PixelLowVoltageMap::PixelLowVoltageMap(std::vector< std::vector < std::string> > &tableMat):PixelConfigBase("","","")
00023 {
00024   std::string mthn = "[PixelLowVoltageMap::PixelLowVoltageMap()] " ;
00025   std::map<std::string , int > colM;
00026   std::vector<std::string > colNames;
00027 /*
00028   EXTENSION_TABLE_NAME: XDAQ_LOW_VOLTAGE_MAP  (VIEW: CONF_KEY_XDAQ_LOW_VOLTAGE_V) 
00029   
00030   CONFIG_KEY                                NOT NULL VARCHAR2(80)
00031   KEY_TYPE                                  NOT NULL VARCHAR2(80)
00032   KEY_ALIAS                                 NOT NULL VARCHAR2(80)
00033   VERSION                                            VARCHAR2(40)
00034   KIND_OF_COND                              NOT NULL VARCHAR2(40)
00035   PANEL_NAME                                NOT NULL VARCHAR2(200)
00036   DATAPOINT                                 NOT NULL VARCHAR2(200)
00037   LV_DIGITAL                                NOT NULL VARCHAR2(200)
00038   LV_ANALOG                                 NOT NULL VARCHAR2(200)
00039   
00040 */
00041 
00042   colNames.push_back("CONFIG_KEY"  );
00043   colNames.push_back("KEY_TYPE"    );
00044   colNames.push_back("KEY_ALIAS"   );
00045   colNames.push_back("VERSION"     );
00046   colNames.push_back("KIND_OF_COND");
00047   colNames.push_back("PANEL_NAME"  );
00048   colNames.push_back("DATAPOINT"   );
00049   colNames.push_back("LV_DIGITAL"  );
00050   colNames.push_back("LV_ANALOG"   );
00051 /*
00052   colNames.push_back("CONFIG_KEY_ID"    );
00053   colNames.push_back("CONFG_KEY"        );
00054   colNames.push_back("VERSION"  );
00055   colNames.push_back("KIND_OF_COND"     );
00056   colNames.push_back("RUN_TYPE" );
00057   colNames.push_back("RUN_NUMBER"       );
00058   colNames.push_back("PANEL_NAME"       );
00059   colNames.push_back("DATAPOINT"        );
00060   colNames.push_back("LV_DIGITAL"       );
00061   colNames.push_back("LV_ANALOG"        );
00062 */
00063   
00064   for(unsigned int c = 0 ; c < tableMat[0].size() ; c++)
00065     {
00066       for(unsigned int n=0; n<colNames.size(); n++)
00067         {
00068           if(tableMat[0][c] == colNames[n])
00069             {
00070               colM[colNames[n]] = c;
00071               break;
00072             }
00073         }
00074     }//end for
00075   for(unsigned int n=0; n<colNames.size(); n++)
00076     {
00077       if(colM.find(colNames[n]) == colM.end())
00078         {
00079           std::cerr << mthn << "Couldn't find in the database the column with name " << colNames[n] << std::endl;
00080           assert(0);
00081         }
00082     }
00083   
00084   std::string modulename   ;
00085   std::string dpNameBase   ;
00086   std::string ianaChannel  ;
00087   std::string idigiChannel ;
00088   for(unsigned int r = 1 ; r < tableMat.size() ; r++)    //Goes to every row of the Matrix
00089     {
00090       modulename  = tableMat[r][colM["PANEL_NAME"]] ;
00091       dpNameBase  = tableMat[r][colM["DATAPOINT"]]  ;
00092       ianaChannel = tableMat[r][colM["LV_ANALOG"]] ; 
00093       idigiChannel= tableMat[r][colM["LV_DIGITAL"]]  ; 
00094       PixelModuleName module(modulename);
00095       pair<string, string> channels(ianaChannel,idigiChannel);
00096       pair<string, pair<string,string> > dpName(dpNameBase,channels);
00097       dpNameMap_[module]=dpName;
00098     }
00099 }//end constructor
00100 
00101 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00102 
00103 PixelLowVoltageMap::PixelLowVoltageMap(std::string filename):
00104   PixelConfigBase("","",""){
00105   
00106   std::string mthn = "[PixelLowVoltageMap::PixelLowVoltageMap()]\t\t\t    " ;
00107   
00108   if (filename[filename.size()-1]=='t'){
00109     
00110     std::ifstream in(filename.c_str());
00111     
00112     if (!in.good()){
00113       std::cout << __LINE__ << "]\t" << mthn << "Could not open: " << filename << std::endl;
00114       throw std::runtime_error("Failed to open file "+filename);
00115     }
00116     else {
00117       std::cout << __LINE__ << "]\t" << mthn << "Opened: "         << filename << std::endl;
00118     }
00119     
00120     if (in.eof()){
00121       std::cout << __LINE__ << "]\t" << mthn << "eof before reading anything!" << std::endl;
00122       throw std::runtime_error("Failure when reading file; file seems to be empty: "+filename);
00123     }
00124 
00125     
00126     dpNameMap_.clear();
00127     
00128     std::string modulename;
00129     std::string dpNameBase;
00130     std::string ianaChannel;
00131     std::string idigiChannel;
00132     
00133     in >> modulename >> dpNameBase >> ianaChannel >> idigiChannel;
00134     
00135     while (!in.eof()){
00136       cout << __LINE__ << "]\t" << mthn << "Read modulename: " << modulename << endl;
00137       PixelModuleName module(modulename);
00138       pair<string, string> channels(ianaChannel,idigiChannel);
00139       pair<string, pair<string,string> > dpName(dpNameBase,channels);
00140       dpNameMap_[module]=dpName;
00141       in >> modulename >> dpNameBase >> ianaChannel >> idigiChannel;
00142     }
00143     
00144   }
00145   else{
00146     assert(0);
00147   }
00148 }
00149 
00150 std::string PixelLowVoltageMap::dpNameIana(const PixelModuleName& module) const{
00151 
00152   std::string mthn = "[PixelLowVoltageMap::dpNameIana()]\t\t\t    " ;
00153   std::map<PixelModuleName, pair< string, pair<string, string> > >::const_iterator i=
00154     dpNameMap_.find(module);
00155   
00156   if (i==dpNameMap_.end()) {
00157     cout << __LINE__ << "]\t" << mthn << "Could not find module: " << module << endl;
00158   }
00159   
00160   return i->second.first+"/"+i->second.second.first;
00161 
00162 }
00163 
00164 std::string PixelLowVoltageMap::dpNameIdigi(const PixelModuleName& module) const{
00165 
00166   std::string mthn = "[PixelLowVoltageMap::dpNameIdigi()]\t\t\t    " ;
00167   std::map<PixelModuleName, pair< string, pair<string, string> > >::const_iterator i=
00168     dpNameMap_.find(module);
00169   
00170   if (i==dpNameMap_.end()) {
00171     cout << __LINE__ << "]\t" << mthn << "Could not find module: " << module << endl;
00172   }
00173 
00174   return i->second.first+"/"+i->second.second.second;
00175 
00176 }
00177 
00178 
00179 void PixelLowVoltageMap::writeASCII(std::string dir) const {
00180 
00181   std::string mthn = "[PixelLowVoltageMap::writeASCII()]\t\t\t    " ;
00182   if (dir!="") dir+="/";
00183   std::string filename=dir+"lowvoltagemap.dat";
00184 
00185   std::ofstream out(filename.c_str(), std::ios_base::out) ;
00186   if(!out) {
00187     std::cout << __LINE__ << "]\t" << mthn << "Could not open file " << filename << " for write" << std::endl ;
00188     exit(1);
00189   }
00190   std::map<PixelModuleName, pair< string, pair<string, string> > >::const_iterator imodule=
00191     dpNameMap_.begin();
00192 
00193   for (;imodule!=dpNameMap_.end();++imodule) {
00194     out <<       imodule->first
00195         << " "<< imodule->second.first 
00196         << " "<< imodule->second.second.first
00197         << " "<< imodule->second.second.second 
00198         <<endl;
00199   }
00200 
00201   out.close();
00202 
00203 }
00204 
00205 //=============================================================================================
00206 void PixelLowVoltageMap::writeXMLHeader(pos::PixelConfigKey key, 
00207                                         int version, 
00208                                         std::string path, 
00209                                         std::ofstream *outstream,
00210                                         std::ofstream *out1stream,
00211                                         std::ofstream *out2stream) const
00212 {
00213   std::string mthn = "[PixelLowVoltageMap::writeXMLHeader()]\t\t\t    " ;
00214   std::stringstream maskFullPath ;
00215 
00216   maskFullPath << path << "/XDAQLowVoltageMap_Test_" << PixelTimeFormatter::getmSecTime() << ".xml";
00217   std::cout << __LINE__ << "]\t" << mthn << "Writing to: " << maskFullPath.str() << std::endl ;
00218 
00219   outstream->open(maskFullPath.str().c_str()) ;
00220   
00221   *outstream << "<?xml version='1.0' encoding='UTF-8' standalone='yes'?>"                                 << std::endl ;
00222   *outstream << "<ROOT xmlns:xsi='https://www.w3.org/2001/XMLSchema-instance'>"                            << std::endl ;
00223   *outstream << ""                                                                                        << std::endl ; 
00224   *outstream << " <HEADER>"                                                                               << std::endl ; 
00225   *outstream << "  <TYPE>"                                                                                << std::endl ; 
00226   *outstream << "   <EXTENSION_TABLE_NAME>XDAQ_LOW_VOLTAGE_MAP</EXTENSION_TABLE_NAME>"                    << std::endl ; 
00227   *outstream << "   <NAME>XDAQ Low Voltage Map</NAME>"                                                    << std::endl ; 
00228   *outstream << "  </TYPE>"                                                                               << std::endl ; 
00229   *outstream << "  <RUN>"                                                                                 << std::endl ; 
00230   *outstream << "   <RUN_TYPE>XDAQ Low Voltage Map</RUN_TYPE>"                                            << std::endl ; 
00231   *outstream << "   <RUN_NUMBER>1</RUN_NUMBER>"                                                           << std::endl ; 
00232   *outstream << "   <RUN_BEGIN_TIMESTAMP>" << PixelTimeFormatter::getTime() << "</RUN_BEGIN_TIMESTAMP>"   << std::endl ; 
00233   *outstream << "   <LOCATION>CERN P5</LOCATION>"                                                         << std::endl ; 
00234   *outstream << "  </RUN>"                                                                                << std::endl ; 
00235   *outstream << " </HEADER>"                                                                              << std::endl ; 
00236   *outstream << ""                                                                                        << std::endl ; 
00237   *outstream << " <DATA_SET>"                                                                             << std::endl ;
00238   *outstream << ""                                                                                        << std::endl ;
00239   *outstream << "  <VERSION>"             << version      << "</VERSION>"                                 << std::endl ;
00240   *outstream << "  <COMMENT_DESCRIPTION>" << getComment() << "</COMMENT_DESCRIPTION>"                     << std::endl ;
00241   *outstream << "  <CREATED_BY_USER>"     << getAuthor()  << "</CREATED_BY_USER>"                         << std::endl ;
00242   *outstream << ""                                                                                        << std::endl ;
00243   *outstream << "  <PART>"                                                                                << std::endl ;
00244   *outstream << "   <NAME_LABEL>CMS-PIXEL-ROOT</NAME_LABEL>"                                              << std::endl ;      
00245   *outstream << "   <KIND_OF_PART>Detector ROOT</KIND_OF_PART>"                                           << std::endl ;         
00246   *outstream << "  </PART>"                                                                               << std::endl ;
00247   *outstream << " "                                                                                       << std::endl ;
00248 
00249 }
00250 
00251 //=============================================================================================
00252 void PixelLowVoltageMap::writeXML( std::ofstream *outstream,
00253                                    std::ofstream *out1stream,
00254                                    std::ofstream *out2stream) const 
00255 {
00256   std::string mthn = "[PixelLowVoltageMap::writeXML()]\t\t\t    " ;
00257 
00258   std::map<PixelModuleName, pair< string, pair<string, string> > >::const_iterator imodule=dpNameMap_.begin();
00259 
00260   for (;imodule!=dpNameMap_.end();++imodule) {
00261     *outstream << "  <DATA>"                                                                              << std::endl ;
00262     *outstream << "   <PANEL_NAME>" << imodule->first                << "</PANEL_NAME>"                   << std::endl ;
00263     *outstream << "   <DATAPOINT>"  << imodule->second.first         << "</DATAPOINT>"                    << std::endl ;
00264     *outstream << "   <LV_DIGITAL>" << imodule->second.second.first  << "</LV_DIGITAL>"                   << std::endl ;
00265     *outstream << "   <LV_ANALOG>"  << imodule->second.second.second << "</LV_ANALOG>"                    << std::endl ;
00266     *outstream << "  </DATA>"                                                                             << std::endl ;
00267     *outstream << ""                                                                                      << std::endl ;
00268   }
00269 }
00270 
00271 //=============================================================================================
00272 void PixelLowVoltageMap::writeXMLTrailer(std::ofstream *outstream,
00273                                          std::ofstream *out1stream,
00274                                          std::ofstream *out2stream ) const 
00275 {
00276   std::string mthn = "[PixelLowVoltageMap::writeXMLTrailer()]\t\t\t    " ;
00277   
00278   *outstream << " </DATA_SET>"                                                                            << std::endl ;
00279   *outstream << "</ROOT>"                                                                                 << std::endl ;
00280   
00281   outstream->close() ;
00282   std::cout << __LINE__ << "]\t" << mthn << "Data written "                                               << std::endl ;
00283 
00284 }
00285