ATLAS Offline Software
Loading...
Searching...
No Matches
ActionToolBase.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3*/
4
5#ifndef G4ATLASTOOLS__G4UA__ACTIONTOOLBASE_H
6#define G4ATLASTOOLS__G4UA__ACTIONTOOLBASE_H
7
8// System includes
9#include <memory>
10
11// Framework includes
13
14// Local includes
15#include "ThreadActionHolder.h"
16
17namespace G4UA
18{
19
33 template <class ActionType>
35 {
36
37 public:
38
40 ActionToolBase(const std::string& type, const std::string& name,
41 const IInterface* parent)
42 : AthAlgTool(type, name, parent)
43 {}
44
48 ActionType* getAction()
49 {
50 ActionType* action = m_actions.get();
51 if(!action){
52 auto uniqueAction = makeAction();
53 action = uniqueAction.get();
54 m_actions.set( std::move(uniqueAction) );
55 }
56 return action;
57 }
58
59 protected:
60
63 virtual std::unique_ptr<ActionType> makeAction() = 0;
64
68
69 private:
70
73
74 }; // class ActionToolBase
75
76
86 template <class ActionType>
87 class ActionToolBaseReport : public ActionToolBase<ActionType>
88 {
89
90 public:
91
93 ActionToolBaseReport(const std::string& type, const std::string& name,
94 const IInterface* parent)
95 : ActionToolBase<ActionType>(type, name, parent)
96 {}
97
98 protected:
99
104 for(auto tidAction : this->actions()) {
105 auto& rep = tidAction.second->getReport();
106 m_report.merge(rep);
107 }
108 }
109
111 typename ActionType::Report m_report;
112
113 }; // class ActionToolBaseReport
114
115} // namespace G4UA
116
117#endif
AthAlgTool(const std::string &type, const std::string &name, const IInterface *parent)
Constructor with parameters:
ActionType::Report m_report
This type must be defined in the concrete tool subclass.
ActionToolBaseReport(const std::string &type, const std::string &name, const IInterface *parent)
Standard constructor.
void mergeReports()
Loop over per-thread actions and merge the results.
ThreadActionHolder< ActionType > m_actions
Thread-local storage of my user actions.
virtual std::unique_ptr< ActionType > makeAction()=0
Abstract method to create a custom action on demand.
ActionToolBase(const std::string &type, const std::string &name, const IInterface *parent)
Standard constructor.
const ThreadActionHolder< ActionType > & actions()
Retrieve const-ref to the action holder.
ActionType * getAction()
Helper method for retrieving an action interface.
A thread-local storage wrapper for the user actions.