CMS 3D CMS Logo

CMSSW_4_4_3_patch1/src/L1TriggerConfig/CSCTFConfigProducers/src/CSCTFConfigOnlineProd.cc

Go to the documentation of this file.
00001 #include "L1TriggerConfig/CSCTFConfigProducers/interface/CSCTFConfigOnlineProd.h"
00002 //#include <FWCore/MessageLogger/interface/MessageLogger.h>
00003 #include <cstdio>
00004 
00005 boost::shared_ptr< L1MuCSCTFConfiguration >
00006 CSCTFConfigOnlineProd::newObject( const std::string& objectKey )
00007 {
00008   
00009   edm::LogInfo( "L1-O2O: CSCTFConfigOnlineProd" ) << "Producing "
00010                                                   << "L1MuCSCTFConfiguration "
00011                                                   << "with key CSCTF_KEY="
00012                                                   << objectKey;
00013 
00014   std::string csctfreg[12];
00015 
00016   // loop over the 12 SPs forming the CSCTF crate
00017   for (int iSP=1;iSP<13; iSP++) {
00018 
00019     char spName[2];
00020     if (iSP<10) sprintf(spName,"0%d",iSP);
00021     else        sprintf(spName, "%d",iSP);
00022 
00023     std::string spkey = objectKey + "00" + spName;
00024 
00025   
00026   
00027     //  SELECT Multiple columns  FROM TABLE with correct key: 
00028     std::vector< std::string > columns ;
00029     columns.push_back( "STATIC_CONFIG" ) ;
00030     columns.push_back( "ETA_CONFIG" ) ;
00031     columns.push_back( "FIRMWARE" ) ;
00032      
00033     //SELECT * FROM CMS_CSC_TF.CSCTF_SP_CONF WHERE CSCTF_SP_CONF.SP_KEY = spkey
00034     l1t::OMDSReader::QueryResults results = m_omdsReader.basicQuery(
00035                                                                     columns,
00036                                                                     "CMS_CSC_TF",
00037                                                                     "CSCTF_SP_CONF",
00038                                                                     "CSCTF_SP_CONF.SP_KEY",
00039                                                                     m_omdsReader.singleAttribute( spkey )
00040                                                                     ) ;
00041   
00042     if( results.queryFailed() ) // check if query was successful
00043       {
00044         edm::LogError( "L1-O2O" ) << "Problem with L1CSCTFParameters key." ;
00045         // return empty configuration
00046         return boost::shared_ptr< L1MuCSCTFConfiguration >( new L1MuCSCTFConfiguration() ) ;
00047       }
00048   
00049 
00050     std::string conf_stat, conf_eta, conf_firmware;
00051     results.fillVariable( "STATIC_CONFIG", conf_stat );
00052     results.fillVariable( "ETA_CONFIG",    conf_eta  );
00053     results.fillVariable( "FIRMWARE",      conf_firmware );
00054     
00055     LogDebug( "L1-O2O: CSCTFConfigOnlineProd:" ) << "conf_stat queried: " << conf_stat
00056                                                  << "conf_eta queried:"   << conf_eta
00057                                                  << "conf_firmware queried:" << conf_firmware;
00058     
00059     for(size_t pos=conf_stat.find("\\n"); pos!=std::string::npos; pos=conf_stat.find("\\n",pos)) 
00060       { 
00061         conf_stat[pos]=' '; 
00062         conf_stat[pos+1]='\n'; 
00063       }
00064     
00065     for(size_t pos=conf_eta.find("\\n"); pos!=std::string::npos; pos=conf_eta.find("\\n",pos)) 
00066       { 
00067         conf_eta[pos]=' '; 
00068         conf_eta[pos+1]='\n'; 
00069       }
00070 
00071   
00072     for(size_t pos=conf_firmware.find("\\n"); pos!=std::string::npos; pos=conf_firmware.find("\\n",pos)) 
00073       { 
00074         conf_firmware[pos]=' '; 
00075         conf_firmware[pos+1]='\n';
00076       }
00077 
00078     LogDebug( "L1-O2O: CSCTFConfigOnlineProd" ) << "\nSP KEY: "                  << spkey
00079                                                 << "\n\nSTATIC CONFIGURATION:\n" << conf_stat
00080                                                 << "\nDAT_ETA CONFIGURATION:\n"  << conf_eta
00081                                                 << "\nFIRMWARE VERSIONS:\n"      << conf_firmware;
00082 
00083     // The CSCTF firmware needs a bit more manipulation
00084     // The firmware is written in the DBS as SP SP day/month/year, where the real year is 2000+year
00085     // For easy handling when retrieving the configuration I prefer to write is as
00086     // FIRMWARE SP SP yearmonthday
00087     // e.g. SP SP 26/06/09 -> FIRMWARE SP SP 20090626
00088 
00089     std::string conf_firmware_sp;
00090 
00091     std::stringstream conf(conf_firmware);
00092     while( !conf.eof() ){
00093       char buff[1024];
00094       conf.getline(buff,1024);
00095       std::stringstream line(buff);
00096       
00097       std::string register_ = "FIRMWARE";
00098       std::string chip_;    line>>chip_;
00099       std::string muon_;    line>>muon_;
00100       std::string writeValue_;   line>>writeValue_;
00101 
00102       size_t pos;
00103       pos=writeValue_.find('/');
00104       
00105       std::string day;
00106       day.push_back(writeValue_[pos-2]);
00107       day.push_back(writeValue_[pos-1]);
00108 
00109       std::string month;
00110       month.push_back(writeValue_[pos+1]);
00111       month.push_back(writeValue_[pos+2]);
00112 
00113       std::string year("20");
00114       year.push_back(writeValue_[pos+4]);
00115       year.push_back(writeValue_[pos+5]);
00116 
00117       //std::cout << "day "   << day   <<std::endl;
00118       //std::cout << "month " << month <<std::endl;
00119       //std::cout << "year "  << year  <<std::endl;
00120 
00121       std::string date=year+month+day;
00122       // std::cout << register_  << " -- "
00123       //           << chip_      << " -- "
00124       //           << muon_      << " -- " 
00125       //           << date       << " -- " 
00126       //           << std::endl;
00127 
00128       // for the CSCTF emulator there is no need of the other firmware (CCB and MS)
00129       if(chip_ == "SP")
00130         conf_firmware_sp+=register_+" "+chip_+" "+muon_+" "+date+"\n";      
00131     }
00132     
00133     edm::LogInfo( "L1-O2O: CSCTFConfigOnlineProd" ) << "\nSP KEY: "                  << spkey
00134                                                     << "\n\nSTATIC CONFIGURATION:\n" << conf_stat
00135                                                     << "\nDAT_ETA CONFIGURATION:\n"  << conf_eta
00136                                                     << "\nFIRMWARE VERSIONS:\n"      << conf_firmware_sp;
00137 
00138     std::string conf_read=conf_eta+conf_stat+conf_firmware_sp;
00139     // write all registers for a given SP
00140     csctfreg[iSP-1]=conf_read; 
00141   }  
00142   
00143   // return the final object with the configuration for all CSCTF
00144   return boost::shared_ptr< L1MuCSCTFConfiguration >( new L1MuCSCTFConfiguration(csctfreg) ) ;    
00145 
00146 }
00147 
00148