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
00024
00025
00026 std::cout << m_sid<<"/"<<m_user<<"/"<<m_location<<"/"<<m_gentag << std::endl;
00027
00028
00029 }
00030
00031 popcon::EcalIntercalibHandler::~EcalIntercalibHandler()
00032 {
00033 }
00034
00035
00036 void popcon::EcalIntercalibHandler::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
00050
00051 std::cout << "retrieved last payload " << std::endl;
00052
00053
00054 EcalIntercalibConstant the_cal = 0.;
00055
00056 int iX=50;
00057 int iY=5;
00058 int iZ=-1;
00059 float the_value_high=0.75585;
00060
00061 if (EEDetId::validDetId(iX,iY,iZ))
00062 {
00063 EEDetId eedetidpos(iX,iY,iZ);
00064
00065 EcalIntercalibConstants::const_iterator it =ped_db->find(eedetidpos.rawId());
00066
00067
00068 the_cal = (*it);
00069
00070 }
00071
00072 bool magnet_high=true;
00073 if(the_cal!= the_value_high) magnet_high=false;
00074
00075
00076
00077
00078 std::cout << "Connecting to ONLINE DB ... " << std::endl;
00079 econn = new EcalCondDBInterface( m_sid, m_user, m_pass );
00080 std::cout << "Connection done" << std::endl;
00081
00082 if (!econn)
00083 {
00084 std::cout << " Problem with OMDS: connection parameters " <<m_sid <<"/"<<m_user<<"/"<<m_pass<<std::endl;
00085 throw cms::Exception("OMDS not available");
00086 }
00087
00088
00089 std::cout << "Retrieving last run from ONLINE DB ... " << std::endl;
00090 std::map<EcalLogicID, RunDat> rundat;
00091 RunIOV rp ;
00092 run_t runmax=10000000;
00093 std::string location_p5="P5_Co";
00094 econn->fetchValidDataSet(&rundat , &rp, location_p5 ,runmax);
00095
00096 unsigned long long irun=(unsigned long long) rp.getRunNumber();
00097
00098 std::cout<< "retrieved run number "<< irun <<std::endl;
00099
00100 if(irun>max_since) {
00101
00102
00103
00104
00105
00106 std::map<EcalLogicID, RunDCSMagnetDat> dataset;
00107
00108 econn->fetchDataSet(&dataset, &rp);
00109
00110 if (!dataset.size()) {
00111 throw(std::runtime_error("Zero rows read back"));
00112 } else {
00113 std::cout<< "retrieved magnet current"<<std::endl;
00114 }
00115
00116
00117 float mag_cur=0;
00118
00119 std::map< EcalLogicID, RunDCSMagnetDat >::iterator it;
00120 for (it=dataset.begin(); it!=dataset.end(); ++it){
00121
00122 RunDCSMagnetDat a_mag = (*it).second;
00123 mag_cur= a_mag.getMagnetCurrent();
00124
00125 }
00126
00127
00128 std::string file_=m_file_highfield;
00129 bool something_to_transfer=false;
00130 if(mag_cur>5000. && magnet_high ) {
00131
00132 std::cout << " the magnet is ON and the constants are for magnet ON " << std::endl;
00133
00134 } else if(mag_cur>5000. && !magnet_high ) {
00135 something_to_transfer=true;
00136 std::cout << " the magnet is ON and the constants are for magnet OFF " << std::endl;
00137 std::cout << " I transfer the ON constants "<< std::endl;
00138 file_=m_file_highfield;
00139
00140 } else if(mag_cur<3000. && magnet_high ) {
00141 something_to_transfer=true;
00142 std::cout << " the magnet is OFF and the constants are for magnet ON "<< std::endl;
00143 std::cout << " I transfer the OFF constants "<< std::endl;
00144 file_=m_file_lowfield;
00145
00146 } else if( mag_cur<3000. && !magnet_high ){
00147
00148 std::cout << " the magnet is OFF and the constants are for magnet OFF "<< std::endl;
00149 file_=m_file_lowfield;
00150
00151 } else {
00152
00153 std::cout << " the magnet is in a strange situation I do nothing ... just be patient "<< std::endl;
00154
00155 }
00156
00157
00158 if(something_to_transfer){
00159
00160 std::cout << "Generating popcon record for run " << irun << "..." << std::flush;
00161 std::cout << "going to open file "<<file_ << std::flush;
00162
00163
00164 EcalCondHeader header;
00165 EcalIntercalibConstants * payload = new EcalIntercalibConstants;
00166 EcalFloatCondObjectContainerXMLTranslator::readXML(file_,header,*payload);
00167
00168
00169 Time_t snc= (Time_t) irun ;
00170
00171 popcon::PopConSourceHandler<EcalIntercalibConstants>::m_to_transfer.push_back(
00172 std::make_pair(payload,snc));
00173
00174 ss << "Run=" << irun << "_Magnet_changed_"<<std::endl;
00175 m_userTextLog = ss.str()+";";
00176
00177
00178 } else {
00179 std::cout << "Run " << irun << " nothing sent to the DB"<< std::endl;
00180
00181 ss<< "Run=" << irun << "_Magnet_NOT_changed_"<<std::endl;
00182 m_userTextLog = ss.str()+";";
00183 }
00184
00185
00186 delete econn;
00187 } else {
00188 std::cout << "Run " << irun << " nothing sent to the DB"<< std::endl;
00189 ss<< "Run=" << irun << "_no_new_runs_"<<std::endl;
00190 m_userTextLog = ss.str()+";";
00191
00192
00193 }
00194
00195
00196
00197 std::cout << "Ecal - > end of getNewObjects -----------\n";
00198
00199 }
00200