ndmspc v1.2.0-0.1.rc7
Loading...
Searching...
No Matches
NThreadData.cxx
1#include <iostream>
2#include <vector>
3#include <thread>
4#include <TString.h>
5#include "NLogger.h"
6#include "NThreadData.h"
7
9ClassImp(Ndmspc::NThreadData);
11namespace Ndmspc {
14{
18}
19
26void NThreadData::Process(const std::vector<int> & coords)
27{
28
29 NLogTrace("Processing coordinates in thread %llu",
30 (unsigned long long)std::hash<std::thread::id>{}(std::this_thread::get_id()));
31 // Use renamed members with lowercase 'f'
32 if (!fIdSet) {
33 fThreadId = std::this_thread::get_id();
34 fIdSet = true;
35 }
36 fItemCount++;
37 for (int val : coords) {
38 fCoordSum += val;
39 }
40 std::this_thread::sleep_for(std::chrono::milliseconds(500));
41}
42
43void NThreadData::Print(Option_t * /*option*/) const
44{
45 NLogTrace("NThreadData [Index: %zu, ThreadId: %llu, Items: %lld, Sum: %lld]", fAssignedIndex,
46 (unsigned long long)std::hash<std::thread::id>{}(fThreadId), fItemCount, fCoordSum);
47}
48
49} // namespace Ndmspc
Thread-local data object for NDMSPC processing.
Definition NThreadData.h:21
bool fIdSet
Flag to indicate if the thread ID is set.
size_t fAssignedIndex
Index assigned to this object.
virtual ~NThreadData()
Virtual destructor.
long long fCoordSum
Sum of coordinates.
virtual void Print(Option_t *option="") const
Print method override.
std::thread::id fThreadId
Thread ID.
virtual void Process(const std::vector< int > &coords)
Process method for thread data.
NThreadData()
Default constructor.
long long fItemCount
Number of items processed.
static std::mutex fSharedMutex
Shared mutex for thread-safe operations.
Definition NThreadData.h:98
Global callback function for libwebsockets client events.