CMS 3D CMS Logo

EcalCPUDigisProducer.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <utility>
3 
20 
21 #include "DeclsForKernels.h"
22 #include "UnpackGPU.h"
23 
24 class EcalCPUDigisProducer : public edm::stream::EDProducer<edm::ExternalWork> {
25 public:
26  explicit EcalCPUDigisProducer(edm::ParameterSet const& ps);
27  ~EcalCPUDigisProducer() override = default;
29 
30 private:
32  void produce(edm::Event&, edm::EventSetup const&) override;
33 
34  template <typename ProductType, typename... ARGS>
36  return (produceDummyIntegrityCollections_) ? produces<ProductType>(std::forward<ARGS>(args)...)
38  }
39 
40 private:
41  // input digi collections in GPU-friendly format
45 
46  // output digi collections in legacy format
49 
50  // whether to produce dummy integrity collections
52 
53  // dummy producer collections
56 
57  // dummy integrity for xtal data
61 
62  // dummy integrity for xtal data - EE specific (to be rivisited towards EB+EE common collection)
66 
67  // dummy integrity errors
71 
73 
74  // dummy TCC collections
77 
78  // FIXME better way to pass pointers from acquire to produce?
79  std::vector<uint32_t, cms::cuda::HostAllocator<uint32_t>> idsebtmp, idseetmp;
80  std::vector<uint16_t, cms::cuda::HostAllocator<uint16_t>> dataebtmp, dataeetmp;
81 };
82 
85 
86  desc.add<edm::InputTag>("digisInLabelEB", edm::InputTag{"ecalRawToDigiGPU", "ebDigis"});
87  desc.add<edm::InputTag>("digisInLabelEE", edm::InputTag{"ecalRawToDigiGPU", "eeDigis"});
88  desc.add<std::string>("digisOutLabelEB", "ebDigis");
89  desc.add<std::string>("digisOutLabelEE", "eeDigis");
90 
91  desc.add<bool>("produceDummyIntegrityCollections", false);
92 
93  std::string label = "ecalCPUDigisProducer";
94  confDesc.add(label, desc);
95 }
96 
98  : // input digi collections in GPU-friendly format
99  digisInEBToken_{consumes<InputProduct>(ps.getParameter<edm::InputTag>("digisInLabelEB"))},
100  digisInEEToken_{consumes<InputProduct>(ps.getParameter<edm::InputTag>("digisInLabelEE"))},
101 
102  // output digi collections in legacy format
103  digisOutEBToken_{produces<EBDigiCollection>(ps.getParameter<std::string>("digisOutLabelEB"))},
104  digisOutEEToken_{produces<EEDigiCollection>(ps.getParameter<std::string>("digisOutLabelEE"))},
105 
106  // whether to produce dummy integrity collections
107  produceDummyIntegrityCollections_{ps.getParameter<bool>("produceDummyIntegrityCollections")},
108 
109  // dummy collections
110  ebSrFlagToken_{dummyProduces<EBSrFlagCollection>()},
111  eeSrFlagToken_{dummyProduces<EESrFlagCollection>()},
112 
113  // dummy integrity for xtal data
114  ebIntegrityGainErrorsToken_{dummyProduces<EBDetIdCollection>("EcalIntegrityGainErrors")},
115  ebIntegrityGainSwitchErrorsToken_{dummyProduces<EBDetIdCollection>("EcalIntegrityGainSwitchErrors")},
116  ebIntegrityChIdErrorsToken_{dummyProduces<EBDetIdCollection>("EcalIntegrityChIdErrors")},
117 
118  // dummy integrity for xtal data - EE specific (to be rivisited towards EB+EE common collection)
119  eeIntegrityGainErrorsToken_{dummyProduces<EEDetIdCollection>("EcalIntegrityGainErrors")},
120  eeIntegrityGainSwitchErrorsToken_{dummyProduces<EEDetIdCollection>("EcalIntegrityGainSwitchErrors")},
121  eeIntegrityChIdErrorsToken_{dummyProduces<EEDetIdCollection>("EcalIntegrityChIdErrors")},
122 
123  // dummy integrity errors
124  integrityTTIdErrorsToken_{dummyProduces<EcalElectronicsIdCollection>("EcalIntegrityTTIdErrors")},
125  integrityZSXtalIdErrorsToken_{dummyProduces<EcalElectronicsIdCollection>("EcalIntegrityZSXtalIdErrors")},
126  integrityBlockSizeErrorsToken_{dummyProduces<EcalElectronicsIdCollection>("EcalIntegrityBlockSizeErrors")},
127 
128  //
129  pnDiodeDigisToken_{dummyProduces<EcalPnDiodeDigiCollection>()},
130 
131  // dummy TCC collections
132  ecalTriggerPrimitivesToken_{dummyProduces<EcalTrigPrimDigiCollection>("EcalTriggerPrimitives")},
133  ecalPseudoStripInputsToken_{dummyProduces<EcalPSInputDigiCollection>("EcalPseudoStripInputs")}
134 // constructor body
135 {}
136 
138  edm::EventSetup const& setup,
139  edm::WaitingTaskWithArenaHolder taskHolder) {
140  // retrieve data/ctx
141  auto const& ebdigisProduct = event.get(digisInEBToken_);
142  auto const& eedigisProduct = event.get(digisInEEToken_);
143  cms::cuda::ScopedContextAcquire ctx{ebdigisProduct, std::move(taskHolder)};
144  auto const& ebdigis = ctx.get(ebdigisProduct);
145  auto const& eedigis = ctx.get(eedigisProduct);
146 
147  // resize tmp buffers
148  dataebtmp.resize(ebdigis.size * EcalDataFrame::MAXSAMPLES);
149  dataeetmp.resize(eedigis.size * EcalDataFrame::MAXSAMPLES);
150  idsebtmp.resize(ebdigis.size);
151  idseetmp.resize(eedigis.size);
152 
153  // enqeue transfers
154  cudaCheck(cudaMemcpyAsync(
155  dataebtmp.data(), ebdigis.data.get(), dataebtmp.size() * sizeof(uint16_t), cudaMemcpyDeviceToHost, ctx.stream()));
156  cudaCheck(cudaMemcpyAsync(
157  dataeetmp.data(), eedigis.data.get(), dataeetmp.size() * sizeof(uint16_t), cudaMemcpyDeviceToHost, ctx.stream()));
158  cudaCheck(cudaMemcpyAsync(
159  idsebtmp.data(), ebdigis.ids.get(), idsebtmp.size() * sizeof(uint32_t), cudaMemcpyDeviceToHost, ctx.stream()));
160  cudaCheck(cudaMemcpyAsync(
161  idseetmp.data(), eedigis.ids.get(), idseetmp.size() * sizeof(uint32_t), cudaMemcpyDeviceToHost, ctx.stream()));
162 }
163 
165  // output collections
166  auto digisEB = std::make_unique<EBDigiCollection>();
167  auto digisEE = std::make_unique<EEDigiCollection>();
168  digisEB->resize(idsebtmp.size());
169  digisEE->resize(idseetmp.size());
170 
171  // cast constness away
172  // use pointers to buffers instead of move operator= semantics
173  // cause we have different allocators in there...
174  auto* dataEB = const_cast<uint16_t*>(digisEB->data().data());
175  auto* dataEE = const_cast<uint16_t*>(digisEE->data().data());
176  auto* idsEB = const_cast<uint32_t*>(digisEB->ids().data());
177  auto* idsEE = const_cast<uint32_t*>(digisEE->ids().data());
178 
179  // copy data
180  std::memcpy(dataEB, dataebtmp.data(), dataebtmp.size() * sizeof(uint16_t));
181  std::memcpy(dataEE, dataeetmp.data(), dataeetmp.size() * sizeof(uint16_t));
182  std::memcpy(idsEB, idsebtmp.data(), idsebtmp.size() * sizeof(uint32_t));
183  std::memcpy(idsEE, idseetmp.data(), idseetmp.size() * sizeof(uint32_t));
184 
185  event.put(digisOutEBToken_, std::move(digisEB));
186  event.put(digisOutEEToken_, std::move(digisEE));
187 
189  // dummy collections
190  event.emplace(ebSrFlagToken_);
191  event.emplace(eeSrFlagToken_);
192  // dummy integrity for xtal data
193  event.emplace(ebIntegrityGainErrorsToken_);
194  event.emplace(ebIntegrityGainSwitchErrorsToken_);
195  event.emplace(ebIntegrityChIdErrorsToken_);
196  // dummy integrity for xtal data - EE specific (to be rivisited towards EB+EE common collection)
197  event.emplace(eeIntegrityGainErrorsToken_);
198  event.emplace(eeIntegrityGainSwitchErrorsToken_);
199  event.emplace(eeIntegrityChIdErrorsToken_);
200  // dummy integrity errors
201  event.emplace(integrityTTIdErrorsToken_);
202  event.emplace(integrityZSXtalIdErrorsToken_);
203  event.emplace(integrityBlockSizeErrorsToken_);
204  //
205  event.emplace(pnDiodeDigisToken_);
206  // dummy TCC collections
207  event.emplace(ecalTriggerPrimitivesToken_);
208  event.emplace(ecalPseudoStripInputsToken_);
209  }
210 }
211 
EcalDataFrame::MAXSAMPLES
static constexpr int MAXSAMPLES
Definition: EcalDataFrame.h:48
writedatasetfile.args
args
Definition: writedatasetfile.py:18
EcalCPUDigisProducer::idsebtmp
std::vector< uint32_t, cms::cuda::HostAllocator< uint32_t > > idsebtmp
Definition: EcalCPUDigisProducer.cc:79
DeclsForKernels.h
EcalCPUDigisProducer::digisOutEBToken_
edm::EDPutTokenT< EBDigiCollection > digisOutEBToken_
Definition: EcalCPUDigisProducer.cc:47
EcalCPUDigisProducer::pnDiodeDigisToken_
edm::EDPutTokenT< EcalPnDiodeDigiCollection > pnDiodeDigisToken_
Definition: EcalCPUDigisProducer.cc:72
EcalCPUDigisProducer::produce
void produce(edm::Event &, edm::EventSetup const &) override
Definition: EcalCPUDigisProducer.cc:164
HostAllocator.h
edm::EDGetTokenT
Definition: EDGetToken.h:33
edm::EDPutTokenT
Definition: EDPutToken.h:33
EcalCPUDigisProducer::integrityZSXtalIdErrorsToken_
edm::EDPutTokenT< EcalElectronicsIdCollection > integrityZSXtalIdErrorsToken_
Definition: EcalCPUDigisProducer.cc:69
EcalDetIdCollections.h
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
EDProducer.h
EcalCPUDigisProducer::ebSrFlagToken_
edm::EDPutTokenT< EBSrFlagCollection > ebSrFlagToken_
Definition: EcalCPUDigisProducer.cc:54
EcalCPUDigisProducer
Definition: EcalCPUDigisProducer.cc:24
ElectronicsMappingGPU.h
EcalCPUDigisProducer::digisInEEToken_
edm::EDGetTokenT< InputProduct > digisInEEToken_
Definition: EcalCPUDigisProducer.cc:44
EcalDataFrame.h
singleTopDQM_cfi.setup
setup
Definition: singleTopDQM_cfi.py:37
EcalCPUDigisProducer::eeIntegrityGainErrorsToken_
edm::EDPutTokenT< EEDetIdCollection > eeIntegrityGainErrorsToken_
Definition: EcalCPUDigisProducer.cc:63
edm::WaitingTaskWithArenaHolder
Definition: WaitingTaskWithArenaHolder.h:34
MakerMacros.h
EcalCPUDigisProducer::acquire
void acquire(edm::Event const &, edm::EventSetup const &, edm::WaitingTaskWithArenaHolder) override
Definition: EcalCPUDigisProducer.cc:137
EcalCPUDigisProducer::dummyProduces
edm::EDPutTokenT< ProductType > dummyProduces(ARGS &&... args)
Definition: EcalCPUDigisProducer.cc:35
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::ConfigurationDescriptions::add
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:57
EcalCPUDigisProducer::~EcalCPUDigisProducer
~EcalCPUDigisProducer() override=default
EcalDigiCollections.h
EcalCPUDigisProducer::eeIntegrityGainSwitchErrorsToken_
edm::EDPutTokenT< EEDetIdCollection > eeIntegrityGainSwitchErrorsToken_
Definition: EcalCPUDigisProducer.cc:64
EcalCPUDigisProducer::dataebtmp
std::vector< uint16_t, cms::cuda::HostAllocator< uint16_t > > dataebtmp
Definition: EcalCPUDigisProducer.cc:80
EcalCPUDigisProducer::ebIntegrityChIdErrorsToken_
edm::EDPutTokenT< EBDetIdCollection > ebIntegrityChIdErrorsToken_
Definition: EcalCPUDigisProducer.cc:60
EcalCPUDigisProducer::ecalPseudoStripInputsToken_
edm::EDPutTokenT< EcalPSInputDigiCollection > ecalPseudoStripInputsToken_
Definition: EcalCPUDigisProducer.cc:76
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::ParameterSet
Definition: ParameterSet.h:47
Event.h
EcalCPUDigisProducer::produceDummyIntegrityCollections_
bool produceDummyIntegrityCollections_
Definition: EcalCPUDigisProducer.cc:51
EcalCPUDigisProducer::ebIntegrityGainErrorsToken_
edm::EDPutTokenT< EBDetIdCollection > ebIntegrityGainErrorsToken_
Definition: EcalCPUDigisProducer.cc:58
UnpackGPU.h
EcalCPUDigisProducer::digisOutEEToken_
edm::EDPutTokenT< EEDigiCollection > digisOutEEToken_
Definition: EcalCPUDigisProducer.cc:48
EcalCPUDigisProducer::EcalCPUDigisProducer
EcalCPUDigisProducer(edm::ParameterSet const &ps)
Definition: EcalCPUDigisProducer.cc:97
FEDRawDataCollection.h
cudaCheck.h
EcalMappingElectronicsRcd.h
edm::stream::EDProducer
Definition: EDProducer.h:38
edm::EventSetup
Definition: EventSetup.h:58
DigisCollection.h
EcalCPUDigisProducer::ebIntegrityGainSwitchErrorsToken_
edm::EDPutTokenT< EBDetIdCollection > ebIntegrityGainSwitchErrorsToken_
Definition: EcalCPUDigisProducer.cc:59
EcalCPUDigisProducer::integrityBlockSizeErrorsToken_
edm::EDPutTokenT< EcalElectronicsIdCollection > integrityBlockSizeErrorsToken_
Definition: EcalCPUDigisProducer.cc:70
cms::cuda::ScopedContextAcquire
Definition: ScopedContext.h:101
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
eostools.move
def move(src, dest)
Definition: eostools.py:511
cudaCheck
#define cudaCheck(ARG,...)
Definition: cudaCheck.h:62
EcalCPUDigisProducer::idseetmp
std::vector< uint32_t, cms::cuda::HostAllocator< uint32_t > > idseetmp
Definition: EcalCPUDigisProducer.cc:79
EcalCPUDigisProducer::integrityTTIdErrorsToken_
edm::EDPutTokenT< EcalElectronicsIdCollection > integrityTTIdErrorsToken_
Definition: EcalCPUDigisProducer.cc:68
EcalCPUDigisProducer::digisInEBToken_
edm::EDGetTokenT< InputProduct > digisInEBToken_
Definition: EcalCPUDigisProducer.cc:43
cms::cuda::Product
Definition: Product.h:34
ScopedContext.h
EcalCPUDigisProducer::ecalTriggerPrimitivesToken_
edm::EDPutTokenT< EcalTrigPrimDigiCollection > ecalTriggerPrimitivesToken_
Definition: EcalCPUDigisProducer.cc:75
EventSetup.h
EcalCPUDigisProducer::eeSrFlagToken_
edm::EDPutTokenT< EESrFlagCollection > eeSrFlagToken_
Definition: EcalCPUDigisProducer.cc:55
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
EcalCPUDigisProducer::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &)
Definition: EcalCPUDigisProducer.cc:83
ParameterSet.h
EcalCPUDigisProducer::dataeetmp
std::vector< uint16_t, cms::cuda::HostAllocator< uint16_t > > dataeetmp
Definition: EcalCPUDigisProducer.cc:80
event
Definition: event.py:1
edm::Event
Definition: Event.h:73
edm::InputTag
Definition: InputTag.h:15
label
const char * label
Definition: PFTauDecayModeTools.cc:11
EcalCPUDigisProducer::eeIntegrityChIdErrorsToken_
edm::EDPutTokenT< EEDetIdCollection > eeIntegrityChIdErrorsToken_
Definition: EcalCPUDigisProducer.cc:65