ATLAS Offline Software
Loading...
Searching...
No Matches
StateHandler.h
Go to the documentation of this file.
1//
2// Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3//
4// Dear emacs, this is -*- c++ -*-
5//
6
7#ifndef ATHXRTINTERFACES_STATEHANDLER_H
8#define ATHXRTINTERFACES_STATEHANDLER_H
9
10#include "GaudiKernel/IIncidentListener.h"
11#include "GaudiKernel/IIncidentSvc.h"
12#include "GaudiKernel/ConcurrencyFlags.h"
13#include "GaudiKernel/ServiceHandle.h"
14
17
18
19namespace AthXRT {
25
26class StateHandler : virtual public ::IIncidentListener
27{
28 protected:
29
31 virtual StatusCode initialize_global()
32 {
33 return StatusCode::SUCCESS;
34 }
35
37 virtual StatusCode initialize_worker()
38 {
39 return StatusCode::SUCCESS;
40 }
41
43 virtual StatusCode stop_worker()
44 {
45 return StatusCode::SUCCESS;
46 }
47
48 virtual StatusCode initialize()
49 {
51
52 const bool is_multiprocess = (Gaudi::Concurrency::ConcurrencyFlags::numProcs() > 0);
53
54 if (is_multiprocess)
55 {
56 ServiceHandle<IIncidentSvc> incidentSvc("IncidentSvc","StateHandler");
57 incidentSvc->addListener(this, AthenaInterprocess::UpdateAfterFork::type());
58 }
59 else
60 {
62 }
63
64 return StatusCode::SUCCESS;
65 }
66
67 virtual StatusCode stop() {
68 const bool is_multiprocess = (Gaudi::Concurrency::ConcurrencyFlags::numProcs() > 0);
69
70 if (!is_multiprocess) {
71 ATH_CHECK(this->stop_worker());
72 } else {
73 if (m_is_child){
74 ATH_CHECK(this->stop_worker());
75 }
76 }
77
78 return StatusCode::SUCCESS;
79 }
80
81 bool m_is_child = false;
82
83 public:
84
85 void handle(const Incident & incident) override
86 {
87 const bool is_multiprocess = (Gaudi::Concurrency::ConcurrencyFlags::numProcs() > 0);
88 if (is_multiprocess && incident.type() == AthenaInterprocess::UpdateAfterFork::type())
89 {
90 m_is_child = true;
91 if (!this->initialize_worker().isSuccess())
92 {
93 throw GaudiException("Failed to initialize the XRT setup!",
94 "StateHandler::handle",
95 StatusCode::FAILURE);
96 }
97 }
98 }
99
100 virtual ~StateHandler() = default;
101
102};
103
104} // namespace AthXRT
105
106#endif //ATHXRTCORE_STATEHANDLER_H
#define ATH_CHECK
Evaluate an expression and check for errors.
Base class to provide common infrastructure for handling multiprocess state transitions for FPGA.
virtual StatusCode initialize()
void handle(const Incident &incident) override
virtual StatusCode initialize_worker()
Initialization per process.
virtual StatusCode stop_worker()
clean up
virtual StatusCode stop()
virtual StatusCode initialize_global()
Glocal XRT initialization.
virtual ~StateHandler()=default
static const std::string & type()
Incident type.
Definition Incidents.h:49