Go to the documentation of this file.00001 #ifndef JetCorrectionService_h
00002 #define JetCorrectionService_h
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include <memory>
00013 #include <string>
00014 #include "boost/shared_ptr.hpp"
00015
00016
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
00029 #define DEFINE_JET_CORRECTION_SERVICE(corrector_, name_ ) \
00030 typedef JetCorrectionService <corrector_> name_; \
00031 DEFINE_FWK_EVENTSETUP_SOURCE(name_)
00032
00033
00034
00035 template <class Corrector>
00036 class JetCorrectionService : public edm::ESProducer,
00037 public edm::EventSetupRecordIntervalFinder
00038 {
00039 private:
00040
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
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
00068 ~JetCorrectionService () {}
00069
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());
00101 }
00102 };
00103
00104 #endif