CMS 3D CMS Logo

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
59  recHitsLegacyTokenOut_{produceLegacy_
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  auto lambdaToTransfer = [&ctx](auto& dest, auto* src) {
80  using vector_type = typename std::remove_reference<decltype(dest)>::type;
81  using src_data_type = typename std::remove_pointer<decltype(src)>::type;
82  using type = typename vector_type::value_type;
83  static_assert(std::is_same<src_data_type, type>::value && "Dest and Src data types do not match");
84  cudaCheck(cudaMemcpyAsync(dest.data(), src, dest.size() * sizeof(type), cudaMemcpyDeviceToHost, ctx.stream()));
85  };
86 
87  lambdaToTransfer(tmpRecHits_.energy, recHits.energy.get());
88  lambdaToTransfer(tmpRecHits_.chi2, recHits.chi2.get());
89  lambdaToTransfer(tmpRecHits_.energyM0, recHits.energyM0.get());
90  lambdaToTransfer(tmpRecHits_.timeM0, recHits.timeM0.get());
91  lambdaToTransfer(tmpRecHits_.did, recHits.did.get());
92 }
93 
95  if (produceLegacy_) {
96  // populate the legacy collection
97  auto recHitsLegacy = std::make_unique<HBHERecHitCollection>();
98  // did not set size with ctor as there is no setter for did
99  recHitsLegacy->reserve(tmpRecHits_.did.size());
100  for (uint32_t i = 0; i < tmpRecHits_.did.size(); i++) {
101  recHitsLegacy->emplace_back(HcalDetId{tmpRecHits_.did[i]},
103  0 // timeRising
104  );
105 
106  // update newly pushed guy
107  (*recHitsLegacy)[i].setChiSquared(tmpRecHits_.chi2[i]);
108  (*recHitsLegacy)[i].setRawEnergy(tmpRecHits_.energyM0[i]);
109  }
110 
111  // put the legacy collection
112  event.put(recHitsLegacyTokenOut_, std::move(recHitsLegacy));
113  }
114 
115  if (produceSoA_) {
116  // put the SoA collection
117  event.emplace(recHitsM0TokenOut_, std::move(tmpRecHits_));
118  }
119  // clear the temporary collection for the next event
120  tmpRecHits_.resize(0);
121 }
122 
hcal::RecHitCollection::timeM0
StoragePolicy::template StorageSelector< float >::type timeM0
Definition: RecHitCollection.h:23
hcal::RecHitCollection::resize
std::enable_if< std::is_same< U, ::calo::common::tags::Vec >::value, void >::type resize(size_t size)
Definition: RecHitCollection.h:27
mps_fire.i
i
Definition: mps_fire.py:428
RecHitCollection.h
HcalCPURecHitsProducer::produce
void produce(edm::Event &, edm::EventSetup const &) override
Definition: HcalCPURecHitsProducer.cc:94
HcalCPURecHitsProducer::HcalCPURecHitsProducer
HcalCPURecHitsProducer(edm::ParameterSet const &ps)
Definition: HcalCPURecHitsProducer.cc:53
HostAllocator.h
edm::EDGetTokenT
Definition: EDGetToken.h:33
edm
HLT enums.
Definition: AlignableModifier.h:19
edm::EDPutTokenT
Definition: EDPutToken.h:33
gather_cfg.cout
cout
Definition: gather_cfg.py:144
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
HcalCPURecHitsProducer::recHitsLegacyTokenOut_
const edm::EDPutTokenT< HBHERecHitCollection > recHitsLegacyTokenOut_
Definition: HcalCPURecHitsProducer.cc:35
EDProducer.h
edm::SortedCollection
Definition: SortedCollection.h:49
HcalCPURecHitsProducer
Definition: HcalCPURecHitsProducer.cc:15
singleTopDQM_cfi.setup
setup
Definition: singleTopDQM_cfi.py:37
HcalCPURecHitsProducer::produceLegacy_
const bool produceLegacy_
Definition: HcalCPURecHitsProducer.cc:28
HcalCPURecHitsProducer::tmpRecHits_
OProductType tmpRecHits_
Definition: HcalCPURecHitsProducer.cc:38
edm::WaitingTaskWithArenaHolder
Definition: WaitingTaskWithArenaHolder.h:34
MakerMacros.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
HcalCPURecHitsProducer::acquire
void acquire(edm::Event const &, edm::EventSetup const &, edm::WaitingTaskWithArenaHolder) override
Definition: HcalCPURecHitsProducer.cc:64
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
FastTrackerRecHitMaskProducer_cfi.recHits
recHits
Definition: FastTrackerRecHitMaskProducer_cfi.py:8
edm::ParameterSet
Definition: ParameterSet.h:47
TrackRefitter_38T_cff.src
src
Definition: TrackRefitter_38T_cff.py:24
HcalCPURecHitsProducer::~HcalCPURecHitsProducer
~HcalCPURecHitsProducer() override=default
Event.h
type
type
Definition: SiPixelVCal_PayloadInspector.cc:37
gainCalibHelper::gainCalibPI::type
type
Definition: SiPixelGainCalibHelper.h:40
HcalCPURecHitsProducer::recHitsM0TokenIn_
const edm::EDGetTokenT< IProductType > recHitsM0TokenIn_
Definition: HcalCPURecHitsProducer.cc:31
HcalDetId
Definition: HcalDetId.h:12
cudaCheck.h
edm::stream::EDProducer
Definition: EDProducer.h:38
edm::EventSetup
Definition: EventSetup.h:58
HcalCPURecHitsProducer::recHitsM0TokenOut_
const edm::EDPutTokenT< OProductType > recHitsM0TokenOut_
Definition: HcalCPURecHitsProducer.cc:34
reco::JetExtendedAssociation::value_type
Container::value_type value_type
Definition: JetExtendedAssociation.h:30
hcal::RecHitCollection::chi2
StoragePolicy::template StorageSelector< float >::type chi2
Definition: RecHitCollection.h:21
HcalCPURecHitsProducer::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &)
Definition: HcalCPURecHitsProducer.cc:41
cms::cuda::ScopedContextAcquire
Definition: ScopedContext.h:101
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
eostools.move
def move(src, dest)
Definition: eostools.py:511
cudaCheck
#define cudaCheck(ARG,...)
Definition: cudaCheck.h:62
relativeConstraints.value
value
Definition: relativeConstraints.py:53
cms::cuda::Product
Definition: Product.h:34
ScopedContext.h
EventSetup.h
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
HcalRecHitCollections.h
hcal::RecHitCollection::energyM0
StoragePolicy::template StorageSelector< float >::type energyM0
Definition: RecHitCollection.h:22
ParameterSet.h
hcal::RecHitCollection::did
StoragePolicy::template StorageSelector< uint32_t >::type did
Definition: RecHitCollection.h:24
event
Definition: event.py:1
edm::Event
Definition: Event.h:73
edm::InputTag
Definition: InputTag.h:15
hcal::RecHitCollection< calo::common::VecStoragePolicy< calo::common::CUDAHostAllocatorAlias > >
hcal::RecHitCollection::energy
StoragePolicy::template StorageSelector< float >::type energy
Definition: RecHitCollection.h:20
edm::ConfigurationDescriptions::addWithDefaultLabel
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:87
mps_fire.dest
dest
Definition: mps_fire.py:179
HcalCPURecHitsProducer::produceSoA_
const bool produceSoA_
Definition: HcalCPURecHitsProducer.cc:27