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>
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 ResetCounter(ECounterKey key) { faCounters[key] = 0; }
88
91 void StartTimer(ETimerKey key) { faTimers[key].Start(); }
92
95 void StopTimer(ETimerKey key) { faTimers[key].Stop(); }
96
97 private:
98 friend class boost::serialization::access;
99 template<typename Archive>
100 void serialize(Archive& ar, const unsigned int /*version*/)
101 {
102 ar& faTimers;
103 ar& faCounters;
104 }
105
108 };
109
110
111 // *****************************************
112 // ** Template function implementations **
113 // *****************************************
114
115 // ---------------------------------------------------------------------------------------------------------------------
116 //
117 template<class ECounterKey, class ETimerKey>
119 bool parallel)
120 {
121 for (size_t iCounter = 0; iCounter < faCounters.size(); ++iCounter) {
122 faCounters[iCounter] += other.faCounters[iCounter];
123 }
124 for (size_t iTimer = 0; iTimer < faTimers.size(); ++iTimer) {
125 faTimers[iTimer].AddTimer(other.faTimers[iTimer], parallel);
126 }
127 }
128
129 // ---------------------------------------------------------------------------------------------------------------------
130 //
131 template<class ECounterKey, class ETimerKey>
133 {
134 faCounters.fill(0);
135 std::for_each(faTimers.begin(), faTimers.end(), [](auto& timer) { timer.Reset(); });
136 }
137} // 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.
int GetNofCounters() const
Gets number of counters.
void serialize(Archive &ar, const unsigned int)
EnumArray< ECounterKey, T > CounterArray
Alias to array, indexed by the counter enumeration.
void ResetCounter(ECounterKey key)
Resets a particular counter.
EnumArray< ETimerKey, T > TimerArray
Alias to array, indexed by the timer enumeration.
const Timer & GetTimer(ETimerKey key) const
Gets timer.
void Reset()
Resets all the counters and timers.
int GetNofTimers() const
Gets number of timers.
MonitorData(MonitorData &&)=default
Move constructor.
MonitorData & operator=(const MonitorData &)=default
Copy assignment operator.
void StartTimer(ETimerKey key)
Starts timer.
void StopTimer(ETimerKey key)
Stops timer.
void IncrementCounter(ECounterKey key, int num)
Increments key counter by a number.
void IncrementCounter(ECounterKey key)
Increments key counter by 1.
void AddMonitorData(const MonitorData &other, bool parallel=false)
Adds the other monitor data to this.
MonitorData & operator=(MonitorData &&)=default
Move assignment operator.
MonitorData()=default
Default constructor.
MonitorData(const MonitorData &)=default
Copy constructor.
int GetCounterValue(ECounterKey key) const
Gets counter value.
~MonitorData()=default
Destructor.
A timer class for the monitor.
Definition CaTimer.h:25
TODO: SZh 8.11.2022: add selection of parameterisation.
Definition CaBranch.h:14