Skip to content

Commit

Permalink
build: exclude algorithms which depend on ROOT, if we don't have ROOT
Browse files Browse the repository at this point in the history
  • Loading branch information
c-dilks committed Feb 21, 2024
1 parent abc0aaa commit ab99c70
Show file tree
Hide file tree
Showing 8 changed files with 127 additions and 101 deletions.
7 changes: 3 additions & 4 deletions bind/python/iguana-example-00-basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,13 @@

seq = iguana.AlgorithmSequence('pyiguana')
seq.Add('clas12::EventBuilderFilter')
seq.Add('clas12::LorentzTransformer')
# seq.Add('clas12::MomentumCorrection') # FIXME
seq.PrintSequence()

seq.SetOption('clas12::EventBuilderFilter', 'log', 'debug')
seq.SetOption('clas12::LorentzTransformer', 'log', 'debug')
seq.SetOption('clas12::EventBuilderFilter', 'log', 'debug')
# seq.SetOption('clas12::MomentumCorrection', 'log', 'debug') # FIXME

seq.SetOption('clas12::EventBuilderFilter', 'pids', [11, 211, -211])
seq.SetOption('clas12::LorentzTransformer', 'frame', 'mirror')

def prettyPrint(message, bank):
print(f'{"="*30} {message} {"="*30}')
Expand Down
32 changes: 16 additions & 16 deletions bind/python/iguana-example-01-bank-rows.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
pyiguana.include(
'hipo4/reader.h',
'iguana/algorithms/clas12/EventBuilderFilter.h',
'iguana/algorithms/clas12/LorentzTransformer.h',
# 'iguana/algorithms/clas12/MomentumCorrection.h', # FIXME
)
# then import the bound namespaces (must be after including the headers)
from cppyy.gbl import hipo, iguana
Expand All @@ -20,15 +20,14 @@
banks = reader.getBanks(["REC::Particle", "REC::Calorimeter"]);

algo_eventbuilder_filter = iguana.clas12.EventBuilderFilter()
algo_lorentz_transformer = iguana.clas12.LorentzTransformer()
# algo_momentum_correction = iguana.clas12.MomentumCorrection() # FIXME

algo_eventbuilder_filter.SetOption('log', 'debug')
algo_lorentz_transformer.SetOption('log', 'debug')
# algo_momentum_correction.SetOption('log', 'debug') # FIXME
algo_eventbuilder_filter.SetOption('pids', [11, 211, -211])
algo_lorentz_transformer.SetOption('frame', 'mirror')

algo_eventbuilder_filter.Start()
algo_lorentz_transformer.Start()
# algo_momentum_correction.Start() # FIXME

iEvent = 0
while(reader.next(banks) and (numEvents==0 or iEvent < numEvents)):
Expand All @@ -42,16 +41,17 @@
pid = particleBank.getInt('pid', row)
if(algo_eventbuilder_filter.Filter(pid)):

px, py, pz, e = algo_lorentz_transformer.Transform(
particleBank.getFloat("px", row),
particleBank.getFloat("py", row),
particleBank.getFloat("pz", row),
0.0,
)

print(f'Accepted PID {pid}:')
print(f' p_old = ({particleBank.getFloat("px", row)}, {particleBank.getFloat("py", row)}, {particleBank.getFloat("pz", row)})')
print(f' p_new = ({px}, {py}, {pz})')
# FIXME: need momentum correction algo
# px, py, pz, e = algo_momentum_correction.Transform(
# particleBank.getFloat("px", row),
# particleBank.getFloat("py", row),
# particleBank.getFloat("pz", row),
# 0.0,
# )
#
# print(f'Accepted PID {pid}:')
# print(f' p_old = ({particleBank.getFloat("px", row)}, {particleBank.getFloat("py", row)}, {particleBank.getFloat("pz", row)})')
# print(f' p_new = ({px}, {py}, {pz})')

algo_eventbuilder_filter.Stop()
algo_lorentz_transformer.Stop()
# algo_momentum_correction.Stop()
5 changes: 2 additions & 3 deletions examples/iguana-example-00-basic.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,14 @@ int main(int argc, char **argv) {
// iguana algorithm sequence
iguana::AlgorithmSequence seq;
seq.Add("clas12::EventBuilderFilter"); // filter by Event Builder PID
seq.Add("clas12::LorentzTransformer"); // Lorentz transform the momenta
// seq.Add("clas12::MomentumCorrection"); // FIXME

// set log levels
seq.SetOption("clas12::EventBuilderFilter", "log", "debug");
seq.SetOption("clas12::LorentzTransformer", "log", "debug");
// seq.SetOption("clas12::MomentumCorrection", "log", "debug"); // FIXME

// set algorithm options
seq.SetOption<std::vector<int>>("clas12::EventBuilderFilter", "pids", {11, 211, -211});
seq.SetOption("clas12::LorentzTransformer", "frame", "mirror");

// start the algorithms
seq.Start(banks);
Expand Down
17 changes: 9 additions & 8 deletions examples/iguana-example-01-bank-rows.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include <iguana/algorithms/clas12/EventBuilderFilter.h>
#include <iguana/algorithms/clas12/LorentzTransformer.h>
// #include <iguana/algorithms/clas12/MomentumCorrection.h> // FIXME
#include <hipo4/reader.h>

int main(int argc, char **argv) {
Expand All @@ -18,19 +18,18 @@ int main(int argc, char **argv) {

// create the algorithms
iguana::clas12::EventBuilderFilter algo_eventbuilder_filter;
iguana::clas12::LorentzTransformer algo_lorentz_transformer;
// iguana::clas12::MomentumCorrection algo_momentum_correction; // FIXME

// set log levels
algo_eventbuilder_filter.SetOption("log", "debug");
algo_lorentz_transformer.SetOption("log", "debug");
// algo_momentum_correction.SetOption("log", "debug"); // FIXME

// set algorithm options
algo_eventbuilder_filter.SetOption<std::vector<int>>("pids", {11, 211, -211});
algo_lorentz_transformer.SetOption("frame", "mirror");

// start the algorithms
algo_eventbuilder_filter.Start();
algo_lorentz_transformer.Start();
// algo_momentum_correction.Start(); // FIXME

// run the algorithm sequence on each event
int iEvent = 0;
Expand All @@ -47,8 +46,9 @@ int main(int argc, char **argv) {
auto pid = particleBank.getInt("pid", row);
if(algo_eventbuilder_filter.Filter(pid)) {

// if accepted PID, transform its momentum with LorentzTransformer
auto [px, py, pz, e] = algo_lorentz_transformer.Transform(
// if accepted PID, correct its momentum
/* FIXME: need momentum correction algo
auto [px, py, pz, e] = algo_momentum_correction.Transform(
particleBank.getFloat("px", row),
particleBank.getFloat("py", row),
particleBank.getFloat("pz", row),
Expand All @@ -63,13 +63,14 @@ int main(int argc, char **argv) {
printMomentum(particleBank.getFloat("px", row), px);
printMomentum(particleBank.getFloat("py", row), py);
printMomentum(particleBank.getFloat("pz", row), pz);
*/

}
}
}

// stop the algorithms
algo_eventbuilder_filter.Stop();
algo_lorentz_transformer.Stop();
// algo_momentum_correction.Stop(); // FIXME
return 0;
}
4 changes: 2 additions & 2 deletions examples/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ foreach src : example_sources
executable(
src.split('.')[0],
src,
include_directories: [ project_inc ] + root_dep_inc_dirs,
include_directories: [ project_inc ] + ROOT_dep_inc_dirs,
dependencies: project_deps,
link_with: project_libs,
link_args: root_dep_link_args,
link_args: ROOT_dep_link_args,
install: true,
install_rpath: ':'.join(project_exe_rpath),
)
Expand Down
22 changes: 10 additions & 12 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ hipo_dep = dependency(
method: 'pkg-config',
version: '>=4.0.1',
)
root_dep = dependency(
ROOT_dep = dependency(
'ROOT',
method: 'cmake',
version: run_command('meson' / 'minimum-version.sh', 'ROOT', check: true).stdout().strip(),
Expand All @@ -51,11 +51,9 @@ root_dep = dependency(
# ordered such that the ones users are *least likely* to try to build
# themselves are listed last (see FIXME in meson/this_iguana.sh.in)
dep_list = []
foreach dep : [ hipo_dep, fmt_dep, yamlcpp_dep, root_dep ]
foreach dep : [ hipo_dep, fmt_dep, yamlcpp_dep, ROOT_dep ]
if dep.found()
dep_list += dep
else
warning(dep.name(), 'is not found; code which depends on it will not be included in this build')
endif
endforeach

Expand All @@ -73,7 +71,7 @@ foreach dep : dep_list
foreach lib : dep.get_variable(cmake: 'PACKAGE_LIBRARIES').split(';')
libdirs += run_command('dirname', lib, check: true).stdout().strip()
endforeach
incdirs = root_dep.get_variable(cmake: 'PACKAGE_INCLUDE_DIRS').split(';')
incdirs = ROOT_dep.get_variable(cmake: 'PACKAGE_INCLUDE_DIRS').split(';')
### error, if unknown
else
error('Cannot determine how dependency "' + dep.name() + '" was found')
Expand All @@ -94,17 +92,17 @@ message('Dependency library dirs = [', ', '.join(dep_lib_paths), ']')
message('Dependency include dirs = [', ', '.join(dep_inc_paths), ']')

# handle ROOT
root_dep_inc_dirs = []
root_dep_link_args = []
if root_dep.found()
root_config = {
ROOT_dep_inc_dirs = []
ROOT_dep_link_args = []
if ROOT_dep.found()
ROOT_config = {
'incdir': run_command('root-config', '--incdir', check: true).stdout().strip(),
'libs': run_command('root-config', '--libs', check: true).stdout().strip(),
}
root_dep_inc_dirs += include_directories(root_config['incdir'])
foreach arg : root_config['libs'].split()
ROOT_dep_inc_dirs += include_directories(ROOT_config['incdir'])
foreach arg : ROOT_config['libs'].split()
if not arg.contains('-rpath') # do not let `root-config` control the rpath
root_dep_link_args += arg
ROOT_dep_link_args += arg
endif
endforeach
endif
Expand Down
106 changes: 65 additions & 41 deletions src/iguana/algorithms/meson.build
Original file line number Diff line number Diff line change
@@ -1,62 +1,86 @@
# algorithm source files
algo_sources = [
'Algorithm.cc',
'AlgorithmFactory.cc',
'AlgorithmSequence.cc',
'example/ExampleAlgorithm.cc',
'clas12/EventBuilderFilter.cc',
'clas12/ZVertexFilter.cc',
'clas12/LorentzTransformer.cc',
'clas12/MomentumCorrection.cc',
]

# algorithm headers
algo_public_headers = [
'Algorithm.h',
'AlgorithmBoilerplate.h',
'AlgorithmSequence.h',
'TypeDefs.h',
'example/ExampleAlgorithm.h',
'clas12/EventBuilderFilter.h',
'clas12/ZVertexFilter.h',
'clas12/LorentzTransformer.h',
'clas12/MomentumCorrection.h',
]

algo_config_files = [
'clas12/ZVertexFilter.yaml',
]

# algorithm unique names and required banks, for those we want to test automatically
algos_and_banks_for_unit_testing = {
'example::ExampleAlgorithm': ['REC::Particle'],
'clas12::EventBuilderFilter': ['REC::Particle'],
'clas12::ZVertexFilter': ['REC::Particle'],
'clas12::LorentzTransformer': ['REC::Particle'],
'clas12::MomentumCorrection': ['REC::Particle', 'RUN::config'],
# dictionary for info about each algorithm
#
# example:
# ========
# ALGORITHM_FULL_NAME: {
# 'sources': LIST_OF_SOURCE FILES,
# 'headers': LIST_OF_HEADER_FILES,
# 'configs': LIST_OF_CONFIG_FILES,
# 'unit_test': DICTIONARY_FOR_UNIT_TESTING_ARGS, # if excluded, unit tests won't run for this algorithm
# 'needs_ROOT': BOOLEAN, # whether this algorithm needs ROOT or not (default=false)
# }
#
algo_dict = {
'main': {
'sources': [ 'Algorithm.cc', 'AlgorithmFactory.cc', 'AlgorithmSequence.cc' ],
'headers': [ 'Algorithm.h', 'AlgorithmBoilerplate.h', 'TypeDefs.h', 'AlgorithmSequence.h' ],
},
'example::ExampleAlgorithm': {
'sources': [ 'example/ExampleAlgorithm.cc' ],
'headers': [ 'example/ExampleAlgorithm.h' ],
'unit_test': { 'banks': ['REC::Particle'] },
},
'clas12::EventBuilderFilter': {
'sources': [ 'clas12/EventBuilderFilter.cc' ],
'headers': [ 'clas12/EventBuilderFilter.h' ],
'unit_test': { 'banks': ['REC::Particle'] },
},
'clas12::ZVertexFilter': {
'sources': [ 'clas12/ZVertexFilter.cc' ],
'headers': [ 'clas12/ZVertexFilter.h' ],
'configs': [ 'clas12/ZVertexFilter.yaml' ],
'unit_test': { 'banks': ['REC::Particle'] },
},
'clas12::LorentzTransformer': {
'sources': [ 'clas12/LorentzTransformer.cc' ],
'headers': [ 'clas12/LorentzTransformer.h' ],
'unit_test': { 'banks': ['REC::Particle'] },
'needs_ROOT': true,
},
'clas12::MomentumCorrection' {
'sources': [ 'clas12/MomentumCorrection.cc' ],
'headers': [ 'clas12/MomentumCorrection.h' ],
'unit_test': { 'banks': ['REC::Particle', 'RUN::config'] },
},
}

# make lists of objects to build; inclusion depends on whether ROOT is needed or not, and if we have ROOT
algo_sources = []
algo_headers = []
algo_configs = []
foreach name, info : algo_dict
needs_ROOT = info.get('needs_ROOT', false)
if (needs_ROOT and ROOT_dep.found()) or not needs_ROOT
algo_sources += info.get('sources', [])
algo_headers += info.get('headers', [])
algo_configs += info.get('configs', [])
else
warning('Excluding algorithm "' + name + '", which depends on ROOT')
endif
endforeach

# build and install
algo_lib = shared_library(
'IguanaAlgorithms',
algo_sources,
include_directories: [ project_inc ] + root_dep_inc_dirs,
include_directories: [ project_inc ] + ROOT_dep_inc_dirs,
dependencies: project_deps,
link_with: services_lib,
link_args: root_dep_link_args,
link_args: ROOT_dep_link_args,
install: true,
install_rpath: project_lib_rpath,
)
project_libs += algo_lib

install_headers(
algo_public_headers,
algo_headers,
subdir: meson.project_name() / 'algorithms',
preserve_path: true,
)

foreach algo_config_file : algo_config_files
foreach algo_config : algo_configs
install_data(
algo_config_file,
algo_config,
install_dir: project_etc,
preserve_path: true,
)
Expand Down
35 changes: 20 additions & 15 deletions src/iguana/tests/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,26 @@ test_exe = executable(

if fs.is_file(get_option('test_data_file'))
message('Test sample file provided; you may run tests with `meson test`')
foreach algo, banks : algos_and_banks_for_unit_testing
bank_args = []
foreach bank : banks
bank_args += ['-b', bank]
endforeach
test(
test_exe_name + ' ' + algo.replace('::', '__'),
test_exe,
args: [
'-c', 'algorithm',
'-f', get_option('test_data_file'),
'-n', get_option('test_num_events'),
'-a', algo
] + bank_args,
)
foreach name, info : algo_dict
if info.has_key('unit_test')
needs_ROOT = info.get('needs_ROOT', false)
if (needs_ROOT and ROOT_dep.found()) or not needs_ROOT
bank_args = []
foreach bank : info['unit_test'].get('banks', [])
bank_args += ['-b', bank]
endforeach
test(
test_exe_name + ' ' + name.replace('::', '__'),
test_exe,
args: [
'-c', 'algorithm',
'-f', get_option('test_data_file'),
'-n', get_option('test_num_events'),
'-a', name
] + bank_args,
)
endif
endif
endforeach
else
stat_file = get_option('test_data_file')=='' ? 'provided' : 'found'
Expand Down

0 comments on commit ab99c70

Please sign in to comment.