Skip to content

Commit c12d547

Browse files
Karl Smithacarte53
authored andcommitted
Moved ReadScaler to align better with statsHandler.
The scalers are now read out when the statsHandler indicates it has surpassed the statsInterval. This should bring the values between OCR and parsing rate into closer agreement. It also reduces some of the code complexity.
1 parent 162e8be commit c12d547

5 files changed

Lines changed: 26 additions & 33 deletions

File tree

Poll/include/poll2_core.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,6 @@ class Poll{
137137
StatsHandler *statsHandler;
138138
static const int statsInterval_ = 3; ///<The amount time between scaler reads in seconds.
139139

140-
141140
const static std::vector<std::string> runControlCommands_;
142141
const static std::vector<std::string> paramControlCommands_;
143142
const static std::vector<std::string> pollStatusCommands_;
@@ -234,9 +233,6 @@ class Poll{
234233

235234
void SetThreshWords(const size_t &thresh_){ threshWords = thresh_; }
236235

237-
/// Set the external poll stats handler
238-
void SetStatsHandler(StatsHandler *handler){ statsHandler = handler; }
239-
240236
///Set the terminal pointer.
241237
void SetTerminal(Terminal *term){ poll_term_ = term; };
242238

Poll/include/poll2_stats.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ class StatsHandler{
1515

1616
void AddEvent(unsigned int mod, unsigned int ch, size_t size, int delta_=1);
1717

18-
void AddTime(double dtime);
18+
bool AddTime(double dtime);
19+
20+
///Set the amount of time between scalers dumps in seconds.
21+
void SetDumpInterval(double interval) {dumpTime = interval;};
1922

2023
double GetDataRate(size_t mod);
2124

Poll/source/poll2.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
#include "poll2_core.h"
1919
#include "Display.h"
20-
#include "StatsHandler.hpp"
2120
#include "CTerminal.h"
2221

2322
/* Print help dialogue for command line options. */
@@ -141,8 +140,6 @@ int main(int argc, char *argv[]){
141140
if(poll.GetPacmanMode()){ std::cout << "Using pacman mode!\n"; }
142141
std::cout << std::endl;
143142

144-
StatsHandler handler(poll.GetNcards());
145-
poll.SetStatsHandler(&handler);
146143
poll.SetTerminal(&poll_term);
147144

148145
if(poll.GetSendAlarm()){

Poll/source/poll2_core.cpp

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,6 @@ Poll::Poll(){
134134
udp_sequence = 0;
135135
total_spill_chunks = 0;
136136

137-
statsHandler = NULL;
138-
139137
client = new Client();
140138
}
141139

@@ -200,6 +198,9 @@ bool Poll::Initialize(){
200198
commands_.insert(commands_.begin(), runControlCommands_.begin(), runControlCommands_.end());
201199
}
202200

201+
statsHandler = new StatsHandler(n_cards);
202+
statsHandler->SetDumpInterval(statsInterval_);
203+
203204
return init = true;
204205
}
205206

@@ -1292,7 +1293,6 @@ void Poll::RunControl(){
12921293
}
12931294

12941295
if(acq_running){
1295-
ReadScalers();
12961296
ReadFIFO();
12971297

12981298
//Handle a stop signal
@@ -1386,11 +1386,6 @@ void Poll::RunControl(){
13861386
}
13871387

13881388
void Poll::ReadScalers() {
1389-
//Check if enough time has passed since last scaler read.
1390-
static long long previousReadTime = 0;
1391-
//The stats interval has not passed so we return without doing anything.
1392-
if (statsHandler->GetTotalTime() < previousReadTime + statsInterval_) return;
1393-
13941389
static std::vector< std::pair<double, double> > xiaRates(16, std::make_pair<double, double>(0,0));
13951390
static int numChPerMod = pif->GetNumberChannels();
13961391

@@ -1568,17 +1563,24 @@ bool Poll::ReadFIFO() {
15681563
dataWords += nWords[mod];
15691564
} //End loop over modules for reading FIFO
15701565

1566+
//Get the length of the spill
1567+
double spillTime = usGetTime(startTime);
1568+
double durSpill = spillTime - lastSpillTime;
1569+
lastSpillTime = spillTime;
1570+
1571+
// Add time to the statsHandler and check if interval has been exceeded.
1572+
//If exceed interval we read the scalers from the modules and dump the stats.
1573+
if (statsHandler->AddTime(durSpill * 1e-6)) {
1574+
ReadScalers();
1575+
statsHandler->Dump();
1576+
statsHandler->ClearRates();
1577+
}
1578+
15711579
if (!is_quiet) std::cout << "Writing/Broadcasting " << dataWords << " words.\n";
15721580
//We have read the FIFO now we write the data
15731581
if (record_data && !pac_mode) write_data(fifoData, dataWords);
15741582
broadcast_data(fifoData, dataWords);
15751583

1576-
//Get the length of the spill
1577-
double spillTime = usGetTime(startTime);
1578-
double durSpill = spillTime - lastSpillTime;
1579-
lastSpillTime = spillTime;
1580-
// Add time to the statsHandler (for monitor.bash)
1581-
if(statsHandler){ statsHandler->AddTime(durSpill * 1e-6); }
15821584
} //If we had exceeded the threshold or forced a flush
15831585

15841586
return true;

Poll/source/poll2_stats.cpp

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -92,20 +92,15 @@ void StatsHandler::AddEvent(unsigned int mod, unsigned int ch, size_t size, int
9292
dataTotal[mod] += size;
9393
}
9494

95-
void StatsHandler::AddTime(double dtime) {
95+
/**
96+
* \return Returns true if the dump interval is exceeded.
97+
*/
98+
bool StatsHandler::AddTime(double dtime) {
9699
timeElapsed += dtime;
97100
totalTime += dtime;
101+
102+
return (timeElapsed >= dumpTime);
98103

99-
if (timeElapsed >= dumpTime) {
100-
Dump();
101-
timeElapsed = 0;
102-
for(size_t i = 0; i < numCards; i++){
103-
for(size_t j = 0; j < NUM_CHAN_PER_MOD; j++){
104-
nEventsDelta[i][j] = 0;
105-
}
106-
dataDelta[i] = 0;
107-
}
108-
}
109104
}
110105

111106
void StatsHandler::Dump(void){

0 commit comments

Comments
 (0)