00001 #include "CondTools/Ecal/interface/EcalLaserHandler.h"
00002 #include "FWCore/ParameterSet/interface/ParameterSetfwd.h"
00003
00004 #include<iostream>
00005
00006
00007
00008 popcon::EcalLaserHandler::EcalLaserHandler(const edm::ParameterSet & ps)
00009 : m_name(ps.getUntrackedParameter<std::string>("name","EcalLaserHandler")) {
00010
00011 std::cout << "EcalLaser Source handler constructor\n" << std::endl;
00012
00013 m_firstRun=(unsigned long)atoi( ps.getParameter<std::string>("firstRun").c_str());
00014 m_lastRun=(unsigned long)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
00022 std::cout << m_sid<<"/"<<m_user<<"/"<<m_pass<<"/"<<m_location<<"/"<<m_gentag << std::endl;
00023 }
00024
00025 popcon::EcalLaserHandler::~EcalLaserHandler()
00026 {
00027 }
00028
00029 void popcon::EcalLaserHandler::getNewObjects()
00030 {
00031 std::cerr << "------- " << m_name
00032 << " - > getNewObjects" << std::endl;
00033
00034 std::cout << "------- Ecal - > getNewObjects\n";
00035
00036
00037 int max_since=0;
00038 max_since=(int)tagInfo().lastInterval.first;
00039 std::cout << "max_since : " << max_since << endl;
00040 Ref payload= lastPayload();
00041
00042 std::cout << "retrieved last payload " << endl;
00043
00044
00045
00046 EcalLaserAPDPNRatios* apdpns_temp = new EcalLaserAPDPNRatios();
00047
00048
00049
00050 EcalLaserAPDPNRatios::EcalLaserTimeStamp timestamp;
00051 EcalLaserAPDPNRatios::EcalLaserAPDPNpair apdpnpair;
00052
00053 EcalLaserAPDPNRatios::EcalLaserTimeStamp timestamp_temp;
00054 EcalLaserAPDPNRatios::EcalLaserAPDPNpair apdpnpair_temp;
00055
00056 const EcalLaserAPDPNRatios::EcalLaserAPDPNRatiosMap& laserRatiosMap = payload->getLaserMap();
00057 const EcalLaserAPDPNRatios::EcalLaserTimeStampMap& laserTimeMap = payload->getTimeMap();
00058 std::cout << "going to access objects in the last payload " << endl;
00059
00060
00061
00062
00063
00064
00065 for(int iEta=-EBDetId::MAX_IETA; iEta<=EBDetId::MAX_IETA ;++iEta) {
00066 if(iEta==0) continue;
00067 for(int iPhi=EBDetId::MIN_IPHI; iPhi<=EBDetId::MAX_IPHI; ++iPhi) {
00068 try
00069 {
00070 if (EBDetId::validDetId(iEta,iPhi))
00071 {
00072 EBDetId ebdetid(iEta,iPhi);
00073 unsigned int hiee = ebdetid.hashedIndex();
00074 if (laserRatiosMap.find(ebdetid)!=laserRatiosMap.end()){
00075 apdpnpair = laserRatiosMap[ebdetid];
00076 apdpnpair_temp.p1 = apdpnpair.p1;
00077 apdpnpair_temp.p2 = apdpnpair.p2;
00078 apdpns_temp->setValue(ebdetid, apdpnpair_temp);
00079 if (hiee%1000 == 0 )std::cout <<"hiee = "<< hiee << " p1 = " << apdpnpair.p1 <<" p2 = " << apdpnpair.p2 <<endl;
00080 } else {
00081 edm::LogError("EcalLaserHandler") << "error with laserRatiosMap!" << endl;
00082 }
00083 }
00084 }
00085 catch (cms::Exception &e) { }
00086 }
00087 }
00088
00089 std::cout << "going to access Endcap objects in the last payload " << endl;
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129 for (int i=0; i<92; i++){
00130 timestamp = laserTimeMap[i];
00131
00132 timestamp_temp.t1 = timestamp.t1;
00133 timestamp_temp.t2 = timestamp.t2;
00134
00135 apdpns_temp->setTime(i,timestamp_temp);
00136 }
00137
00138 cout <<"WOW: we just retrieved the last valid record from DB "<< endl;
00139
00140
00141
00142
00143 cout << "Retrieving run list from ONLINE DB ... " << endl;
00144 try {
00145 cout << "Making connection..." << flush;
00146 econn = new EcalCondDBInterface( m_sid, m_user, m_pass );
00147 cout << "Done." << endl;
00148 } catch (runtime_error &e) {
00149 cout << " connection parameters " <<m_sid <<"/"<<m_user<<"/"<<m_pass<<endl;
00150 cerr << e.what() << endl;
00151 throw cms::Exception("OMDS not available");
00152 }
00153
00154
00155 RunList my_runlist ;
00156 RunTag my_runtag;
00157 LocationDef my_locdef;
00158 RunTypeDef my_rundef;
00159
00160 my_locdef.setLocation(m_location);
00161 my_rundef.setRunType("LASER");
00162 my_runtag.setLocationDef(my_locdef);
00163 my_runtag.setRunTypeDef(my_rundef);
00164 my_runtag.setGeneralTag(m_gentag);
00165
00166
00167
00168
00169 LMFRunTag lmf_tag;
00170 lmf_tag.setGeneralTag("default");
00171 LMFRunList lmf_list;
00172 lmf_list.setLMFRunTag(lmf_tag);
00173 lmf_list.setRunTag(my_runtag);
00174
00175
00176 int min_run=m_firstRun;
00177 if(m_firstRun==0 || m_firstRun < (max_since+1) ){
00178 min_run=(int)max_since+1;
00179 }
00180 cout << " minimum accepted run is "<<min_run<< endl;
00181
00182
00183 int max_run=(int)m_lastRun;
00184 lmf_list=econn->fetchLMFRunList(my_runtag, lmf_tag,min_run,max_run );
00185
00186 std::vector<LMFRunIOV> lmf_run_vec= lmf_list.getRuns();
00187 int lmf_runs=lmf_run_vec.size();
00188 cout <<"number of LMF runs is : "<< lmf_runs<< endl;
00189
00190 if(lmf_runs>0){
00191
00192 for(int kr=0; kr<lmf_runs; kr++){
00193
00194 unsigned long irun=(unsigned long) lmf_run_vec[kr].getRunIOV().getRunNumber();
00195 cout << "here is the run number: "<< lmf_run_vec[kr].getRunIOV().getRunNumber() << endl;
00196
00197 cout <<" retrieve the data for a given run"<< endl;
00198
00199 if (lmf_run_vec[kr].getSubRunNumber() <=1){
00200
00201
00202 RunIOV runiov_prime = lmf_run_vec[kr].getRunIOV();
00203
00204
00205 map<EcalLogicID, LMFLaserBlueNormDat> dataset_lmf;
00206 econn->fetchDataSet(&dataset_lmf, &lmf_run_vec[kr]);
00207 cout <<"OMDS record for run "<<irun <<" is made of "<< dataset_lmf.size() << endl;
00208 typedef map<EcalLogicID, LMFLaserBlueNormDat>::const_iterator CIlmf;
00209 EcalLogicID ecid_xt;
00210 LMFLaserBlueNormDat rd_apdnorm;
00211
00212
00213
00214
00215
00216
00217
00218 for (CIlmf p = dataset_lmf.begin(); p != dataset_lmf.end(); p++) {
00219 ecid_xt = p->first;
00220 rd_apdnorm = p->second;
00221 int sm_num=ecid_xt.getID1();
00222 const EcalLaserAPDPNRatios::EcalLaserAPDPNRatiosMap& laserRatiosMap = apdpns_temp->getLaserMap();
00223 int xt_num=ecid_xt.getID2();
00224 EBDetId ebdetid(sm_num,xt_num,EBDetId::SMCRYSTALMODE);
00225 unsigned int hiee = ebdetid.hashedIndex();
00226 apdpnpair = laserRatiosMap[ebdetid];
00227
00228
00229 apdpnpair_temp.p1 = apdpnpair.p2;
00230
00231 apdpnpair_temp.p2 = rd_apdnorm.getAPDOverPNMean();
00232
00233
00234
00235
00236 apdpns_temp->setValue(ebdetid, apdpnpair_temp);
00237 }
00238
00239 for (int i=0; i<92; i++){
00240 const EcalLaserAPDPNRatios::EcalLaserTimeStampMap& laserTimeMap = apdpns_temp->getTimeMap();
00241 timestamp = laserTimeMap[i];
00242
00243 timestamp_temp.t1 = timestamp.t2;
00244
00245 timestamp_temp.t2 = irun;
00246
00247 apdpns_temp->setTime(i,timestamp_temp);
00248 }
00249
00250 cout << "Generating popcon record for run " << irun << "..." << flush;
00251
00252
00253
00254
00255
00256
00257
00258 EcalLaserAPDPNRatios* apdpns_popcon = new EcalLaserAPDPNRatios();
00259
00260 for(int iEta=-EBDetId::MAX_IETA; iEta<=EBDetId::MAX_IETA ;++iEta) {
00261 if(iEta==0) continue;
00262 for(int iPhi=EBDetId::MIN_IPHI; iPhi<=EBDetId::MAX_IPHI; ++iPhi) {
00263
00264 if (EBDetId::validDetId(iEta,iPhi))
00265 {
00266 EBDetId ebdetid(iEta,iPhi);
00267 unsigned int hiee = ebdetid.hashedIndex();
00268
00269
00270
00271 if (laserRatiosMap.find(ebdetid)!=laserRatiosMap.end()){
00272
00273 const EcalLaserAPDPNRatios::EcalLaserAPDPNRatiosMap& laserRatiosMap = apdpns_temp->getLaserMap();
00274 apdpnpair = laserRatiosMap[ebdetid];
00275 apdpnpair_temp.p1 = apdpnpair.p1;
00276 apdpnpair_temp.p2 = apdpnpair.p2;
00277
00278 apdpns_popcon->setValue(ebdetid, apdpnpair_temp);
00279 } else {
00280 edm::LogError("EcalLaserHandler") << "error with laserRatiosMap!" << endl;
00281 }
00282
00283 }
00284 }
00285 }
00286
00287 for (int i=0; i<92; i++){
00288
00289 const EcalLaserAPDPNRatios::EcalLaserTimeStampMap& laserTimeMap = apdpns_temp->getTimeMap();
00290 timestamp = laserTimeMap[i];
00291
00292 timestamp_temp.t1 = timestamp.t1;
00293 timestamp_temp.t2 = timestamp.t2;
00294
00295 apdpns_popcon->setTime(i,timestamp_temp);
00296 }
00297
00298 Time_t snc = irun ;
00299
00300
00301
00302
00303
00304
00305 m_to_transfer.push_back(std::make_pair(apdpns_popcon,snc));
00306
00307 std::cout << "Ecal - > end of getNewObjects -----------\n";
00308
00309
00310 }
00311 }
00312
00313 }
00314
00315
00316 delete econn;
00317 delete apdpns_temp;
00318
00319
00320 }