GRSISort "v4.0.0.5"
An extension of the ROOT analysis Framework
Loading...
Searching...
No Matches
TScalerQueue.cxx
Go to the documentation of this file.
1
2#include "TScalerQueue.h"
3
6
7///////////////////////////////////////////////////////////////
8///
9/// \class TDeadtimeScalerQueue
10///
11/// This class is where we store scalers. It is thread-safe
12/// and returns it's status in order to monitor progress.
13///
14///////////////////////////////////////////////////////////////
15
17
26
28 : fStopwatch(new TStopwatch())
29{
31 // When the Global Q is created, start a timer to see how long we are using it.
32 fStopwatch->Start();
33
34 Clear();
35}
36
37void TDeadtimeScalerQueue::Print(Option_t*) const
38{
39 /// Print the status of the Scaler Queue
41}
42
44{
45 /// Clear the entire Queue, Queue counters, and timer.
46 bool locked = false;
47 if(!fDeadtimeScalerQueue.empty()) {
48 while(!TDeadtimeScalerQueue::All.try_lock()) {
49 // do nothing
50 }
51 locked = true;
52 }
53
54 if(fScalersInQueue != 0) {
55 std::cout << RED << std::endl
56 << "\tWarning, discarding " << fScalersInQueue << " Scalers!" << RESET_COLOR << std::endl;
57 while(!fDeadtimeScalerQueue.empty()) {
59 }
61 }
62
63 fScalersIn = 0;
64 fScalersOut = 0;
65
68
69 fStopwatch->Reset();
70
71 if(locked) {
73 }
74}
75
77{
78 /// The status thread runs the status update at various intervals to show the progress of the analysis tree.
79 fStatusUpdateOn = true;
80
81 std::thread statusUpdate(&TDeadtimeScalerQueue::StatusUpdate, this);
82 statusUpdate.detach();
83}
84
86{
87 /// Stops the status update
88 fStatusUpdateOn = false;
89}
90
92{
93 /// Add a Scaler to the scaler Queue.
94 if(scalerData == nullptr) {
95 return;
96 }
97
98 while(!TDeadtimeScalerQueue::Sorted.try_lock()) {
99 // do nothing
100 }
101
102 fDeadtimeScalerQueue.push(scalerData);
103
106 fScalersIn++;
107
109}
110
112{
113 // Take a scaler out of the Queue
114 while(!TDeadtimeScalerQueue::Sorted.try_lock()) {
115 // do nothing
116 }
119 fScalersOut++;
121}
122
124{
125 // Take a scaler out of the Queue and return a pointer to it.
126 while(!TDeadtimeScalerQueue::Sorted.try_lock()) {
127 // do nothing
128 }
129 if(Size() > 0) {
130 TScalerData* scaler = fDeadtimeScalerQueue.front();
131 if(scaler != nullptr) {
134 fScalersOut++;
136 }
138 return scaler;
139 }
141 return nullptr;
142}
143
145{
146 // Returns the number of scalers in the Queue
147 return fScalersInQueue;
148}
149
151{
152 // Checks the status of the Queue. This is called by the Print() function.
153 while(!TDeadtimeScalerQueue::All.try_lock()) {
154 // do nothing
155 }
156
157 std::cout << BLUE << "# Scalers currently in Q = " << Size() << RESET_COLOR << std::endl;
158 std::cout << BLUE << "# Total Scalers put in Q = " << fTotalScalersIn << RESET_COLOR << std::endl;
159 std::cout << DGREEN << "# Total Scalers taken from Q = " << fTotalScalersOut << RESET_COLOR << std::endl;
160
162}
163
165{
166 // Updates the status of the scaler Queue
167 double time = 0;
168 double scaler_rate_in = 0;
169 double scaler_rate_out = 0;
170
171 while(fStatusUpdateOn) {
172 time = fStopwatch->RealTime();
173 scaler_rate_in = static_cast<double>(fScalersIn) / time;
174 scaler_rate_out = static_cast<double>(fScalersOut) / time;
175 while(!TDeadtimeScalerQueue::All.try_lock()) {
176 // do nothing
177 }
178
179 std::cout << BLUE << "\tscalers rate in = " << scaler_rate_in << "/sec, nqueue = " << Size() << RESET_COLOR << std::endl;
180 std::cout << DGREEN << "\tscalers rate out = " << scaler_rate_out << "/sec" << RESET_COLOR << std::endl;
183 fStopwatch->Start();
184 }
185}
186
188{
189 // Resets the number of scalers in and scalers out counter. This is useful for checking to see if the rate
190 // of scaler parsing is changing.
191 while(!TDeadtimeScalerQueue::All.try_lock()) {
192 // do nothing
193 }
194
195 fScalersIn = 0;
196 fScalersOut = 0;
198}
199
200std::mutex TRateScalerQueue::All;
201std::mutex TRateScalerQueue::Sorted;
202
203///////////////////////////////////////////////////////////////
204///
205/// \class TRateScalerQueue
206///
207/// This class is where we store scalers. It is thread-safe
208/// and returns it's status in order to monitor progress.
209///
210///////////////////////////////////////////////////////////////
211
213
215{
216 /// Get a pointer to the global scaler Q.
217 if(fRateScalerQueueClassPointer == nullptr) {
219 }
221}
222
224 : fStopwatch(new TStopwatch())
225{
227 // When the Global Q is created, start a timer to see how long we are using it.
228 fStopwatch->Start();
229
230 Clear();
231}
232
233void TRateScalerQueue::Print(Option_t*) const
234{
235 /// Print the status of the Scaler Queue
236 CheckStatus();
237}
238
240{
241 /// Clear the entire Queue, Queue counters, and timer.
242 bool locked = false;
243 if(!fRateScalerQueue.empty()) {
244 while(!TRateScalerQueue::All.try_lock()) {
245 // do nothing
246 }
247 locked = true;
248 }
249
250 if(fScalersInQueue != 0) {
251 std::cout << RED << "\tWarning, discarding " << fScalersInQueue << " Scalers!" << RESET_COLOR << std::endl;
252 while(!fRateScalerQueue.empty()) {
253 fRateScalerQueue.pop();
254 }
255 fScalersInQueue = 0;
256 }
257
258 fScalersIn = 0;
259 fScalersOut = 0;
260
261 fTotalScalersIn = 0;
263
264 fStopwatch->Reset();
265
266 if(locked) {
267 TRateScalerQueue::All.unlock();
268 }
269}
270
272{
273 /// The status thread runs the status update at various intervals to show the progress of the analysis tree.
274 fStatusUpdateOn = true;
275
276 std::thread statusUpdate(&TRateScalerQueue::StatusUpdate, this);
277 statusUpdate.detach();
278}
279
281{
282 /// Stops the status update
283 fStatusUpdateOn = false;
284}
285
287{
288 /// Add a Scaler to the scaler Queue.
289 if(scalerData == nullptr) {
290 return;
291 }
292
293 while(!TRateScalerQueue::Sorted.try_lock()) {
294 // do nothing
295 }
296
297 fRateScalerQueue.push(scalerData);
298
301 fScalersIn++;
302
304}
305
307{
308 // Take a scaler out of the Queue
309 while(!TRateScalerQueue::Sorted.try_lock()) {
310 // do nothing
311 }
312 fRateScalerQueue.pop();
314 fScalersOut++;
316}
317
319{
320 // Take a scaler out of the Queue and return a pointer to it.
321 while(!TRateScalerQueue::Sorted.try_lock()) {
322 // do nothing
323 }
324 if(Size() > 0) {
325 TScalerData* scaler = fRateScalerQueue.front();
326 if(scaler != nullptr) {
327 fRateScalerQueue.pop();
329 fScalersOut++;
331 }
333 return scaler;
334 }
336 return nullptr;
337}
338
340{
341 // Returns the number of scalers in the Queue
342 return fScalersInQueue;
343}
344
346{
347 // Checks the status of the Queue. This is called by the Print() function.
348 while(!TRateScalerQueue::All.try_lock()) {
349 // do nothing
350 }
351
352 std::cout << BLUE << "# Scalers currently in Q = " << Size() << RESET_COLOR << std::endl;
353 std::cout << BLUE << "# Total Scalers put in Q = " << fTotalScalersIn << RESET_COLOR << std::endl;
354 std::cout << DGREEN << "# Total Scalers taken from Q = " << fTotalScalersOut << RESET_COLOR << std::endl;
355
356 TRateScalerQueue::All.unlock();
357}
358
360{
361 // Updates the status of the scaler Queue
362 double time = 0;
363 double scaler_rate_in = 0;
364 double scaler_rate_out = 0;
365
366 while(fStatusUpdateOn) {
367 time = fStopwatch->RealTime();
368 scaler_rate_in = static_cast<double>(fScalersIn) / time;
369 scaler_rate_out = static_cast<double>(fScalersOut) / time;
370 while(!TRateScalerQueue::All.try_lock()) {
371 // do nothing
372 }
373
374 std::cout << BLUE << "\tscalers rate in = " << scaler_rate_in << "/sec, nqueue = " << Size() << RESET_COLOR << std::endl;
375 std::cout << DGREEN << "\tscalers rate out = " << scaler_rate_out << "/sec" << RESET_COLOR << std::endl;
376 TRateScalerQueue::All.unlock();
378 fStopwatch->Start();
379 }
380}
381
383{
384 // Resets the number of scalers in and scalers out counter. This is useful for checking to see if the rate
385 // of scaler parsing is changing.
386 while(!TRateScalerQueue::All.try_lock()) {
387 // do nothing
388 }
389
390 fScalersIn = 0;
391 fScalersOut = 0;
392 TRateScalerQueue::All.unlock();
393}
#define DGREEN
Definition Globals.h:17
#define BLUE
Definition Globals.h:6
#define RED
Definition Globals.h:9
#define RESET_COLOR
Definition Globals.h:5
unsigned int fTotalScalersOut
void Add(TScalerData *)
std::queue< TScalerData * > fDeadtimeScalerQueue
TStopwatch * fStopwatch
void Pop() override
void Clear(Option_t *opt="") override
TScalerData * PopScaler()
static TDeadtimeScalerQueue * fDeadtimeScalerQueueClassPointer
static TDeadtimeScalerQueue * Get()
unsigned int fTotalScalersIn
void Print(Option_t *opt="") const override
static std::mutex Sorted
static std::mutex All
void Print(Option_t *opt="") const override
static std::mutex Sorted
static TRateScalerQueue * fRateScalerQueueClassPointer
void CheckStatus() const
unsigned int fTotalScalersOut
TScalerData * PopScaler()
void Clear(Option_t *opt="") override
void Add(TScalerData *)
static std::mutex All
TStopwatch * fStopwatch
std::queue< TScalerData * > fRateScalerQueue
unsigned int fTotalScalersIn
void Pop() override
static TRateScalerQueue * Get()