CMS 3D CMS Logo

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 <fstream>
00016 #include <map>
00017 #include <iostream>
00018 #include <assert.h>
00019 
00020 using namespace pos;
00021 using namespace std;
00022 
00023 PixelMaskAllPixels::PixelMaskAllPixels(std::vector< std::vector<std::string> >& tableMat) : PixelMaskBase("","","")
00024 {
00025 
00026   std::cout<<"Table Size in const:"<<tableMat.size()<<std::endl;
00027 
00028  std::vector< std::string > ins = tableMat[0];
00029  std::map<std::string , int > colM;
00030  std::vector<std::string > colNames;
00031 
00032  colNames.push_back("CONFIG_KEY_ID" );
00033  colNames.push_back("CONFG_KEY"     );
00034  colNames.push_back("VERSION"       );
00035  colNames.push_back("KIND_OF_COND"  );
00036  colNames.push_back("ROC_NAME"      );
00037  colNames.push_back("HUB_ADDRS"     );
00038  colNames.push_back("PORT_NUMBER"   );
00039  colNames.push_back("ROC_I2C_ADDR"  );
00040  colNames.push_back("GEOM_ROC_NUM"  );
00041  colNames.push_back("DATA_FILE"     );
00042  colNames.push_back("MASK_CLOB"     );
00043 
00044 
00045   
00046  for(unsigned int c = 0 ; c < ins.size() ; c++)
00047    {
00048      for(unsigned int n=0; n<colNames.size(); n++)
00049        {
00050          if(tableMat[0][c] == colNames[n])
00051            {
00052              colM[colNames[n]] = c;
00053              break;
00054            }
00055        }
00056    }//end for
00057  for(unsigned int n=0; n<colNames.size(); n++)
00058    {
00059      if(colM.find(colNames[n]) == colM.end())
00060        {
00061          std::cerr << "[PixelMaskAllPixels::PixelMaskAllPixels()]\tCouldn't find in the database the column with name " << colNames[n] << std::endl;
00062          assert(0);
00063        }
00064    }
00065  
00066   for(unsigned int r = 1 ; r < tableMat.size() ; r++){   //Goes to every row of the Matrix
00067     std::string currentRocName = tableMat[r][colM["ROC_NAME"]]  ;               
00068     PixelROCName rocid(currentRocName);
00069     PixelROCMaskBits tmp;
00070     std::istringstream istring ;
00071     istring.str(tableMat[r][colM["MASK_CLOB"]]) ;
00072     tmp.read(rocid,istring);
00073     maskbits_.push_back(tmp);
00074   }//end for r 
00075 //std::cout<<maskbits_.size()<<std::endl;
00076 }
00077 
00078 // modified by MR on 18-04-2008 10:02:00
00079 PixelMaskAllPixels::PixelMaskAllPixels():PixelMaskBase("","",""){;}
00080 
00081 void PixelMaskAllPixels::addROCMaskBits(PixelROCMaskBits bits)
00082 {
00083   maskbits_.push_back(bits);
00084 }
00085 
00086 //**********************************************************************
00087 
00088 
00089 
00090 PixelMaskAllPixels::PixelMaskAllPixels(std::string filename):
00091   PixelMaskBase("","",""){
00092 
00093     if (filename[filename.size()-1]=='t'){
00094 
00095 
00096         std::ifstream in(filename.c_str());
00097 
00098         if (!in.good()){
00099             std::cout << "Could not open:"<<filename<<std::endl;
00100             assert(0);
00101         }
00102         
00103         std::string tag;
00104         in >> tag;
00105 
00106         maskbits_.clear();
00107 
00108         while (!in.eof()) {
00109 
00110             PixelROCName rocid(in);
00111 
00112             PixelROCMaskBits tmp;
00113             
00114             tmp.read(rocid,in);
00115             
00116             maskbits_.push_back(tmp);
00117             
00118             in >> tag;
00119             
00120         }
00121         
00122         in.close();
00123 
00124     }
00125     else{
00126 
00127         std::ifstream in(filename.c_str(),std::ios::binary);
00128 
00129         char nchar;
00130 
00131         in.read(&nchar,1);
00132 
00133         //in >> nchar;
00134 
00135         std::string s1;
00136 
00137         //wrote these lines of code without ref. needs to be fixed
00138         for(int i=0;i< nchar; i++){
00139             char c;
00140             in >>c;
00141             s1.push_back(c);
00142         }
00143 
00144         //std::cout << "READ ROC name:"<<s1<<std::endl;
00145         
00146         maskbits_.clear();
00147 
00148 
00149         while (!in.eof()){
00150 
00151             //std::cout << "PixelMaskAllPixels::PixelMaskAllPixels read s1:"<<s1<<std::endl;
00152 
00153             PixelROCName rocid(s1);
00154 
00155             //std::cout << "PixelMaskAllPixels::PixelMaskAllPixels read rocid:"<<rocid<<std::endl;
00156             
00157             PixelROCMaskBits tmp;
00158       
00159             tmp.readBinary(rocid, in);
00160 
00161             maskbits_.push_back(tmp);
00162 
00163 
00164             in.read(&nchar,1);
00165 
00166             s1.clear();
00167 
00168             if (in.eof()) continue;
00169             
00170             //std::cout << "Will read:"<<(int)nchar<<" characters."<<std::endl;
00171 
00172             //wrote these lines of code without ref. needs to be fixed
00173             for(int i=0;i< nchar; i++){
00174                 char c;
00175                 in >>c;
00176                 //std::cout <<" "<<c;
00177                 s1.push_back(c);
00178             }
00179             //std::cout << std::endl;
00180 
00181 
00182         }
00183 
00184         in.close();
00185 
00186 
00187 
00188     }
00189 
00190 
00191     //std::cout << "Read maskbits for "<<maskbits_.size()<<" ROCs"<<std::endl;
00192         
00193     }
00194     
00195 const PixelROCMaskBits& PixelMaskAllPixels::getMaskBits(int ROCId) const {
00196 
00197   return maskbits_[ROCId];
00198 
00199 }
00200 
00201 PixelROCMaskBits* PixelMaskAllPixels::getMaskBits(PixelROCName name) {
00202 
00203   for(unsigned int i=0;i<maskbits_.size();i++){
00204     if (maskbits_[i].name()==name) return &(maskbits_[i]);
00205   }
00206 
00207   return 0;
00208 
00209 }
00210 
00211 void PixelMaskAllPixels::writeBinary(std::string filename) const{
00212 
00213   
00214     std::ofstream out(filename.c_str(),std::ios::binary);
00215 
00216     for(unsigned int i=0;i<maskbits_.size();i++){
00217         maskbits_[i].writeBinary(out);
00218     }
00219 
00220 
00221 }
00222 
00223 
00224 void PixelMaskAllPixels::writeASCII(std::string dir) const{
00225 
00226   if (dir!="") dir+="/";
00227   PixelModuleName module(maskbits_[0].name().rocname());
00228   std::string filename=dir+"ROC_Masks_module_"+module.modulename()+".dat";
00229   
00230     std::ofstream out(filename.c_str());
00231 
00232     for(unsigned int i=0;i<maskbits_.size();i++){
00233         maskbits_[i].writeASCII(out);
00234     }
00235 
00236 
00237 }
00238 

Generated on Tue Jun 9 17:25:25 2009 for CMSSW by  doxygen 1.5.4