Skip to content

Commit e292500

Browse files
authored
[PWGJE] Use const& and std::move to avoid copies (#17710)
1 parent afa6bfe commit e292500

26 files changed

Lines changed: 56 additions & 53 deletions

PWGJE/Core/JetBkgSubUtils.cxx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <algorithm>
3030
#include <cstdlib>
3131
#include <tuple>
32+
#include <utility>
3233
#include <vector>
3334

3435
#include <math.h>
@@ -41,7 +42,7 @@ JetBkgSubUtils::JetBkgSubUtils(float jetBkgR_out, float bkgEtaMin_out, float bkg
4142
constSubAlpha(constSubAlpha_out),
4243
constSubRMax(constSubRMax_out),
4344
nHardReject(nHardReject_out),
44-
ghostAreaSpec(ghostAreaSpec_out)
45+
ghostAreaSpec(std::move(ghostAreaSpec_out))
4546

4647
{
4748
}
@@ -162,11 +163,11 @@ std::vector<fastjet::PseudoJet> JetBkgSubUtils::doJetConstSub(std::vector<fastje
162163
return constituentSub(jets);
163164
}
164165

165-
double JetBkgSubUtils::getMd(fastjet::PseudoJet jet) const
166+
double JetBkgSubUtils::getMd(const fastjet::PseudoJet& jet) const
166167
{
167168
// Refere to https://arxiv.org/abs/1211.2811 for the rhoM caclulation
168169
double sum(0);
169-
for (auto constituent : jet.constituents()) {
170+
for (const auto& constituent : jet.constituents()) {
170171
sum += TMath::Sqrt(constituent.m() * constituent.m() + constituent.pt() * constituent.pt()) - constituent.pt();
171172
}
172173

PWGJE/Core/JetBkgSubUtils.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <fastjet/Selector.hh>
2525

2626
#include <tuple>
27+
#include <utility>
2728
#include <vector>
2829

2930
#include <math.h>
@@ -107,7 +108,7 @@ class JetBkgSubUtils
107108
constSubRMax = rmax_out;
108109
}
109110
void setDoRhoMassSub(bool doMSub_out = true) { doRhoMassSub = doMSub_out; }
110-
void setGhostAreaSpec(fastjet::GhostedAreaSpec ghostAreaSpec_out) { ghostAreaSpec = ghostAreaSpec_out; }
111+
void setGhostAreaSpec(fastjet::GhostedAreaSpec ghostAreaSpec_out) { ghostAreaSpec = std::move(ghostAreaSpec_out); }
111112

112113
// Getters
113114
float getJetBkgR() const { return jetBkgR; }
@@ -124,7 +125,7 @@ class JetBkgSubUtils
124125
fastjet::Selector getRhoSelector() const { return selRho; }
125126

126127
// Calculate the jet mass
127-
double getMd(fastjet::PseudoJet jet) const;
128+
double getMd(const fastjet::PseudoJet& jet) const;
128129

129130
protected:
130131
float jetBkgR = 0.2;

PWGJE/Core/JetDerivedDataUtilities.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ enum JCollisionSubGeneratorId {
6363
};
6464

6565
template <typename T>
66-
bool selectCollision(T const& collision, const std::vector<int>& eventSelectionMaskBits, bool skipMBGapEvents = true, bool rctSelection = true, std::string rctLabel = "CBT_hadronPID", bool rejectLimitedAcceptanceRct = false, bool requireZDCRct = false)
66+
bool selectCollision(T const& collision, const std::vector<int>& eventSelectionMaskBits, bool skipMBGapEvents = true, bool rctSelection = true, const std::string& rctLabel = "CBT_hadronPID", bool rejectLimitedAcceptanceRct = false, bool requireZDCRct = false)
6767
{
6868

6969
if (skipMBGapEvents && collision.getSubGeneratorId() == JCollisionSubGeneratorId::mbGap) {
@@ -96,7 +96,7 @@ bool selectCollision(T const& collision, const std::vector<int>& eventSelectionM
9696
return !isOrCondition;
9797
}
9898

99-
bool eventSelectionMasksContainSelection(const std::string& eventSelectionMasks, std::string selection)
99+
bool eventSelectionMasksContainSelection(const std::string& eventSelectionMasks, const std::string& selection)
100100
{
101101
size_t position = 0;
102102
while ((position = eventSelectionMasks.find(selection, position)) != std::string::npos) {
@@ -325,7 +325,7 @@ bool selectTrigger(T const& collision, int triggerMaskBit)
325325
return collision.triggerSel() & (1ULL << triggerMaskBit);
326326
}
327327

328-
bool triggerMasksContainTrigger(const std::string& triggerMasks, std::string trigger)
328+
bool triggerMasksContainTrigger(const std::string& triggerMasks, const std::string& trigger)
329329
{
330330
size_t position = 0;
331331
while ((position = triggerMasks.find(trigger, position)) != std::string::npos) {
@@ -733,7 +733,7 @@ bool selectTrackDcaZ(T const& track, double dcaZmax = 99.)
733733
return std::abs(track.dcaZ()) < dcaZmax;
734734
}
735735

736-
std::vector<int> initialiseClusterDefinitions(const std::string clusterDefinitions)
736+
std::vector<int> initialiseClusterDefinitions(const std::string& clusterDefinitions)
737737
{
738738
std::vector<int> clusterDefinitionsVec;
739739
if (clusterDefinitions.empty()) {

PWGJE/Core/JetFindingUtilities.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include <memory>
3939
#include <string>
4040
#include <type_traits>
41+
#include <utility>
4142
#include <vector>
4243

4344
#include <math.h>
@@ -278,9 +279,9 @@ bool analyseV0s(std::vector<fastjet::PseudoJet>& inputParticles, T const& v0s, f
278279
* @param doHFJetFinding set whether only jets containing a HF candidate are saved
279280
*/
280281
template <typename T, typename U, typename V>
281-
void findJets(JetFinder& jetFinder, std::vector<fastjet::PseudoJet>& inputParticles, float jetPtMin, float jetPtMax, std::vector<double> jetRadius, float jetAreaFractionMin, T const& collision, U& jetsTable, V& constituentsTable, std::shared_ptr<THn> thnSparseJet, bool fillThnSparse, bool doCandidateJetFinding = false)
282+
void findJets(JetFinder& jetFinder, std::vector<fastjet::PseudoJet>& inputParticles, float jetPtMin, float jetPtMax, std::vector<double> jetRadius, float jetAreaFractionMin, T const& collision, U& jetsTable, V& constituentsTable, const std::shared_ptr<THn>& thnSparseJet, bool fillThnSparse, bool doCandidateJetFinding = false)
282283
{
283-
auto jetRValues = static_cast<std::vector<double>>(jetRadius);
284+
auto jetRValues = static_cast<std::vector<double>>(std::move(jetRadius));
284285
jetFinder.jetPtMin = jetPtMin;
285286
jetFinder.jetPtMax = jetPtMax;
286287
for (auto R : jetRValues) {

PWGJE/Core/MlResponseHfTagging.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,9 @@
3434
// Fill the map of available input features
3535
// the key is the feature's name (std::string)
3636
// the value is the corresponding value in EnumInputFeatures
37-
#define FILL_MAP_BJET(FEATURE) \
38-
{ \
39-
#FEATURE, static_cast<uint8_t>(InputFeaturesBTag::FEATURE) \
40-
}
37+
#define FILL_MAP_BJET(FEATURE) \
38+
{ \
39+
#FEATURE, static_cast<uint8_t>(InputFeaturesBTag::FEATURE)}
4140

4241
// Check if the index of mCachedIndices (index associated to a FEATURE)
4342
// matches the entry in EnumInputFeatures associated to this FEATURE
@@ -424,7 +423,7 @@ class GNNBjetAllocator : public TensorAllocator
424423

425424
public:
426425
GNNBjetAllocator() : TensorAllocator(), nJetFeat(4), nTrkFeat(13), nFlav(3), nTrkOrigin(5), maxNNodes(40), tfFunc([](float x) { return x; }) {}
427-
GNNBjetAllocator(int64_t nJetFeat, int64_t nTrkFeat, int64_t nFlav, int64_t nTrkOrigin, std::vector<float>& tfJetMean, std::vector<float>& tfJetStdev, std::vector<float>& tfTrkMean, std::vector<float>& tfTrkStdev, int64_t maxNNodes = 40, std::string tfFuncType = "linear")
426+
GNNBjetAllocator(int64_t nJetFeat, int64_t nTrkFeat, int64_t nFlav, int64_t nTrkOrigin, std::vector<float>& tfJetMean, std::vector<float>& tfJetStdev, std::vector<float>& tfTrkMean, std::vector<float>& tfTrkStdev, int64_t maxNNodes = 40, const std::string& tfFuncType = "linear")
428427
: TensorAllocator(), nJetFeat(nJetFeat), nTrkFeat(nTrkFeat), nFlav(nFlav), nTrkOrigin(nTrkOrigin), maxNNodes(maxNNodes), tfJetMean(tfJetMean), tfJetStdev(tfJetStdev), tfTrkMean(tfTrkMean), tfTrkStdev(tfTrkStdev), tfFunc([](float x) { return x; })
429428
{
430429
if (tfFuncType == "asinh") {

PWGJE/DataModel/EMCALClusterDefinition.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#define PWGJE_DATAMODEL_EMCALCLUSTERDEFINITION_H_
1818

1919
#include <string>
20+
#include <utility>
2021

2122
namespace o2::aod
2223
{
@@ -50,7 +51,7 @@ struct EMCALClusterDefinition {
5051
algorithm = pAlgorithm;
5152
storageID = pStorageID;
5253
selectedCellType = pSelectedCellType;
53-
name = pName;
54+
name = std::move(pName);
5455
seedEnergy = pSeedEnergy;
5556
minCellEnergy = pMinCellEnergy;
5657
timeMin = pTimeMin;

PWGJE/TableProducer/derivedDataProducer.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,7 @@ struct JetDerivedDataProducerTask {
620620
void processClusters(aod::Collision const&, aod::EMCALClusters const& clusters, aod::EMCALClusterCells const& cells, aod::Calos const&, aod::EMCALMatchedTracks const& matchedTracks, soa::Join<aod::Tracks, aod::TracksExtra> const&)
621621
{
622622

623-
for (auto cluster : clusters) {
623+
for (const auto& cluster : clusters) {
624624

625625
auto const clusterCells = cells.sliceBy(preslices.perClusterCells, cluster.globalIndex());
626626

PWGJE/TableProducer/derivedDataSelector.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,9 @@ struct JetDerivedDataSelector {
155155

156156
void processSelectMcCollisionsPerCollision(aod::JMcCollisions const& mcCollisions, soa::Join<aod::JCollisions, aod::JMcCollisionLbs> const& collisions)
157157
{
158-
for (auto mcCollision : mcCollisions) {
158+
for (const auto& mcCollision : mcCollisions) {
159159
const auto collisionsPerMcCollision = collisions.sliceBy(CollisionsPerMcCollision, mcCollision.globalIndex());
160-
for (auto collision : collisionsPerMcCollision) {
160+
for (const auto& collision : collisionsPerMcCollision) {
161161
if (collisionFlag[collision.globalIndex()]) {
162162
mcCollisionFlag[mcCollision.globalIndex()] = true;
163163
}

PWGJE/TableProducer/derivedDataWriter.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -713,11 +713,11 @@ struct JetDerivedDataWriter {
713713

714714
const auto particlesPerMcCollision = particles.sliceBy(preslices.ParticlesPerMcCollision, mcCollision.globalIndex());
715715

716-
for (auto particle : particlesPerMcCollision) {
716+
for (const auto& particle : particlesPerMcCollision) {
717717
particleMapping[particle.globalIndex()] = particleTableIndex;
718718
particleTableIndex++;
719719
}
720-
for (auto particle : particlesPerMcCollision) {
720+
for (const auto& particle : particlesPerMcCollision) {
721721

722722
std::vector<int32_t> mothersIds;
723723
int daughtersIds[2] = {-1, -1};

PWGJE/TableProducer/mcOutlierRejector.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ struct McOutlierRejectorTask {
6969
if (selectionObjects.size() != 0) {
7070
float selectionObjectPt = 0.0;
7171
if constexpr (std::is_same_v<std::decay_t<T>, aod::JetTracksMCD> || std::is_same_v<std::decay_t<T>, aod::JetParticles>) {
72-
for (auto selectionObject : selectionObjects) {
72+
for (const auto& selectionObject : selectionObjects) {
7373
selectionObjectPt = selectionObject.pt();
7474
// may be slow - could save only MC particle then check difference only for tracks IDd as outliers?
7575
if constexpr (std::is_same_v<std::decay_t<T>, aod::JetTracksMCD>) { // tracks

0 commit comments

Comments
 (0)