RecoLocalCalo
HcalRecProducers
src
HcalCPURecHitsProducer.cc
Go to the documentation of this file.
1
#include <iostream>
2
#include <string>
3
4
#include "
CUDADataFormats/HcalRecHitSoA/interface/RecHitCollection.h
"
5
#include "
DataFormats/HcalRecHit/interface/HcalRecHitCollections.h
"
6
#include "
FWCore/Framework/interface/Event.h
"
7
#include "
FWCore/Framework/interface/EventSetup.h
"
8
#include "
FWCore/Framework/interface/MakerMacros.h
"
9
#include "
FWCore/Framework/interface/stream/EDProducer.h
"
10
#include "
FWCore/ParameterSet/interface/ParameterSet.h
"
11
#include "
HeterogeneousCore/CUDACore/interface/ScopedContext.h
"
12
#include "
HeterogeneousCore/CUDAUtilities/interface/HostAllocator.h
"
13
#include "
HeterogeneousCore/CUDAUtilities/interface/cudaCheck.h
"
14
15
class
HcalCPURecHitsProducer
:
public
edm::stream::EDProducer
<edm::ExternalWork> {
16
public
:
17
explicit
HcalCPURecHitsProducer
(
edm::ParameterSet
const
& ps);
18
~HcalCPURecHitsProducer
()
override
;
19
static
void
fillDescriptions
(
edm::ConfigurationDescriptions
&);
20
21
private
:
22
void
acquire
(
edm::Event
const
&,
edm::EventSetup
const
&,
edm::WaitingTaskWithArenaHolder
)
override
;
23
void
produce
(
edm::Event
&,
edm::EventSetup
const
&)
override
;
24
25
private
:
26
using
IProductType
=
cms::cuda::Product<hcal::RecHitCollection<calo::common::DevStoragePolicy>
>;
27
edm::EDGetTokenT<IProductType>
recHitsM0TokenIn_
;
28
using
OProductType
=
hcal::RecHitCollection<calo::common::VecStoragePolicy<calo::common::CUDAHostAllocatorAlias>
>;
29
edm::EDPutTokenT<OProductType>
recHitsM0TokenOut_
;
30
edm::EDPutTokenT<HBHERecHitCollection>
recHitsLegacyTokenOut_
;
31
32
// to pass from acquire to produce
33
OProductType
tmpRecHits_
;
34
};
35
36
void
HcalCPURecHitsProducer::fillDescriptions
(
edm::ConfigurationDescriptions
& confDesc) {
37
edm::ParameterSetDescription
desc
;
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
46
HcalCPURecHitsProducer::HcalCPURecHitsProducer
(
const
edm::ParameterSet
& ps)
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
51
HcalCPURecHitsProducer::~HcalCPURecHitsProducer
() {}
52
53
void
HcalCPURecHitsProducer::acquire
(
edm::Event
const
&
event
,
54
edm::EventSetup
const
&
setup
,
55
edm::WaitingTaskWithArenaHolder
taskHolder) {
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
62
tmpRecHits_
.
resize
(
recHits
.size);
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
83
void
HcalCPURecHitsProducer::produce
(
edm::Event
&
event
,
edm::EventSetup
const
&
setup
) {
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
]},
90
tmpRecHits_
.
energy
[
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
106
DEFINE_FWK_MODULE
(
HcalCPURecHitsProducer
);
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
Generated for CMSSW Reference Manual by
1.8.16