From 77e8d735fc0154272a094c87eb605abe016480bd Mon Sep 17 00:00:00 2001 From: "s.zharko@gsi.de" <s.zharko@gsi.de> Date: Sun, 12 Jan 2025 11:32:04 +0100 Subject: [PATCH] CbmEvent: - setting const qualifier to the GetIndex and the GetStsTrackIndex functions - re-implimenting the GetIndex function to make it const qualified and reduce the number of access calls --- core/data/CbmEvent.cxx | 15 ++++++++++----- core/data/CbmEvent.h | 11 +++++++++-- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/core/data/CbmEvent.cxx b/core/data/CbmEvent.cxx index 5339587459..96bfae7e78 100644 --- a/core/data/CbmEvent.cxx +++ b/core/data/CbmEvent.cxx @@ -39,12 +39,17 @@ void CbmEvent::ClearData(ECbmDataType type) { fIndexMap[type].clear(); } // ----- Get a data index ---------------------------------------------- -uint32_t CbmEvent::GetIndex(ECbmDataType type, uint32_t iData) +uint32_t CbmEvent::GetIndex(ECbmDataType type, uint32_t iData) const { - - if (fIndexMap.find(type) == fIndexMap.end()) return -1; - if (fIndexMap[type].size() <= iData) return -2; - return fIndexMap.at(type)[iData]; + auto it = fIndexMap.find(type); + if (it == fIndexMap.end()) { + return -1; + } + const auto& indices = it->second; + if (indices.size() <= iData) { + return -2; + } + return indices[iData]; } // ------------------------------------------------------------------------- diff --git a/core/data/CbmEvent.h b/core/data/CbmEvent.h index 8e790138fd..043732d738 100644 --- a/core/data/CbmEvent.h +++ b/core/data/CbmEvent.h @@ -89,7 +89,7 @@ public: ** @param iData Running number of data object in event ** @value Index of data object in its TClonesArray **/ - uint32_t GetIndex(ECbmDataType type, uint32_t iData); + uint32_t GetIndex(ECbmDataType type, uint32_t iData) const; /** Get match object @@ -125,7 +125,7 @@ public: ** @param iTrack Running number of STS track in the event ** @value index Index of STS track in TClonesArray **/ - int32_t GetStsTrackIndex(int32_t iTrack) { return GetIndex(ECbmDataType::kStsTrack, iTrack); } + int32_t GetStsTrackIndex(int32_t iTrack) const { return GetIndex(ECbmDataType::kStsTrack, iTrack); } /** Get event end time @@ -209,6 +209,13 @@ public: **/ CbmVertex* GetVertex() { return &fVertex; } + + /** Get event vertex (constant access) + ** @value Pointer to vertex object + **/ + const CbmVertex* GetVertex() const { return &fVertex; } + + /** Swap two events **/ void Swap(CbmEvent& e); -- GitLab