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 
30  void produce(edm::StreamID sid, device::Event& event, device::EventSetup const&) const override {
31  const edm::SortedCollection<typename CAL::CaloRecHitType>& recHits = event.get(recHitsToken_);
32  const int32_t num_recHits = recHits.size();
33  if (DEBUG)
34  printf("Found %d recHits\n", num_recHits);
35 
36  reco::CaloRecHitHostCollection hostProduct{num_recHits, event.queue()};
37  auto& view = hostProduct.view();
38 
39  for (int i = 0; i < num_recHits; i++) {
40  convertRecHit(view[i], recHits[i]);
41 
42  if (DEBUG && i < 10)
43  printf("recHit %4d %u %f %f %08x\n", i, view.detId(i), view.energy(i), view.time(i), view.flags(i));
44  }
45 
46  reco::CaloRecHitDeviceCollection deviceProduct{num_recHits, event.queue()};
47  alpaka::memcpy(event.queue(), deviceProduct.buffer(), hostProduct.buffer());
48  if (synchronise_)
49  alpaka::wait(event.queue());
50  event.emplace(deviceToken_, std::move(deviceProduct));
51  }
52 
53  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
55  desc.add<edm::InputTag>("src")->setComment("Input calorimeter rec hit collection");
56  desc.addUntracked<bool>("synchronise", false)
57  ->setComment("Add synchronisation point after execution (for benchmarking asynchronous execution)");
58  descriptions.addWithDefaultLabel(desc);
59  }
60 
61  private:
64  const bool synchronise_;
65 
66  static void convertRecHit(reco::CaloRecHitHostCollection::View::element to,
67  const typename CAL::CaloRecHitType& from);
68  };
69 
70  template <>
71  void CaloRecHitSoAProducer<HCAL>::convertRecHit(reco::CaloRecHitHostCollection::View::element to,
72  const HCAL::CaloRecHitType& from) {
73  // Fill SoA from HCAL rec hit
74  to.detId() = from.id().rawId();
75  to.energy() = from.energy();
76  to.time() = from.time();
77  to.flags() = from.flags();
78  }
79 
80  template <>
81  void CaloRecHitSoAProducer<ECAL>::convertRecHit(reco::CaloRecHitHostCollection::View::element to,
82  const ECAL::CaloRecHitType& from) {
83  // Fill SoA from ECAL rec hit
84  to.detId() = from.id().rawId();
85  to.energy() = from.energy();
86  to.time() = from.time();
87  to.flags() = from.flagsBits();
88  }
89 
92 } // namespace ALPAKA_ACCELERATOR_NAMESPACE
93 
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