CMS 3D CMS Logo

CaloRecHitSoAProducer.cc
Go to the documentation of this file.
1 #include <utility>
2 
3 #include <alpaka/alpaka.hpp>
4 
15 #include "CalorimeterDefinitions.h"
16 
17 #define DEBUG false
18 
20  using namespace particleFlowRecHitProducer;
21 
22  template <typename CAL>
24  public:
26  : recHitsToken_(consumes(config.getParameter<edm::InputTag>("src"))),
27  deviceToken_(produces()),
28  synchronise_(config.getUntrackedParameter<bool>("synchronise")) {
29  // Workaround until the ProductID problem in issue https://github.com/cms-sw/cmssw/issues/44643 is fixed
30 #ifdef ALPAKA_ACC_CPU_B_SEQ_T_SEQ_ENABLED
31  producesTemporarily("edm::DeviceProduct<alpaka_cuda_async::reco::CaloRecHitDeviceCollection>");
32 #endif
33  }
34 
35  void produce(edm::StreamID sid, device::Event& event, device::EventSetup const&) const override {
36  const edm::SortedCollection<typename CAL::CaloRecHitType>& recHits = event.get(recHitsToken_);
37  const int32_t num_recHits = recHits.size();
38  if (DEBUG)
39  printf("Found %d recHits\n", num_recHits);
40 
41  reco::CaloRecHitHostCollection hostProduct{num_recHits, event.queue()};
42  auto& view = hostProduct.view();
43 
44  for (int i = 0; i < num_recHits; i++) {
45  convertRecHit(view[i], recHits[i]);
46 
47  if (DEBUG && i < 10)
48  printf("recHit %4d %u %f %f %08x\n", i, view.detId(i), view.energy(i), view.time(i), view.flags(i));
49  }
50 
51  reco::CaloRecHitDeviceCollection deviceProduct{num_recHits, event.queue()};
52  alpaka::memcpy(event.queue(), deviceProduct.buffer(), hostProduct.buffer());
53  if (synchronise_)
54  alpaka::wait(event.queue());
55  event.emplace(deviceToken_, std::move(deviceProduct));
56  }
57 
58  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
60  desc.add<edm::InputTag>("src", edm::InputTag(""))->setComment("Input calorimeter rec hit collection");
61  desc.addUntracked<bool>("synchronise", false)
62  ->setComment("Add synchronisation point after execution (for benchmarking asynchronous execution)");
63  descriptions.addWithDefaultLabel(desc);
64  }
65 
66  private:
69  const bool synchronise_;
70 
71  static void convertRecHit(reco::CaloRecHitHostCollection::View::element to,
72  const typename CAL::CaloRecHitType& from);
73  };
74 
75  template <>
76  void CaloRecHitSoAProducer<HCAL>::convertRecHit(reco::CaloRecHitHostCollection::View::element to,
77  const HCAL::CaloRecHitType& from) {
78  // Fill SoA from HCAL rec hit
79  to.detId() = from.id().rawId();
80  to.energy() = from.energy();
81  to.time() = from.time();
82  to.flags() = from.flags();
83  }
84 
85  template <>
86  void CaloRecHitSoAProducer<ECAL>::convertRecHit(reco::CaloRecHitHostCollection::View::element to,
87  const ECAL::CaloRecHitType& from) {
88  // Fill SoA from ECAL rec hit
89  to.detId() = from.id().rawId();
90  to.energy() = from.energy();
91  to.time() = from.time();
92  to.flags() = from.flagsBits();
93  }
94 
97 } // namespace ALPAKA_ACCELERATOR_NAMESPACE
98 
void produce(edm::StreamID sid, device::Event &event, device::EventSetup const &) const override
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
float time() const
Definition: EcalRecHit.h:71
#define DEBUG
CaloRecHitSoAProducer< ECAL > ECALRecHitSoAProducer
CaloRecHitSoAProducer< HCAL > HCALRecHitSoAProducer
Definition: config.py:1
const edm::EDGetTokenT< edm::SortedCollection< typename CAL::CaloRecHitType > > recHitsToken_
constexpr float energy() const
Definition: CaloRecHit.h:29
static void convertRecHit(reco::CaloRecHitHostCollection::View::element to, const typename CAL::CaloRecHitType &from)
const device::EDPutToken< reco::CaloRecHitDeviceCollection > deviceToken_
constexpr uint32_t flags() const
Definition: CaloRecHit.h:34
uint32_t flagsBits() const
Definition: EcalRecHit.h:202
constexpr HcalDetId id() const
get the id
Definition: HBHERecHit.h:41
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
DetId id() const
get the id
Definition: EcalRecHit.h:78
PortableCollection<::reco::CaloRecHitSoA > CaloRecHitDeviceCollection
constexpr float time() const
Definition: CaloRecHit.h:31
HLT enums.
#define DEFINE_FWK_ALPAKA_MODULE(name)
Definition: MakerMacros.h:16
float energy() const
Definition: EcalRecHit.h:69
def move(src, dest)
Definition: eostools.py:511
Definition: event.py:1