CMS 3D CMS Logo

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

Go to the documentation of this file.
00001 //
00002 // This class provide a base class for the
00003 // pixel mask data for the pixel FEC configuration
00004 // This is a pure interface (abstract class) that
00005 // needs to have an implementation.
00006 //
00007 // All applications should just use this 
00008 // interface and not care about the specific
00009 // implementation
00010 //
00011 //
00012 #include <sstream>
00013 #include "CalibFormats/SiPixelObjects/interface/PixelModuleName.h"
00014 #include "CalibFormats/SiPixelObjects/interface/PixelMaskAllPixels.h"
00015 #include "CalibFormats/SiPixelObjects/interface/PixelTimeFormatter.h"
00016 #include "CalibFormats/SiPixelObjects/interface/PixelBase64.h"
00017 #include <fstream>
00018 #include <map>
00019 #include <iostream>
00020 #include <assert.h>
00021 #include <stdexcept>
00022 
00023 using namespace pos;
00024 using namespace std;
00025 
00026 //================================================================================================================
00027 PixelMaskAllPixels::PixelMaskAllPixels(std::vector< std::vector<std::string> >& tableMat) : PixelMaskBase("","","")
00028 {
00029  std::string mthn = "[PixelMaskAllPixels::PixelMaskAllPixels()]\t\t    " ;
00030  //std::cout << __LINE__ << "]\t" << mthn << "Table Size in const: " << tableMat.size() << std::endl;
00031 
00032  std::vector< std::string > ins = tableMat[0];
00033  std::map<std::string , int > colM;
00034  std::vector<std::string > colNames;
00035 
00036 /*
00037  EXTENSION_TABLE_NAME: ROC_MASKS (VIEW: CONF_KEY_ROC_MASKS_V)
00038 
00039  CONFIG_KEY                                NOT NULL VARCHAR2(80)
00040  KEY_TYPE                                  NOT NULL VARCHAR2(80)
00041  KEY_ALIAS                                 NOT NULL VARCHAR2(80)
00042  VERSION                                            VARCHAR2(40)
00043  KIND_OF_COND                              NOT NULL VARCHAR2(40)
00044  ROC_NAME                                  NOT NULL VARCHAR2(200)
00045  KILL_MASK                                 NOT NULL VARCHAR2(4000) colNames.push_back("CONFIG_KEY_ID" );
00046 */
00047  colNames.push_back("CONFIG_KEY"  );
00048  colNames.push_back("KEY_TYPE"    );
00049  colNames.push_back("KEY_ALIAS"   );
00050  colNames.push_back("VERSION"     );
00051  colNames.push_back("KIND_OF_COND");
00052  colNames.push_back("ROC_NAME"    );
00053  colNames.push_back("KILL_MASK"   );
00054   
00055  for(unsigned int c = 0 ; c < ins.size() ; c++)
00056    {
00057      for(unsigned int n=0; n<colNames.size(); n++)
00058        {
00059          if(tableMat[0][c] == colNames[n])
00060            {
00061              colM[colNames[n]] = c;
00062              break;
00063            }
00064        }
00065    }//end for
00066  for(unsigned int n=0; n<colNames.size(); n++)
00067    {
00068      if(colM.find(colNames[n]) == colM.end())
00069        {
00070          std::cerr << mthn << "Couldn't find in the database the column with name " << colNames[n] << std::endl;
00071          assert(0);
00072        }
00073    }
00074   maskbits_.clear() ;
00075   for(unsigned int r = 1 ; r < tableMat.size() ; r++){   //Goes to every row of the Matrix
00076     std::string currentRocName = tableMat[r][colM["ROC_NAME"]]  ;               
00077     PixelROCName rocid(currentRocName);
00078     PixelROCMaskBits tmp;
00079     tmp.read(rocid,base64_decode(tableMat[r][colM["KILL_MASK"]])) ; // decode back from specially base64-encoded data for XML 
00080     maskbits_.push_back(tmp);
00081   }                                                      //end for r 
00082 }
00083 
00084 //================================================================================================================
00085 // modified by MR on 18-04-2008 10:02:00
00086 PixelMaskAllPixels::PixelMaskAllPixels():PixelMaskBase("","",""){;}
00087 
00088 //================================================================================================================
00089 void PixelMaskAllPixels::addROCMaskBits(PixelROCMaskBits bits)
00090 {
00091   maskbits_.push_back(bits);
00092 }
00093 
00094 //================================================================================================================
00095 PixelMaskAllPixels::PixelMaskAllPixels(std::string filename):
00096   PixelMaskBase("","",""){
00097 
00098     std::string mthn = "[PixelMaskAllPixels::PixelMaskAllPixels()]\t\t    " ;
00099 
00100     if (filename[filename.size()-1]=='t'){
00101 
00102 
00103         std::ifstream in(filename.c_str());
00104 
00105         if (!in.good()){
00106             std::cout << __LINE__ << "]\t" << mthn << "Could not open: " << filename << std::endl;
00107             throw std::runtime_error("Failed to open file "+filename);
00108         }
00109         
00110         std::string tag;
00111         in >> tag;
00112 
00113         maskbits_.clear();
00114 
00115         while (!in.eof()) {
00116 
00117             PixelROCName rocid(in);
00118 
00119             PixelROCMaskBits tmp;
00120             
00121             tmp.read(rocid,in);
00122             
00123             maskbits_.push_back(tmp);
00124             
00125             in >> tag;
00126             
00127         }
00128         
00129         in.close();
00130 
00131     }
00132     else{
00133 
00134         std::ifstream in(filename.c_str(),std::ios::binary);
00135 
00136         char nchar;
00137 
00138         in.read(&nchar,1);
00139 
00140         //in >> nchar;
00141 
00142         std::string s1;
00143 
00144         //wrote these lines of code without ref. needs to be fixed
00145         for(int i=0;i< nchar; i++){
00146             char c;
00147             in >>c;
00148             s1.push_back(c);
00149         }
00150 
00151         //std::cout << __LINE__ << "]\t" << mthn << "READ ROC name: "  << s1    << std::endl;
00152         
00153         maskbits_.clear();
00154 
00155 
00156         while (!in.eof()){
00157 
00158             //std::cout << __LINE__ << "]\t" << mthn << "read s1: "    << s1    << std::endl;
00159 
00160             PixelROCName rocid(s1);
00161 
00162             //std::cout << __LINE__ << "]\t" << mthn << "read rocid: " << rocid << std::endl;
00163             
00164             PixelROCMaskBits tmp;
00165       
00166             tmp.readBinary(rocid, in);
00167 
00168             maskbits_.push_back(tmp);
00169 
00170 
00171             in.read(&nchar,1);
00172 
00173             s1.clear();
00174 
00175             if (in.eof()) continue;
00176             
00177             //std::cout << __LINE__ << "]\t" << mthn << "Will read: " << (int)nchar << " characters." <<std::endl;
00178 
00179             //wrote these lines of code without ref. needs to be fixed
00180             for(int i=0;i< nchar; i++){
00181                 char c;
00182                 in >>c;
00183                 //std::cout << " " <<c;
00184                 s1.push_back(c);
00185             }
00186             //std::cout << std::endl;
00187 
00188 
00189         }
00190 
00191         in.close();
00192 
00193 
00194 
00195     }
00196 
00197 
00198     //std::cout << __LINE__ << "]\t" << mthn << "Read maskbits for " << maskbits_.size() << " ROCs" << std::endl;
00199         
00200     }
00201     
00202 //================================================================================================================
00203 const PixelROCMaskBits& PixelMaskAllPixels::getMaskBits(int ROCId) const {
00204 
00205   return maskbits_[ROCId];
00206 
00207 }
00208 
00209 //================================================================================================================
00210 PixelROCMaskBits* PixelMaskAllPixels::getMaskBits(PixelROCName name) {
00211 
00212   for(unsigned int i=0;i<maskbits_.size();i++){
00213     if (maskbits_[i].name()==name) return &(maskbits_[i]);
00214   }
00215 
00216   return 0;
00217 
00218 }
00219 
00220 //================================================================================================================
00221 void PixelMaskAllPixels::writeBinary(std::string filename) const{
00222 
00223   
00224     std::ofstream out(filename.c_str(),std::ios::binary);
00225 
00226     for(unsigned int i=0;i<maskbits_.size();i++){
00227         maskbits_[i].writeBinary(out);
00228     }
00229 
00230 
00231 }
00232 
00233 //================================================================================================================
00234 void PixelMaskAllPixels::writeASCII(std::string dir) const{
00235 
00236   if (dir!="") dir+="/";
00237   PixelModuleName module(maskbits_[0].name().rocname());
00238   std::string filename=dir+"ROC_Masks_module_"+module.modulename()+".dat";
00239   
00240     std::ofstream out(filename.c_str());
00241 
00242     for(unsigned int i=0;i<maskbits_.size();i++){
00243         maskbits_[i].writeASCII(out);
00244     }
00245 
00246 
00247 }
00248 
00249 //=============================================================================================
00250 void PixelMaskAllPixels::writeXMLHeader(pos::PixelConfigKey key, 
00251                                         int version, 
00252                                         std::string path, 
00253                                         std::ofstream *outstream,
00254                                         std::ofstream *out1stream,
00255                                         std::ofstream *out2stream) const
00256 {
00257   std::string mthn = "[PixelMaskAllPixels::writeXMLHeader()]\t\t\t    " ;
00258   std::stringstream maskFullPath ;
00259 
00260   maskFullPath << path << "/Pixel_RocMasks_" << PixelTimeFormatter::getmSecTime() << ".xml";
00261   std::cout << __LINE__ << "]\t" << mthn << "Writing to: " << maskFullPath.str() << std::endl ;
00262 
00263   outstream->open(maskFullPath.str().c_str()) ;
00264   
00265   *outstream << "<?xml version='1.0' encoding='UTF-8' standalone='yes'?>"                               << std::endl ;
00266   *outstream << "<ROOT xmlns:xsi='https://www.w3.org/2001/XMLSchema-instance'>"                          << std::endl ;
00267   *outstream << ""                                                                                      << std::endl ; 
00268   *outstream << " <HEADER>"                                                                             << std::endl ; 
00269   *outstream << "  <TYPE>"                                                                              << std::endl ; 
00270   *outstream << "   <EXTENSION_TABLE_NAME>ROC_MASKS</EXTENSION_TABLE_NAME>"                             << std::endl ; 
00271   *outstream << "   <NAME>ROC Mask Bits</NAME>"                                                         << std::endl ; 
00272   *outstream << "  </TYPE>"                                                                             << std::endl ; 
00273   *outstream << "  <RUN>"                                                                               << std::endl ; 
00274   *outstream << "   <RUN_TYPE>ROC Mask Bits</RUN_TYPE>"                                                 << std::endl ; 
00275   *outstream << "   <RUN_NUMBER>1</RUN_NUMBER>"                                                         << std::endl ; 
00276   *outstream << "   <RUN_BEGIN_TIMESTAMP>" << PixelTimeFormatter::getTime() << "</RUN_BEGIN_TIMESTAMP>" << std::endl ; 
00277   *outstream << "   <LOCATION>CERN P5</LOCATION>"                                                       << std::endl ; 
00278   *outstream << "  </RUN>"                                                                              << std::endl ; 
00279   *outstream << " </HEADER>"                                                                            << std::endl ; 
00280   *outstream << ""                                                                                      << std::endl ; 
00281   *outstream << " <DATA_SET>"                                                                           << std::endl ;
00282   *outstream << ""                                                                                      << std::endl ;
00283   *outstream << "  <VERSION>"             << version      << "</VERSION>"                               << std::endl ;
00284   *outstream << "  <COMMENT_DESCRIPTION>" << getComment() << "</COMMENT_DESCRIPTION>"                   << std::endl ;
00285   *outstream << "  <CREATED_BY_USER>"     << getAuthor()  << "</CREATED_BY_USER>"                       << std::endl ;
00286   *outstream << ""                                                                                      << std::endl ;
00287   *outstream << "  <PART>"                                                                              << std::endl ;
00288   *outstream << "   <NAME_LABEL>CMS-PIXEL-ROOT</NAME_LABEL>"                                            << std::endl ;      
00289   *outstream << "   <KIND_OF_PART>Detector ROOT</KIND_OF_PART>"                                         << std::endl ;         
00290   *outstream << "  </PART>"                                                                             << std::endl ;
00291   *outstream << "  "                                                                                    << std::endl ;
00292 
00293 }
00294 //=============================================================================================
00295 void PixelMaskAllPixels::writeXML( std::ofstream *outstream,
00296                                    std::ofstream *out1stream,
00297                                    std::ofstream *out2stream) const 
00298 {
00299   std::string mthn = "[PixelMaskAllPixels::writeXML()]\t\t\t    " ;
00300 
00301   for(unsigned int i=0;i<maskbits_.size();i++){
00302       maskbits_[i].writeXML(outstream);
00303   }
00304 }
00305 //=============================================================================================
00306 void PixelMaskAllPixels::writeXMLTrailer(std::ofstream *outstream,
00307                                          std::ofstream *out1stream,
00308                                          std::ofstream *out2stream ) const 
00309 {
00310   std::string mthn = "[PixelMaskAllPixels::writeXMLTrailer()]\t\t\t    " ;
00311   
00312   *outstream << "  "                                                                                    << std::endl ;
00313   *outstream << " </DATA_SET>"                                                                          << std::endl ;
00314   *outstream << "</ROOT>"                                                                               << std::endl ;
00315   
00316   outstream->close() ;
00317   std::cout << __LINE__ << "]\t" << mthn << "Data written "                                             << std::endl ;
00318 
00319 }
00320