CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_7_hltpatch2/src/CalibFormats/SiPixelObjects/src/PixelTrimCommon.cc

Go to the documentation of this file.
00001 //
00002 // This class provide an implementation for
00003 // pixel trim data where all pixels have the
00004 // same settings.
00005 //
00006 //
00007 // All applications should just use this 
00008 // interface and not care about the specific
00009 // implementation
00010 //
00011 
00012 #include <iostream>
00013 #include <ios>
00014 #include "CalibFormats/SiPixelObjects/interface/PixelTrimCommon.h"
00015 #include "CalibFormats/SiPixelObjects/interface/PixelROCName.h"
00016 
00017 using namespace pos;
00018 
00019 PixelTrimCommon::PixelTrimCommon(std::string filename):
00020   PixelTrimBase("","",""){
00021 
00022     if (filename[filename.size()-1]=='t'){
00023 
00024         std::ifstream in(filename.c_str());
00025         
00026         std::string s1;
00027         in >> s1;
00028 
00029         trimbits_.clear();
00030 
00031 
00032         while (!in.eof()){
00033 
00034             //std::cout << "PixelTrimCommon::PixelTrimCommon read s1:"<<s1<<std::endl;
00035 
00036             PixelROCName rocid(in);
00037 
00038             //std::cout << "PixelTrimCommon::PixelTrimCommon read rocid:"<<rocid<<std::endl;
00039             
00040             unsigned int trimbits;
00041       
00042             in >> trimbits;
00043 
00044             trimbits_.push_back(trimbits);
00045 
00046             in >> s1;
00047 
00048         }
00049 
00050         in.close();
00051 
00052     }
00053     else{
00054 
00055         std::ifstream in(filename.c_str(),std::ios::binary);
00056 
00057         char nchar;
00058 
00059         in.read(&nchar,1);
00060 
00061         std::string s1;
00062 
00063         //wrote these lines of code without ref. needs to be fixed
00064         for(int i=0;i< nchar; i++){
00065             char c;
00066             in >>c;
00067             s1.push_back(c);
00068         }
00069 
00070         //std::cout << "READ ROC name:"<<s1<<std::endl;
00071 
00072         trimbits_.clear();
00073 
00074 
00075         while (!in.eof()){
00076 
00077             //std::cout << "PixelTrimCommon::PixelTrimCommon read s1:"<<s1<<std::endl;
00078 
00079             PixelROCName rocid(s1);
00080 
00081             //std::cout << "PixelTrimCommon::PixelTrimCommon read rocid:"<<rocid<<std::endl;
00082             
00083             unsigned int trimbits;
00084       
00085             in >> trimbits;
00086 
00087             trimbits_.push_back(trimbits);
00088 
00089 
00090             in.read(&nchar,1);
00091 
00092             s1.clear();
00093 
00094             if (in.eof()) continue;
00095 
00096             //wrote these lines of code without ref. needs to be fixed
00097             for(int i=0;i< nchar; i++){
00098                 char c;
00099                 in >>c;
00100                 s1.push_back(c);
00101             }
00102 
00103 
00104         }
00105 
00106         in.close();
00107 
00108 
00109 
00110     }
00111 
00112     //std::cout << "Read trimbits for "<<trimbits_.size()<<" ROCs"<<std::endl;
00113 
00114 }
00115 
00116 
00117 //std::string PixelTrimCommon::getConfigCommand(PixelMaskBase& pixelMask){
00118 //
00119 //  std::string s;
00120 //  return s;
00121 //
00122 //}
00123 
00124 //PixelROCTrimBits PixelTrimCommon::getTrimBits(int ROCId) const {
00125 //
00126 //  return trimbits_[ROCId];
00127 //
00128 //}
00129 
00130 
00131 void PixelTrimCommon::generateConfiguration(PixelFECConfigInterface* pixelFEC,
00132                                                PixelNameTranslation* trans,
00133                                                const PixelMaskBase& pixelMask) const{
00134 
00135     for(unsigned int i=0;i<trimbits_.size();i++){
00136 
00137         std::vector<unsigned char> trimAndMasks(4160);
00138 
00139         const PixelROCMaskBits& maskbits=pixelMask.getMaskBits(i);
00140 
00141         for (unsigned int col=0;col<52;col++){
00142             for (unsigned int row=0;row<80;row++){
00143                 unsigned char tmp=trimbits_[i];
00144                 if (maskbits.mask(col,row)!=0) tmp|=0x80;
00145                 trimAndMasks[col*80+row]=tmp;
00146             }
00147         }
00148 
00149         pixelFEC->setMaskAndTrimAll(*(trans->getHdwAddress(rocname_[i])),trimAndMasks);
00150 
00151     }
00152 }
00153 
00154 void PixelTrimCommon::writeBinary(std::string filename) const{
00155 
00156   
00157     std::ofstream out(filename.c_str(),std::ios::binary);
00158 
00159     for(unsigned int i=0;i<trimbits_.size();i++){
00160         assert(0);
00161         //trimbits_[i].writeBinary(out);
00162     }
00163 
00164 
00165 }
00166 
00167 
00168 void PixelTrimCommon::writeASCII(std::string filename) const{
00169 
00170     std::ofstream out(filename.c_str());
00171 
00172     for(unsigned int i=0;i<trimbits_.size();i++){
00173         assert(0);
00174         //trimbits_[i].writeASCII(out);
00175     }
00176 
00177 
00178 }