CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_9_patch3/src/CondTools/Ecal/src/EcalIntercalibHandler.cc

Go to the documentation of this file.
00001 #include "CondTools/Ecal/interface/EcalIntercalibHandler.h"
00002 #include "FWCore/ParameterSet/interface/ParameterSetfwd.h"
00003 #include "CondFormats/EcalObjects/interface/EcalIntercalibConstants.h"
00004 #include "CondTools/Ecal/interface/EcalFloatCondObjectContainerXMLTranslator.h"
00005 
00006 
00007 #include<iostream>
00008 
00009 popcon::EcalIntercalibHandler::EcalIntercalibHandler(const edm::ParameterSet & ps)
00010   :    m_name(ps.getUntrackedParameter<std::string>("name","EcalIntercalibHandler")) {
00011 
00012         std::cout << "EcalIntercalib 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         m_value_highfield= ps.getUntrackedParameter< double >("Value_Bon");
00024         //      m_value_highfield= 0.75585;
00025 
00026 
00027 
00028         std::cout << m_sid<<"/"<<m_user<<"/"<<m_location<<"/"<<m_gentag   << std::endl;
00029 
00030 
00031 }
00032 
00033 popcon::EcalIntercalibHandler::~EcalIntercalibHandler()
00034 {
00035 }
00036 
00037 
00038 void popcon::EcalIntercalibHandler::getNewObjects()
00039 {
00040 
00041         std::cout << "------- Ecal - > getNewObjects\n";
00042 
00043   std::ostringstream ss; 
00044   ss<<"ECAL ";
00045 
00046         unsigned int max_since=0;
00047         max_since=static_cast<unsigned int>(tagInfo().lastInterval.first);
00048         std::cout << "max_since : "  << max_since << std::endl;
00049         Ref ped_db = lastPayload();
00050         
00051         // we parse the last record in the DB and check if it is low or high field 
00052 
00053         std::cout << "retrieved last payload "  << std::endl;
00054 
00055 
00056         EcalIntercalibConstant the_cal = 0. ; // relies on it being a float.
00057                                               // instead should perhaps
00058                                               // protect the next if when
00059                                               // the EEDetId isn't valid?
00060 
00061         int iX=50;
00062         int iY=5;
00063         int iZ=-1;
00064 
00065 
00066         float the_value_high=(float)m_value_highfield;
00067         std::cout << "The value for high field at EE x/y/z= 50/5/-1 is " << the_value_high << std::endl;
00068 
00069         if (EEDetId::validDetId(iX,iY,iZ))
00070           {
00071             EEDetId eedetidpos(iX,iY,iZ);
00072             
00073             EcalIntercalibConstants::const_iterator it =ped_db->find(eedetidpos.rawId());
00074             
00075 
00076             the_cal = (*it);
00077 
00078           }
00079         
00080         bool magnet_high=true; 
00081         if(the_cal!= the_value_high) magnet_high=false; 
00082 
00083 
00084         // here we connect to the online DB to check the value of the magnetic field 
00085 
00086         std::cout << "Connecting to ONLINE DB ... " << std::endl;
00087         econn = new EcalCondDBInterface( m_sid, m_user, m_pass );
00088         std::cout << "Connection done" << std::endl;
00089         
00090         if (!econn)
00091           {
00092             std::cout << " Problem with OMDS: connection parameters " <<m_sid <<"/"<<m_user<<"/"<<m_pass<<std::endl;
00093             throw cms::Exception("OMDS not available");
00094           } 
00095 
00096 
00097         std::cout << "Retrieving last run from ONLINE DB ... " << std::endl;
00098         std::map<EcalLogicID, RunDat> rundat;
00099         RunIOV rp ;
00100         run_t runmax=10000000;
00101         std::string location_p5="P5_Co";
00102         econn->fetchValidDataSet(&rundat , &rp, location_p5 ,runmax);
00103         
00104         unsigned long long  irun=(unsigned long long) rp.getRunNumber();
00105 
00106         std::cout<< "retrieved run number "<< irun <<std::endl;  
00107 
00108         if(irun>max_since) {
00109 
00110 
00111           // retrieve from last value data record 
00112           // always call this method at first run
00113           
00114           std::map<EcalLogicID, RunDCSMagnetDat> dataset;
00115           
00116           econn->fetchDataSet(&dataset, &rp);
00117           
00118           if (!dataset.size()) {
00119             throw(std::runtime_error("Zero rows read back"));
00120           } else {
00121             std::cout<< "retrieved magnet current"<<std::endl;  
00122           }
00123           
00124           
00125           float mag_cur=0;
00126           
00127           std::map<  EcalLogicID, RunDCSMagnetDat >::iterator it;
00128           for (it=dataset.begin(); it!=dataset.end(); ++it){
00129             
00130             RunDCSMagnetDat  a_mag = (*it).second;
00131             mag_cur= a_mag.getMagnetCurrent();
00132             
00133           }
00134           
00135           
00136           std::string file_=m_file_highfield;
00137           bool something_to_transfer=false;
00138           if(mag_cur>7000. && magnet_high ) {
00139             
00140             std::cout << " the magnet is ON and the constants are for magnet ON " << std::endl; 
00141             
00142           } else if(mag_cur>7000. && !magnet_high ) {
00143             something_to_transfer=true;
00144             std::cout << " the magnet is ON and the constants are for magnet OFF " << std::endl; 
00145             std::cout << " I transfer the ON constants "<< std::endl; 
00146             file_=m_file_highfield;
00147             
00148           } else if(mag_cur<6000. && magnet_high ) {
00149             something_to_transfer=true;
00150             std::cout << " the magnet is OFF and the constants are for magnet ON "<< std::endl;
00151             std::cout << " I transfer the OFF constants "<< std::endl;
00152             file_=m_file_lowfield;
00153             
00154           } else if( mag_cur<6000. && !magnet_high ){
00155             
00156             std::cout << " the magnet is OFF and the constants are for magnet OFF "<< std::endl;
00157             file_=m_file_lowfield;
00158             
00159           } else {
00160             
00161             std::cout << " the magnet is in a strange situation I do nothing ... just be patient "<< std::endl;
00162             
00163           }
00164           
00165           
00166           if(something_to_transfer){
00167             
00168             std::cout << "Generating popcon record for run " << irun << "..." << std::flush;
00169             std::cout << "going to open file "<<file_ << std::flush;
00170             
00171             
00172             EcalCondHeader   header;
00173             EcalIntercalibConstants * payload = new EcalIntercalibConstants;
00174             EcalFloatCondObjectContainerXMLTranslator::readXML(file_,header,*payload);
00175             
00176             
00177             Time_t snc= (Time_t) irun ;
00178             
00179             popcon::PopConSourceHandler<EcalIntercalibConstants>::m_to_transfer.push_back(
00180                                                                                           std::make_pair(payload,snc));
00181             
00182             ss << "Run=" << irun << "_Magnet_changed_"<<std::endl; 
00183             m_userTextLog = ss.str()+";";
00184             
00185             
00186           } else {
00187             std::cout << "Run " << irun << " nothing sent to the DB"<< std::endl;
00188           
00189             ss<< "Run=" << irun << "_Magnet_NOT_changed_"<<std::endl; 
00190             m_userTextLog = ss.str()+";";
00191           }
00192           
00193         
00194           delete econn;
00195         } else {
00196             std::cout << "Run " << irun << " nothing sent to the DB"<< std::endl;
00197             ss<< "Run=" << irun << "_no_new_runs_"<<std::endl; 
00198             m_userTextLog = ss.str()+";";
00199 
00200 
00201         }
00202 
00203         
00204 
00205         std::cout << "Ecal - > end of getNewObjects -----------\n";
00206 
00207 }
00208