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;
20 
21 private:
23  void produce(edm::Event&, edm::EventSetup const&) override;
24 
25 private:
31 
32  // to pass from acquire to produce
34 };
35 
38 
39  desc.add<edm::InputTag>("recHitsM0LabelIn", edm::InputTag{"hbheRecHitProducerGPU", "recHitsM0HBHE"});
40  desc.add<std::string>("recHitsM0LabelOut", "recHitsM0HBHE");
41  desc.add<std::string>("recHitsLegacyLabelOut", "recHitsLegacyHBHE");
42 
43  confDesc.addWithDefaultLabel(desc);
44 }
45 
47  : recHitsM0TokenIn_{consumes<IProductType>(ps.getParameter<edm::InputTag>("recHitsM0LabelIn"))},
48  recHitsM0TokenOut_{produces<OProductType>(ps.getParameter<std::string>("recHitsM0LabelOut"))},
49  recHitsLegacyTokenOut_{produces<HBHERecHitCollection>(ps.getParameter<std::string>("recHitsLegacyLabelOut"))} {}
50 
52 
54  edm::EventSetup const& setup,
56  // retrieve data/ctx
57  auto const& recHitsProduct = event.get(recHitsM0TokenIn_);
58  cms::cuda::ScopedContextAcquire ctx{recHitsProduct, std::move(taskHolder)};
59  auto const& recHits = ctx.get(recHitsProduct);
60 
61  // resize tmp buffers
63 
64 #ifdef HCAL_MAHI_CPUDEBUG
65  std::cout << "num rec Hits = " << recHits.size << std::endl;
66 #endif
67 
68  auto lambdaToTransfer = [&ctx](auto& dest, auto* src) {
69  using vector_type = typename std::remove_reference<decltype(dest)>::type;
70  using src_data_type = typename std::remove_pointer<decltype(src)>::type;
71  using type = typename vector_type::value_type;
72  static_assert(std::is_same<src_data_type, type>::value && "Dest and Src data types do not match");
73  cudaCheck(cudaMemcpyAsync(dest.data(), src, dest.size() * sizeof(type), cudaMemcpyDeviceToHost, ctx.stream()));
74  };
75 
76  lambdaToTransfer(tmpRecHits_.energy, recHits.energy.get());
77  lambdaToTransfer(tmpRecHits_.chi2, recHits.chi2.get());
78  lambdaToTransfer(tmpRecHits_.energyM0, recHits.energyM0.get());
79  lambdaToTransfer(tmpRecHits_.timeM0, recHits.timeM0.get());
80  lambdaToTransfer(tmpRecHits_.did, recHits.did.get());
81 }
82 
84  // populate the legacy collection
85  auto recHitsLegacy = std::make_unique<HBHERecHitCollection>();
86  // did not set size with ctor as there is no setter for did
87  recHitsLegacy->reserve(tmpRecHits_.did.size());
88  for (uint32_t i = 0; i < tmpRecHits_.did.size(); i++) {
89  recHitsLegacy->emplace_back(HcalDetId{tmpRecHits_.did[i]},
91  0 // timeRising
92  );
93 
94  // update newly pushed guy
95  (*recHitsLegacy)[i].setChiSquared(tmpRecHits_.chi2[i]);
96  (*recHitsLegacy)[i].setRawEnergy(tmpRecHits_.energyM0[i]);
97  }
98 
99  // put a legacy format
100  event.put(recHitsLegacyTokenOut_, std::move(recHitsLegacy));
101 
102  // put a new format
103  event.emplace(recHitsM0TokenOut_, std::move(tmpRecHits_));
104 }
105 
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:83
HcalCPURecHitsProducer::HcalCPURecHitsProducer
HcalCPURecHitsProducer(edm::ParameterSet const &ps)
Definition: HcalCPURecHitsProducer.cc:46
HostAllocator.h
edm::EDGetTokenT
Definition: EDGetToken.h:33
edm::EDPutTokenT
Definition: EDPutToken.h:33
gather_cfg.cout
cout
Definition: gather_cfg.py:144
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
EDProducer.h
HcalCPURecHitsProducer
Definition: HcalCPURecHitsProducer.cc:15
singleTopDQM_cfi.setup
setup
Definition: singleTopDQM_cfi.py:37
HcalCPURecHitsProducer::tmpRecHits_
OProductType tmpRecHits_
Definition: HcalCPURecHitsProducer.cc:33
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:53
HcalCPURecHitsProducer::~HcalCPURecHitsProducer
~HcalCPURecHitsProducer() override
Definition: HcalCPURecHitsProducer.cc:51
HcalCPURecHitsProducer::recHitsLegacyTokenOut_
edm::EDPutTokenT< HBHERecHitCollection > recHitsLegacyTokenOut_
Definition: HcalCPURecHitsProducer.cc:30
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
Event.h
type
type
Definition: SiPixelVCal_PayloadInspector.cc:37
gainCalibHelper::gainCalibPI::type
type
Definition: SiPixelGainCalibHelper.h:40
HcalDetId
Definition: HcalDetId.h:12
cudaCheck.h
edm::stream::EDProducer
Definition: EDProducer.h:38
edm::EventSetup
Definition: EventSetup.h:58
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:36
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
HcalCPURecHitsProducer::recHitsM0TokenOut_
edm::EDPutTokenT< OProductType > recHitsM0TokenOut_
Definition: HcalCPURecHitsProducer.cc:29
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
HcalCPURecHitsProducer::recHitsM0TokenIn_
edm::EDGetTokenT< IProductType > recHitsM0TokenIn_
Definition: HcalCPURecHitsProducer.cc:27
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