ATLAS Offline Software
UserProcessFactory.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #ifndef GENERATOR_PYTHIA8_USER_PROCESS_FACTORY_H
6 #define GENERATOR_PYTHIA8_USER_PROCESS_FACTORY_H
7 
8 #include "Pythia8/SigmaProcess.h"
9 
10 
11 #include <map>
12 #include <string>
13 
15 
16  using Pythia8::Sigma2Process;
17 
18 
20 
21  public:
22 
23  static std::shared_ptr<Sigma2Process> create(const std::string &procName);
24 
25  private:
26 
28 
29  class ICreator{
30  public:
31  virtual std::shared_ptr<Sigma2Process> create() const = 0;
32  virtual ~ICreator(){};
33  };
34 
35  public:
36 
37  template <class T>
38  class Creator: public ICreator{
39 
40  public:
41  Creator(const std::string &name) :
42  m_name(name){
44  }
45 
47  if(s_creators()[m_name] == this){
48  s_creators().erase(m_name);
49  }
50  }
51 
52  std::shared_ptr<Sigma2Process> create()const{
53  return std::make_shared<T>();
54  }
55 
56  private:
57 
58  std::string m_name;
59 
60  };
61 
62  private:
63  static std::map<std::string, const ICreator*> &s_creators();
64 
65  };
66 }
67 #endif
Pythia8_UserProcess::UserProcessFactory::Creator::create
std::shared_ptr< Sigma2Process > create() const
Definition: UserProcessFactory.h:52
Pythia8_UserProcess::UserProcessFactory::Creator::m_name
std::string m_name
Definition: UserProcessFactory.h:58
Pythia8_UserProcess::UserProcessFactory::s_creators
static std::map< std::string, const ICreator * > & s_creators()
static function to instantiate map of string name Vs. creator object on first use
Definition: UserProcessFactory.cxx:22
Pythia8_UserProcess::UserProcessFactory::UserProcessFactory
UserProcessFactory()
Definition: UserProcessFactory.h:27
Pythia8_UserProcess::UserProcessFactory::ICreator::create
virtual std::shared_ptr< Sigma2Process > create() const =0
Pythia8_UserProcess::UserProcessFactory::create
static std::shared_ptr< Sigma2Process > create(const std::string &procName)
Definition: UserProcessFactory.cxx:11
Pythia8_UserProcess::UserProcessFactory::ICreator
Definition: UserProcessFactory.h:29
Pythia8_UserProcess::UserProcessFactory::Creator
Definition: UserProcessFactory.h:38
Pythia8_UserProcess::UserProcessFactory::ICreator::~ICreator
virtual ~ICreator()
Definition: UserProcessFactory.h:32
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
Pythia8_UserProcess::UserProcessFactory::Creator::Creator
Creator(const std::string &name)
Definition: UserProcessFactory.h:41
Pythia8_UserProcess::UserProcessFactory
Definition: UserProcessFactory.h:19
Pythia8_UserProcess::UserProcessFactory::Creator::~Creator
~Creator()
Definition: UserProcessFactory.h:46
Pythia8_UserProcess
Definition: UserProcessFactory.h:14