CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch12/src/CalibFormats/SiPixelObjects/src/PixelDelay25Calib.cc

Go to the documentation of this file.
00001 //
00002 // This class manages data and files used
00003 // in the Delay25 calibration
00004 //
00005 //
00006 //
00007 //
00008 
00009 #include "CalibFormats/SiPixelObjects/interface/PixelDelay25Calib.h"
00010 #include "CalibFormats/SiPixelObjects/interface/PixelTimeFormatter.h"
00011 #include <iostream>
00012 #include <assert.h>
00013 #include <map>
00014 #include <sstream>
00015 
00016 using namespace pos;
00017 
00018 using namespace std;
00019 
00020 PixelDelay25Calib::PixelDelay25Calib(vector< vector<string> > &tableMat) : 
00021   PixelCalibBase(),
00022   PixelConfigBase("","","")
00023 {
00024   std::string mthn = "[PixelDelay25Calib::PixelDelay25Calib()]\t\t\t    " ;
00025   std::cout << __LINE__ << "]\t" << mthn << std::endl;
00026   std::map<std::string , int > colM;
00027   std::vector<std::string > colNames;
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("CALIB_TYPE"         );
00048   colNames.push_back("CALIB_OBJ_DATA_FILE");
00049   colNames.push_back("CALIB_OBJ_DATA_CLOB");
00050   
00051   for(unsigned int c = 0 ; c < tableMat[0].size() ; c++)
00052     {
00053       for(unsigned int n=0; n<colNames.size(); n++)
00054         {
00055           if(tableMat[0][c] == colNames[n])
00056             {
00057               colM[colNames[n]] = c;
00058               break;
00059             }
00060         }
00061     }//end for
00062   for(unsigned int n=0; n<colNames.size(); n++)
00063     {
00064       if(colM.find(colNames[n]) == colM.end())
00065         {
00066           std::cerr << "[[PixelDelay25Calib::PixelDelay25Calib()]\tCouldn't find in the database the column with name " << colNames[n] << std::endl;
00067           assert(0);
00068         }
00069     }
00070 
00071   
00072   std::istringstream in ;
00073   in.str(tableMat[1][colM["CALIB_OBJ_DATA_CLOB"]]) ;
00074   
00075   //Read initial SDa and RDa values, ranges,
00076   //and grid step size from file
00077   
00078   std::string tmp;
00079 
00080   in >> tmp;
00081 
00082   assert(tmp=="Mode:");
00083   in >> mode_;
00084 
00085   in >> tmp;
00086 
00087   assert(tmp=="Portcards:");
00088   in >> tmp;
00089   if(tmp=="All")
00090     {
00091       allPortcards_ = true;
00092     } else {
00093     allPortcards_ = false;
00094   }
00095   while (tmp!="AllModules:")
00096     {
00097       portcardNames_.insert(tmp);
00098       in >> tmp;
00099     }
00100 
00101   assert(tmp=="AllModules:");
00102   in >> allModules_;
00103 
00104   in >> tmp;
00105 
00106   assert(tmp=="OrigSDa:");
00107   in >> origSDa_;
00108 
00109   in >> tmp;
00110 
00111   assert(tmp=="OrigRDa:");
00112   in >> origRDa_;
00113 
00114   in >> tmp;
00115 
00116   assert(tmp=="Range:");
00117   in >> range_;
00118 
00119   in >> tmp;
00120 
00121   assert(tmp=="GridSize:");
00122   in >> gridSize_;
00123 
00124   in >> tmp;
00125   assert(tmp=="Tests:");
00126   in >> numTests_;
00127 
00128   in >> tmp;
00129   if(tmp=="Commands:") {
00130     in >> commands_;
00131   } else {
00132     commands_=0;
00133   }
00134 
00135   //Number of steps in the grid
00136   gridSteps_ = range_/gridSize_;
00137 }
00138 
00139 
00140 PixelDelay25Calib::PixelDelay25Calib(std::string filename) : 
00141   PixelCalibBase(),
00142   PixelConfigBase("","",""){
00143 
00144   std::string mthn = "[PixelDelay25Calib::PixelDelay25Calib()]\t\t\t    ";
00145   
00146   std::ifstream in(filename.c_str());
00147   
00148   if(!in.good()){
00149     std::cout << __LINE__ << "]\t" << mthn << "Could not open: " << filename << std::endl;
00150     assert(0);
00151   }
00152   else {
00153     std::cout << __LINE__ << "]\t" << mthn << "Opened: " << filename << std::endl;
00154   }
00155 
00156   //Read initial SDa and RDa values, ranges,
00157   //and grid step size from file
00158   
00159   std::string tmp;
00160 
00161   in >> tmp;
00162 
00163   assert(tmp=="Mode:");
00164   in >> mode_;
00165 
00166   //cout << __LINE__ << "]\t" << mthn  << "mode_="<<mode_<<endl;
00167 
00168   in >> tmp;
00169 
00170   assert(tmp=="Portcards:");
00171   in >> tmp;
00172   if(tmp=="All")
00173     {
00174       allPortcards_ = true;
00175     } else {
00176       allPortcards_ = false;
00177     }
00178   while (tmp!="AllModules:")
00179     {
00180       portcardNames_.insert(tmp);
00181       in >> tmp;
00182     }
00183 
00184   assert(tmp=="AllModules:");
00185   in >> allModules_;
00186 
00187   in >> tmp;
00188 
00189   assert(tmp=="OrigSDa:");
00190   in >> origSDa_;
00191 
00192   in >> tmp;
00193 
00194   assert(tmp=="OrigRDa:");
00195   in >> origRDa_;
00196 
00197   in >> tmp;
00198 
00199   assert(tmp=="Range:");
00200   in >> range_;
00201 
00202   in >> tmp;
00203 
00204   assert(tmp=="GridSize:");
00205   in >> gridSize_;
00206 
00207   in >> tmp;
00208   assert(tmp=="Tests:");
00209   in >> numTests_;
00210 
00211   in >> tmp;
00212   if(tmp=="Commands:") {
00213     in >> commands_;
00214   } else {
00215     commands_=0;
00216   }
00217 
00218   in.close();
00219 
00220   //Number of steps in the grid
00221   gridSteps_ = range_/gridSize_;
00222 
00223 }
00224 
00225 PixelDelay25Calib::~PixelDelay25Calib() {
00226 }
00227 
00228 void PixelDelay25Calib::openFiles(std::string portcardName, std::string moduleName, std::string path) {
00229   if (path!="") path+="/";
00230   graph_ = path+"graph_"+portcardName+"_"+moduleName+".dat";
00231   graphout_.open(graph_.c_str());
00232   return;
00233 }
00234 
00235 void PixelDelay25Calib::writeSettings(std::string portcardName, std::string moduleName) {
00236   graphout_ << "Portcard: " << portcardName << endl;
00237   graphout_ << "Module: " << moduleName << endl;
00238   graphout_ << "SDaOrigin: " << origSDa_ << endl;
00239   graphout_ << "RDaOrigin: " << origRDa_ << endl;
00240   graphout_ << "SDaRange: " << range_ << endl;
00241   graphout_ << "RDaRange: " << range_ << endl;
00242   graphout_ << "GridSize: " << gridSize_ << endl;
00243   graphout_ << "Tests: " << numTests_ << endl;
00244   return;
00245 }
00246 
00247 void PixelDelay25Calib::writeFiles( std::string tmp ) {
00248   graphout_ << tmp << endl;
00249   return;
00250 }
00251 
00252 void PixelDelay25Calib::writeFiles( int currentSDa, int currentRDa, int number ) {
00253   graphout_ << currentSDa << " " << currentRDa << " " << number << endl;
00254   return;
00255 }
00256 
00257 void PixelDelay25Calib::closeFiles() {
00258   graphout_.close();
00259   return;
00260 }
00261 
00262 void PixelDelay25Calib::writeASCII(std::string dir) const {
00263 
00264 
00265   //FIXME this is not tested for all the use cases...
00266 
00267   if (dir!="") dir+="/";
00268   std::string filename=dir+"delay25.dat";
00269   std::ofstream out(filename.c_str());
00270 
00271   out << "Mode: "<<mode_<<endl;
00272   
00273   out << "Portcards:" <<endl;
00274 
00275   std::set<std::string>::const_iterator i=portcardNames_.begin();
00276   while (i!=portcardNames_.end()) {
00277     out << *i << endl;
00278     ++i;
00279   }
00280 
00281   out << "AllModules:" <<endl;
00282   if (allModules_) {
00283     out << "1" <<endl;
00284   } else {
00285     out << "0" <<endl;
00286   }
00287 
00288   out << "OrigSDa:"<<endl;
00289   out << origSDa_<<endl;
00290   
00291   out << "OrigRDa:"<<endl;
00292   out << origRDa_<<endl;
00293   
00294   out << "Range:"<<endl;
00295   out << range_<<endl;
00296   
00297   out << "GridSize:"<<endl;
00298   out << gridSize_<<endl;
00299   
00300   out << "Tests:"<<endl;
00301   out << numTests_<<endl;
00302 
00303   out << "Commands:"<<endl;
00304   out << commands_<<endl;
00305   
00306   out.close();
00307 }
00308 
00309 //=============================================================================================
00310 void PixelDelay25Calib::writeXMLHeader(pos::PixelConfigKey key, 
00311                                        int version, 
00312                                        std::string path, 
00313                                        std::ofstream *outstream,
00314                                        std::ofstream *out1stream,
00315                                        std::ofstream *out2stream) const
00316 {
00317   std::string mthn = "[PixelDelay25Calib::writeXMLHeader()]\t\t\t    " ;
00318   std::stringstream maskFullPath ;
00319 
00320   writeASCII(path) ;
00321 
00322   maskFullPath << path << "/PixelCalib_Test_" << PixelTimeFormatter::getmSecTime() << ".xml";
00323   std::cout  << __LINE__ << "]\t" << mthn << "Writing to: " << maskFullPath.str() << std::endl ;
00324 
00325   outstream->open(maskFullPath.str().c_str()) ;
00326   
00327   *outstream << "<?xml version='1.0' encoding='UTF-8' standalone='yes'?>"                                 << std::endl ;
00328   *outstream << "<ROOT xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>"                            << std::endl ;
00329   *outstream << ""                                                                                        << std::endl ; 
00330   *outstream << " <!-- " << mthn << "-->"                                                                 << std::endl ; 
00331   *outstream << ""                                                                                        << std::endl ; 
00332   *outstream << " <HEADER>"                                                                               << std::endl ; 
00333   *outstream << "  <TYPE>"                                                                                << std::endl ; 
00334   *outstream << "   <EXTENSION_TABLE_NAME>PIXEL_CALIB_CLOB</EXTENSION_TABLE_NAME>"                        << std::endl ; 
00335   *outstream << "   <NAME>Calibration Object Clob</NAME>"                                                 << std::endl ; 
00336   *outstream << "  </TYPE>"                                                                               << std::endl ; 
00337   *outstream << "  <RUN>"                                                                                 << std::endl ; 
00338   *outstream << "   <RUN_TYPE>delay25</RUN_TYPE>"                                                         << std::endl ; 
00339   *outstream << "   <RUN_NUMBER>1</RUN_NUMBER>"                                                           << std::endl ; 
00340   *outstream << "   <RUN_BEGIN_TIMESTAMP>" << PixelTimeFormatter::getTime() << "</RUN_BEGIN_TIMESTAMP>"   << std::endl ; 
00341   *outstream << "   <LOCATION>CERN P5</LOCATION>"                                                         << std::endl ; 
00342   *outstream << "  </RUN>"                                                                                << std::endl ; 
00343   *outstream << " </HEADER>"                                                                              << std::endl ; 
00344   *outstream << ""                                                                                        << std::endl ; 
00345   *outstream << " <DATA_SET>"                                                                             << std::endl ;
00346   *outstream << ""                                                                                        << std::endl ;
00347   *outstream << "  <VERSION>"             << version      << "</VERSION>"                                 << std::endl ;
00348   *outstream << "  <COMMENT_DESCRIPTION>" << getComment() << "</COMMENT_DESCRIPTION>"                     << std::endl ;
00349   *outstream << "  <CREATED_BY_USER>"     << getAuthor()  << "</CREATED_BY_USER>"                         << std::endl ;
00350   *outstream << ""                                                                                        << std::endl ;
00351   *outstream << "  <PART>"                                                                                << std::endl ;
00352   *outstream << "   <NAME_LABEL>CMS-PIXEL-ROOT</NAME_LABEL>"                                              << std::endl ;      
00353   *outstream << "   <KIND_OF_PART>Detector ROOT</KIND_OF_PART>"                                           << std::endl ;         
00354   *outstream << "  </PART>"                                                                               << std::endl ;
00355 
00356 }
00357 
00358 //=============================================================================================
00359 void PixelDelay25Calib::writeXML( std::ofstream *outstream,
00360                                   std::ofstream *out1stream,
00361                                   std::ofstream *out2stream) const 
00362 {
00363   std::string mthn = "[PixelDelay25Calib::writeXML()]\t\t\t    " ;
00364   
00365 
00366   *outstream << " "                                                                                       << std::endl ;
00367   *outstream << "  <DATA>"                                                                                << std::endl ;
00368   *outstream << "   <CALIB_OBJ_DATA_FILE>./delay25.dat</CALIB_OBJ_DATA_FILE>"                             << std::endl ;
00369   *outstream << "   <CALIB_TYPE>delay25</CALIB_TYPE>"                                                     << std::endl ;
00370   *outstream << "  </DATA>"                                                                               << std::endl ;
00371   *outstream << " "                                                                                       << std::endl ;
00372 }
00373 
00374 //=============================================================================================
00375 void PixelDelay25Calib::writeXMLTrailer(std::ofstream *outstream,
00376                                         std::ofstream *out1stream,
00377                                         std::ofstream *out2stream ) const 
00378 {
00379   std::string mthn = "[PixelDelay25Calib::writeXMLTrailer()]\t\t\t    " ;
00380   
00381   *outstream << " </DATA_SET>"                                                                            << std::endl ;
00382   *outstream << "</ROOT>"                                                                                 << std::endl ;
00383   
00384   outstream->close() ;
00385   std::cout  << __LINE__ << "]\t" << mthn << "Data written "                                              << std::endl ;
00386 
00387 }
00388 
00389