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#include "TScalerQueue.h"
2
3#include <thread>
4
7
8///////////////////////////////////////////////////////////////
9///
10/// \class TDeadtimeScalerQueue
11///
12/// This class is where we store scalers. It is thread-safe
13/// and returns it's status in order to monitor progress.
14///
15///////////////////////////////////////////////////////////////
16
18
27
29 : fStopwatch(new TStopwatch())
30{
32 // When the Global Q is created, start a timer to see how long we are using it.
33 fStopwatch->Start();
34
35 Clear();
36}
37
39{
40 if(!fDeadtimeScalerQueue.empty()) {
41 Clear();
42 }
43 delete fStopwatch;
44}
45
46void TDeadtimeScalerQueue::Print(Option_t*) const
47{
48 /// Print the status of the Scaler Queue
50}
51
53{
54 /// Clear the entire Queue, Queue counters, and timer.
55 bool locked = false;
56 if(!fDeadtimeScalerQueue.empty()) {
57 while(!TDeadtimeScalerQueue::All.try_lock()) {
58 // do nothing
59 }
60 locked = true;
61 }
62
63 if(fScalersInQueue != 0) {
64 std::cout << RED << std::endl
65 << "\tWarning, discarding " << fScalersInQueue << " Scalers!" << RESET_COLOR << std::endl;
66 while(!fDeadtimeScalerQueue.empty()) {
67 delete fDeadtimeScalerQueue.front();
69 }
71 }
72
73 fScalersIn = 0;
74 fScalersOut = 0;
75
78
79 fStopwatch->Reset();
80
81 if(locked) {
83 }
84}
85
87{
88 /// The status thread runs the status update at various intervals to show the progress of the analysis tree.
89 fStatusUpdateOn = true;
90
91 std::thread statusUpdate(&TDeadtimeScalerQueue::StatusUpdate, this);
92 statusUpdate.detach();
93}
94
96{
97 /// Stops the status update
98 fStatusUpdateOn = false;
99}
100
102{
103 /// Add a Scaler to the scaler Queue.
104 if(scalerData == nullptr) {
105 return;
106 }
107
108 while(!TDeadtimeScalerQueue::Sorted.try_lock()) {
109 // do nothing
110 }
111
112 fDeadtimeScalerQueue.push(scalerData);
113
116 fScalersIn++;
117
119}
120
122{
123 // Take a scaler out of the Queue
124 while(!TDeadtimeScalerQueue::Sorted.try_lock()) {
125 // do nothing
126 }
129 fScalersOut++;
131}
132
134{
135 // Take a scaler out of the Queue and return a pointer to it.
136 while(!TDeadtimeScalerQueue::Sorted.try_lock()) {
137 // do nothing
138 }
139 if(Size() > 0) {
140 TScalerData* scaler = fDeadtimeScalerQueue.front();
141 if(scaler != nullptr) {
144 fScalersOut++;
146 }
148 return scaler;
149 }
151 return nullptr;
152}
153
155{
156 // Returns the number of scalers in the Queue
157 return fScalersInQueue;
158}
159
161{
162 // Checks the status of the Queue. This is called by the Print() function.
163 while(!TDeadtimeScalerQueue::All.try_lock()) {
164 // do nothing
165 }
166
167 std::cout << BLUE << "# Scalers currently in Q = " << Size() << RESET_COLOR << std::endl;
168 std::cout << BLUE << "# Total Scalers put in Q = " << fTotalScalersIn << RESET_COLOR << std::endl;
169 std::cout << DGREEN << "# Total Scalers taken from Q = " << fTotalScalersOut << RESET_COLOR << std::endl;
170
172}
173
175{
176 // Updates the status of the scaler Queue
177 double time = 0;
178 double scaler_rate_in = 0;
179 double scaler_rate_out = 0;
180
181 while(fStatusUpdateOn) {
182 time = fStopwatch->RealTime();
183 scaler_rate_in = static_cast<double>(fScalersIn) / time;
184 scaler_rate_out = static_cast<double>(fScalersOut) / time;
185 while(!TDeadtimeScalerQueue::All.try_lock()) {
186 // do nothing
187 }
188
189 std::cout << BLUE << "\tscalers rate in = " << scaler_rate_in << "/sec, nqueue = " << Size() << RESET_COLOR << std::endl;
190 std::cout << DGREEN << "\tscalers rate out = " << scaler_rate_out << "/sec" << RESET_COLOR << std::endl;
193 fStopwatch->Start();
194 }
195}
196
198{
199 // Resets the number of scalers in and scalers out counter. This is useful for checking to see if the rate
200 // of scaler parsing is changing.
201 while(!TDeadtimeScalerQueue::All.try_lock()) {
202 // do nothing
203 }
204
205 fScalersIn = 0;
206 fScalersOut = 0;
208}
209
210std::mutex TRateScalerQueue::All;
211std::mutex TRateScalerQueue::Sorted;
212
213///////////////////////////////////////////////////////////////
214///
215/// \class TRateScalerQueue
216///
217/// This class is where we store scalers. It is thread-safe
218/// and returns it's status in order to monitor progress.
219///
220///////////////////////////////////////////////////////////////
221
223
225{
226 /// Get a pointer to the global scaler Q.
227 if(fRateScalerQueueClassPointer == nullptr) {
229 }
231}
232
234 : fStopwatch(new TStopwatch())
235{
237 // When the Global Q is created, start a timer to see how long we are using it.
238 fStopwatch->Start();
239
240 Clear();
241}
242
244{
245 if(!fRateScalerQueue.empty()) {
246 Clear();
247 }
248 delete fStopwatch;
249}
250
251void TRateScalerQueue::Print(Option_t*) const
252{
253 /// Print the status of the Scaler Queue
254 CheckStatus();
255}
256
258{
259 /// Clear the entire Queue, Queue counters, and timer.
260 bool locked = false;
261 if(!fRateScalerQueue.empty()) {
262 while(!TRateScalerQueue::All.try_lock()) {
263 // do nothing
264 }
265 locked = true;
266 }
267
268 if(fScalersInQueue != 0) {
269 std::cout << RED << "\tWarning, discarding " << fScalersInQueue << " Scalers!" << RESET_COLOR << std::endl;
270 while(!fRateScalerQueue.empty()) {
271 delete fRateScalerQueue.front();
272 fRateScalerQueue.pop();
273 }
274 fScalersInQueue = 0;
275 }
276
277 fScalersIn = 0;
278 fScalersOut = 0;
279
280 fTotalScalersIn = 0;
282
283 fStopwatch->Reset();
284
285 if(locked) {
286 TRateScalerQueue::All.unlock();
287 }
288}
289
291{
292 /// The status thread runs the status update at various intervals to show the progress of the analysis tree.
293 fStatusUpdateOn = true;
294
295 std::thread statusUpdate(&TRateScalerQueue::StatusUpdate, this);
296 statusUpdate.detach();
297}
298
300{
301 /// Stops the status update
302 fStatusUpdateOn = false;
303}
304
306{
307 /// Add a Scaler to the scaler Queue.
308 if(scalerData == nullptr) {
309 return;
310 }
311
312 while(!TRateScalerQueue::Sorted.try_lock()) {
313 // do nothing
314 }
315
316 fRateScalerQueue.push(scalerData);
317
320 fScalersIn++;
321
323}
324
326{
327 // Take a scaler out of the Queue
328 while(!TRateScalerQueue::Sorted.try_lock()) {
329 // do nothing
330 }
331 fRateScalerQueue.pop();
333 fScalersOut++;
335}
336
338{
339 // Take a scaler out of the Queue and return a pointer to it.
340 while(!TRateScalerQueue::Sorted.try_lock()) {
341 // do nothing
342 }
343 if(Size() > 0) {
344 TScalerData* scaler = fRateScalerQueue.front();
345 if(scaler != nullptr) {
346 fRateScalerQueue.pop();
348 fScalersOut++;
350 }
352 return scaler;
353 }
355 return nullptr;
356}
357
359{
360 // Returns the number of scalers in the Queue
361 return fScalersInQueue;
362}
363
365{
366 // Checks the status of the Queue. This is called by the Print() function.
367 while(!TRateScalerQueue::All.try_lock()) {
368 // do nothing
369 }
370
371 std::cout << BLUE << "# Scalers currently in Q = " << Size() << RESET_COLOR << std::endl;
372 std::cout << BLUE << "# Total Scalers put in Q = " << fTotalScalersIn << RESET_COLOR << std::endl;
373 std::cout << DGREEN << "# Total Scalers taken from Q = " << fTotalScalersOut << RESET_COLOR << std::endl;
374
375 TRateScalerQueue::All.unlock();
376}
377
379{
380 // Updates the status of the scaler Queue
381 double time = 0;
382 double scaler_rate_in = 0;
383 double scaler_rate_out = 0;
384
385 while(fStatusUpdateOn) {
386 time = fStopwatch->RealTime();
387 scaler_rate_in = static_cast<double>(fScalersIn) / time;
388 scaler_rate_out = static_cast<double>(fScalersOut) / time;
389 while(!TRateScalerQueue::All.try_lock()) {
390 // do nothing
391 }
392
393 std::cout << BLUE << "\tscalers rate in = " << scaler_rate_in << "/sec, nqueue = " << Size() << RESET_COLOR << std::endl;
394 std::cout << DGREEN << "\tscalers rate out = " << scaler_rate_out << "/sec" << RESET_COLOR << std::endl;
395 TRateScalerQueue::All.unlock();
397 fStopwatch->Start();
398 }
399}
400
402{
403 // Resets the number of scalers in and scalers out counter. This is useful for checking to see if the rate
404 // of scaler parsing is changing.
405 while(!TRateScalerQueue::All.try_lock()) {
406 // do nothing
407 }
408
409 fScalersIn = 0;
410 fScalersOut = 0;
411 TRateScalerQueue::All.unlock();
412}
#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()