ATLAS Offline Software
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 
19 namespace AthXRT {
26 class StateHandler : virtual public ::IIncidentListener
27 {
28  protected:
29 
32  {
33  return StatusCode::SUCCESS;
34  }
35 
38  {
39  return StatusCode::SUCCESS;
40  }
41 
44  {
45  return StatusCode::SUCCESS;
46  }
47 
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
AthXRT::StateHandler::~StateHandler
virtual ~StateHandler()=default
AthCheckMacros.h
AthXRT::StateHandler::stop
virtual StatusCode stop()
Definition: StateHandler.h:67
AthXRT::StateHandler::initialize_global
virtual StatusCode initialize_global()
Glocal XRT initialization.
Definition: StateHandler.h:31
AthXRT::StateHandler::stop_worker
virtual StatusCode stop_worker()
clean up
Definition: StateHandler.h:43
AthXRT::StateHandler::m_is_child
bool m_is_child
Definition: StateHandler.h:81
AthXRT::StateHandler
Base class to provide common infrastructure for handling multiprocess state transitions for FPGA....
Definition: StateHandler.h:27
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
Incidents.h
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
AthXRT::StateHandler::initialize_worker
virtual StatusCode initialize_worker()
Initialization per process.
Definition: StateHandler.h:37
AthXRT::StateHandler::initialize
virtual StatusCode initialize()
Definition: StateHandler.h:48
AthenaInterprocess::UpdateAfterFork::type
static const std::string & type()
Incident type.
Definition: Incidents.h:49
AthXRT::StateHandler::handle
void handle(const Incident &incident) override
Definition: StateHandler.h:85
AthXRT
Definition: IDeviceMgmtSvc.h:30
ServiceHandle< IIncidentSvc >