Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Corryvreckan
Corryvreckan
Commits
f3d45219
Commit
f3d45219
authored
Dec 13, 2018
by
Simon Spannagel
Browse files
Core: update configuration, currently only a "hotfix"
Need to also update the manager and how we interface it.
parent
645335d4
Changes
4
Hide whitespace changes
Inline
Side-by-side
src/core/config/ConfigManager.cpp
View file @
f3d45219
...
...
@@ -37,7 +37,8 @@ ConfigManager::ConfigManager(std::string file_name) : file_name_(std::move(file_
file_name_
=
corryvreckan
::
get_canonical_path
(
file_name_
);
// Initialize global base configuration with absolute file name
global_base_config_
=
Configuration
(
""
,
file_name_
);
// FIXME do not hard-code name!
global_base_config_
=
Configuration
(
"Corryvreckan"
,
file_name_
);
// Read the file
reader_
.
add
(
file
,
file_name_
);
...
...
@@ -62,7 +63,8 @@ void ConfigManager::addGlobalHeaderName(std::string name) {
Configuration
ConfigManager
::
getGlobalConfiguration
()
{
// Copy base config and set name
Configuration
global_config
=
global_base_config_
;
global_config
.
setName
(
global_default_name_
);
// FIXME needs to be done when loading
// global_config.setName(global_default_name_);
// Add all other global configuration
for
(
auto
&
global_name
:
global_names_
)
{
...
...
src/core/config/Configuration.cpp
View file @
f3d45219
/**
* @file
* @brief Implementation of configuration
* @copyright Copyright (c) 2017 CERN and the
Allpix Squared
authors.
* @copyright Copyright (c) 2017 CERN and the
Corryvreckan
authors.
* 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
* Intergovernmental Organization or submit itself to any jurisdiction.
...
...
@@ -25,12 +25,23 @@ bool Configuration::has(const std::string& key) const {
return
config_
.
find
(
key
)
!=
config_
.
cend
();
}
unsigned
int
Configuration
::
count
(
std
::
initializer_list
<
std
::
string
>
keys
)
const
{
if
(
keys
.
size
()
==
0
)
{
throw
std
::
invalid_argument
(
"list of keys cannot be empty"
);
}
unsigned
int
found
=
0
;
for
(
auto
&
key
:
keys
)
{
if
(
has
(
key
))
{
found
++
;
}
}
return
found
;
}
std
::
string
Configuration
::
getName
()
const
{
return
name_
;
}
void
Configuration
::
setName
(
const
std
::
string
&
name
)
{
name_
=
name
;
}
std
::
string
Configuration
::
getFilePath
()
const
{
return
path_
;
}
...
...
@@ -93,12 +104,12 @@ std::string Configuration::path_to_absolute(std::string path, bool canonicalize_
// Set new path
path
=
directory
+
"/"
+
path
;
}
// Normalize path only if we have to check if it exists
// NOTE: This throws an error if the path does not exist
if
(
canonicalize_path
)
{
path
=
corryvreckan
::
get_canonical_path
(
path
);
}
// Normalize path only if we have to check if it exists
// NOTE: This throws an error if the path does not exist
if
(
canonicalize_path
)
{
path
=
corryvreckan
::
get_canonical_path
(
path
);
}
return
path
;
}
...
...
src/core/config/Configuration.hpp
View file @
f3d45219
...
...
@@ -62,6 +62,13 @@ namespace corryvreckan {
*/
bool
has
(
const
std
::
string
&
key
)
const
;
/**
* @brief Check how many of the given keys are defined
* @param keys Keys to check for existence
* @return number of existing keys from the given list
*/
unsigned
int
count
(
std
::
initializer_list
<
std
::
string
>
keys
)
const
;
/**
* @brief Get value of a key in requested type
* @param key Key to get value of
...
...
@@ -143,19 +150,19 @@ namespace corryvreckan {
std
::
vector
<
std
::
string
>
getPathArray
(
const
std
::
string
&
key
,
bool
check_exists
=
false
)
const
;
/**
* @brief Set value for a key in a given type
with units
* @brief Set value for a key in a given type
* @param key Key to set value of
* @param val Value to assign to the key
* @param units List of possible output units
*/
template
<
typename
T
>
void
set
(
const
std
::
string
&
key
,
const
T
&
val
,
std
::
initializer_list
<
std
::
string
>
units
);
template
<
typename
T
>
void
set
(
const
std
::
string
&
key
,
const
T
&
val
);
/**
* @brief S
e
t value for a key in a given type
* @brief St
ore
value for a key in a given type
, including units
* @param key Key to set value of
* @param val Value to assign to the key
* @param units List of possible output units
*/
template
<
typename
T
>
void
set
(
const
std
::
string
&
key
,
const
T
&
val
);
template
<
typename
T
>
void
set
(
const
std
::
string
&
key
,
const
T
&
val
,
std
::
initializer_list
<
std
::
string
>
units
);
/**
* @brief Set list of values for a key in a given type
...
...
@@ -211,11 +218,6 @@ namespace corryvreckan {
*/
std
::
string
getName
()
const
;
/**
* @brief Set name of the configuration header
*/
void
setName
(
const
std
::
string
&
name
);
/**
* @brief Get path to the file containing the configuration if it has one
* @return Absolute path to configuration file or empty if not linked to a file
...
...
src/core/config/Configuration.tpp
View file @
f3d45219
...
...
@@ -91,7 +91,7 @@ namespace corryvreckan {
auto
node
=
parse_value
(
str
);
for
(
auto
&
child
:
node
->
children
)
{
if
(
child
->
children
.
empty
())
{
throw
std
::
invalid_argument
(
"matrix has less than two dimensions"
);
throw
std
::
invalid_argument
(
"matrix has less than two dimensions
, enclosing brackets might be missing
"
);
}
std
::
vector
<
T
>
array
;
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment