CMS 3D CMS Logo

HcalCPUDigisProducer.cc
Go to the documentation of this file.
1 #include <iostream>
2 
14 
15 class HcalCPUDigisProducer : public edm::stream::EDProducer<edm::ExternalWork> {
16 public:
17  explicit HcalCPUDigisProducer(edm::ParameterSet const& ps);
18  ~HcalCPUDigisProducer() override;
20 
21 private:
23  void produce(edm::Event&, edm::EventSetup const&) override;
24 
25 private:
32 
33  using OProductTypef01 =
36  using OProductTypef5 =
39  using OProductTypef3 =
42 
43  // needed to pass data from acquire to produce
47 };
48 
51 
52  desc.add<edm::InputTag>("digisLabelF01HEIn", edm::InputTag{"hcalRawToDigiGPU", "f01HEDigisGPU"});
53  desc.add<edm::InputTag>("digisLabelF5HBIn", edm::InputTag{"hcalRawToDigiGPU", "f5HBDigisGPU"});
54  desc.add<edm::InputTag>("digisLabelF3HBIn", edm::InputTag{"hcalRawToDigiGPU", "f3HBDigisGPU"});
55  desc.add<std::string>("digisLabelF01HEOut", "f01HEDigis");
56  desc.add<std::string>("digisLabelF5HBOut", "f5HBDigis");
57  desc.add<std::string>("digisLabelF3HBOut", "f3HBDigis");
58 
59  confDesc.addWithDefaultLabel(desc);
60 }
61 
63  : digisF01HETokenIn_{consumes<IProductTypef01>(ps.getParameter<edm::InputTag>("digisLabelF01HEIn"))},
64  digisF5HBTokenIn_{consumes<IProductTypef5>(ps.getParameter<edm::InputTag>("digisLabelF5HBIn"))},
65  digisF3HBTokenIn_{consumes<IProductTypef3>(ps.getParameter<edm::InputTag>("digisLabelF3HBIn"))},
66  digisF01HETokenOut_{produces<OProductTypef01>(ps.getParameter<std::string>("digisLabelF01HEOut"))},
67  digisF5HBTokenOut_{produces<OProductTypef5>(ps.getParameter<std::string>("digisLabelF5HBOut"))},
68  digisF3HBTokenOut_{produces<OProductTypef3>(ps.getParameter<std::string>("digisLabelF3HBOut"))} {}
69 
71 
73  edm::EventSetup const& setup,
75  // retrieve data/ctx
76  auto const& f01HEProduct = event.get(digisF01HETokenIn_);
77  auto const& f5HBProduct = event.get(digisF5HBTokenIn_);
78  auto const& f3HBProduct = event.get(digisF3HBTokenIn_);
79  cms::cuda::ScopedContextAcquire ctx{f01HEProduct, std::move(taskHolder)};
80  auto const& f01HEDigis = ctx.get(f01HEProduct);
81  auto const& f5HBDigis = ctx.get(f5HBProduct);
82  auto const& f3HBDigis = ctx.get(f3HBProduct);
83 
84  // resize out tmp buffers
85  digisf01HE_.stride = f01HEDigis.stride;
86  digisf5HB_.stride = f5HBDigis.stride;
87  digisf3HB_.stride = f3HBDigis.stride;
88  digisf01HE_.resize(f01HEDigis.size);
89  digisf5HB_.resize(f5HBDigis.size);
90  digisf3HB_.resize(f3HBDigis.size);
91 
92  auto lambdaToTransfer = [&ctx](auto& dest, auto* src) {
93  using vector_type = typename std::remove_reference<decltype(dest)>::type;
94  using type = typename vector_type::value_type;
95  using src_data_type = typename std::remove_pointer<decltype(src)>::type;
96  static_assert(std::is_same<src_data_type, type>::value && "Dest and Src data types do not match");
97  cudaCheck(cudaMemcpyAsync(dest.data(), src, dest.size() * sizeof(type), cudaMemcpyDeviceToHost, ctx.stream()));
98  };
99 
100  lambdaToTransfer(digisf01HE_.data, f01HEDigis.data.get());
101  lambdaToTransfer(digisf01HE_.ids, f01HEDigis.ids.get());
102 
103  lambdaToTransfer(digisf5HB_.data, f5HBDigis.data.get());
104  lambdaToTransfer(digisf5HB_.ids, f5HBDigis.ids.get());
105  lambdaToTransfer(digisf5HB_.npresamples, f5HBDigis.npresamples.get());
106 
107  lambdaToTransfer(digisf3HB_.data, f3HBDigis.data.get());
108  lambdaToTransfer(digisf3HB_.ids, f3HBDigis.ids.get());
109 }
110 
112  event.emplace(digisF01HETokenOut_, std::move(digisf01HE_));
113  event.emplace(digisF5HBTokenOut_, std::move(digisf5HB_));
114  event.emplace(digisF3HBTokenOut_, std::move(digisf3HB_));
115 }
116 
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
edm::EDPutTokenT< OProductTypef01 > digisF01HETokenOut_
std::enable_if< std::is_same< T, ::calo::common::tags::Vec >::value, void >::type resize(std::size_t size)
void acquire(edm::Event const &, edm::EventSetup const &, edm::WaitingTaskWithArenaHolder) override
StoragePolicy::template StorageSelector< uint16_t >::type data
edm::EDPutTokenT< OProductTypef3 > digisF3HBTokenOut_
static void fillDescriptions(edm::ConfigurationDescriptions &)
edm::EDGetTokenT< IProductTypef01 > digisF01HETokenIn_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
StoragePolicy::template StorageSelector< uint32_t >::type ids
edm::EDPutTokenT< OProductTypef5 > digisF5HBTokenOut_
void produce(edm::Event &, edm::EventSetup const &) override
#define cudaCheck(ARG,...)
Definition: cudaCheck.h:69
HcalCPUDigisProducer(edm::ParameterSet const &ps)
edm::EDGetTokenT< IProductTypef3 > digisF3HBTokenIn_
def move(src, dest)
Definition: eostools.py:511
Definition: event.py:1
edm::EDGetTokenT< IProductTypef5 > digisF5HBTokenIn_