CMS 3D CMS Logo

EcalCPUUncalibRecHitProducer.cc
Go to the documentation of this file.
1 #include <iostream>
2 
3 // framework
5 
12 
13 // algorithm specific
14 
16 
18 
19 class EcalCPUUncalibRecHitProducer : public edm::stream::EDProducer<edm::ExternalWork> {
20 public:
24 
25 private:
27  void produce(edm::Event&, edm::EventSetup const&) override;
28 
29 private:
34 
37 };
38 
41 
42  desc.add<edm::InputTag>("recHitsInLabelEB", edm::InputTag{"ecalUncalibRecHitProducerGPU", "EcalUncalibRecHitsEB"});
43  desc.add<edm::InputTag>("recHitsInLabelEE", edm::InputTag{"ecalUncalibRecHitProducerGPU", "EcalUncalibRecHitsEE"});
44  desc.add<std::string>("recHitsOutLabelEB", "EcalUncalibRecHitsEB");
45  desc.add<std::string>("recHitsOutLabelEE", "EcalUncalibRecHitsEE");
46  desc.add<bool>("containsTimingInformation", false);
47 
48  confDesc.add("ecalCPUUncalibRecHitProducer", desc);
49 }
50 
52  : recHitsInEBToken_{consumes<InputProduct>(ps.getParameter<edm::InputTag>("recHitsInLabelEB"))},
53  recHitsInEEToken_{consumes<InputProduct>(ps.getParameter<edm::InputTag>("recHitsInLabelEE"))},
54  recHitsOutEBToken_{produces<OutputProduct>(ps.getParameter<std::string>("recHitsOutLabelEB"))},
55  recHitsOutEEToken_{produces<OutputProduct>(ps.getParameter<std::string>("recHitsOutLabelEE"))},
56  containsTimingInformation_{ps.getParameter<bool>("containsTimingInformation")} {}
57 
59 
61  edm::EventSetup const& setup,
63  // retrieve data/ctx
64  auto const& ebRecHitsProduct = event.get(recHitsInEBToken_);
65  auto const& eeRecHitsProduct = event.get(recHitsInEEToken_);
66  cms::cuda::ScopedContextAcquire ctx{ebRecHitsProduct, std::move(taskHolder)};
67  auto const& ebRecHits = ctx.get(ebRecHitsProduct);
68  auto const& eeRecHits = ctx.get(eeRecHitsProduct);
69 
70  // resize the output buffers
71  recHitsEB_.resize(ebRecHits.size);
72  recHitsEE_.resize(eeRecHits.size);
73 
74  auto lambdaToTransfer = [&ctx](auto& dest, auto* src) {
75  using vector_type = typename std::remove_reference<decltype(dest)>::type;
76  using type = typename vector_type::value_type;
77  using src_type = typename std::remove_pointer<decltype(src)>::type;
78  static_assert(std::is_same<src_type, type>::value && "dst and src data types do not match");
79  cudaCheck(cudaMemcpyAsync(dest.data(), src, dest.size() * sizeof(type), cudaMemcpyDeviceToHost, ctx.stream()));
80  };
81 
82  // enqeue transfers
83  lambdaToTransfer(recHitsEB_.did, ebRecHits.did.get());
84  lambdaToTransfer(recHitsEE_.did, eeRecHits.did.get());
85 
86  lambdaToTransfer(recHitsEB_.amplitudesAll, ebRecHits.amplitudesAll.get());
87  lambdaToTransfer(recHitsEE_.amplitudesAll, eeRecHits.amplitudesAll.get());
88 
89  lambdaToTransfer(recHitsEB_.amplitude, ebRecHits.amplitude.get());
90  lambdaToTransfer(recHitsEE_.amplitude, eeRecHits.amplitude.get());
91 
92  lambdaToTransfer(recHitsEB_.chi2, ebRecHits.chi2.get());
93  lambdaToTransfer(recHitsEE_.chi2, eeRecHits.chi2.get());
94 
95  lambdaToTransfer(recHitsEB_.pedestal, ebRecHits.pedestal.get());
96  lambdaToTransfer(recHitsEE_.pedestal, eeRecHits.pedestal.get());
97 
98  lambdaToTransfer(recHitsEB_.flags, ebRecHits.flags.get());
99  lambdaToTransfer(recHitsEE_.flags, eeRecHits.flags.get());
100 
102  lambdaToTransfer(recHitsEB_.jitter, ebRecHits.jitter.get());
103  lambdaToTransfer(recHitsEE_.jitter, eeRecHits.jitter.get());
104 
105  lambdaToTransfer(recHitsEB_.jitterError, ebRecHits.jitterError.get());
106  lambdaToTransfer(recHitsEE_.jitterError, eeRecHits.jitterError.get());
107  }
108 }
109 
111  // tmp vectors
112  auto recHitsOutEB = std::make_unique<OutputProduct>(std::move(recHitsEB_));
113  auto recHitsOutEE = std::make_unique<OutputProduct>(std::move(recHitsEE_));
114 
115  // put into event
116  event.put(recHitsOutEBToken_, std::move(recHitsOutEB));
117  event.put(recHitsOutEEToken_, std::move(recHitsOutEE));
118 }
119 
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
edm::EDPutTokenT< OutputProduct > recHitsOutEEToken_
void acquire(edm::Event const &, edm::EventSetup const &, edm::WaitingTaskWithArenaHolder) override
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::EDGetTokenT< InputProduct > recHitsInEEToken_
edm::EDGetTokenT< InputProduct > recHitsInEBToken_
std::enable_if< std::is_same< U, ::calo::common::tags::Vec >::value, void >::type resize(size_t size)
edm::EDPutTokenT< OutputProduct > recHitsOutEBToken_
StoragePolicy::template StorageSelector< reco::StorageScalarType >::type jitterError
StoragePolicy::template StorageSelector< uint32_t >::type flags
StoragePolicy::template StorageSelector< uint32_t >::type did
static void fillDescriptions(edm::ConfigurationDescriptions &)
void produce(edm::Event &, edm::EventSetup const &) override
StoragePolicy::template StorageSelector< reco::ComputationScalarType >::type amplitudesAll
void add(std::string const &label, ParameterSetDescription const &psetDescription)
StoragePolicy::template StorageSelector< reco::StorageScalarType >::type amplitude
StoragePolicy::template StorageSelector< reco::StorageScalarType >::type jitter
StoragePolicy::template StorageSelector< reco::StorageScalarType >::type chi2
#define cudaCheck(ARG,...)
Definition: cudaCheck.h:69
EcalCPUUncalibRecHitProducer(edm::ParameterSet const &ps)
def move(src, dest)
Definition: eostools.py:511
Definition: event.py:1
StoragePolicy::template StorageSelector< reco::StorageScalarType >::type pedestal