Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MFT] Move static arrays to be initialized before the processing starts #10665

Merged
merged 5 commits into from
Feb 6, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ namespace mft
{

using namespace constants::mft;
using BinContainer = std::array<std::array<std::array<std::vector<Int_t>, constants::index_table::MaxRPhiBins>, (constants::mft::LayersNumber - 1)>, (constants::mft::LayersNumber - 1)>;

class TrackerConfig
{
Expand All @@ -39,12 +40,14 @@ class TrackerConfig
const Int_t getPhiBinIndex(const Float_t phi) const;
const Int_t getBinIndex(const Int_t rIndex, const Int_t phiIndex) const;

// tracking configuration parameters
const auto& getBinsS() { return mBinsS; }
const auto& getBins() { return mBins; }
static void initBins(const BinContainer* mBinContainer);
static void initBinContainers();

const std::pair<Int_t, Int_t>& getClusterBinIndexRange(Int_t layerId, Int_t bin) const { return mClusterBinIndexRange[layerId][bin]; }

static std::unique_ptr<BinContainer> mBins;
static std::unique_ptr<BinContainer> mBinsS;
robincaron13 marked this conversation as resolved.
Show resolved Hide resolved

protected:
// tracking configuration parameters
Int_t mMinTrackPointsLTF;
Expand All @@ -67,25 +70,25 @@ class TrackerConfig
bool mFullClusterScan = false;
Float_t mTrueTrackMCThreshold; // Minimum fraction of correct MC labels to tag True tracks

static std::mutex sTCMutex;

static Float_t mPhiBinSize;
static Float_t mInversePhiBinSize;
static std::array<Float_t, constants::mft::LayersNumber> mInverseRBinSize;
robincaron13 marked this conversation as resolved.
Show resolved Hide resolved
static std::array<Int_t, constants::mft::LayersNumber> mPhiBinWin;
static std::array<Float_t, constants::mft::LayersNumber> mRBinSize;
static std::array<Float_t, constants::mft::LayersNumber> mInverseRBinSize;
static std::array<std::array<std::array<std::vector<Int_t>, constants::index_table::MaxRPhiBins>, (constants::mft::LayersNumber - 1)>, (constants::mft::LayersNumber - 1)> mBins;
static std::array<std::array<std::array<std::vector<Int_t>, constants::index_table::MaxRPhiBins>, (constants::mft::LayersNumber - 1)>, (constants::mft::LayersNumber - 1)> mBinsS;
std::array<std::array<std::pair<Int_t, Int_t>, constants::index_table::MaxRPhiBins>, constants::mft::LayersNumber> mClusterBinIndexRange;

ClassDefNV(TrackerConfig, 3);
};

inline Float_t TrackerConfig::mPhiBinSize;
inline Float_t TrackerConfig::mInversePhiBinSize;
inline std::array<Float_t, constants::mft::LayersNumber> TrackerConfig::mInverseRBinSize;
inline std::array<Int_t, constants::mft::LayersNumber> TrackerConfig::mPhiBinWin;
inline std::array<Float_t, constants::mft::LayersNumber> TrackerConfig::mRBinSize;
inline std::array<Float_t, constants::mft::LayersNumber> TrackerConfig::mInverseRBinSize;
inline std::array<std::array<std::array<std::vector<Int_t>, constants::index_table::MaxRPhiBins>, (constants::mft::LayersNumber - 1)>, (constants::mft::LayersNumber - 1)> TrackerConfig::mBins;
inline std::array<std::array<std::array<std::vector<Int_t>, constants::index_table::MaxRPhiBins>, (constants::mft::LayersNumber - 1)>, (constants::mft::LayersNumber - 1)> TrackerConfig::mBinsS;
inline std::unique_ptr<BinContainer> TrackerConfig::mBins;
inline std::unique_ptr<BinContainer> TrackerConfig::mBinsS;

inline const Int_t TrackerConfig::getRBinIndex(const Float_t r, const Int_t layer) const
{
Expand Down
16 changes: 10 additions & 6 deletions Detectors/ITSMFT/MFT/tracking/src/Tracker.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ namespace o2
namespace mft
{

std::mutex o2::mft::TrackerConfig::sTCMutex;

//_________________________________________________________________________________________________
template <typename T>
Tracker<T>::Tracker(bool useMC) : mUseMC{useMC}
Expand Down Expand Up @@ -113,6 +115,8 @@ void Tracker<T>::initializeFinder()
return;
}

std::lock_guard<std::mutex> guard(o2::mft::TrackerConfig::sTCMutex);
robincaron13 marked this conversation as resolved.
Show resolved Hide resolved

/// calculate Look-Up-Table of the R-Phi bins projection from one layer to another
/// layer1 + global R-Phi bin index ---> layer2 + R bin index + Phi bin index
/// To be executed by the first tracker in case of multiple threads
Expand Down Expand Up @@ -195,7 +199,7 @@ void Tracker<T>::initializeFinder()
}

binIndex2S = getBinIndex(binR, binPhiS);
mBinsS[layer1][layer2 - 1][binIndex1].emplace_back(binIndex2S);
mBinsS.get()[0][layer1][layer2 - 1][binIndex1].emplace_back(binIndex2S);
robincaron13 marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand All @@ -211,7 +215,7 @@ void Tracker<T>::initializeFinder()
}

binIndex2 = getBinIndex(binR, binPhi);
mBins[layer1][layer2 - 1][binIndex1].emplace_back(binIndex2);
mBins.get()[0][layer1][layer2 - 1][binIndex1].emplace_back(binIndex2);
robincaron13 marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down Expand Up @@ -288,7 +292,7 @@ void Tracker<T>::findTracksLTF(ROframe<T>& event)
clsInLayer1 = it1 - event.getClustersInLayer(layer1).begin();

// loop over the bins in the search window
for (const auto& binS : getBinsS()[layer1][layer2 - 1][cluster1.indexTableBin]) {
for (const auto& binS : mBinsS.get()[0][layer1][layer2 - 1][cluster1.indexTableBin]) {
robincaron13 marked this conversation as resolved.
Show resolved Hide resolved

getBinClusterRange(event, layer2, binS, clsMinIndexS, clsMaxIndexS);

Expand Down Expand Up @@ -318,7 +322,7 @@ void Tracker<T>::findTracksLTF(ROframe<T>& event)

// loop over the bins in the search window
dR2min = mLTFConeRadius ? dR2cut * dRCone * dRCone : dR2cut;
for (const auto& bin : getBins()[layer1][layer - 1][cluster1.indexTableBin]) {
for (const auto& bin : mBins.get()[0][layer1][layer - 1][cluster1.indexTableBin]) {

getBinClusterRange(event, layer, bin, clsMinIndex, clsMaxIndex);

Expand Down Expand Up @@ -567,7 +571,7 @@ void Tracker<T>::findTracksCA(ROframe<T>& event)
clsInLayer1 = it1 - event.getClustersInLayer(layer1).begin();

// loop over the bins in the search window
for (const auto& binS : getBinsS()[layer1][layer2 - 1][cluster1.indexTableBin]) {
for (const auto& binS : mBinsS.get()[0][layer1][layer2 - 1][cluster1.indexTableBin]) {

getBinClusterRange(event, layer2, binS, clsMinIndexS, clsMaxIndexS);

Expand All @@ -593,7 +597,7 @@ void Tracker<T>::findTracksCA(ROframe<T>& event)
dR2min = mLTFConeRadius ? dR2cut * dRCone * dRCone : dR2cut;

// loop over the bins in the search window
for (const auto& bin : getBins()[layer1][layer - 1][cluster1.indexTableBin]) {
for (const auto& bin : mBins.get()[0][layer1][layer - 1][cluster1.indexTableBin]) {

getBinClusterRange(event, layer, bin, clsMinIndex, clsMaxIndex);

Expand Down
27 changes: 26 additions & 1 deletion Detectors/ITSMFT/MFT/tracking/src/TrackerConfig.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,29 @@ void o2::mft::TrackerConfig::initialize(const MFTTrackingParam& trkParam)
mTrueTrackMCThreshold = trkParam.TrueTrackMCThreshold;

assert(mRPhiBins < constants::index_table::MaxRPhiBins && "Track finder binning overflow");
}
}

//__________________________________________________________________________
void o2::mft::TrackerConfig::initBins(const BinContainer* mBinContainer)
{
// if it's a non-static method: mutex could be used here
// also to protect a BinContainer shared between multiple threads

// TODO: do nothing at this moment
// init the BinContainer
// the function initializeFinnder in tracker.cxx is doing this job
}

robincaron13 marked this conversation as resolved.
Show resolved Hide resolved
//__________________________________________________________________________
void o2::mft::TrackerConfig::initBinContainers()
{
if (!mBins) {
mBins = std::make_unique<BinContainer>();
// init bins with static method. If not possible to do using static method, then make this method non-static and lock the code by mutex.
initBins(mBins.get());
}
if (!mBinsS) {
mBinsS = std::make_unique<BinContainer>();
initBins(mBinsS.get());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class TrackerDPL : public o2::framework::Task

public:
TrackerDPL(std::shared_ptr<o2::base::GRPGeomRequest> gr, bool useMC, int nThreads = 1) : mGGCCDBRequest(gr), mUseMC(useMC), mNThreads(nThreads) {}
~TrackerDPL() override = default;
~TrackerDPL() override;
void init(framework::InitContext& ic) final;
void run(framework::ProcessingContext& pc) final;
void endOfStream(framework::EndOfStreamContext& ec) final;
Expand Down
11 changes: 11 additions & 0 deletions Detectors/ITSMFT/MFT/workflow/src/TrackerSpec.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "MFTTracking/Tracker.h"
#include "MFTTracking/TrackCA.h"
#include "MFTBase/GeometryTGeo.h"
#include "MFTTracking/TrackerConfig.h"

#include <vector>
#include <future>
Expand Down Expand Up @@ -55,6 +56,8 @@ void TrackerDPL::init(InitContext& ic)

// tracking configuration parameters
auto& trackingParam = MFTTrackingParam::Instance(); // to avoid loading interpreter during the run

TrackerConfig::initBinContainers();
robincaron13 marked this conversation as resolved.
Show resolved Hide resolved
}

void TrackerDPL::run(ProcessingContext& pc)
Expand Down Expand Up @@ -427,5 +430,13 @@ DataProcessorSpec getTrackerSpec(bool useMC, int nThreads)
Options{}};
}

///_______________________________________
TrackerDPL::~TrackerDPL()
{
// Deallocate the memory that was previously reserved for these arrays.
robincaron13 marked this conversation as resolved.
Show resolved Hide resolved
TrackerConfig::mBins.reset();
TrackerConfig::mBinsS.reset();
}

} // namespace mft
} // namespace o2