00001 // -*- C++ -*- 00002 // 00003 // Package: HcalTPGCoderULUT 00004 // Class: HcalTPGCoderULUT 00005 // 00013 // 00014 // Original Author: Jeremiah Mans 00015 // Created: Fri Sep 15 11:49:44 CDT 2006 00016 // $Id: HcalTPGCoderULUT.cc,v 1.6 2008/01/30 08:44:17 tulika Exp $ 00017 // 00018 // 00019 00020 00021 // system include files 00022 #include <memory> 00023 #include "boost/shared_ptr.hpp" 00024 00025 // user include files 00026 00027 #include "FWCore/Framework/interface/ModuleFactory.h" 00028 #include "FWCore/Framework/interface/ESProducer.h" 00029 00030 #include "FWCore/Framework/interface/ESHandle.h" 00031 #include "CalibCalorimetry/HcalTPGAlgos/interface/HcaluLUTTPGCoder.h" 00032 #include "CalibFormats/HcalObjects/interface/HcalTPGRecord.h" 00033 #include "FWCore/MessageLogger/interface/MessageLogger.h" 00034 00035 00036 // 00037 // class decleration 00038 // 00039 00040 class HcalTPGCoderULUT : public edm::ESProducer { 00041 00042 public: 00043 HcalTPGCoderULUT(const edm::ParameterSet&); 00044 ~HcalTPGCoderULUT(); 00045 00046 typedef boost::shared_ptr<HcalTPGCoder> ReturnType; 00047 void dbRecordCallback(const HcalDbRecord&); 00048 00049 ReturnType produce(const HcalTPGRecord&); 00050 private: 00051 // ----------member data --------------------------- 00052 edm::FileInPath *ifilename_; 00053 ReturnType coder_; 00054 HcaluLUTTPGCoder* theCoder; 00055 bool read_Ascii; 00056 }; 00057 00058 // 00059 // constants, enums and typedefs 00060 // 00061 00062 // 00063 // static data member definitions 00064 // 00065 00066 // 00067 // constructors and destructor 00068 // 00069 HcalTPGCoderULUT::HcalTPGCoderULUT(const edm::ParameterSet& iConfig) 00070 { 00071 /* 00072 ifilename_=0; 00073 try { 00074 ofilename_=new edm::FileInPath(iConfig.getParameter<edm::FileInPath>("outputLUTs")); 00075 } catch (...) { 00076 ifilename_=new edm::FileInPath(iConfig.getParameter<edm::FileInPath>("filename")); 00077 ofilename_=0; 00078 } 00079 */ 00080 read_Ascii=false; 00081 read_Ascii=iConfig.getParameter<bool>("read_Ascii_LUTs"); 00082 if (read_Ascii==true) ifilename_=new edm::FileInPath(iConfig.getParameter<edm::FileInPath>("inputLUTs")); 00083 else ifilename_=new edm::FileInPath(iConfig.getParameter<edm::FileInPath>("filename")); 00084 00085 00086 //the following line is needed to tell the framework what 00087 // data is being produced 00088 if (read_Ascii==false) setWhatProduced(this,(dependsOn(&HcalTPGCoderULUT::dbRecordCallback))); 00089 else setWhatProduced(this); 00090 00091 00092 //now do what ever other initialization is needed 00093 using namespace edm::es; 00094 if (read_Ascii==true){ 00095 edm::LogInfo("HCAL") << "Using ASCII LUTs" << ifilename_->fullPath() << " for HcalTPGCoderULUT initialization"; 00096 theCoder=new HcaluLUTTPGCoder(ifilename_->fullPath().c_str(),read_Ascii); 00097 coder_=ReturnType(theCoder); 00098 } 00099 else { 00100 edm::LogInfo("HCAL") << "Using " << ifilename_->fullPath() << " for HcalTPGCoderULUT initialization"; 00101 theCoder=new HcaluLUTTPGCoder(ifilename_->fullPath().c_str(),read_Ascii); 00102 coder_=ReturnType(theCoder); 00103 } 00104 } 00105 00106 00107 HcalTPGCoderULUT::~HcalTPGCoderULUT() 00108 { 00109 00110 // do anything here that needs to be done at desctruction time 00111 // (e.g. close files, deallocate resources etc.) 00112 00113 00114 if (ifilename_!=0) delete ifilename_; 00115 } 00116 00117 00118 // 00119 // member functions 00120 // 00121 00122 // ------------ method called to produce the data ------------ 00123 HcalTPGCoderULUT::ReturnType 00124 HcalTPGCoderULUT::produce(const HcalTPGRecord& iRecord) 00125 { 00126 return coder_; 00127 } 00128 00129 void HcalTPGCoderULUT::dbRecordCallback(const HcalDbRecord& theRec) { 00130 edm::ESHandle<HcalDbService> conditions; 00131 theRec.get(conditions); 00132 theCoder->update(*conditions); 00133 } 00134 00135 //define this as a plug-in 00136 DEFINE_FWK_EVENTSETUP_MODULE(HcalTPGCoderULUT);