CbmRoot
Loading...
Searching...
No Matches
CaMonitorData.h
Go to the documentation of this file.
1/* Copyright (C) 2023 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Sergei Zharko [committer] */
4
9
10#pragma once
11
12#include "CaEnumArray.h"
13#include "CaTimer.h"
14
15#include <boost/serialization/access.hpp>
16
17#include <algorithm>
18
19namespace cbm::algo::ca
20{
26 template<class ECounterKey, class ETimerKey>
27 class MonitorData {
28 public:
30 template<typename T>
32
34 template<typename T>
36
38 MonitorData() = default;
39
41 MonitorData(const MonitorData&) = default;
42
45
47 ~MonitorData() = default;
48
50 MonitorData& operator=(const MonitorData&) = default;
51
54
58 void AddMonitorData(const MonitorData& other, bool parallel = false);
59
62 int GetCounterValue(ECounterKey key) const { return faCounters[key]; }
63
65 int GetNofCounters() const { return static_cast<int>(ECounterKey::END); }
66
68 int GetNofTimers() const { return static_cast<int>(ETimerKey::END); }
69
71 const Timer& GetTimer(ETimerKey key) const { return faTimers[key]; }
72
75 void IncrementCounter(ECounterKey key) { ++faCounters[key]; };
76
80 void IncrementCounter(ECounterKey key, int num) { faCounters[key] += num; }
81
83 void Reset();
84
87 void StartTimer(ETimerKey key) { faTimers[key].Start(); }
88
91 void StopTimer(ETimerKey key) { faTimers[key].Stop(); }
92
93 private:
95 template<typename Archive>
96 void serialize(Archive& ar, const unsigned int /*version*/)
97 {
98 ar& faTimers;
99 ar& faCounters;
100 }
101
104 };
105
106
107 // *****************************************
108 // ** Template function implementations **
109 // *****************************************
110
111 // ---------------------------------------------------------------------------------------------------------------------
112 //
113 template<class ECounterKey, class ETimerKey>
115 bool parallel)
116 {
117 for (size_t iCounter = 0; iCounter < faCounters.size(); ++iCounter) {
118 faCounters[iCounter] += other.faCounters[iCounter];
119 }
120 for (size_t iTimer = 0; iTimer < faTimers.size(); ++iTimer) {
121 faTimers[iTimer].AddTimer(other.faTimers[iTimer], parallel);
122 }
123 }
124
125 // ---------------------------------------------------------------------------------------------------------------------
126 //
127 template<class ECounterKey, class ETimerKey>
129 {
130 faCounters.fill(0);
131 std::for_each(faTimers.begin(), faTimers.end(), [](auto& timer) { timer.Reset(); });
132 }
133} // namespace cbm::algo::ca
Implementation of cbm::algo::ca::EnumArray class.
Timer class for CA tracking (header)
Class of arrays, which can be accessed by an enum class entry as an index.
Monitor data block.
Definition Reco.h:80
MonitorData(const MonitorData &)=default
Copy constructor.
void serialize(Archive &ar, const unsigned int)
~MonitorData()=default
Destructor.
int GetCounterValue(ECounterKey key) const
Gets counter value.
TimerArray< Timer > faTimers
Array of timers.
MonitorData(MonitorData &&)=default
Move constructor.
void IncrementCounter(ECounterKey key, int num)
Increments key counter by a number.
void Reset()
Resets all the counters and timers.
CounterArray< int > faCounters
Array of counters.
int GetNofTimers() const
Gets number of timers.
MonitorData()=default
Default constructor.
void StopTimer(ETimerKey key)
Stops timer.
void IncrementCounter(ECounterKey key)
Increments key counter by 1.
int GetNofCounters() const
Gets number of counters.
void StartTimer(ETimerKey key)
Starts timer.
MonitorData & operator=(MonitorData &&)=default
Move assignment operator.
friend class boost::serialization::access
void AddMonitorData(const MonitorData &other, bool parallel=false)
Adds the other monitor data to this.
const Timer & GetTimer(ETimerKey key) const
Gets timer.
MonitorData & operator=(const MonitorData &)=default
Copy assignment operator.
A timer class for the monitor.
Definition CaTimer.h:25
TODO: SZh 8.11.2022: add selection of parameterisation.
Definition CaBranch.h:14