From ab99c700cd15ae5c14b71cd361b9b58046a6f704 Mon Sep 17 00:00:00 2001 From: Christopher Dilks Date: Tue, 20 Feb 2024 12:44:27 -0500 Subject: [PATCH] build: exclude algorithms which depend on ROOT, if we don't have ROOT --- bind/python/iguana-example-00-basic.py | 7 +- bind/python/iguana-example-01-bank-rows.py | 32 +++---- examples/iguana-example-00-basic.cc | 5 +- examples/iguana-example-01-bank-rows.cc | 17 ++-- examples/meson.build | 4 +- meson.build | 22 ++--- src/iguana/algorithms/meson.build | 106 +++++++++++++-------- src/iguana/tests/meson.build | 35 ++++--- 8 files changed, 127 insertions(+), 101 deletions(-) diff --git a/bind/python/iguana-example-00-basic.py b/bind/python/iguana-example-00-basic.py index a0ac992d..dd495511 100755 --- a/bind/python/iguana-example-00-basic.py +++ b/bind/python/iguana-example-00-basic.py @@ -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}') diff --git a/bind/python/iguana-example-01-bank-rows.py b/bind/python/iguana-example-01-bank-rows.py index 6052b4d7..5ddd8bd7 100755 --- a/bind/python/iguana-example-01-bank-rows.py +++ b/bind/python/iguana-example-01-bank-rows.py @@ -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 @@ -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)): @@ -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() diff --git a/examples/iguana-example-00-basic.cc b/examples/iguana-example-00-basic.cc index fa7ca867..d02e2e41 100644 --- a/examples/iguana-example-00-basic.cc +++ b/examples/iguana-example-00-basic.cc @@ -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>("clas12::EventBuilderFilter", "pids", {11, 211, -211}); - seq.SetOption("clas12::LorentzTransformer", "frame", "mirror"); // start the algorithms seq.Start(banks); diff --git a/examples/iguana-example-01-bank-rows.cc b/examples/iguana-example-01-bank-rows.cc index a33ec5e3..70bd70cb 100644 --- a/examples/iguana-example-01-bank-rows.cc +++ b/examples/iguana-example-01-bank-rows.cc @@ -1,5 +1,5 @@ #include -#include +// #include // FIXME #include int main(int argc, char **argv) { @@ -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>("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; @@ -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), @@ -63,6 +63,7 @@ int main(int argc, char **argv) { printMomentum(particleBank.getFloat("px", row), px); printMomentum(particleBank.getFloat("py", row), py); printMomentum(particleBank.getFloat("pz", row), pz); + */ } } @@ -70,6 +71,6 @@ int main(int argc, char **argv) { // stop the algorithms algo_eventbuilder_filter.Stop(); - algo_lorentz_transformer.Stop(); + // algo_momentum_correction.Stop(); // FIXME return 0; } diff --git a/examples/meson.build b/examples/meson.build index 3e59509c..8fe23ffa 100644 --- a/examples/meson.build +++ b/examples/meson.build @@ -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), ) diff --git a/meson.build b/meson.build index 492abf26..e2a9ef7e 100644 --- a/meson.build +++ b/meson.build @@ -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(), @@ -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 @@ -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') @@ -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 diff --git a/src/iguana/algorithms/meson.build b/src/iguana/algorithms/meson.build index e4227bc4..953e725e 100644 --- a/src/iguana/algorithms/meson.build +++ b/src/iguana/algorithms/meson.build @@ -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, ) diff --git a/src/iguana/tests/meson.build b/src/iguana/tests/meson.build index 19842f8c..d4e2fc2f 100644 --- a/src/iguana/tests/meson.build +++ b/src/iguana/tests/meson.build @@ -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'