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
de136480
Commit
de136480
authored
Mar 25, 2020
by
Jin Zhang
Browse files
following suggetion to as to make a Detector::Factory wrapper rather than string comparison
parent
944a5b70
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/core/detector/Detector.cpp
View file @
de136480
...
...
@@ -77,6 +77,17 @@ Detector::Detector(const Configuration& config) : m_role(DetectorRole::NONE) {
}
}
std
::
shared_ptr
<
Detector
>
corryvreckan
::
Detector
::
Factory
(
const
Configuration
&
config
)
{
// default coordinate is cartesian coordinate
std
::
string
coordinates
=
config
.
get
<
std
::
string
>
(
"coordinates"
,
"cartesian"
);
std
::
transform
(
coordinates
.
begin
(),
coordinates
.
end
(),
coordinates
.
begin
(),
::
tolower
);
if
(
coordinates
==
"cartesian"
)
{
return
std
::
make_shared
<
PlanarDetector
>
(
config
);
}
else
{
throw
InvalidValueError
(
config
,
"coordinates"
,
"Coordiantes can only set to be cartesian now"
);
}
}
double
Detector
::
getTimeResolution
()
const
{
if
(
m_timeResolution
>
0
)
{
return
m_timeResolution
;
...
...
src/core/detector/Detector.hpp
View file @
de136480
...
...
@@ -80,6 +80,13 @@ namespace corryvreckan {
*/
Detector
(
const
Configuration
&
config
);
/**
* @brief Factory to dynamically create detectors
* @param The name of the coordinates which should be used
* @return By param coordinates assigned detector to be used
*/
static
std
::
shared_ptr
<
Detector
>
Factory
(
const
Configuration
&
config
);
/**
* @brief Get type of the detector
* @return Type of the detector model
...
...
@@ -344,4 +351,5 @@ namespace corryvreckan {
};
}
// namespace corryvreckan
#include
"PlanarDetector.hpp"
#endif // CORRYVRECKAN_DETECTOR_H
src/core/module/ModuleManager.cpp
View file @
de136480
...
...
@@ -51,8 +51,8 @@ void ModuleManager::load_detectors() {
for
(
auto
&
detector_section
:
conf_manager_
->
getDetectorConfigurations
())
{
std
::
string
name
=
detector_section
.
getName
();
std
::
string
coordinate
=
detector_section
.
get
<
std
::
string
>
(
"coordinates"
,
"cartesian"
);
std
::
transform
(
coordinate
.
begin
(),
coordinate
.
end
(),
coordinate
.
begin
(),
::
tolower
);
//
std::string coordinate = detector_section.get<std::string>("coordinates", "cartesian");
//
std::transform(coordinate.begin(), coordinate.end(), coordinate.begin(), ::tolower);
// Check if we have a duplicate:
if
(
std
::
find_if
(
m_detectors
.
begin
(),
m_detectors
.
end
(),
[
&
name
](
std
::
shared_ptr
<
Detector
>
obj
)
{
...
...
@@ -63,11 +63,9 @@ void ModuleManager::load_detectors() {
}
LOG_PROGRESS
(
STATUS
,
"DET_LOAD_LOOP"
)
<<
"Loading detector "
<<
name
;
// the default coordinates is cartesian, any other type is forbidden now
// @to do: other detector types, e.g., ATLAS endcap strip detector
// default coordinate is cartesian coordinate
std
::
shared_ptr
<
Detector
>
detector
;
if
(
coordinate
==
"cartesian"
)
detector
=
std
::
make_shared
<
PlanarDetector
>
(
detector_section
);
auto
detector
=
Detector
::
Factory
(
detector_section
);
// Check if we already found a reference plane:
if
(
m_reference
!=
nullptr
&&
detector
->
isReference
())
{
...
...
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