CMS 3D CMS Logo

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