From d7da496aae1ef1733a4f83d97bdd9de4157fda48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Tich=C3=A1k?= Date: Mon, 2 Jun 2025 11:44:13 +0200 Subject: [PATCH] [OCTRL-932] sorted runs list when received from Kafka --- examples/8-KafkaToHttpServer.cxx | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/examples/8-KafkaToHttpServer.cxx b/examples/8-KafkaToHttpServer.cxx index f4e01b20..5a11cb81 100644 --- a/examples/8-KafkaToHttpServer.cxx +++ b/examples/8-KafkaToHttpServer.cxx @@ -123,6 +123,27 @@ void deserializeActiveRuns(const std::string& lastActiveRunMessage) << activeRuns.activeruns(i).environmentid() << ")" << MonLogger::End(); } } + + // sort received active runs according to following rules: + // 1) runs with more than 2 detectors are listed first + // 2) if there are more than 1 run with more than 2 detectors list those with ITS first + auto* runsToSort = activeRuns.mutable_activeruns(); + std::sort(runsToSort->begin(), runsToSort->end(), [](const aliceo2::envs::EnvInfo& a, const aliceo2::envs::EnvInfo& b) { + auto hasITS = [](auto&& detectors) { + return std::find(detectors.begin(), detectors.end(), "ITS") != detectors.end(); + }; + + if (a.detectors().size() >= 2 && b.detectors().size() >= 2) { + if (hasITS(a.detectors())) { + return true; + } + if (hasITS(b.detectors())) { + return false; + } + } + + return a.detectors().size() > b.detectors().size(); + }); const std::lock_guard lock(gEnvAccess); gActiveEnvs = activeRuns; }