@@ -541,18 +541,33 @@ void WorkflowHelpers::injectServiceDevices(WorkflowSpec& workflow, ConfigContext
541541 } else if (providesDISTSTF) {
542542 ccdbBackend.inputs .push_back (InputSpec{" tfn" , dstf, Lifetime::Timeframe});
543543 } else {
544- for (auto & dp : workflow) {
545- bool enumOnly = dp.inputs .size () == 1 && dp.inputs [0 ].lifetime == Lifetime::Enumeration;
546- bool timerOnly = dp.inputs .size () == 1 && dp.inputs [0 ].lifetime == Lifetime::Timer;
547- if (enumOnly == true ) {
548- dp.outputs .push_back (OutputSpec{{" ccdb-diststf" }, dstf, Lifetime::Timeframe});
549- ccdbBackend.inputs .push_back (InputSpec{" tfn" , dstf, Lifetime::Timeframe});
550- break ;
551- } else if (timerOnly == true ) {
552- dstf = DataSpecUtils::asConcreteDataMatcher (dp.outputs [0 ]);
553- ccdbBackend.inputs .push_back (InputSpec{{" tfn" }, dstf, Lifetime::Timeframe});
554- break ;
544+ // We find the first device which has either just enumerations or
545+ // just timers, and we add the DISTSUBTIMEFRAME to it.
546+ // Notice how we do so in a stable manner by sorting the devices
547+ // by name.
548+ int enumCandidate = -1 ;
549+ int timerCandidate = -1 ;
550+ for (size_t wi = 0 ; wi < workflow.size (); wi++) {
551+ auto & dp = workflow[wi];
552+ if (dp.inputs .size () != 1 ) {
553+ continue ;
555554 }
555+ auto lifetime = dp.inputs [0 ].lifetime ;
556+ if (lifetime == Lifetime::Enumeration && (enumCandidate == -1 || workflow[enumCandidate].name > dp.name )) {
557+ enumCandidate = wi;
558+ }
559+ if (lifetime == Lifetime::Timer && (timerCandidate == -1 || workflow[timerCandidate].name > dp.name )) {
560+ timerCandidate = wi;
561+ }
562+ }
563+ if (enumCandidate != -1 ) {
564+ auto & dp = workflow[enumCandidate];
565+ dp.outputs .push_back (OutputSpec{{" ccdb-diststf" }, dstf, Lifetime::Timeframe});
566+ ccdbBackend.inputs .push_back (InputSpec{" tfn" , dstf, Lifetime::Timeframe});
567+ } else if (timerCandidate != -1 ) {
568+ auto & dp = workflow[timerCandidate];
569+ dstf = DataSpecUtils::asConcreteDataMatcher (dp.outputs [0 ]);
570+ ccdbBackend.inputs .push_back (InputSpec{{" tfn" }, dstf, Lifetime::Timeframe});
556571 }
557572 }
558573
@@ -573,18 +588,33 @@ void WorkflowHelpers::injectServiceDevices(WorkflowSpec& workflow, ConfigContext
573588 }
574589 }
575590 if (requiresDISTSUBTIMEFRAME) {
576- for (auto & dp : workflow) {
577- bool enumOnly = dp.inputs .size () == 1 && dp.inputs [0 ].lifetime == Lifetime::Enumeration;
578- bool timerOnly = dp.inputs .size () == 1 && dp.inputs [0 ].lifetime == Lifetime::Timer;
579- if (enumOnly == true ) {
580- dp.outputs .push_back (OutputSpec{{" ccdb-diststf" }, dstf, Lifetime::Timeframe});
581- ccdbBackend.inputs .push_back (InputSpec{" tfn" , dstf, Lifetime::Timeframe});
582- break ;
583- } else if (timerOnly == true ) {
584- dstf = DataSpecUtils::asConcreteDataMatcher (dp.outputs [0 ]);
585- ccdbBackend.inputs .push_back (InputSpec{{" tfn" }, dstf, Lifetime::Timeframe});
586- break ;
591+ // We find the first device which has either just enumerations or
592+ // just timers, and we add the DISTSUBTIMEFRAME to it.
593+ // Notice how we do so in a stable manner by sorting the devices
594+ // by name.
595+ int enumCandidate = -1 ;
596+ int timerCandidate = -1 ;
597+ for (size_t wi = 0 ; wi < workflow.size (); wi++) {
598+ auto & dp = workflow[wi];
599+ if (dp.inputs .size () != 1 ) {
600+ continue ;
587601 }
602+ auto lifetime = dp.inputs [0 ].lifetime ;
603+ if (lifetime == Lifetime::Enumeration && (enumCandidate == -1 || workflow[enumCandidate].name > dp.name )) {
604+ enumCandidate = wi;
605+ }
606+ if (lifetime == Lifetime::Timer && (timerCandidate == -1 || workflow[timerCandidate].name > dp.name )) {
607+ timerCandidate = wi;
608+ }
609+ }
610+ if (enumCandidate != -1 ) {
611+ auto & dp = workflow[enumCandidate];
612+ dp.outputs .push_back (OutputSpec{{" ccdb-diststf" }, dstf, Lifetime::Timeframe});
613+ ccdbBackend.inputs .push_back (InputSpec{" tfn" , dstf, Lifetime::Timeframe});
614+ } else if (timerCandidate != -1 ) {
615+ auto & dp = workflow[timerCandidate];
616+ dstf = DataSpecUtils::asConcreteDataMatcher (dp.outputs [0 ]);
617+ ccdbBackend.inputs .push_back (InputSpec{{" tfn" }, dstf, Lifetime::Timeframe});
588618 }
589619 }
590620 }
0 commit comments