CMS 3D CMS Logo

EcalCPURecHitProducer.cc
Go to the documentation of this file.
1 //#define ECAL_RECO_CUDA_DEBUG
2 
3 #ifdef ECAL_RECO_CUDA_DEBUG
4 #include <iostream>
5 #endif
6 
7 // framework
9 
15 
17 
18 // algorithm specific
19 
21 
23 
24 class EcalCPURecHitProducer : public edm::stream::EDProducer<edm::ExternalWork> {
25 public:
26  explicit EcalCPURecHitProducer(edm::ParameterSet const& ps);
27  ~EcalCPURecHitProducer() override = default;
29 
30 private:
32  void produce(edm::Event&, edm::EventSetup const&) override;
33 
34 private:
39 
42 };
43 
46 
47  desc.add<edm::InputTag>("recHitsInLabelEB", edm::InputTag{"ecalRecHitProducerGPU", "EcalRecHitsEB"});
48  desc.add<edm::InputTag>("recHitsInLabelEE", edm::InputTag{"ecalRecHitProducerGPU", "EcalRecHitsEE"});
49  desc.add<std::string>("recHitsOutLabelEB", "EcalRecHitsEB");
50  desc.add<std::string>("recHitsOutLabelEE", "EcalRecHitsEE");
51  desc.add<bool>("containsTimingInformation", false);
52 
53  confDesc.addWithDefaultLabel(desc);
54 }
55 
57  : recHitsInEBToken_{consumes<InputProduct>(ps.getParameter<edm::InputTag>("recHitsInLabelEB"))},
58  recHitsInEEToken_{consumes<InputProduct>(ps.getParameter<edm::InputTag>("recHitsInLabelEE"))},
59  recHitsOutEBToken_{produces<OutputProduct>(ps.getParameter<std::string>("recHitsOutLabelEB"))},
60  recHitsOutEEToken_{produces<OutputProduct>(ps.getParameter<std::string>("recHitsOutLabelEE"))},
61  containsTimingInformation_{ps.getParameter<bool>("containsTimingInformation")} {}
62 
64  edm::EventSetup const& setup,
66  // retrieve data/ctx
67  auto const& ebRecHitsProduct = event.get(recHitsInEBToken_);
68  auto const& eeRecHitsProduct = event.get(recHitsInEEToken_);
69  cms::cuda::ScopedContextAcquire ctx{ebRecHitsProduct, std::move(taskHolder)};
70  auto const& ebRecHits = ctx.get(ebRecHitsProduct);
71  auto const& eeRecHits = ctx.get(eeRecHitsProduct);
72 
73  // resize the output buffers
74  recHitsEB_.resize(ebRecHits.size);
75  recHitsEE_.resize(eeRecHits.size);
76 
77 #ifdef ECAL_RECO_CUDA_DEBUG
78  std::cout << " [EcalCPURecHitProducer::acquire] ebRecHits.size = " << ebRecHits.size << std::endl;
79  std::cout << " [EcalCPURecHitProducer::acquire] eeRecHits.size = " << eeRecHits.size << std::endl;
80 #endif
81 
82  // enqeue transfers
83  cudaCheck(cudaMemcpyAsync(recHitsEB_.did.data(),
84  ebRecHits.did.get(),
85  recHitsEB_.did.size() * sizeof(uint32_t),
86  cudaMemcpyDeviceToHost,
87  ctx.stream()));
88  cudaCheck(cudaMemcpyAsync(recHitsEE_.did.data(),
89  eeRecHits.did.get(),
90  recHitsEE_.did.size() * sizeof(uint32_t),
91  cudaMemcpyDeviceToHost,
92  ctx.stream()));
93  //
94  // ./CUDADataFormats/EcalRecHitSoA/interface/RecoTypes.h:using StorageScalarType = float;
95  //
96 
97  cudaCheck(cudaMemcpyAsync(recHitsEB_.energy.data(),
98  ebRecHits.energy.get(),
100  cudaMemcpyDeviceToHost,
101  ctx.stream()));
102  cudaCheck(cudaMemcpyAsync(recHitsEE_.energy.data(),
103  eeRecHits.energy.get(),
105  cudaMemcpyDeviceToHost,
106  ctx.stream()));
107 
108  cudaCheck(cudaMemcpyAsync(recHitsEB_.chi2.data(),
109  ebRecHits.chi2.get(),
111  cudaMemcpyDeviceToHost,
112  ctx.stream()));
113  cudaCheck(cudaMemcpyAsync(recHitsEE_.chi2.data(),
114  eeRecHits.chi2.get(),
116  cudaMemcpyDeviceToHost,
117  ctx.stream()));
118 
119  cudaCheck(cudaMemcpyAsync(recHitsEB_.extra.data(),
120  ebRecHits.extra.get(),
121  recHitsEB_.extra.size() * sizeof(uint32_t),
122  cudaMemcpyDeviceToHost,
123  ctx.stream()));
124  cudaCheck(cudaMemcpyAsync(recHitsEE_.extra.data(),
125  eeRecHits.extra.get(),
126  recHitsEE_.extra.size() * sizeof(uint32_t),
127  cudaMemcpyDeviceToHost,
128  ctx.stream()));
129 
130  cudaCheck(cudaMemcpyAsync(recHitsEB_.flagBits.data(),
131  ebRecHits.flagBits.get(),
132  recHitsEB_.flagBits.size() * sizeof(uint32_t),
133  cudaMemcpyDeviceToHost,
134  ctx.stream()));
135  cudaCheck(cudaMemcpyAsync(recHitsEE_.flagBits.data(),
136  eeRecHits.flagBits.get(),
137  recHitsEE_.flagBits.size() * sizeof(uint32_t),
138  cudaMemcpyDeviceToHost,
139  ctx.stream()));
140 
141 #ifdef ECAL_RECO_CUDA_DEBUG
142  for (unsigned int ieb = 0; ieb < ebRecHits.size; ieb++) {
143  if (recHitsEB_.extra[ieb] != 0)
144  std::cout << " [ " << ieb << " :: " << ebRecHits.size << " ] [ " << recHitsEB_.did[ieb]
145  << " ] eb extra = " << recHitsEB_.extra[ieb] << std::endl;
146  }
147 
148  for (unsigned int ieb = 0; ieb < ebRecHits.size; ieb++) {
149  if (recHitsEB_.energy[ieb] != 0)
150  std::cout << " [ " << ieb << " :: " << ebRecHits.size << " ] [ " << recHitsEB_.did[ieb]
151  << " ] eb energy = " << recHitsEB_.energy[ieb] << std::endl;
152  }
153 
154  for (unsigned int iee = 0; iee < eeRecHits.size; iee++) {
155  if (recHitsEE_.energy[iee] != 0)
156  std::cout << " [ " << iee << " :: " << eeRecHits.size << " ] [ " << recHitsEE_.did[iee]
157  << " ] ee energy = " << recHitsEE_.energy[iee] << std::endl;
158  }
159 #endif
160 }
161 
163  // put into event
164  event.emplace(recHitsOutEBToken_, std::move(recHitsEB_));
165  event.emplace(recHitsOutEEToken_, std::move(recHitsEE_));
166 }
167 
EcalCPURecHitProducer::recHitsEB_
OutputProduct recHitsEB_
Definition: EcalCPURecHitProducer.cc:40
EcalCPURecHitProducer::~EcalCPURecHitProducer
~EcalCPURecHitProducer() override=default
ecal::reco::StorageScalarType
float StorageScalarType
Definition: RecoTypes.h:8
edm::EDGetTokenT
Definition: EDGetToken.h:33
edm::EDPutTokenT
Definition: EDPutToken.h:33
EcalCPURecHitProducer::recHitsInEBToken_
edm::EDGetTokenT< InputProduct > recHitsInEBToken_
Definition: EcalCPURecHitProducer.cc:36
gather_cfg.cout
cout
Definition: gather_cfg.py:144
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
EDProducer.h
ecal::RecHit::chi2
StoragePolicy::template StorageSelector< reco::StorageScalarType >::type chi2
Definition: EcalRecHit.h:25
singleTopDQM_cfi.setup
setup
Definition: singleTopDQM_cfi.py:37
EcalCPURecHitProducer::recHitsEE_
OutputProduct recHitsEE_
Definition: EcalCPURecHitProducer.cc:40
edm::WaitingTaskWithArenaHolder
Definition: WaitingTaskWithArenaHolder.h:34
MakerMacros.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
ecal::RecHit::flagBits
StoragePolicy::template StorageSelector< uint32_t >::type flagBits
Definition: EcalRecHit.h:29
EcalRecHit.h
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
edm::ParameterSet
Definition: ParameterSet.h:47
Event.h
FEDRawDataCollection.h
cudaCheck.h
edm::stream::EDProducer
Definition: EDProducer.h:36
EcalCPURecHitProducer::EcalCPURecHitProducer
EcalCPURecHitProducer(edm::ParameterSet const &ps)
Definition: EcalCPURecHitProducer.cc:56
EcalCPURecHitProducer
Definition: EcalCPURecHitProducer.cc:24
edm::EventSetup
Definition: EventSetup.h:58
ecal::RecHit::energy
StoragePolicy::template StorageSelector< reco::StorageScalarType >::type energy
Definition: EcalRecHit.h:22
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
EcalCPURecHitProducer::recHitsOutEEToken_
edm::EDPutTokenT< OutputProduct > recHitsOutEEToken_
Definition: EcalCPURecHitProducer.cc:38
cms::cuda::ScopedContextAcquire
Definition: ScopedContext.h:101
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
ecal::RecHit::extra
StoragePolicy::template StorageSelector< uint32_t >::type extra
Definition: EcalRecHit.h:27
eostools.move
def move(src, dest)
Definition: eostools.py:511
cudaCheck
#define cudaCheck(ARG,...)
Definition: cudaCheck.h:69
EcalCPURecHitProducer::recHitsInEEToken_
edm::EDGetTokenT< InputProduct > recHitsInEEToken_
Definition: EcalCPURecHitProducer.cc:36
EcalCPURecHitProducer::acquire
void acquire(edm::Event const &, edm::EventSetup const &, edm::WaitingTaskWithArenaHolder) override
Definition: EcalCPURecHitProducer.cc:63
cms::cuda::Product
Definition: Product.h:34
ScopedContext.h
ecal::RecHit::resize
std::enable_if< std::is_same< U, ::calo::common::tags::Vec >::value, void >::type resize(size_t size)
Definition: EcalRecHit.h:33
EventSetup.h
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
ParameterSet.h
EcalCPURecHitProducer::containsTimingInformation_
bool containsTimingInformation_
Definition: EcalCPURecHitProducer.cc:41
EcalCPURecHitProducer::recHitsOutEBToken_
edm::EDPutTokenT< OutputProduct > recHitsOutEBToken_
Definition: EcalCPURecHitProducer.cc:38
event
Definition: event.py:1
edm::Event
Definition: Event.h:73
edm::InputTag
Definition: InputTag.h:15
ecal::RecHit::did
StoragePolicy::template StorageSelector< uint32_t >::type did
Definition: EcalRecHit.h:30
edm::ConfigurationDescriptions::addWithDefaultLabel
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:87
EcalCPURecHitProducer::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &)
Definition: EcalCPURecHitProducer.cc:44
ecal::RecHit< calo::common::VecStoragePolicy< calo::common::CUDAHostAllocatorAlias > >
EcalCPURecHitProducer::produce
void produce(edm::Event &, edm::EventSetup const &) override
Definition: EcalCPURecHitProducer.cc:162