Skip to content

Commit 2fcd35c

Browse files
authored
[ALICE3] Use const& and std::move to avoid copies (#17702)
1 parent 8f530a6 commit 2fcd35c

10 files changed

Lines changed: 25 additions & 24 deletions

ALICE3/Core/DelphesO2LutWriter.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ void DelphesO2LutWriter::diagonalise(lutEntry_t& lutEntry)
376376
// m.Print();
377377
TMatrixDSymEigen eigen(m);
378378
// eigenvalues vector
379-
TVectorD eigenVal = eigen.GetEigenValues();
379+
const TVectorD& eigenVal = eigen.GetEigenValues();
380380
for (int i = 0; i < kEig; ++i)
381381
lutEntry.eigval[i] = eigenVal[i];
382382
// eigenvectors matrix

ALICE3/Core/FastTracker.cxx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ namespace fastsim
5151

5252
// +-~-<*>-~-+-~-<*>-~-+-~-<*>-~-+-~-<*>-~-+-~-<*>-~-+-~-<*>-~-+-~-<*>-~-+-~-<*>-~-+
5353

54-
DetLayer* FastTracker::AddLayer(TString name, float r, float z, float x0, float xrho, float resRPhi, float resZ, float eff, int type)
54+
DetLayer* FastTracker::AddLayer(const TString& name, float r, float z, float x0, float xrho, float resRPhi, float resZ, float eff, int type)
5555
{
5656
LOG(debug) << "Adding layer " << name << " r=" << r << " z=" << z << " x0=" << x0 << " xrho=" << xrho << " resRPhi=" << resRPhi << " resZ=" << resZ << " eff=" << eff << " type=" << type;
5757
DetLayer newLayer(name, r, z, x0, xrho, resRPhi, resZ, eff, type);
@@ -154,7 +154,7 @@ void FastTracker::AddTPC(float phiResMean, float zResMean)
154154
}
155155
}
156156

157-
void FastTracker::AddGenericDetector(o2::fastsim::GeometryEntry configMap, o2::ccdb::BasicCCDBManager* ccdbManager)
157+
void FastTracker::AddGenericDetector(const o2::fastsim::GeometryEntry& configMap, o2::ccdb::BasicCCDBManager* ccdbManager)
158158
{
159159
// Layers
160160
for (const auto& layer : configMap.getLayerNames()) {
@@ -586,7 +586,7 @@ int FastTracker::FastTrack(o2::track::TrackParCov inputTrack, o2::track::TrackPa
586586
m.SetMatrixArray(reinterpret_cast<double*>(fcovm));
587587
TMatrixDSymEigen eigen(m);
588588
TMatrixD eigVec = eigen.GetEigenVectors();
589-
TVectorD eigVal = eigen.GetEigenValues();
589+
const TVectorD& eigVal = eigen.GetEigenValues();
590590
bool negEigVal = false;
591591
for (int ii = 0; ii < 5; ii++) {
592592
if (eigVal[ii] < 0.0f)

ALICE3/Core/FastTracker.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class FastTracker
4646
virtual ~FastTracker() {}
4747

4848
// Layer and layer configuration
49-
DetLayer* AddLayer(TString name, float r, float z, float x0, float xrho, float resRPhi = 0.0f, float resZ = 0.0f, float eff = 0.0f, int type = 0);
49+
DetLayer* AddLayer(const TString& name, float r, float z, float x0, float xrho, float resRPhi = 0.0f, float resZ = 0.0f, float eff = 0.0f, int type = 0);
5050

5151
/// Add a dead region in phi for a specific layer
5252
/// \param layerName Name of the layer to modify
@@ -59,11 +59,11 @@ class FastTracker
5959
size_t GetNLayers() const { return layers.size(); }
6060
bool IsLayerInert(const int layer) const { return layers[layer].isInert(); }
6161
void ClearLayers() { layers.clear(); }
62-
void SetRadiationLength(const std::string layerName, float x0) { layers[GetLayerIndex(layerName)].setRadiationLength(x0); }
63-
void SetRadius(const std::string layerName, float r) { layers[GetLayerIndex(layerName)].setRadius(r); }
64-
void SetResolutionRPhi(const std::string layerName, float resRPhi) { layers[GetLayerIndex(layerName)].setResolutionRPhi(resRPhi); }
65-
void SetResolutionZ(const std::string layerName, float resZ) { layers[GetLayerIndex(layerName)].setResolutionZ(resZ); }
66-
void SetResolution(const std::string layerName, float resRPhi, float resZ)
62+
void SetRadiationLength(const std::string& layerName, float x0) { layers[GetLayerIndex(layerName)].setRadiationLength(x0); }
63+
void SetRadius(const std::string& layerName, float r) { layers[GetLayerIndex(layerName)].setRadius(r); }
64+
void SetResolutionRPhi(const std::string& layerName, float resRPhi) { layers[GetLayerIndex(layerName)].setResolutionRPhi(resRPhi); }
65+
void SetResolutionZ(const std::string& layerName, float resZ) { layers[GetLayerIndex(layerName)].setResolutionZ(resZ); }
66+
void SetResolution(const std::string& layerName, float resRPhi, float resZ)
6767
{
6868
SetResolutionRPhi(layerName, resRPhi);
6969
SetResolutionZ(layerName, resZ);
@@ -80,7 +80,7 @@ class FastTracker
8080
*
8181
* @param configMap Configuration map describing the detector.
8282
*/
83-
void AddGenericDetector(o2::fastsim::GeometryEntry configMap, o2::ccdb::BasicCCDBManager* ccdbManager = nullptr);
83+
void AddGenericDetector(const o2::fastsim::GeometryEntry& configMap, o2::ccdb::BasicCCDBManager* ccdbManager = nullptr);
8484

8585
void Print();
8686

ALICE3/Core/FlatLutWriter.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ void FlatLutWriter::diagonalise(lutEntry_t& lutEntry)
392392
TMatrixDSymEigen eigen(m);
393393

394394
// Eigenvalues
395-
TVectorD eigenVal = eigen.GetEigenValues();
395+
const TVectorD& eigenVal = eigen.GetEigenValues();
396396
for (int i = 0; i < kEig; ++i)
397397
lutEntry.eigval[i] = eigenVal[i];
398398

ALICE3/Core/GeometryContainer.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ void GeometryEntry::replaceValue(const std::string& layerName, const std::string
159159
setValue(layerName, key, value);
160160
}
161161

162-
std::string GeometryEntry::accessFile(const std::string& path, const std::string downloadPath, o2::ccdb::BasicCCDBManager* ccdb, int timeoutSeconds)
162+
std::string GeometryEntry::accessFile(const std::string& path, const std::string& downloadPath, o2::ccdb::BasicCCDBManager* ccdb, int timeoutSeconds)
163163
{
164164

165165
if (path.rfind("ccdb:", 0) == 0) {

ALICE3/Core/GeometryContainer.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ namespace o2::fastsim
3333
struct GeometryEntry {
3434
// Default constructor
3535
GeometryEntry() = default;
36-
explicit GeometryEntry(std::string filename, o2::ccdb::BasicCCDBManager* ccdb = nullptr)
36+
explicit GeometryEntry(const std::string& filename, o2::ccdb::BasicCCDBManager* ccdb = nullptr)
3737
{
3838
mFileName = accessFile(filename, "./.ALICE3/Configuration/", ccdb);
3939
mConfigurations = GeometryEntry::parseTEnvConfiguration(mFileName, mLayerNames);
@@ -59,7 +59,7 @@ struct GeometryEntry {
5959
* @param timeoutSeconds If positive, then this function will wait for these seconds after download before removing the downloaded file.
6060
* @return The local path to the file, either the original local path or the path to the retrieved file from ccdb
6161
*/
62-
static std::string accessFile(const std::string& path, const std::string downloadPath = "/tmp/GeometryContainer/", o2::ccdb::BasicCCDBManager* ccdb = nullptr, int timeoutSeconds = 0);
62+
static std::string accessFile(const std::string& path, const std::string& downloadPath = "/tmp/GeometryContainer/", o2::ccdb::BasicCCDBManager* ccdb = nullptr, int timeoutSeconds = 0);
6363

6464
std::map<std::string, std::map<std::string, std::string>> getConfigurations() const { return mConfigurations; }
6565
std::map<std::string, std::string> getConfiguration(const std::string& layerName) const;

ALICE3/Macros/testFastTracker.C

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
#include <string>
2121

22-
void testFastTracker(std::string geometryFile = "a3geo.ini")
22+
void testFastTracker(const std::string& geometryFile = "a3geo.ini")
2323
{
2424

2525
fair::Logger::SetConsoleSeverity(fair::Severity::debug);

ALICE3/TableProducer/OTF/onTheFlyTracker.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ struct OnTheFlyTracker {
423423
std::get<std::shared_ptr<T>>(it->second)->Fill(std::forward<Args>(args)...);
424424
}
425425

426-
void insertHist(const std::string& name, const std::string& title, HistType type, std::vector<AxisSpec> axisSpecs)
426+
void insertHist(const std::string& name, const std::string& title, HistType type, const std::vector<AxisSpec>& axisSpecs)
427427
{
428428
histPointers[name] = histos.add(name.c_str(), title.c_str(), type, axisSpecs);
429429
}

ALICE3/TableProducer/OTF/onTheFlyTrackerPid.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ struct OnTheFlyTrackerPid {
304304
return (measuredToT - expectedToT) / resolution;
305305
}
306306

307-
float getToTMeanFromMomentumSlice(std::shared_ptr<TH2> hist, float momentum)
307+
float getToTMeanFromMomentumSlice(const std::shared_ptr<TH2>& hist, float momentum)
308308
{
309309
if (!hist)
310310
return -1.f;
@@ -319,7 +319,7 @@ struct OnTheFlyTrackerPid {
319319
return mean;
320320
}
321321

322-
float getToTResolutionFromMomentumSlice(std::shared_ptr<TH2> hist, float momentum)
322+
float getToTResolutionFromMomentumSlice(const std::shared_ptr<TH2>& hist, float momentum)
323323
{
324324
if (!hist)
325325
return -1.f;

ALICE3/TableProducer/alice3TrackingTranslator.cxx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
#include <iostream>
5555
#include <map>
5656
#include <string>
57+
#include <utility>
5758
#include <vector>
5859

5960
TString inputPath;
@@ -113,7 +114,7 @@ struct Alice3TrackingTranslator {
113114
}
114115

115116
struct FileStruct {
116-
FileStruct(std::string filename, std::string treename) : mFile(filename.c_str(), "READ")
117+
FileStruct(const std::string& filename, const std::string& treename) : mFile(filename.c_str(), "READ")
117118
{
118119
if (mFile.IsZombie()) {
119120
LOG(fatal) << "Could not open file '" << filename << "'";
@@ -137,7 +138,7 @@ struct Alice3TrackingTranslator {
137138
};
138139

139140
struct ParticleStruct : public FileStruct {
140-
ParticleStruct(std::string filename, std::string treename) : FileStruct(filename, treename)
141+
ParticleStruct(const std::string& filename, const std::string& treename) : FileStruct(std::move(filename), std::move(treename))
141142
{
142143
// mTree->Print();
143144
SETADDRESS("particle_type", m_particle_type);
@@ -180,7 +181,7 @@ struct Alice3TrackingTranslator {
180181
};
181182

182183
struct VertexStruct : public FileStruct {
183-
VertexStruct(std::string filename, std::string treename) : FileStruct(filename, treename)
184+
VertexStruct(const std::string& filename, const std::string& treename) : FileStruct(filename, treename)
184185
{
185186
SETADDRESS("vx", m_x);
186187
SETADDRESS("vy", m_y);
@@ -214,7 +215,7 @@ struct Alice3TrackingTranslator {
214215
};
215216

216217
struct TrackStruct : public FileStruct {
217-
TrackStruct(std::string filename, std::string treename) : FileStruct(filename, treename)
218+
TrackStruct(const std::string& filename, const std::string& treename) : FileStruct(std::move(filename), std::move(treename))
218219
{
219220
mTree->Print();
220221
// Set branch addresses for ACTS track parameters
@@ -288,7 +289,7 @@ struct Alice3TrackingTranslator {
288289
};
289290

290291
struct HitsStruct : public FileStruct {
291-
HitsStruct(std::string filename, std::string treename) : FileStruct(filename, treename)
292+
HitsStruct(const std::string& filename, const std::string& treename) : FileStruct(std::move(filename), std::move(treename))
292293
{
293294
mTree->Print();
294295
SETADDRESS("barcode", barcode);

0 commit comments

Comments
 (0)