CMS 3D CMS Logo

/data/git/CMSSW_5_3_11_patch5/src/CondTools/Ecal/src/EcalGetLaserData.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:    Ecal
00004 // Class:      GetLaserData
00005 // 
00011 //
00012 // Original Author:  Vladlen Timciuc
00013 //         Created:  Wed Jul  4 13:55:56 CEST 2007
00014 // $Id: EcalGetLaserData.cc,v 1.6 2010/10/18 22:04:26 wmtan Exp $
00015 //
00016 //
00017 
00018 
00019 // system include files
00020 #include <memory>
00021 
00022 // user include files
00023 
00024 #include "FWCore/ServiceRegistry/interface/Service.h"
00025 #include "CondCore/DBOutputService/interface/PoolDBOutputService.h"
00026 
00027 #include "FWCore/Framework/interface/Frameworkfwd.h"
00028 #include "FWCore/Framework/interface/EDAnalyzer.h"
00029 
00030 #include "FWCore/Framework/interface/Event.h"
00031 #include "FWCore/Framework/interface/MakerMacros.h"
00032 
00033 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00034 
00035 #include "DataFormats/Common/interface/Handle.h"
00036 
00037 #include "CondTools/Ecal/interface/EcalGetLaserData.h"
00038 
00039 #include "FWCore/Framework/interface/ESHandle.h"
00040 #include "FWCore/Framework/interface/EventSetup.h"
00041 #include "FWCore/Framework/interface/EventSetupRecordKey.h"
00042 
00043 
00044 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00045 
00046 //
00047 // constants, enums and typedefs
00048 //
00049 
00050 //
00051 // static data member definitions
00052 //
00053 
00054 //
00055 // constructors and destructor
00056 //
00057 EcalGetLaserData::EcalGetLaserData(const edm::ParameterSet& iConfig) :
00058   // m_timetype(iConfig.getParameter<std::string>("timetype")),
00059   m_cacheIDs(),
00060   m_records()
00061 {
00062   std::string container;
00063   std::string tag;
00064   std::string record;
00065 
00066   //m_firstRun=(unsigned long long)atoi( iConfig.getParameter<std::string>("firstRun").c_str());
00067   //m_lastRun=(unsigned long long)atoi( iConfig.getParameter<std::string>("lastRun").c_str());
00068 
00069   typedef std::vector< edm::ParameterSet > Parameters;
00070   Parameters toGet = iConfig.getParameter<Parameters>("toGet");
00071   for(Parameters::iterator i = toGet.begin(); i != toGet.end(); ++i) {
00072     container = i->getParameter<std::string>("container");
00073     record = i->getParameter<std::string>("record");
00074     m_cacheIDs.insert( std::make_pair(container, 0) );
00075     m_records.insert( std::make_pair(container, record) );
00076 
00077   } //now do what ever initialization is needed
00078 
00079 }
00080 
00081 
00082 EcalGetLaserData::~EcalGetLaserData()
00083 {
00084  
00085    // do anything here that needs to be done at desctruction time
00086    // (e.g. close files, deallocate resources etc.)
00087 
00088 }
00089 
00090 
00091 //
00092 // member functions
00093 //
00094 
00095 // ------------ method called to for each event  ------------
00096 void
00097 EcalGetLaserData::analyze(const edm::Event& evt, const edm::EventSetup& evtSetup)
00098 {
00099   using namespace edm;
00100   
00101   // loop on offline DB conditions to be transferred as from config file 
00102   std::string container;
00103   std::string record;
00104   typedef std::map<std::string, std::string>::const_iterator recordIter;
00105   for (recordIter i = m_records.begin(); i != m_records.end(); ++i) {
00106     container = (*i).first;
00107     record = (*i).second;
00108     
00109     std::string recordName = m_records[container];
00110 
00111     
00112     if (container == "EcalLaserAPDPNRatios") {
00113       
00114       // get from offline DB the last valid laser set 
00115       edm::ESHandle<EcalLaserAPDPNRatios> handle;
00116       evtSetup.get<EcalLaserAPDPNRatiosRcd>().get(handle);
00117 
00118       // this is the offline object 
00119       EcalLaserAPDPNRatios::EcalLaserTimeStamp timestamp;
00120       EcalLaserAPDPNRatios::EcalLaserAPDPNpair apdpnpair;
00121             
00122       const EcalLaserAPDPNRatios::EcalLaserAPDPNRatiosMap& laserRatiosMap = handle.product()->getLaserMap(); 
00123       const EcalLaserAPDPNRatios::EcalLaserTimeStampMap& laserTimeMap = handle.product()->getTimeMap(); 
00124 
00125       // loop through ecal barrel
00126       for(int iEta=-EBDetId::MAX_IETA; iEta<=EBDetId::MAX_IETA ;++iEta) {
00127         if(iEta==0) continue;
00128         for(int iPhi=EBDetId::MIN_IPHI; iPhi<=EBDetId::MAX_IPHI; ++iPhi) {
00129           
00130           EBDetId ebdetid(iEta,iPhi);
00131           int hi = ebdetid.hashedIndex();
00132           
00133           if (hi<static_cast<int>(laserRatiosMap.size())) {
00134             apdpnpair = laserRatiosMap[hi];
00135             std::cout << "A sample value of APDPN pair EB : " 
00136                       << hi << " : " << apdpnpair.p1 << " , " << apdpnpair.p2 << std::endl;               
00137           } else {
00138             edm::LogError("EcalGetLaserData") << "error with laserRatiosMap!" << std::endl;     
00139           }
00140           
00141         }
00142       }  
00143 
00144       // loop through ecal endcap      
00145       for(int iX=EEDetId::IX_MIN; iX<=EEDetId::IX_MAX ;++iX) {
00146         for(int iY=EEDetId::IY_MIN; iY<=EEDetId::IY_MAX; ++iY) {
00147 
00148           if (!EEDetId::validDetId(iX,iY,1))
00149             continue;
00150           
00151           EEDetId eedetidpos(iX,iY,1);
00152           int hi = eedetidpos.hashedIndex();
00153           
00154           if (hi< static_cast<int>(laserRatiosMap.size())) {
00155             apdpnpair = laserRatiosMap[hi];
00156             std::cout << "A sample value of APDPN pair EE+ : " 
00157                       << hi << " : " << apdpnpair.p1 << " , " << apdpnpair.p2 << std::endl;
00158           } else {
00159             edm::LogError("EcalGetLaserData") << "error with laserRatiosMap!" << std::endl;     
00160           }
00161           
00162           if (!EEDetId::validDetId(iX,iY,-1))
00163             continue;
00164           EEDetId eedetidneg(iX,iY,1);
00165           hi = eedetidneg.hashedIndex();
00166           
00167           if (hi< static_cast<int>(laserRatiosMap.size())) {
00168             apdpnpair = laserRatiosMap[hi];
00169             std::cout << "A sample value of APDPN pair EE- : " 
00170                       << hi << " : " << apdpnpair.p1 << " , " << apdpnpair.p2 << std::endl;
00171           } else {
00172             edm::LogError("EcalGetLaserData") << "error with laserRatiosMap!" << std::endl;     
00173           }
00174         }
00175       }
00176       
00177       for(int i=0; i<92; i++){
00178         timestamp = laserTimeMap[i];  
00179         std::cout << "A value of timestamp pair : "  
00180                   << i << " " << timestamp.t1.value() << " , " << timestamp.t2.value() << std::endl;    
00181       }
00182       
00183       std::cout <<".. just retrieved the last valid record from DB "<< std::endl;
00184 
00185     } else if(container == "EcalLaserAPDPNRatiosRef") { 
00186 
00187       // get from offline DB the last valid laser set 
00188       edm::ESHandle<EcalLaserAPDPNRatiosRef> handle;
00189       evtSetup.get<EcalLaserAPDPNRatiosRefRcd>().get(handle);
00190 
00191       EcalLaserAPDPNref apdpnref;      
00192       const EcalLaserAPDPNRatiosRefMap& laserRefMap = handle.product()->getMap(); 
00193       
00194       // first barrel
00195       for(int iEta=-EBDetId::MAX_IETA; iEta<=EBDetId::MAX_IETA ;++iEta) {
00196         if(iEta==0) continue;
00197         for(int iPhi=EBDetId::MIN_IPHI; iPhi<=EBDetId::MAX_IPHI; ++iPhi) {
00198           
00199           EBDetId ebdetid(iEta,iPhi);
00200           int hi = ebdetid.hashedIndex();
00201           
00202           if (hi< static_cast<int>(laserRefMap.size())) {
00203             apdpnref = laserRefMap[hi];
00204             std::cout << "A sample value of APDPN Reference value EB : "  
00205                  << hi << " : " << apdpnref << std::endl;                 
00206           } else { 
00207             edm::LogError("EcalGetLaserData") << "error with laserRefMap!" << std::endl;     
00208           }               
00209         }
00210       }
00211       
00212       // now for endcap
00213       for(int iX=EEDetId::IX_MIN; iX<=EEDetId::IX_MAX ;++iX) {
00214         for(int iY=EEDetId::IY_MIN; iY<=EEDetId::IY_MAX; ++iY) {
00215 
00216           if (!EEDetId::validDetId(iX,iY,1))
00217             continue;
00218           
00219           EEDetId eedetidpos(iX,iY,1);
00220           int hi = eedetidpos.hashedIndex();
00221           
00222           if (hi< static_cast<int>(laserRefMap.size())) {
00223             apdpnref = laserRefMap[hi];
00224             std::cout << "A sample value of APDPN Reference value EE+ : "  
00225                  << hi << " : " << apdpnref << std::endl;                                 
00226             
00227           } else { 
00228             edm::LogError("EcalGetLaserData") << "error with laserRefMap!" << std::endl;     
00229           }
00230           
00231           if (!EEDetId::validDetId(iX,iY,-1))
00232             continue;
00233           EEDetId eedetidneg(iX,iY,-1);
00234           hi = eedetidneg.hashedIndex();
00235           
00236           if (hi< static_cast<int>(laserRefMap.size())) {
00237             apdpnref = laserRefMap[hi];
00238             std::cout << "A sample value of APDPN Reference value EE- : "  
00239                  << hi << " : " << apdpnref << std::endl;                
00240           } else { 
00241             edm::LogError("EcalGetLaserData") << "error with laserRefMap!" << std::endl;     
00242           }           
00243         }
00244       }
00245       
00246       std::cout << "... just retrieved the last valid record from DB "<< std::endl;
00247       
00248     } else if (container == "EcalLaserAlphas") { 
00249 
00250       // get from offline DB the last valid laser set 
00251       edm::ESHandle<EcalLaserAlphas> handle;
00252       evtSetup.get<EcalLaserAlphasRcd>().get(handle);
00253 
00254       // this is the offline object 
00255       EcalLaserAlpha alpha;     
00256       const EcalLaserAlphaMap& laserAlphaMap = handle.product()->getMap(); // map of apdpns
00257 
00258       // first barrel
00259       for(int iEta=-EBDetId::MAX_IETA; iEta<=EBDetId::MAX_IETA ;++iEta) {
00260         if(iEta==0) continue;
00261         for(int iPhi=EBDetId::MIN_IPHI; iPhi<=EBDetId::MAX_IPHI; ++iPhi) {
00262           
00263           EBDetId ebdetid(iEta,iPhi);
00264           int hi = ebdetid.hashedIndex();
00265           
00266           if (hi< static_cast<int>(laserAlphaMap.size())) {
00267             alpha = laserAlphaMap[hi];
00268             std::cout << " A sample value of Alpha value EB : " << hi << " : " << alpha << std::endl;
00269           } else {
00270             edm::LogError("EcalGetLaserData") << "error with laserAlphaMap!" << std::endl;     
00271           }       
00272         }
00273       }
00274       
00275       // next endcap
00276       for(int iX=EEDetId::IX_MIN; iX<=EEDetId::IX_MAX ;++iX) {
00277         for(int iY=EEDetId::IY_MIN; iY<=EEDetId::IY_MAX; ++iY) {
00278 
00279           if (!EEDetId::validDetId(iX,iY,1))
00280             continue;
00281 
00282           EEDetId eedetidpos(iX,iY,1);
00283           int hi = eedetidpos.hashedIndex();
00284           
00285           if (hi< static_cast<int>(laserAlphaMap.size())) {
00286             alpha = laserAlphaMap[hi];
00287             std::cout << " A sample value of Alpha value EE+ : " << hi << " : " << alpha << std::endl;  
00288           } else {
00289             edm::LogError("EcalGetLaserData") << "error with laserAlphaMap!" << std::endl;     
00290           }                   
00291           
00292 
00293           if (!EEDetId::validDetId(iX,iY,-1))
00294             continue;
00295           EEDetId eedetidneg(iX,iY,-1);
00296           hi = eedetidneg.hashedIndex();
00297           
00298           if (hi< static_cast<int>(laserAlphaMap.size())) {
00299             alpha = laserAlphaMap[hi];
00300             std::cout << " A sample value of Alpha value EE- : " << hi << " : " << alpha << std::endl;
00301           } else {
00302             edm::LogError("EcalGetLaserData") << "error with laserAlphaMap!" << std::endl;     
00303           }       
00304         }
00305       }
00306       
00307       std::cout <<"... just retrieved the last valid record from DB "<< std::endl;
00308 
00309     } else {
00310       edm::LogError("EcalGetLaserData") << "Cannot retrieve for container: " 
00311                                         << container << std::endl;           
00312     }
00313     
00314   }
00315 
00316 }
00317 
00318 
00319 // ------------ method called once each job just before starting event loop  ------------
00320 void 
00321 EcalGetLaserData::beginJob()
00322 {
00323 }
00324 
00325 // ------------ method called once each job just after ending the event loop  ------------
00326 void 
00327 EcalGetLaserData::endJob() {
00328 }