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
40ac7826
Commit
40ac7826
authored
Apr 16, 2018
by
Simon Spannagel
Browse files
Rest of the code: Algorithm -> Module.
parent
c39edf0e
Pipeline
#358630
passed with stages
in 8 minutes and 5 seconds
Changes
143
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
cmake/corryvreckan.cmake
View file @
40ac7826
# For every
algorithm
, build a separate library to be loaded by corryvreckan core
# For every
module
, build a separate library to be loaded by corryvreckan core
MACRO
(
corryvreckan_enable_default val
)
# Get the name of the
algorithm
GET_FILENAME_COMPONENT
(
_corryvreckan_
algorithm
_dir
${
CMAKE_CURRENT_SOURCE_DIR
}
NAME
)
# Get the name of the
module
GET_FILENAME_COMPONENT
(
_corryvreckan_
module
_dir
${
CMAKE_CURRENT_SOURCE_DIR
}
NAME
)
# Build all
algorithm
s by default if not specified otherwise
OPTION
(
BUILD_
${
_corryvreckan_
algorithm
_dir
}
"Build
algorithm
in directory
${
_corryvreckan_
algorithm
_dir
}
?"
${
val
}
)
# Build all
module
s by default if not specified otherwise
OPTION
(
BUILD_
${
_corryvreckan_
module
_dir
}
"Build
module
in directory
${
_corryvreckan_
module
_dir
}
?"
${
val
}
)
ENDMACRO
()
# Common
algorithm
definitions
MACRO
(
corryvreckan_
algorithm
name
)
# Get the name of the
algorithm
GET_FILENAME_COMPONENT
(
_corryvreckan_
algorithm
_dir
${
CMAKE_CURRENT_SOURCE_DIR
}
NAME
)
# Common
module
definitions
MACRO
(
corryvreckan_
module
name
)
# Get the name of the
module
GET_FILENAME_COMPONENT
(
_corryvreckan_
module
_dir
${
CMAKE_CURRENT_SOURCE_DIR
}
NAME
)
# Build all
algorithm
s by default if not specified otherwise
OPTION
(
BUILD_
${
_corryvreckan_
algorithm
_dir
}
"Build
algorithm
in directory
${
_corryvreckan_
algorithm
_dir
}
?"
ON
)
# Build all
module
s by default if not specified otherwise
OPTION
(
BUILD_
${
_corryvreckan_
module
_dir
}
"Build
module
in directory
${
_corryvreckan_
module
_dir
}
?"
ON
)
# Quit the file if not building this file or all
algorithm
s
IF
(
NOT
(
BUILD_
${
_corryvreckan_
algorithm
_dir
}
OR BUILD_ALL_
ALGORITHM
S
))
# Quit the file if not building this file or all
module
s
IF
(
NOT
(
BUILD_
${
_corryvreckan_
module
_dir
}
OR BUILD_ALL_
MODULE
S
))
RETURN
()
ENDIF
()
# Put message
MESSAGE
(
STATUS
"Building
algorithm
: "
${
_corryvreckan_
algorithm
_dir
}
)
MESSAGE
(
STATUS
"Building
module
: "
${
_corryvreckan_
module
_dir
}
)
# Prepend with the
algorithm
prefix to create the name of the
algorithm
SET
(
${
name
}
"Corryvreckan
Algorithm
${
_corryvreckan_
algorithm
_dir
}
"
)
# Prepend with the
module
prefix to create the name of the
module
SET
(
${
name
}
"Corryvreckan
Module
${
_corryvreckan_
module
_dir
}
"
)
# Save the
algorithm
library for prelinking in the executable (NOTE: see exec folder)
SET
(
CORRYVRECKAN_
ALGORITHM
_LIBRARIES
${
CORRYVRECKAN_
ALGORITHM
_LIBRARIES
}
${${
name
}}
CACHE INTERNAL
"
Algorithm
libraries"
)
# Save the
module
library for prelinking in the executable (NOTE: see exec folder)
SET
(
CORRYVRECKAN_
MODULE
_LIBRARIES
${
CORRYVRECKAN_
MODULE
_LIBRARIES
}
${${
name
}}
CACHE INTERNAL
"
Module
libraries"
)
# Set default
algorithm
class name
SET
(
_corryvreckan_
algorithm
_class
"
${
_corryvreckan_
algorithm
_dir
}
"
)
# Set default
module
class name
SET
(
_corryvreckan_
module
_class
"
${
_corryvreckan_
module
_dir
}
"
)
# Find if alternative
algorithm
class name is passed or we can use the default
# Find if alternative
module
class name is passed or we can use the default
SET
(
extra_macro_args
${
ARGN
}
)
LIST
(
LENGTH extra_macro_args num_extra_args
)
IF
(
${
num_extra_args
}
GREATER 0
)
MESSAGE
(
AUTHOR_WARNING
"Provided non-standard
algorithm
class name! Naming it
${
_corryvreckan_
algorithm
_class
}
is recommended"
)
LIST
(
GET extra_macro_args 0 _corryvreckan_
algorithm
_class
)
MESSAGE
(
AUTHOR_WARNING
"Provided non-standard
module
class name! Naming it
${
_corryvreckan_
module
_class
}
is recommended"
)
LIST
(
GET extra_macro_args 0 _corryvreckan_
module
_class
)
ENDIF
()
# check if main header file is defined
IF
(
NOT EXISTS
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/
${
_corryvreckan_
algorithm
_class
}
.h"
)
MESSAGE
(
FATAL_ERROR
"Header file
${
_corryvreckan_
algorithm
_class
}
.h does not exist, cannot build
algorithm
! \
IF
(
NOT EXISTS
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/
${
_corryvreckan_
module
_class
}
.h"
)
MESSAGE
(
FATAL_ERROR
"Header file
${
_corryvreckan_
module
_class
}
.h does not exist, cannot build
module
! \
Create the header or provide the alternative class name as first argument"
)
ENDIF
()
...
...
@@ -53,15 +53,15 @@ Create the header or provide the alternative class name as first argument")
TARGET_INCLUDE_DIRECTORIES
(
${${
name
}}
PRIVATE
${
CMAKE_CURRENT_SOURCE_DIR
}
)
# Set the special header flags and add the special dynamic implementation file
TARGET_COMPILE_DEFINITIONS
(
${${
name
}}
PRIVATE CORRYVRECKAN_
ALGORITHM
_NAME=
${
_corryvreckan_
algorithm
_class
}
)
TARGET_COMPILE_DEFINITIONS
(
${${
name
}}
PRIVATE CORRYVRECKAN_
ALGORITHM
_HEADER=
"
${
_corryvreckan_
algorithm
_class
}
.h"
)
TARGET_COMPILE_DEFINITIONS
(
${${
name
}}
PRIVATE CORRYVRECKAN_
MODULE
_NAME=
${
_corryvreckan_
module
_class
}
)
TARGET_COMPILE_DEFINITIONS
(
${${
name
}}
PRIVATE CORRYVRECKAN_
MODULE
_HEADER=
"
${
_corryvreckan_
module
_class
}
.h"
)
TARGET_SOURCES
(
${${
name
}}
PRIVATE
"
${
PROJECT_SOURCE_DIR
}
/src/core/
algorithm/dynamic_algorithm
_impl.cpp"
)
SET_PROPERTY
(
SOURCE
"
${
PROJECT_SOURCE_DIR
}
/src/core/
algorithm/dynamic_algorithm
_impl.cpp"
APPEND PROPERTY OBJECT_DEPENDS
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/
${
_corryvreckan_
algorithm
_class
}
.h"
)
TARGET_SOURCES
(
${${
name
}}
PRIVATE
"
${
PROJECT_SOURCE_DIR
}
/src/core/
module/dynamic_module
_impl.cpp"
)
SET_PROPERTY
(
SOURCE
"
${
PROJECT_SOURCE_DIR
}
/src/core/
module/dynamic_module
_impl.cpp"
APPEND PROPERTY OBJECT_DEPENDS
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/
${
_corryvreckan_
module
_class
}
.h"
)
ENDMACRO
()
# Add sources to the
algorithm
MACRO
(
corryvreckan_
algorithm
_sources name
)
# Add sources to the
module
MACRO
(
corryvreckan_
module
_sources name
)
# Get the list of sources
SET
(
_list_var
"
${
ARGN
}
"
)
LIST
(
REMOVE_ITEM _list_var
${
name
}
)
...
...
@@ -76,8 +76,8 @@ MACRO(corryvreckan_algorithm_sources name)
TARGET_LINK_LIBRARIES
(
${
name
}
${
CORRYVRECKAN_LIBRARIES
}
${
CORRYVRECKAN_DEPS_LIBRARIES
}
)
ENDMACRO
()
# Provide default install target for the
algorithm
MACRO
(
corryvreckan_
algorithm
_install name
)
# Provide default install target for the
module
MACRO
(
corryvreckan_
module
_install name
)
INSTALL
(
TARGETS
${
name
}
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
...
...
etc/addAlgorithm.sh
deleted
100755 → 0
View file @
c39edf0e
#!/bin/bash
# Ask for the name of the new algorithm
read
-p
"Name of the new algorithm: "
NEWALGORITHM
# Copy the GenericAlgorithm and replace the name with the new algorithm name
echo
"Creating folder src/algorithms/
${
NEWALGORITHM
}
"
mkdir
../src/algorithms/
${
NEWALGORITHM
}
echo
"Creating
${
NEWALGORITHM
}
.cpp"
cp
../src/algorithms/GenericAlgorithm/GenericAlgorithm.cpp ../src/algorithms/
${
NEWALGORITHM
}
/
${
NEWALGORITHM
}
.cpp
echo
"Creating
${
NEWALGORITHM
}
.h"
cp
../src/algorithms/GenericAlgorithm/GenericAlgorithm.h ../src/algorithms/
${
NEWALGORITHM
}
/
${
NEWALGORITHM
}
.h
echo
"Creating supplimentory files"
cp
../src/algorithms/GenericAlgorithm/CMakeLists.txt ../src/algorithms/
${
NEWALGORITHM
}
/CMakeLists.txt
cp
../src/algorithms/README_template.md ../src/algorithms/
${
NEWALGORITHM
}
/README.md
# Check mac or linux platform
platform
=
`
uname
`
if
[
"
$platform
"
==
"Darwin"
]
then
sed
-i
""
s/
"GenericAlgorithm"
/
"
${
NEWALGORITHM
}
"
/g ../src/algorithms/
${
NEWALGORITHM
}
/
${
NEWALGORITHM
}
.cpp
sed
-i
""
s/
"GenericAlgorithm"
/
"
${
NEWALGORITHM
}
"
/g ../src/algorithms/
${
NEWALGORITHM
}
/
${
NEWALGORITHM
}
.h
sed
-i
""
s/
"GenericAlgorithm"
/
"
${
NEWALGORITHM
}
"
/g ../src/algorithms/
${
NEWALGORITHM
}
/CMakeLists.txt
else
sed
-i
s/
"GenericAlgorithm"
/
"
${
NEWALGORITHM
}
"
/g ../src/algorithms/
${
NEWALGORITHM
}
/
${
NEWALGORITHM
}
.cpp
sed
-i
s/
"GenericAlgorithm"
/
"
${
NEWALGORITHM
}
"
/g ../src/algorithms/
${
NEWALGORITHM
}
/
${
NEWALGORITHM
}
.h
sed
-i
s/
"GenericAlgorithm"
/
"
${
NEWALGORITHM
}
"
/g ../src/algorithms/
${
NEWALGORITHM
}
/CMakeLists.txt
fi
etc/addModule.sh
0 → 100755
View file @
40ac7826
#!/bin/bash
# Ask for the name of the new module
read
-p
"Name of the new module: "
NEWMODULE
# Copy the GenericAlgorithm and replace the name with the new module name
echo
"Creating folder src/modules/
${
NEWMODULE
}
"
mkdir
../src/modules/
${
NEWMODULE
}
echo
"Creating
${
NEWMODULE
}
.cpp"
cp
../src/modules/GenericAlgorithm/GenericAlgorithm.cpp ../src/modules/
${
NEWMODULE
}
/
${
NEWMODULE
}
.cpp
echo
"Creating
${
NEWMODULE
}
.h"
cp
../src/modules/GenericAlgorithm/GenericAlgorithm.h ../src/modules/
${
NEWMODULE
}
/
${
NEWMODULE
}
.h
echo
"Creating supplimentory files"
cp
../src/modules/GenericAlgorithm/CMakeLists.txt ../src/modules/
${
NEWMODULE
}
/CMakeLists.txt
cp
../src/modules/README_template.md ../src/modules/
${
NEWMODULE
}
/README.md
# Check mac or linux platform
platform
=
`
uname
`
if
[
"
$platform
"
==
"Darwin"
]
then
sed
-i
""
s/
"GenericAlgorithm"
/
"
${
NEWMODULE
}
"
/g ../src/modules/
${
NEWMODULE
}
/
${
NEWMODULE
}
.cpp
sed
-i
""
s/
"GenericAlgorithm"
/
"
${
NEWMODULE
}
"
/g ../src/modules/
${
NEWMODULE
}
/
${
NEWMODULE
}
.h
sed
-i
""
s/
"GenericAlgorithm"
/
"
${
NEWMODULE
}
"
/g ../src/modules/
${
NEWMODULE
}
/CMakeLists.txt
else
sed
-i
s/
"GenericAlgorithm"
/
"
${
NEWMODULE
}
"
/g ../src/modules/
${
NEWMODULE
}
/
${
NEWMODULE
}
.cpp
sed
-i
s/
"GenericAlgorithm"
/
"
${
NEWMODULE
}
"
/g ../src/modules/
${
NEWMODULE
}
/
${
NEWMODULE
}
.h
sed
-i
s/
"GenericAlgorithm"
/
"
${
NEWMODULE
}
"
/g ../src/modules/
${
NEWMODULE
}
/CMakeLists.txt
fi
src/core/Analysis.cpp
View file @
40ac7826
...
...
@@ -7,15 +7,15 @@
// Local include files
#include
"Analysis.h"
#include
"
algorithm
/exceptions.h"
#include
"
module
/exceptions.h"
#include
"utils/log.h"
#include
<dlfcn.h>
#include
<fstream>
#include
<iomanip>
#define CORRYVRECKAN_
ALGORITHM
_PREFIX "libCorryvreckan
Algorithm
"
#define CORRYVRECKAN_GENERATOR_FUNCTION "corryvreckan_
algorithm
_generator"
#define CORRYVRECKAN_
MODULE
_PREFIX "libCorryvreckan
Module
"
#define CORRYVRECKAN_GENERATOR_FUNCTION "corryvreckan_
module
_generator"
using
namespace
corryvreckan
;
...
...
@@ -92,7 +92,7 @@ void Analysis::load() {
add_units
();
load_detectors
();
load_
algorithm
s
();
load_
module
s
();
}
void
Analysis
::
load_detectors
()
{
...
...
@@ -131,7 +131,7 @@ void Analysis::load_detectors() {
});
}
void
Analysis
::
load_
algorithm
s
()
{
void
Analysis
::
load_
module
s
()
{
std
::
vector
<
Configuration
>
configs
=
conf_mgr_
->
getConfigurations
();
// Create histogram output file
...
...
@@ -142,14 +142,14 @@ void Analysis::load_algorithms() {
throw
RuntimeError
(
"Cannot create main ROOT file "
+
histogramFile
);
}
LOG
(
DEBUG
)
<<
"Start loading
algorithm
s, have "
<<
configs
.
size
()
<<
" configurations."
;
LOG
(
DEBUG
)
<<
"Start loading
module
s, have "
<<
configs
.
size
()
<<
" configurations."
;
// Loop through all non-global configurations
for
(
auto
&
config
:
configs
)
{
// Load library for each module. Libraries are named (by convention + CMAKE)
// libAllpixModule Name.suffix
std
::
string
lib_name
=
std
::
string
(
CORRYVRECKAN_
ALGORITHM
_PREFIX
).
append
(
config
.
getName
()).
append
(
SHARED_LIBRARY_SUFFIX
);
LOG_PROGRESS
(
STATUS
,
"LOAD_LOOP"
)
<<
"Loading
algorithm
"
<<
config
.
getName
();
std
::
string
(
CORRYVRECKAN_
MODULE
_PREFIX
).
append
(
config
.
getName
()).
append
(
SHARED_LIBRARY_SUFFIX
);
LOG_PROGRESS
(
STATUS
,
"LOAD_LOOP"
)
<<
"Loading
module
"
<<
config
.
getName
();
void
*
lib
=
nullptr
;
bool
load_error
=
false
;
...
...
@@ -226,7 +226,7 @@ void Analysis::load_algorithms() {
<<
std
::
endl
<<
"- Recompile the library "
<<
problem_lib
<<
" with tls-model=global-dynamic"
;
}
else
if
(
lib_error
!=
nullptr
&&
std
::
strstr
(
lib_error
,
"cannot open shared object file"
)
!=
nullptr
&&
problem_lib
.
find
(
CORRYVRECKAN_
ALGORITHM
_PREFIX
)
==
std
::
string
::
npos
)
{
problem_lib
.
find
(
CORRYVRECKAN_
MODULE
_PREFIX
)
==
std
::
string
::
npos
)
{
LOG
(
ERROR
)
<<
"Library could not be loaded: one of its dependencies is missing"
<<
std
::
endl
<<
"The name of the missing library is "
<<
problem_lib
<<
std
::
endl
<<
"Please make sure the library is properly initialized and try "
...
...
@@ -252,44 +252,44 @@ void Analysis::load_algorithms() {
std
::
string
global_dir
=
gSystem
->
pwd
();
config
.
set
<
std
::
string
>
(
"_global_dir"
,
global_dir
);
// Merge the global configuration into the
algorithm
s config:
// Merge the global configuration into the
module
s config:
config
.
merge
(
global_config
);
// Create the
algorithm
s from the library
m_
algorithm
s
.
emplace_back
(
create_
algorithm
(
loaded_libraries_
[
lib_name
],
config
));
// Create the
module
s from the library
m_
module
s
.
emplace_back
(
create_
module
(
loaded_libraries_
[
lib_name
],
config
));
}
LOG
(
STATUS
)
<<
"Loaded "
<<
configs
.
size
()
<<
" modules"
;
}
Algorithm
*
Analysis
::
create_
algorithm
(
void
*
library
,
Configuration
config
)
{
LOG
(
TRACE
)
<<
"Creating
algorithm
"
<<
config
.
getName
()
<<
", using generator
\"
"
<<
CORRYVRECKAN_GENERATOR_FUNCTION
Module
*
Analysis
::
create_
module
(
void
*
library
,
Configuration
config
)
{
LOG
(
TRACE
)
<<
"Creating
module
"
<<
config
.
getName
()
<<
", using generator
\"
"
<<
CORRYVRECKAN_GENERATOR_FUNCTION
<<
"
\"
"
;
// Make the vector to return
std
::
string
algorithm
_name
=
config
.
getName
();
std
::
string
module
_name
=
config
.
getName
();
// Get the generator function for this module
void
*
generator
=
dlsym
(
library
,
CORRYVRECKAN_GENERATOR_FUNCTION
);
// If the generator function was not found, throw an error
if
(
generator
==
nullptr
)
{
LOG
(
ERROR
)
<<
"
Algorithm
library is invalid or outdated: required "
LOG
(
ERROR
)
<<
"
Module
library is invalid or outdated: required "
"interface function not found!"
;
throw
corryvreckan
::
RuntimeError
(
"Error instantiating
algorithm
from "
+
config
.
getName
());
throw
corryvreckan
::
RuntimeError
(
"Error instantiating
module
from "
+
config
.
getName
());
}
// Convert to correct generator function
auto
algorithm
_generator
=
reinterpret_cast
<
Algorithm
*
(
*
)(
Configuration
,
std
::
vector
<
Detector
*>
)
>
(
generator
);
// NOLINT
auto
module
_generator
=
reinterpret_cast
<
Module
*
(
*
)(
Configuration
,
std
::
vector
<
Detector
*>
)
>
(
generator
);
// NOLINT
// Figure out which detectors should run on this
algorithm
:
std
::
vector
<
Detector
*>
algorithm
_det
;
// Figure out which detectors should run on this
module
:
std
::
vector
<
Detector
*>
module
_det
;
if
(
!
config
.
has
(
"detectors"
))
{
algorithm
_det
=
detectors
;
module
_det
=
detectors
;
}
else
{
std
::
vector
<
std
::
string
>
det_list
=
config
.
getArray
<
std
::
string
>
(
"detectors"
);
for
(
auto
&
d
:
detectors
)
{
if
(
std
::
find
(
det_list
.
begin
(),
det_list
.
end
(),
d
->
name
())
!=
det_list
.
end
())
{
algorithm
_det
.
push_back
(
d
);
module
_det
.
push_back
(
d
);
}
}
}
...
...
@@ -298,10 +298,10 @@ Algorithm* Analysis::create_algorithm(void* library, Configuration config) {
if
(
config
.
has
(
"masked"
))
{
std
::
vector
<
std
::
string
>
mask_list
=
config
.
getArray
<
std
::
string
>
(
"masked"
);
for
(
auto
it
=
algorithm
_det
.
begin
();
it
!=
algorithm
_det
.
end
();)
{
for
(
auto
it
=
module
_det
.
begin
();
it
!=
module
_det
.
end
();)
{
// Remove detectors which are masked:
if
(
std
::
find
(
mask_list
.
begin
(),
mask_list
.
end
(),
(
*
it
)
->
name
())
!=
mask_list
.
end
())
{
it
=
algorithm
_det
.
erase
(
it
);
it
=
module
_det
.
erase
(
it
);
}
else
{
it
++
;
}
...
...
@@ -314,18 +314,18 @@ Algorithm* Analysis::create_algorithm(void* library, Configuration config) {
section_name
+=
config
.
getName
();
Log
::
setSection
(
section_name
);
// Set module specific log settings
auto
old_settings
=
set_
algorithm
_before
(
config
.
getName
(),
config
);
// Build
algorithm
Algorithm
*
algorithm
=
algorithm
_generator
(
config
,
algorithm
_det
);
auto
old_settings
=
set_
module
_before
(
config
.
getName
(),
config
);
// Build
module
Module
*
module
=
module
_generator
(
config
,
module
_det
);
// Reset log
Log
::
setSection
(
old_section_name
);
set_
algorithm
_after
(
old_settings
);
set_
module
_after
(
old_settings
);
// Return the
algorithm
to the analysis
return
algorithm
;
// Return the
module
to the analysis
return
module
;
}
// Run the analysis loop - this initialises, runs and finalises all
algorithm
s
// Run the analysis loop - this initialises, runs and finalises all
module
s
void
Analysis
::
run
()
{
// Check if we have an event or track limit:
...
...
@@ -333,7 +333,7 @@ void Analysis::run() {
int
number_of_tracks
=
global_config
.
get
<
int
>
(
"number_of_tracks"
,
-
1
);
float
run_time
=
global_config
.
get
<
float
>
(
"run_time"
,
Units
::
convert
(
-
1.0
,
"s"
));
// Loop over all events, running each
algorithm
on each "event"
// Loop over all events, running each
module
on each "event"
LOG
(
STATUS
)
<<
"========================| Event loop |========================"
;
m_events
=
1
;
int
events_prev
=
1
;
...
...
@@ -357,24 +357,24 @@ void Analysis::run() {
if
(
number_of_tracks
>
-
1
&&
m_tracks
>=
number_of_tracks
)
break
;
// Run all
algorithm
s
for
(
auto
&
algorithm
:
m_algorithm
s
)
{
// Run all
module
s
for
(
auto
&
module
:
m_module
s
)
{
// Set run module section header
std
::
string
old_section_name
=
Log
::
getSection
();
std
::
string
section_name
=
"R:"
;
section_name
+=
algorithm
->
getName
();
section_name
+=
module
->
getName
();
Log
::
setSection
(
section_name
);
// Set module specific settings
auto
old_settings
=
set_
algorithm_before
(
algorithm
->
getName
(),
algorithm
->
getConfig
());
auto
old_settings
=
set_
module_before
(
module
->
getName
(),
module
->
getConfig
());
// Change to the output file directory
m_directory
->
cd
(
algorithm
->
getName
().
c_str
());
// Run the
algorithm
s with timing enabled
algorithm
->
getStopwatch
()
->
Start
(
false
);
StatusCode
check
=
algorithm
->
run
(
m_clipboard
);
algorithm
->
getStopwatch
()
->
Stop
();
m_directory
->
cd
(
module
->
getName
().
c_str
());
// Run the
module
s with timing enabled
module
->
getStopwatch
()
->
Start
(
false
);
StatusCode
check
=
module
->
run
(
m_clipboard
);
module
->
getStopwatch
()
->
Stop
();
// Reset logging
Log
::
setSection
(
old_section_name
);
set_
algorithm
_after
(
old_settings
);
set_
module
_after
(
old_settings
);
if
(
check
==
NoData
)
{
noData
=
true
;
skipped
++
;
...
...
@@ -407,7 +407,7 @@ void Analysis::run() {
// Clear objects from this iteration from the clipboard
m_clipboard
->
clear
();
// Check if any of the
algorithm
s return a value saying it should stop
// Check if any of the
module
s return a value saying it should stop
if
(
!
run
)
break
;
// Increment event number
...
...
@@ -429,54 +429,54 @@ void Analysis::terminate() {
m_terminate
=
true
;
}
// Initalise all
algorithm
s
// Initalise all
module
s
void
Analysis
::
initialiseAll
()
{
// Loop over all
algorithm
s and initialise them
LOG
(
STATUS
)
<<
"=================| Initialising
algorithm
s |=================="
;
for
(
auto
&
algorithm
:
m_algorithm
s
)
{
// Loop over all
module
s and initialise them
LOG
(
STATUS
)
<<
"=================| Initialising
module
s |=================="
;
for
(
auto
&
module
:
m_module
s
)
{
// Set init module section header
std
::
string
old_section_name
=
Log
::
getSection
();
std
::
string
section_name
=
"I:"
;
section_name
+=
algorithm
->
getName
();
section_name
+=
module
->
getName
();
Log
::
setSection
(
section_name
);
// Set module specific settings
auto
old_settings
=
set_
algorithm_before
(
algorithm
->
getName
(),
algorithm
->
getConfig
());
auto
old_settings
=
set_
module_before
(
module
->
getName
(),
module
->
getConfig
());
// Make a new folder in the output file
m_directory
->
cd
();
m_directory
->
mkdir
(
algorithm
->
getName
().
c_str
());
m_directory
->
cd
(
algorithm
->
getName
().
c_str
());
LOG
(
INFO
)
<<
"Initialising
\"
"
<<
algorithm
->
getName
()
<<
"
\"
"
;
// Initialise the
algorithm
algorithm
->
initialise
();
m_directory
->
mkdir
(
module
->
getName
().
c_str
());
m_directory
->
cd
(
module
->
getName
().
c_str
());
LOG
(
INFO
)
<<
"Initialising
\"
"
<<
module
->
getName
()
<<
"
\"
"
;
// Initialise the
module
module
->
initialise
();
// Reset logging
Log
::
setSection
(
old_section_name
);
set_
algorithm
_after
(
old_settings
);
set_
module
_after
(
old_settings
);
}
}
// Finalise all
algorithm
s
// Finalise all
module
s
void
Analysis
::
finaliseAll
()
{
// Loop over all
algorithm
s and finalise them
LOG
(
STATUS
)
<<
"===================| Finalising
algorithm
s |==================="
;
for
(
auto
&
algorithm
:
m_algorithm
s
)
{
// Loop over all
module
s and finalise them
LOG
(
STATUS
)
<<
"===================| Finalising
module
s |==================="
;
for
(
auto
&
module
:
m_module
s
)
{
// Set init module section header
std
::
string
old_section_name
=
Log
::
getSection
();
std
::
string
section_name
=
"F:"
;
section_name
+=
algorithm
->
getName
();
section_name
+=
module
->
getName
();
Log
::
setSection
(
section_name
);
// Set module specific settings
auto
old_settings
=
set_
algorithm_before
(
algorithm
->
getName
(),
algorithm
->
getConfig
());
auto
old_settings
=
set_
module_before
(
module
->
getName
(),
module
->
getConfig
());
// Change to the output file directory
m_directory
->
cd
(
algorithm
->
getName
().
c_str
());
// Finalise the
algorithm
algorithm
->
finalise
();
m_directory
->
cd
(
module
->
getName
().
c_str
());
// Finalise the
module
module
->
finalise
();
// Reset logging
Log
::
setSection
(
old_section_name
);
set_
algorithm
_after
(
old_settings
);
set_
module
_after
(
old_settings
);
}
// Write the output histogram file
...
...
@@ -506,19 +506,19 @@ void Analysis::finaliseAll() {
timing
();
}
// Display timing statistics for each
algorithm
, over all events and per event
// Display timing statistics for each
module
, over all events and per event
void
Analysis
::
timing
()
{
LOG
(
STATUS
)
<<
"===============| Wall-clock timing (seconds) |================"
;
for
(
auto
&
algorithm
:
m_algorithm
s
)
{
LOG
(
STATUS
)
<<
std
::
setw
(
25
)
<<
algorithm
->
getName
()
<<
" -- "
<<
std
::
fixed
<<
std
::
setprecision
(
5
)
<<
algorithm
->
getStopwatch
()
->
RealTime
()
<<
" = "
<<
std
::
setprecision
(
9
)
<<
algorithm
->
getStopwatch
()
->
RealTime
()
/
m_events
<<
" s/evt"
;
for
(
auto
&
module
:
m_module
s
)
{
LOG
(
STATUS
)
<<
std
::
setw
(
25
)
<<
module
->
getName
()
<<
" -- "
<<
std
::
fixed
<<
std
::
setprecision
(
5
)
<<
module
->
getStopwatch
()
->
RealTime
()
<<
" = "
<<
std
::
setprecision
(
9
)
<<
module
->
getStopwatch
()
->
RealTime
()
/
m_events
<<
" s/evt"
;
}
LOG
(
STATUS
)
<<
"=============================================================="
;
}
// Helper functions to set the module specific log settings if necessary
std
::
tuple
<
LogLevel
,
LogFormat
>
Analysis
::
set_
algorithm
_before
(
const
std
::
string
&
,
const
Configuration
&
config
)
{
std
::
tuple
<
LogLevel
,
LogFormat
>
Analysis
::
set_
module
_before
(
const
std
::
string
&
,
const
Configuration
&
config
)
{
// Set new log level if necessary
LogLevel
prev_level
=
Log
::
getReportingLevel
();
if
(
config
.
has
(
"log_level"
))
{
...
...
@@ -553,7 +553,7 @@ std::tuple<LogLevel, LogFormat> Analysis::set_algorithm_before(const std::string
return
std
::
make_tuple
(
prev_level
,
prev_format
);
}
void
Analysis
::
set_
algorithm
_after
(
std
::
tuple
<
LogLevel
,
LogFormat
>
prev
)
{
void
Analysis
::
set_
module
_after
(
std
::
tuple
<
LogLevel
,
LogFormat
>
prev
)
{
// Reset the previous log level
LogLevel
cur_level
=
Log
::
getReportingLevel
();
LogLevel
old_level
=
std
::
get
<
0
>
(
prev
);
...
...
src/core/Analysis.h
View file @
40ac7826
...
...
@@ -11,18 +11,18 @@
#include
"Clipboard.h"
#include
"Detector.h"
#include
"algorithm/Algorithm.h"
#include
"config/ConfigManager.hpp"
#include
"config/Configuration.hpp"
#include
"module/Module.hpp"
//-------------------------------------------------------------------------------
// The analysis class is the core class which allows the event processing to
// run. It basically contains a vector of
algorithm
s, each of which is
// run. It basically contains a vector of
module
s, each of which is
// initialised,
// run on each event and finalised. It does not define what an event is, merely
// runs each
algorithm
sequentially and passes the clipboard between them
// runs each
module
sequentially and passes the clipboard between them
// (erasing
// it at the end of each run sequence). When an
algorithm
returns a 0, the event
// it at the end of each run sequence). When an
module
returns a 0, the event
// processing will stop.
//-------------------------------------------------------------------------------
...
...
@@ -55,7 +55,7 @@ namespace corryvreckan {
private:
void
load_detectors
();
void
load_
algorithm
s
();
void
load_
module
s
();
void
add_units
();
// Log file if specified
...
...
@@ -66,15 +66,15 @@ namespace corryvreckan {
int
m_events
;
int
m_tracks
;
std
::
vector
<
Algorithm
*>
m_algorithm
s
;
std
::
vector
<
Module
*>
m_module
s
;
std
::
map
<
std
::
string
,
void
*>
loaded_libraries_
;
std
::
atomic
<
bool
>
m_terminate
;
std
::
unique_ptr
<
corryvreckan
::
ConfigManager
>
conf_mgr_
;
Algorithm
*
create_algorithm
(
void
*
library
,
corryvreckan
::
Configuration
config
);
std
::
tuple
<
LogLevel
,
LogFormat
>
set_
algorithm
_before
(
const
std
::
string
&
,
const
Configuration
&
config
);
void
set_
algorithm
_after
(
std
::
tuple
<
LogLevel
,
LogFormat
>
prev
);
Module
*
create_module
(
void
*
library
,
corryvreckan
::
Configuration
config
);
std
::
tuple
<
LogLevel
,
LogFormat
>
set_
module
_before
(
const
std
::
string
&
,
const
Configuration
&
config
);
void
set_
module
_after
(
std
::
tuple
<
LogLevel
,
LogFormat
>
prev
);
};
}
// namespace corryvreckan
#endif // ANALYSIS_H
src/core/Clipboard.h
View file @
40ac7826
...
...
@@ -10,7 +10,7 @@
#include
"utils/log.h"
//-------------------------------------------------------------------------------
// The Clipboard class is used to transfer information between
algorithm
s during
// The Clipboard class is used to transfer information between
module
s during
// the event processing. Any object inheriting from TestBeamObject can be placed
// on the clipboard, and retrieved by its name. At the end of each event, the
// clipboard is wiped clean.
...
...
src/core/
algorithm/Algorithm.h
→
src/core/
module/Module.hpp
View file @
40ac7826
#ifndef
ALGORITHM
_H
#define
ALGORITHM
_H 1
#ifndef
MODULE
_H
#define
MODULE
_H 1
// Include files
#include
<string>
...
...
@@ -10,14 +10,14 @@
#include
"exceptions.h"
//-------------------------------------------------------------------------------
// The
algorithm
class is the base class that all user
algorithm
s are built on.
// The
module
class is the base class that all user
module
s are built on.
// It
// allows the analysis class to hold
algorithm
s of different types, without
// allows the analysis class to hold
module
s of different types, without
// knowing
// what they are, and provides the functions initialise, run and finalise. It
// also
// gives some basic tools like the "tcout" replacement for "cout" (appending the
//
algorithm
name) and the stopwatch for timing measurements.
//
module
name) and the stopwatch for timing measurements.
//-------------------------------------------------------------------------------
namespace
corryvreckan
{
...
...
@@ -28,15 +28,15 @@ namespace corryvreckan {
Failure
,
};
/** Base class for all
algorithm
s
* @defgroup
Algorithms Algorithm
s
/** Base class for all
module
s
* @defgroup
Modules Module
s
*/
class
Algorithm
{
class
Module
{
public:
// Constructors and destructors
Algorithm
()
{}
Algorithm
(
Configuration
config
,
std
::
vector
<
Detector
*>
detectors
)
{
Module
()
{}
Module
(
Configuration
config
,
std
::
vector
<
Detector
*>
detectors
)
{
m_name
=
config
.
getName
();
m_config
=
config
;
m_detectors
=
detectors
;
...
...
@@ -46,13 +46,13 @@ namespace corryvreckan {
for
(
auto
&
d
:
m_detectors
)
{
det
<<
d
->
name
()
<<
", "
;
}
LOG
(
TRACE
)
<<
"
Algorithm
determined to run on detectors: "
<<
det
.
str
();
LOG
(
TRACE
)
<<
"
Module
determined to run on detectors: "
<<
det
.
str
();
}