Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,21 @@ class EcalUncalibRecHitSoAToLegacy : public edm::global::EDProducer<> {
void EcalUncalibRecHitSoAToLegacy::fillDescriptions(edm::ConfigurationDescriptions &confDesc) {
edm::ParameterSetDescription desc;

desc.add<edm::InputTag>("inputCollectionEB",
edm::InputTag("ecalMultiFitUncalibRecHitPortable", "EcalUncalibRecHitsEB"));
desc.add<std::string>("outputLabelEB", "EcalUncalibRecHitsEB");
desc.ifValue(edm::ParameterDescription<bool>("isPhase2", false, true),
false >> (edm::ParameterDescription<edm::InputTag>(
"inputCollectionEB",
edm::InputTag("ecalMultiFitUncalibRecHitPortable", "EcalUncalibRecHitsEB"),
true) and
edm::ParameterDescription<edm::InputTag>(
"inputCollectionEE",
edm::InputTag("ecalMultiFitUncalibRecHitPortable", "EcalUncalibRecHitsEE"),
true) and
edm::ParameterDescription<std::string>("outputLabelEE", "EcalUncalibRecHitsEE", true)) or
true >> edm::EmptyGroupDescription());
true >> (edm::ParameterDescription<edm::InputTag>(
"inputCollectionEB",
edm::InputTag("ecalUncalibRecHitPhase2Portable", "EcalUncalibRecHitsEB"),
true)));
confDesc.add("ecalUncalibRecHitSoAToLegacy", desc);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#include "DataFormats/EcalDigi/interface/EcalDigiCollections.h"
#include "DataFormats/EcalDigi/interface/EcalDigiPhase2HostCollection.h"
#include "DataFormats/EcalDigi/interface/alpaka/EcalDigiPhase2DeviceCollection.h"
#include "FWCore/Utilities/interface/EDGetToken.h"
#include "FWCore/Utilities/interface/EDPutToken.h"
#include "HeterogeneousCore/AlpakaCore/interface/alpaka/global/EDProducer.h"
#include "HeterogeneousCore/AlpakaCore/interface/alpaka/Event.h"
#include "HeterogeneousCore/AlpakaCore/interface/alpaka/EventSetup.h"
#include "HeterogeneousCore/AlpakaCore/interface/alpaka/MakerMacros.h"
#include "HeterogeneousCore/AlpakaInterface/interface/config.h"

namespace ALPAKA_ACCELERATOR_NAMESPACE {

class EcalPhase2DigiToPortableProducer : public global::EDProducer<> {
public:
explicit EcalPhase2DigiToPortableProducer(edm::ParameterSet const &ps);
~EcalPhase2DigiToPortableProducer() override = default;
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions);

void produce(edm::StreamID sid, device::Event &event, device::EventSetup const &setup) const override;

private:
const edm::EDGetTokenT<EBDigiCollectionPh2> inputDigiToken_;
const edm::EDPutTokenT<EcalDigiPhase2HostCollection> outputDigiHostToken_;
};

void EcalPhase2DigiToPortableProducer::fillDescriptions(edm::ConfigurationDescriptions &descriptions) {
edm::ParameterSetDescription desc;

desc.add<edm::InputTag>("BarrelDigis", edm::InputTag("simEcalUnsuppressedDigis", ""));
desc.add<std::string>("digisLabelEB", "ebDigis");

descriptions.addWithDefaultLabel(desc);
}

EcalPhase2DigiToPortableProducer::EcalPhase2DigiToPortableProducer(edm::ParameterSet const &ps)
: EDProducer(ps),
inputDigiToken_{consumes(ps.getParameter<edm::InputTag>("BarrelDigis"))},
outputDigiHostToken_{produces(ps.getParameter<std::string>("digisLabelEB"))} {}

void EcalPhase2DigiToPortableProducer::produce(edm::StreamID sid,
device::Event &event,
device::EventSetup const &setup) const {
//input data from event
const auto &inputDigis = event.get(inputDigiToken_);

const uint32_t size = inputDigis.size();

//create host and device Digi collections of required size
EcalDigiPhase2HostCollection digisHostColl{static_cast<int32_t>(size), event.queue()};
auto digisHostCollView = digisHostColl.view();

//iterate over digis
uint32_t i = 0;
for (const auto &inputDigi : inputDigis) {
const int nSamples = inputDigi.size();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a check that nSamples == ecalPh2::sampleSize ?
Or is it guaranteed to always be the case ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not always guaranteed, so we have added an if statement to make sure the size of the input is not larger than the max sample size in Phase 2, if smaller we set it to 0.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you set the "extra" entries to 0, how do you know later that they were originally not there at all, instead of being present ans with a value if 0 ? Or is 0 an impossible value?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0 is not an impossible value but 0 times weight is still 0 so all samples that the original simulated digis might not have would have no effect on the amplitude.
This is a hypothetical scenario in any case because we expect to have ecalPh2::sampleSize samples under all normal circumstances. Nevertheless, someone could come up with a reason to have a different number of samples and as longs as this is smaller than ecalPh2::sampleSize the module could still handle it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If having fewer samples or having the last N samples equal to 0 is effectively equivalent, OK.

If later (e.g. with multifit) it turns out to potentially lead to a different results, we may need to add a new column with the number of samples to the SoA.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes that could be handled with an additional scalar if it turns out that it is really needed.

//assign id to host collection
digisHostCollView.id()[i] = inputDigi.id();
//iterate over sample in digi
for (int sample = 0; sample < nSamples; ++sample) {
//get samples from input digi
EcalLiteDTUSample thisSample = inputDigi[sample];
//assign adc data to host collection
digisHostCollView.data()[i][sample] = thisSample.raw();
}
++i;
}
digisHostCollView.size() = i;

//emplace device collection in the event
event.emplace(outputDigiHostToken_, std::move(digisHostColl));
}
} // namespace ALPAKA_ACCELERATOR_NAMESPACE

DEFINE_FWK_ALPAKA_MODULE(EcalPhase2DigiToPortableProducer);
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#include <alpaka/alpaka.hpp>

#include "DataFormats/EcalDigi/interface/alpaka/EcalDigiPhase2DeviceCollection.h"
#include "DataFormats/EcalDigi/interface/EcalDataFrame_Ph2.h"
#include "DataFormats/EcalDigi/interface/EcalDigiCollections.h"
#include "DataFormats/EcalRecHit/interface/alpaka/EcalUncalibratedRecHitDeviceCollection.h"
#include "DataFormats/EcalRecHit/interface/EcalUncalibratedRecHit.h"

#include "HeterogeneousCore/AlpakaInterface/interface/config.h"
#include "HeterogeneousCore/AlpakaInterface/interface/traits.h"
#include "HeterogeneousCore/AlpakaInterface/interface/workdivision.h"

#include "EcalUncalibRecHitPhase2WeightsAlgoPortable.h"
#include "EcalUncalibRecHitPhase2WeightsStruct.h"

namespace ALPAKA_ACCELERATOR_NAMESPACE::ecal::weights {
using namespace cms::alpakatools;

class Phase2WeightsKernel {
public:
ALPAKA_FN_ACC void operator()(Acc1D const& acc,
EcalUncalibRecHitPhase2Weights const* weightsObj,
EcalDigiPhase2DeviceCollection::ConstView digisDev,
EcalUncalibratedRecHitDeviceCollection::View uncalibratedRecHitsDev) const {
constexpr int nsamples = ecalPh2::sampleSize;
auto const nchannels = digisDev.size();
// one thread sets the output collection size scalar
if (once_per_grid(acc)) {
uncalibratedRecHitsDev.size() = digisDev.size();
}

auto const* weightsdata = weightsObj->weights.data();
auto const* timeWeightsdata = weightsObj->timeWeights.data();
//divide the grid into uniform elements
for (auto tx : uniform_elements(acc, nchannels)) {
bool g1 = false;
const auto digi = digisDev[tx].data();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const auto digi = digisDev[tx].data();
const auto& digi = digisDev[tx].data();

to avoid making a copy of the StdArray

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fwyzard with this change gcc complains about possible dangling reference, see link

>> Compiling alpaka/serial scram_x86-64-v2 edm plugin src/RecoLocalCalo/EcalRecProducers/plugins/alpaka/KernelHelpers.dev.cc
/data/cmsbld/jenkins/workspace/build-any-ib/w/el8_amd64_gcc14/external/gcc/14.2.1-475d4640d5186beb85fe6c9d366d668f/bin/c++ -c -DCMS_MICRO_ARCH='x86-64-v2' -DGNU_GCC -D_GNU_SOURCE -DTBB_USE_GLIBCXX_VERSION=140201 -DTBB_SUPPRESS_DEPRECATED_MESSAGES -DTBB_PREVIEW_RESUMABLE_TASKS=1 -DTBB_PREVIEW_TASK_GROUP_EXTENSIONS=1 -DBOOST_SPIRIT_THREADSAFE -DPHOENIX_THREADSAFE -DBOOST_MATH_DISABLE_STD_FPCLASSIFY -DBOOST_UUID_RANDOM_PROVIDER_FORCE_POSIX -DBOOST_MPL_IGNORE_PARENTHESES_WARNING -DDD4HEP_USE_GEANT4_UNITS=1 -DCMSSW_GIT_HASH='CMSSW_15_1_X_2025-04-23-2300' -DPROJECT_NAME='CMSSW' -DPROJECT_VERSION='CMSSW_15_1_X_2025-04-23-2300' -Isrc -Ipoison -I/data/cmsbld/jenkins/workspace/build-any-ib/w/el8_amd64_gcc14/cms/cmssw/CMSSW_15_1_X_2025-04-21-2300/src -I/data/cmsbld/jenkins/workspace/build-any-ib/w/el8_amd64_gcc14/external/dd4hep/v01-29-00-a7d2f3fa9698a8af208e6626d9424d74/include -I/data/cmsbld/jenkins/workspace/build-any-ib/w/el8_amd64_gcc14/external/alpaka/1.2.0-3e35c1de77f81c8ba5df8b88ae089955/include -I/data/cmsbld/jenkins/workspace/build-any-ib/w/el8_amd64_gcc14/external/pcre/8.43-fec6e6028744fb6ef466c775a44bdbc6/include -isystem/data/cmsbld/jenkins/workspace/build-any-ib/w/el8_amd64_gcc14/external/boost/1.80.0-568acc6bf98000fa1932ee81ef82c0ed/include -I/data/cmsbld/jenkins/workspace/build-any-ib/w/el8_amd64_gcc14/external/bz2lib/1.0.6-5144693e7a37ea5b81cd450abd20a4e3/include -isystem/data/cmsbld/jenkins/workspace/build-any-ib/w/el8_amd64_gcc14/external/clhep/2.4.7.1-f00060af34dc2ab8b3dcb35c4ceb818d/include -I/data/cmsbld/jenkins/workspace/build-any-ib/w/el8_amd64_gcc14/external/cuda/12.8.0-88740af71f61096948e1ccabfda70dea/include -I/data/cmsbld/jenkins/workspace/build-any-ib/w/el8_amd64_gcc14/external/gsl/2.6-6508fb106023911bfb9f369409186e05/include -I/data/cmsbld/jenkins/workspace/build-any-ib/w/el8_amd64_gcc14/external/hepmc/2.06.10-f836a4b0b1d1fff3b90cdc2d904f0d85/include -I/data/cmsbld/jenkins/workspace/build-any-ib/w/el8_amd64_gcc14/external/libuuid/2.34-1d099d79c169c484b1c981ae6ba60d78/include -isystem/data/cmsbld/jenkins/workspace/build-any-ib/w/el8_amd64_gcc14/lcg/root/6.32.13-648e06eec9ef66b6ffea552d87999e71/include -isystem/data/cmsbld/jenkins/workspace/build-any-ib/w/el8_amd64_gcc14/external/tbb/v2022.0.0-9d5216d68922bb4495df90ed7ef537a5/include -I/data/cmsbld/jenkins/workspace/build-any-ib/w/el8_amd64_gcc14/cms/vdt/0.4.3-9a3e3f7b7c8090f8090c6d665bb4fb23/include -I/data/cmsbld/jenkins/workspace/build-any-ib/w/el8_amd64_gcc14/external/xerces-c/3.1.3-020702e21b426a03eada31f0a286a389/include -I/data/cmsbld/jenkins/workspace/build-any-ib/w/el8_amd64_gcc14/external/xz/5.6.4-293c8a36b5ace241306f493d5287e628/include -I/data/cmsbld/jenkins/workspace/build-any-ib/w/el8_amd64_gcc14/external/zlib/1.2.13-da03c076b1efafbcb159a35e20281b60/include -I/data/cmsbld/jenkins/workspace/build-any-ib/w/el8_amd64_gcc14/external/eigen/3bb6a48d8c171cf20b5f8e48bfb4e424fbd4f79e-6bc3adf269199bc8fe27c291ef7412d8/include -I/data/cmsbld/jenkins/workspace/build-any-ib/w/el8_amd64_gcc14/external/eigen/3bb6a48d8c171cf20b5f8e48bfb4e424fbd4f79e-6bc3adf269199bc8fe27c291ef7412d8/include/eigen3 -I/data/cmsbld/jenkins/workspace/build-any-ib/w/el8_amd64_gcc14/external/fmt/10.2.1-90400412956988d7d2f85ea6ac8b3733/include -I/data/cmsbld/jenkins/workspace/build-any-ib/w/el8_amd64_gcc14/external/md5/1.0.0-0eeec7a8b876f86bc41aaf0176f636dd/include -I/data/cmsbld/jenkins/workspace/build-any-ib/w/el8_amd64_gcc14/external/OpenBLAS/0.3.27-7afdad1f1cc07eb5a57c343e8a8a572a/include -I/data/cmsbld/jenkins/workspace/build-any-ib/w/el8_amd64_gcc14/external/tinyxml2/6.2.0-ef678365738ddd2833328bb954dd98c5/include -O3 -pthread -pipe -Werror=main -Werror=pointer-arith -Werror=overlength-strings -Wno-vla -Werror=overflow -std=c++20 -ftree-vectorize -Werror=array-bounds -Werror=format-contains-nul -Werror=type-limits -fvisibility-inlines-hidden -fno-math-errno --param vect-max-version-for-alias-checks=50 -Xassembler --compress-debug-sections -Wno-error=array-bounds -Warray-bounds -fuse-ld=bfd -felide-constructors -fmessage-length=0 -Wall -Wno-non-template-friend -Wno-long-long -Wreturn-type -Wextra -Wpessimizing-move -Wclass-memaccess -Wno-cast-function-type -Wno-unused-but-set-parameter -Wno-ignored-qualifiers -Wno-unused-parameter -Wunused -Wparentheses -Werror=return-type -Werror=missing-braces -Werror=unused-value -Werror=unused-label -Werror=address -Werror=format -Werror=sign-compare -Werror=write-strings -Werror=delete-non-virtual-dtor -Werror=strict-aliasing -Werror=narrowing -Werror=unused-but-set-variable -Werror=reorder -Werror=unused-variable -Werror=conversion-null -Werror=return-local-addr -Wnon-virtual-dtor -Werror=switch -fdiagnostics-show-option -Wno-unused-local-typedefs -Wno-attributes -Wno-psabi -DEIGEN_DONT_PARALLELIZE -DEIGEN_MAX_ALIGN_BYTES=64 -Wno-error=unused-variable -DALPAKA_DEFAULT_HOST_MEMORY_ALIGNMENT=128 -DALPAKA_DISABLE_VENDOR_RNG -DALPAKA_ACC_CPU_B_SEQ_T_SEQ_ENABLED -DBOOST_DISABLE_ASSERTS -march=x86-64-v2 -flto=auto -fipa-icf -flto-odr-type-merging -fno-fat-lto-objects -Wodr -fPIC -MMD -MF tmp/el8_amd64_gcc14/src/RecoLocalCalo/EcalRecProducers/plugins/RecoLocalCaloEcalRecProducersPluginsPortableSerialSync/scram_x86-64-v2/alpaka/KernelHelpers.dev.cc.d src/RecoLocalCalo/EcalRecProducers/plugins/alpaka/KernelHelpers.dev.cc -o tmp/el8_amd64_gcc14/src/RecoLocalCalo/EcalRecProducers/plugins/RecoLocalCaloEcalRecProducersPluginsPortableSerialSync/scram_x86-64-v2/alpaka/KernelHelpers.dev.cc.o
src/RecoLocalCalo/EcalRecProducers/plugins/alpaka/EcalUncalibRecHitPhase2WeightsAlgoPortable.dev.cc: In member function 'void alpaka_serial_sync::ecal::weights::Phase2WeightsKernel::operator()(const alpaka_serial_sync::Acc1D&, const alpaka_serial_sync::EcalUncalibRecHitPhase2Weights*, PortableHostCollection<EcalDigiPhase2SoALayout<> >::ConstView, PortableHostCollection<EcalUncalibratedRecHitSoALayout<> >::View) const':
  src/RecoLocalCalo/EcalRecProducers/plugins/alpaka/EcalUncalibRecHitPhase2WeightsAlgoPortable.dev.cc:37:21: warning: possibly dangling reference to a temporary [-Wdangling-reference]
    37 |         const auto& digi = digisDev[tx].data();
      |                     ^~~~
src/RecoLocalCalo/EcalRecProducers/plugins/alpaka/EcalUncalibRecHitPhase2WeightsAlgoPortable.dev.cc:37:45: note: the temporary was destroyed at the end of the full expression 'digisDev.EcalDigiPhase2SoALayout<>::ConstViewTemplateFreeParams<128, false, true, true>::operator[](((EcalDigiPhase2SoALayout<>::ConstViewTemplateFreeParams<128, false, true, true>::size_type)tx)).EcalDigiPhase2SoALayout<>::ConstViewTemplateFreeParams<128, false, true, true>::const_element::data()'
   37 |         const auto& digi = digisDev[tx].data();
      |                            ~~~~~~~~~~~~~~~~~^~

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd think that warning to be a false positive, because the temporary object retruned by digisDev[tx] is a "proxy" that points to data held (and owned) elsewhere.

auto recHit = uncalibratedRecHitsDev[tx];
recHit.amplitude() = 0;
recHit.jitter() = 0;
for (int s = 0; s < nsamples; ++s) {
const auto sample = digi[s];
const auto trace =
(static_cast<float>(ecalLiteDTU::adc(sample))) * ecalPh2::gains[ecalLiteDTU::gainId(sample)];
recHit.amplitude() += (trace * weightsdata[s]);
recHit.jitter() += (trace * timeWeightsdata[s]);
if (ecalLiteDTU::gainId(sample) == 1)
g1 = true;
recHit.outOfTimeAmplitudes()[s] = 0.;
}
recHit.amplitudeError() = 1.0f;
recHit.id() = digisDev.id()[tx];
recHit.flags() = 0;
recHit.pedestal() = 0.;
recHit.jitterError() = 0.;
recHit.chi2() = 0.;
recHit.aux() = 0;
if (g1) {
recHit.flags() = 0x1 << EcalUncalibratedRecHit::kHasSwitchToGain1;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this supposed to be set also if all samples are in gain 1 ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. This flag indicates that the HW has switched from the default gain 10 to gain 1 for at least one of the samples. I do not think having all samples in gain 1 will ever happen anyway.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK.

}
} //if within nchannels
} //kernel}
};

void phase2Weights(EcalDigiPhase2DeviceCollection const& digis,
EcalUncalibratedRecHitDeviceCollection& uncalibratedRecHits,
EcalUncalibRecHitPhase2Weights const* weightsObj,
Queue& queue) {
// use 64 items per group (arbitrary value, a reasonable starting point)
uint32_t items = 64;
// use as many groups as needed to cover the whole problem
uint32_t groups = divide_up_by(digis->metadata().size(), items);
//create the work division
auto workDiv = make_workdiv<Acc1D>(groups, items);
//launch the kernel
alpaka::exec<Acc1D>(
queue, workDiv, Phase2WeightsKernel{}, weightsObj, digis.const_view(), uncalibratedRecHits.view());
}

} // namespace ALPAKA_ACCELERATOR_NAMESPACE::ecal::weights
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#ifndef RecoLocalCalo_EcalRecProducers_plugins_alpaka_EcalUncalibRecHitPhase2WeightsAlgoPortable_h
#define RecoLocalCalo_EcalRecProducers_plugins_alpaka_EcalUncalibRecHitPhase2WeightsAlgoPortable_h

#include "DataFormats/EcalDigi/interface/alpaka/EcalDigiPhase2DeviceCollection.h"
#include "DataFormats/EcalRecHit/interface/alpaka/EcalUncalibratedRecHitDeviceCollection.h"

#include "DataFormats/EcalDigi/interface/EcalDataFrame_Ph2.h"
#include "EcalUncalibRecHitPhase2WeightsStruct.h"

namespace ALPAKA_ACCELERATOR_NAMESPACE::ecal::weights {

void phase2Weights(EcalDigiPhase2DeviceCollection const &digis,
EcalUncalibratedRecHitDeviceCollection &uncalibratedRecHits,
EcalUncalibRecHitPhase2Weights const *weightsObj,
Queue &queue);

} //namespace ALPAKA_ACCELERATOR_NAMESPACE::ecal::weights

#endif // RecoLocalCalo_EcalRecProducers_plugins_EcalUncalibRecHitPhase2WeightsAlgoPortable_h
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
#include <array>
#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Utilities/interface/StreamID.h"
#include "FWCore/Utilities/interface/InputTag.h"

#include "HeterogeneousCore/AlpakaInterface/interface/config.h"
#include "HeterogeneousCore/AlpakaCore/interface/alpaka/Event.h"
#include "HeterogeneousCore/AlpakaCore/interface/alpaka/EventSetup.h"
#include "HeterogeneousCore/AlpakaCore/interface/alpaka/EDPutToken.h"
#include "HeterogeneousCore/AlpakaCore/interface/alpaka/global/EDProducer.h"
#include "HeterogeneousCore/AlpakaCore/interface/alpaka/MakerMacros.h"
#include "HeterogeneousCore/AlpakaCore/interface/MoveToDeviceCache.h"

#include "DataFormats/EcalDigi/interface/EcalDataFrame_Ph2.h"
#include "DataFormats/EcalDigi/interface/EcalConstants.h"
#include "DataFormats/EcalDigi/interface/alpaka/EcalDigiPhase2DeviceCollection.h"
#include "DataFormats/EcalDigi/interface/EcalDigiPhase2HostCollection.h"
#include "DataFormats/EcalRecHit/interface/EcalUncalibratedRecHitHostCollection.h"
#include "DataFormats/EcalRecHit/interface/alpaka/EcalUncalibratedRecHitDeviceCollection.h"
#include "DataFormats/Portable/interface/PortableObject.h"

#include "EcalUncalibRecHitPhase2WeightsAlgoPortable.h"
#include "EcalUncalibRecHitPhase2WeightsStruct.h"

namespace ALPAKA_ACCELERATOR_NAMESPACE {
class EcalUncalibRecHitPhase2WeightsProducerPortable : public global::EDProducer<> {
public:
explicit EcalUncalibRecHitPhase2WeightsProducerPortable(edm::ParameterSet const &ps);
~EcalUncalibRecHitPhase2WeightsProducerPortable() override = default;
static void fillDescriptions(edm::ConfigurationDescriptions &);

void produce(edm::StreamID sid, device::Event &, device::EventSetup const &) const override;

private:
using InputProduct = EcalDigiPhase2DeviceCollection;
const device::EDGetToken<InputProduct> digisToken_; //both tokens stored on the device
using OutputProduct = EcalUncalibratedRecHitDeviceCollection;
const device::EDPutToken<OutputProduct> uncalibratedRecHitsToken_;

// class data member
cms::alpakatools::MoveToDeviceCache<Device, PortableHostObject<EcalUncalibRecHitPhase2Weights>> weightsCache_;
};

// constructor with initialisation of elements
EcalUncalibRecHitPhase2WeightsProducerPortable::EcalUncalibRecHitPhase2WeightsProducerPortable(
const edm::ParameterSet &ps)
: EDProducer(ps),
digisToken_{consumes(ps.getParameter<edm::InputTag>("digisLabelEB"))},
uncalibratedRecHitsToken_{produces(ps.getParameter<std::string>("uncalibratedRecHitsLabelEB"))},
weightsCache_(PortableHostObject<EcalUncalibRecHitPhase2Weights>(
cms::alpakatools::host(), [](const edm::ParameterSet &ps) {
EcalUncalibRecHitPhase2Weights weights;
const auto amp_weights = ps.getParameter<std::vector<double>>("weights");
const auto timeWeights = ps.getParameter<std::vector<double>>("timeWeights");
for (unsigned int i = 0; i < ecalPh2::sampleSize; ++i) {
if (i < amp_weights.size()) {
weights.weights[i] = static_cast<float>(amp_weights[i]);
} else {
weights.weights[i] = 0;
}
if (i < timeWeights.size()) {
weights.timeWeights[i] = static_cast<float>(timeWeights[i]);
} else {
weights.timeWeights[i] = 0;
}
}
return weights;
}(ps))) {}

void EcalUncalibRecHitPhase2WeightsProducerPortable::fillDescriptions(edm::ConfigurationDescriptions &descriptions) {
edm::ParameterSetDescription desc;

desc.add<std::string>("uncalibratedRecHitsLabelEB", "EcalUncalibRecHitsEB");
//The below weights values should be kept up to date with those on the CPU version of this module
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add where the CPU version of the weights are ?
For example,

Suggested change
//The below weights values should be kept up to date with those on the CPU version of this module
//The weights values below should be kept up to date with those on the CPU version of this module
//in RecoLocalCalo/EcalRecProducers/plugins/EcalUncalibRecHitPhase2WeightsProducer.cc

desc.add<std::vector<double>>("weights",
{-0.121016,
-0.119899,
-0.120923,
-0.0848959,
0.261041,
0.509881,
0.373591,
0.134899,
-0.0233605,
-0.0913195,
-0.112452,
-0.118596,
-0.121737,
-0.121737,
-0.121737,
-0.121737});
desc.add<std::vector<double>>("timeWeights",
{0.429452,
0.442762,
0.413327,
0.858327,
4.42324,
2.04369,
-3.42426,
-4.16258,
-2.36061,
-0.725371,
0.0727267,
0.326005,
0.402035,
0.404287,
0.434207,
0.422775});

desc.add<edm::InputTag>("digisLabelEB", edm::InputTag("simEcalUnsuppressedDigis", ""));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are the simEcalUnsuppressedDigis in a portable collection in SoA format ?
Otherwise a better default could be

Suggested change
desc.add<edm::InputTag>("digisLabelEB", edm::InputTag("simEcalUnsuppressedDigis", ""));
desc.add<edm::InputTag>("digisLabelEB", edm::InputTag("ecalPhase2DigiToPortableProducer", "ebDigis"));


descriptions.addWithDefaultLabel(desc);
}

void EcalUncalibRecHitPhase2WeightsProducerPortable::produce(edm::StreamID sid,
device::Event &event,
const device::EventSetup &setup) const {
//get the device collection of digis
auto const &digis = event.get(digisToken_);

//get size of digis
const uint32_t size = digis->metadata().size();

//allocate output product on the device
OutputProduct uncalibratedRecHits{static_cast<int32_t>(size), event.queue()};

//do not run the algo if there are no digis
if (size > 0) {
auto const &weightsObj = weightsCache_.get(event.queue());
//launch the asynchronous work
ecal::weights::phase2Weights(digis, uncalibratedRecHits, weightsObj.const_data(), event.queue());
}
//put the output collection into the event
event.emplace(uncalibratedRecHitsToken_, std::move(uncalibratedRecHits));
}

} //namespace ALPAKA_ACCELERATOR_NAMESPACE
DEFINE_FWK_ALPAKA_MODULE(EcalUncalibRecHitPhase2WeightsProducerPortable);
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#ifndef RecoLocalCalo_EcalRecProducers_plugins_alpaka_EcalUncalibRecHitPhase2WeightsStruct_h
#define RecoLocalCalo_EcalRecProducers_plugins_alpaka_EcalUncalibRecHitPhase2WeightsStruct_h

#include "DataFormats/EcalDigi/interface/EcalDataFrame_Ph2.h"

namespace ALPAKA_ACCELERATOR_NAMESPACE {

// define a struct for the data
struct EcalUncalibRecHitPhase2Weights {
std::array<float, ecalPh2::sampleSize> weights;
std::array<float, ecalPh2::sampleSize> timeWeights;
};
} //namespace ALPAKA_ACCELERATOR_NAMESPACE

#endif // RecoLocalCalo_EcalRecProducers_plugins_EcalUncalibRecHitPhase2WeightsStruct_h
10 changes: 10 additions & 0 deletions RecoLocalCalo/EcalRecProducers/python/ecalRecHit_cff.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,13 @@
alpakaValidationEcal.toModify(ecalRecHit, cpu = ecalRecHitCPU)
alpakaValidationEcal.toModify(ecalRecHit, cuda = _ecalRecHitSoAToLegacy.clone())

from Configuration.Eras.Modifier_phase2_ecal_devel_cff import phase2_ecal_devel
phase2_ecal_devel.toModify(ecalRecHitPortable, isPhase2=True)
phase2_ecal_devel.toModify(ecalRecHitPortable, uncalibrecHitsInLabelEB = 'ecalUncalibRecHitPhase2Portable:EcalUncalibRecHitsEB')
phase2_ecal_devel.toModify(ecalRecHitPortable, EELaserMAX= None)
phase2_ecal_devel.toModify(ecalRecHitPortable, EELaserMIN= None)
phase2_ecal_devel.toModify(ecalRecHitPortable, recHitsLabelEE= None)
phase2_ecal_devel.toModify(ecalRecHitPortable, recoverEEFE= None)
phase2_ecal_devel.toModify(ecalRecHitPortable, recoverEEIsolatedChannels= None)
phase2_ecal_devel.toModify(ecalRecHitPortable, recoverEEVFE= None)
phase2_ecal_devel.toModify(ecalRecHitPortable, uncalibrecHitsInLabelEE= None)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pedantic formatting suggestion:

Suggested change
from Configuration.Eras.Modifier_phase2_ecal_devel_cff import phase2_ecal_devel
phase2_ecal_devel.toModify(ecalRecHitPortable, isPhase2=True)
phase2_ecal_devel.toModify(ecalRecHitPortable, uncalibrecHitsInLabelEB = 'ecalUncalibRecHitPhase2Portable:EcalUncalibRecHitsEB')
phase2_ecal_devel.toModify(ecalRecHitPortable, EELaserMAX= None)
phase2_ecal_devel.toModify(ecalRecHitPortable, EELaserMIN= None)
phase2_ecal_devel.toModify(ecalRecHitPortable, recHitsLabelEE= None)
phase2_ecal_devel.toModify(ecalRecHitPortable, recoverEEFE= None)
phase2_ecal_devel.toModify(ecalRecHitPortable, recoverEEIsolatedChannels= None)
phase2_ecal_devel.toModify(ecalRecHitPortable, recoverEEVFE= None)
phase2_ecal_devel.toModify(ecalRecHitPortable, uncalibrecHitsInLabelEE= None)
from Configuration.Eras.Modifier_phase2_ecal_devel_cff import phase2_ecal_devel
phase2_ecal_devel.toModify(ecalRecHitPortable, isPhase2 = True)
phase2_ecal_devel.toModify(ecalRecHitPortable, uncalibrecHitsInLabelEB = 'ecalUncalibRecHitPhase2Portable:EcalUncalibRecHitsEB')
phase2_ecal_devel.toModify(ecalRecHitPortable, EELaserMAX = None)
phase2_ecal_devel.toModify(ecalRecHitPortable, EELaserMIN = None)
phase2_ecal_devel.toModify(ecalRecHitPortable, recHitsLabelEE = None)
phase2_ecal_devel.toModify(ecalRecHitPortable, recoverEEFE = None)
phase2_ecal_devel.toModify(ecalRecHitPortable, recoverEEIsolatedChannels = None)
phase2_ecal_devel.toModify(ecalRecHitPortable, recoverEEVFE = None)
phase2_ecal_devel.toModify(ecalRecHitPortable, uncalibrecHitsInLabelEE = None)

Loading