File indexing completed on 2024-07-03 04:18:11
0001 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0002 #include "FWCore/Utilities/interface/ESGetToken.h"
0003
0004 #include "CondFormats/HcalObjects/interface/alpaka/HcalSiPMCharacteristicsDevice.h"
0005 #include "CondFormats/HcalObjects/interface/HcalSiPMCharacteristicsSoA.h"
0006 #include "CondFormats/DataRecord/interface/HcalSiPMCharacteristicsRcd.h"
0007
0008 #include "HeterogeneousCore/AlpakaCore/interface/alpaka/ESProducer.h"
0009 #include "HeterogeneousCore/AlpakaCore/interface/alpaka/ModuleFactory.h"
0010 #include "HeterogeneousCore/AlpakaInterface/interface/config.h"
0011 #include "HeterogeneousCore/AlpakaInterface/interface/host.h"
0012 #include "HeterogeneousCore/AlpakaInterface/interface/memory.h"
0013
0014 namespace ALPAKA_ACCELERATOR_NAMESPACE {
0015 class HcalSiPMCharacteristicsESProducer : public ESProducer {
0016 public:
0017 HcalSiPMCharacteristicsESProducer(edm::ParameterSet const& iConfig) : ESProducer(iConfig) {
0018 auto cc = setWhatProduced(this);
0019 sipmCharacteristicsToken_ = cc.consumes();
0020 }
0021
0022 static void fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0023 edm::ParameterSetDescription desc;
0024 descriptions.addWithDefaultLabel(desc);
0025 }
0026
0027 std::unique_ptr<hcal::HcalSiPMCharacteristicsPortableHost> produce(HcalSiPMCharacteristicsRcd const& iRecord) {
0028 auto const& sipmCharacteristics = iRecord.get(sipmCharacteristicsToken_);
0029
0030 size_t const totalItems = sipmCharacteristics.getTypes();
0031
0032 auto product = std::make_unique<hcal::HcalSiPMCharacteristicsPortableHost>(totalItems, cms::alpakatools::host());
0033
0034 auto view = product->view();
0035
0036 for (uint32_t i = 0; i < sipmCharacteristics.getTypes(); i++) {
0037 auto vi = view[i];
0038 auto const type = sipmCharacteristics.getType(i);
0039
0040
0041 if (static_cast<uint32_t>(type) != i + 1)
0042 throw cms::Exception("HcalSiPMCharacteristics")
0043 << "Wrong assumption for HcalSiPMcharacteristics type values, "
0044 << "should be type value <- type index + 1" << std::endl
0045 << "Observed type value = " << type << " and index = " << i << std::endl;
0046
0047 vi.precisionItem() = HcalSiPMCharacteristics::PrecisionItem(type,
0048 sipmCharacteristics.getPixels(type),
0049 sipmCharacteristics.getNonLinearities(type)[0],
0050 sipmCharacteristics.getNonLinearities(type)[1],
0051 sipmCharacteristics.getNonLinearities(type)[2],
0052 sipmCharacteristics.getCrossTalk(type),
0053 sipmCharacteristics.getAuxi1(type),
0054 sipmCharacteristics.getAuxi2(type));
0055 }
0056 return product;
0057 }
0058
0059 private:
0060 edm::ESGetToken<HcalSiPMCharacteristics, HcalSiPMCharacteristicsRcd> sipmCharacteristicsToken_;
0061 };
0062 }
0063
0064 DEFINE_FWK_EVENTSETUP_ALPAKA_MODULE(HcalSiPMCharacteristicsESProducer);