Go to the documentation of this file.00001
00002
00003
00004
00005
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <memory>
00023 #include <string>
00024 #include "boost/shared_ptr.hpp"
00025
00026
00027
00028 #include "FWCore/Framework/interface/ModuleFactory.h"
00029 #include "FWCore/Framework/interface/ESProducer.h"
00030
00031 #include "FWCore/Framework/interface/ESHandle.h"
00032 #include "CalibCalorimetry/HcalTPGAlgos/interface/HcaluLUTTPGCoder.h"
00033 #include "CalibFormats/HcalObjects/interface/HcalTPGRecord.h"
00034 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00035 #include "Geometry/CaloTopology/interface/HcalTopology.h"
00036 #include "CalibFormats/HcalObjects/interface/HcalDbService.h"
00037
00038
00039
00040
00041
00042 class HcalTPGCoderULUT : public edm::ESProducer {
00043 public:
00044 HcalTPGCoderULUT(const edm::ParameterSet&);
00045 ~HcalTPGCoderULUT();
00046
00047 typedef boost::shared_ptr<HcalTPGCoder> ReturnType;
00048 void dbRecordCallback(const HcalDbRecord&);
00049
00050 ReturnType produce(const HcalTPGRecord&);
00051 private:
00052 void buildCoder(const HcalTopology*);
00053
00054 ReturnType coder_;
00055 HcaluLUTTPGCoder* theCoder_;
00056 bool read_FGLut_, read_Ascii_,read_XML_,LUTGenerationMode_;
00057 int maskBit_;
00058 edm::FileInPath fgfile_,ifilename_;
00059 };
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072 HcalTPGCoderULUT::HcalTPGCoderULUT(const edm::ParameterSet& iConfig)
00073 {
00074 read_Ascii_ = iConfig.getParameter<bool>("read_Ascii_LUTs");
00075 read_XML_ = iConfig.getParameter<bool>("read_XML_LUTs");
00076 read_FGLut_ = iConfig.getParameter<bool>("read_FG_LUTs");
00077 fgfile_ = iConfig.getParameter<edm::FileInPath>("FGLUTs");
00078
00079
00080 if (!(read_Ascii_ || read_XML_)) {
00081 setWhatProduced(this,(dependsOn(&HcalTPGCoderULUT::dbRecordCallback)));
00082 LUTGenerationMode_ = iConfig.getParameter<bool>("LUTGenerationMode");
00083 maskBit_ = iConfig.getParameter<int>("MaskBit");
00084 } else {
00085 ifilename_=iConfig.getParameter<edm::FileInPath>("inputLUTs");
00086 setWhatProduced(this);
00087 }
00088
00089 theCoder_=0;
00090 }
00091
00092
00093 void HcalTPGCoderULUT::buildCoder(const HcalTopology* topo) {
00094 using namespace edm::es;
00095 theCoder_ = new HcaluLUTTPGCoder();
00096 if (read_Ascii_ || read_XML_){
00097 edm::LogInfo("HCAL") << "Using ASCII/XML LUTs" << ifilename_.fullPath() << " for HcalTPGCoderULUT initialization";
00098 if (read_Ascii_) {
00099 theCoder_->update(ifilename_.fullPath().c_str(),*topo);
00100 } else if (read_XML_) theCoder_->updateXML(ifilename_.fullPath().c_str(),*topo);
00101
00102
00103 if (read_FGLut_) {
00104 theCoder_->update(fgfile_.fullPath().c_str(), *topo,true);
00105 }
00106 } else {
00107 theCoder_->setLUTGenerationMode(LUTGenerationMode_);
00108 theCoder_->setMaskBit(maskBit_);
00109 }
00110 coder_=ReturnType(theCoder_);
00111 }
00112
00113
00114 HcalTPGCoderULUT::~HcalTPGCoderULUT()
00115 {
00116
00117
00118
00119 }
00120
00121
00122
00123
00124
00125
00126
00127 HcalTPGCoderULUT::ReturnType
00128 HcalTPGCoderULUT::produce(const HcalTPGRecord& iRecord)
00129 {
00130 if (theCoder_==0) {
00131 edm::ESHandle<HcalTopology> htopo;
00132 iRecord.getRecord<IdealGeometryRecord>().get(htopo);
00133 const HcalTopology* topo=&(*htopo);
00134 buildCoder(topo);
00135 }
00136
00137
00138 return coder_;
00139 }
00140
00141 void HcalTPGCoderULUT::dbRecordCallback(const HcalDbRecord& theRec) {
00142 edm::ESHandle<HcalDbService> conditions;
00143 theRec.get(conditions);
00144 const HcalTopology* topo=conditions->getTopologyUsed();
00145
00146 if (theCoder_==0) {
00147 buildCoder(topo);
00148 }
00149
00150 theCoder_->update(*conditions);
00151
00152
00153
00154 if (read_FGLut_) theCoder_->update(fgfile_.fullPath().c_str(),*topo,true);
00155 }
00156
00157
00158 DEFINE_FWK_EVENTSETUP_MODULE(HcalTPGCoderULUT);