Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:02:57

0001 #include "CondTools/Ecal/interface/EcalLaserHandler.h"
0002 
0003 #include "CondTools/Ecal/interface/EcalPedestalsHandler.h"
0004 #include "FWCore/ParameterSet/interface/ParameterSetfwd.h"
0005 
0006 #include <cstring>
0007 #include <iostream>
0008 #include <fstream>
0009 
0010 #include "TFile.h"
0011 #include "TTree.h"
0012 
0013 const Int_t kChannels = 75848, kEBChannels = 61200, kEEChannels = 14648, kGains = 3;
0014 const Int_t Nbpedxml = 81;  // Number of Gain1 Gain6 files in 2016 (26), 2017 (25), 2018 (30) : L1248 and L1600
0015 const Int_t gainValues[kGains] = {12, 6, 1};
0016 
0017 popcon::EcalPedestalsHandler::EcalPedestalsHandler(const edm::ParameterSet& ps)
0018     : m_name(ps.getUntrackedParameter<std::string>("name", "EcalPedestalsHandler")) {
0019   edm::LogInfo("EcalPedestals Source handler constructor\n");
0020   m_firstRun = static_cast<unsigned int>(atoi(ps.getParameter<std::string>("firstRun").c_str()));
0021   m_lastRun = static_cast<unsigned int>(atoi(ps.getParameter<std::string>("lastRun").c_str()));
0022   m_sid = ps.getParameter<std::string>("OnlineDBSID");
0023   m_user = ps.getParameter<std::string>("OnlineDBUser");
0024   m_pass = ps.getParameter<std::string>("OnlineDBPassword");
0025   m_locationsource = ps.getParameter<std::string>("LocationSource");
0026   m_location = ps.getParameter<std::string>("Location");
0027   m_gentag = ps.getParameter<std::string>("GenTag");
0028   m_runtag = ps.getParameter<std::string>("RunTag");
0029   m_filename = ps.getUntrackedParameter<std::string>("filename", "EcalPedestals.txt");
0030   m_runtype = ps.getUntrackedParameter<int>("RunType", 1);
0031   m_corrected = ps.getUntrackedParameter<bool>("corrected", false);
0032 
0033   edm::LogInfo("EcalPedestalsHandler") << m_sid << "/"
0034                                        << "/" << m_location << "/" << m_gentag;
0035 }
0036 
0037 popcon::EcalPedestalsHandler::~EcalPedestalsHandler() {}
0038 
0039 void popcon::EcalPedestalsHandler::getNewObjects() {
0040   edm::LogInfo("------- Ecal - > getNewObjects\n");
0041   if (m_locationsource == "P5") {
0042     getNewObjectsP5();
0043   } else if (m_locationsource == "H2") {
0044     getNewObjectsH2();
0045   } else if (m_locationsource == "File") {
0046     readPedestalFile();
0047   } else if (m_locationsource == "MC") {
0048     readPedestalMC();
0049   } else if (m_locationsource == "2017") {
0050     readPedestal2017();
0051   } else if (m_locationsource == "Tree") {
0052     readPedestalTree();
0053   } else if (m_locationsource == "Timestamp") {
0054     readPedestalTimestamp();
0055   } else {
0056     edm::LogInfo(" unknown location ") << m_locationsource << " give up ";
0057     exit(-1);
0058   }
0059 }
0060 
0061 bool popcon::EcalPedestalsHandler::checkPedestal(EcalPedestals::Item* item) {
0062   // true means all is standard and OK
0063   bool result = true;
0064   if (item->rms_x12 > 3 || item->rms_x12 <= 0)
0065     result = false;
0066   if (item->rms_x6 > 2 || item->rms_x6 <= 0)
0067     result = false;
0068   if (item->rms_x1 > 1 || item->rms_x1 <= 0)
0069     result = false;
0070   if (item->mean_x12 > 300 || item->mean_x12 <= 100)
0071     result = false;
0072   if (item->mean_x1 > 300 || item->mean_x1 <= 100)
0073     result = false;
0074   if (item->mean_x6 > 300 || item->mean_x6 <= 100)
0075     result = false;
0076   return result;
0077 }
0078 
0079 ////////////////////////////////////////////////////////////////////////////////////
0080 
0081 void popcon::EcalPedestalsHandler::getNewObjectsP5() {
0082   std::ostringstream ss;
0083   ss << "ECAL ";
0084 
0085   unsigned int max_since = 0;
0086   max_since = static_cast<unsigned int>(tagInfo().lastInterval.since);
0087   edm::LogInfo("max_since : ") << max_since;
0088   Ref ped_db = lastPayload();
0089 
0090   // we copy the last valid record to a temporary object peds
0091   EcalPedestals* peds = new EcalPedestals();
0092   edm::LogInfo("retrieved last payload ");
0093 
0094   for (int iEta = -EBDetId::MAX_IETA; iEta <= EBDetId::MAX_IETA; ++iEta) {
0095     if (iEta == 0)
0096       continue;
0097     for (int iPhi = EBDetId::MIN_IPHI; iPhi <= EBDetId::MAX_IPHI; ++iPhi) {
0098       // make an EBDetId since we need EBDetId::rawId() to be used as the key for the pedestals
0099       if (EBDetId::validDetId(iEta, iPhi)) {
0100         EBDetId ebdetid(iEta, iPhi, EBDetId::ETAPHIMODE);
0101         EcalPedestals::const_iterator it = ped_db->find(ebdetid.rawId());
0102         EcalPedestals::Item aped = (*it);
0103 
0104         // here I copy the last valid value in the peds object
0105         EcalPedestals::Item item;
0106         item.mean_x1 = aped.mean_x1;
0107         item.rms_x1 = aped.rms_x1;
0108         item.mean_x6 = aped.mean_x6;
0109         item.rms_x6 = aped.rms_x6;
0110         item.mean_x12 = aped.mean_x12;
0111         item.rms_x12 = aped.rms_x12;
0112 
0113         peds->insert(std::make_pair(ebdetid.rawId(), item));
0114       }
0115     }
0116   }
0117 
0118   for (int iX = EEDetId::IX_MIN; iX <= EEDetId::IX_MAX; ++iX) {
0119     for (int iY = EEDetId::IY_MIN; iY <= EEDetId::IY_MAX; ++iY) {
0120       // make an EEDetId since we need EEDetId::rawId() to be used as the key for the pedestals
0121       if (EEDetId::validDetId(iX, iY, 1)) {
0122         EEDetId eedetidpos(iX, iY, 1);
0123 
0124         EcalPedestals::const_iterator it = ped_db->find(eedetidpos.rawId());
0125         EcalPedestals::Item aped = (*it);
0126 
0127         //  unsigned int hiee = eedetidpos.hashedIndex();
0128         //  EcalPedestals::Item aped= ped_db->endcap(hiee);
0129 
0130         // here I copy the last valid value in the peds object
0131         EcalPedestals::Item item;
0132         item.mean_x1 = aped.mean_x1;
0133         item.rms_x1 = aped.rms_x1;
0134         item.mean_x6 = aped.mean_x6;
0135         item.rms_x6 = aped.rms_x6;
0136         item.mean_x12 = aped.mean_x12;
0137         item.rms_x12 = aped.rms_x12;
0138         peds->insert(std::make_pair(eedetidpos.rawId(), item));
0139       }
0140       if (EEDetId::validDetId(iX, iY, -1)) {
0141         EEDetId eedetidneg(iX, iY, -1);
0142 
0143         EcalPedestals::const_iterator it = ped_db->find(eedetidneg.rawId());
0144         EcalPedestals::Item aped = (*it);
0145         //     unsigned int hiee = eedetidneg.hashedIndex();
0146         //     EcalPedestals::Item aped= ped_db->endcap(hiee);
0147 
0148         // here I copy the last valid value in the peds object
0149         EcalPedestals::Item item;
0150         item.mean_x1 = aped.mean_x1;
0151         item.rms_x1 = aped.rms_x1;
0152         item.mean_x6 = aped.mean_x6;
0153         item.rms_x6 = aped.rms_x6;
0154         item.mean_x12 = aped.mean_x12;
0155         item.rms_x12 = aped.rms_x12;
0156         peds->insert(std::make_pair(eedetidneg.rawId(), item));
0157       }
0158     }
0159   }
0160 
0161   // here we retrieve all the runs after the last from online DB
0162 
0163   edm::LogInfo("Retrieving run list from ONLINE DB ... ");
0164   econn = new EcalCondDBInterface(m_sid, m_user, m_pass);
0165   edm::LogInfo("Connection done");
0166 
0167   // these are the online conditions DB classes
0168   RunList my_runlist;
0169   RunTag my_runtag;
0170   LocationDef my_locdef;
0171   RunTypeDef my_rundef;
0172 
0173   my_locdef.setLocation(m_location);
0174   //    my_rundef.setRunType("PEDESTAL");  // 2017
0175   my_rundef.setRunType(m_runtag);
0176   my_runtag.setLocationDef(my_locdef);
0177   my_runtag.setRunTypeDef(my_rundef);
0178   my_runtag.setGeneralTag(m_gentag);
0179 
0180   // here we retrieve the Monitoring run records
0181 
0182   MonVersionDef monverdef;
0183   monverdef.setMonitoringVersion("test01");
0184 
0185   MonRunTag mon_tag;
0186   //    mon_tag.setGeneralTag("CMSSW");
0187   mon_tag.setGeneralTag("CMSSW-offline-private");
0188   mon_tag.setMonVersionDef(monverdef);
0189   MonRunList mon_list;
0190   mon_list.setMonRunTag(mon_tag);
0191   mon_list.setRunTag(my_runtag);
0192   //    mon_list=econn->fetchMonRunList(my_runtag, mon_tag);
0193   unsigned int min_run = 0;
0194   if (m_firstRun < max_since) {
0195     min_run = max_since + 1;  // we have to add 1 to the last transferred one
0196   } else {
0197     min_run = m_firstRun;
0198   }
0199 
0200   unsigned int max_run = m_lastRun;
0201   mon_list = econn->fetchMonRunList(my_runtag, mon_tag, min_run, max_run);
0202 
0203   std::vector<MonRunIOV> mon_run_vec = mon_list.getRuns();
0204   int mon_runs = mon_run_vec.size();
0205   edm::LogInfo("number of Mon runs is : ") << mon_runs;
0206 
0207   if (mon_runs > 0) {
0208     int krmax = std::min(mon_runs, 30);
0209     for (int kr = 0; kr < krmax; kr++) {
0210       edm::LogInfo("-kr------:  ") << kr;
0211 
0212       unsigned int irun = static_cast<unsigned int>(mon_run_vec[kr].getRunIOV().getRunNumber());
0213       edm::LogInfo("retrieve the data for run number: ") << mon_run_vec[kr].getRunIOV().getRunNumber();
0214       if (mon_run_vec[kr].getSubRunNumber() <= 1) {
0215         // retrieve the data for a given run
0216         RunIOV runiov_prime = mon_run_vec[kr].getRunIOV();
0217         // retrieve the pedestals from OMDS for this run
0218         std::map<EcalLogicID, MonPedestalsDat> dataset_mon;
0219         econn->fetchDataSet(&dataset_mon, &mon_run_vec[kr]);
0220         edm::LogInfo("OMDS record for run ") << irun << " is made of " << dataset_mon.size();
0221         int nEB = 0, nEE = 0;
0222         typedef std::map<EcalLogicID, MonPedestalsDat>::const_iterator CImon;
0223         EcalLogicID ecid_xt;
0224         MonPedestalsDat rd_ped;
0225 
0226         // this to validate ...
0227         int nbad = 0;
0228         for (CImon p = dataset_mon.begin(); p != dataset_mon.end(); p++) {
0229           ecid_xt = p->first;
0230           rd_ped = p->second;
0231           int sm_num = ecid_xt.getID1();
0232           int xt_num = ecid_xt.getID2();
0233           int yt_num = ecid_xt.getID3();
0234 
0235           EcalPedestals::Item item;
0236           item.mean_x1 = rd_ped.getPedMeanG1();
0237           item.rms_x1 = rd_ped.getPedRMSG1();
0238           item.mean_x6 = rd_ped.getPedMeanG6();
0239           item.rms_x6 = rd_ped.getPedRMSG6();
0240           item.mean_x12 = rd_ped.getPedMeanG12();
0241           item.rms_x12 = rd_ped.getPedRMSG12();
0242           /*    
0243       if(irun != 280216 && irun != 280218 && irun != 280259 && irun != 280261 && irun != 280392 && irun != 280394
0244          && irun != 280762 && irun != 280765 && irun != 280936 && irun != 280939 && irun != 281756 && irun != 281757) {
0245       */
0246           if (ecid_xt.getName() == "EB_crystal_number") {
0247             nEB++;
0248           } else {
0249             nEE++;
0250           }
0251 
0252           // here we check and count how many bad channels we have
0253 
0254           if (!checkPedestal(&item)) {
0255             nbad++;
0256             if (nbad < 10)
0257               std::cout << "BAD LIST: channel " << sm_num << "/" << xt_num << "/" << yt_num << "ped/rms "
0258                         << item.mean_x12 << "/" << item.rms_x12 << std::endl;
0259           }
0260           /*
0261       }
0262       else {      // only gain 12 in these runs
0263         if(ecid_xt.getName()=="EB_crystal_number") {
0264           nEB++;
0265           if(item.mean_x12 <= 100 || item.mean_x12 > 300 || item.rms_x12 > 3 || item.rms_x12 <= 0) {
0266         nbad++;
0267         nEBbad++;
0268           }
0269         }
0270         else {
0271           nEE++;
0272           if(item.mean_x12 <= 100 || item.mean_x12 > 300 || item.rms_x12 > 3 || item.rms_x12 <= 0) {
0273         nbad++;
0274         nEEbad++;
0275           }
0276         }
0277       }    //    only gain 12 in these runs
0278         */
0279         }  // loop over all channels
0280 
0281         // ok or bad?
0282         // a bad run is for more than 5% bad channels
0283 
0284         //        if(nbad<(dataset_mon.size()*0.1)){
0285         if (nbad < (dataset_mon.size() * 0.05) && (nEB > 10200 || nEE > 2460)) {
0286           for (CImon p = dataset_mon.begin(); p != dataset_mon.end(); p++) {
0287             ecid_xt = p->first;
0288             rd_ped = p->second;
0289             int sm_num = ecid_xt.getID1();
0290             int xt_num = ecid_xt.getID2();
0291             int yt_num = ecid_xt.getID3();
0292 
0293             EcalPedestals::Item item;
0294             item.mean_x1 = rd_ped.getPedMeanG1();
0295             item.rms_x1 = rd_ped.getPedRMSG1();
0296             item.mean_x6 = rd_ped.getPedMeanG6();
0297             item.rms_x6 = rd_ped.getPedRMSG6();
0298             item.mean_x12 = rd_ped.getPedMeanG12();
0299             item.rms_x12 = rd_ped.getPedRMSG12();
0300 
0301             if (ecid_xt.getName() == "EB_crystal_number") {
0302               // Barrel channel
0303               EBDetId ebdetid(sm_num, xt_num, EBDetId::SMCRYSTALMODE);
0304 
0305               // individual objects check
0306               if (item.mean_x1 == -1 || item.rms_x1 == -1 || item.mean_x6 == -1 || item.rms_x6 == -1 ||
0307                   item.mean_x12 == -1 || item.rms_x12 == -1 || item.mean_x1 == 0 || item.rms_x1 == 0 ||
0308                   item.mean_x6 == 0 || item.rms_x6 == 0 || item.mean_x12 == 0 || item.rms_x12 == 0) {
0309                 // if one is bad we
0310                 // retrieve the old valid value
0311                 unsigned int hieb = ebdetid.hashedIndex();
0312                 EcalPedestals::Item previous_ped = peds->barrel(hieb);
0313                 if (item.mean_x1 == -1 || item.mean_x1 == 0)
0314                   item.mean_x1 = previous_ped.mean_x1;
0315                 if (item.rms_x1 == -1 || item.rms_x1 == 0)
0316                   item.rms_x1 = previous_ped.rms_x1;
0317                 if (item.mean_x6 == -1 || item.mean_x6 == 0)
0318                   item.mean_x6 = previous_ped.mean_x6;
0319                 if (item.rms_x6 == -1 || item.rms_x6 == 0)
0320                   item.rms_x6 = previous_ped.rms_x6;
0321                 if (item.mean_x12 == -1 || item.mean_x12 == 0)
0322                   item.mean_x12 = previous_ped.mean_x12;
0323                 if (item.rms_x12 == -1 || item.rms_x12 == 0)
0324                   item.rms_x12 = previous_ped.rms_x12;
0325               }
0326 
0327               // here we change in the peds object only the channels that are available in the online DB
0328               // otherwise we keep the previous value
0329               peds->insert(std::make_pair(ebdetid.rawId(), item));
0330             } else {
0331               // Endcap channel
0332               // in this case xt_num is x
0333               // yt_num is y and sm_num is the side +/- 1
0334               if (EEDetId::validDetId(xt_num, yt_num, sm_num)) {
0335                 EEDetId eedetid(xt_num, yt_num, sm_num);
0336 
0337                 // individual objects check
0338                 if (item.mean_x1 == -1 || item.rms_x1 == -1 || item.mean_x6 == -1 || item.rms_x6 == -1 ||
0339                     item.mean_x12 == -1 || item.rms_x12 == -1 || item.mean_x1 == 0 || item.rms_x1 == 0 ||
0340                     item.mean_x6 == 0 || item.rms_x6 == 0 || item.mean_x12 == 0 || item.rms_x12 == 0) {
0341                   // if one is bad we
0342                   // retrieve the old valid value
0343                   unsigned int hiee = eedetid.hashedIndex();
0344                   EcalPedestals::Item previous_ped = peds->endcap(hiee);
0345                   if (item.mean_x1 == -1 || item.mean_x1 == 0)
0346                     item.mean_x1 = previous_ped.mean_x1;
0347                   if (item.rms_x1 == -1 || item.rms_x1 == 0)
0348                     item.rms_x1 = previous_ped.rms_x1;
0349                   if (item.mean_x6 == -1 || item.mean_x6 == 0)
0350                     item.mean_x6 = previous_ped.mean_x6;
0351                   if (item.rms_x6 == -1 || item.rms_x6 == 0)
0352                     item.rms_x6 = previous_ped.rms_x6;
0353                   if (item.mean_x12 == -1 || item.mean_x12 == 0)
0354                     item.mean_x12 = previous_ped.mean_x12;
0355                   if (item.rms_x12 == -1 || item.rms_x12 == 0)
0356                     item.rms_x12 = previous_ped.rms_x12;
0357                 }
0358                 // here we change in the peds object only the channels that are available in the online DB
0359                 // otherwise we keep the previous value
0360                 peds->insert(std::make_pair(eedetid.rawId(), item));
0361               }
0362             }
0363           }
0364 
0365           edm::LogInfo("Generating popcon record for run ") << irun << "..." << std::flush;
0366           // now I copy peds in pedtemp and I ship pedtemp to popcon
0367           // if I use always the same peds I always overwrite
0368           // so I really have to create new objects for each new run
0369           // popcon deletes everything for me
0370 
0371           EcalPedestals* pedtemp = new EcalPedestals();
0372           for (int iEta = -EBDetId::MAX_IETA; iEta <= EBDetId::MAX_IETA; ++iEta) {
0373             if (iEta == 0)
0374               continue;
0375             for (int iPhi = EBDetId::MIN_IPHI; iPhi <= EBDetId::MAX_IPHI; ++iPhi) {
0376               // make an EBDetId since we need EBDetId::rawId() to be used as the key for the pedestals
0377               if (EBDetId::validDetId(iEta, iPhi)) {
0378                 EBDetId ebdetid(iEta, iPhi);
0379                 unsigned int hiee = ebdetid.hashedIndex();
0380                 EcalPedestals::Item aped = peds->barrel(hiee);
0381 
0382                 // here I copy the last valid value in the peds object
0383                 EcalPedestals::Item item;
0384                 item.mean_x1 = aped.mean_x1;
0385                 item.rms_x1 = aped.rms_x1;
0386                 item.mean_x6 = aped.mean_x6;
0387                 item.rms_x6 = aped.rms_x6;
0388                 item.mean_x12 = aped.mean_x12;
0389                 item.rms_x12 = aped.rms_x12;
0390                 // here I copy the last valid value in the pedtemp object
0391                 pedtemp->insert(std::make_pair(ebdetid.rawId(), item));
0392                 if ((iEta == -1 || iEta == 1) && iPhi == 20) {
0393                   float x = aped.mean_x12;
0394                   edm::LogInfo("channel:") << iEta << "/" << iPhi << "/" << hiee << " ped mean 12=" << x;
0395                 }
0396               }
0397             }
0398           }
0399           // endcaps
0400           for (int iX = EEDetId::IX_MIN; iX <= EEDetId::IX_MAX; ++iX) {
0401             for (int iY = EEDetId::IY_MIN; iY <= EEDetId::IY_MAX; ++iY) {
0402               // make an EEDetId since we need EEDetId::rawId() to be used as the key for the pedestals
0403               if (EEDetId::validDetId(iX, iY, 1)) {
0404                 EEDetId eedetid(iX, iY, 1);
0405                 unsigned int hiee = eedetid.hashedIndex();
0406                 EcalPedestals::Item aped = peds->endcap(hiee);
0407                 // here I copy the last valid value in the peds object
0408                 EcalPedestals::Item item;
0409                 item.mean_x1 = aped.mean_x1;
0410                 item.rms_x1 = aped.rms_x1;
0411                 item.mean_x6 = aped.mean_x6;
0412                 item.rms_x6 = aped.rms_x6;
0413                 item.mean_x12 = aped.mean_x12;
0414                 item.rms_x12 = aped.rms_x12;
0415                 // here I copy the last valid value in the pedtemp object
0416                 pedtemp->insert(std::make_pair(eedetid.rawId(), item));
0417               }
0418               if (EEDetId::validDetId(iX, iY, -1)) {
0419                 EEDetId eedetid(iX, iY, -1);
0420                 unsigned int hiee = eedetid.hashedIndex();
0421                 EcalPedestals::Item aped = peds->endcap(hiee);
0422                 // here I copy the last valid value in the peds object
0423                 EcalPedestals::Item item;
0424                 item.mean_x1 = aped.mean_x1;
0425                 item.rms_x1 = aped.rms_x1;
0426                 item.mean_x6 = aped.mean_x6;
0427                 item.rms_x6 = aped.rms_x6;
0428                 item.mean_x12 = aped.mean_x12;
0429                 item.rms_x12 = aped.rms_x12;
0430                 // here I copy the last valid value in the pedtemp object
0431                 pedtemp->insert(std::make_pair(eedetid.rawId(), item));
0432               }
0433             }
0434           }
0435 
0436           Time_t snc = (Time_t)irun;
0437           m_to_transfer.push_back(std::make_pair((EcalPedestals*)pedtemp, snc));
0438 
0439           ss << "Run=" << irun << "_WAS_GOOD_" << std::endl;
0440           m_userTextLog = ss.str() + ";";
0441         }  // good run : write in DB
0442         else {
0443           edm::LogInfo("Run ") << irun << " was BAD !!!! not sent to the DB";
0444           if (nbad >= (dataset_mon.size() * 0.05))
0445             edm::LogInfo(" number of bad channels = ") << nbad;
0446           if (nEB <= 10200)
0447             edm::LogInfo(" number of EB channels = ") << nEB;
0448           if (nEE <= 2440)
0449             edm::LogInfo(" number of EE channels = ") << nEE;
0450           ss << "Run=" << irun << "_WAS_BAD_" << std::endl;
0451           m_userTextLog = ss.str() + ";";
0452         }  //  bad run : do not write in DB
0453       }    //  SubRunNumber
0454     }      // loop over runs
0455 
0456     delete econn;
0457     delete peds;  // this is the only one that popcon does not delete
0458   }               // runs to analyze ?
0459   edm::LogInfo("Ecal - > end of getNewObjects -----------\n");
0460 }
0461 
0462 ////////////////////////////////////////////////////////////////////////////////////
0463 
0464 void popcon::EcalPedestalsHandler::getNewObjectsH2() {
0465   unsigned int max_since = 0;
0466   max_since = static_cast<unsigned int>(tagInfo().lastInterval.since);
0467   edm::LogInfo("max_since : ") << max_since;
0468   Ref ped_db = lastPayload();
0469 
0470   edm::LogInfo("retrieved last payload ");
0471 
0472   // we copy the last valid record to a temporary object peds
0473   EcalPedestals* peds = new EcalPedestals();
0474 
0475   // get from offline DB the last valid pedestal set ped_db
0476   //    edm::ESHandle<EcalPedestals> pedestals;
0477   //    esetup.get<EcalPedestalsRcd>().get(pedestals);
0478 
0479   // only positive endcap side and
0480   // x from 86 to 95
0481   // y from 46 to 55
0482   int ixmin = 86;
0483   int ixmax = 95;
0484   int iymin = 46;
0485   int iymax = 55;
0486   for (int iX = ixmin; iX <= ixmax; ++iX) {
0487     for (int iY = iymin; iY <= iymax; ++iY) {
0488       if (EEDetId::validDetId(iX, iY, 1)) {
0489         EEDetId eedetidpos(iX, iY, 1);
0490         unsigned int hiee = eedetidpos.hashedIndex();
0491         EcalPedestals::Item aped = ped_db->endcap(hiee);
0492 
0493         // here I copy the last valid value in the peds object
0494         EcalPedestals::Item item;
0495         item.mean_x1 = aped.mean_x1;
0496         item.rms_x1 = aped.rms_x1;
0497         item.mean_x6 = aped.mean_x6;
0498         item.rms_x6 = aped.rms_x6;
0499         item.mean_x12 = aped.mean_x12;
0500         item.rms_x12 = aped.rms_x12;
0501         peds->insert(std::make_pair(eedetidpos.rawId(), item));
0502         if (iX == ixmin && iY == iymin)
0503           std::cout << "ped12 " << item.mean_x12 << std::endl;
0504       }
0505     }
0506   }
0507 
0508   edm::LogInfo("We just retrieved the last valid record from DB ");
0509 
0510   // here we retrieve all the runs after the last from online DB
0511 
0512   edm::LogInfo("Retrieving run list from ONLINE DB ... ");
0513 
0514   edm::LogInfo("Making connection...") << std::flush;
0515   econn = new EcalCondDBInterface(m_sid, m_user, m_pass);
0516   edm::LogInfo("Done.");
0517 
0518   if (!econn) {
0519     edm::LogInfo(" connection parameters ") << m_sid;
0520     throw cms::Exception("OMDS not available");
0521   }
0522 
0523   // these are the online conditions DB classes
0524   RunList my_runlist;
0525   RunTag my_runtag;
0526   LocationDef my_locdef;
0527   RunTypeDef my_rundef;
0528 
0529   my_locdef.setLocation("H2_07");
0530   my_rundef.setRunType("PEDESTAL");
0531   my_runtag.setLocationDef(my_locdef);
0532   my_runtag.setRunTypeDef(my_rundef);
0533   my_runtag.setGeneralTag("LOCAL");
0534 
0535   // here we retrieve the Monitoring run records
0536 
0537   MonVersionDef monverdef;
0538   monverdef.setMonitoringVersion("test01");
0539 
0540   MonRunTag mon_tag;
0541   mon_tag.setGeneralTag("CMSSW");
0542   mon_tag.setMonVersionDef(monverdef);
0543   MonRunList mon_list;
0544   mon_list.setMonRunTag(mon_tag);
0545   mon_list.setRunTag(my_runtag);
0546   //    mon_list=econn->fetchMonRunList(my_runtag, mon_tag);
0547   unsigned int min_run = max_since + 1;  // we have to add 1 to the last transferred one
0548 
0549   unsigned int max_run = m_lastRun;
0550   mon_list = econn->fetchMonRunList(my_runtag, mon_tag, min_run, max_run);
0551 
0552   std::vector<MonRunIOV> mon_run_vec = mon_list.getRuns();
0553   size_t mon_runs = mon_run_vec.size();
0554   edm::LogInfo("number of Mon runs is : ") << mon_runs;
0555 
0556   if (mon_runs > 0) {
0557     for (size_t kr = 0; kr < mon_runs; kr++) {
0558       unsigned int irun = static_cast<unsigned int>(mon_run_vec[kr].getRunIOV().getRunNumber());
0559 
0560       edm::LogInfo("here is first sub run : ") << mon_run_vec[kr].getSubRunNumber();
0561       edm::LogInfo("here is the run number: ") << mon_run_vec[kr].getRunIOV().getRunNumber();
0562 
0563       edm::LogInfo(" retrieve the data for a given run");
0564 
0565       if (mon_run_vec[kr].getSubRunNumber() <= 1) {
0566         // retrieve the data for a given run
0567         RunIOV runiov_prime = mon_run_vec[kr].getRunIOV();
0568 
0569         // retrieve the pedestals from OMDS for this run
0570         std::map<EcalLogicID, MonPedestalsDat> dataset_mon;
0571         econn->fetchDataSet(&dataset_mon, &mon_run_vec[kr]);
0572         std::cout << "OMDS record for run " << irun << " is made of " << dataset_mon.size() << std::endl;
0573         typedef std::map<EcalLogicID, MonPedestalsDat>::const_iterator CImon;
0574         EcalLogicID ecid_xt;
0575         MonPedestalsDat rd_ped;
0576 
0577         //int iEta=0;
0578         //int iPhi=0;
0579         int ix = 0;
0580         int iy = 0;
0581 
0582         for (CImon p = dataset_mon.begin(); p != dataset_mon.end(); p++) {
0583           ecid_xt = p->first;
0584           rd_ped = p->second;
0585           //int sm_num=ecid_xt.getID1();
0586           int xt_num = ecid_xt.getID2();  // careful here !!! we number the channels from 1 to 1700
0587 
0588           //iEta=(xt_num/20)+1;
0589           //iPhi=20-(xt_num-(iEta-1)*20);
0590 
0591           ix = 95 - (xt_num - 1) / 20;
0592           iy = 46 + (xt_num - 1) % 20;
0593 
0594           EcalPedestals::Item item;
0595           item.mean_x1 = rd_ped.getPedMeanG1();
0596           item.rms_x1 = rd_ped.getPedRMSG1();
0597           item.mean_x6 = rd_ped.getPedMeanG6();
0598           item.rms_x6 = rd_ped.getPedRMSG6();
0599           item.mean_x12 = rd_ped.getPedMeanG12();
0600           item.rms_x12 = rd_ped.getPedRMSG12();
0601 
0602           EEDetId eedetidpos(ix, iy, 1);
0603           // EBDetId ebdetid(iEta,iPhi);
0604 
0605           // here we change in the peds object only the values that are available in the online DB
0606           // otherwise we keep the old value
0607 
0608           peds->insert(std::make_pair(eedetidpos.rawId(), item));
0609           if (ix == ixmin && iy == iymin)
0610             std::cout << "ped12 " << item.mean_x12 << std::endl;
0611         }
0612 
0613         edm::LogInfo("Generating popcon record for run ") << irun << "..." << std::flush;
0614 
0615         // now I copy peds in pedtemp and I ship pedtemp to popcon
0616         // if I use always the same peds I always overwrite
0617         // so I really have to create new objects for each new run
0618         // popcon deletes everything for me
0619 
0620         EcalPedestals* pedtemp = new EcalPedestals();
0621 
0622         for (int iX = ixmin; iX <= ixmax; ++iX) {
0623           for (int iY = iymin; iY <= iymax; ++iY) {
0624             if (EEDetId::validDetId(iX, iY, 1)) {
0625               EEDetId eedetidpos(iX, iY, 1);
0626               unsigned int hiee = eedetidpos.hashedIndex();
0627               EcalPedestals::Item aped = peds->endcap(hiee);
0628 
0629               EcalPedestals::Item item;
0630               item.mean_x1 = aped.mean_x1;
0631               item.rms_x1 = aped.rms_x1;
0632               item.mean_x6 = aped.mean_x6;
0633               item.rms_x6 = aped.rms_x6;
0634               item.mean_x12 = aped.mean_x12;
0635               item.rms_x12 = aped.rms_x12;
0636               // here I copy the last valid value in the pedtemp object
0637               pedtemp->insert(std::make_pair(eedetidpos.rawId(), item));
0638               if (iX == ixmin && iY == iymin)
0639                 std::cout << "ped12 " << item.mean_x12 << std::endl;
0640             }
0641           }
0642         }
0643 
0644         Time_t snc = (Time_t)irun;
0645 
0646         m_to_transfer.push_back(std::make_pair((EcalPedestals*)pedtemp, snc));
0647 
0648         edm::LogInfo("Ecal - > end of getNewObjectsH2 -----------\n");
0649       }
0650     }
0651   }
0652   delete econn;
0653   delete peds;  // this is the only one that popcon does not delete
0654 }
0655 //////////////////////////////////////////////////////////////////////////////////////
0656 
0657 void popcon::EcalPedestalsHandler::readPedestalFile() {
0658   edm::LogInfo(" reading the input file ") << m_filename;
0659   std::ifstream fInput;
0660   fInput.open(m_filename);
0661   if (!fInput.is_open()) {
0662     edm::LogInfo("ERROR : cannot open file ") << m_filename;
0663     exit(1);
0664   }
0665   //  string pos, dummyLine;
0666   int hashedId;
0667   float EBmean12[kEBChannels], EBrms12[kEBChannels], EBmean6[kEBChannels], EBrms6[kEBChannels], EBmean1[kEBChannels],
0668       EBrms1[kEBChannels];
0669   //*****************  barrel
0670   //  getline(fInput, dummyLine);   // skip first line
0671   for (int iChannel = 0; iChannel < kEBChannels; iChannel++) {
0672     fInput >> hashedId >> EBmean12[iChannel] >> EBrms12[iChannel] >> EBmean6[iChannel] >> EBrms6[iChannel] >>
0673         EBmean1[iChannel] >> EBrms1[iChannel];
0674     if (hashedId != iChannel + 1) {
0675       edm::LogInfo("File") << m_filename << " strange hash " << hashedId << " while iChannel " << iChannel;
0676       exit(-1);
0677     }
0678   }
0679 
0680   // ***************** now EE *****************
0681   float EEmean12[kEEChannels], EErms12[kEEChannels], EEmean6[kEEChannels], EErms6[kEEChannels], EEmean1[kEEChannels],
0682       EErms1[kEEChannels];
0683   for (int iChannel = 0; iChannel < kEEChannels; iChannel++) {
0684     fInput >> hashedId >> EEmean12[iChannel] >> EErms12[iChannel] >> EEmean6[iChannel] >> EErms6[iChannel] >>
0685         EEmean1[iChannel] >> EErms1[iChannel];
0686     if (hashedId != iChannel + kEBChannels + 1) {
0687       edm::LogInfo("File") << m_filename << " strange hash " << hashedId << " while iChannel " << iChannel;
0688       exit(-1);
0689     }
0690   }
0691   fInput.close();
0692 
0693   EcalPedestals* ped = new EcalPedestals();
0694   // barrel
0695   for (int iEta = -EBDetId::MAX_IETA; iEta <= EBDetId::MAX_IETA; ++iEta) {
0696     if (iEta == 0)
0697       continue;
0698     for (int iPhi = EBDetId::MIN_IPHI; iPhi <= EBDetId::MAX_IPHI; ++iPhi) {
0699       if (EBDetId::validDetId(iEta, iPhi)) {
0700         EBDetId ebdetid(iEta, iPhi);
0701         unsigned int hieb = ebdetid.hashedIndex();
0702         EcalPedestals::Item item;
0703         item.mean_x1 = EBmean1[hieb];
0704         item.rms_x1 = EBrms1[hieb];
0705         item.mean_x6 = EBmean6[hieb];
0706         item.rms_x6 = EBrms6[hieb];
0707         item.mean_x12 = EBmean12[hieb];
0708         item.rms_x12 = EBrms12[hieb];
0709         ped->insert(std::make_pair(ebdetid.rawId(), item));
0710       }  // valid EBId
0711     }    //  loop over phi
0712   }      //   loop over eta
0713   // endcaps
0714   //  std::ofstream fout;
0715   //  fout.open("Pedestal.check");
0716   for (int iz = -1; iz < 2; iz = iz + 2) {  // z : -1 and +1
0717     for (int iX = EEDetId::IX_MIN; iX <= EEDetId::IX_MAX; ++iX) {
0718       for (int iY = EEDetId::IY_MIN; iY <= EEDetId::IY_MAX; ++iY) {
0719         if (EEDetId::validDetId(iX, iY, iz)) {
0720           EEDetId eedetid(iX, iY, iz);
0721           unsigned int hiee = eedetid.hashedIndex();
0722           //      fout << hiee << " mean 12 " << EEmean12[hiee] << std::endl;
0723           EcalPedestals::Item item;
0724           item.mean_x1 = EEmean1[hiee];
0725           item.rms_x1 = EErms1[hiee];
0726           item.mean_x6 = EEmean6[hiee];
0727           item.rms_x6 = EErms6[hiee];
0728           item.mean_x12 = EEmean12[hiee];
0729           item.rms_x12 = EErms12[hiee];
0730           ped->insert(std::make_pair(eedetid.rawId(), item));
0731         }  // val EEId
0732       }    //  loop over y
0733     }      //   loop over x
0734   }        //   loop over z
0735   //  fout.close();
0736 
0737   unsigned int irun = m_firstRun;
0738   Time_t snc = (Time_t)irun;
0739   m_to_transfer.push_back(std::make_pair((EcalPedestals*)ped, snc));
0740 
0741   edm::LogInfo("Ecal - > end of readPedestalFile -----------\n");
0742 }
0743 //////////////////////////////////////////////////////////////////////////////
0744 
0745 void popcon::EcalPedestalsHandler::readPedestalMC() {
0746   edm::LogInfo(" reading the input file ") << m_filename;
0747   std::ifstream fxml;
0748   fxml.open(m_filename);
0749   if (!fxml.is_open()) {
0750     edm::LogInfo("ERROR : cannot open file ") << m_filename;
0751     exit(1);
0752   }
0753   std::ofstream fout;
0754   fout.open("Pedestal.check");
0755   //  int hashedId;
0756   float EBmean12[kEBChannels], EBrms12[kEBChannels], EBmean6[kEBChannels], EBrms6[kEBChannels], EBmean1[kEBChannels],
0757       EBrms1[kEBChannels];
0758   //  int ringEB[kEBChannels], ringEE[kEEChannels];
0759   double RingMean[28][2][3], RingRMS[28][2][3];
0760   int NbVal[28][2][3];
0761   for (int ring = 0; ring < 28; ring++) {
0762     for (int side = 0; side < 2; side++) {
0763       for (int igain = 0; igain < kGains; igain++) {
0764         RingMean[ring][side][igain] = 0.;
0765         RingRMS[ring][side][igain] = 0.;
0766         NbVal[ring][side][igain] = 0;
0767       }
0768     }
0769   }
0770   std::string dummyLine, mean12, rms12, bid;
0771   for (int i = 0; i < 9; i++)
0772     std::getline(fxml, dummyLine);  // skip first lines
0773   // Barrel
0774   for (int iEBChannel = 0; iEBChannel < kEBChannels; iEBChannel++) {
0775     EBDetId ebdetid = EBDetId::unhashIndex(iEBChannel);
0776     int ieta = ebdetid.ieta();
0777     int ring = (abs(ieta) - 1) / 5;
0778     if (ring < 0 || ring > 16)
0779       edm::LogInfo("EB channel ") << iEBChannel << " ring " << ring;
0780     int izz = 0;
0781     if (ieta > 0)
0782       izz = 1;
0783     fxml >> bid;
0784     std::string stt = bid.substr(10, 15);
0785     std::istringstream m12(stt);
0786     m12 >> EBmean12[iEBChannel];
0787     fxml >> bid;
0788     stt = bid.substr(9, 15);
0789     std::istringstream r12(stt);
0790     r12 >> EBrms12[iEBChannel];
0791     if (EBrms12[iEBChannel] != 0. && EBrms12[iEBChannel] < 5.) {
0792       RingMean[ring][izz][0] += EBrms12[iEBChannel];
0793       RingRMS[ring][izz][0] += EBrms12[iEBChannel] * EBrms12[iEBChannel];
0794       NbVal[ring][izz][0]++;
0795     }
0796     fxml >> bid;
0797     stt = bid.substr(9, 15);
0798     std::istringstream m6(stt);
0799     m6 >> EBmean6[iEBChannel];
0800     fxml >> bid;
0801     stt = bid.substr(8, 15);
0802     std::istringstream r6(stt);
0803     r6 >> EBrms6[iEBChannel];
0804     if (EBrms6[iEBChannel] != 0. && EBrms6[iEBChannel] < 5.) {
0805       RingMean[ring][izz][1] += EBrms6[iEBChannel];
0806       RingRMS[ring][izz][1] += EBrms6[iEBChannel] * EBrms6[iEBChannel];
0807       NbVal[ring][izz][1]++;
0808     }
0809     fxml >> bid;
0810     stt = bid.substr(9, 15);
0811     std::istringstream m1(stt);
0812     m1 >> EBmean1[iEBChannel];
0813     fxml >> bid;
0814     stt = bid.substr(8, 15);
0815     std::istringstream r1(stt);
0816     r1 >> EBrms1[iEBChannel];
0817     if (EBrms1[iEBChannel] != 0. && EBrms1[iEBChannel] < 5.) {
0818       RingMean[ring][izz][2] += EBrms1[iEBChannel];
0819       RingRMS[ring][izz][2] += EBrms1[iEBChannel] * EBrms1[iEBChannel];
0820       NbVal[ring][izz][2]++;
0821     }
0822     if (iEBChannel % 10000 == 0)
0823       fout << " EB channel " << iEBChannel << " " << EBmean12[iEBChannel] << " " << EBrms12[iEBChannel] << " "
0824            << EBmean6[iEBChannel] << " " << EBrms6[iEBChannel] << " " << EBmean1[iEBChannel] << " "
0825            << EBrms1[iEBChannel] << std::endl;
0826     for (int i = 0; i < 3; i++)
0827       std::getline(fxml, dummyLine);  // skip lines
0828   }
0829 
0830   // ***************** now EE *****************
0831   std::ifstream fCrystal;
0832   fCrystal.open("Crystal");
0833   if (!fCrystal.is_open()) {
0834     edm::LogInfo("ERROR : cannot open file Crystal");
0835     exit(1);
0836   }
0837   int ringEE[kEEChannels];
0838   for (int iChannel = 0; iChannel < kEEChannels; iChannel++) {
0839     fCrystal >> ringEE[iChannel];
0840     int ring = abs(ringEE[iChannel]) - 1;
0841     if (ring < 17 || ring > 27) {
0842       edm::LogInfo(" EE channel ") << iChannel << " ring " << ringEE[iChannel];
0843       exit(-1);
0844     }
0845   }
0846   fCrystal.close();
0847 
0848   float EEmean12[kEEChannels], EErms12[kEEChannels], EEmean6[kEEChannels], EErms6[kEEChannels], EEmean1[kEEChannels],
0849       EErms1[kEEChannels];
0850   for (int i = 0; i < 6; i++)
0851     std::getline(fxml, dummyLine);  // skip lines
0852   for (int iEEChannel = 0; iEEChannel < kEEChannels; iEEChannel++) {
0853     //    int ich = iEEChannel + kEBChannels;
0854     fxml >> bid;
0855     std::string stt = bid.substr(10, 15);
0856     std::istringstream m12(stt);
0857     m12 >> EEmean12[iEEChannel];
0858     int ring = abs(ringEE[iEEChannel]) - 1;
0859     if (ring < 17 || ring > 27)
0860       edm::LogInfo("EE channel ") << iEEChannel << " ring " << ring;
0861     int izz = 1;
0862     if (iEEChannel < 7324)
0863       izz = 0;
0864     fxml >> bid;
0865     stt = bid.substr(9, 15);
0866     std::istringstream r12(stt);
0867     r12 >> EErms12[iEEChannel];
0868     if (EErms12[iEEChannel] != 0. && EErms12[iEEChannel] < 5.) {
0869       RingMean[ring][izz][0] += EErms12[iEEChannel];
0870       RingRMS[ring][izz][0] += EErms12[iEEChannel] * EErms12[iEEChannel];
0871       NbVal[ring][izz][0]++;
0872     }
0873     fxml >> bid;
0874     stt = bid.substr(9, 15);
0875     std::istringstream m6(stt);
0876     m6 >> EEmean6[iEEChannel];
0877     fxml >> bid;
0878     stt = bid.substr(8, 15);
0879     std::istringstream r6(stt);
0880     r6 >> EErms6[iEEChannel];
0881     if (EErms6[iEEChannel] != 0. && EErms6[iEEChannel] < 5.) {
0882       RingMean[ring][izz][1] += EErms6[iEEChannel];
0883       RingRMS[ring][izz][1] += EErms6[iEEChannel] * EErms6[iEEChannel];
0884       NbVal[ring][izz][1]++;
0885     }
0886     fxml >> bid;
0887     stt = bid.substr(9, 15);
0888     std::istringstream m1(stt);
0889     m1 >> EEmean1[iEEChannel];
0890     fxml >> bid;
0891     stt = bid.substr(8, 15);
0892     std::istringstream r1(stt);
0893     r1 >> EErms1[iEEChannel];
0894     if (EErms1[iEEChannel] != 0. && EErms1[iEEChannel] < 5.) {
0895       RingMean[ring][izz][2] += EErms1[iEEChannel];
0896       RingRMS[ring][izz][2] += EErms1[iEEChannel] * EErms1[iEEChannel];
0897       NbVal[ring][izz][2]++;
0898     }
0899     if (iEEChannel % 1000 == 0)
0900       fout << " EE channel " << iEEChannel << " " << EEmean12[iEEChannel] << " " << EErms12[iEEChannel] << " "
0901            << EEmean6[iEEChannel] << " " << EErms6[iEEChannel] << " " << EEmean1[iEEChannel] << " "
0902            << EErms1[iEEChannel] << std::endl;
0903     for (int i = 0; i < 3; i++)
0904       std::getline(fxml, dummyLine);  // skip lines
0905   }
0906 
0907   fxml.close();
0908 
0909   for (int gain = 0; gain < kGains; gain++) {
0910     fout << "\n"
0911          << "**** Gain ****  " << gainValues[gain] << "\n";
0912     for (int ring = 0; ring < 28; ring++) {
0913       for (int side = 0; side < 2; side++) {
0914         if (NbVal[ring][side][gain] <= 0) {
0915           edm::LogInfo(" No entry for ring ") << ring;
0916           exit(-1);
0917         }
0918         RingMean[ring][side][gain] /= (double)NbVal[ring][side][gain];
0919         double x = RingMean[ring][side][gain];
0920         RingRMS[ring][side][gain] /= (double)NbVal[ring][side][gain];
0921         double rms = sqrt(RingRMS[ring][side][gain] - x * x);
0922         RingRMS[ring][side][gain] = rms;
0923         fout << " ring " << ring + 1 << " mean " << x << " rms " << rms << "    ";
0924       }  //  loop over sides
0925       fout << std::endl;
0926       if (ring == 16)
0927         fout << "*****  End caps *****     EE-                              EE+" << std::endl;
0928     }  //  loop over rings
0929   }    //  loop over gains
0930 
0931   // read also the ring value from Crystal file
0932 
0933   EcalPedestals* ped = new EcalPedestals();
0934   // barrel
0935   for (int iEta = -EBDetId::MAX_IETA; iEta <= EBDetId::MAX_IETA; ++iEta) {
0936     if (iEta == 0)
0937       continue;
0938     for (int iPhi = EBDetId::MIN_IPHI; iPhi <= EBDetId::MAX_IPHI; ++iPhi) {
0939       if (EBDetId::validDetId(iEta, iPhi)) {
0940         EBDetId ebdetid(iEta, iPhi);
0941         unsigned int hieb = ebdetid.hashedIndex();
0942         EcalPedestals::Item item;
0943         item.mean_x1 = 200.;
0944         item.mean_x6 = 200.;
0945         item.mean_x12 = 200.;
0946         if (m_corrected) {
0947           int ring = (abs(iEta) - 1) / 5;
0948           if (ring < 0 || ring > 16)
0949             edm::LogInfo("EB channel ") << hieb << " ring " << ring;
0950           int side = 0;
0951           if (iEta > 0)
0952             side = 1;
0953           if (EBrms1[hieb] == 0 || EBrms1[hieb] > RingMean[ring][side][2] + 3 * RingRMS[ring][side][2]) {
0954             fout << " EB channel " << hieb << " eta " << iEta << " phi " << iPhi << " ring " << ring + 1
0955                  << " gain 1 rms " << EBrms1[hieb] << " replaced by " << RingMean[ring][side][2] << std::endl;
0956             item.rms_x1 = RingMean[ring][side][2];
0957           } else
0958             item.rms_x1 = EBrms1[hieb];
0959           if (EBrms6[hieb] == 0 || EBrms6[hieb] > RingMean[ring][side][1] + 3 * RingRMS[ring][side][1]) {
0960             fout << " EB channel " << hieb << " eta " << iEta << " phi " << iPhi << " ring " << ring + 1
0961                  << " gain 6 rms " << EBrms6[hieb] << " replaced by " << RingMean[ring][side][1] << std::endl;
0962             item.rms_x6 = RingMean[ring][side][1];
0963           } else
0964             item.rms_x6 = EBrms6[hieb];
0965           if (EBrms12[hieb] == 0 || EBrms12[hieb] > RingMean[ring][side][0] + 3 * RingRMS[ring][side][0]) {
0966             fout << " EB channel " << hieb << " eta " << iEta << " phi " << iPhi << " ring " << ring + 1
0967                  << " gain 12 rms " << EBrms12[hieb] << " replaced by " << RingMean[ring][side][0] << std::endl;
0968             item.rms_x12 = RingMean[ring][side][0];
0969           } else
0970             item.rms_x12 = EBrms12[hieb];
0971           if (hieb > 4534 && hieb < 4540)
0972             edm::LogInfo(" Channel ") << hieb << " ring " << ring << " 12 " << EBrms12[hieb] << " mean "
0973                                       << RingMean[ring][side][0] << " rms " << RingRMS[ring][side][0] << "  6 "
0974                                       << EBrms6[hieb] << " mean " << RingMean[ring][side][1] << " rms "
0975                                       << RingRMS[ring][side][1] << "  1 " << EBrms1[hieb] << " mean "
0976                                       << RingMean[ring][side][2] << " rms " << RingRMS[ring][side][2];
0977         }  // if corrected
0978         else {
0979           item.rms_x1 = EBrms1[hieb];
0980           item.rms_x6 = EBrms6[hieb];
0981           item.rms_x12 = EBrms12[hieb];
0982         }
0983         if (item.rms_x1 > 4. || item.rms_x6 > 4. || item.rms_x12 > 4.)
0984           edm::LogInfo(" Channel ") << hieb << " 12 " << item.rms_x12 << " 6 " << item.rms_x6 << " 1 " << item.rms_x1;
0985         ped->insert(std::make_pair(ebdetid.rawId(), item));
0986       }  // valid EBId
0987     }    //  loop over phi
0988   }      //   loop over eta
0989 
0990   // endcaps
0991   for (int iz = -1; iz < 2; iz = iz + 2) {  // z : -1 and +1
0992     for (int iX = EEDetId::IX_MIN; iX <= EEDetId::IX_MAX; ++iX) {
0993       for (int iY = EEDetId::IY_MIN; iY <= EEDetId::IY_MAX; ++iY) {
0994         if (EEDetId::validDetId(iX, iY, iz)) {
0995           EEDetId eedetid(iX, iY, iz);
0996           unsigned int hiee = eedetid.hashedIndex();
0997           //      fout << hiee << " mean 12 " << EEmean12[hiee] << std::endl;
0998           EcalPedestals::Item item;
0999           item.mean_x1 = 200.;
1000           item.mean_x6 = 200.;
1001           item.mean_x12 = 200.;
1002           if (m_corrected) {
1003             int ring = abs(ringEE[hiee]) - 1;
1004             if (ring < 17 || ring > 27)
1005               edm::LogInfo("EE channel ") << hiee << " ring " << ring;
1006             if (EErms1[hiee] == 0 || EErms1[hiee] > RingMean[ring][iz][2] + 3 * RingRMS[ring][iz][2]) {
1007               fout << " EE channel " << hiee << " x " << iX << " y " << iY << " z " << iz << " ring " << ring + 1
1008                    << " gain 1 rms " << EErms1[hiee] << " replaced by " << RingMean[ring][iz][2] << std::endl;
1009               item.rms_x1 = RingMean[ring][iz][2];
1010             } else
1011               item.rms_x1 = EErms1[hiee];
1012             if (EErms6[hiee] == 0 || EErms6[hiee] > RingMean[ring][iz][1] + 3 * RingRMS[ring][iz][1]) {
1013               fout << " EE channel " << hiee << " x " << iX << " y " << iY << " z " << iz << " ring " << ring + 1
1014                    << " gain 6 rms " << EErms6[hiee] << " replaced by " << RingMean[ring][iz][1] << std::endl;
1015               item.rms_x6 = RingMean[ring][iz][1];
1016             } else
1017               item.rms_x6 = EErms6[hiee];
1018             if (EErms12[hiee] == 0 || EErms12[hiee] > RingMean[ring][iz][0] + 3 * RingRMS[ring][iz][0]) {
1019               fout << " EE channel " << hiee << " x " << iX << " y " << iY << " z " << iz << " ring " << ring + 1
1020                    << " gain 12 rms " << EErms12[hiee] << " replaced by " << RingMean[ring][iz][0] << std::endl;
1021               item.rms_x12 = RingMean[ring][iz][0];
1022             } else
1023               item.rms_x12 = EErms12[hiee];
1024           }  // if corrected
1025           else {
1026             item.rms_x1 = EErms1[hiee];
1027             item.rms_x6 = EErms6[hiee];
1028             item.rms_x12 = EErms12[hiee];
1029           }
1030           ped->insert(std::make_pair(eedetid.rawId(), item));
1031         }  // val EEId
1032       }    //  loop over y
1033     }      //   loop over x
1034   }        //   loop over z
1035   fout.close();
1036 
1037   unsigned int irun = m_firstRun;
1038   Time_t snc = (Time_t)irun;
1039   m_to_transfer.push_back(std::make_pair((EcalPedestals*)ped, snc));
1040 
1041   edm::LogInfo("Ecal - > end of readPedestalMC -----------\n");
1042 }
1043 
1044 ///////////////////////////////////////////////////////////////////////////////////////////
1045 
1046 void popcon::EcalPedestalsHandler::readPedestal2017() {
1047   bool debug = false;
1048   edm::LogInfo(" reading local Pedestal run (2017 way)! ") << m_filename;
1049 
1050   // First we copy the last valid record to a temporary object peds
1051   Ref ped_db = lastPayload();
1052   EcalPedestals* peds = new EcalPedestals();
1053   edm::LogInfo("retrieved last payload ");
1054 
1055   for (int iEta = -EBDetId::MAX_IETA; iEta <= EBDetId::MAX_IETA; ++iEta) {
1056     if (iEta == 0)
1057       continue;
1058     for (int iPhi = EBDetId::MIN_IPHI; iPhi <= EBDetId::MAX_IPHI; ++iPhi) {
1059       // make an EBDetId since we need EBDetId::rawId() to be used as the key for the pedestals
1060       if (EBDetId::validDetId(iEta, iPhi)) {
1061         EBDetId ebdetid(iEta, iPhi, EBDetId::ETAPHIMODE);
1062         EcalPedestals::const_iterator it = ped_db->find(ebdetid.rawId());
1063         EcalPedestals::Item aped = (*it);
1064         // here I copy the last valid value in the peds object
1065         EcalPedestals::Item item;
1066         item.mean_x1 = aped.mean_x1;
1067         item.rms_x1 = aped.rms_x1;
1068         item.mean_x6 = aped.mean_x6;
1069         item.rms_x6 = aped.rms_x6;
1070         item.mean_x12 = aped.mean_x12;
1071         item.rms_x12 = aped.rms_x12;
1072         peds->insert(std::make_pair(ebdetid.rawId(), item));
1073       }
1074     }
1075   }
1076   for (int iX = EEDetId::IX_MIN; iX <= EEDetId::IX_MAX; ++iX) {
1077     for (int iY = EEDetId::IY_MIN; iY <= EEDetId::IY_MAX; ++iY) {
1078       // make an EEDetId since we need EEDetId::rawId() to be used as the key for the pedestals
1079       if (EEDetId::validDetId(iX, iY, 1)) {
1080         EEDetId eedetidpos(iX, iY, 1);
1081         EcalPedestals::const_iterator it = ped_db->find(eedetidpos.rawId());
1082         EcalPedestals::Item aped = (*it);
1083         // here I copy the last valid value in the peds object
1084         EcalPedestals::Item item;
1085         item.mean_x1 = aped.mean_x1;
1086         item.rms_x1 = aped.rms_x1;
1087         item.mean_x6 = aped.mean_x6;
1088         item.rms_x6 = aped.rms_x6;
1089         item.mean_x12 = aped.mean_x12;
1090         item.rms_x12 = aped.rms_x12;
1091         peds->insert(std::make_pair(eedetidpos.rawId(), item));
1092       }
1093       if (EEDetId::validDetId(iX, iY, -1)) {
1094         EEDetId eedetidneg(iX, iY, -1);
1095         EcalPedestals::const_iterator it = ped_db->find(eedetidneg.rawId());
1096         EcalPedestals::Item aped = (*it);
1097         // here I copy the last valid value in the peds object
1098         EcalPedestals::Item item;
1099         item.mean_x1 = aped.mean_x1;
1100         item.rms_x1 = aped.rms_x1;
1101         item.mean_x6 = aped.mean_x6;
1102         item.rms_x6 = aped.rms_x6;
1103         item.mean_x12 = aped.mean_x12;
1104         item.rms_x12 = aped.rms_x12;
1105         peds->insert(std::make_pair(eedetidneg.rawId(), item));
1106       }
1107     }
1108   }
1109 
1110   edm::LogInfo(" reading the input file ") << m_filename;
1111   std::ifstream fInput;
1112   fInput.open(m_filename);
1113   if (!fInput.is_open()) {
1114     edm::LogInfo("ERROR : cannot open file ") << m_filename;
1115     exit(1);
1116   }
1117   //  string pos, dummyLine;
1118   int hashedId;
1119   float EBmean12[kEBChannels], EBrms12[kEBChannels], EBmean6[kEBChannels], EBrms6[kEBChannels], EBmean1[kEBChannels],
1120       EBrms1[kEBChannels];
1121   //*****************  barrel
1122   //  getline(fInput, dummyLine);   // skip first line
1123   for (int iChannel = 0; iChannel < kEBChannels; iChannel++) {
1124     fInput >> hashedId >> EBmean12[iChannel] >> EBrms12[iChannel] >> EBmean6[iChannel] >> EBrms6[iChannel] >>
1125         EBmean1[iChannel] >> EBrms1[iChannel];
1126     if (hashedId != iChannel + 1) {
1127       edm::LogInfo("File ") << m_filename << " strange hash " << hashedId << " while iChannel " << iChannel;
1128       exit(-1);
1129     }
1130   }
1131 
1132   // ***************** now EE *****************
1133   float EEmean12[kEEChannels], EErms12[kEEChannels], EEmean6[kEEChannels], EErms6[kEEChannels], EEmean1[kEEChannels],
1134       EErms1[kEEChannels];
1135   for (int iChannel = 0; iChannel < kEEChannels; iChannel++) {
1136     fInput >> hashedId >> EEmean12[iChannel] >> EErms12[iChannel] >> EEmean6[iChannel] >> EErms6[iChannel] >>
1137         EEmean1[iChannel] >> EErms1[iChannel];
1138     if (hashedId != iChannel + kEBChannels + 1) {
1139       edm::LogInfo("File ") << m_filename << " strange hash " << hashedId << " while iChannel " << iChannel;
1140       exit(-1);
1141     }
1142   }
1143   fInput.close();
1144 
1145   EcalPedestals* ped = new EcalPedestals();
1146   // barrel
1147   for (int iEta = -EBDetId::MAX_IETA; iEta <= EBDetId::MAX_IETA; ++iEta) {
1148     if (iEta == 0)
1149       continue;
1150     for (int iPhi = EBDetId::MIN_IPHI; iPhi <= EBDetId::MAX_IPHI; ++iPhi) {
1151       if (EBDetId::validDetId(iEta, iPhi)) {
1152         EBDetId ebdetid(iEta, iPhi);
1153         unsigned int hieb = ebdetid.hashedIndex();
1154         EcalPedestals::Item item;
1155         EcalPedestals::Item previous_ped = peds->barrel(hieb);
1156         if (debug & (EBmean12[hieb] == -999. || EBrms12[hieb] == -999. || EBmean6[hieb] == -999. ||
1157                      EBrms6[hieb] == -999. || EBmean1[hieb] == -999. || EBrms1[hieb] == -999.))
1158           edm::LogInfo(" bad EB channel eta ")
1159               << iEta << " phi " << iPhi << " " << EBmean12[hieb] << " " << EBrms12[hieb] << " " << EBmean6[hieb] << " "
1160               << EBrms6[hieb] << " " << EBmean1[hieb] << " " << EBrms1[hieb];
1161         if (EBmean1[hieb] != -999.)
1162           item.mean_x1 = EBmean1[hieb];
1163         else
1164           item.mean_x1 = previous_ped.mean_x1;
1165         if (EBrms1[hieb] != -999.)
1166           item.rms_x1 = EBrms1[hieb];
1167         else
1168           item.rms_x1 = previous_ped.rms_x1;
1169         if (EBmean6[hieb] != -999.)
1170           item.mean_x6 = EBmean6[hieb];
1171         else
1172           item.mean_x6 = previous_ped.mean_x6;
1173         if (EBrms6[hieb] != -999.)
1174           item.rms_x6 = EBrms6[hieb];
1175         else
1176           item.rms_x6 = previous_ped.rms_x6;
1177         if (EBmean12[hieb] != -999.)
1178           item.mean_x12 = EBmean12[hieb];
1179         else
1180           item.mean_x12 = previous_ped.mean_x12;
1181         if (EBrms12[hieb] != -999.)
1182           item.rms_x12 = EBrms12[hieb];
1183         else
1184           item.rms_x12 = previous_ped.rms_x12;
1185         ped->insert(std::make_pair(ebdetid.rawId(), item));
1186       }  // valid EBId
1187     }    //  loop over phi
1188   }      //   loop over eta
1189   // endcaps
1190   //  std::ofstream fout;
1191   //  fout.open("Pedestal.check");
1192   for (int iz = -1; iz < 2; iz = iz + 2) {  // z : -1 and +1
1193     for (int iX = EEDetId::IX_MIN; iX <= EEDetId::IX_MAX; ++iX) {
1194       for (int iY = EEDetId::IY_MIN; iY <= EEDetId::IY_MAX; ++iY) {
1195         if (EEDetId::validDetId(iX, iY, iz)) {
1196           EEDetId eedetid(iX, iY, iz);
1197           unsigned int hiee = eedetid.hashedIndex();
1198           //      fout << hiee << " mean 12 " << EEmean12[hiee] << std::endl;
1199           EcalPedestals::Item item;
1200           EcalPedestals::Item previous_ped = peds->endcap(hiee);
1201           if (debug & (EEmean12[hiee] == -999. || EErms12[hiee] == -999. || EEmean6[hiee] == -999. ||
1202                        EErms6[hiee] == -999. || EEmean1[hiee] == -999. || EErms1[hiee] == -999.))
1203             edm::LogInfo(" bad EE channel x ")
1204                 << iX << " y " << iY << " z" << iz << " " << EEmean12[hiee] << " " << EErms12[hiee] << " "
1205                 << EEmean6[hiee] << " " << EErms6[hiee] << " " << EEmean1[hiee] << " " << EErms1[hiee];
1206           if (EEmean1[hiee] != -999.)
1207             item.mean_x1 = EEmean1[hiee];
1208           else
1209             item.mean_x1 = previous_ped.mean_x1;
1210           if (EErms1[hiee] != -999.)
1211             item.rms_x1 = EErms1[hiee];
1212           else
1213             item.rms_x1 = previous_ped.rms_x1;
1214           if (EEmean6[hiee] != -999.)
1215             item.mean_x6 = EEmean6[hiee];
1216           else
1217             item.mean_x6 = previous_ped.mean_x6;
1218           if (EErms6[hiee] != -999.)
1219             item.rms_x6 = EErms6[hiee];
1220           else
1221             item.rms_x6 = previous_ped.rms_x6;
1222           if (EEmean12[hiee] != -999.)
1223             item.mean_x12 = EEmean12[hiee];
1224           else
1225             item.mean_x12 = previous_ped.mean_x12;
1226           if (EErms12[hiee] != -999.)
1227             item.rms_x12 = EErms12[hiee];
1228           else
1229             item.rms_x12 = previous_ped.rms_x12;
1230           ped->insert(std::make_pair(eedetid.rawId(), item));
1231         }  // val EEId
1232       }    //  loop over y
1233     }      //   loop over x
1234   }        //   loop over z
1235   //  fout.close();
1236 
1237   unsigned int irun = m_firstRun;
1238   Time_t snc = (Time_t)irun;
1239   m_to_transfer.push_back(std::make_pair((EcalPedestals*)ped, snc));
1240 
1241   edm::LogInfo("Ecal - > end of readPedestal2017 -----------\n");
1242 }
1243 /////////////////////////////////////////////////////////////////////////////////////////
1244 
1245 void popcon::EcalPedestalsHandler::readPedestalTree() {
1246   edm::LogInfo(" reading the root file ") << m_filename;
1247   TFile* hfile = new TFile(m_filename.c_str());
1248 
1249   TTree* treeChan = (TTree*)hfile->Get("PedChan");
1250   int iChannel = 0, ix = 0, iy = 0, iz = 0;
1251   treeChan->SetBranchAddress("Channels", &iChannel);
1252   treeChan->SetBranchAddress("x", &ix);
1253   treeChan->SetBranchAddress("y", &iy);
1254   treeChan->SetBranchAddress("z", &iz);
1255   int neventsChan = (int)treeChan->GetEntries();
1256   edm::LogInfo("PedChan nb entries ") << neventsChan;
1257   int ringEB[kEBChannels], sideEB[kEBChannels], ixEE[kEEChannels], iyEE[kEEChannels], izEE[kEEChannels];
1258   for (int entry = 0; entry < neventsChan; entry++) {
1259     treeChan->GetEntry(entry);
1260     if (entry < kEBChannels) {
1261       ringEB[iChannel] = (abs(ix) - 1) / 5;  // -85...-1, 1...85 give 0...16
1262       sideEB[iChannel] = 1;
1263       if (ix < 0)
1264         sideEB[iChannel] = 0;
1265       if (entry % 10000 == 0)
1266         edm::LogInfo(" EB channel ") << iChannel << " eta " << ix << " phi " << iy << " side " << sideEB[iChannel]
1267                                      << " ring " << ringEB[iChannel];
1268     } else {
1269       ixEE[iChannel] = ix;
1270       iyEE[iChannel] = iy;
1271       izEE[iChannel] = iz;
1272       if (entry % 1000 == 0)
1273         edm::LogInfo(" EE channel ") << iChannel << " x " << ixEE[iChannel] << " y " << iyEE[iChannel] << " z "
1274                                      << izEE[iChannel];
1275     }
1276   }
1277   //    2016 : 26
1278   Int_t pedxml[Nbpedxml] = {271948,
1279                             273634,
1280                             273931,
1281                             274705,
1282                             275403,
1283                             276108,
1284                             276510,
1285                             277169,
1286                             278123,
1287                             278183,
1288                             278246,
1289                             278389,
1290                             278499,
1291                             278693,
1292                             278858,
1293                             278888,
1294                             278931,
1295                             279728,
1296                             280129,
1297                             280263,
1298                             280941,
1299                             281753,
1300                             282631,
1301                             282833,
1302                             283199,
1303                             283766,
1304                             //    2017 : 25
1305                             286535,
1306                             293513,
1307                             293632,
1308                             293732,
1309                             295507,
1310                             295672,
1311                             296391,
1312                             296917,
1313                             297388,
1314                             298481,
1315                             299279,
1316                             299710,
1317                             300186,
1318                             300581,
1319                             301191,
1320                             302006,
1321                             302293,
1322                             302605,
1323                             303436,
1324                             303848,
1325                             304211,
1326                             304680,
1327                             305117,
1328                             305848,
1329                             306176,
1330                             //    2018 : 30
1331                             313760,
1332                             315434,
1333                             315831,
1334                             316299,
1335                             316694,
1336                             316963,
1337                             317399,
1338                             317669,
1339                             318249,
1340                             318747,
1341                             319111,
1342                             319365,
1343                             319700,
1344                             320098,
1345                             320515,
1346                             320905,
1347                             321184,
1348                             321480,
1349                             321855,
1350                             322151,
1351                             322653,
1352                             323261,
1353                             323802,
1354                             324250,
1355                             324632,
1356                             325909,
1357                             326038,
1358                             326652,
1359                             326979,
1360                             327271};
1361 
1362   Int_t run16Index = 0;
1363 
1364   Int_t fed[kChannels], chan[kChannels], id, run, run_type, seq_id, las_id, fill_num, run_num_infill, run_time,
1365       run_time_stablebeam, nxt, time[54];
1366   Float_t ped[kChannels], pedrms[kChannels], lumi, bfield;
1367   TTree* tree = (TTree*)hfile->Get("T");
1368   tree->Print();
1369   tree->SetBranchAddress("id", &id);
1370   tree->SetBranchAddress("run", &run);
1371   tree->SetBranchAddress("run_type", &run_type);
1372   tree->SetBranchAddress("seq_id", &seq_id);
1373   tree->SetBranchAddress("las_id", &las_id);
1374   tree->SetBranchAddress("fill_num", &fill_num);
1375   tree->SetBranchAddress("run_num_infill", &run_num_infill);
1376   tree->SetBranchAddress("run_time", &run_time);
1377   tree->SetBranchAddress("run_time_stablebeam", &run_time_stablebeam);
1378   tree->SetBranchAddress("lumi", &lumi);
1379   tree->SetBranchAddress("bfield", &bfield);
1380   tree->SetBranchAddress("nxt", &nxt);  // nb of filled Crystals
1381   tree->SetBranchAddress("time", time);
1382   tree->SetBranchAddress("fed", fed);
1383   tree->SetBranchAddress("chan", chan);
1384   tree->SetBranchAddress("ped", ped);
1385   tree->SetBranchAddress("pedrms", pedrms);
1386   int nevents = (int)tree->GetEntries();
1387   edm::LogInfo(" nb entries ") << nevents;
1388   std::ofstream fout;
1389   fout.open("copyTreePedestals.txt");
1390   if (!fout.is_open()) {
1391     edm::LogInfo("ERROR : cannot open file copyTreePedestals.txt");
1392     exit(1);
1393   }
1394   Double_t EAmean1[kChannels], EArms1[kChannels], EAmean6[kChannels], EArms6[kChannels], EAmean12[kChannels],
1395       EArms12[kChannels];
1396   Int_t RunEntry = 0, EAentry[kChannels];
1397   for (int ich = 0; ich < kChannels; ich++) {
1398     EAmean12[ich] = 0;
1399     EArms12[ich] = 0;
1400     EAentry[ich] = 0;
1401   }
1402   tree->GetEntry(0);
1403   fout << " first run " << run << " fill " << fill_num << " B field " << bfield << " run type " << run_type
1404        << " seq_id " << seq_id << " las_id " << las_id << " run_num_infill " << run_num_infill << " lumi " << lumi
1405        << " nb of Crystals " << nxt << std::endl;
1406   for (int ich = 0; ich < kChannels; ich++) {
1407     if (ped[ich] != 0.) {
1408       if (ich < kEBChannels)
1409         fout << " channel " << ich << " FED " << fed[ich] << " chan " << chan[ich] << " pedestal " << ped[ich]
1410              << " RMS " << pedrms[ich] << std::endl;
1411       else  //   EE
1412         fout << " channel " << ich << " EE channel " << ich - kEBChannels << " FED " << fed[ich] << " chan "
1413              << chan[ich] << " pedestal " << ped[ich] << " RMS " << pedrms[ich] << std::endl;
1414     }
1415   }
1416 
1417   int run_type_kept = m_runtype;         // 1 collision 2 cosmics 3 circulating 4 test
1418   int first_run_kept = (int)m_firstRun;  //  m_firstRun is unsigned!
1419   int last_run_kept = (int)m_lastRun;    //  m_lastRun is unsigned!
1420   int runold = run;
1421   int firsttimeFED = -1;
1422   //  int timeold = -1;
1423   for (int entry = 0; entry < nevents; entry++) {
1424     tree->GetEntry(entry);
1425     if (run < first_run_kept) {
1426       fout << " entry " << entry << " run " << run << " sequence " << seq_id << " run_time " << run_time
1427            << " before first wanted " << m_firstRun << std::endl;
1428       runold = run;
1429       continue;
1430     }
1431     if (run > last_run_kept) {
1432       fout << " entry " << entry << " run " << run << " sequence " << seq_id << " run_time " << run_time
1433            << " after last wanted " << m_lastRun << std::endl;
1434       runold = run;
1435       break;
1436     }
1437     if (run_type != run_type_kept) {
1438       fout << " entry " << entry << " run " << run << " sequence " << seq_id << " run_time " << run_time << " run type "
1439            << run_type << std::endl;
1440       continue;  // use only wanted type runs
1441     }
1442     if (nxt != kChannels) {
1443       fout << " entry " << entry << " run " << run << " sequence " << seq_id << " run_time " << run_time
1444            << " ***********  Number of channels " << nxt << std::endl;
1445       continue;
1446     }
1447     if (bfield < 3.79) {
1448       fout << " entry " << entry << " run " << run << " sequence " << seq_id << " run_time " << run_time
1449            << " ***********  bfield = " << bfield << std::endl;
1450       //      continue;  keep these runs
1451     }
1452     if (run_type_kept == 1) {  // for collision runs, keep only sequences after stable beam
1453       int time_seq = 0;
1454       for (int ifed = 0; ifed < 54; ifed++) {
1455         if (time[ifed] < run_time_stablebeam) {
1456           if (time_seq == 0)
1457             fout << " entry " << entry << " run " << run << " sequence " << seq_id << " run_time " << run_time
1458                  << "  ***********  sequence before stable beam at " << run_time_stablebeam << " FED " << ifed << " : "
1459                  << time[ifed];
1460           else
1461             fout << " FED " << ifed << " : " << time[ifed];
1462           time_seq++;
1463         }
1464       }
1465       if (time_seq != 0) {
1466         fout << " total nb " << time_seq << std::endl;
1467         continue;
1468       }
1469     }  // only collision runs
1470     //    if(idtime != timeold) {
1471     //      edm::LogInfo(" entry ")<< entry << " run " << run << " time " << idtime << " run type " << run_type;
1472     //      timeold = idtime;
1473     //    }
1474     if (run == runold) {
1475       RunEntry++;
1476       for (int ich = 0; ich < kChannels; ich++) {
1477         if (ped[ich] < 300 && ped[ich] > 100) {
1478           EAmean12[ich] += ped[ich];
1479           EArms12[ich] += pedrms[ich];
1480           EAentry[ich]++;
1481         }
1482       }
1483     } else {
1484       // new run. Write the previous one
1485       //      edm::LogInfo(" entry ")<< entry << " fill " << fill_num << " run " << runold << " nb of events " << RunEntry
1486       //        << " time " << run_time << " " << run_time_stablebeam << " " << time[0] << " run type " << run_type;
1487       if (RunEntry == 0 || (run_type_kept == 2 && RunEntry < 6))
1488         fout << " skiped run " << runold << " not enough entries : " << RunEntry << std::endl;
1489       else {
1490         fout << " entry " << entry - 1 << " run " << runold << " nb of events " << RunEntry;
1491         firsttimeFED = time[0];
1492         for (int ifed = 0; ifed < 54; ifed++) {
1493           fout << " " << time[ifed];
1494           if (firsttimeFED < time[ifed])
1495             firsttimeFED = time[ifed];
1496         }
1497         fout << std::endl;
1498 
1499         // get gain 1 and 6 results
1500         bool foundNew = false;
1501         for (int i = run16Index; i < Nbpedxml; i++) {
1502           if (runold > pedxml[i]) {
1503             fout << " found a new gain 1, 6 file " << pedxml[i] << " at index " << i << std::endl;
1504             run16Index++;
1505             foundNew = true;
1506             if (runold < pedxml[i + 1])
1507               break;
1508           }
1509         }
1510         if (foundNew) {
1511           int Indexxml = run16Index - 1;
1512           fout << " opening Pedestals_" << pedxml[Indexxml] << ".xml at index " << Indexxml << std::endl;
1513           std::ifstream fxml;
1514           fxml.open(Form("Pedestals_%i.xml", pedxml[Indexxml]));
1515           if (!fxml.is_open()) {
1516             edm::LogInfo("ERROR : cannot open file Pedestals_") << pedxml[Indexxml] << ".xml";
1517             exit(1);
1518           }
1519           std::string dummyLine, mean12, rms12, bid;
1520           for (int i = 0; i < 9; i++)
1521             std::getline(fxml, dummyLine);  // skip first lines
1522           // Barrel
1523           for (int iEBChannel = 0; iEBChannel < kEBChannels; iEBChannel++) {
1524             fxml >> mean12 >> rms12 >> bid;
1525             //    std::string stt = bid.std::substr(10,15);
1526             //    istringstream ii(stt);
1527             //    ii >> EBmean12[iEBChannel];
1528             //    fxml >> bid;
1529             //    stt = bid.substr(9,15);
1530             //    istringstream r12(stt);
1531             //    r12 >> EBrms12[iEBChannel];
1532             //    fxml >> bid;
1533             std::string stt = bid.substr(9, 15);
1534             std::istringstream m6(stt);
1535             m6 >> EAmean6[iEBChannel];
1536             fxml >> bid;
1537             stt = bid.substr(8, 15);
1538             std::istringstream r6(stt);
1539             r6 >> EArms6[iEBChannel];
1540             fxml >> bid;
1541             stt = bid.substr(9, 15);
1542             std::istringstream m1(stt);
1543             m1 >> EAmean1[iEBChannel];
1544             fxml >> bid;
1545             stt = bid.substr(8, 15);
1546             std::istringstream r1(stt);
1547             r1 >> EArms1[iEBChannel];
1548             if (iEBChannel % 10000 == 0)
1549               fout << " EB channel " << iEBChannel << " " << mean12 << " " << rms12 << " " << EAmean6[iEBChannel] << " "
1550                    << EArms6[iEBChannel] << " " << EAmean1[iEBChannel] << " " << EArms1[iEBChannel] << std::endl;
1551             for (int i = 0; i < 3; i++)
1552               std::getline(fxml, dummyLine);  // skip lines
1553           }
1554           for (int i = 0; i < 6; i++)
1555             std::getline(fxml, dummyLine);  // skip lines
1556           for (int iEEChannel = 0; iEEChannel < kEEChannels; iEEChannel++) {
1557             int ich = iEEChannel + kEBChannels;
1558             fxml >> mean12 >> rms12 >> bid;
1559             std::string stt = bid.substr(9, 15);
1560             std::istringstream m6(stt);
1561             m6 >> EAmean6[ich];
1562             fxml >> bid;
1563             stt = bid.substr(8, 15);
1564             std::istringstream r6(stt);
1565             r6 >> EArms6[ich];
1566             fxml >> bid;
1567             stt = bid.substr(9, 15);
1568             std::istringstream m1(stt);
1569             m1 >> EAmean1[ich];
1570             fxml >> bid;
1571             stt = bid.substr(8, 15);
1572             std::istringstream r1(stt);
1573             r1 >> EArms1[ich];
1574             if (iEEChannel % 1000 == 0)
1575               fout << " EE channel " << iEEChannel << " " << mean12 << " " << rms12 << " " << EAmean6[ich] << " "
1576                    << EArms6[ich] << " " << EAmean1[ich] << " " << EArms1[ich] << std::endl;
1577             for (int i = 0; i < 3; i++)
1578               std::getline(fxml, dummyLine);  // skip lines
1579           }
1580 
1581           fxml.close();
1582         }
1583         // end gain 1 and 6 results
1584 
1585         EcalPedestals* pedestal = new EcalPedestals();
1586         EcalPedestals::Item item;
1587         for (int ich = 0; ich < kChannels; ich++) {
1588           if (EAentry[ich] != 0) {
1589             EAmean12[ich] /= EAentry[ich];
1590             EArms12[ich] /= EAentry[ich];
1591           } else {
1592             EAmean12[ich] = 200.;
1593             EArms12[ich] = 0.;
1594           }
1595           if (ich % 10000 == 0)
1596             fout << " channel " << ich << " ped " << EAmean12[ich] << " RMS " << EArms12[ich] << std::endl;
1597           //
1598           item.mean_x1 = EAmean1[ich];
1599           item.rms_x1 = EArms1[ich];
1600           item.mean_x6 = EAmean6[ich];
1601           item.rms_x6 = EArms6[ich];
1602           item.mean_x12 = EAmean12[ich];
1603           item.rms_x12 = EArms12[ich];
1604           if (ich < kEBChannels) {
1605             //  EBDetId ebdetid(fed, chan, EBDetId::SMCRYSTALMODE);
1606             EBDetId ebdetid = EBDetId::unhashIndex(ich);
1607             pedestal->insert(std::make_pair(ebdetid.rawId(), item));
1608           } else {
1609             //    EEDetId eedetid(iX, iY, iz);
1610             int iChannel = ich - kEBChannels;
1611             EEDetId eedetid = EEDetId::unhashIndex(iChannel);
1612             pedestal->insert(std::make_pair(eedetid.rawId(), item));
1613           }
1614         }  // end loop over all channels
1615         Time_t snc = (Time_t)runold;
1616         m_to_transfer.push_back(std::make_pair((EcalPedestals*)pedestal, snc));
1617       }  // skip too short cosmics runs
1618 
1619       runold = run;
1620       RunEntry = 1;
1621       for (int ich = 0; ich < kChannels; ich++) {
1622         if (ped[ich] < 300 && ped[ich] > 100) {
1623           EAmean12[ich] = ped[ich];
1624           EArms12[ich] = pedrms[ich];
1625           EAentry[ich] = 1;
1626         } else {
1627           EAmean12[ich] = 0;
1628           EArms12[ich] = 0;
1629           EAentry[ich] = 0;
1630         }
1631       }
1632     }  // new run
1633   }    // end loop over all entries
1634   // write also the last run
1635   fout << " last entry fill " << fill_num << " run " << runold << " nb of events " << RunEntry << " time " << run_time
1636        << " " << run_time_stablebeam << " " << time[0] << " run type " << run_type << std::endl;
1637   for (int ifed = 0; ifed < 54; ifed++)
1638     fout << " " << time[ifed];
1639   fout << std::endl;
1640   EcalPedestals* pedestal = new EcalPedestals();
1641   EcalPedestals::Item item;
1642   for (int ich = 0; ich < kChannels; ich++) {
1643     if (EAentry[ich] != 0) {
1644       EAmean12[ich] /= EAentry[ich];
1645       EArms12[ich] /= EAentry[ich];
1646     } else {
1647       EAmean12[ich] = 200.;
1648       EArms12[ich] = 0.;
1649     }
1650     if (ich % 10000 == 0)
1651       fout << " channel " << ich << " ped " << EAmean12[ich] << " RMS " << EArms12[ich] << std::endl;
1652     // get gain 1 and 6 results
1653     // ...
1654     //
1655     item.mean_x1 = EAmean1[ich];
1656     item.rms_x1 = EArms1[ich];
1657     item.mean_x6 = EAmean6[ich];
1658     item.rms_x6 = EArms6[ich];
1659     item.mean_x12 = EAmean12[ich];
1660     item.rms_x12 = EArms12[ich];
1661     if (ich < kEBChannels) {
1662       //    EBDetId ebdetid(fed, chan, EBDetId::SMCRYSTALMODE);
1663       EBDetId ebdetid = EBDetId::unhashIndex(ich);
1664       pedestal->insert(std::make_pair(ebdetid.rawId(), item));
1665     } else {
1666       //      EEDetId eedetid(iX, iY, iz);
1667       int iChannel = ich - kEBChannels;
1668       EEDetId eedetid = EEDetId::unhashIndex(iChannel);
1669       pedestal->insert(std::make_pair(eedetid.rawId(), item));
1670     }
1671   }  // end loop over all channels
1672   Time_t snc = (Time_t)runold;
1673   m_to_transfer.push_back(std::make_pair((EcalPedestals*)pedestal, snc));  // run based IOV
1674   edm::LogInfo("Ecal - > end of readPedestalTree -----------\n");
1675 }
1676 /////////////////////////////////////////////////////////////////////////////////////////////////
1677 
1678 void popcon::EcalPedestalsHandler::readPedestalTimestamp() {
1679   bool debug = false;
1680   edm::LogInfo(" reading the root file ") << m_filename;
1681   TFile* hfile = new TFile(m_filename.c_str());
1682 
1683   TTree* treeChan = (TTree*)hfile->Get("PedChan");
1684   int iChannel = 0, ix = 0, iy = 0, iz = 0;
1685   treeChan->SetBranchAddress("Channels", &iChannel);
1686   treeChan->SetBranchAddress("x", &ix);
1687   treeChan->SetBranchAddress("y", &iy);
1688   treeChan->SetBranchAddress("z", &iz);
1689   int neventsChan = (int)treeChan->GetEntries();
1690   edm::LogInfo("PedChan nb entries ") << neventsChan;
1691   int ringEB[kEBChannels], sideEB[kEBChannels], ixEE[kEEChannels], iyEE[kEEChannels], izEE[kEEChannels];
1692   for (int entry = 0; entry < neventsChan; entry++) {
1693     treeChan->GetEntry(entry);
1694     if (entry < kEBChannels) {
1695       ringEB[iChannel] = (abs(ix) - 1) / 5;  // -85...-1, 1...85 give 0...16
1696       sideEB[iChannel] = 1;
1697       if (ix < 0)
1698         sideEB[iChannel] = 0;
1699       if (debug && entry % 10000 == 0)
1700         edm::LogInfo(" EB channel ") << iChannel << " eta " << ix << " phi " << iy << " side " << sideEB[iChannel]
1701                                      << " ring " << ringEB[iChannel];
1702     } else {
1703       ixEE[iChannel] = ix;
1704       iyEE[iChannel] = iy;
1705       izEE[iChannel] = iz;
1706       if (debug && entry % 1000 == 0)
1707         edm::LogInfo(" EE channel ") << iChannel << " x " << ixEE[iChannel] << " y " << iyEE[iChannel] << " z "
1708                                      << izEE[iChannel];
1709     }
1710   }
1711   //    2016: 26
1712   Int_t pedxml[Nbpedxml] = {271948,
1713                             273634,
1714                             273931,
1715                             274705,
1716                             275403,
1717                             276108,
1718                             276510,
1719                             277169,
1720                             278123,
1721                             278183,
1722                             278246,
1723                             278389,
1724                             278499,
1725                             278693,
1726                             278858,
1727                             278888,
1728                             278931,
1729                             279728,
1730                             280129,
1731                             280263,
1732                             280941,
1733                             281753,
1734                             282631,
1735                             282833,
1736                             283199,
1737                             283766,
1738                             //    2017 : 25
1739                             286535,
1740                             293513,
1741                             293632,
1742                             293732,
1743                             295507,
1744                             295672,
1745                             296391,
1746                             296917,
1747                             297388,
1748                             298481,
1749                             299279,
1750                             299710,
1751                             300186,
1752                             300581,
1753                             301191,
1754                             302006,
1755                             302293,
1756                             302605,
1757                             303436,
1758                             303848,
1759                             304211,
1760                             304680,
1761                             305117,
1762                             305848,
1763                             306176,
1764                             //    2018 : 30
1765                             313760,
1766                             315434,
1767                             315831,
1768                             316299,
1769                             316694,
1770                             316963,
1771                             317399,
1772                             317669,
1773                             318249,
1774                             318747,
1775                             319111,
1776                             319365,
1777                             319700,
1778                             320098,
1779                             320515,
1780                             320905,
1781                             321184,
1782                             321480,
1783                             321855,
1784                             322151,
1785                             322653,
1786                             323261,
1787                             323802,
1788                             324250,
1789                             324632,
1790                             325909,
1791                             326038,
1792                             326652,
1793                             326979,
1794                             327271};
1795 
1796   Int_t run16Index = 0;
1797 
1798   Int_t fed[kChannels], chan[kChannels], id, run, run_type, seq_id, las_id, fill_num, run_num_infill, run_time,
1799       run_time_stablebeam, nxt, time[54];
1800   Float_t ped[kChannels], pedrms[kChannels], lumi, bfield;
1801   TTree* tree = (TTree*)hfile->Get("T");
1802   tree->Print();
1803   tree->SetBranchAddress("id", &id);
1804   tree->SetBranchAddress("run", &run);
1805   tree->SetBranchAddress("run_type", &run_type);
1806   tree->SetBranchAddress("seq_id", &seq_id);
1807   tree->SetBranchAddress("las_id", &las_id);
1808   tree->SetBranchAddress("fill_num", &fill_num);
1809   tree->SetBranchAddress("run_num_infill", &run_num_infill);
1810   tree->SetBranchAddress("run_time", &run_time);
1811   tree->SetBranchAddress("run_time_stablebeam", &run_time_stablebeam);
1812   tree->SetBranchAddress("lumi", &lumi);
1813   tree->SetBranchAddress("bfield", &bfield);
1814   tree->SetBranchAddress("nxt", &nxt);  // nb of filled Crystals
1815   tree->SetBranchAddress("time", time);
1816   tree->SetBranchAddress("fed", fed);
1817   tree->SetBranchAddress("chan", chan);
1818   tree->SetBranchAddress("ped", ped);
1819   tree->SetBranchAddress("pedrms", pedrms);
1820   int nevents = (int)tree->GetEntries();
1821   edm::LogInfo(" nb entries ") << nevents;
1822   std::ofstream fout;
1823   fout.open("copyTimestampPedestals.txt");
1824   if (!fout.is_open()) {
1825     edm::LogInfo("ERROR : cannot open file copyTimestampPedestals.txt");
1826     exit(1);
1827   }
1828   Double_t EAmean1[kChannels], EArms1[kChannels], EAmean6[kChannels], EArms6[kChannels], EAmean12[kChannels],
1829       EArms12[kChannels];
1830   for (int ich = 0; ich < kChannels; ich++) {
1831     EAmean12[ich] = 200.;
1832     EArms12[ich] = 0.;
1833   }
1834   tree->GetEntry(0);
1835   fout << " first run " << run << " fill " << fill_num << " B field " << bfield << " run type " << run_type
1836        << " seq_id " << seq_id << " las_id " << las_id << " run_num_infill " << run_num_infill << " lumi " << lumi
1837        << " nb of Crystals " << nxt << std::endl;
1838   if (debug) {
1839     for (int ich = 0; ich < kChannels; ich++) {
1840       if (ped[ich] != 0.) {
1841         if (ich < kEBChannels)
1842           fout << " channel " << ich << " FED " << fed[ich] << " chan " << chan[ich] << " pedestal " << ped[ich]
1843                << " RMS " << pedrms[ich] << std::endl;
1844         else  //   EE
1845           fout << " channel " << ich << " EE channel " << ich - kEBChannels << " FED " << fed[ich] << " chan "
1846                << chan[ich] << " pedestal " << ped[ich] << " RMS " << pedrms[ich] << std::endl;
1847       }
1848     }
1849   }  // debug
1850 
1851   int runold = -1, fillold = -1, firsttimeFEDold = -1;
1852   int firsttimeFED = -1, firstFillSequence = 0;
1853   bool firstSeqBeforeStable = false;
1854   int transfer = 0;
1855   int first_run_kept = (int)m_firstRun;  //  m_firstRun is unsigned!
1856   int last_run_kept = (int)m_lastRun;    //  m_lastRun is unsigned!
1857   for (int entry = 0; entry < nevents; entry++) {
1858     tree->GetEntry(entry);
1859     if (nxt != kChannels) {
1860       //      fout << " entry " << entry << " run " << run << " sequence " << seq_id << " run_time " << run_time
1861       fout << " entry " << entry << " run " << run << " sequence " << seq_id  // run_time always 0!
1862            << " ***********  Number of channels " << nxt;
1863       //      if(seq_id == 0) {    corrected Sep 15 2017
1864       fout << " rejected" << std::endl;
1865       continue;
1866       //      }
1867       //      else fout << std::endl;
1868     }
1869     if (run_type != 1) {
1870       fout << " entry " << entry << " run " << run << " sequence " << seq_id
1871            << " ***********  run_type ( 1 coll, 2 cosm, 3 circ, 4 test ) = " << run_type << std::endl;
1872       continue;
1873     }
1874     if (las_id != 447) {  //447 = blue laser
1875       fout << " entry " << entry << " run " << run << " sequence " << seq_id
1876            << " ***********  laser wave length = " << las_id << std::endl;
1877       continue;
1878     }
1879     //    if(las_id != 527) {  //527 = green laser
1880     //      fout << " entry " << entry << " run " << run << " sequence " << seq_id
1881     //         << " ***********  laser wave length = " << las_id << std::endl;
1882     //      continue;
1883     //    }
1884     if (bfield < 3.79) {
1885       fout << " entry " << entry << " run " << run << " sequence " << seq_id << " ***********  bfield = " << bfield
1886            << std::endl;
1887       //      continue;  keep these runs
1888     }
1889     fout << " entry " << entry << " run " << run;
1890     if (run_type == 1)
1891       fout << " fill " << fill_num;
1892     fout << " sequence " << seq_id;
1893     if (run_type == 1) {
1894       fout << " stable " << run_time_stablebeam;
1895       if (run_time_stablebeam < first_run_kept) {
1896         fout << " before first wanted " << m_firstRun << std::endl;
1897         continue;
1898       }
1899     }
1900     firsttimeFED = time[0];
1901     for (int ifed = 0; ifed < 54; ifed++) {
1902       if (time[ifed] > firsttimeFEDold && time[ifed] < firsttimeFED)
1903         firsttimeFED = time[ifed];  // take the first AFTER the previous sequence one!...
1904     }
1905     if (firsttimeFED < first_run_kept) {
1906       fout << " time " << firsttimeFED << " before first wanted " << m_firstRun << std::endl;
1907       continue;
1908     }
1909     if (firsttimeFED > last_run_kept) {
1910       fout << " entry " << entry << " time " << firsttimeFED << " after last wanted " << m_lastRun << std::endl;
1911       break;
1912     }
1913     fout << " time " << firsttimeFED << std::endl;
1914     if (firsttimeFED <= firsttimeFEDold) {
1915       edm::LogInfo(" Problem finding the IOV : old one ") << firsttimeFEDold << " new one " << firsttimeFED;
1916       for (int ifed = 0; ifed < 54; ifed++)
1917         edm::LogInfo("Time ") << time[ifed] << " ignore this entry ";
1918       continue;
1919     }
1920     firsttimeFEDold = firsttimeFED;
1921 
1922     //    if(run != runold) firstSeqBeforeStable = false;
1923     if (fill_num != fillold) {
1924       firstSeqBeforeStable = false;
1925       firstFillSequence = 0;
1926     } else
1927       firstFillSequence++;
1928     if (run_type == 1) {
1929       if (run_time_stablebeam > 0) {
1930         if (firsttimeFED < run_time_stablebeam) {
1931           fout << " data taken before stable beam, skip it" << std::endl;
1932           firstSeqBeforeStable = true;
1933           runold = run;
1934           fillold = fill_num;
1935           continue;
1936         }
1937       } else  //  problem with run_time_stablebeam
1938         fout << " *** entry " << entry << " run_time_stablebeam " << run_time_stablebeam << std::endl;
1939       if (firstSeqBeforeStable) {  // this is the first fully filled entry after stable beam
1940         firstSeqBeforeStable = false;
1941         firsttimeFED = run_time_stablebeam;
1942         fout << " first full sequence after stable; change the IOV " << firsttimeFED << std::endl;
1943       }
1944       if (firstFillSequence == 0) {  // first sequence in this fill
1945         if (firsttimeFED > run_time_stablebeam) {
1946           fout << " first full sequence " << firsttimeFED << " after stable " << run_time_stablebeam
1947                << "; change the IOV " << std::endl;
1948           firsttimeFED = run_time_stablebeam;
1949         }
1950       }
1951     }  // only collision runs
1952 
1953     for (int ich = 0; ich < kChannels; ich++) {
1954       if (ped[ich] < 300 && ped[ich] > 100) {
1955         EAmean12[ich] = ped[ich];
1956         EArms12[ich] = pedrms[ich];
1957       }
1958     }
1959     // get gain 1 and 6 results
1960     bool foundNew = false;
1961     if (run != runold) {
1962       for (int i = run16Index; i < Nbpedxml; i++) {
1963         if (run > pedxml[i]) {
1964           fout << " found a new gain 1, 6 file " << pedxml[i] << " at index " << i << std::endl;
1965           run16Index++;
1966           foundNew = true;
1967           //      if(runold < pedxml[i + 1]) break;   why runold??
1968           if (run < pedxml[i + 1])
1969             break;
1970         }
1971       }
1972       if (foundNew) {
1973         int Indexxml = run16Index - 1;
1974         fout << " opening Pedestals_" << pedxml[Indexxml] << ".xml at index " << Indexxml << std::endl;
1975         std::ifstream fxml;
1976         fxml.open(Form("Pedestals_%i.xml", pedxml[Indexxml]));
1977         if (!fxml.is_open()) {
1978           edm::LogInfo("ERROR : cannot open file Pedestals_") << pedxml[Indexxml] << ".xml";
1979           exit(1);
1980         }
1981         std::string dummyLine, mean12, rms12, bid;
1982         for (int i = 0; i < 9; i++)
1983           std::getline(fxml, dummyLine);  // skip first lines
1984         // Barrel
1985         for (int iEBChannel = 0; iEBChannel < kEBChannels; iEBChannel++) {
1986           fxml >> mean12 >> rms12 >> bid;
1987           std::string stt = bid.substr(9, 15);
1988           std::istringstream m6(stt);
1989           m6 >> EAmean6[iEBChannel];
1990           fxml >> bid;
1991           stt = bid.substr(8, 15);
1992           std::istringstream r6(stt);
1993           r6 >> EArms6[iEBChannel];
1994           fxml >> bid;
1995           stt = bid.substr(9, 15);
1996           std::istringstream m1(stt);
1997           m1 >> EAmean1[iEBChannel];
1998           fxml >> bid;
1999           stt = bid.substr(8, 15);
2000           std::istringstream r1(stt);
2001           r1 >> EArms1[iEBChannel];
2002           if (debug && iEBChannel % 10000 == 0)
2003             fout << " EB channel " << iEBChannel << " " << mean12 << " " << rms12 << " " << EAmean6[iEBChannel] << " "
2004                  << EArms6[iEBChannel] << " " << EAmean1[iEBChannel] << " " << EArms1[iEBChannel] << std::endl;
2005           for (int i = 0; i < 3; i++)
2006             std::getline(fxml, dummyLine);  // skip lines
2007         }
2008         for (int i = 0; i < 6; i++)
2009           std::getline(fxml, dummyLine);  // skip lines
2010         for (int iEEChannel = 0; iEEChannel < kEEChannels; iEEChannel++) {
2011           int ich = iEEChannel + kEBChannels;
2012           fxml >> mean12 >> rms12 >> bid;
2013           std::string stt = bid.substr(9, 15);
2014           std::istringstream m6(stt);
2015           m6 >> EAmean6[ich];
2016           fxml >> bid;
2017           stt = bid.substr(8, 15);
2018           std::istringstream r6(stt);
2019           r6 >> EArms6[ich];
2020           fxml >> bid;
2021           stt = bid.substr(9, 15);
2022           std::istringstream m1(stt);
2023           m1 >> EAmean1[ich];
2024           fxml >> bid;
2025           stt = bid.substr(8, 15);
2026           std::istringstream r1(stt);
2027           r1 >> EArms1[ich];
2028           if (debug && iEEChannel % 1000 == 0)
2029             fout << " EE channel " << iEEChannel << " " << mean12 << " " << rms12 << " " << EAmean6[ich] << " "
2030                  << EArms6[ich] << " " << EAmean1[ich] << " " << EArms1[ich] << std::endl;
2031           for (int i = 0; i < 3; i++)
2032             std::getline(fxml, dummyLine);  // skip lines
2033         }
2034         fxml.close();
2035       }  // found a new gain 1 6 file
2036     }    // check gain 1 and 6 results only for new runs
2037 
2038     EcalPedestals* pedestal = new EcalPedestals();
2039     EcalPedestals::Item item;
2040     for (int ich = 0; ich < kChannels; ich++) {
2041       if (debug && ich % 10000 == 0)
2042         fout << " channel " << ich << " ped " << EAmean12[ich] << " RMS " << EArms12[ich] << std::endl;
2043       //
2044       item.mean_x1 = EAmean1[ich];
2045       item.rms_x1 = EArms1[ich];
2046       item.mean_x6 = EAmean6[ich];
2047       item.rms_x6 = EArms6[ich];
2048       item.mean_x12 = EAmean12[ich];
2049       item.rms_x12 = EArms12[ich];
2050       if (ich < kEBChannels) {
2051         //  EBDetId ebdetid(fed, chan, EBDetId::SMCRYSTALMODE);
2052         EBDetId ebdetid = EBDetId::unhashIndex(ich);
2053         pedestal->insert(std::make_pair(ebdetid.rawId(), item));
2054       } else {
2055         //    EEDetId eedetid(iX, iY, iz);
2056         int iChannel = ich - kEBChannels;
2057         EEDetId eedetid = EEDetId::unhashIndex(iChannel);
2058         pedestal->insert(std::make_pair(eedetid.rawId(), item));
2059       }
2060     }  // end loop over all channels
2061     uint64_t iov = (uint64_t)firsttimeFED << 32;
2062     Time_t snc = (Time_t)iov;
2063     transfer++;
2064     fout << " entry " << entry << " transfer " << transfer << " iov " << iov << std::endl;
2065     m_to_transfer.push_back(std::make_pair((EcalPedestals*)pedestal, snc));  // time based IOV
2066     fout << "  m_to_transfer " << firsttimeFED << std::endl;
2067     runold = run;
2068     fillold = fill_num;
2069   }  // end loop over all entries
2070 
2071   edm::LogInfo("Ecal - > end of readPedestalTimestamp -----------\n");
2072 }