ATLAS Offline Software
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 
17 namespace G4UA
18 {
19 
33  template <class ActionType>
34  class ActionToolBase : public AthAlgTool
35  {
36 
37  public:
38 
40  ActionToolBase(const std::string& type, const std::string& name,
41  const IInterface* 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 
67  { return m_actions; }
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 
103  void mergeReports(){
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
G4UA::ActionToolBaseReport::m_report
ActionType::Report m_report
This type must be defined in the concrete tool subclass.
Definition: ActionToolBase.h:111
G4UA::ActionToolBase::getAction
ActionType * getAction()
Helper method for retrieving an action interface.
Definition: ActionToolBase.h:48
G4UA::ActionToolBase::m_actions
ThreadActionHolder< ActionType > m_actions
Thread-local storage of my user actions.
Definition: ActionToolBase.h:72
G4UA
for nSW
Definition: CalibrationDefaultProcessing.h:19
make_hlt_rep.rep
rep
Definition: make_hlt_rep.py:32
G4UA::ActionToolBaseReport::mergeReports
void mergeReports()
Loop over per-thread actions and merge the results.
Definition: ActionToolBase.h:103
ThreadActionHolder.h
G4UA::ActionToolBase
abstract template utility base-class for G4 user-action tools.
Definition: ActionToolBase.h:35
G4UA::ActionToolBaseReport::ActionToolBaseReport
ActionToolBaseReport(const std::string &type, const std::string &name, const IInterface *parent)
Standard constructor.
Definition: ActionToolBase.h:93
G4UA::ActionToolBase::makeAction
virtual std::unique_ptr< ActionType > makeAction()=0
Abstract method to create a custom action on demand.
AthAlgTool.h
test_pyathena.parent
parent
Definition: test_pyathena.py:15
G4UA::ThreadActionHolder
A thread-local storage wrapper for the user actions.
Definition: ThreadActionHolder.h:31
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:192
G4UA::ActionToolBaseReport
Specialized action tool base class for tools that must merge results across all threads.
Definition: ActionToolBase.h:88
python.CaloScaleNoiseConfig.action
action
Definition: CaloScaleNoiseConfig.py:77
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
G4UA::ActionToolBase::ActionToolBase
ActionToolBase(const std::string &type, const std::string &name, const IInterface *parent)
Standard constructor.
Definition: ActionToolBase.h:40
AthAlgTool
Definition: AthAlgTool.h:26
G4UA::ActionToolBase::actions
const ThreadActionHolder< ActionType > & actions()
Retrieve const-ref to the action holder.
Definition: ActionToolBase.h:66