ATLAS Offline Software
Loading...
Searching...
No Matches
RemoteExecHiveEventLoopMgr.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
8
9#include <algorithm>
10#include <cstdio>
11#include <fstream>
12#include <limits>
13#include <optional>
14#include <sstream>
15#include <thread>
16#include <utility>
17
21#include "GaudiKernel/EventContext.h"
22#include "GaudiKernel/EventIDBase.h"
23#include "GaudiKernel/IAlgManager.h"
24#include "GaudiKernel/IAlgorithm.h"
25#include "GaudiKernel/ThreadLocalContext.h"
27
28namespace AthRemoteExec {
29
31 ISvcLocator* svcLoc)
32 : AthenaHiveEventLoopMgr(name, svcLoc) {
33 // This driver supplies events directly; it never reads a batch selector.
34 m_evtsel = "NONE";
35 m_schedulerName = "AvalancheSchedulerSvc";
36 declareProperty("EvtStore",
37 m_eventStore); // Preserve the RemoteExec property name.
38}
39
41
44
45 if (m_sequences.empty()) {
47 "No sequences configured; the server would have nothing to "
48 "offer. Set the Sequences property.");
49 return StatusCode::FAILURE;
50 }
51
52 const auto known = [this](const std::string& sequence) {
53 return std::find(m_sequences.begin(), m_sequences.end(), sequence) !=
54 m_sequences.end();
55 };
56 for (const auto& [sequence, keys] : m_outputKeys) {
57 if (!known(sequence)) {
58 ATH_MSG_ERROR("OutputKeys names sequence '{}', which is not in Sequences",
59 sequence);
60 return StatusCode::FAILURE;
61 }
62 }
63 for (const auto& [sequence, key] : m_replyKeys) {
64 if (!known(sequence)) {
65 ATH_MSG_ERROR("ReplyKeys names sequence '{}', which is not in Sequences",
66 sequence);
67 return StatusCode::FAILURE;
68 }
69 }
70 for (const auto& [sequence, keys] : m_outputKeys) {
71 if (!keys.empty() && m_replyKeys.value().count(sequence) == 0) {
72 ATH_MSG_ERROR("Sequence '{}' declares outputs but no entry in ReplyKeys",
73 sequence);
74 return StatusCode::FAILURE;
75 }
76 }
77
78 std::ostringstream menu;
79 for (const std::string& sequence : m_sequences) {
80 menu << (menu.tellp() == 0 ? "" : ", ") << sequence;
81 }
82 ATH_MSG_INFO("Serving {} sequence(s): {} over {} slot(s)", m_sequences.size(),
83 menu.str(), m_whiteboard->getNumberOfStores());
84
85 return StatusCode::SUCCESS;
86}
87
89 // Normally already done by nextEvent. This covers the paths where the loop
90 // never ran or threw, so the threads cannot outlive the services they use.
92 if (m_server) {
93 m_server->shutdown();
94 m_server.reset();
95 }
97}
98
100 ATH_MSG_INFO("Stop requested, draining the server");
101 m_stopRequested = true;
102 if (m_server) {
103 m_server->shutdown();
104 }
105 m_scheduledStop = true;
106 return StatusCode::SUCCESS;
107}
108
110 // Started here rather than in initialize() so that threads survives any
111 // future fork.
112 m_server = std::make_unique<Server>();
113
114 std::vector<SequenceInfo> menu;
115 menu.reserve(m_sequences.size());
116 for (const std::string& sequence : m_sequences) {
117 SequenceInfo info;
118 info.name = sequence;
119 // Advertise key#encoding#schema, so a client can discover what server is
120 // capable of receiving and replying. This is the same declaration the gate
121 // and pack algorithms parse.
122 const auto advertise = [](const std::vector<std::string>& specs,
123 std::vector<BoundaryInfo>& out) {
124 for (const std::string& spec : specs) {
125 const auto boundary = parseBoundary(spec);
126 if (boundary.has_value()) {
127 out.push_back(std::move(*boundary));
128 }
129 }
130 };
131 if (auto inputs = m_inputKeys.value().find(sequence);
132 inputs != m_inputKeys.value().end()) {
133 advertise(inputs->second, info.inputs);
134 }
135 if (auto outputs = m_outputKeys.value().find(sequence);
136 outputs != m_outputKeys.value().end()) {
137 advertise(outputs->second, info.outputs);
138 }
139 menu.push_back(std::move(info));
140 }
141 m_server->setMenu(std::move(menu));
142
143 const int boundPort =
145 [this](Server::Level level, const std::string& text) {
146 serverMessage(level, text);
147 });
148 if (boundPort < 0) {
149 ATH_MSG_ERROR("Could not start the gRPC server");
150 return StatusCode::FAILURE;
151 }
152 ATH_MSG_INFO("gRPC server listening on {}:{}", m_address.value(), boundPort);
153
154 if (!m_portFile.empty()) {
155 const std::string temporary = m_portFile + ".tmp";
156 {
157 std::ofstream out(temporary);
158 out << boundPort << '\n';
159 }
160 if (std::rename(temporary.c_str(), m_portFile.value().c_str()) != 0) {
161 ATH_MSG_ERROR("Could not write the port file " << m_portFile.value());
162 return StatusCode::FAILURE;
163 }
164 }
165 return StatusCode::SUCCESS;
166}
167
169 if (maxevt == 0) {
170 return StatusCode::SUCCESS;
171 }
173
174 const size_t limit = maxevt < 0 ? std::numeric_limits<size_t>::max()
175 : static_cast<size_t>(maxevt);
176 const size_t slots = m_whiteboard->getNumberOfStores();
177 const std::chrono::milliseconds poll(m_pollInterval);
178 size_t accepted = 0;
179
180 ATH_MSG_INFO("Starting the request loop");
181 std::optional<Clock::time_point> firstAccepted;
182 startHelpers();
183
184 const auto canAccept = [&] {
185 return !m_stopRequested && accepted < limit && m_inFlight.size() < slots &&
186 m_schedulerSvc->freeSlots() > 0;
187 };
188
189 while (true) {
190 if (m_inFlight.empty() && (m_stopRequested || accepted >= limit)) {
191 break;
192 }
193
194 bool progressed = false;
195
196 while (canAccept()) {
197 ExecuteRequest request;
198 std::unique_ptr<Server::Job> job;
199 const Take taken = takeRequest(request, job);
200 if (taken == Take::None) {
201 break;
202 }
203 if (taken == Take::Stopped) {
204 m_stopRequested = true;
205 progressed = true;
206 break;
207 }
208 ++accepted;
209 if (!firstAccepted) {
210 firstAccepted = Clock::now();
211 }
212 ATH_CHECK(dispatch(std::move(request), std::move(job)));
213 progressed = true;
214 }
215
216 // Complete everything the output thread has collected.
217 for (const Finished& finished : takeFinished()) {
218 ATH_CHECK(complete(finished));
219 progressed = true;
220 }
221
223
224 if (progressed) {
225 continue;
226 }
227
228 // Wait until we can accept new request or there are finished events OR
229 // periodically check if events passed their deadline
230 std::unique_lock<std::mutex> lock(m_pendingMutex);
231 const auto nothingToDo = [&] {
232 return (m_incoming.empty() || !canAccept()) && m_finishedEvents.empty();
233 };
234 if (nothingToDo()) {
235 if (m_requestTimeout > 0.0) {
236 m_pending.wait_for(lock, poll);
237 } else {
238 m_pending.wait(lock, [&] { return !nothingToDo(); });
239 }
240 }
241 }
242
243 stopHelpers();
244
245 ATH_MSG_INFO("Request loop finished: {} request(s) accepted, {} event(s) run",
246 accepted, m_completed);
247
248 // Cakculate throughput
249 if (firstAccepted && m_completed > 0) {
250 const double seconds =
251 std::chrono::duration<double>(Clock::now() - *firstAccepted).count();
252 if (seconds > 0.0) {
254 "Throughput: {} request(s) in {} s = {} request/s over {} slot(s)",
255 m_completed, seconds, (m_completed / seconds),
256 m_whiteboard->getNumberOfStores());
257 }
258 }
259
260 if (m_server) {
261 if (m_reportTiming) {
262 const std::string report = m_server->timingReport();
263 if (!report.empty()) {
264 ATH_MSG_ALWAYS('\n' << report);
265 }
266 }
267 m_server->shutdown();
268 }
269
270 return StatusCode::SUCCESS;
271}
272
274 {
275 const std::lock_guard<std::mutex> lock(m_pendingMutex);
276 m_helpersStopping = false;
277 // One work spot per slot, so the loop never waits on the input thread
278 m_incomingLimit = std::max<size_t>(1, m_whiteboard->getNumberOfStores());
279 m_inputDone = (m_server == nullptr);
280 }
281 if (m_server && !m_inputThread.joinable()) {
282 m_inputThread = std::thread([this] { inputLoop(); });
283 }
284 if (!m_outputThread.joinable()) {
285 m_outputThread = std::thread([this] { outputLoop(); });
286 }
287}
288
290 {
291 const std::lock_guard<std::mutex> lock(m_pendingMutex);
292 m_helpersStopping = true;
293 }
294 m_inFlightCv.notify_all();
295 m_pending.notify_all();
296 m_incomingRoom.notify_all();
297
298 // Stop accepting new request first...
299 if (m_inputThread.joinable()) {
300 if (m_server) {
301 m_server->stopAccepting();
302 }
303 m_inputThread.join();
304 }
305
306 // ...reply to client about all unfinished jobs...
307 drainPending();
308
309 // ... and stop replying
310 if (m_server) {
311 m_server->shutdown();
312 }
313 if (m_outputThread.joinable()) {
314 m_outputThread.join();
315 }
316}
317
319 std::deque<std::unique_ptr<Server::Job>> leftover;
320 std::deque<Finished> uncollected;
321 {
322 const std::lock_guard<std::mutex> lock(m_pendingMutex);
323 leftover.swap(m_incoming);
324 uncollected.swap(m_finishedEvents);
325 }
326 const std::string msgStr{"the server stopped before this request was served"};
327 for (const std::unique_ptr<Server::Job>& job : leftover) {
328 // Reply to clients so they won't stay stuck waiting
329 ATH_MSG_WARNING("Request {} ({}) was still queued when the loop stopped",
330 job->request.requestId, job->request.sequence);
331 respondDirect(job->request, job, AthRemoteExec::Status::ShuttingDown, msgStr);
332 }
333
334 // Destroy finished events
335 for (const Finished& finished : uncollected) {
336 delete finished.ctx;
337 }
338}
339
341 std::unique_ptr<Server::Job> job;
342 while (m_server->pop(job)) {
343 {
344 std::unique_lock<std::mutex> lock(m_pendingMutex);
345 // Wait until there is space for a new job
346 m_incomingRoom.wait(lock, [this] {
348 });
349 m_incoming.push_back(std::move(job));
350 }
351 m_pending.notify_one();
352 }
353 {
354 const std::lock_guard<std::mutex> lock(m_pendingMutex);
355 m_inputDone = true;
356 }
357 m_pending.notify_one();
358}
359
361 while (true) {
362 {
363 std::unique_lock<std::mutex> lock(m_pendingMutex);
364 m_inFlightCv.wait(lock, [this] {
366 });
367 if (m_awaitingCompletion == 0) {
368 return;
369 }
370 }
371
372 // Wait until there is a finished job to collect
373 EventContext* finished = nullptr;
374 if (m_schedulerSvc->popFinishedEvent(finished).isFailure()) {
375 std::this_thread::sleep_for(std::chrono::milliseconds(1));
376 continue;
377 }
378 const Clock::time_point at = Clock::now();
379
380 {
381 const std::lock_guard<std::mutex> lock(m_pendingMutex);
383 m_finishedEvents.push_back(Finished{finished, at});
384 }
385 m_pending.notify_one();
386 }
387}
388
389std::vector<RemoteExecHiveEventLoopMgr::Finished>
391 std::vector<Finished> finished;
392 const std::lock_guard<std::mutex> lock(m_pendingMutex);
393 finished.assign(m_finishedEvents.begin(), m_finishedEvents.end());
394 m_finishedEvents.clear();
395 return finished;
396}
397
399 ExecuteRequest& request, std::unique_ptr<Server::Job>& job) {
400 std::unique_lock<std::mutex> lock(m_pendingMutex);
401 if (m_incoming.empty()) {
403 }
404 job = std::move(m_incoming.front());
405 m_incoming.pop_front();
406
407 request = std::move(job->request);
408 if (job->timing) {
409 job->timing->taken = Clock::now();
410 }
411 lock.unlock();
412
413 m_incomingRoom.notify_one();
414
415 return Take::Job;
416}
417
419 const ExecuteRequest& request, std::string& diagnostics) const {
420 if (std::find(m_sequences.begin(), m_sequences.end(), request.sequence) ==
421 m_sequences.end()) {
422 diagnostics = "no sequence named '" + request.sequence + "'";
424 }
425
426 if (const std::vector<std::string> absent = request.eventId.missing();
427 !absent.empty()) {
428 std::ostringstream text;
429 text << "request carries no usable event identity; missing ";
430 for (size_t i = 0; i < absent.size(); ++i) {
431 text << (i == 0 ? "" : ", ") << absent[i];
432 }
433 diagnostics = text.str();
435 }
436
437 const auto declared = m_inputKeys.value().find(request.sequence);
438 std::vector<BoundaryInfo> boundaries;
439 if (declared != m_inputKeys.value().end()) {
440 for (const std::string& spec : declared->second) {
441 const auto boundary = parseBoundary(spec);
442 if (boundary.has_value()) {
443 boundaries.push_back(std::move(*boundary));
444 }
445 }
446 }
447
448 for (auto payload = request.inputs.begin(); payload != request.inputs.end();
449 ++payload) {
450 if (payload->key.empty()) {
451 diagnostics = "payload with an empty StoreGate key";
453 }
454
455 if (payload->encoding.empty()) {
456 diagnostics =
457 std::format("payload '{}' carries no encoding", payload->key);
459 }
460
461 if (std::any_of(request.inputs.begin(), payload,
462 [&payload](const Payload& earlier) {
463 return earlier.key == payload->key;
464 })) {
465 diagnostics =
466 std::format("payload '{}' is supplied more than once", payload->key);
468 }
469
470 const auto boundary =
471 std::find_if(boundaries.begin(), boundaries.end(),
472 [&payload](const BoundaryInfo& candidate) {
473 return candidate.key == payload->key;
474 });
475 if (boundary == boundaries.end()) {
476 diagnostics = std::format("sequence '{}' declares no input '{}'",
477 request.sequence, payload->key);
479 }
480
481 if (payload->encoding != boundary->encoding ||
482 payload->schema != boundary->schema) {
483 diagnostics = std::format(
484 "input '{}' arrived as {} [{}] but sequence '{}' declares {} [{}]",
485 payload->key, payload->schema, payload->encoding, request.sequence,
486 boundary->schema, boundary->encoding);
488 }
489 }
490
491 for (const BoundaryInfo& boundary : boundaries) {
492 const auto supplied = std::find_if(
493 request.inputs.begin(), request.inputs.end(),
494 [&boundary](const Payload& p) { return p.key == boundary.key; });
495 if (supplied == request.inputs.end()) {
496 diagnostics = std::format("sequence '{}' requires input '{}'",
497 request.sequence, boundary.key);
499 }
500 }
501
503}
504
506 ExecuteRequest request, std::unique_ptr<Server::Job> job) {
507 std::string diagnostics;
508 if (const AthRemoteExec::Status early = validate(request, diagnostics);
509 early != AthRemoteExec::Status::Ok) {
510 respondDirect(request, job, early, diagnostics);
511 return StatusCode::SUCCESS;
512 }
513
514 EventContext ctx = allocateEventContext(m_nextEvent);
515 if (!ctx.valid()) {
517 "could not allocate an event slot");
518 return StatusCode::SUCCESS;
519 }
520 const size_t slot = ctx.slot();
521
522 const EventId& id = request.eventId;
523 ctx.setEventID(EventIDBase(
524 *id.runNumber, static_cast<EventIDBase::event_number_t>(*id.eventNumber),
525 *id.timeStamp, id.timeStampNsOffset, *id.lumiBlock, id.bunchCrossingId));
527 Gaudi::Hive::setCurrentContext(ctx);
528 m_aess->reset(ctx);
529
530 if (m_eventStore->record(std::make_unique<EventContext>(ctx), "EventContext")
531 .isFailure() ||
532 // The payloads are moved into the descriptor: nothing downstream reads
533 // request.inputs again (InFlight keeps the request only for its id and
534 // sequence name), and copying them here was a second duplicate of the
535 // whole payload on the critical path.
537 ->record(std::make_unique<RequestDescriptor>(
538 request.sequence, request.requestId,
539 std::move(request.inputs)),
541 .isFailure()) {
542 ATH_MSG_ERROR("Could not prepare slot {} for request {}", slot,
543 request.requestId);
545 "could not prepare the event store");
546 m_whiteboard->clearStore(slot).ignore();
547 m_whiteboard->freeStore(slot).ignore();
548 return StatusCode::SUCCESS;
549 }
550
551 if (job && job->timing) {
552 job->timing->recorded = Clock::now();
553 }
554
555 InFlight entry;
556 entry.request = std::move(request);
557 entry.job = std::move(job);
558 if (m_requestTimeout > 0.0) {
559 entry.hasDeadline = true;
560 entry.deadline =
561 Clock::now() +
562 std::chrono::milliseconds(static_cast<long>(m_requestTimeout * 1000.0));
563 }
564
566 "RemoteExec request {} ({}) dispatched to slot {} as run {} lb {} event "
567 "{}",
568 entry.request.requestId, entry.request.sequence, slot, *id.runNumber,
569 *id.lumiBlock, *id.eventNumber);
570
571 const uint64_t requestId = entry.request.requestId;
572 auto [placed, inserted] = m_inFlight.emplace(slot, std::move(entry));
573 if (!inserted) {
574 ATH_MSG_FATAL("Slot {} was already in flight", slot);
575 return StatusCode::FAILURE;
576 }
577
578 if (submitEvent(ctx).isFailure()) {
579 ATH_MSG_ERROR("Could not submit request " << requestId);
580 respond(placed->second, ExecuteReply{AthRemoteExec::Status::AlgFailure,
581 "could not submit the event",
582 {},
583 requestId});
584 m_whiteboard->clearStore(slot).ignore();
585 m_whiteboard->freeStore(slot).ignore();
586 m_inFlight.erase(placed);
587 Gaudi::Hive::setCurrentContext(EventContext());
588 return StatusCode::SUCCESS;
589 }
590
591 if (placed->second.job && placed->second.job->timing) {
592 placed->second.job->timing->pushed = Clock::now();
593 }
594
595 {
596 const std::lock_guard<std::mutex> lock(m_pendingMutex);
597 ++m_awaitingCompletion;
598 }
599 m_inFlightCv.notify_one();
600
601 ++m_nextEvent;
602 Gaudi::Hive::setCurrentContext(EventContext());
603 return StatusCode::SUCCESS;
604}
605
607 if (finished.ctx == nullptr) {
608 ATH_MSG_FATAL("Scheduler returned a null context");
609 return StatusCode::FAILURE;
610 }
611 const std::unique_ptr<EventContext> ctx(finished.ctx);
612
613 const size_t slot = ctx->slot();
614 const auto entry = m_inFlight.find(slot);
615 if (entry == m_inFlight.end()) {
616 ATH_MSG_FATAL("Slot {} finished but no request was in flight on it", slot);
617 return StatusCode::FAILURE;
618 }
619
620 if (entry->second.job && entry->second.job->timing) {
621 entry->second.job->timing->finished = finished.at;
622 }
623
624 const StatusCode sc = finishEvent(*ctx);
625 if (sc.isFailure()) {
626 respond(entry->second, ExecuteReply{AthRemoteExec::Status::AlgFailure,
627 "could not finish the event",
628 {},
629 entry->second.request.requestId});
630 }
631
632 m_inFlight.erase(entry);
633 ++m_completed;
634 Gaudi::Hive::setCurrentContext(EventContext());
635 return sc;
636}
637
638StatusCode RemoteExecHiveEventLoopMgr::eventFinished(const EventContext& ctx) {
639 auto& entry = m_inFlight.at(ctx.slot());
640 respond(entry, buildReply(ctx, entry));
641
642 // An algorithm failure is a failed request, not a reason to stop serving!
643 return StatusCode::SUCCESS;
644}
645
647 const InFlight& entry) {
648 ExecuteReply reply;
649 reply.requestId = entry.request.requestId;
650
651 if (m_aess->eventStatus(ctx) != EventStatus::Success) {
652 std::ostringstream diagnostics;
653 diagnostics << "sequence '" << entry.request.sequence << "' failed ("
654 << m_aess->eventStatus(ctx) << ")";
655 const std::string failed = failedAlgorithms(ctx);
656 if (!failed.empty()) {
657 diagnostics << ": " << failed;
658 }
660 reply.diagnostics = diagnostics.str();
661 return reply;
662 }
663
664 const std::string replyKey = replyKeyFor(entry.request.sequence);
665 if (replyKey.empty()) {
666 // A fragment may legitimately return nothing at all.
668 return reply;
669 }
670
671 if (m_whiteboard->selectStore(ctx.slot()).isFailure()) {
673 reply.diagnostics =
674 "could not select the event slot to read the reply from";
675 return reply;
676 }
677
678 ReplyStaging* staged = nullptr;
679 if (m_eventStore->retrieve(staged, replyKey).isFailure() ||
680 staged == nullptr) {
682 reply.diagnostics = std::format(
683 "sequence '{}' staged no reply under '{}'; did its gate select it?",
684 entry.request.sequence, replyKey);
685 return reply;
686 }
687
688 reply = staged->takeReply();
689 reply.requestId = entry.request.requestId;
690 return reply;
691}
692
694 if (m_requestTimeout <= 0.0) {
695 return;
696 }
697
698 const Clock::time_point now = Clock::now();
699 for (auto& [slot, entry] : m_inFlight) {
700 if (entry.answered || !entry.hasDeadline || now < entry.deadline) {
701 continue;
702 }
703
705 "Request {} ({}) on slot {} exceeded {} s; answering the client now "
706 "and releasing the slot when the event finishes",
707 entry.request.requestId, entry.request.sequence, slot,
708 m_requestTimeout.value());
709 std::ostringstream diagnostics;
710 diagnostics << "the server did not finish within "
711 << m_requestTimeout.value() << " s";
712 ExecuteReply reply;
714 reply.diagnostics = diagnostics.str();
715 respond(entry, std::move(reply));
716 }
717}
718
720 if (entry.answered) {
721 return;
722 }
723 entry.answered = true;
724 reply.requestId = entry.request.requestId;
725
726 if (reply.status != AthRemoteExec::Status::Ok) {
728 "RemoteExec request {} ({}) -> {}{}", reply.requestId,
729 entry.request.sequence, toString(reply.status),
730 !reply.diagnostics.empty() ? " : " + reply.diagnostics : "");
731 } else {
732 ATH_MSG_DEBUG("RemoteExec request {} ({}) -> {}{}", reply.requestId,
733 entry.request.sequence, toString(reply.status),
734 !reply.diagnostics.empty() ? " : " + reply.diagnostics : "");
735 for (const Payload& output : reply.outputs) {
736 ATH_MSG_DEBUG(" output " << output.key << " = " << describe(output));
737 }
738 }
739
740 if (entry.job) {
741 if (entry.job->timing) {
742 entry.job->timing->replied = Clock::now();
743 }
744 entry.job->reply.set_value(std::move(reply));
745 }
746}
747
749 const ExecuteRequest& request, const std::unique_ptr<Server::Job>& job,
750 AthRemoteExec::Status status, const std::string& diagnostics) {
751 ATH_MSG_INFO("RemoteExec request {} ({}) -> {}{}", request.requestId,
752 request.sequence, toString(status),
753 !diagnostics.empty() ? " : " + diagnostics : "");
754 if (job) {
755 ExecuteReply reply;
756 reply.status = status;
757 reply.diagnostics = diagnostics;
758 reply.requestId = request.requestId;
759 job->reply.set_value(std::move(reply));
760 }
761}
762
764 const EventContext& ctx) {
765 SmartIF<IAlgManager> algMgr = serviceLocator()->as<IAlgManager>();
766 if (!algMgr) {
767 return {};
768 }
769
770 std::ostringstream names;
771 for (IAlgorithm* alg : algMgr->getAlgorithms()) {
772 if (alg == nullptr) {
773 continue;
774 }
775
776 const AlgExecStateRef state = m_aess->algExecState(alg, ctx);
777 if (state.state() == AlgExecState::State::Done &&
778 state.execStatus().isFailure()) {
779 names << (names.tellp() == 0 ? "" : ", ") << alg->name();
780 }
781 }
782
783 return names.str();
784}
785
787 const std::string& sequence) const {
788 const auto found = m_replyKeys.value().find(sequence);
789 return found == m_replyKeys.value().end() ? std::string{} : found->second;
790}
791
793 const std::string& text) {
794 std::lock_guard<std::mutex> lock(m_messageMutex);
795 msg(static_cast<MSG::Level>(level)) << "[gRPC] " << text << endmsg;
796}
797
798} // namespace AthRemoteExec
#define endmsg
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_DEBUG(x,...)
#define ATH_MSG_ERROR(x,...)
#define ATH_MSG_ALWAYS(x,...)
#define ATH_MSG_WARNING(x,...)
#define ATH_MSG_INFO(x,...)
#define ATH_MSG_FATAL(x,...)
Assign a CLID to EventContext.
virtual void lock()=0
Interface to allow an object to lock itself when made const in SG.
static Double_t sc
Multi-threaded event loop manager driven by RPC requests.
The reply, written by OutputCnvAlg onto SG.
The request, read by InputCnvAlg from SG.
StatusCode eventFinished(const EventContext &ctx) override
Process an event's result and decide whether the driving loop may continue.
std::string replyKeyFor(const std::string &sequence) const
The reply key of sequence, or an empty string if it declares none.
std::condition_variable m_pending
loop waits here
void inputLoop()
Loop and wait for incoming job.
std::map< size_t, InFlight > m_inFlight
keyed by whiteboard slot
StatusCode complete(const Finished &finished)
Read the result of one finished event and release its slot.
std::condition_variable m_incomingRoom
input thread waits here
void respond(InFlight &entry, ExecuteReply reply)
Reply to the request.
void respondDirect(const ExecuteRequest &request, const std::unique_ptr< Server::Job > &job, AthRemoteExec::Status status, const std::string &diagnostics)
Reply to the request that never got assigned to slot.
Gaudi::Property< std::map< std::string, std::vector< std::string > > > m_inputKeys
StatusCode dispatch(ExecuteRequest request, std::unique_ptr< Server::Job > job)
Give a request a slot and push it to the scheduler.
void expireDeadlines()
Reply to all request that passed their deadline.
virtual Take takeRequest(ExecuteRequest &request, std::unique_ptr< Server::Job > &job)
Take the next request from the incoming event queue.
void drainPending()
Answer to anything that the loop did not manage to finish.
virtual StatusCode startServing()
Create and start the server.
RemoteExecHiveEventLoopMgr(const std::string &name, ISvcLocator *svcLoc)
Gaudi::Property< std::map< std::string, std::vector< std::string > > > m_outputKeys
std::condition_variable m_inFlightCv
output thread waits here
virtual StatusCode initialize() override
implementation of IAppMgrUI::initalize
std::deque< std::unique_ptr< Server::Job > > m_incoming
ExecuteReply buildReply(const EventContext &ctx, const InFlight &entry)
Turn a finished event into the reply for its request.
AthRemoteExec::Status validate(const ExecuteRequest &request, std::string &diagnostics) const
Reject requests that cannot possibly run, before a slot is spent on them.
virtual StatusCode stopRun() override
Ask the loop to stop accepting work and drain what is in flight.
std::vector< Finished > takeFinished()
Take whatever the output thread has collected from finished event queue.
void outputLoop()
Loop and wait for finished job.
Gaudi::Property< std::vector< std::string > > m_sequences
virtual StatusCode finalize() override
implementation of IAppMgrUI::finalize
void serverMessage(Server::Level level, const std::string &text)
Thread-safe log sink handed to the RPC server.
Gaudi::Property< std::map< std::string, std::string > > m_replyKeys
virtual StatusCode nextEvent(int maxevt) override
Serve requests.
std::string failedAlgorithms(const EventContext &ctx)
Names of the algorithms that failed in ctx. For the reply diagnostics.
ExecuteReply takeReply()
Hand the reply over, leaving this object empty.
Level
Severity levels, matching MSG::Level so the funnel can forward them.
Definition Server.h:42
virtual StatusCode initialize() override
implementation of IAppMgrUI::initalize
SmartIF< IHiveWhiteBoard > m_whiteboard
Reference to the Whiteboard interface.
SmartIF< IAlgExecStateSvc > m_aess
Reference to the Algorithm Execution State Svc.
virtual const std::string & name() const override
std::string m_schedulerName
Name of the scheduler to be used.
EventContext allocateEventContext(size_t eventNumber)
StatusCode submitEvent(EventContext &ctx)
Submit a recorded context; the scheduler receives its own copy.
StoreGateSvc_t m_eventStore
Reference to StoreGateSvc;.
AthenaHiveEventLoopMgr(const std::string &nam, ISvcLocator *svcLoc)
Standard Constructor.
virtual StatusCode finalize() override
implementation of IAppMgrUI::finalize
bool m_scheduledStop
Scheduled stop of event processing.
StatusCode finishEvent(const EventContext &ctx)
Finish one scheduler-returned event on the driving thread.
SmartIF< IScheduler > m_schedulerSvc
A shortcut for the scheduler.
void setConditionsRun(EventIDBase::number_type conditionsRun)
make the sidebar many part of the config
Definition hcg.cxx:554
std::optional< BoundaryInfo > parseBoundary(std::string_view spec)
Parse "key#encoding#schema" into BoundaryInfo.
Definition Protocol.h:155
constexpr std::string_view toString(Status status)
String representation of Status enum.
Definition Protocol.h:49
std::string describe(const Payload &payload)
Human-readable rendering of a payload, for log messages.
Definition Protocol.h:80
Status
RPC reply status.
Definition Protocol.h:32
const ExtendedEventContext & getExtendedEventContext(const EventContext &ctx)
Retrieve an extended context from a context object.
Information what kind of data is expected, in which RPC protocol, and the meaning of the data.
Definition Protocol.h:147
An unique event identifier.
Definition Protocol.h:104
std::vector< std::string > missing() const
Names of the required fields that are missing.
Definition Protocol.h:113
std::vector< Payload > outputs
Definition Protocol.h:141
std::string sequence
fragment name, e.g. "RemoteExecSeqSum"
Definition Protocol.h:132
uint64_t requestId
client correlation id, echoed back
Definition Protocol.h:134
std::vector< Payload > inputs
Definition Protocol.h:133
The actual data that is sent via RPC.
Definition Protocol.h:72
A finished event, from the scheduler's point of view.
A request that has been given a slot and handed to the scheduler.
Information about what sequence the server is capable of executing.
Definition Protocol.h:171
MsgStream & msg
Definition testRead.cxx:32