Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:25:40

0001 #include <memory>
0002 #include "FWCore/Framework/interface/ModuleFactory.h"
0003 #include "FWCore/Framework/interface/ESProducer.h"
0004 #include "FWCore/Framework/interface/ESProductHost.h"
0005 #include "FWCore/Framework/interface/ESHandle.h"
0006 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0007 #include "FWCore/Utilities/interface/ReusableObjectHolder.h"
0008 #include "RecoLocalCalo/EcalRecAlgos/interface/EcalSeverityLevelAlgoRcd.h"
0009 #include "CondFormats/DataRecord/interface/EcalChannelStatusRcd.h"
0010 #include "RecoLocalCalo/EcalRecAlgos/interface/EcalSeverityLevelAlgo.h"
0011 
0012 /*
0013   Provide  a hook to retrieve the EcalSeverityLevelAlgo
0014   through the EventSetup 
0015  
0016   Appartently there is no smarter way to do it in CMSSW
0017 
0018   Author: Stefano Argiro
0019  */
0020 
0021 class EcalSeverityLevelESProducer : public edm::ESProducer {
0022 public:
0023   EcalSeverityLevelESProducer(const edm::ParameterSet& iConfig);
0024 
0025   typedef std::shared_ptr<EcalSeverityLevelAlgo> ReturnType;
0026 
0027   ReturnType produce(const EcalSeverityLevelAlgoRcd& iRecord);
0028 
0029 private:
0030   void setupChannelStatus(const EcalChannelStatusRcd&, EcalSeverityLevelAlgo*);
0031 
0032   using HostType = edm::ESProductHost<EcalSeverityLevelAlgo, EcalChannelStatusRcd>;
0033 
0034   edm::ReusableObjectHolder<HostType> holder_;
0035   edm::ParameterSet const pset_;
0036   edm::ESGetToken<EcalChannelStatus, EcalChannelStatusRcd> const channelToken_;
0037 };
0038 
0039 EcalSeverityLevelESProducer::EcalSeverityLevelESProducer(const edm::ParameterSet& iConfig)
0040     : pset_(iConfig), channelToken_(setWhatProduced(this).consumesFrom<EcalChannelStatus, EcalChannelStatusRcd>()) {}
0041 
0042 EcalSeverityLevelESProducer::ReturnType EcalSeverityLevelESProducer::produce(const EcalSeverityLevelAlgoRcd& iRecord) {
0043   auto host = holder_.makeOrGet([this]() { return new HostType(pset_); });
0044 
0045   host->ifRecordChanges<EcalChannelStatusRcd>(iRecord,
0046                                               [this, h = host.get()](auto const& rec) { setupChannelStatus(rec, h); });
0047 
0048   return host;
0049 }
0050 
0051 void EcalSeverityLevelESProducer::setupChannelStatus(const EcalChannelStatusRcd& chs, EcalSeverityLevelAlgo* algo) {
0052   algo->setChannelStatus(chs.get(channelToken_));
0053 }
0054 
0055 //define this as a plug-in
0056 DEFINE_FWK_EVENTSETUP_MODULE(EcalSeverityLevelESProducer);