CMS 3D CMS Logo

SiPixelRawToCluster.cc
Go to the documentation of this file.
1 #include <memory>
2 #include <stdexcept>
3 #include <string>
4 #include <utility>
5 #include <vector>
6 
37 
39 
41 
42  template <typename TrackerTraits>
44  public:
45  explicit SiPixelRawToCluster(const edm::ParameterSet& iConfig);
46  ~SiPixelRawToCluster() override = default;
47 
48  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
50 
51  private:
52  void acquire(device::Event const& iEvent, device::EventSetup const& iSetup) override;
53  void produce(device::Event& iEvent, device::EventSetup const& iSetup) override;
54 
60 
65 
66  std::unique_ptr<SiPixelFedCablingTree> cabling_;
67  std::vector<unsigned int> fedIds_;
69  std::unique_ptr<PixelUnpackingRegions> regions_;
70 
73 
74  const bool includeErrors_;
75  const bool useQuality_;
76  uint32_t nDigis_;
78  };
79 
80  template <typename TrackerTraits>
82  : rawGetToken_(consumes(iConfig.getParameter<edm::InputTag>("InputLabel"))),
83  digiPutToken_(produces()),
84  clusterPutToken_(produces()),
85  mapToken_(esConsumes()),
86  gainsToken_(esConsumes()),
88  edm::ESInputTag("", iConfig.getParameter<std::string>("CablingMapLabel")))),
89  includeErrors_(iConfig.getParameter<bool>("IncludeErrors")),
90  useQuality_(iConfig.getParameter<bool>("UseQualityInfo")),
91  clusterThresholds_{iConfig.getParameter<int32_t>("clusterThreshold_layer1"),
92  iConfig.getParameter<int32_t>("clusterThreshold_otherLayers"),
93  static_cast<float>(iConfig.getParameter<double>("VCaltoElectronGain")),
94  static_cast<float>(iConfig.getParameter<double>("VCaltoElectronGain_L1")),
95  static_cast<float>(iConfig.getParameter<double>("VCaltoElectronOffset")),
96  static_cast<float>(iConfig.getParameter<double>("VCaltoElectronOffset_L1"))} {
97  if (includeErrors_) {
98  digiErrorPutToken_ = produces();
99  fmtErrorToken_ = produces();
100  }
101 
102  // regions
103  if (!iConfig.getParameter<edm::ParameterSet>("Regions").getParameterNames().empty()) {
104  regions_ = std::make_unique<PixelUnpackingRegions>(iConfig, consumesCollector());
105  }
106  }
107 
108  template <typename TrackerTraits>
111  desc.add<bool>("IncludeErrors", true);
112  desc.add<bool>("UseQualityInfo", false);
113  // Note: this parameter is obsolete: it is ignored and will have no effect.
114  // It is kept to avoid breaking older configurations, and will not be printed in the generated cfi.py file.
115  desc.addOptionalNode(edm::ParameterDescription<uint32_t>("MaxFEDWords", 0, true), false)
116  ->setComment("This parameter is obsolete and will be ignored.");
117  desc.add<int32_t>("clusterThreshold_layer1", pixelClustering::clusterThresholdLayerOne);
118  desc.add<int32_t>("clusterThreshold_otherLayers", pixelClustering::clusterThresholdOtherLayers);
119  desc.add<double>("VCaltoElectronGain", 47.f);
120  desc.add<double>("VCaltoElectronGain_L1", 50.f);
121  desc.add<double>("VCaltoElectronOffset", -60.f);
122  desc.add<double>("VCaltoElectronOffset_L1", -670.f);
123 
124  desc.add<edm::InputTag>("InputLabel", edm::InputTag("rawDataCollector"));
125  {
127  psd0.addOptional<std::vector<edm::InputTag>>("inputs");
128  psd0.addOptional<std::vector<double>>("deltaPhi");
129  psd0.addOptional<std::vector<double>>("maxZ");
130  psd0.addOptional<edm::InputTag>("beamSpot");
131  desc.add<edm::ParameterSetDescription>("Regions", psd0)
132  ->setComment("## Empty Regions PSet means complete unpacking");
133  }
134  desc.add<std::string>("CablingMapLabel", "")->setComment("CablingMap label"); //Tav
135  descriptions.addWithDefaultLabel(desc);
136  }
137 
138  template <typename TrackerTraits>
140  [[maybe_unused]] auto const& hMap = iSetup.getData(mapToken_);
141  auto const& dGains = iSetup.getData(gainsToken_);
143  auto modulesToUnpackRegional =
144  cms::alpakatools::make_device_buffer<unsigned char[]>(iEvent.queue(), ::pixelgpudetails::MAX_SIZE);
145  const unsigned char* modulesToUnpack;
146  // initialize cabling map or update if necessary
147  if (recordWatcher_.check(iSetup)) {
148  // cabling map, which maps online address (fed->link->ROC->local pixel) to offline (DetId->global pixel)
149  cablingMap_ = &iSetup.getData(cablingMapToken_);
150  fedIds_ = cablingMap_->fedIds();
151  cabling_ = cablingMap_->cablingTree();
152  LogDebug("map version:") << cablingMap_->version();
153  }
154  if (regions_) {
155  regions_->run(iEvent, iSetup);
156  LogDebug("SiPixelRawToCluster") << "region2unpack #feds: " << regions_->nFEDs();
157  LogDebug("SiPixelRawToCluster") << "region2unpack #modules (BPIX,EPIX,total): " << regions_->nBarrelModules()
158  << " " << regions_->nForwardModules() << " " << regions_->nModules();
159 
160  modulesToUnpackRegional = SiPixelMappingUtilities::getModToUnpRegionalAsync(
161  *(regions_->modulesToUnpack()), cabling_.get(), fedIds_, iEvent.queue());
162  modulesToUnpack = modulesToUnpackRegional.data();
163  } else {
164  modulesToUnpack = hMap->modToUnpDefault();
165  }
166 
167  const auto& buffers = iEvent.get(rawGetToken_);
168 
169  errors_.clear();
170 
171  // GPU specific: Data extraction for RawToDigi GPU
172  unsigned int wordCounter = 0;
173  unsigned int fedCounter = 0;
174  bool errorsInEvent = false;
175  std::vector<unsigned int> index(fedIds_.size(), 0);
176  std::vector<cms_uint32_t const*> start(fedIds_.size(), nullptr);
177  std::vector<ptrdiff_t> words(fedIds_.size(), 0);
178  // In CPU algorithm this loop is part of PixelDataFormatter::interpretRawData()
179  ErrorChecker errorcheck;
180  for (uint32_t i = 0; i < fedIds_.size(); ++i) {
181  const int fedId = fedIds_[i];
182  if (regions_ && !regions_->mayUnpackFED(fedId))
183  continue;
184 
185  // for GPU
186  // first 150 index stores the fedId and next 150 will store the
187  // start index of word in that fed
189  fedCounter++;
190 
191  // get event data for this fed
192  const FEDRawData& rawData = buffers.FEDData(fedId);
193 
194  // GPU specific
195  int nWords = rawData.size() / sizeof(cms_uint64_t);
196  if (nWords == 0) {
197  continue;
198  }
199  // check CRC bit
200  const cms_uint64_t* trailer = reinterpret_cast<const cms_uint64_t*>(rawData.data()) + (nWords - 1);
201  if (not errorcheck.checkCRC(errorsInEvent, fedId, trailer, errors_)) {
202  continue;
203  }
204  // check headers
205  const cms_uint64_t* header = reinterpret_cast<const cms_uint64_t*>(rawData.data());
206  header--;
207  bool moreHeaders = true;
208  while (moreHeaders) {
209  header++;
210  bool headerStatus = errorcheck.checkHeader(errorsInEvent, fedId, header, errors_);
211  moreHeaders = headerStatus;
212  }
213 
214  // check trailers
215  bool moreTrailers = true;
216  trailer++;
217  while (moreTrailers) {
218  trailer--;
219  bool trailerStatus = errorcheck.checkTrailer(errorsInEvent, fedId, nWords, trailer, errors_);
220  moreTrailers = trailerStatus;
221  }
222 
223  const cms_uint32_t* bw = (const cms_uint32_t*)(header + 1);
224  const cms_uint32_t* ew = (const cms_uint32_t*)(trailer);
225 
226  assert(0 == (ew - bw) % 2);
227  index[i] = wordCounter;
228  start[i] = bw;
229  words[i] = (ew - bw);
230  wordCounter += (ew - bw);
231 
232  } // end of for loop
233  nDigis_ = wordCounter;
234  if (nDigis_ == 0)
235  return;
236 
237  // copy the FED data to a single cpu buffer
238  pixelDetails::WordFedAppender wordFedAppender(nDigis_);
239  for (uint32_t i = 0; i < fedIds_.size(); ++i) {
240  wordFedAppender.initializeWordFed(fedIds_[i], index[i], start[i], words[i]);
241  }
242  Algo_.makePhase1ClustersAsync(iEvent.queue(),
243  clusterThresholds_,
244  hMap.const_view(),
245  modulesToUnpack,
246  dGains.const_view(),
247  wordFedAppender,
248  wordCounter,
249  fedCounter,
250  useQuality_,
251  includeErrors_,
253  }
254 
255  template <typename TrackerTraits>
257  if (nDigis_ == 0) {
258  // Cannot use the default constructor here, as it would not allocate memory.
259  // In the case of no digis, clusters_d are not being instantiated, but are
260  // still used downstream to initialize TrackingRecHitSoADevice. If there
261  // are no valid pointers to clusters' Collection columns, instantiation
262  // of TrackingRecHits fail. Example: workflow 11604.0
263 
264  iEvent.emplace(digiPutToken_, nDigis_, iEvent.queue());
265  iEvent.emplace(clusterPutToken_, pixelTopology::Phase1::numberOfModules, iEvent.queue());
266  if (includeErrors_) {
267  iEvent.emplace(digiErrorPutToken_);
268  iEvent.emplace(fmtErrorToken_);
269  }
270  return;
271  }
272 
273  iEvent.emplace(digiPutToken_, Algo_.getDigis());
274  iEvent.emplace(clusterPutToken_, Algo_.getClusters());
275  if (includeErrors_) {
276  iEvent.emplace(digiErrorPutToken_, Algo_.getErrors());
277  iEvent.emplace(fmtErrorToken_, std::move(errors_));
278  }
279  }
280 
283 
284 } // namespace ALPAKA_ACCELERATOR_NAMESPACE
285 
286 // define as framework plugin
Definition: start.py:1
constexpr uint16_t clusterThresholdOtherLayers
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
ParameterDescriptionBase * addOptional(U const &iLabel, T const &value)
SiPixelRawToCluster< pixelTopology::Phase1 > SiPixelRawToClusterPhase1
edm::ESWatcher< SiPixelFedCablingMapRcd > recordWatcher_
const edm::ESGetToken< SiPixelFedCablingMap, SiPixelFedCablingMapRcd > cablingMapToken_
static MessageDrop * instance()
Definition: MessageDrop.cc:33
device::EDPutToken< SiPixelDigisSoACollection > digiPutToken_
edm::EDPutTokenT< SiPixelFormatterErrors > fmtErrorToken_
assert(be >=bs)
int iEvent
Definition: GenABIO.cc:224
const device::ESGetToken< SiPixelMappingDevice, SiPixelMappingSoARecord > mapToken_
void acquire(device::Event const &iEvent, device::EventSetup const &iSetup) override
PortableCollection< SiPixelGainCalibrationForHLTSoA > SiPixelGainCalibrationForHLTDevice
constexpr uint16_t clusterThresholdLayerOne
void produce(device::Event &iEvent, device::EventSetup const &iSetup) override
unsigned int cms_uint32_t
Definition: typedefs.h:15
SiPixelRawToCluster< pixelTopology::HIonPhase1 > SiPixelRawToClusterHIonPhase1
T const & getData(edm::ESGetToken< T, R > const &iToken) const
Definition: EventSetup.h:32
constexpr float gains[NGAINS]
Definition: EcalConstants.h:20
device::EDPutToken< SiPixelClustersSoACollection > clusterPutToken_
edm::EDGetTokenT< FEDRawDataCollection > rawGetToken_
HLT enums.
std::unique_ptr< SiPixelFedCablingTree > cabling_
constexpr unsigned int MAX_SIZE
#define DEFINE_FWK_ALPAKA_MODULE(name)
Definition: MakerMacros.h:16
SiPixelRawToCluster(const edm::ParameterSet &iConfig)
void initializeWordFed(int fedId, unsigned int wordCounterGPU, const uint32_t *src, unsigned int length)
const device::ESGetToken< SiPixelGainCalibrationForHLTDevice, SiPixelGainCalibrationForHLTSoARcd > gainsToken_
unsigned long long cms_uint64_t
Definition: typedefs.h:17
device::EDPutToken< SiPixelDigiErrorsSoACollection > digiErrorPutToken_
ALPAKA_FN_HOST_ACC ALPAKA_FN_ACC static ALPAKA_FN_INLINE cms::alpakatools::device_buffer< Device, unsigned char[]> getModToUnpRegionalAsync(std::set< unsigned int > const &modules, const SiPixelFedCablingTree *cabling, std::vector< unsigned int > const &fedIds, Queue &queue)
std::vector< std::string > getParameterNames() const
std::unique_ptr< PixelUnpackingRegions > regions_
def move(src, dest)
Definition: eostools.py:511
std::map< cms_uint32_t, DetErrors > Errors
static constexpr uint16_t numberOfModules
#define LogDebug(id)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)