ATLAS Offline Software
Loading...
Searching...
No Matches
TestActionTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3*/
4
5// Main header include
6#include "TestActionTool.h"
7
8// Geant4 includes
9#include "G4ios.hh"
10
11namespace G4UA
12{
13
14 //---------------------------------------------------------------------------
15 // TestAction constructor
16 //---------------------------------------------------------------------------
19
20 //---------------------------------------------------------------------------
21 // Begin of G4 run method
22 //---------------------------------------------------------------------------
24 {
25 G4cout << "TestAction::BeginOfRunAction" << G4endl;
26 }
27
28 //---------------------------------------------------------------------------
29 // End of G4 run method
30 //---------------------------------------------------------------------------
31 void TestAction::EndOfRunAction(const G4Run*)
32 {
33 G4cout << "TestAction::EndOfRunAction - "
34 << m_report.numEvent << " events processed, "
35 << m_report.numStep << " steps processed"
36 << G4endl;
37 }
38
39 //---------------------------------------------------------------------------
40 // Begin of G4 event method
41 //---------------------------------------------------------------------------
42 void TestAction::BeginOfEventAction(const G4Event*)
43 {
44 G4cout << "TestAction::BeginOfEventAction" << G4endl;
45 m_report.numEvent++;
46 }
47
48 //---------------------------------------------------------------------------
49 // End of G4 event method
50 //---------------------------------------------------------------------------
51 void TestAction::EndOfEventAction(const G4Event*)
52 {
53 G4cout << "TestAction::EndOfEventAction" << G4endl;
54 }
55
56 //---------------------------------------------------------------------------
57 // G4 stepping method
58 //---------------------------------------------------------------------------
60 {
61 m_report.numStep++;
62 }
63
64 //---------------------------------------------------------------------------
65 // Constructor
66 //---------------------------------------------------------------------------
68 const std::string& name,
69 const IInterface* parent)
70 : UserActionToolBase<TestAction>(type, name, parent)
71 {
72 }
73
74 //---------------------------------------------------------------------------
75 // Initialize the tool
76 //---------------------------------------------------------------------------
78 {
79 ATH_MSG_INFO( "Initializing " << name() );
80 return StatusCode::SUCCESS;
81 }
82
83 //---------------------------------------------------------------------------
84 // Finalize the tool
85 //---------------------------------------------------------------------------
87 {
88 ATH_MSG_INFO( "Finalizing " << name() );
89
90 // Accumulate results across threads
91 TestAction::Report results;
92 m_actions.accumulate(results, &TestAction::getReport,
94 ATH_MSG_INFO("Final accumulated results: " <<
95 results.numEvent << " events processed, " <<
96 results.numStep << " steps processed");
97
98 return StatusCode::SUCCESS;
99 }
100
101 //---------------------------------------------------------------------------
102 // Construct and fill the user action
103 //---------------------------------------------------------------------------
104 std::unique_ptr<TestAction>
106 {
107 ATH_MSG_INFO("Constructing and filling a TestAction");
108
109 auto action = std::make_unique<TestAction>();
110 actions.runActions.push_back( action.get() );
111 actions.eventActions.push_back( action.get() );
112 actions.steppingActions.push_back( action.get() );
113 return action;
114 }
115
116} // namespace G4UA
#define ATH_MSG_INFO(x)
virtual StatusCode initialize() override final
Initialize the tool.
TestActionTool(const std::string &type, const std::string &name, const IInterface *parent)
Standard constructor.
virtual StatusCode finalize() override final
Finalize the tool.
virtual std::unique_ptr< TestAction > makeAndFillAction(G4AtlasUserActions &actions) override final
Fill user action.
const Report & getReport() const
Get the results report.
virtual void BeginOfRunAction(const G4Run *) override final
Executes before the run.
virtual void EndOfEventAction(const G4Event *) override final
Executes at end of G4 event.
TestAction()
Constructor.
virtual void UserSteppingAction(const G4Step *step) override final
Stepping action method.
virtual void EndOfRunAction(const G4Run *) override final
Exeuctes after the run.
virtual void BeginOfEventAction(const G4Event *) override final
Executes at beginning of G4 event.
Report m_report
Results report.
ThreadSpecificUserAction< TestAction > m_actions
UserActionToolBase(const std::string &type, const std::string &name, const IInterface *parent)
Struct for passing around user actions.
std::vector< G4UserSteppingAction * > steppingActions
std::vector< G4UserEventAction * > eventActions
std::vector< G4UserRunAction * > runActions
Results to be accumulated across threads at end of job.
void merge(const Report &other)