ndmspc  v1.2.0-0.1.rc3
NThreadData.h
1 #ifndef Ndmspc_NThreadData_H
2 #define Ndmspc_NThreadData_H
3 #include <vector>
4 #include <thread>
5 #include <cstddef>
6 #include <mutex>
7 #include <TObject.h>
8 #include "NResourceMonitor.h"
9 
10 namespace Ndmspc {
11 
21 class NThreadData : public TObject {
22  public:
24 
29  void SetItemCount(long long itemCount) { fItemCount = itemCount; }
30 
35  void SetCoordSum(long long coordSum) { fCoordSum = coordSum; }
36 
41  void SetThreadId(std::thread::id threadId) { fThreadId = threadId; }
42 
47  void SetIdSet(bool idSet) { fIdSet = idSet; }
48 
53  void SetAssignedIndex(size_t assignedIndex) { fAssignedIndex = assignedIndex; }
54 
64  void SetResourceMonitor(NResourceMonitor * monitor) { fResourceMonitor = monitor; }
65 
67 
72  long long GetItemCount() const { return fItemCount; }
73 
78  long long GetCoordSum() const { return fCoordSum; }
79 
84  std::thread::id GetThreadId() const { return fThreadId; }
85 
90  bool GetIdSet() const { return fIdSet; }
91 
96  size_t GetAssignedIndex() const { return fAssignedIndex; }
98  static std::mutex fSharedMutex;
99 
109 
113  NThreadData();
114 
118  virtual ~NThreadData();
119 
124  virtual void Process(const std::vector<int> & coords);
125 
130  virtual void Print(Option_t * option = "") const;
131 
132  protected:
134 
135  private:
136  long long fItemCount = 0;
137  long long fCoordSum = 0;
138  std::thread::id fThreadId;
139  bool fIdSet = false;
140  size_t fAssignedIndex = 0;
141 
143  ClassDef(NThreadData, 1);
145 };
146 } // namespace Ndmspc
147 #endif
Monitors and records resource usage (CPU, memory, wall time) for processes or threads.
Thread-local data object for NDMSPC processing.
Definition: NThreadData.h:21
void SetItemCount(long long itemCount)
Setters for data members.
Definition: NThreadData.h:29
NResourceMonitor * GetResourceMonitor() const
Gets the resource monitor associated with this thread data.
Definition: NThreadData.h:108
void SetResourceMonitor(NResourceMonitor *monitor)
Sets the resource monitor for this thread data.
Definition: NThreadData.h:64
bool fIdSet
Flag to indicate if the thread ID is set.
Definition: NThreadData.h:139
long long GetCoordSum() const
Get the sum of coordinates processed by the thread.
Definition: NThreadData.h:78
size_t fAssignedIndex
Index assigned to this object.
Definition: NThreadData.h:140
virtual ~NThreadData()
Virtual destructor.
Definition: NThreadData.cxx:20
long long fCoordSum
Sum of coordinates.
Definition: NThreadData.h:137
long long GetItemCount() const
Getters for data members.
Definition: NThreadData.h:72
virtual void Print(Option_t *option="") const
Print method override.
Definition: NThreadData.cxx:43
size_t GetAssignedIndex() const
Get the assigned index for the thread.
Definition: NThreadData.h:96
std::thread::id fThreadId
Thread ID.
Definition: NThreadData.h:138
std::thread::id GetThreadId() const
Get the thread's unique identifier.
Definition: NThreadData.h:84
virtual void Process(const std::vector< int > &coords)
Process method for thread data.
Definition: NThreadData.cxx:26
void SetAssignedIndex(size_t assignedIndex)
Set the assigned index for the thread.
Definition: NThreadData.h:53
NResourceMonitor * fResourceMonitor
Pointer to resource monitor.
Definition: NThreadData.h:133
NThreadData()
Default constructor.
Definition: NThreadData.cxx:13
long long fItemCount
Number of items processed.
Definition: NThreadData.h:136
void SetCoordSum(long long coordSum)
Set the sum of coordinates processed by the thread.
Definition: NThreadData.h:35
void SetThreadId(std::thread::id threadId)
Set the thread's unique identifier.
Definition: NThreadData.h:41
void SetIdSet(bool idSet)
Set whether the thread ID has been assigned.
Definition: NThreadData.h:47
bool GetIdSet() const
Check if the thread ID has been assigned.
Definition: NThreadData.h:90
static std::mutex fSharedMutex
Shared mutex for thread-safe operations.
Definition: NThreadData.h:98