Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2025-01-04 00:29:53

0001 #include "CommonTools/Utils/interface/StringToEnumValue.h"
0002 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0003 
0004 #include "CondFormats/EcalObjects/interface/EcalChannelStatusCode.h"
0005 #include "CondFormats/EcalObjects/interface/EcalRecHitParameters.h"
0006 #include "CondFormats/EcalObjects/interface/alpaka/EcalRecHitParametersDevice.h"
0007 
0008 #include "DataFormats/EcalRecHit/interface/EcalRecHit.h"
0009 
0010 #include "HeterogeneousCore/AlpakaCore/interface/alpaka/ESGetToken.h"
0011 #include "HeterogeneousCore/AlpakaCore/interface/alpaka/ESProducer.h"
0012 #include "HeterogeneousCore/AlpakaCore/interface/alpaka/ModuleFactory.h"
0013 #include "HeterogeneousCore/AlpakaInterface/interface/config.h"
0014 #include "HeterogeneousCore/AlpakaInterface/interface/host.h"
0015 #include "HeterogeneousCore/AlpakaInterface/interface/memory.h"
0016 #include "HeterogeneousCore/CUDACore/interface/JobConfigurationGPURecord.h"
0017 
0018 namespace ALPAKA_ACCELERATOR_NAMESPACE {
0019   class EcalRecHitParametersESProducer : public ESProducer {
0020   public:
0021     EcalRecHitParametersESProducer(edm::ParameterSet const&);
0022     ~EcalRecHitParametersESProducer() override = default;
0023 
0024     static void fillDescriptions(edm::ConfigurationDescriptions&);
0025     std::unique_ptr<EcalRecHitParametersHost> produce(JobConfigurationGPURecord const&);
0026 
0027   private:
0028     std::bitset<kNEcalChannelStatusCodes> channelStatusCodesToBeExcluded_;
0029     RecoFlagBitsArray recoFlagBitsArray_;
0030   };
0031 
0032   EcalRecHitParametersESProducer::EcalRecHitParametersESProducer(edm::ParameterSet const& iConfig)
0033       : ESProducer(iConfig), recoFlagBitsArray_() {
0034     setWhatProduced(this);
0035 
0036     // Translate string representation of ChannelStatusToBeExcluded to enum values and pack into bitset
0037     auto const& channelStatusToBeExcluded = StringToEnumValue<EcalChannelStatusCode::Code>(
0038         iConfig.getParameter<std::vector<std::string>>("ChannelStatusToBeExcluded"));
0039     for (auto const& st : channelStatusToBeExcluded) {
0040       channelStatusCodesToBeExcluded_.set(st);
0041     }
0042 
0043     // Generate map of channel status codes and corresponding recoFlag bits
0044     auto const& fmdbRecoPset = iConfig.getParameter<edm::ParameterSet>("flagsMapDBReco");
0045     auto const& recoFlagStrings = fmdbRecoPset.getParameterNames();
0046     for (auto const& recoFlagString : recoFlagStrings) {
0047       auto const recoFlag = static_cast<EcalRecHit::Flags>(StringToEnumValue<EcalRecHit::Flags>(recoFlagString));
0048       auto const& channelStatusCodeStrings = fmdbRecoPset.getParameter<std::vector<std::string>>(recoFlagString);
0049       for (auto const& channelStatusCodeString : channelStatusCodeStrings) {
0050         auto const chStatCode = StringToEnumValue<EcalChannelStatusCode::Code>(channelStatusCodeString);
0051         // set recoFlagBits for this channel status code
0052         recoFlagBitsArray_.at(chStatCode) = static_cast<uint32_t>(recoFlag);
0053       }
0054     }
0055   }
0056 
0057   void EcalRecHitParametersESProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0058     edm::ParameterSetDescription desc;
0059     // channel statuses to be exluded from reconstruction
0060     desc.add<std::vector<std::string>>("ChannelStatusToBeExcluded",
0061                                        {"kDAC",
0062                                         "kNoisy",
0063                                         "kNNoisy",
0064                                         "kFixedG6",
0065                                         "kFixedG1",
0066                                         "kFixedG0",
0067                                         "kNonRespondingIsolated",
0068                                         "kDeadVFE",
0069                                         "kDeadFE",
0070                                         "kNoDataNoTP"});
0071 
0072     // reco flags association to channel status flags
0073     edm::ParameterSetDescription psd0;
0074     psd0.add<std::vector<std::string>>("kGood", {"kOk", "kDAC", "kNoLaser", "kNoisy"});
0075     psd0.add<std::vector<std::string>>("kNeighboursRecovered", {"kFixedG0", "kNonRespondingIsolated", "kDeadVFE"});
0076     psd0.add<std::vector<std::string>>("kDead", {"kNoDataNoTP"});
0077     psd0.add<std::vector<std::string>>("kNoisy", {"kNNoisy", "kFixedG6", "kFixedG1"});
0078     psd0.add<std::vector<std::string>>("kTowerRecovered", {"kDeadFE"});
0079     desc.add<edm::ParameterSetDescription>("flagsMapDBReco", psd0);
0080 
0081     descriptions.addWithDefaultLabel(desc);
0082   }
0083 
0084   std::unique_ptr<EcalRecHitParametersHost> EcalRecHitParametersESProducer::produce(
0085       JobConfigurationGPURecord const& iRecord) {
0086     auto product = std::make_unique<EcalRecHitParametersHost>(cms::alpakatools::host());
0087     auto value = product->value();
0088 
0089     std::memcpy(value.recoFlagBits.data(), recoFlagBitsArray_.data(), sizeof(uint32_t) * recoFlagBitsArray_.size());
0090 
0091     value.channelStatusCodesToBeExcluded = channelStatusCodesToBeExcluded_;
0092 
0093     return product;
0094   }
0095 
0096 }  // namespace ALPAKA_ACCELERATOR_NAMESPACE
0097 
0098 DEFINE_FWK_EVENTSETUP_ALPAKA_MODULE(EcalRecHitParametersESProducer);