CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_7/src/CondTools/Ecal/src/EcalPedestalsHandler.cc

Go to the documentation of this file.
00001 #include "CondTools/Ecal/interface/EcalLaserHandler.h"
00002 
00003 #include "CondTools/Ecal/interface/EcalPedestalsHandler.h"
00004 #include "FWCore/ParameterSet/interface/ParameterSetfwd.h"
00005 
00006 #include<iostream>
00007 
00008 popcon::EcalPedestalsHandler::EcalPedestalsHandler(const edm::ParameterSet & ps)
00009   :    m_name(ps.getUntrackedParameter<std::string>("name","EcalPedestalsHandler")) {
00010 
00011         std::cout << "EcalPedestals Source handler constructor\n" << std::endl;
00012         m_firstRun=static_cast<unsigned int>(atoi( ps.getParameter<std::string>("firstRun").c_str()));
00013         m_lastRun=static_cast<unsigned int>(atoi( ps.getParameter<std::string>("lastRun").c_str()));
00014         m_sid= ps.getParameter<std::string>("OnlineDBSID");
00015         m_user= ps.getParameter<std::string>("OnlineDBUser");
00016         m_pass= ps.getParameter<std::string>("OnlineDBPassword");
00017         m_locationsource= ps.getParameter<std::string>("LocationSource");
00018         m_location=ps.getParameter<std::string>("Location");
00019         m_gentag=ps.getParameter<std::string>("GenTag");
00020 
00021         std::cout << m_sid<<"/"<<m_user<<"/"<<m_pass<<"/"<<m_location<<"/"<<m_gentag   << std::endl;
00022 
00023 
00024 }
00025 
00026 popcon::EcalPedestalsHandler::~EcalPedestalsHandler()
00027 {
00028 }
00029 
00030 
00031 void popcon::EcalPedestalsHandler::getNewObjects()
00032 {
00033 
00034         std::cout << "------- Ecal - > getNewObjects\n";
00035 
00036         if(m_locationsource=="H2") {
00037           getNewObjectsH2();
00038         } else if (m_locationsource=="P5") {
00039           getNewObjectsP5();
00040         }
00041 }
00042 
00043 
00044 bool popcon::EcalPedestalsHandler::checkPedestal( EcalPedestals::Item* item ){
00045   // true means all is standard and OK
00046   bool result=true;
00047   if(item->rms_x12 >3 || item->rms_x12<=0) result=false; 
00048   if(item->rms_x6 >2 || item->rms_x6<=0) result=false; 
00049   if(item->rms_x1 >1 || item->rms_x1<=0) result=false; 
00050   if(item->mean_x12>300 || item->mean_x12<=100) result=false; 
00051   if(item->mean_x1>300 || item->mean_x1<=100) result=false; 
00052   if(item->mean_x6>300 || item->mean_x6<=100) result=false; 
00053   return result; 
00054   }
00055 
00056 void popcon::EcalPedestalsHandler::getNewObjectsP5()
00057 {
00058 
00059   std::ostringstream ss; 
00060   ss<<"ECAL ";
00061 
00062         unsigned int max_since=0;
00063         max_since=static_cast<unsigned int>(tagInfo().lastInterval.first);
00064         std::cout << "max_since : "  << max_since << std::endl;
00065         Ref ped_db = lastPayload();
00066         
00067         // we copy the last valid record to a temporary object peds
00068         EcalPedestals* peds = new EcalPedestals();
00069         std::cout << "retrieved last payload "  << std::endl;
00070 
00071         for(int iEta=-EBDetId::MAX_IETA; iEta<=EBDetId::MAX_IETA ;++iEta) {
00072           if(iEta==0) continue;
00073           for(int iPhi=EBDetId::MIN_IPHI; iPhi<=EBDetId::MAX_IPHI; ++iPhi) {
00074             // make an EBDetId since we need EBDetId::rawId() to be used as the key for the pedestals
00075             if (EBDetId::validDetId(iEta,iPhi))
00076               {
00077         
00078 
00079                 EBDetId ebdetid(iEta,iPhi,EBDetId::ETAPHIMODE);
00080                 EcalPedestals::const_iterator it =ped_db->find(ebdetid.rawId());
00081         
00082                 EcalPedestals::Item aped = (*it);
00083         
00084 
00085                 // here I copy the last valid value in the peds object
00086                 EcalPedestals::Item item;
00087                 item.mean_x1  = aped.mean_x1;
00088                 item.rms_x1   = aped.rms_x1;
00089                 item.mean_x6  = aped.mean_x6;
00090                 item.rms_x6   = aped.rms_x6;
00091                 item.mean_x12 = aped.mean_x12;
00092                 item.rms_x12  = aped.rms_x12;
00093 
00094                 peds->insert(std::make_pair(ebdetid.rawId(),item));
00095         
00096               }
00097           }
00098         }
00099 
00100 
00101         for(int iX=EEDetId::IX_MIN; iX<=EEDetId::IX_MAX ;++iX) {
00102           for(int iY=EEDetId::IY_MIN; iY<=EEDetId::IY_MAX; ++iY) {
00103             // make an EEDetId since we need EEDetId::rawId() to be used as the key for the pedestals
00104             if (EEDetId::validDetId(iX,iY,1))
00105               {
00106                 EEDetId eedetidpos(iX,iY,1);
00107 
00108                 EcalPedestals::const_iterator it =ped_db->find(eedetidpos.rawId());
00109                 EcalPedestals::Item aped = (*it);
00110 
00111                 //      unsigned int hiee = eedetidpos.hashedIndex();
00112                 //      EcalPedestals::Item aped= ped_db->endcap(hiee);
00113 
00114                 // here I copy the last valid value in the peds object
00115                 EcalPedestals::Item item;
00116                 item.mean_x1  = aped.mean_x1;
00117                 item.rms_x1   = aped.rms_x1;
00118                 item.mean_x6  = aped.mean_x6;
00119                 item.rms_x6   = aped.rms_x6;
00120                 item.mean_x12 = aped.mean_x12;
00121                 item.rms_x12  = aped.rms_x12;
00122                 peds->insert(std::make_pair(eedetidpos.rawId(),item));
00123 
00124               }
00125             if(EEDetId::validDetId(iX,iY,-1))
00126               {
00127                 EEDetId eedetidneg(iX,iY,-1);
00128 
00129                 EcalPedestals::const_iterator it =ped_db->find(eedetidneg.rawId());
00130                 EcalPedestals::Item aped = (*it);
00131                 //     unsigned int hiee = eedetidneg.hashedIndex();
00132                 //     EcalPedestals::Item aped= ped_db->endcap(hiee);
00133 
00134                 // here I copy the last valid value in the peds object
00135                 EcalPedestals::Item item;
00136                 item.mean_x1  = aped.mean_x1;
00137                 item.rms_x1   = aped.rms_x1;
00138                 item.mean_x6  = aped.mean_x6;
00139                 item.rms_x6   = aped.rms_x6;
00140                 item.mean_x12 = aped.mean_x12;
00141                 item.rms_x12  = aped.rms_x12;
00142                 peds->insert(std::make_pair(eedetidneg.rawId(),item));
00143 
00144               }
00145           }
00146         }
00147 
00148         // here we retrieve all the runs after the last from online DB 
00149 
00150         std::cout << "Retrieving run list from ONLINE DB ... " << std::endl;
00151         econn = new EcalCondDBInterface( m_sid, m_user, m_pass );
00152         std::cout << "Connection done" << std::endl;
00153         
00154         if (!econn)
00155           {
00156             std::cout << " Problem with OMDS: connection parameters " <<m_sid <<"/"<<m_user<<"/"<<m_pass<<std::endl;
00157             throw cms::Exception("OMDS not available");
00158           } 
00159 
00160         // these are the online conditions DB classes 
00161         RunList my_runlist ;
00162         RunTag  my_runtag;
00163         LocationDef my_locdef;
00164         RunTypeDef my_rundef;
00165         
00166         my_locdef.setLocation(m_location);
00167         my_rundef.setRunType("PEDESTAL");
00168         my_runtag.setLocationDef(my_locdef);
00169         my_runtag.setRunTypeDef(my_rundef);
00170         my_runtag.setGeneralTag(m_gentag);
00171         
00172 
00173       // here we retrieve the Monitoring run records
00174       
00175         MonVersionDef monverdef;
00176         monverdef.setMonitoringVersion("test01");
00177         
00178         MonRunTag mon_tag;
00179         //      mon_tag.setGeneralTag("CMSSW");
00180         mon_tag.setGeneralTag("CMSSW-offline-private");
00181         mon_tag.setMonVersionDef(monverdef);
00182         MonRunList mon_list;
00183         mon_list.setMonRunTag(mon_tag);
00184         mon_list.setRunTag(my_runtag);
00185         //    mon_list=econn->fetchMonRunList(my_runtag, mon_tag);
00186         unsigned int min_run=0;
00187         if(m_firstRun<max_since) {
00188           min_run=max_since+1; // we have to add 1 to the last transferred one
00189         } else {
00190           min_run=m_firstRun;
00191         }
00192 
00193         unsigned int max_run=m_lastRun;
00194         mon_list=econn->fetchMonRunList(my_runtag, mon_tag,min_run,max_run );
00195       
00196         std::vector<MonRunIOV> mon_run_vec=  mon_list.getRuns();
00197         int mon_runs = mon_run_vec.size();
00198         std::cout <<"number of Mon runs is : "<< mon_runs<< std::endl;
00199 
00200         if(mon_runs > 0){
00201           int krmax = std::min(mon_runs, 30);
00202           for(int kr = 0; kr < krmax; kr++){
00203             std::cout << "-kr------:  "<<kr<<std::endl;
00204 
00205 
00206             unsigned int irun=static_cast<unsigned int>(mon_run_vec[kr].getRunIOV().getRunNumber());
00207           
00208             std::cout << "retrieve the data for run number: "<< mon_run_vec[kr].getRunIOV().getRunNumber() << std::endl;
00209           
00210             if (mon_run_vec[kr].getSubRunNumber() <=1){ 
00211 
00212               // retrieve the data for a given run
00213               RunIOV runiov_prime = mon_run_vec[kr].getRunIOV();
00214               
00215               // retrieve the pedestals from OMDS for this run 
00216               std::map<EcalLogicID, MonPedestalsDat> dataset_mon;
00217               econn->fetchDataSet(&dataset_mon, &mon_run_vec[kr]);
00218               std::cout <<"OMDS record for run "<<irun  <<" is made of "<< dataset_mon.size() << std::endl;
00219               int nEB = 0, nEE = 0, nEBbad = 0, nEEbad =0;
00220               typedef std::map<EcalLogicID, MonPedestalsDat>::const_iterator CImon;
00221               EcalLogicID ecid_xt;
00222               MonPedestalsDat  rd_ped;
00223 
00224 
00225               // this to validate ...         
00226               int nbad=0;
00227               for (CImon p = dataset_mon.begin(); p != dataset_mon.end(); p++) {
00228                 ecid_xt = p->first;
00229                 rd_ped  = p->second;
00230                 int sm_num=ecid_xt.getID1();
00231                 int xt_num=ecid_xt.getID2(); 
00232                 int yt_num=ecid_xt.getID3(); 
00233 
00234                 EcalPedestals::Item item;
00235                 item.mean_x1  =rd_ped.getPedMeanG1() ;
00236                 item.rms_x1   =rd_ped.getPedRMSG1();
00237                 item.mean_x6  =rd_ped.getPedMeanG6();
00238                 item.rms_x6   =rd_ped.getPedRMSG6() ;
00239                 item.mean_x12 =rd_ped.getPedMeanG12();
00240                 item.rms_x12  =rd_ped.getPedRMSG12();
00241                 
00242                 if(ecid_xt.getName()=="EB_crystal_number") {
00243                   nEB++;
00244                   if(!checkPedestal(&item) ) nEBbad++;
00245                 }
00246                 else {
00247                   nEE++;
00248                   if(!checkPedestal(&item) ) nEEbad++;
00249                 }
00250 
00251                 // here we check and count how many bad channels we have 
00252 
00253                 if(!checkPedestal(&item) ){
00254                   nbad++;
00255                   if(nbad < 10) std::cout <<"BAD LIST: channel " << sm_num << "/" << xt_num << "/"<< yt_num 
00256                                    <<  "ped/rms "<<item.mean_x12<< "/"<< item.rms_x12 << std::endl;
00257                 }
00258               }
00259             
00260               // ok or bad? 
00261               // a bad run is for more than 5% bad channels 
00262 
00263               //              if(nbad<(dataset_mon.size()*0.1)){
00264               if(nbad<(dataset_mon.size()*0.05) && (nEB > 10200 || nEE > 2460)) {
00265 
00266                 for (CImon p = dataset_mon.begin(); p != dataset_mon.end(); p++) {
00267                   ecid_xt = p->first;
00268                   rd_ped  = p->second;
00269                   int sm_num=ecid_xt.getID1();
00270                   int xt_num=ecid_xt.getID2(); 
00271                   int yt_num=ecid_xt.getID3(); 
00272                   
00273 
00274                   EcalPedestals::Item item;
00275                   item.mean_x1  =rd_ped.getPedMeanG1() ;
00276                   item.rms_x1   =rd_ped.getPedRMSG1();
00277                   item.mean_x6  =rd_ped.getPedMeanG6();
00278                   item.rms_x6   =rd_ped.getPedRMSG6() ;
00279                   item.mean_x12 =rd_ped.getPedMeanG12();
00280                   item.rms_x12  =rd_ped.getPedRMSG12();
00281 
00282 
00283                   if(ecid_xt.getName()=="EB_crystal_number") {
00284                     // Barrel channel 
00285                     EBDetId ebdetid(sm_num,xt_num,EBDetId::SMCRYSTALMODE);
00286                     
00287                     // individual objects check
00288                     if(item.mean_x1==-1 || item.rms_x1 ==-1 || item.mean_x6==-1 || 
00289                        item.rms_x6==-1 || item.mean_x12==-1 || item.rms_x12==-1 ||
00290                        item.mean_x1==0 || item.rms_x1 ==0 || item.mean_x6==0 || 
00291                        item.rms_x6==0 || item.mean_x12==0 || item.rms_x12==0 ) {
00292                       // if one is bad we 
00293                       // retrieve the old valid value  
00294                       unsigned int hieb = ebdetid.hashedIndex();
00295                       EcalPedestals::Item previous_ped= peds->barrel(hieb);
00296                       if(item.mean_x1==-1  || item.mean_x1==0) item.mean_x1 =previous_ped.mean_x1;
00297                       if(item.rms_x1==-1   || item.rms_x1==0)  item.rms_x1  =previous_ped.rms_x1;
00298                       if(item.mean_x6==-1  || item.mean_x6==0) item.mean_x6 =previous_ped.mean_x6;
00299                       if(item.rms_x6==-1   || item.rms_x6==0)  item.rms_x6  =previous_ped.rms_x6;
00300                       if(item.mean_x12==-1 || item.mean_x12==0)item.mean_x12=previous_ped.mean_x12;
00301                       if(item.rms_x12==-1  || item.rms_x12==0) item.rms_x12 =previous_ped.rms_x12;
00302                     } 
00303                     
00304                     // here we change in the peds object only the channels that are available in the online DB 
00305                     // otherwise we keep the previous value 
00306                   
00307                     peds->insert(std::make_pair(ebdetid.rawId(),item)); 
00308                   } else {
00309                     // Endcap channel 
00310                     // in this case xt_num is x 
00311                     // yt_num is y and sm_num is the side +/- 1 
00312                     if(EEDetId::validDetId(xt_num,yt_num,sm_num)){
00313                       EEDetId eedetid(xt_num,yt_num,sm_num);
00314                       
00315                       // individual objects check
00316                       if(item.mean_x1==-1 || item.rms_x1 ==-1 || item.mean_x6==-1 || 
00317                          item.rms_x6==-1 || item.mean_x12==-1 || item.rms_x12==-1 ||
00318                          item.mean_x1==0 || item.rms_x1 ==0 || item.mean_x6==0 || 
00319                          item.rms_x6==0 || item.mean_x12==0 || item.rms_x12==0 ) {
00320                         // if one is bad we 
00321                         // retrieve the old valid value  
00322                         unsigned int hiee = eedetid.hashedIndex();
00323                         EcalPedestals::Item previous_ped= peds->endcap(hiee);
00324                         if(item.mean_x1==-1  || item.mean_x1==0) item.mean_x1 =previous_ped.mean_x1;
00325                         if(item.rms_x1==-1   || item.rms_x1==0)  item.rms_x1  =previous_ped.rms_x1;
00326                         if(item.mean_x6==-1  || item.mean_x6==0) item.mean_x6 =previous_ped.mean_x6;
00327                         if(item.rms_x6==-1   || item.rms_x6==0)  item.rms_x6  =previous_ped.rms_x6;
00328                         if(item.mean_x12==-1 || item.mean_x12==0)item.mean_x12=previous_ped.mean_x12;
00329                         if(item.rms_x12==-1  || item.rms_x12==0) item.rms_x12 =previous_ped.rms_x12;
00330                       } 
00331                       
00332                       // here we change in the peds object only the channels that are available in the online DB 
00333                       // otherwise we keep the previous value 
00334                       peds->insert(std::make_pair(eedetid.rawId(),item)); 
00335                     }
00336                     
00337                   }                    
00338                 
00339                 }
00340               
00341                 std::cout << "Generating popcon record for run " << irun << "..." << std::flush;
00342                 
00343                 // now I copy peds in pedtemp and I ship pedtemp to popcon
00344                 // if I use always the same peds I always overwrite
00345                 // so I really have to create new objects for each new run
00346                 // popcon deletes everything for me 
00347 
00348                 EcalPedestals* pedtemp = new EcalPedestals();
00349                 
00350                 for(int iEta=-EBDetId::MAX_IETA; iEta<=EBDetId::MAX_IETA ;++iEta) {
00351                   if(iEta==0) continue;
00352                   for(int iPhi=EBDetId::MIN_IPHI; iPhi<=EBDetId::MAX_IPHI; ++iPhi) {
00353                     // make an EBDetId since we need EBDetId::rawId() to be used as the key for the pedestals
00354                     if (EBDetId::validDetId(iEta,iPhi))
00355                       {
00356                         EBDetId ebdetid(iEta,iPhi);
00357                         unsigned int hiee = ebdetid.hashedIndex();
00358                         EcalPedestals::Item aped= peds->barrel(hiee);
00359                         
00360                         // here I copy the last valid value in the peds object
00361                         EcalPedestals::Item item;
00362                         item.mean_x1  = aped.mean_x1;
00363                         item.rms_x1   = aped.rms_x1;
00364                         item.mean_x6  = aped.mean_x6;
00365                         item.rms_x6   = aped.rms_x6;
00366                         item.mean_x12 = aped.mean_x12;
00367                         item.rms_x12  = aped.rms_x12;
00368                         // here I copy the last valid value in the pedtemp object
00369                         pedtemp->insert(std::make_pair(ebdetid.rawId(),item));
00370                         if((iEta==-1 || iEta==1) && iPhi==20){
00371                           float x=aped.mean_x12 ;
00372                           std::cout<< "channel:" <<iEta<<"/"<<iPhi<< "/" << hiee << " ped mean 12="<< x << std::endl;
00373                         }
00374                       }
00375                   }
00376                 }
00377                 // endcaps 
00378                 for(int iX=EEDetId::IX_MIN; iX<=EEDetId::IX_MAX ;++iX) {
00379                   for(int iY=EEDetId::IY_MIN; iY<=EEDetId::IY_MAX; ++iY) {
00380                     // make an EEDetId since we need EEDetId::rawId() to be used as the key for the pedestals
00381                     if (EEDetId::validDetId(iX,iY,1))
00382                       {
00383                         EEDetId eedetid(iX,iY,1);
00384                         unsigned int hiee = eedetid.hashedIndex();
00385                         EcalPedestals::Item aped= peds->endcap(hiee);
00386                         // here I copy the last valid value in the peds object
00387                         EcalPedestals::Item item;
00388                         item.mean_x1  = aped.mean_x1;
00389                         item.rms_x1   = aped.rms_x1;
00390                         item.mean_x6  = aped.mean_x6;
00391                         item.rms_x6   = aped.rms_x6;
00392                         item.mean_x12 = aped.mean_x12;
00393                         item.rms_x12  = aped.rms_x12;
00394                         // here I copy the last valid value in the pedtemp object
00395                         pedtemp->insert(std::make_pair(eedetid.rawId(),item));
00396                       }
00397                     if (EEDetId::validDetId(iX,iY,-1))
00398                       {
00399                         EEDetId eedetid(iX,iY,-1);
00400                         unsigned int hiee = eedetid.hashedIndex();
00401                         EcalPedestals::Item aped= peds->endcap(hiee);
00402                         // here I copy the last valid value in the peds object
00403                         EcalPedestals::Item item;
00404                         item.mean_x1  = aped.mean_x1;
00405                         item.rms_x1   = aped.rms_x1;
00406                         item.mean_x6  = aped.mean_x6;
00407                         item.rms_x6   = aped.rms_x6;
00408                         item.mean_x12 = aped.mean_x12;
00409                         item.rms_x12  = aped.rms_x12;
00410                         // here I copy the last valid value in the pedtemp object
00411                         pedtemp->insert(std::make_pair(eedetid.rawId(),item));
00412                       }
00413                   }
00414                 }
00415 
00416                 Time_t snc= (Time_t) irun ;
00417                       
00418                 m_to_transfer.push_back(std::make_pair((EcalPedestals*)pedtemp,snc));
00419               
00420 
00421                 ss << "Run=" << irun << "_WAS_GOOD_"<<std::endl; 
00422                 m_userTextLog = ss.str()+";";
00423               
00424               
00425                 } else {
00426                   std::cout << "Run " << irun << " was BAD !!!! not sent to the DB";
00427                   if(nbad >= (dataset_mon.size()*0.05))
00428                     std::cout << " number of bad channels = " << nbad;
00429                   if(nEB <= 10200)
00430                     std::cout << " number of EB channels = " << nEB;
00431                   if(nEE <= 2440)
00432                     std::cout << " number of EE channels = " << nEE;
00433                   std::cout << std::endl;
00434                   ss << "Run=" << irun << "_WAS_BAD_"<<std::endl; 
00435                   m_userTextLog = ss.str()+";";
00436                 }
00437             }
00438           }
00439             
00440         
00441           delete econn;
00442           delete peds;  // this is the only one that popcon does not delete 
00443 
00444         }
00445           std::cout << "Ecal - > end of getNewObjects -----------\n";
00446 
00447         
00448 }
00449 
00450 
00451 void popcon::EcalPedestalsHandler::getNewObjectsH2()
00452 {
00453         unsigned int max_since=0;
00454         max_since=static_cast<unsigned int>(tagInfo().lastInterval.first);
00455         std::cout << "max_since : "  << max_since << std::endl;
00456         Ref ped_db = lastPayload();
00457         
00458         std::cout << "retrieved last payload "  << std::endl;
00459 
00460 
00461         // we copy the last valid record to a temporary object peds
00462         EcalPedestals* peds = new EcalPedestals();
00463 
00464         // get from offline DB the last valid pedestal set ped_db
00465         //      edm::ESHandle<EcalPedestals> pedestals;
00466         //      esetup.get<EcalPedestalsRcd>().get(pedestals);
00467         
00468 
00469         // only positive endcap side and 
00470         // x from 86 to 95
00471         // y from 46 to 55 
00472         int ixmin=86;     int ixmax=95;
00473         int iymin=46;     int iymax=55;
00474         for(int iX=ixmin; iX<=ixmax ;++iX) {
00475           for(int iY=iymin; iY<=iymax; ++iY) {
00476 
00477             if (EEDetId::validDetId(iX,iY,1)) {
00478               EEDetId eedetidpos(iX,iY,1);
00479               unsigned int hiee = eedetidpos.hashedIndex();
00480               EcalPedestals::Item aped= ped_db->endcap(hiee);
00481 
00482               // here I copy the last valid value in the peds object
00483               EcalPedestals::Item item;
00484               item.mean_x1  = aped.mean_x1;
00485               item.rms_x1   = aped.rms_x1;
00486               item.mean_x6  = aped.mean_x6;
00487               item.rms_x6   = aped.rms_x6;
00488               item.mean_x12 = aped.mean_x12;
00489               item.rms_x12  = aped.rms_x12;
00490               peds->insert(std::make_pair(eedetidpos.rawId(),item));
00491               if(iX==ixmin && iY==iymin) std::cout<<"ped12 " << item.mean_x12<< std::endl;  
00492               
00493             }
00494           }
00495         }
00496         
00497 
00498         std::cout <<"WOW: we just retrieved the last valid record from DB "<< std::endl;
00499 
00500 
00501         // here we retrieve all the runs after the last from online DB 
00502 
00503         std::cout << "Retrieving run list from ONLINE DB ... " << std::endl;
00504         
00505         std::cout << "Making connection..." << std::flush;
00506         econn = new EcalCondDBInterface( m_sid, m_user, m_pass );
00507         std::cout << "Done." << std::endl;
00508 
00509         if (!econn)
00510           {
00511             std::cout << " connection parameters " <<m_sid <<"/"<<m_user<<"/"<<m_pass<<std::endl;
00512             throw cms::Exception("OMDS not available");
00513           } 
00514 
00515         // these are the online conditions DB classes 
00516         RunList my_runlist ;
00517         RunTag  my_runtag;
00518         LocationDef my_locdef;
00519         RunTypeDef my_rundef;
00520         
00521         my_locdef.setLocation("H2_07");
00522         my_rundef.setRunType("PEDESTAL");
00523         my_runtag.setLocationDef(my_locdef);
00524         my_runtag.setRunTypeDef(my_rundef);
00525         my_runtag.setGeneralTag("LOCAL");
00526         
00527 
00528       // here we retrieve the Monitoring run records
00529       
00530         MonVersionDef monverdef;
00531         monverdef.setMonitoringVersion("test01");
00532         
00533         MonRunTag mon_tag;
00534         mon_tag.setGeneralTag("CMSSW");
00535         mon_tag.setMonVersionDef(monverdef);
00536         MonRunList mon_list;
00537         mon_list.setMonRunTag(mon_tag);
00538         mon_list.setRunTag(my_runtag);
00539         //    mon_list=econn->fetchMonRunList(my_runtag, mon_tag);
00540         unsigned int min_run=max_since+1; // we have to add 1 to the last transferred one 
00541         
00542         unsigned int max_run=m_lastRun;
00543         mon_list=econn->fetchMonRunList(my_runtag, mon_tag,min_run,max_run );
00544       
00545         std::vector<MonRunIOV> mon_run_vec=  mon_list.getRuns();
00546         size_t mon_runs=mon_run_vec.size();
00547         std::cout <<"number of Mon runs is : "<< mon_runs<< std::endl;
00548 
00549         if(mon_runs>0){
00550 
00551           for(size_t kr=0; kr<mon_runs; kr++){
00552 
00553             unsigned int irun=static_cast<unsigned int>(mon_run_vec[kr].getRunIOV().getRunNumber());
00554           
00555             std::cout << "here is first sub run : "<< mon_run_vec[kr].getSubRunNumber() << std::endl;
00556             std::cout << "here is the run number: "<< mon_run_vec[kr].getRunIOV().getRunNumber() << std::endl;
00557           
00558             std::cout <<" retrieve the data for a given run"<< std::endl;
00559           
00560             if (mon_run_vec[kr].getSubRunNumber() <=1){ 
00561 
00562 
00563               // retrieve the data for a given run
00564               RunIOV runiov_prime = mon_run_vec[kr].getRunIOV();
00565               
00566               // retrieve the pedestals from OMDS for this run 
00567               std::map<EcalLogicID, MonPedestalsDat> dataset_mon;
00568               econn->fetchDataSet(&dataset_mon, &mon_run_vec[kr]);
00569               std::cout <<"OMDS record for run "<<irun  <<" is made of "<< dataset_mon.size() << std::endl;
00570               typedef std::map<EcalLogicID, MonPedestalsDat>::const_iterator CImon;
00571               EcalLogicID ecid_xt;
00572               MonPedestalsDat  rd_ped;
00573               
00574               //int iEta=0;
00575               //int iPhi=0;
00576               int ix=0;
00577               int iy=0;
00578               
00579               for (CImon p = dataset_mon.begin(); p != dataset_mon.end(); p++) {
00580                 ecid_xt = p->first;
00581                 rd_ped  = p->second;
00582                 //int sm_num=ecid_xt.getID1();
00583                 int xt_num=ecid_xt.getID2(); // careful here !!! we number the channels from 1 to 1700
00584                 
00585                 //iEta=(xt_num/20)+1;
00586                 //iPhi=20-(xt_num-(iEta-1)*20);
00587 
00588                 ix=95-(xt_num-1)/20;
00589                 iy=46+(xt_num-1)%20;
00590                 
00591 
00592                 EcalPedestals::Item item;
00593                 item.mean_x1  =rd_ped.getPedMeanG1() ;
00594                 item.rms_x1   =rd_ped.getPedRMSG1();
00595                 item.mean_x6  =rd_ped.getPedMeanG6();
00596                 item.rms_x6   =rd_ped.getPedRMSG6() ;
00597                 item.mean_x12 =rd_ped.getPedMeanG12();
00598                 item.rms_x12  =rd_ped.getPedRMSG12();
00599                 
00600                 EEDetId eedetidpos(ix,iy,1);
00601                 // EBDetId ebdetid(iEta,iPhi);
00602 
00603                 // here we change in the peds object only the values that are available in the online DB 
00604                 // otherwise we keep the old value 
00605                 
00606                 peds->insert(std::make_pair(eedetidpos.rawId(),item));
00607                 if(ix==ixmin && iy==iymin) std::cout<<"ped12 " << item.mean_x12<< std::endl;  
00608               }
00609             
00610               std::cout << "Generating popcon record for run " << irun << "..." << std::flush;
00611 
00612 
00613               // now I copy peds in pedtemp and I ship pedtemp to popcon
00614               // if I use always the same peds I always overwrite
00615               // so I really have to create new objects for each new run
00616               // popcon deletes everything for me 
00617 
00618               EcalPedestals* pedtemp = new EcalPedestals();
00619              
00620 
00621               for(int iX=ixmin; iX<=ixmax ;++iX) {
00622                 for(int iY=iymin; iY<=iymax; ++iY) {
00623                   
00624                   if (EEDetId::validDetId(iX,iY,1))
00625                     {
00626                       EEDetId eedetidpos(iX,iY,1);
00627                       unsigned int hiee = eedetidpos.hashedIndex();
00628                       EcalPedestals::Item aped = peds->endcap(hiee);
00629 
00630                       EcalPedestals::Item item;
00631                       item.mean_x1  = aped.mean_x1;
00632                       item.rms_x1   = aped.rms_x1;
00633                       item.mean_x6  = aped.mean_x6;
00634                       item.rms_x6   = aped.rms_x6;
00635                       item.mean_x12 = aped.mean_x12;
00636                       item.rms_x12  = aped.rms_x12;
00637                       // here I copy the last valid value in the pedtemp object
00638                       pedtemp->insert(std::make_pair(eedetidpos.rawId(),item));
00639                       if(iX==ixmin && iY==iymin) std::cout<<"ped12 " << item.mean_x12<< std::endl;  
00640                     }
00641                 }
00642               }
00643 
00644 
00645 
00646               Time_t snc= (Time_t) irun ;
00647                       
00648               m_to_transfer.push_back(std::make_pair((EcalPedestals*)pedtemp,snc));
00649               
00650               std::cout << "Ecal - > end of getNewObjectsH2 -----------\n";
00651 
00652               
00653               
00654             }
00655           }
00656           
00657         }
00658         
00659         
00660         delete econn;
00661         delete peds;  // this is the only one that popcon does not delete 
00662         
00663 }