From c733b859fc74acf861093e1fcf585504be6a9c5d Mon Sep 17 00:00:00 2001 From: AuroraPerego Date: Fri, 30 Aug 2024 00:03:23 +0200 Subject: [PATCH] use reserve instead of defining the size in the constructor --- .../HGCalLayerClustersFromSoAProducer.cc | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/RecoLocalCalo/HGCalRecProducers/plugins/HGCalLayerClustersFromSoAProducer.cc b/RecoLocalCalo/HGCalRecProducers/plugins/HGCalLayerClustersFromSoAProducer.cc index 8696bc79cc7e9..1c75439261287 100644 --- a/RecoLocalCalo/HGCalRecProducers/plugins/HGCalLayerClustersFromSoAProducer.cc +++ b/RecoLocalCalo/HGCalRecProducers/plugins/HGCalLayerClustersFromSoAProducer.cc @@ -66,6 +66,12 @@ class HGCalLayerClustersFromSoAProducer : public edm::stream::EDProducer<> { std::unique_ptr> clusters(new std::vector); clusters->reserve(deviceData->metadata().size()); + // Create a vector of locations, where each location holds a + // vector of floats. These vectors are used to compute the time for + // each cluster. + std::vector> times(deviceData->metadata().size()); + std::vector> timeErrors(deviceData->metadata().size()); + for (int i = 0; i < deviceData->metadata().size(); ++i) { std::vector> thisCluster; thisCluster.reserve(deviceView.cells(i)); @@ -75,20 +81,14 @@ class HGCalLayerClustersFromSoAProducer : public edm::stream::EDProducer<> { std::move(thisCluster), algoId_); clusters->back().setSeed(deviceView.seed(i)); + times[i].reserve(deviceView.cells(i)); + timeErrors[i].reserve(deviceView.cells(i)); } // Populate hits and fractions required to compute the cluster's time. // This procedure is complex and involves two SoAs: the original RecHits // SoA and the clustering algorithm's output SoA. Both SoAs have the same // cardinality, and crucially, the output SoA includes the cluster index. - - // Create a vector of locations, where each location holds a - // vector of 16 floats. These vectors are used to compute the time for - // each cluster. The size of 16 is a heuristic to minimize memory - // reallocation and the associated overhead when the vector's capacity - // needs to be extended. - std::vector> times(clusters->size(), std::vector(16, 0.0f)); - std::vector> timeErrors(clusters->size(), std::vector(16, 0.0f)); for (int32_t i = 0; i < soaRecHitsExtra_v.metadata().size(); ++i) { if (soaRecHitsExtra_v[i].clusterIndex() == -1) { continue; @@ -105,6 +105,7 @@ class HGCalLayerClustersFromSoAProducer : public edm::stream::EDProducer<> { // Finally, compute and assign the time to each cluster. std::vector> cluster_times; + cluster_times.reserve(clusters->size()); hgcalsimclustertime::ComputeClusterTime timeEstimator; for (unsigned i = 0; i < clusters->size(); ++i) { if (detector_ != "BH") {