From 89eba8f73d6fe0a83979f6ab6fb74057ce4fe158 Mon Sep 17 00:00:00 2001 From: "s.zharko@gsi.de" <s.zharko@gsi.de> Date: Thu, 21 Jul 2022 21:00:19 +0200 Subject: [PATCH] L1: L1Algo: enumeration of portion sizes replaced with constant expressions in L1Constants --- reco/L1/L1Algo/L1Algo.cxx | 28 ++++++++--------- reco/L1/L1Algo/L1Algo.h | 50 +++++++++--------------------- reco/L1/L1Algo/L1CATrackFinder.cxx | 50 ++++++++++++++++-------------- reco/L1/L1Algo/L1ConfigRW.cxx | 2 +- reco/L1/L1Algo/L1ConfigRW.h | 2 -- reco/L1/L1Algo/L1Constants.h | 44 +++++++++++++++----------- reco/L1/L1Algo/L1InitManager.h | 21 +++++++++---- reco/L1/L1Algo/L1Parameters.cxx | 11 +++---- reco/L1/L1Algo/L1Parameters.h | 28 ++++++++--------- 9 files changed, 114 insertions(+), 122 deletions(-) diff --git a/reco/L1/L1Algo/L1Algo.cxx b/reco/L1/L1Algo/L1Algo.cxx index ab40e8f3e4..5a27570b36 100644 --- a/reco/L1/L1Algo/L1Algo.cxx +++ b/reco/L1/L1Algo/L1Algo.cxx @@ -34,25 +34,25 @@ void L1Algo::SetNThreads(unsigned int n) fTrackCandidates[i].SetName(std::stringstream() << "L1Algo::fTrackCandidates[" << i << "]"); - fT_3[i].reserve(MaxPortionTriplets / fvecLen); + fT_3[i].reserve(L1Constants::size::kMaxPortionTripletsP); fhitsl_3[i].SetName(std::stringstream() << "L1Algo::fhitsl_3[" << i << "]"); fhitsm_3[i].SetName(std::stringstream() << "L1Algo::fhitsm_3[" << i << "]"); fhitsr_3[i].SetName(std::stringstream() << "L1Algo::fhitsr_3[" << i << "]"); - fhitsl_3[i].reserve(MaxPortionTriplets); - fhitsm_3[i].reserve(MaxPortionTriplets); - fhitsr_3[i].reserve(MaxPortionTriplets); - - fu_front3[i].reserve(MaxPortionTriplets / fvecLen); - fu_back3[i].reserve(MaxPortionTriplets / fvecLen); - fz_pos3[i].reserve(MaxPortionTriplets / fvecLen); - fTimeR[i].reserve(MaxPortionTriplets / fvecLen); - fTimeER[i].reserve(MaxPortionTriplets / fvecLen); - dx[i].reserve(MaxPortionTriplets / fvecLen); - dy[i].reserve(MaxPortionTriplets / fvecLen); - du[i].reserve(MaxPortionTriplets / fvecLen); - dv[i].reserve(MaxPortionTriplets / fvecLen); + fhitsl_3[i].reserve(L1Constants::size::kMaxPortionTriplets); + fhitsm_3[i].reserve(L1Constants::size::kMaxPortionTriplets); + fhitsr_3[i].reserve(L1Constants::size::kMaxPortionTriplets); + + fu_front3[i].reserve(L1Constants::size::kMaxPortionTripletsP); + fu_back3[i].reserve(L1Constants::size::kMaxPortionTripletsP); + fz_pos3[i].reserve(L1Constants::size::kMaxPortionTripletsP); + fTimeR[i].reserve(L1Constants::size::kMaxPortionTripletsP); + fTimeER[i].reserve(L1Constants::size::kMaxPortionTripletsP); + dx[i].reserve(L1Constants::size::kMaxPortionTripletsP); + dy[i].reserve(L1Constants::size::kMaxPortionTripletsP); + du[i].reserve(L1Constants::size::kMaxPortionTripletsP); + dv[i].reserve(L1Constants::size::kMaxPortionTripletsP); for (unsigned int j = 0; j < L1Constants::size::kMaxNstations; j++) { fTriplets[j][i].SetName(std::stringstream() << "L1Algo::fTriplets[" << i << "][" << j << "]"); diff --git a/reco/L1/L1Algo/L1Algo.h b/reco/L1/L1Algo/L1Algo.h index 60c760139c..ebb8d3bc47 100644 --- a/reco/L1/L1Algo/L1Algo.h +++ b/reco/L1/L1Algo/L1Algo.h @@ -259,20 +259,20 @@ public: int GetMcTrackIdForUnusedHit(int iHit); public: - int fNstrips {0}; ///> number of strips - L1Vector<L1Hit>* vHits {nullptr}; ///> hits as a combination of front-, backstrips and z-position - L1Grid vGrid[L1Constants::size::kMaxNstations]; ///> hits as a combination of front-, backstrips and z-position - L1Grid vGridTime[L1Constants::size::kMaxNstations]; ///> + int fNstrips {0}; ///< number of strips + L1Vector<L1Hit>* vHits {nullptr}; ///< hits as a combination of front and back strips and z-position + L1Grid vGrid[L1Constants::size::kMaxNstations]; ///< hits as a combination of front and back strips and z-position + L1Grid vGridTime[L1Constants::size::kMaxNstations]; ///< L1Vector<unsigned char>* fStripFlag {nullptr}; // information of hits station & using hits in tracks; double fCATime {0.}; // time of track finding - L1Vector<L1Track> fTracks {"L1Algo::fTracks"}; // reconstructed tracks - L1Vector<L1HitIndex_t> fRecoHits {"L1Algo::fRecoHits"}; // packed hits of reconstructed tracks + L1Vector<L1Track> fTracks {"L1Algo::fTracks"}; ///< reconstructed tracks + L1Vector<L1HitIndex_t> fRecoHits {"L1Algo::fRecoHits"}; ///< packed hits of reconstructed tracks - const L1HitIndex_t* HitsStartIndex {nullptr}; // station-bounders in vHits array - const L1HitIndex_t* HitsStopIndex {nullptr}; // station-bounders in vHits array + const L1HitIndex_t* HitsStartIndex {nullptr}; ///< station-bounders in vHits array + const L1HitIndex_t* HitsStopIndex {nullptr}; ///< station-bounders in vHits array // L1Branch* pointer; @@ -305,36 +305,15 @@ public: fvec EventTime[L1Constants::size::kMaxNthreads][L1Constants::size::kMaxNthreads] {{0}}; fvec Err[L1Constants::size::kMaxNthreads][L1Constants::size::kMaxNthreads] {{0}}; - - /// standard sizes of the arrays - enum - { - multiCoeff = 1, // central - 1, mbias - - - coeff = 64 / 4, - - Portion = 1024 / coeff, // portion of left hits - - MaxPortionDoublets = 10000 / 5 * 64 / 2 / coeff /*/ multiCoeff*/ * 1, - MaxPortionTriplets = 10000 * 5 * 64 / 2 / coeff /*/ multiCoeff*/ * 1, - MaxNPortion = 40 * coeff / multiCoeff, - - - MaxArrSize = MaxNPortion * MaxPortionDoublets / L1Constants::size::kMaxNstations - //200000, // standart size of big arrays // mas be 40000 for normal work in cbmroot! - }; - - /// --- data used during finding iterations int isec {0}; // iteration TODO: to be dispatched (S.Zharko, 21.06.2022) - const L1CAIteration* fpCurrentIteration {nullptr}; ///< pointer to the current CA track finder iteration + const L1CAIteration* fpCurrentIteration = nullptr; ///< pointer to the current CA track finder iteration - L1Vector<L1Hit>* vHitsUnused {nullptr}; - L1Vector<L1HitIndex_t>* RealIHitP {nullptr}; - L1Vector<L1HitIndex_t>* RealIHitPBuf {nullptr}; - L1Vector<L1HitPoint>* vHitPointsUnused {nullptr}; - L1HitIndex_t* RealIHit {nullptr}; // index in vHits indexed by index in vHitsUnused + L1Vector<L1Hit>* vHitsUnused = nullptr; + L1Vector<L1HitIndex_t>* RealIHitP = nullptr; + L1Vector<L1HitIndex_t>* RealIHitPBuf = nullptr; + L1Vector<L1HitPoint>* vHitPointsUnused = nullptr; + L1HitIndex_t* RealIHit = nullptr; // index in vHits indexed by index in vHitsUnused L1HitIndex_t HitsUnusedStartIndex[L1Constants::size::kMaxNstations + 1] {0}; L1HitIndex_t HitsUnusedStopIndex[L1Constants::size::kMaxNstations + 1] {0}; @@ -467,7 +446,6 @@ private: /// void CAMergeClones(); - inline __attribute__((always_inline)) void PackLocation(unsigned int& location, unsigned int& triplet, unsigned int iStation, unsigned int& thread) { diff --git a/reco/L1/L1Algo/L1CATrackFinder.cxx b/reco/L1/L1Algo/L1CATrackFinder.cxx index efe9cc2cba..1f34006ce5 100644 --- a/reco/L1/L1Algo/L1CATrackFinder.cxx +++ b/reco/L1/L1Algo/L1CATrackFinder.cxx @@ -1479,18 +1479,20 @@ inline void L1Algo::DupletsStaPort( L1HitPoint* vHits_l = &((*vHitPointsUnused)[0]) + HitsUnusedStartIndex[istal]; L1HitPoint* vHits_m = &((*vHitPointsUnused)[0]) + HitsUnusedStartIndex[istam]; - fvec u_front[Portion / fvecLen], u_back[Portion / fvecLen]; - fvec dv0[Portion / fvecLen], du0[Portion / fvecLen]; - fvec zPos[Portion / fvecLen]; - fvec HitTime[Portion / fvecLen]; - fvec HitTimeEr[Portion / fvecLen]; - fvec Event[Portion / fvecLen]; + fvec u_front[L1Constants::size::kPortionLeftHitsP]; + fvec u_back[L1Constants::size::kPortionLeftHitsP]; + fvec dv0[L1Constants::size::kPortionLeftHitsP]; + fvec du0[L1Constants::size::kPortionLeftHitsP]; + fvec zPos[L1Constants::size::kPortionLeftHitsP]; + fvec HitTime[L1Constants::size::kPortionLeftHitsP]; + fvec HitTimeEr[L1Constants::size::kPortionLeftHitsP]; + fvec Event[L1Constants::size::kPortionLeftHitsP]; /// prepare the portion of left hits data Tindex& n1 = n_g[ip]; findSingletsStep0( // input - (ip - portionStopIndex_[istal + 1]) * Portion, n1, vHits_l, + (ip - portionStopIndex_[istal + 1]) * L1Constants::size::kPortionLeftHits, n1, vHits_l, // output u_front, u_back, zPos, hitsl_1, HitTime, HitTimeEr, Event, du0, dv0); @@ -1720,6 +1722,7 @@ inline void L1Algo::TripletsStaPort( /// creates triplets: void L1Algo::CATrackFinder() { + #ifdef _OPENMP omp_set_num_threads(fNThreads); #endif @@ -2019,10 +2022,10 @@ void L1Algo::CATrackFinder() fDupletPortionSize.clear(); for (int istal = fNstations - 2; istal >= fFirstCAstation; istal--) { //start downstream chambers int NHits_l = HitsUnusedStopIndex[istal] - HitsUnusedStartIndex[istal]; - int nPortions = NHits_l / Portion; - int rest = NHits_l - nPortions * Portion; + int nPortions = NHits_l / L1Constants::size::kPortionLeftHits; + int rest = NHits_l - nPortions * L1Constants::size::kPortionLeftHits; for (int ipp = 0; ipp < nPortions; ipp++) { - fDupletPortionSize.push_back(Portion); + fDupletPortionSize.push_back(L1Constants::size::kPortionLeftHits); } // start_lh - portion of left hits if (rest > 0) fDupletPortionSize.push_back(rest); fDupletPortionStopIndex[istal] = fDupletPortionSize.size(); @@ -2042,17 +2045,17 @@ void L1Algo::CATrackFinder() for (int istal = fNstations-2; istal >= fFirstCAstation; istal--) //start downstream chambers { int nHits = HitsUnusedStopIndex[istal] - HitsUnusedStartIndex[istal]; - - int NHits_P = nHits/Portion; - + + int NHits_P = nHits/L1Constants::size::kPortionLeftHits; + for( int ipp = 0; ipp < NHits_P; ipp++ ) { - n_g1[ip] = Portion; + n_g1[ip] = L1Constants::size::kPortionLeftHits; ip++; } // start_lh - portion of left hits - - n_g1[ip] = nHits - NHits_P*Portion; - + + n_g1[ip] = nHits - NHits_P * L1Constants::size::kPortionLeftHits; + ip++; fDupletPortionStopIndex[istal] = ip; }// lstations @@ -2067,13 +2070,12 @@ void L1Algo::CATrackFinder() #endif - const Tindex vPortion = Portion / fvecLen; - L1TrackPar T_1[vPortion]; - L1FieldRegion fld_1[vPortion]; - L1HitIndex_t hitsl_1[Portion]; - L1TrackPar TG_1[vPortion]; - L1FieldRegion fldG_1[vPortion]; - L1HitIndex_t hitslG_1[Portion]; + L1TrackPar T_1[L1Constants::size::kPortionLeftHitsP]; + L1FieldRegion fld_1[L1Constants::size::kPortionLeftHitsP]; + L1HitIndex_t hitsl_1[L1Constants::size::kPortionLeftHits]; + L1TrackPar TG_1[L1Constants::size::kPortionLeftHitsP]; + L1FieldRegion fldG_1[L1Constants::size::kPortionLeftHitsP]; + L1HitIndex_t hitslG_1[L1Constants::size::kPortionLeftHits]; /// middle hits indexed by number of doublets in portion(i2) L1Vector<L1HitIndex_t> hitsm_2("L1CATrackFinder::hitsm_2"); diff --git a/reco/L1/L1Algo/L1ConfigRW.cxx b/reco/L1/L1Algo/L1ConfigRW.cxx index 7b89b925eb..6f3c55da21 100644 --- a/reco/L1/L1Algo/L1ConfigRW.cxx +++ b/reco/L1/L1Algo/L1ConfigRW.cxx @@ -36,7 +36,7 @@ std::vector<std::string> L1ConfigRW::GetNodeKeys(const YAML::Node& node) const } } catch (const YAML::InvalidNode& exc) { // It is impossible to - LOG(warn) << "L1 config: attempt to call L1ConfigRW::GetNodeKeys for node, which keys could not be represented " + LOG(warn) << "L1 config: attempt to call L1ConfigRW::GetNodeKeys for node, keys of which could not be represented " << "with strings. An empty vector will be returned"; std::vector<std::string>().swap(res); } diff --git a/reco/L1/L1Algo/L1ConfigRW.h b/reco/L1/L1Algo/L1ConfigRW.h index ce83641362..accde1d92c 100644 --- a/reco/L1/L1Algo/L1ConfigRW.h +++ b/reco/L1/L1Algo/L1ConfigRW.h @@ -43,8 +43,6 @@ private: void ReadCAIterations(const YAML::Node& node); /// Gets parameters content of the node - /// FIXME: We assume, that all of the keys of node can be represented with strings. This assumption is not always true, so - /// one should be sure about the assumption when using this function. /// \param node YAML node /// \return Vector of key names std::vector<std::string> GetNodeKeys(const YAML::Node& node) const; diff --git a/reco/L1/L1Algo/L1Constants.h b/reco/L1/L1Algo/L1Constants.h index 0e6bca4b4b..22ef92fc24 100644 --- a/reco/L1/L1Algo/L1Constants.h +++ b/reco/L1/L1Algo/L1Constants.h @@ -13,6 +13,7 @@ #define L1Constants_h 1 #include "L1NaN.h" +#include "vectors/P4_F32vec4.h" // for fvecLen /// Namespace contains compile-time constants definition for the L1 tracking algorithm namespace L1Constants @@ -28,15 +29,23 @@ namespace L1Constants constexpr int kMaxFieldApproxPolynomialOrder {5}; /// Amount of bits to code a station, thread or triplet. This values determine the ma - constexpr unsigned int kStationBits {6u}; ///< Amount of bits to code one station - constexpr unsigned int kThreadBits {6u}; ///< Amount of bits to code one thread - constexpr unsigned int kTripletBits {32u - kStationBits - kThreadBits}; ///< Amount of bits to code one triplet - - constexpr int kMaxNdetectors {5}; ///< Max number of tracking detectors - constexpr int kMaxNstations {1u << kStationBits}; ///< Max number of stations, 2^6 = 64 - constexpr int kMaxNthreads {1u << kThreadBits}; ///< Max number of threads, 2^6 = 64 - constexpr int kMaxNtriplets {1u << kTripletBits}; ///< Max number of triplets, 2^20 = 1,048,576 - } // end namespace size + constexpr unsigned int kStationBits = 6u; ///< Amount of bits to code one station + constexpr unsigned int kThreadBits = 6u; ///< Amount of bits to code one thread + constexpr unsigned int kTripletBits = 32u - kStationBits - kThreadBits; ///< Amount of bits to code one triplet + + constexpr int kMaxNdetectors = 5; ///< Max number of tracking detectors + constexpr int kMaxNstations = 1u << kStationBits; ///< Max number of stations, 2^6 = 64 + constexpr int kMaxNthreads = 1u << kThreadBits; ///< Max number of threads, 2^6 = 64 + constexpr int kMaxNtriplets = 1u << kTripletBits; ///< Max number of triplets, 2^20 = 1,048,576 + + // TODO: Clarify the meaning of these coefficients + constexpr int kCoeff = 64 / 4; ///< TODO: + constexpr int kPortionLeftHits = 1024 / kCoeff; ///< portion of left hits + constexpr int kPortionLeftHitsP = 1024 / kCoeff / fvecLen; ///< portion of left hits per one vector word + constexpr int kMaxPortionDoublets = 10000 / 5 * 64 / 2 / kCoeff; ///< Max size of the doublets portion + constexpr int kMaxPortionTriplets = 10000 * 5 * 64 / 2 / kCoeff; ///< Max size of the triplets portion + constexpr int kMaxPortionTripletsP = kMaxPortionTriplets / fvecLen; ///< Max size of the triplets portion + } // namespace size /// Control flags namespace control @@ -64,26 +73,25 @@ namespace L1Constants namespace phys { /* Particle masses used for track fit */ - constexpr float kMuonMass {0.10565800f}; ///< Muon mass [GeV/c2] - constexpr float kElectronMass {0.000511f}; ///< Electron mass [GeV/c2] - } // namespace phys + constexpr float kMuonMass = 0.10565800f; ///< Muon mass [GeV/c2] + constexpr float kElectronMass = 0.000511f; ///< Electron mass [GeV/c2] + } // namespace phys /// Miscellaneous constants namespace misc { constexpr int kAssertionLevel {0}; ///< Assertion level constexpr int kAlignment {16}; - } // end namespace misc + } // namespace misc /// NoInit constants (aliases) namespace noin { - constexpr float kF {L1NaN::SetNaN<float>()}; - constexpr double kD {L1NaN::SetNaN<double>()}; - constexpr int k32I {L1NaN::SetNaN<int>()}; - constexpr unsigned int k32U {L1NaN::SetNaN<unsigned int>()}; + constexpr float kF = L1NaN::SetNaN<float>(); + constexpr double kD = L1NaN::SetNaN<double>(); + constexpr int k32I = L1NaN::SetNaN<int>(); + constexpr unsigned int k32U = L1NaN::SetNaN<unsigned int>(); } // namespace noin - } // end namespace L1Constants diff --git a/reco/L1/L1Algo/L1InitManager.h b/reco/L1/L1Algo/L1InitManager.h index c77951f947..3564b83647 100644 --- a/reco/L1/L1Algo/L1InitManager.h +++ b/reco/L1/L1Algo/L1InitManager.h @@ -74,8 +74,8 @@ class L1InitManager { private: enum class EInitKey { - // NOTE: Please, keep the numbers of enum items in the existing order: it helps to debug the initialization with - // this->GetObjectInitController().ToString() method call (S.Zharko) + // NOTE: Please, keep the numbers of the enumeration items in the existing order: it helps to debug the + // initialization with this->GetObjectInitController().ToString() method call (S.Zharko) kActiveDetectorIDs, ///< 0) If the detector sequence is set kStationsNumberCrosscheck, ///< 1) If the crosscheck station numbers were setup kFieldFunction, ///< 2) If magnetic field getter function is set @@ -87,7 +87,7 @@ private: kTrackingLevel, ///< 8) kGhostSuppression, ///< 9) kMomentumCutOff, ///< 10) - kEnd ///< 11) [technical] number of entries in the enum + kEnd ///< 11) [technical] number of entries in the enumeration }; using L1DetectorIDIntMap_t = std::unordered_map<L1DetectorID, int, L1Utils::EnumClassHash>; @@ -232,9 +232,9 @@ public: /// \param destination Reference to the destination of the L1 object void TransferParametersContainer(L1Parameters& destination); - /// *************************** - /// ** Flags for development ** - /// *************************** + // *************************** + // ** Flags for development ** + // *************************** /// Ignore hit search areas void DevSetIgnoreHitSearchAreas(bool value = true) { fParameters.fDevIsIgnoreHitSearchAreas = value; } @@ -249,6 +249,10 @@ public: void DevSetIsMatchTripletsViaMc(bool value = true) { fParameters.fDevIsMatchTripletsViaMc = value; } private: + // ********************* + // ** Private methods ** + // ********************* + /// Checker for L1CAIteration container initialization (sets EInitKey::kCAIterations) /// \return true If all L1CAIteration objects were initialized properly void CheckCAIterationsInit(); @@ -260,6 +264,11 @@ private: /// Forms parameters container void FormParametersContainer(); + + // ***************** + // ** Data fields ** + // ***************** + // * Basic fields * InitController_t fInitController {}; ///< Initialization flags diff --git a/reco/L1/L1Algo/L1Parameters.cxx b/reco/L1/L1Algo/L1Parameters.cxx index 7036097f36..29bdaddc15 100644 --- a/reco/L1/L1Algo/L1Parameters.cxx +++ b/reco/L1/L1Algo/L1Parameters.cxx @@ -2,12 +2,11 @@ SPDX-License-Identifier: GPL-3.0-only Authors: Sergey Gorbunov, Sergei Zharko [committer] */ -/************************************************************************************************************ - * @file L1Parameters.cxx - * @brief Parameter container for the L1Algo library - * @since 10.02.2022 - * @author S.Zharko <s.zharko@gsi.de> - ***********************************************************************************************************/ +/// @file L1Parameters.cxx +/// @brief Parameter container for the L1Algo library +/// @since 10.02.2022 +/// @author S.Zharko <s.zharko@gsi.de> + #include "L1Parameters.h" #include <FairLogger.h> diff --git a/reco/L1/L1Algo/L1Parameters.h b/reco/L1/L1Algo/L1Parameters.h index 5b7e36d0ce..650cbc0829 100644 --- a/reco/L1/L1Algo/L1Parameters.h +++ b/reco/L1/L1Algo/L1Parameters.h @@ -2,12 +2,10 @@ SPDX-License-Identifier: GPL-3.0-only Authors: Sergey Gorbunov, Sergei Zharko [committer] */ -/************************************************************************************************************ - * @file L1Parameters.h - * @brief Parameter container for the L1Algo library - * @since 19.12.2021 - * @author S.Zharko <s.zharko@gsi.de> - ***********************************************************************************************************/ +/// @file L1Parameters.h +/// @brief Parameter container for the L1Algo library +/// @since 19.12.2021 +/// @author S.Zharko <s.zharko@gsi.de> #ifndef L1Parameters_h #define L1Parameters_h 1 @@ -164,9 +162,9 @@ public: /// Class invariant checker void CheckConsistency() const; - /// *************************** - /// ** Flags for development ** - /// *************************** + // *************************** + // ** Flags for development ** + // *************************** /// Are the hit search areas ignored bool DevIsIgnoreHitSearchAreas() const { return fDevIsIgnoreHitSearchAreas; } @@ -220,9 +218,9 @@ private: /// active index: 0 -1 1 2 -1 3 4 5 6 7 0 0 0 0 alignas(L1Constants::misc::kAlignment) std::array<int, L1Constants::size::kMaxNstations> fActiveStationGlobalIDs {}; - /// *************************** - /// ** Flags for development ** - /// *************************** + // *************************** + // ** Flags for development ** + // *************************** bool fDevIsIgnoreHitSearchAreas {false}; ///< Process all hits on the station ignoring hit search area @@ -232,9 +230,9 @@ private: bool fDevIsMatchTripletsViaMc {false}; ///< Flag to match triplets using Mc information - /******************************** - ** Friend classes declaration ** - ********************************/ + // ******************************** + // ** Friend classes declaration ** + // ******************************** friend class L1InitManager; }; -- GitLab