Skip to content

Commit

Permalink
Produce HCAL rechit SoA in CaloRecHitSoAProducer
Browse files Browse the repository at this point in the history
Revert column name to detId

Code checks and formatting
  • Loading branch information
jsamudio committed Jun 19, 2024
1 parent cb5a294 commit bcbae48
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
#include "HeterogeneousCore/AlpakaCore/interface/alpaka/global/EDProducer.h"
#include "CalorimeterDefinitions.h"

#include "DataFormats/HcalRecHit/interface/HcalRecHitHostCollection.h"
#include "DataFormats/HcalRecHit/interface/alpaka/HcalRecHitDeviceCollection.h"

#define DEBUG false

namespace ALPAKA_ACCELERATOR_NAMESPACE {
Expand All @@ -25,30 +28,25 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE {
CaloRecHitSoAProducer(edm::ParameterSet const& config)
: recHitsToken_(consumes(config.getParameter<edm::InputTag>("src"))),
deviceToken_(produces()),
synchronise_(config.getUntrackedParameter<bool>("synchronise")) {
// Workaround until the ProductID problem in issue https://github.com/cms-sw/cmssw/issues/44643 is fixed
#ifdef ALPAKA_ACC_CPU_B_SEQ_T_SEQ_ENABLED
producesTemporarily("edm::DeviceProduct<alpaka_cuda_async::reco::CaloRecHitDeviceCollection>");
#endif
}
synchronise_(config.getUntrackedParameter<bool>("synchronise")) {}

void produce(edm::StreamID sid, device::Event& event, device::EventSetup const&) const override {
const edm::SortedCollection<typename CAL::CaloRecHitType>& recHits = event.get(recHitsToken_);
const int32_t num_recHits = recHits.size();
if (DEBUG)
printf("Found %d recHits\n", num_recHits);

reco::CaloRecHitHostCollection hostProduct{num_recHits, event.queue()};
hcal::RecHitHostCollection hostProduct{num_recHits, event.queue()};
auto& view = hostProduct.view();

for (int i = 0; i < num_recHits; i++) {
convertRecHit(view[i], recHits[i]);

if (DEBUG && i < 10)
printf("recHit %4d %u %f %f %08x\n", i, view.detId(i), view.energy(i), view.time(i), view.flags(i));
printf("recHit %4d %u %f %f\n", i, view.detId(i), view.energy(i), view.timeM0(i));
}

reco::CaloRecHitDeviceCollection deviceProduct{num_recHits, event.queue()};
hcal::RecHitDeviceCollection deviceProduct{num_recHits, event.queue()};
alpaka::memcpy(event.queue(), deviceProduct.buffer(), hostProduct.buffer());
if (synchronise_)
alpaka::wait(event.queue());
Expand All @@ -65,23 +63,29 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE {

private:
const edm::EDGetTokenT<edm::SortedCollection<typename CAL::CaloRecHitType>> recHitsToken_;
const device::EDPutToken<reco::CaloRecHitDeviceCollection> deviceToken_;
const device::EDPutToken<hcal::RecHitDeviceCollection> deviceToken_;
const bool synchronise_;

static void convertRecHit(reco::CaloRecHitHostCollection::View::element to,
const typename CAL::CaloRecHitType& from);
static void convertRecHit(hcal::RecHitHostCollection::View::element to, const typename CAL::CaloRecHitType& from);
};

template <>
void CaloRecHitSoAProducer<HCAL>::convertRecHit(reco::CaloRecHitHostCollection::View::element to,
void CaloRecHitSoAProducer<HCAL>::convertRecHit(hcal::RecHitHostCollection::View::element to,
const HCAL::CaloRecHitType& from) {
// Fill SoA from HCAL rec hit
to.detId() = from.id().rawId();
to.energy() = from.energy();
to.time() = from.time();
to.flags() = from.flags();
to.timeM0() = from.time();
}

/*
The ECALRecHitSoAProducer currently has no use, but is available via this
module. In the case where ECAL PF Clustering is moved to Alpaka, we can then
decide to use this converted solely for ECAL, or if the SoA is available
we can switch to using just the ECAL RecHit SoA.
*/

/*
template <>
void CaloRecHitSoAProducer<ECAL>::convertRecHit(reco::CaloRecHitHostCollection::View::element to,
const ECAL::CaloRecHitType& from) {
Expand All @@ -91,11 +95,14 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE {
to.time() = from.time();
to.flags() = from.flagsBits();
}
*/

using HCALRecHitSoAProducer = CaloRecHitSoAProducer<HCAL>;
using ECALRecHitSoAProducer = CaloRecHitSoAProducer<ECAL>;

// Purposely commented out; see above.
//using ECALRecHitSoAProducer = CaloRecHitSoAProducer<ECAL>;
} // namespace ALPAKA_ACCELERATOR_NAMESPACE

#include "HeterogeneousCore/AlpakaCore/interface/alpaka/MakerMacros.h"
DEFINE_FWK_ALPAKA_MODULE(HCALRecHitSoAProducer);
DEFINE_FWK_ALPAKA_MODULE(ECALRecHitSoAProducer);
//DEFINE_FWK_ALPAKA_MODULE(ECALRecHitSoAProducer);
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
#include "RecoParticleFlow/PFRecHitProducer/interface/alpaka/PFRecHitParamsDeviceCollection.h"
#include "RecoParticleFlow/PFRecHitProducer/interface/alpaka/PFRecHitTopologyDeviceCollection.h"

#include "DataFormats/HcalRecHit/interface/HcalRecHitHostCollection.h"
#include "DataFormats/HcalRecHit/interface/alpaka/HcalRecHitDeviceCollection.h"

// Forward declaration of EventSetup records, to avoid propagating the dependency on framework headers to device code
class PFRecHitHCALParamsRecord;
class PFRecHitHCALTopologyRecord;
Expand All @@ -34,8 +37,8 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::particleFlowRecHitProducer {

struct HCAL {
using CaloRecHitType = HBHERecHit;
using CaloRecHitSoATypeHost = reco::CaloRecHitHostCollection;
using CaloRecHitSoATypeDevice = reco::CaloRecHitDeviceCollection;
using CaloRecHitSoATypeHost = hcal::RecHitHostCollection;
using CaloRecHitSoATypeDevice = hcal::RecHitDeviceCollection;
using ParameterType = reco::PFRecHitHCALParamsDeviceCollection;
using ParameterRecordType = PFRecHitHCALParamsRecord;
using TopologyTypeHost = reco::PFRecHitHCALTopologyHostCollection;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE {
pfrh.detId() = rh.detId();
pfrh.denseId() = HCAL::detId2denseId(rh.detId());
pfrh.energy() = rh.energy();
pfrh.time() = rh.time();
pfrh.time() = rh.timeM0();
pfrh.depth() = HCAL::getDepth(pfrh.detId());
const uint32_t subdet = getSubdet(pfrh.detId());
if (subdet == HcalBarrel)
Expand Down

0 comments on commit bcbae48

Please sign in to comment.