CMS 3D CMS Logo

PixelTrimAllPixels.cc

Go to the documentation of this file.
00001 //
00002 // This class provide a base class for the
00003 // pixel trim data for the pixel FEC configuration
00004 // This is a pure interface (abstract class) that
00005 // needs to have an implementation.
00006 //
00007 // Need to figure out what is 'VMEcommand' below! 
00008 //
00009 // All applications should just use this 
00010 // interface and not care about the specific
00011 // implementation.
00012 //
00013 
00014 #include <sstream>
00015 #include <iostream>
00016 #include <ios>
00017 #include <assert.h>
00018 #include "CalibFormats/SiPixelObjects/interface/PixelTrimAllPixels.h"
00019 
00020 using namespace pos;
00021 
00022 PixelTrimAllPixels::PixelTrimAllPixels( std::vector <std::vector<std::string> >& tableMat):
00023   PixelTrimBase("","","")
00024 {
00025 
00026     std::stringstream currentRocName;
00027     std::map<std::string , int > colM;
00028     std::vector<std::string > colNames;
00047     colNames.push_back("CONFIG_KEY_ID"  );
00048     colNames.push_back("CONFG_KEY"      );
00049     colNames.push_back("VERSION"        );
00050     colNames.push_back("KIND_OF_COND"   );
00051     colNames.push_back("ROC_NAME"       );
00052     colNames.push_back("HUB_ADDRS"      );
00053     colNames.push_back("PORT_NUMBER"    );
00054     colNames.push_back("ROC_I2C_ADDR"   );
00055     colNames.push_back("GEOM_ROC_NUM"   );
00056     colNames.push_back("DATA_FILE"      );
00057     colNames.push_back("TRIM_CLOB"      );
00058  
00059 
00060     for(unsigned int c = 0 ; c < tableMat[0].size() ; c++)
00061       {
00062         for(unsigned int n=0; n<colNames.size(); n++)
00063           {
00064             if(tableMat[0][c] == colNames[n])
00065               {
00066                 colM[colNames[n]] = c;
00067                 break;
00068               }
00069           }
00070       }//end for
00071     for(unsigned int n=0; n<colNames.size(); n++)
00072       {
00073       if(colM.find(colNames[n]) == colM.end())
00074         {
00075           std::cerr << "[PixelTrimAllPixels::PixelTrimAllPixels()]\tCouldn't find in the database the column with name " << colNames[n] << std::endl;
00076           assert(0);
00077         }
00078       }
00079     
00080     //unsigned char *bits ;        /// supose to be " unsigned  char bits[tableMat[1][colM["TRIM_BLOB"]].size()] ;  "
00081     //char c[2080];
00082     std::string bits;
00083         
00084     for(unsigned int r = 1 ; r < tableMat.size() ; r++)    //Goes to every row of the Matrix
00085       {
00086         PixelROCName rocid( tableMat[r][colM["ROC_NAME"]] );
00087         // tableMat[r][colM["TRIM_BLOB"]].copy(c , 2080 );
00088         // unsigned char *bits = (unsigned char* )(tableMat[r][colM["TRIM_BLOB"]].c_str());
00089         //bits = (unsigned char)(tableMat[r][colM["TRIM_BLOB"]].c_str());
00090         PixelROCTrimBits tmp;     // Have to add like this  PixelROCTrimBits tmp(rocid , bits ); 
00091         std::istringstream istring ;
00092         istring.str(tableMat[r][colM["TRIM_CLOB"]]) ;
00093         tmp.read(rocid, istring) ;
00094 //      bits = tableMat[r][colM["TRIM_CLOB"]];
00095         //std::cout<<rocid<<std::endl;
00096         // std::cout<<bits.size()<<std::endl;
00097 //      tmp.setROCTrimBits(rocid, bits);
00098         trimbits_.push_back(tmp);
00099         //std::cout<<"Pase por aqui:"<<r<<std::endl;
00100         // dacValue = atoi(tableMat[r][colM["VALUE"]].c_str());
00101         // pDSM.insert(pair<string,pair<string,int> >(currentRocName.str(),pair<string,int>(dacName,dacValue)));
00102       }//end for r 
00103     //std::cout<<trimbits_.size()<<std::endl;
00104 } //end contructor with databasa table
00105 
00106  
00107 PixelTrimAllPixels::PixelTrimAllPixels(std::string filename):
00108   PixelTrimBase("","",""){
00109 
00110     if (filename[filename.size()-1]=='t'){
00111 
00112       std::ifstream in(filename.c_str());
00113         
00114       //        std::cout << "filename =" << filename << std::endl;
00115 
00116       std::string s1;
00117       in >> s1; 
00118 
00119       trimbits_.clear();
00120 
00121 
00122       while (in.good()){
00123           
00124         std::string s2;
00125         in>>s2;
00126 
00127         //          std::cout << "PixelTrimAllPixels::PixelTrimAllPixels read s1:"<<s1<< " s2:" << s2 << std::endl;
00128 
00129         assert( s1 == "ROC:" );
00130 
00131         PixelROCName rocid(s2);
00132 
00133         //std::cout << "PixelTrimAllPixels::PixelTrimAllPixels read rocid:"<<rocid<<std::endl;
00134             
00135         PixelROCTrimBits tmp;
00136       
00137         tmp.read(rocid, in);
00138 
00139         trimbits_.push_back(tmp);
00140 
00141         in >> s1;
00142 
00143       }
00144 
00145       in.close();
00146 
00147     }
00148     else{
00149 
00150       std::ifstream in(filename.c_str(),std::ios::binary);
00151 
00152       char nchar;
00153 
00154       in.read(&nchar,1);
00155 
00156       std::string s1;
00157 
00158       //wrote these lines of code without ref. needs to be fixed
00159       for(int i=0;i< nchar; i++){
00160         char c;
00161         in >>c;
00162         s1.push_back(c);
00163       }
00164 
00165       //std::cout << "READ ROC name:"<<s1<<std::endl;
00166 
00167       trimbits_.clear();
00168 
00169 
00170       while (!in.eof()){
00171 
00172         //std::cout << "PixelTrimAllPixels::PixelTrimAllPixels read s1:"<<s1<<std::endl;
00173 
00174         PixelROCName rocid(s1);
00175 
00176         //std::cout << "PixelTrimAllPixels::PixelTrimAllPixels read rocid:"<<rocid<<std::endl;
00177             
00178         PixelROCTrimBits tmp;
00179       
00180         tmp.readBinary(rocid, in);
00181 
00182         trimbits_.push_back(tmp);
00183 
00184 
00185         in.read(&nchar,1);
00186 
00187         s1.clear();
00188 
00189         if (in.eof()) continue;
00190 
00191         //wrote these lines of code without ref. needs to be fixed
00192         for(int i=0;i< nchar; i++){
00193           char c;
00194           in >>c;
00195           s1.push_back(c);
00196         }
00197 
00198 
00199       }
00200 
00201       in.close();
00202 
00203 
00204 
00205     }
00206 
00207     //std::cout << "Read trimbits for "<<trimbits_.size()<<" ROCs"<<std::endl;
00208 
00209   }
00210 
00211 
00212 //std::string PixelTrimAllPixels::getConfigCommand(PixelMaskBase& pixelMask){
00213 //
00214 //  std::string s;
00215 //  return s;
00216 //
00217 //}
00218 
00219 PixelROCTrimBits PixelTrimAllPixels::getTrimBits(int ROCId) const {
00220 
00221   return trimbits_[ROCId];
00222 
00223 }
00224 
00225 PixelROCTrimBits* PixelTrimAllPixels::getTrimBits(PixelROCName name){
00226 
00227   for(unsigned int i=0;i<trimbits_.size();i++){
00228     if (trimbits_[i].name()==name) return &(trimbits_[i]);
00229   }
00230 
00231   return 0;
00232 
00233 }
00234 
00235 
00236 
00237 void PixelTrimAllPixels::generateConfiguration(PixelFECConfigInterface* pixelFEC,
00238                                                PixelNameTranslation* trans,
00239                                                const PixelMaskBase& pixelMask) const{
00240 
00241   for(unsigned int i=0;i<trimbits_.size();i++){
00242 
00243     std::vector<unsigned char> trimAndMasks(4160);
00244 
00245     const PixelROCMaskBits& maskbits=pixelMask.getMaskBits(i);
00246 
00247     for (unsigned int col=0;col<52;col++){
00248       for (unsigned int row=0;row<80;row++){
00249         unsigned char tmp=trimbits_[i].trim(col,row);
00250         if (maskbits.mask(col,row)!=0) tmp|=0x80;
00251         trimAndMasks[col*80+row]=tmp;
00252       }
00253     }
00254 
00255     // the slow way, one pixel at a time
00256     //pixelFEC->setMaskAndTrimAll(*(trans->getHdwAddress(trimbits_[i].name())),trimAndMasks);
00257     // the fast way, a full roc in column mode (& block xfer)
00258     const PixelHdwAddress* theROC = trans->getHdwAddress(trimbits_[i].name());
00259     pixelFEC->roctrimload(theROC->mfec(),
00260                           theROC->mfecchannel(),
00261                           theROC->hubaddress(),
00262                           theROC->portaddress(),
00263                           theROC->rocid(),
00264                           trimAndMasks);
00265   }
00266 }
00267 
00268 void PixelTrimAllPixels::writeBinary(std::string filename) const{
00269 
00270   
00271   std::ofstream out(filename.c_str(),std::ios::binary);
00272 
00273   for(unsigned int i=0;i<trimbits_.size();i++){
00274     trimbits_[i].writeBinary(out);
00275   }
00276 
00277 
00278 }
00279 
00280 
00281 void PixelTrimAllPixels::writeASCII(std::string dir) const{
00282 
00283   if (dir!="") dir+="/";
00284   PixelModuleName module(trimbits_[0].name().rocname());
00285   std::string filename=dir+"ROC_Trims_module_"+module.modulename()+".dat";
00286   
00287 
00288   std::ofstream out(filename.c_str());
00289 
00290   for(unsigned int i=0;i<trimbits_.size();i++){
00291     trimbits_[i].writeASCII(out);
00292   }
00293 
00294 
00295 }

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