ConfigManager.hpp 4.82 KB
Newer Older
1
2
/**
 * @file
3
 * @brief Interface to the main configuration and its normal and special sections
4
 * @copyright Copyright (c) 2017 CERN and the Corryvreckan authors.
5
6
 * This software is distributed under the terms of the MIT License, copied verbatim in the file "LICENSE.md".
 * In applying this license, CERN does not waive the privileges and immunities granted to it by virtue of its status as an
7
8
9
10
11
12
13
14
15
16
17
18
 * Intergovernmental Organization or submit itself to any jurisdiction.
 */

#ifndef CORRYVRECKAN_CONFIG_MANAGER_H
#define CORRYVRECKAN_CONFIG_MANAGER_H

#include <set>
#include <string>
#include <vector>

#include "ConfigReader.hpp"
#include "Configuration.hpp"
19
20
#include "OptionParser.hpp"
#include "core/module/ModuleIdentifier.hpp"
21
22
23
24
25

namespace corryvreckan {

    /**
     * @ingroup Managers
26
     * @brief Manager responsible for loading and providing access to the main configuration
27
     *
28
29
     * The main configuration is the single most important source of configuration. It is split up in:
     * - Global headers that are combined into a single global (not module specific) configuration
30
     * - Ignored headers that are not used at all (mainly useful for debugging)
31
     * - All other headers representing all modules that have to be instantiated by the ModuleManager
32
33
34
35
36
37
38
39
     *
     * Configuration sections are always case-sensitive.
     */
    class ConfigManager {
    public:
        /**
         * @brief Construct the configuration manager
         * @param file_name Path to the main configuration file
40
41
         * @param global List of sections representing the global configuration (excluding the empty header section)
         * @param ignore List of sections that should be ignored
42
         */
43
44
45
        explicit ConfigManager(std::string file_name,
                               std::initializer_list<std::string> global = {},
                               std::initializer_list<std::string> ignore = {"Ignore"});
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
        /**
         * @brief Use default destructor
         */
        ~ConfigManager() = default;

        /// @{
        /**
         * @brief Copying the manager is not allowed
         */
        ConfigManager(const ConfigManager&) = delete;
        ConfigManager& operator=(const ConfigManager&) = delete;
        /// @}

        /// @{
        /**
         * @brief Use default move behaviour
         */
        ConfigManager(ConfigManager&&) noexcept = default;
        ConfigManager& operator=(ConfigManager&&) noexcept = default;
        /// @}

        /**
68
69
         * @brief Get the global configuration
         * @return Reference to global configuration
70
         */
71
        Configuration& getGlobalConfiguration();
72
        /**
73
74
         * @brief Get all the module configurations
         * @return Reference to list of module configurations
75
         */
76
        std::list<Configuration>& getModuleConfigurations();
77
78

        /**
79
80
81
82
         * @brief Add a new module instance configuration and applies instance options
         * @param identifier Identifier for this module instance
         * @param config Instance configuration to store
         * @return Reference to stored instance configuration
83
         */
84
        Configuration& addInstanceConfiguration(const ModuleIdentifier& identifier, const Configuration& config);
85
        /**
86
87
         * @brief Get all the instance configurations
         * @return Reference to list of instance configurations
88
         */
89
        std::list<Configuration>& getInstanceConfigurations();
90

91
        /**
92
93
94
95
96
         * @brief Load module options and directly apply them to the global configuration and the module configurations
         * @param options List of options to load and apply
         * @return True if any actual options where applied
         *
         * @note Instance configuration options are applied in \ref ConfigManager::addInstanceConfiguration instead
97
         */
98
        bool loadModuleOptions(const std::vector<std::string>& options);
99
        /**
100
101
         * @brief Get all the detector configurations
         * @return Reference to list of detector configurations
102
         */
103
        std::list<Configuration>& getDetectorConfigurations();
104

105
        /**
106
107
108
         * @brief Load detector specific options
         * @param options List of options to load and apply
         * @return True if any actual options where applied
109
         */
110
        bool loadDetectorOptions(const std::vector<std::string>& options);
111
112

    private:
113
114
        std::set<std::string> global_names_{};
        std::set<std::string> ignore_names_{};
115

116
        OptionParser module_option_parser_;
117

118
119
        std::list<Configuration> module_configs_;
        Configuration global_config_;
120

121
        std::list<Configuration> detector_configs_;
122

123
124
        std::list<Configuration> instance_configs_;
        std::map<std::string, std::list<Configuration>::iterator> instance_name_to_config_;
125
126
127
128
    };
} // namespace corryvreckan

#endif /* CORRYVRECKAN_CONFIG_MANAGER_H */