diff --git a/algo/ca/core/tracking/CaTrackFinder.cxx b/algo/ca/core/tracking/CaTrackFinder.cxx index 1ab8b5399a914306d15fb16bee86e726baef53a8..df883016cedf441f30ef633dbb2e8dece609adfa 100644 --- a/algo/ca/core/tracking/CaTrackFinder.cxx +++ b/algo/ca/core/tracking/CaTrackFinder.cxx @@ -250,7 +250,7 @@ void TrackFinder::FindTracks() // Add thread monitors to the main monitor for (auto& monitor : frAlgo.fvMonitorDataThread) { - frAlgo.fMonitorData.AddMonitorData(monitor); + frAlgo.fMonitorData.AddMonitorData(monitor, true); monitor.Reset(); } diff --git a/algo/ca/core/tracking/CaTrackFinderWindow.cxx b/algo/ca/core/tracking/CaTrackFinderWindow.cxx index 1d3f744ba25265630d3f72463eb44b2fe2a49722..3ad43cadb0ddfe6cf062840c893d89349c66b879 100644 --- a/algo/ca/core/tracking/CaTrackFinderWindow.cxx +++ b/algo/ca/core/tracking/CaTrackFinderWindow.cxx @@ -776,7 +776,7 @@ void TrackFinderWindow::CAFindTrack(int ista, ca::Branch& best_tr, const ca::Tri fscal new_chi2 = curr_tr.Chi2() + dchi2; - if (0) { //SGtrd2d debug!! + if constexpr (0) { //SGtrd2d debug!! int mc01 = frAlgo.GetMcTrackIdForWindowHit(curr_trip->GetLHit()); int mc02 = frAlgo.GetMcTrackIdForWindowHit(curr_trip->GetMHit()); int mc03 = frAlgo.GetMcTrackIdForWindowHit(curr_trip->GetRHit()); diff --git a/algo/ca/core/utils/CaMonitor.h b/algo/ca/core/utils/CaMonitor.h index 32fe600c7d0cee484ddc3f257cbfe7f54ba87696..389b196fef4b51be0b5c8b054c0967cb6216fe7b 100644 --- a/algo/ca/core/utils/CaMonitor.h +++ b/algo/ca/core/utils/CaMonitor.h @@ -65,8 +65,12 @@ namespace cbm::algo::ca Monitor& operator=(Monitor&&) = delete; /// \brief Adds the other monitor data to this - /// \param data Reference to the other MonitorData object to add - void AddMonitorData(const MonitorData<ECounterKey, ETimerKey>& data) { fMonitorData.AddMonitorData(data); } + /// \param data Reference to the other MonitorData object to add + /// \param parallel True, if the monitor data were obtained in parallel (See Timer::AddMonitorData) + void AddMonitorData(const MonitorData<ECounterKey, ETimerKey>& data, bool parallel = false) + { + fMonitorData.AddMonitorData(data, parallel); + } /// \brief Gets counter name /// \param key Counter key diff --git a/algo/ca/core/utils/CaMonitorData.h b/algo/ca/core/utils/CaMonitorData.h index 9a172980098a485f16c3a7218e73e506cd33c150..c1f0f8d7e88ec497f0a1e5c607235badf5e16dd5 100644 --- a/algo/ca/core/utils/CaMonitorData.h +++ b/algo/ca/core/utils/CaMonitorData.h @@ -53,8 +53,9 @@ namespace cbm::algo::ca MonitorData& operator=(MonitorData&&) = default; /// \brief Adds the other monitor data to this - /// \param other Reference to the other MonitorData object to add - void AddMonitorData(const MonitorData& other); + /// \param other Reference to the other MonitorData object to add + /// \param parallel If the monitors were filled in parallel (See CaTimer::AddTimer) + void AddMonitorData(const MonitorData& other, bool parallel = false); /// \brief Gets counter value /// \param key @@ -110,13 +111,14 @@ namespace cbm::algo::ca // --------------------------------------------------------------------------------------------------------------------- // template<class ECounterKey, class ETimerKey> - inline void MonitorData<ECounterKey, ETimerKey>::AddMonitorData(const MonitorData<ECounterKey, ETimerKey>& other) + inline void MonitorData<ECounterKey, ETimerKey>::AddMonitorData(const MonitorData<ECounterKey, ETimerKey>& other, + bool parallel) { for (size_t iCounter = 0; iCounter < faCounters.size(); ++iCounter) { faCounters[iCounter] += other.faCounters[iCounter]; } for (size_t iTimer = 0; iTimer < faTimers.size(); ++iTimer) { - faTimers[iTimer].AddTimer(other.faTimers[iTimer]); + faTimers[iTimer].AddTimer(other.faTimers[iTimer], parallel); } } diff --git a/algo/ca/core/utils/CaTimer.h b/algo/ca/core/utils/CaTimer.h index 37f7d059e9f1a0258a1dcab1b20221c741f8ed58..6a9fc5ea640d16aa09566e8a147271edb6dbc406 100644 --- a/algo/ca/core/utils/CaTimer.h +++ b/algo/ca/core/utils/CaTimer.h @@ -13,6 +13,7 @@ #include <chrono> #include <cstdint> +#include <iostream> #include <limits> #include <string> @@ -47,8 +48,12 @@ namespace cbm::algo::ca Timer& operator=(Timer&&) = default; /// \brief Adds another timer - /// \param other Reference to the other Timer object to add - void AddTimer(const Timer& other); + /// \param other Reference to the other Timer object to add + /// \param parallel Bool: if the timers were executed in parallel + /// + /// If the parallel flag is true then the resulting fTotal time is taken as a maximum of each total time of + /// the appended timers. If the parallel flag is false, the resulting fTotal is a sum of all timers. + void AddTimer(const Timer& other, bool parallel); /// \brief Gets average time [s] double GetAverage() const { return static_cast<double>(fTotal) / fNofCalls * 1.e-9; } @@ -112,7 +117,7 @@ namespace cbm::algo::ca // ------------------------------------------------------------------------------------------------------------------- // - inline void Timer::AddTimer(const Timer& other) + inline void Timer::AddTimer(const Timer& other, bool parallel) { if (other.fMin < fMin) { fMin = other.fMin; @@ -122,7 +127,14 @@ namespace cbm::algo::ca fMax = other.fMax; fMaxCallIndex = other.fMinCallIndex + fNofCalls; } - fTotal += other.fTotal; + if (parallel) { + if (fTotal < other.fTotal) { + fTotal = other.fTotal; + } + } + else { + fTotal += other.fTotal; + } fNofCalls += other.fNofCalls; }