Belle II Software development
V0VertexFitterFactory.cc
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#include <tracking/v0Finding/fitter/V0VertexFitterFactory.h>
9
10#include <tracking/v0Finding/fitter/KFitV0VertexFitter.h>
11#include <tracking/v0Finding/fitter/RaveV0VertexFitter.h>
12
13#include <framework/logging/Logger.h>
14
15#include <functional>
16#include <map>
17
18using namespace Belle2;
19
20namespace {
21
23 typedef std::function<std::unique_ptr<V0VertexFitter>()> CreatorFunction;
24
26 const std::map<std::string, CreatorFunction>& getRegistry()
27 {
28 static const std::map<std::string, CreatorFunction> registry = {
29 {"KFit", []() -> std::unique_ptr<V0VertexFitter> {return std::make_unique<KFitV0VertexFitter>();}},
30 {"Rave", []() -> std::unique_ptr<V0VertexFitter> {return std::make_unique<RaveV0VertexFitter>();}},
31 };
32 return registry;
33 }
34
35}
36
37std::unique_ptr<V0VertexFitter> V0VertexFitterFactory::create(const std::string& name)
38{
39 const auto& registry = getRegistry();
40 const auto iterator = registry.find(name);
41 if (iterator == registry.end()) {
42 B2FATAL("Unknown V0 vertex fitter requested."
43 << LogVar("requested fitter", name)
44 << LogVar("available fitters", getNamesAsString()));
45 }
46 return iterator->second();
47}
48
49std::vector<std::string> V0VertexFitterFactory::getNames()
50{
51 std::vector<std::string> names;
52 for (const auto& entry : getRegistry()) names.push_back(entry.first);
53 return names;
54}
55
57{
58 std::string names;
59 for (const auto& name : getNames()) {
60 if (not names.empty()) names += ", ";
61 names += name;
62 }
63 return names;
64}
static std::string getNamesAsString()
Get the names of all the registered fitters as a single string, for messages and parameter descriptio...
static std::vector< std::string > getNames()
Get the names of all the registered fitters.
static std::unique_ptr< V0VertexFitter > create(const std::string &name)
Create the fitter registered under the given name.
Class to store variables with their name which were sent to the logging service.
Abstract base class for different kinds of events.