CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch9/src/CalibCalorimetry/HcalTPGEventSetup/src/HcalTPGCoderULUT.cc

Go to the documentation of this file.
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.10 2009/10/27 12:06:34 kvtsang Exp $
00017 //
00018 //
00019 
00020 
00021 // system include files
00022 #include <memory>
00023 #include <string>
00024 #include "boost/shared_ptr.hpp"
00025 
00026 // user include files
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 
00036 
00037 //
00038 // class decleration
00039 //
00040 
00041 class HcalTPGCoderULUT : public edm::ESProducer {
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       ReturnType coder_;  
00053       HcaluLUTTPGCoder* theCoder_;
00054       bool read_FGLut_;
00055       edm::FileInPath fgfile_;
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    bool read_Ascii = iConfig.getParameter<bool>("read_Ascii_LUTs");
00072    bool read_XML = iConfig.getParameter<bool>("read_XML_LUTs");
00073    read_FGLut_ = iConfig.getParameter<bool>("read_FG_LUTs"); 
00074    fgfile_ = iConfig.getParameter<edm::FileInPath>("FGLUTs");
00075 
00076    //the following line is needed to tell the framework what
00077    // data is being produced
00078    if (!(read_Ascii || read_XML)) setWhatProduced(this,(dependsOn(&HcalTPGCoderULUT::dbRecordCallback)));
00079    else setWhatProduced(this);
00080   
00081   //now do what ever other initialization is needed
00082    using namespace edm::es;
00083    theCoder_ = new HcaluLUTTPGCoder();
00084    if (read_Ascii || read_XML){
00085       edm::FileInPath ifilename(iConfig.getParameter<edm::FileInPath>("inputLUTs"));
00086       edm::LogInfo("HCAL") << "Using ASCII/XML LUTs" << ifilename.fullPath() << " for HcalTPGCoderULUT initialization";
00087       if (read_Ascii) theCoder_->update(ifilename.fullPath().c_str());
00088       else if (read_XML) theCoder_->updateXML(ifilename.fullPath().c_str());
00089 
00090       // Read FG LUT and append to most significant bit 11
00091       if (read_FGLut_) theCoder_->update(fgfile_.fullPath().c_str(), true);
00092    } 
00093    else {
00094       bool LUTGenerationMode = iConfig.getParameter<bool>("LUTGenerationMode");
00095       int maskBit = iConfig.getParameter<int>("MaskBit");
00096       theCoder_->setLUTGenerationMode(LUTGenerationMode);
00097       theCoder_->setMaskBit(maskBit);
00098    }  
00099    coder_=ReturnType(theCoder_);
00100 }
00101 
00102 
00103 HcalTPGCoderULUT::~HcalTPGCoderULUT()
00104 {
00105  
00106    // do anything here that needs to be done at desctruction time
00107    // (e.g. close files, deallocate resources etc.)
00108 }
00109 
00110 
00111 //
00112 // member functions
00113 //
00114 
00115 // ------------ method called to produce the data  ------------
00116 HcalTPGCoderULUT::ReturnType
00117 HcalTPGCoderULUT::produce(const HcalTPGRecord& iRecord)
00118 {
00119   return coder_;
00120 }
00121 
00122 void HcalTPGCoderULUT::dbRecordCallback(const HcalDbRecord& theRec) {
00123    edm::ESHandle<HcalDbService> conditions;
00124    theRec.get(conditions);
00125    theCoder_->update(*conditions);
00126 
00127    // Temporary update for FG Lut
00128    // Will be moved to DB
00129    if (read_FGLut_) theCoder_->update(fgfile_.fullPath().c_str(), true);
00130 }
00131 
00132 //define this as a plug-in
00133 DEFINE_FWK_EVENTSETUP_MODULE(HcalTPGCoderULUT);