CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_0/src/CondTools/Ecal/src/EcalADCToGeVHandler.cc

Go to the documentation of this file.
00001 #include "CondTools/Ecal/interface/EcalADCToGeVHandler.h"
00002 #include "FWCore/ParameterSet/interface/ParameterSetfwd.h"
00003 #include "CondFormats/EcalObjects/interface/EcalIntercalibConstants.h"
00004 #include "CondTools/Ecal/interface/EcalADCToGeVXMLTranslator.h"
00005 
00006 
00007 #include<iostream>
00008 
00009 popcon::EcalADCToGeVHandler::EcalADCToGeVHandler(const edm::ParameterSet & ps)
00010   :    m_name(ps.getUntrackedParameter<std::string>("name","EcalADCToGeVHandler")) {
00011 
00012         std::cout << "EcalADCToGeV Source handler constructor\n" << std::endl;
00013         m_firstRun=static_cast<unsigned int>(atoi( ps.getParameter<std::string>("firstRun").c_str()));
00014         m_lastRun=static_cast<unsigned int>(atoi( ps.getParameter<std::string>("lastRun").c_str()));
00015         m_sid= ps.getParameter<std::string>("OnlineDBSID");
00016         m_user= ps.getParameter<std::string>("OnlineDBUser");
00017         m_pass= ps.getParameter<std::string>("OnlineDBPassword");
00018         m_locationsource= ps.getParameter<std::string>("LocationSource");
00019         m_location=ps.getParameter<std::string>("Location");
00020         m_gentag=ps.getParameter<std::string>("GenTag");
00021         m_file_lowfield= ps.getParameter<std::string>("FileLowField");
00022         m_file_highfield= ps.getParameter<std::string>("FileHighField");
00023 
00024 
00025 
00026         std::cout << m_sid<<"/"<<m_user<<"/"<<m_location<<"/"<<m_gentag   << std::endl;
00027 
00028 
00029 }
00030 
00031 popcon::EcalADCToGeVHandler::~EcalADCToGeVHandler()
00032 {
00033 }
00034 
00035 
00036 void popcon::EcalADCToGeVHandler::getNewObjects()
00037 {
00038 
00039         std::cout << "------- Ecal - > getNewObjects\n";
00040 
00041   std::ostringstream ss; 
00042   ss<<"ECAL ";
00043 
00044         unsigned int max_since=0;
00045         max_since=static_cast<unsigned int>(tagInfo().lastInterval.first);
00046         std::cout << "max_since : "  << max_since << std::endl;
00047         Ref ped_db = lastPayload();
00048         
00049         // we parse the last record in the DB and check if it is low or high field 
00050 
00051         std::cout << "retrieved last payload "  << std::endl;
00052 
00053 
00054         EcalADCToGeVConstant the_cal ;
00055 
00056         float adc_eb=ped_db->getEBValue();
00057         float adc_ee=ped_db->getEEValue();
00058  
00059         float the_value_high_eb=0.03894;
00060         float the_value_high_ee=0.06285;
00061 
00062         
00063         bool magnet_high=true; 
00064         if(adc_eb!= the_value_high_eb || adc_ee!= the_value_high_ee ) magnet_high=false; 
00065 
00066 
00067         // here we connect to the online DB to check the value of the magnetic field 
00068 
00069         std::cout << "Connecting to ONLINE DB ... " << std::endl;
00070         econn = new EcalCondDBInterface( m_sid, m_user, m_pass );
00071         std::cout << "Connection done" << std::endl;
00072         
00073         if (!econn)
00074           {
00075             std::cout << " Problem with OMDS: connection parameters " <<m_sid <<"/"<<m_user<<"/"<<m_pass<<std::endl;
00076             throw cms::Exception("OMDS not available");
00077           } 
00078 
00079 
00080         std::cout << "Retrieving last run from ONLINE DB ... " << std::endl;
00081         std::map<EcalLogicID, RunDat> rundat;
00082         RunIOV rp ;
00083         run_t runmax=10000000;
00084         std::string location_p5="P5_Co";
00085         econn->fetchValidDataSet(&rundat , &rp, location_p5 ,runmax);
00086         
00087         unsigned long long  irun=(unsigned long long) rp.getRunNumber();
00088 
00089         std::cout<< "retrieved run number "<< irun <<std::endl;  
00090 
00091         if(irun>max_since) {
00092 
00093 
00094           // retrieve from last value data record 
00095           // always call this method at first run
00096           
00097           std::map<EcalLogicID, RunDCSMagnetDat> dataset;
00098           
00099           econn->fetchDataSet(&dataset, &rp);
00100           
00101           if (!dataset.size()) {
00102             throw(std::runtime_error("Zero rows read back"));
00103           } else {
00104             std::cout<< "retrieved magnet current"<<std::endl;  
00105           }
00106           
00107           
00108           float mag_cur=0;
00109           
00110           std::map<  EcalLogicID, RunDCSMagnetDat >::iterator it;
00111           for (it=dataset.begin(); it!=dataset.end(); ++it){
00112             
00113             RunDCSMagnetDat  a_mag = (*it).second;
00114             mag_cur= a_mag.getMagnetCurrent();
00115             
00116           }
00117           
00118           
00119           std::string file_=m_file_highfield;
00120           bool something_to_transfer=false;
00121           if(mag_cur>7000. && magnet_high ) {
00122             
00123             std::cout << " the magnet is ON and the constants are for magnet ON " << std::endl; 
00124             
00125           } else if(mag_cur>7000. && !magnet_high ) {
00126             something_to_transfer=true;
00127             std::cout << " the magnet is ON and the constants are for magnet OFF " << std::endl; 
00128             std::cout << " I transfer the ON constants "<< std::endl; 
00129             file_=m_file_highfield;
00130             
00131           } else if(mag_cur<6000. && magnet_high ) {
00132             something_to_transfer=true;
00133             std::cout << " the magnet is OFF and the constants are for magnet ON "<< std::endl;
00134             std::cout << " I transfer the OFF constants "<< std::endl;
00135             file_=m_file_lowfield;
00136             
00137           } else if( mag_cur<6000. && !magnet_high ){
00138             
00139             std::cout << " the magnet is OFF and the constants are for magnet OFF "<< std::endl;
00140             file_=m_file_lowfield;
00141             
00142           } else {
00143             
00144             std::cout << " the magnet is in a strange situation I do nothing ... just be patient "<< std::endl;
00145             
00146           }
00147           
00148           
00149           if(something_to_transfer){
00150             
00151             std::cout << "Generating popcon record for run " << irun << "..." << std::flush;
00152             std::cout << "going to open file "<<file_ << std::flush;
00153             
00154             
00155             EcalCondHeader   header;
00156             EcalADCToGeVConstant * payload = new EcalADCToGeVConstant;
00157             EcalADCToGeVXMLTranslator::readXML(file_,header,*payload);
00158             
00159             
00160             Time_t snc= (Time_t) irun ;
00161             
00162             popcon::PopConSourceHandler<EcalADCToGeVConstant>::m_to_transfer.push_back(
00163                                                                                           std::make_pair(payload,snc));
00164             
00165             ss << "Run=" << irun << "_Magnet_changed_"<<std::endl; 
00166             m_userTextLog = ss.str()+";";
00167             
00168             
00169           } else {
00170             std::cout << "Run " << irun << " nothing sent to the DB"<< std::endl;
00171           
00172             ss<< "Run=" << irun << "_Magnet_NOT_changed_"<<std::endl; 
00173             m_userTextLog = ss.str()+";";
00174           }
00175           
00176         
00177           delete econn;
00178         } else {
00179             std::cout << "Run " << irun << " nothing sent to the DB"<< std::endl;
00180             ss<< "Run=" << irun << "_no_new_runs_"<<std::endl; 
00181             m_userTextLog = ss.str()+";";
00182 
00183 
00184         }
00185 
00186         
00187 
00188         std::cout << "Ecal - > end of getNewObjects -----------\n";
00189 
00190 }
00191