Skip to content

Commit 8583004

Browse files
wdconincpre-commit-ci[bot]veprblgithub-actions[bot]
authored
PolynomialMatrixReconstruction: Change xLGraph to thread_local unique_ptr (#2159)
### Briefly, what does this PR introduce? This PR avoids a data race when multiple threads are read/write interacting with their static xLGraph without locking. ### What kind of change does this PR introduce? - [x] Bug fix (issue: https://github.com/eic/EICrecon/actions/runs/18860302788/job/53820369528?pr=2153#step:7:886) - [ ] New feature (issue #__) - [ ] Documentation update - [ ] Other: __ ### Please check if this PR fulfills the following: - [ ] Tests for the changes have been added - [ ] Documentation has been added / updated - [x] Changes have been communicated to collaborators @ajentsch ### Does this PR introduce breaking changes? What changes might users need to make to their code? No. ### Does this PR change default behavior? No. --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Dmitry Kalinkin <[email protected]> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent 7f33b79 commit 8583004

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

src/algorithms/fardetectors/PolynomialMatrixReconstruction.cc

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,16 @@
1212
#include <Math/GenVector/Cartesian3D.h>
1313
#include <Math/GenVector/DisplacementVector3D.h>
1414
#include <TGraph2D.h>
15-
#include <TString.h>
1615
#include <edm4hep/Vector3d.h>
1716
#include <edm4hep/Vector3f.h>
1817
#include <edm4hep/utils/vector_utils.h>
1918
#include <fmt/core.h>
2019
#include <cmath>
20+
#include <filesystem>
2121
#include <gsl/pointers>
2222
#include <memory>
2323
#include <stdexcept>
2424
#include <vector>
25-
#include <filesystem>
2625

2726
#include "algorithms/fardetectors/PolynomialMatrixReconstructionConfig.h"
2827

@@ -141,17 +140,19 @@ void eicrecon::PolynomialMatrixReconstruction::process(
141140

142141
//xL table filled here from LUT -- Graph2D used for nice interpolation functionality and simple loading of LUT file
143142

144-
if (not std::filesystem::exists(
145-
Form("calibrations/RP_60_xL_100_beamEnergy_%.0f.xL.lut", nomMomentum))) {
146-
critical("Cannot find lookup xL table for {}", nomMomentum);
147-
throw std::runtime_error("Cannot find xL lookup table from calibrations -- cannot proceed");
143+
thread_local std::string filename(
144+
fmt::format("calibrations/RP_60_xL_100_beamEnergy_{:.0f}.xL.lut", nomMomentum));
145+
thread_local std::unique_ptr<TGraph2D> xLGraph{nullptr};
146+
if (xLGraph == nullptr) {
147+
if (std::filesystem::exists(filename)) {
148+
xLGraph = std::make_unique<TGraph2D>(filename.c_str(), "%lf %lf %lf");
149+
} else {
150+
critical("Cannot find lookup xL table for {}", nomMomentum);
151+
throw std::runtime_error("Cannot find xL lookup table from calibrations -- cannot proceed");
152+
}
148153
}
149154

150-
static std::unique_ptr<TGraph2D> xLGraph{new TGraph2D(
151-
Form("calibrations/RP_60_xL_100_beamEnergy_%.0f.xL.lut", nomMomentum), "%lf %lf %lf")};
152-
153-
trace("filename for lookup --> {}",
154-
Form("calibrations/RP_60_xL_100_beamEnergy_%.0f.xL.lut", nomMomentum));
155+
trace("filename for lookup --> {}", filename);
155156

156157
//important to ensure interoplation works correctly -- do not remove -- not available until ROOT v6.36, will need to add back in later
157158
//xLGraph->RemoveDuplicates();

0 commit comments

Comments
 (0)