Belle II Software  release-08-01-10
GeneratorBaseModule.h
1 /**************************************************************************
2  * basf2 (Belle II Analysis Software Framework) *
3  * Author: The Belle II Collaboration *
4  * *
5  * See git log for contributors and copyright holders. *
6  * This file is licensed under LGPL-3.0, see LICENSE.md. *
7  **************************************************************************/
8 
9 #pragma once
10 
11 #include <framework/core/Module.h>
12 #include <framework/dataobjects/EventExtraInfo.h>
13 #include <framework/datastore/StoreObjPtr.h>
14 #include <framework/gearbox/Const.h>
15 
16 #include <string>
17 #include <unordered_map>
18 
19 namespace Belle2 {
25  class Module;
26 
29  class GeneratorBaseModule : public Module {
30  public:
35  {
36  //Generator common parameters
37  addParam("eventType", m_eventType, "Event type", std::string(""));
38  };
39 
41  void initialize() override
42  {
43  m_eventExtraInfo.registerInDataStore();
44 
46  };
47 
49  virtual void generatorInitialize() = 0;
50 
52  void event() override
53  {
55 
56  if (not m_eventExtraInfo.isValid())
57  m_eventExtraInfo.create();
58 
59  m_eventExtraInfo->addEventTypeIfNotSet(getEventType());
60 
61  for (auto [name, val] : m_generatorInfoMap)
62  m_eventExtraInfo->addExtraInfo(name, val);
63  };
64 
66  virtual void generatorEvent() = 0;
67 
69  void setGeneratorInfoMap(std::unordered_map<std::string, double> generatorInfoMap)
70  {
71  m_generatorInfoMap = generatorInfoMap;
72  };
73 
75  virtual std::string getEventType() const
76  {
77  return m_eventType;
78  }
79 
80  protected:
83 
85  std::string m_eventType;
87  std::unordered_map<std::string, double> m_generatorInfoMap = {};
88 
89  };
90 
92 } // end namespace Belle2
93 
The base module for generator modules, which sets the generator information as EventExtraInfo.
void initialize() override
Initialize the module.
void setGeneratorInfoMap(std::unordered_map< std::string, double > generatorInfoMap)
Set the generator information
void event() override
Method is called for each event.
std::unordered_map< std::string, double > m_generatorInfoMap
Generator information to be set as extraInfo.
virtual void generatorInitialize()=0
Initialize the module.
virtual std::string getEventType() const
Return m_eventType.
std::string m_eventType
Event type.
StoreObjPtr< EventExtraInfo > m_eventExtraInfo
pointer to EventExtraInfo
virtual void generatorEvent()=0
Method is called for each event.
Base class for Modules.
Definition: Module.h:72
Type-safe access to single objects in the data store.
Definition: StoreObjPtr.h:96
void addParam(const std::string &name, T &paramVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
Definition: Module.h:560
Abstract base class for different kinds of events.