Skip to content

Commit d7da496

Browse files
author
Michal Tichák
committed
[OCTRL-932] sorted runs list when received from Kafka
1 parent fcfe139 commit d7da496

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

examples/8-KafkaToHttpServer.cxx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,27 @@ void deserializeActiveRuns(const std::string& lastActiveRunMessage)
123123
<< activeRuns.activeruns(i).environmentid() << ")" << MonLogger::End();
124124
}
125125
}
126+
127+
// sort received active runs according to following rules:
128+
// 1) runs with more than 2 detectors are listed first
129+
// 2) if there are more than 1 run with more than 2 detectors list those with ITS first
130+
auto* runsToSort = activeRuns.mutable_activeruns();
131+
std::sort(runsToSort->begin(), runsToSort->end(), [](const aliceo2::envs::EnvInfo& a, const aliceo2::envs::EnvInfo& b) {
132+
auto hasITS = [](auto&& detectors) {
133+
return std::find(detectors.begin(), detectors.end(), "ITS") != detectors.end();
134+
};
135+
136+
if (a.detectors().size() >= 2 && b.detectors().size() >= 2) {
137+
if (hasITS(a.detectors())) {
138+
return true;
139+
}
140+
if (hasITS(b.detectors())) {
141+
return false;
142+
}
143+
}
144+
145+
return a.detectors().size() > b.detectors().size();
146+
});
126147
const std::lock_guard<std::mutex> lock(gEnvAccess);
127148
gActiveEnvs = activeRuns;
128149
}

0 commit comments

Comments
 (0)