CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/JetMETCorrections/Modules/interface/JetCorrectionService.h

Go to the documentation of this file.
00001 #ifndef JetCorrectionService_h
00002 #define JetCorrectionService_h
00003 
00004 //
00005 // Original Author:  Fedor Ratnikov
00006 //         Created:  Dec. 28, 2006
00007 // $Id: JetCorrectionService.h,v 1.10 2010/10/26 11:46:29 kkousour Exp $
00008 //
00009 //
00010 
00011 // system include files
00012 #include <memory>
00013 #include <string>
00014 #include "boost/shared_ptr.hpp"
00015 
00016 // user include files
00017 #include "FWCore/Framework/interface/ModuleFactory.h"
00018 #include "FWCore/Framework/interface/ESProducer.h"
00019 #include "FWCore/Framework/interface/EventSetup.h"
00020 #include "FWCore/Framework/interface/EventSetupRecordIntervalFinder.h"
00021 #include "FWCore/Framework/interface/ESHandle.h"
00022 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00023 #include "FWCore/ParameterSet/interface/FileInPath.h"
00024 #include "CondFormats/JetMETObjects/interface/JetCorrectorParameters.h"
00025 #include "JetMETCorrections/Objects/interface/JetCorrector.h"
00026 #include "JetMETCorrections/Objects/interface/JetCorrectionsRecord.h"
00027 
00028 // macro to define instance of JetCorrectionService
00029 #define DEFINE_JET_CORRECTION_SERVICE(corrector_, name_ ) \
00030 typedef JetCorrectionService <corrector_>  name_; \
00031 DEFINE_FWK_EVENTSETUP_SOURCE(name_)
00032 
00033 
00034 // Correction Service itself
00035 template <class Corrector>
00036 class JetCorrectionService : public edm::ESProducer,
00037                              public edm::EventSetupRecordIntervalFinder
00038 {
00039   private:
00040     //boost::shared_ptr<JetCorrector> mCorrector;
00041     edm::ParameterSet mParameterSet;
00042     std::string mLevel;
00043     std::string mEra;
00044     std::string mAlgo;
00045     std::string mSection;
00046     std::string mPayloadName;
00047     bool mUseCondDB;
00048     bool mDebug;
00049 
00050   public:
00051     //------------- construction ---------------------------------------
00052     JetCorrectionService(const edm::ParameterSet& fConfig) : mParameterSet(fConfig) 
00053       {
00054         std::string label = fConfig.getParameter<std::string>("@module_label"); 
00055         mLevel            = fConfig.getParameter<std::string>("level");
00056         mEra              = fConfig.getParameter<std::string>("era");
00057         mAlgo             = fConfig.getParameter<std::string>("algorithm");
00058         mSection          = fConfig.getParameter<std::string>("section");
00059         mUseCondDB        = fConfig.getUntrackedParameter<bool>("useCondDB",false);
00060         mDebug            = fConfig.getUntrackedParameter<bool>("debug",false);
00061         mPayloadName = mAlgo;
00062         
00063         setWhatProduced(this, label);
00064         findingRecord <JetCorrectionsRecord> ();
00065 
00066       }
00067     //------------- destruction ----------------------------------------
00068     ~JetCorrectionService () {}
00069     //------------- member functions -----------------------------------
00070     boost::shared_ptr<JetCorrector> produce(const JetCorrectionsRecord& iRecord) 
00071       {
00072         if (mUseCondDB)
00073           {
00074             edm::ESHandle<JetCorrectorParametersCollection> JetCorParColl;
00075             iRecord.get(mPayloadName,JetCorParColl); 
00076             JetCorrectorParameters const & JetCorPar = (*JetCorParColl)[ mLevel ];
00077             boost::shared_ptr<JetCorrector> mCorrector(new Corrector(JetCorPar,mParameterSet));
00078             return mCorrector;
00079           }
00080         else
00081           {
00082             std::string fileName("CondFormats/JetMETObjects/data/");
00083             if (!mEra.empty())
00084               fileName += mEra;
00085             if (!mLevel.empty())
00086               fileName += "_"+mLevel;
00087             if (!mAlgo.empty())
00088               fileName += "_"+mAlgo;
00089             fileName += ".txt";
00090             if (mDebug)
00091               std::cout<<"Parameter File: "<<fileName<<std::endl;
00092             edm::FileInPath fip(fileName);
00093             JetCorrectorParameters *tmpJetCorPar = new JetCorrectorParameters(fip.fullPath(),mSection);
00094             boost::shared_ptr<JetCorrector> mCorrector(new Corrector(*tmpJetCorPar,mParameterSet));
00095             return mCorrector;
00096           }
00097       }
00098     void setIntervalFor(const edm::eventsetup::EventSetupRecordKey&,const edm::IOVSyncValue&,edm::ValidityInterval& fIOV)
00099       {
00100         fIOV = edm::ValidityInterval(edm::IOVSyncValue::beginOfTime(),edm::IOVSyncValue::endOfTime()); // anytime
00101       }
00102 };
00103 
00104 #endif