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  // 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 
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:99
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
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:39
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:36
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
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
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:69
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