CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
HcalCPURecHitsProducer.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <string>
3 
14 
15 class HcalCPURecHitsProducer : public edm::stream::EDProducer<edm::ExternalWork> {
16 public:
17  explicit HcalCPURecHitsProducer(edm::ParameterSet const& ps);
18  ~HcalCPURecHitsProducer() override = default;
19 
21 
22 private:
24  void produce(edm::Event&, edm::EventSetup const&) override;
25 
26 private:
27  const bool produceSoA_;
28  const bool produceLegacy_;
29 
32 
36 
37  // to pass from acquire to produce
39 };
40 
43 
44  desc.add<edm::InputTag>("recHitsM0LabelIn", edm::InputTag{"hbheRecHitProducerGPU"});
45  desc.add<std::string>("recHitsM0LabelOut", "");
46  desc.add<std::string>("recHitsLegacyLabelOut", "");
47  desc.add<bool>("produceSoA", true);
48  desc.add<bool>("produceLegacy", true);
49 
50  confDesc.addWithDefaultLabel(desc);
51 }
52 
54  : produceSoA_{ps.getParameter<bool>("produceSoA")},
55  produceLegacy_{ps.getParameter<bool>("produceLegacy")},
56  recHitsM0TokenIn_{consumes<IProductType>(ps.getParameter<edm::InputTag>("recHitsM0LabelIn"))},
57  recHitsM0TokenOut_{produceSoA_ ? produces<OProductType>(ps.getParameter<std::string>("recHitsM0LabelOut"))
58  : edm::EDPutTokenT<OProductType>{}}, // empty token if disabled
60  ? produces<HBHERecHitCollection>(ps.getParameter<std::string>("recHitsLegacyLabelOut"))
61  : edm::EDPutTokenT<HBHERecHitCollection>{}} // empty token if disabled
62 {}
63 
65  edm::EventSetup const& setup,
67  // retrieve data/ctx
68  auto const& recHitsProduct = event.get(recHitsM0TokenIn_);
69  cms::cuda::ScopedContextAcquire ctx{recHitsProduct, std::move(taskHolder)};
70  auto const& recHits = ctx.get(recHitsProduct);
71 
72  // resize tmp buffers
74 
75 #ifdef HCAL_MAHI_CPUDEBUG
76  std::cout << "num rec Hits = " << recHits.size << std::endl;
77 #endif
78 
79  // do not try to copy the rechits if they are empty
80  if (recHits.size == 0) {
81  return;
82  }
83 
84  auto lambdaToTransfer = [&ctx](auto& dest, auto* src) {
85  using vector_type = typename std::remove_reference<decltype(dest)>::type;
86  using src_data_type = typename std::remove_pointer<decltype(src)>::type;
87  using type = typename vector_type::value_type;
88  static_assert(std::is_same<src_data_type, type>::value && "Dest and Src data types do not match");
89  cudaCheck(cudaMemcpyAsync(dest.data(), src, dest.size() * sizeof(type), cudaMemcpyDeviceToHost, ctx.stream()));
90  };
91 
92  lambdaToTransfer(tmpRecHits_.energy, recHits.energy.get());
93  lambdaToTransfer(tmpRecHits_.chi2, recHits.chi2.get());
94  lambdaToTransfer(tmpRecHits_.energyM0, recHits.energyM0.get());
95  lambdaToTransfer(tmpRecHits_.timeM0, recHits.timeM0.get());
96  lambdaToTransfer(tmpRecHits_.did, recHits.did.get());
97 }
98 
100  if (produceLegacy_) {
101  // populate the legacy collection
102  auto recHitsLegacy = std::make_unique<HBHERecHitCollection>();
103  // did not set size with ctor as there is no setter for did
104  recHitsLegacy->reserve(tmpRecHits_.did.size());
105  for (uint32_t i = 0; i < tmpRecHits_.did.size(); i++) {
106  recHitsLegacy->emplace_back(HcalDetId{tmpRecHits_.did[i]},
108  0 // timeRising
109  );
110 
111  // update newly pushed guy
112  (*recHitsLegacy)[i].setChiSquared(tmpRecHits_.chi2[i]);
113  (*recHitsLegacy)[i].setRawEnergy(tmpRecHits_.energyM0[i]);
114  }
115 
116  // put the legacy collection
117  event.put(recHitsLegacyTokenOut_, std::move(recHitsLegacy));
118  }
119 
120  if (produceSoA_) {
121  // put the SoA collection
122  event.emplace(recHitsM0TokenOut_, std::move(tmpRecHits_));
123  }
124  // clear the temporary collection for the next event
125  tmpRecHits_.resize(0);
126 }
127 
const edm::EDPutTokenT< OProductType > recHitsM0TokenOut_
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
void acquire(edm::Event const &, edm::EventSetup const &, edm::WaitingTaskWithArenaHolder) override
StoragePolicy::template StorageSelector< float >::type chi2
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
StoragePolicy::template StorageSelector< uint32_t >::type did
const edm::EDGetTokenT< IProductType > recHitsM0TokenIn_
static void fillDescriptions(edm::ConfigurationDescriptions &)
StoragePolicy::template StorageSelector< float >::type energy
def move
Definition: eostools.py:511
void produce(edm::Event &, edm::EventSetup const &) override
ParameterDescriptionBase * add(U const &iLabel, T const &value)
const edm::EDPutTokenT< HBHERecHitCollection > recHitsLegacyTokenOut_
HcalCPURecHitsProducer(edm::ParameterSet const &ps)
std::enable_if< std::is_same< U,::calo::common::tags::Vec >::value, void >::type resize(size_t size)
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
tuple cout
Definition: gather_cfg.py:144
#define cudaCheck(ARG,...)
Definition: cudaCheck.h:69
~HcalCPURecHitsProducer() override=default
StoragePolicy::template StorageSelector< float >::type timeM0
StoragePolicy::template StorageSelector< float >::type energyM0