Belle II Software development
MeasurementCreatorFactory.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#pragma once
9
10#include <framework/logging/Logger.h>
11
12#include <map>
13#include <vector>
14#include <memory>
15
16namespace Belle2 {
31 template <class BaseMeasurementCreatorType>
33 public:
35 typedef BaseMeasurementCreatorType CreatorType;
36
39 {
40 for (const auto& creatorWithParameterDictionary : m_creatorsWithParametersDictionary) {
41 const std::string& creatorName = creatorWithParameterDictionary.first;
42 const std::map<std::string, std::string>& parameterDictionary = creatorWithParameterDictionary.second;
43
44 B2DEBUG(100, "Creating measurement creator with name " << creatorName);
45
46 BaseMeasurementCreatorType* creatorPointer = createMeasurementCreatorFromName(creatorName);
47 if (creatorPointer == nullptr) {
48 B2FATAL("Can not create a measurement creator with the name " << creatorName << ". Creator not known to the factory.");
49 }
50 m_measurementCreators.push_back(std::move(std::shared_ptr<BaseMeasurementCreatorType>(creatorPointer)));
51
52 for (const auto& parameterWithValue : parameterDictionary) {
53 const std::string& parameterName = parameterWithValue.first;
54 const std::string& parameterValue = parameterWithValue.second;
55 creatorPointer->setParameter(parameterName, parameterValue);
56 }
57 }
58 }
59
61 virtual BaseMeasurementCreatorType* createMeasurementCreatorFromName(const std::string& /*creatorName*/) const
62 {
63 return nullptr;
64 }
65
67 const std::vector<std::shared_ptr<BaseMeasurementCreatorType>>& getCreators() const
68 {
70 }
71
73 std::map<std::string, std::map<std::string, std::string>>& getParameters()
74 {
76 }
77
79 void setParameters(const std::map<std::string, std::map<std::string, std::string>>& creatorsWithParametersDictionary)
80 {
81 m_creatorsWithParametersDictionary = std::move(creatorsWithParametersDictionary);
82 }
83
84 private:
86 std::vector<std::shared_ptr<BaseMeasurementCreatorType>> m_measurementCreators;
87
89 std::map<std::string, std::map<std::string, std::string>> m_creatorsWithParametersDictionary;
90 };
92}
This is the base class for all MeasurementCreatorFactories used in the MeasurementCreatorModule.
void initialize()
Use the parameters given to the module and create the measurement creators from them.
virtual BaseMeasurementCreatorType * createMeasurementCreatorFromName(const std::string &) const
Overload this method to create the measurement creators by their name.
std::map< std::string, std::map< std::string, std::string > > & getParameters()
Return a reference to the parameters you can use in the module.
BaseMeasurementCreatorType CreatorType
Typedef for convenience.
std::map< std::string, std::map< std::string, std::string > > m_creatorsWithParametersDictionary
The map of dictionaries of the parameters.
std::vector< std::shared_ptr< BaseMeasurementCreatorType > > m_measurementCreators
A vector with the measurement creators.
const std::vector< std::shared_ptr< BaseMeasurementCreatorType > > & getCreators() const
Return the creators to the module.
void setParameters(const std::map< std::string, std::map< std::string, std::string > > &creatorsWithParametersDictionary)
Set the parameters.
Abstract base class for different kinds of events.