Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:47:24

0001 //
0002 // This class manages data and files used
0003 // in the Delay25 calibration
0004 //
0005 //
0006 //
0007 //
0008 
0009 #include "CalibFormats/SiPixelObjects/interface/PixelDelay25Calib.h"
0010 #include "CalibFormats/SiPixelObjects/interface/PixelTimeFormatter.h"
0011 #include <iostream>
0012 #include <cassert>
0013 #include <map>
0014 #include <sstream>
0015 
0016 using namespace pos;
0017 
0018 using namespace std;
0019 
0020 PixelDelay25Calib::PixelDelay25Calib(vector<vector<string> > &tableMat)
0021     : PixelCalibBase(), PixelConfigBase("", "", "") {
0022   std::string mthn = "[PixelDelay25Calib::PixelDelay25Calib()]\t\t\t    ";
0023   std::map<std::string, int> colM;
0024   std::vector<std::string> colNames;
0025   /**
0026 
0027   EXTENSION_TABLE_NAME: PIXEL_CALIB_CLOB (VIEW: CONF_KEY_PIXEL_CALIB_V)
0028   
0029   CONFIG_KEY                    NOT NULL VARCHAR2(80)
0030   KEY_TYPE                  NOT NULL VARCHAR2(80)
0031   KEY_ALIAS                 NOT NULL VARCHAR2(80)
0032   VERSION                        VARCHAR2(40)
0033   KIND_OF_COND                  NOT NULL VARCHAR2(40)
0034   CALIB_TYPE                         VARCHAR2(200)
0035   CALIB_OBJ_DATA_FILE               NOT NULL VARCHAR2(200)
0036   CALIB_OBJ_DATA_CLOB               NOT NULL CLOB
0037   */
0038 
0039   colNames.push_back("CONFIG_KEY");
0040   colNames.push_back("KEY_TYPE");
0041   colNames.push_back("KEY_ALIAS");
0042   colNames.push_back("VERSION");
0043   colNames.push_back("KIND_OF_COND");
0044   colNames.push_back("CALIB_TYPE");
0045   colNames.push_back("CALIB_OBJ_DATA_FILE");
0046   colNames.push_back("CALIB_OBJ_DATA_CLOB");
0047 
0048   for (unsigned int c = 0; c < tableMat[0].size(); c++) {
0049     for (unsigned int n = 0; n < colNames.size(); n++) {
0050       if (tableMat[0][c] == colNames[n]) {
0051         colM[colNames[n]] = c;
0052         break;
0053       }
0054     }
0055   }  //end for
0056   for (unsigned int n = 0; n < colNames.size(); n++) {
0057     if (colM.find(colNames[n]) == colM.end()) {
0058       std::cerr << "[[PixelDelay25Calib::PixelDelay25Calib()]\tCouldn't find in the database the column with name "
0059                 << colNames[n] << std::endl;
0060       assert(0);
0061     }
0062   }
0063 
0064   std::istringstream in;
0065   in.str(tableMat[1][colM["CALIB_OBJ_DATA_CLOB"]]);
0066 
0067   //Read initial SDa and RDa values, ranges,
0068   //and grid step size from file
0069 
0070   std::string tmp;
0071 
0072   in >> tmp;
0073 
0074   assert(tmp == "Mode:");
0075   in >> mode_;
0076 
0077   in >> tmp;
0078 
0079   assert(tmp == "Portcards:");
0080   in >> tmp;
0081   if (tmp == "All") {
0082     allPortcards_ = true;
0083   } else {
0084     allPortcards_ = false;
0085   }
0086   while (tmp != "AllModules:") {
0087     portcardNames_.insert(tmp);
0088     in >> tmp;
0089   }
0090 
0091   assert(tmp == "AllModules:");
0092   in >> allModules_;
0093 
0094   in >> tmp;
0095 
0096   assert(tmp == "OrigSDa:");
0097   in >> origSDa_;
0098 
0099   in >> tmp;
0100 
0101   assert(tmp == "OrigRDa:");
0102   in >> origRDa_;
0103 
0104   in >> tmp;
0105 
0106   assert(tmp == "Range:");
0107   in >> range_;
0108 
0109   in >> tmp;
0110 
0111   assert(tmp == "GridSize:");
0112   in >> gridSize_;
0113 
0114   in >> tmp;
0115   assert(tmp == "Tests:");
0116   in >> numTests_;
0117 
0118   in >> tmp;
0119   if (tmp == "Commands:") {
0120     in >> commands_;
0121   } else {
0122     commands_ = 0;
0123   }
0124 
0125   //Number of steps in the grid
0126   gridSteps_ = range_ / gridSize_;
0127 
0128   // Added by Dario as a temporary patch for Debbie (this will disappear in the future)
0129   calibFileContent_ = in.str();
0130   //cout << __LINE__ << "] " << __PRETTY_FUNCTION__ << "\tcalibFileContent_\n " << calibFileContent_ << endl ;
0131   // End of temporary patch
0132 }
0133 
0134 PixelDelay25Calib::PixelDelay25Calib(std::string filename) : PixelCalibBase(), PixelConfigBase("", "", "") {
0135   std::string mthn = "[PixelDelay25Calib::PixelDelay25Calib()]\t\t\t    ";
0136 
0137   std::ifstream in(filename.c_str());
0138 
0139   if (!in.good()) {
0140     std::cout << __LINE__ << "]\t" << mthn << "Could not open: " << filename << std::endl;
0141     assert(0);
0142   } else {
0143     std::cout << __LINE__ << "]\t" << mthn << "Opened: " << filename << std::endl;
0144   }
0145 
0146   //Read initial SDa and RDa values, ranges,
0147   //and grid step size from file
0148 
0149   std::string tmp;
0150 
0151   in >> tmp;
0152 
0153   assert(tmp == "Mode:");
0154   in >> mode_;
0155 
0156   //cout << __LINE__ << "]\t" << mthn  << "mode_="<<mode_<<endl;
0157 
0158   in >> tmp;
0159 
0160   assert(tmp == "Portcards:");
0161   in >> tmp;
0162   if (tmp == "All") {
0163     allPortcards_ = true;
0164   } else {
0165     allPortcards_ = false;
0166   }
0167   while (tmp != "AllModules:") {
0168     portcardNames_.insert(tmp);
0169     in >> tmp;
0170   }
0171 
0172   assert(tmp == "AllModules:");
0173   in >> allModules_;
0174 
0175   in >> tmp;
0176 
0177   assert(tmp == "OrigSDa:");
0178   in >> origSDa_;
0179 
0180   in >> tmp;
0181 
0182   assert(tmp == "OrigRDa:");
0183   in >> origRDa_;
0184 
0185   in >> tmp;
0186 
0187   assert(tmp == "Range:");
0188   in >> range_;
0189 
0190   in >> tmp;
0191 
0192   assert(tmp == "GridSize:");
0193   in >> gridSize_;
0194 
0195   in >> tmp;
0196   assert(tmp == "Tests:");
0197   in >> numTests_;
0198 
0199   in >> tmp;
0200   if (tmp == "Commands:") {
0201     in >> commands_;
0202   } else {
0203     commands_ = 0;
0204   }
0205 
0206   in.close();
0207 
0208   //Number of steps in the grid
0209   gridSteps_ = range_ / gridSize_;
0210 
0211   // Added by Dario as a temporary patch for Debbie (this will disappear in the future)
0212   std::ifstream inTmp(filename.c_str());
0213   calibFileContent_ = "";
0214   while (!inTmp.eof()) {
0215     std::string tmpString;
0216     getline(inTmp, tmpString);
0217     calibFileContent_ += tmpString + "\n";
0218     //cout << __LINE__ << "]\t" << "[PixelCalibConfiguration::~PixelCalibConfiguration()]\t\t" << calibFileContent_ << endl ;
0219   }
0220   inTmp.close();
0221   // End of temporary patch
0222 }
0223 
0224 PixelDelay25Calib::~PixelDelay25Calib() {}
0225 
0226 void PixelDelay25Calib::openFiles(std::string portcardName, std::string moduleName, std::string path) {
0227   if (!path.empty())
0228     path += "/";
0229   graph_ = path + "graph_" + portcardName + "_" + moduleName + ".dat";
0230   graphout_.open(graph_.c_str());
0231   return;
0232 }
0233 
0234 void PixelDelay25Calib::writeSettings(std::string portcardName, std::string moduleName) {
0235   graphout_ << "Portcard: " << portcardName << endl;
0236   graphout_ << "Module: " << moduleName << endl;
0237   graphout_ << "SDaOrigin: " << origSDa_ << endl;
0238   graphout_ << "RDaOrigin: " << origRDa_ << endl;
0239   graphout_ << "SDaRange: " << range_ << endl;
0240   graphout_ << "RDaRange: " << range_ << endl;
0241   graphout_ << "GridSize: " << gridSize_ << endl;
0242   graphout_ << "Tests: " << numTests_ << endl;
0243   return;
0244 }
0245 
0246 void PixelDelay25Calib::writeFiles(std::string tmp) {
0247   graphout_ << tmp << endl;
0248   return;
0249 }
0250 
0251 void PixelDelay25Calib::writeFiles(int currentSDa, int currentRDa, int number) {
0252   graphout_ << currentSDa << " " << currentRDa << " " << number << endl;
0253   return;
0254 }
0255 
0256 void PixelDelay25Calib::closeFiles() {
0257   graphout_.close();
0258   return;
0259 }
0260 
0261 void PixelDelay25Calib::writeASCII(std::string dir) const {
0262   //FIXME this is not tested for all the use cases...
0263 
0264   if (!dir.empty())
0265     dir += "/";
0266   std::string filename = dir + "delay25.dat";
0267   std::ofstream out(filename.c_str());
0268 
0269   out << "Mode: " << mode_ << endl;
0270 
0271   out << "Portcards:" << endl;
0272 
0273   std::set<std::string>::const_iterator i = portcardNames_.begin();
0274   while (i != portcardNames_.end()) {
0275     out << *i << endl;
0276     ++i;
0277   }
0278 
0279   out << "AllModules:" << endl;
0280   if (allModules_) {
0281     out << "1" << endl;
0282   } else {
0283     out << "0" << endl;
0284   }
0285 
0286   out << "OrigSDa:" << endl;
0287   out << origSDa_ << endl;
0288 
0289   out << "OrigRDa:" << endl;
0290   out << origRDa_ << endl;
0291 
0292   out << "Range:" << endl;
0293   out << range_ << endl;
0294 
0295   out << "GridSize:" << endl;
0296   out << gridSize_ << endl;
0297 
0298   out << "Tests:" << endl;
0299   out << numTests_ << endl;
0300 
0301   out << "Commands:" << endl;
0302   out << commands_ << endl;
0303 
0304   out.close();
0305 }
0306 
0307 //=============================================================================================
0308 void PixelDelay25Calib::writeXMLHeader(pos::PixelConfigKey key,
0309                                        int version,
0310                                        std::string path,
0311                                        std::ofstream *outstream,
0312                                        std::ofstream *out1stream,
0313                                        std::ofstream *out2stream) const {
0314   std::string mthn = "[PixelDelay25Calib::writeXMLHeader()]\t\t\t    ";
0315   std::stringstream maskFullPath;
0316 
0317   writeASCII(path);
0318 
0319   maskFullPath << path << "/PixelCalib_Test_" << PixelTimeFormatter::getmSecTime() << ".xml";
0320   std::cout << __LINE__ << "]\t" << mthn << "Writing to: " << maskFullPath.str() << std::endl;
0321 
0322   outstream->open(maskFullPath.str().c_str());
0323 
0324   *outstream << "<?xml version='1.0' encoding='UTF-8' standalone='yes'?>" << std::endl;
0325   *outstream << "<ROOT xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>" << std::endl;
0326   *outstream << "" << std::endl;
0327   *outstream << " <!-- " << mthn << "-->" << std::endl;
0328   *outstream << "" << std::endl;
0329   *outstream << " <HEADER>" << std::endl;
0330   *outstream << "  <TYPE>" << std::endl;
0331   *outstream << "   <EXTENSION_TABLE_NAME>PIXEL_CALIB_CLOB</EXTENSION_TABLE_NAME>" << std::endl;
0332   *outstream << "   <NAME>Calibration Object Clob</NAME>" << std::endl;
0333   *outstream << "  </TYPE>" << std::endl;
0334   *outstream << "  <RUN>" << std::endl;
0335   *outstream << "   <RUN_TYPE>delay25</RUN_TYPE>" << std::endl;
0336   *outstream << "   <RUN_NUMBER>1</RUN_NUMBER>" << std::endl;
0337   *outstream << "   <RUN_BEGIN_TIMESTAMP>" << PixelTimeFormatter::getTime() << "</RUN_BEGIN_TIMESTAMP>" << std::endl;
0338   *outstream << "   <LOCATION>CERN P5</LOCATION>" << std::endl;
0339   *outstream << "  </RUN>" << std::endl;
0340   *outstream << " </HEADER>" << std::endl;
0341   *outstream << "" << std::endl;
0342   *outstream << " <DATA_SET>" << std::endl;
0343   *outstream << "" << std::endl;
0344   *outstream << "  <VERSION>" << version << "</VERSION>" << std::endl;
0345   *outstream << "  <COMMENT_DESCRIPTION>" << getComment() << "</COMMENT_DESCRIPTION>" << std::endl;
0346   *outstream << "  <CREATED_BY_USER>" << getAuthor() << "</CREATED_BY_USER>" << std::endl;
0347   *outstream << "" << std::endl;
0348   *outstream << "  <PART>" << std::endl;
0349   *outstream << "   <NAME_LABEL>CMS-PIXEL-ROOT</NAME_LABEL>" << std::endl;
0350   *outstream << "   <KIND_OF_PART>Detector ROOT</KIND_OF_PART>" << std::endl;
0351   *outstream << "  </PART>" << std::endl;
0352 }
0353 
0354 //=============================================================================================
0355 void PixelDelay25Calib::writeXML(std::ofstream *outstream, std::ofstream *out1stream, std::ofstream *out2stream) const {
0356   std::string mthn = "[PixelDelay25Calib::writeXML()]\t\t\t    ";
0357 
0358   std::cout << __LINE__ << "]\t" << mthn << "Writing.." << std::endl;
0359 
0360   *outstream << " " << std::endl;
0361   *outstream << "  <DATA>" << std::endl;
0362   *outstream << "   <CALIB_OBJ_DATA_FILE>./delay25.dat</CALIB_OBJ_DATA_FILE>" << std::endl;
0363   *outstream << "   <CALIB_TYPE>delay25</CALIB_TYPE>" << std::endl;
0364   *outstream << "  </DATA>" << std::endl;
0365   *outstream << " " << std::endl;
0366 }
0367 
0368 //=============================================================================================
0369 void PixelDelay25Calib::writeXMLTrailer(std::ofstream *outstream,
0370                                         std::ofstream *out1stream,
0371                                         std::ofstream *out2stream) const {
0372   std::string mthn = "[PixelDelay25Calib::writeXMLTrailer()]\t\t\t    ";
0373 
0374   *outstream << " </DATA_SET>" << std::endl;
0375   *outstream << "</ROOT>" << std::endl;
0376 
0377   outstream->close();
0378   std::cout << __LINE__ << "]\t" << mthn << "Data written " << std::endl;
0379 }