@@ -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
13881388void 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 ;
0 commit comments