@@ -285,6 +285,12 @@ void TfBuilderDevice::PreRun()
285285 // enable monitoring
286286 DataDistMonitor::enable_datadist (DataDistLogger::sRunNumber , mPartitionId );
287287
288+ // reset tf counters and start accepting tfs
289+ // NOTE: TfBuilder accepts TFs in both READY and RUNNING state.
290+ mFlpInputHandler ->reset ();
291+ mRpc ->reset_run_counters ();
292+ mRpc ->startAcceptingTfs ();
293+
288294 IDDLOG (" Entering running state. RunNumber: {}" , DataDistLogger::sRunNumberStr );
289295
290296 mTfFwdTotalDataSize = 0 ;
@@ -298,6 +304,12 @@ void TfBuilderDevice::PreRun()
298304// Get here when ConditionalRun returns false
299305void TfBuilderDevice::PostRun ()
300306{
307+ // stop accepting tfs until the state is clear in-between runs
308+ mRpc ->stopAcceptingTfs ();
309+
310+ // send EOS
311+ mShouldSendEos = true ;
312+
301313 // Not in Running state
302314 mInRunningState = false ;
303315 DDMON (" tfbuilder" , " running" , 0 );
@@ -310,6 +322,9 @@ void TfBuilderDevice::PostRun()
310322 // disable monitoring
311323 DataDistMonitor::disable_datadist ();
312324
325+ // start accepting tfs for the next run
326+ mRpc ->startAcceptingTfs ();
327+
313328 IDDLOG (" Exiting running state. RunNumber: {}" , DataDistLogger::sRunNumberStr );
314329}
315330
@@ -334,8 +349,6 @@ void TfBuilderDevice::TfForwardThread()
334349{
335350 using hres_clock = std::chrono::high_resolution_clock;
336351 auto lRateStartTime = hres_clock::now ();
337- std::uint64_t lTfOutCnt = 0 ;
338- bool lShouldSendEos = false ;
339352
340353 while (mRunning ) {
341354 std::optional<std::unique_ptr<SubTimeFrame>> lTfOpt = dequeue_for (eTfFwdIn, 100ms);
@@ -350,16 +363,14 @@ void TfBuilderDevice::TfForwardThread()
350363 WDDLOG_RL (1000 , " Dropping a raw TimeFrame because stop of the run is requested." );
351364 }
352365
353- if ( dplEnabled () && lShouldSendEos) {
354- lShouldSendEos = false ;
366+ // send EOS if exiting the running state
367+ if ( dplEnabled () && mShouldSendEos ) {
355368 mTfDplAdapter ->sendEosToDpl ();
369+ mShouldSendEos = false ;
356370 }
357371 continue ;
358372 }
359373
360- // Make sure to send EoS if in running state
361- lShouldSendEos = true ;
362-
363374 if (lTfOpt == std::nullopt ) {
364375 DDMON (" tfbuilder" , " data_output.rate" , 0 );
365376 DDMON (" tfbuilder" , " tf_output.sent_size" , mTfFwdTotalDataSize );
@@ -386,9 +397,8 @@ void TfBuilderDevice::TfForwardThread()
386397
387398 if (!mStandalone ) {
388399 try {
389- lTfOutCnt++;
390400 IDDLOG_RL (5000 , " Forwarding a new TF to DPL. tf_id={} stf_size={:d} unique_equipments={:d} total={:d}" ,
391- lTfId, lTf->getDataSize (), lTf->getEquipmentIdentifiers ().size (), lTfOutCnt );
401+ lTfId, lTf->getDataSize (), lTf->getEquipmentIdentifiers ().size (), mTfFwdTotalTfCount );
392402
393403 if (dplEnabled ()) {
394404 // adapt headers to include DPL processing header on the stack
@@ -413,8 +423,9 @@ void TfBuilderDevice::TfForwardThread()
413423 }
414424
415425 // leaving the output thread, send end of the stream info
416- if (dplEnabled () && lShouldSendEos ) {
426+ if (dplEnabled () && mShouldSendEos ) {
417427 mTfDplAdapter ->sendEosToDpl ();
428+ mShouldSendEos = false ;
418429 }
419430
420431 DDDLOG (" Exiting TF forwarding thread." );
0 commit comments