ATLAS Offline Software
Loading...
Searching...
No Matches
AtlasG4SyncEventUserInfo.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
5#ifndef G4RUNMANAGEMENT_AtlasG4SyncEventUserInfo_H
6#define G4RUNMANAGEMENT_AtlasG4SyncEventUserInfo_H
7
8#include <functional>
9#include <memory>
10#include <mutex>
11#include <condition_variable>
12
13#include "GaudiKernel/EventContext.h"
14
17
18// Forward declaration
19namespace CLHEP{
20 class HepRandomEngine;
21}
22
23class G4Event;
24
25// Synchronization variables stored in a separate structure
26// to allow access from Athena thread after G4EventInfo are destroyed
28{
29 enum class EventStatus {
33 };
34 public:
35 EventStatus Status() const;
37 void Complete(bool eventAborted);
39 bool EventAborted() const {
40 std::scoped_lock lk(m_mutex);
41 return m_event_aborted;
42 }
43
44 private:
45 void WaitStatus(const EventStatus&);
46
47 bool m_event_aborted{false};
49 mutable std::mutex m_mutex;
50 std::condition_variable m_cv;
51};
52
53// Extension of AtlasG4EventUserInfo to store Athena-G4 interface data necessary for synchronized event processing
55{
56 public:
57 using EventFactoryFunction = std::function<StatusCode(G4Event&, std::unique_ptr<AtlasG4SyncEventUserInfo>)>;
58 using SPSyncInterface = std::shared_ptr<G4EventSynchronizationInterface>;
59
60 AtlasG4SyncEventUserInfo(CLHEP::HepRandomEngine*, EventFactoryFunction&&, const EventContext&);
61
63 return GetEventContext().eventID().event_number();
64 }
65
66 CLHEP::HepRandomEngine* HepRandomEngine() {
67 return m_rng_engine;
68 }
69
73
77
78 private:
79 // Random engine for this event seeded by Athena
80 CLHEP::HepRandomEngine* m_rng_engine{nullptr};
81 // Factory function for Athena to prepare the G4 event
83 // Synchronization interface between Athena and Geant4 for this event
84 // held in a shared pointer to allow access from Athena after G4Event is destroyed
86};
87
88#endif// G4RUNMANAGEMENT_AtlasG4SyncEventUserInfo_H
EventIDBase::event_number_t event_number_t
AtlasG4EventUserInfo(const EventContext &ctx)
const EventContext & GetEventContext() const
std::function< StatusCode(G4Event &, std::unique_ptr< AtlasG4SyncEventUserInfo >)> EventFactoryFunction
AtlasG4SyncEventUserInfo(CLHEP::HepRandomEngine *, EventFactoryFunction &&, const EventContext &)
SPSyncInterface SyncInterface() const
event_number_t AthenaEventID() const
std::shared_ptr< G4EventSynchronizationInterface > SPSyncInterface
EventFactoryFunction EventFactory() const
EventFactoryFunction m_event_factory
CLHEP::HepRandomEngine * m_rng_engine
CLHEP::HepRandomEngine * HepRandomEngine()
void Complete(bool eventAborted)
Mark all Geant4 processing for this event as complete and wake Athena.