Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-06-05 02:29:28

0001 #include <array>
0002 #include <tuple>
0003 #include <utility>
0004 
0005 #include "CondFormats/EcalObjects/interface/EcalRecHitParametersGPU.h"
0006 #include "CondFormats/EcalObjects/interface/EcalRechitChannelStatusGPU.h"
0007 #include "FWCore/Framework/interface/ESProducer.h"
0008 #include "FWCore/Framework/interface/ESProductHost.h"
0009 #include "FWCore/Framework/interface/ESTransientHandle.h"
0010 #include "FWCore/Framework/interface/EventSetupRecordIntervalFinder.h"
0011 #include "FWCore/Framework/interface/MakerMacros.h"
0012 #include "FWCore/Framework/interface/ModuleFactory.h"
0013 #include "FWCore/Framework/interface/SourceFactory.h"
0014 #include "FWCore/Framework/interface/eventsetuprecord_registration_macro.h"
0015 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0016 #include "FWCore/Utilities/interface/ReusableObjectHolder.h"
0017 #include "FWCore/Utilities/interface/typelookup.h"
0018 #include "HeterogeneousCore/CUDACore/interface/JobConfigurationGPURecord.h"
0019 #include "CommonTools/Utils/interface/StringToEnumValue.h"
0020 #include "DataFormats/EcalRecHit/interface/EcalRecHit.h"
0021 
0022 class EcalRecHitParametersGPUESProducer : public edm::ESProducer, public edm::EventSetupRecordIntervalFinder {
0023 public:
0024   EcalRecHitParametersGPUESProducer(edm::ParameterSet const&);
0025   ~EcalRecHitParametersGPUESProducer() override = default;
0026 
0027   static void fillDescriptions(edm::ConfigurationDescriptions&);
0028   std::unique_ptr<EcalRecHitParametersGPU> produce(JobConfigurationGPURecord const&);
0029 
0030 protected:
0031   void setIntervalFor(const edm::eventsetup::EventSetupRecordKey&,
0032                       const edm::IOVSyncValue&,
0033                       edm::ValidityInterval&) override;
0034 
0035 private:
0036   edm::ParameterSet const pset_;
0037 };
0038 
0039 EcalRecHitParametersGPUESProducer::EcalRecHitParametersGPUESProducer(edm::ParameterSet const& pset) : pset_{pset} {
0040   setWhatProduced(this);
0041   findingRecord<JobConfigurationGPURecord>();
0042 }
0043 
0044 void EcalRecHitParametersGPUESProducer::setIntervalFor(const edm::eventsetup::EventSetupRecordKey& iKey,
0045                                                        const edm::IOVSyncValue& iTime,
0046                                                        edm::ValidityInterval& oInterval) {
0047   oInterval = edm::ValidityInterval(edm::IOVSyncValue::beginOfTime(), edm::IOVSyncValue::endOfTime());
0048 }
0049 
0050 void EcalRecHitParametersGPUESProducer::fillDescriptions(edm::ConfigurationDescriptions& desc) {
0051   edm::ParameterSetDescription d;
0052 
0053   //---- db statuses to be exluded from reconstruction
0054   d.add<std::vector<std::string>>("ChannelStatusToBeExcluded",
0055                                   {
0056                                       "kDAC",
0057                                       "kNoisy",
0058                                       "kNNoisy",
0059                                       "kFixedG6",
0060                                       "kFixedG1",
0061                                       "kFixedG0",
0062                                       "kNonRespondingIsolated",
0063                                       "kDeadVFE",
0064                                       "kDeadFE",
0065                                       "kNoDataNoTP",
0066                                   });
0067 
0068   // reco flags association to DB flag
0069   edm::ParameterSetDescription desc_list_flagsMapDBReco;
0070   desc_list_flagsMapDBReco.add<std::vector<std::string>>("kGood", {"kOk", "kDAC", "kNoLaser", "kNoisy"});
0071   desc_list_flagsMapDBReco.add<std::vector<std::string>>("kNoisy", {"kNNoisy", "kFixedG6", "kFixedG1"});
0072   desc_list_flagsMapDBReco.add<std::vector<std::string>>("kNeighboursRecovered",
0073                                                          {"kFixedG0", "kNonRespondingIsolated", "kDeadVFE"});
0074   desc_list_flagsMapDBReco.add<std::vector<std::string>>("kTowerRecovered", {"kDeadFE"});
0075   desc_list_flagsMapDBReco.add<std::vector<std::string>>("kDead", {"kNoDataNoTP"});
0076 
0077   d.add<edm::ParameterSetDescription>("flagsMapDBReco", desc_list_flagsMapDBReco);
0078 
0079   desc.addWithDefaultLabel(d);
0080 }
0081 
0082 std::unique_ptr<EcalRecHitParametersGPU> EcalRecHitParametersGPUESProducer::produce(JobConfigurationGPURecord const&) {
0083   auto const& channelStatusToBeExcluded = StringToEnumValue<EcalChannelStatusCode::Code>(
0084       pset_.getParameter<std::vector<std::string>>("ChannelStatusToBeExcluded"));
0085 
0086   //     https://github.com/cms-sw/cmssw/blob/266e21cfc9eb409b093e4cf064f4c0a24c6ac293/RecoLocalCalo/EcalRecProducers/plugins/EcalRecHitWorkerSimple.cc
0087 
0088   // Translate string representation of flagsMapDBReco into enum values
0089   const edm::ParameterSet& p = pset_.getParameter<edm::ParameterSet>("flagsMapDBReco");
0090   std::vector<std::string> recoflagbitsStrings = p.getParameterNames();
0091 
0092   std::vector<EcalRecHitParametersGPU::DBStatus> status;
0093   status.reserve(recoflagbitsStrings.size());
0094   for (auto const& recoflagbitsString : recoflagbitsStrings) {
0095     EcalRecHit::Flags recoflagbit = (EcalRecHit::Flags)StringToEnumValue<EcalRecHit::Flags>(recoflagbitsString);
0096     std::vector<std::string> dbstatus_s = p.getParameter<std::vector<std::string>>(recoflagbitsString);
0097 
0098     std::vector<uint32_t> db_reco_flags;
0099     db_reco_flags.reserve(dbstatus_s.size());
0100     for (auto const& dbstatusString : dbstatus_s) {
0101       EcalChannelStatusCode::Code dbstatus =
0102           (EcalChannelStatusCode::Code)StringToEnumValue<EcalChannelStatusCode::Code>(dbstatusString);
0103       db_reco_flags.push_back(dbstatus);
0104     }
0105     status.emplace_back(static_cast<int>(recoflagbit), db_reco_flags);
0106   }
0107 
0108   return std::make_unique<EcalRecHitParametersGPU>(channelStatusToBeExcluded, status);
0109 }
0110 
0111 DEFINE_FWK_EVENTSETUP_SOURCE(EcalRecHitParametersGPUESProducer);