Skip to content

Commit

Permalink
feat+build: improve algorithm configuration; colored log output; impr…
Browse files Browse the repository at this point in the history
…ove dependency resolution (#20)
  • Loading branch information
c-dilks authored Nov 29, 2023
1 parent 4f3aaa2 commit 0b62279
Show file tree
Hide file tree
Showing 19 changed files with 249 additions and 67 deletions.
53 changes: 43 additions & 10 deletions .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,13 @@ defaults:
run:
shell: bash

env:
hipo_version: 94e2cfc1ab93388680ba07088d9b63b68347ba92 # before hipo::bank::get and put were removed
fmt_version: 9.1.0

jobs:

# build
# dependencies
#########################################################

build_hipo:
Expand All @@ -27,9 +31,10 @@ jobs:
uses: actions/checkout@v4
with:
repository: gavalian/hipo
ref: ${{ env.hipo_version }}
- name: build
run: |
cmake -S . -B build -DCMAKE_INSTALL_PREFIX=hipo
cmake -S . -B build -DCMAKE_INSTALL_PREFIX=hipo -DCMAKE_POSITION_INDEPENDENT_CODE=ON
cmake --build build -j2
cmake --install build
- run: tree hipo
Expand All @@ -41,14 +46,40 @@ jobs:
retention-days: 1
path: hipo.tar.gz

build_fmt:
name: Build fmt
runs-on: ubuntu-latest
steps:
- name: checkout fmt
uses: actions/checkout@v4
with:
repository: fmtlib/fmt
ref: ${{ env.fmt_version }}
- name: build
run: |
cmake -S . -B build -DCMAKE_INSTALL_PREFIX=fmt -DCMAKE_POSITION_INDEPENDENT_CODE=ON
cmake --build build -j2
cmake --install build
- run: tree fmt
- name: tar
run: tar czvf fmt{.tar.gz,}
- uses: actions/upload-artifact@v3
with:
name: build
retention-days: 1
path: fmt.tar.gz

# build
#########################################################

build_iguana:
name: Build Iguana
needs: [ build_hipo ]
needs:
- build_hipo
- build_fmt
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: setup fmt
run: sudo apt install -y libfmt-dev
- name: setup meson
run: python -m pip install meson ninja
- name: summarize dependencies
Expand All @@ -59,15 +90,17 @@ jobs:
for dep in python ruby meson ninja ; do
echo "| \`$dep\` | $($dep --version) |" >> $GITHUB_STEP_SUMMARY
done
echo "| \`fmt\` | $(apt show libfmt-dev | grep -w Version) |" >> $GITHUB_STEP_SUMMARY
echo "| \`fmt\` | ${{ env.fmt_version }} |" >> $GITHUB_STEP_SUMMARY
echo "| \`hipo\` | ${{ env.hipo_version }} |" >> $GITHUB_STEP_SUMMARY
- name: get build artifacts
uses: actions/download-artifact@v3
with:
name: build
- name: untar build
run: ls *.tar.gz | xargs -I{} tar xzvf {}
- run: tree
- name: build iguana
run: ./install.rb --hipo hipo
run: ./install.rb --hipo hipo --fmt fmt
- name: dump build log
if: always()
run: cat build-iguana/meson-logs/meson-log.txt
Expand Down Expand Up @@ -108,11 +141,11 @@ jobs:

test_iguana:
name: Test Iguana
needs: [ download_validation_files, build_iguana ]
needs:
- download_validation_files
- build_iguana
runs-on: ubuntu-latest
steps:
- name: install dependencies
run: sudo apt install -y libfmt-dev
- name: get build artifacts
uses: actions/download-artifact@v3
with:
Expand Down
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
# build artifacts
*.ini
/build*/
/iguana
/bin
/include
/lib

# dependencies
hipo
Expand Down
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,17 @@ install.rb --help # print the usage guide
install.rb # default: install to ./iguana
```
Alternatively, use `meson` for more control.

## Troubleshooting Notes

- if you redirect `stdout` and `stderr` to a file, you may notice that `stderr` lines are out-of-order with respect to the `stdout` lines; for example:
```bash
myAnalysisProgram # stdout and stderr print when they happen; ordering appears correct

myAnalysisProgram |& tee output.txt # stderr prints when it happens, but stdout only prints when its buffer is full;
# ordering appears mixed up
```
To redirect output to a file with the ordering preserved, run your executable with `stdout` unbuffered:
```bash
stdbuf -o0 myAnalysisProgram |& tee output.txt
```
53 changes: 39 additions & 14 deletions install.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
build: "#{Dir.pwd}/build-iguana",
install: "#{Dir.pwd}/iguana",
hipo: "#{Dir.pwd}/hipo",
fmt: nil,
clean: false,
purge: false,
}
Expand All @@ -22,20 +23,32 @@
parser.separator ''
parser.on("-i", "--install [INSTALL DIR]", "Directory for installation", "Default: #{options[:install]}")
parser.separator ''
parser.on("-h", "--hipo [HIPO DIR]", "Path to HIPO installation", "Default: #{options[:hipo]}", "if not found, tries env var $HIPO")
parser.on("--hipo [HIPO DIR]", "Path to HIPO installation", "Default: #{options[:hipo]}", "if not found, tries env var $HIPO")
parser.on("--fmt [FMT DIR]", "Path to fmt installation", "Default: assumes system installation" )
parser.separator 'TROUBLESHOOTING:'
parser.on("--clean", "Remove the buildsystem at [BUILD DIR] beforehand")
parser.on("--purge", "Remove the installation at [INSTALL DIR] beforehand")
parser.parse!(into: options)

# check for HIPO installation, or fallback to $HIPO
options[:hipo] = ENV['HIPO'] unless Dir.exists? options[:hipo]

# use realpaths for dependencies
[ :hipo, :fmt ].each do |dep|
unless options[dep].nil?
if Dir.exists? options[dep]
options[dep] = File.realpath options[dep]
else
$stderr.puts "ERROR: directory '#{options[dep]}' for option '--#{dep.to_s}' does not exist"
exit 1
end
end
end

# print the options
puts "SET OPTIONS:"
options.each do |k,v| puts "#{k.to_s.rjust 15} => #{v}" end

# check for HIPO installation, or fallback to $HIPO
options[:hipo] = ENV['HIPO'] unless Dir.exists? options[:hipo]
options[:hipo] = File.realpath options[:hipo] if Dir.exists? options[:hipo]

# clean and purge
def rmDir(dir,obj='files')
print "\nRemove #{obj} at #{dir} ?\n[y/N] > "
Expand All @@ -56,30 +69,42 @@ def rmDir(dir,obj='files')
FileUtils.mkdir_p options[:install]
prefix = File.realpath options[:install]

# set dependency package paths
cmake_prefix_path = [ options[:hipo] ].compact
pkg_config_path = [ options[:fmt] ].compact.map{ |path| path += '/lib/pkgconfig' }

# generate native INI file
def singleQuotes(arr)
"#{arr}".gsub /"/, "'"
end
native_ini = options[:build] + '.ini'
native_file = File.open native_ini, 'w'
native_file.puts """[built-in options]
; dependency paths
cmake_prefix_path = #{singleQuotes cmake_prefix_path}
pkg_config_path = #{singleQuotes pkg_config_path}
; installation
prefix = '#{prefix}'
"""
native_file.close

# print and run a command
def runCommand(cmd)
puts "[+++] #{cmd}"
system cmd or raise "FAILED: #{cmd}"
end

# set a build option
def buildOpt(key,val)
val.nil? ? '' : "-D#{key}='#{val}'"
end

# meson commands
meson = {
:setup => [
'meson setup',
"--prefix #{prefix}",
buildOpt('hipo', options[:hipo]),
"--native-file #{native_ini}",
options[:build],
SourceDir,
],
:config => [
'meson configure',
"--prefix #{prefix}",
buildOpt('hipo', options[:hipo]),
"--native-file #{native_ini}",
options[:build],
],
:install => [
Expand Down
13 changes: 6 additions & 7 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,16 @@ project(

project_inc = include_directories('src')

project_lib_install_dir = 'lib' # to keep it the same for different Linux distributions
project_bin_install_dir = 'bin'
dep_lib_rpaths = [ ]
foreach path : get_option('cmake_prefix_path')
dep_lib_rpaths += path + '/lib' # TODO: this adds hipo4 libs to the rpath; consider instead linking against hipo4 static lib
endforeach

project_lib_rpath = '$ORIGIN'
project_bin_rpath = ':'.join([
'$ORIGIN/../' + project_lib_install_dir,
get_option('hipo') + '/lib'
])
project_bin_rpath = ':'.join( dep_lib_rpaths + [ '$ORIGIN/../' + get_option('libdir') ] )

hipo_dep = dependency('hipo4')
fmt_dep = dependency('fmt')
hipo_dep = dependency('hipo4', method: 'cmake', cmake_args: '-DCMAKE_PREFIX_PATH=' + get_option('hipo'))

subdir('src/services')
subdir('src/algorithms')
Expand Down
1 change: 0 additions & 1 deletion meson.options

This file was deleted.

27 changes: 14 additions & 13 deletions src/algorithms/clas12/event_builder_filter/EventBuilderFilter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,31 @@
namespace iguana::clas12 {

EventBuilderFilter::EventBuilderFilter() : Algorithm("event_builder_filter") {
m_requiredBanks = {
"REC::Particle",
"REC::Calorimeter"
};

// define required banks
m_requiredBanks = { "REC::Particle", "REC::Calorimeter" }; // TODO: remove calorimeter

}

void EventBuilderFilter::Start(bank_index_cache_t &index_cache) {

// set configuration
m_log->SetLevel(Logger::Level::trace);
m_log->Debug("START {}", m_name);
m_opt.pids = {11, 211, -211};
// define options, their default values, and cache them
CacheOption("pids", std::set<int>{11, 211}, o_pids);
CacheOption("testInt", 8, o_testInt); // TODO: remove
CacheOption("testFloat", 7.0, o_testFloat); // TODO: remove

// cache expected bank indices
CacheBankIndex(index_cache, b_particle, "REC::Particle");
CacheBankIndex(index_cache, b_calo, "REC::Calorimeter");
CacheBankIndex(index_cache, b_calo, "REC::Calorimeter"); // TODO: remove

}


void EventBuilderFilter::Run(bank_vec_t banks) {
m_log->Debug("RUN {}", m_name);

// get the banks
auto particleBank = GetBank(banks, b_particle, "REC::Particle");
auto caloBank = GetBank(banks, b_calo, "REC::Calorimeter");
auto caloBank = GetBank(banks, b_calo, "REC::Calorimeter"); // TODO: remove

// dump the bank
ShowBank(particleBank, Logger::Header("INPUT PARTICLES"));
Expand All @@ -48,12 +47,14 @@ namespace iguana::clas12 {


bool EventBuilderFilter::Filter(int pid) {
return m_opt.pids.find(pid) != m_opt.pids.end();
return o_pids.find(pid) != o_pids.end();
}


void EventBuilderFilter::Stop() {
m_log->Debug("STOP {}", m_name);
m_log->Info("test info");
m_log->Warn("test warn");
m_log->Error("test error");
}

}
16 changes: 8 additions & 8 deletions src/algorithms/clas12/event_builder_filter/EventBuilderFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,6 @@

namespace iguana::clas12 {

class EventBuilderFilterOptions {
public:
std::set<int> pids = {11, 211};
};


class EventBuilderFilter : public Algorithm {

public:
Expand All @@ -25,8 +19,14 @@ namespace iguana::clas12 {
bool Filter(int pid);

private:
EventBuilderFilterOptions m_opt;
int b_particle, b_calo;

/// `bank_vec_t` indices
int b_particle, b_calo; // TODO: remove calorimeter

/// configuration options
std::set<int> o_pids;
int o_testInt; // TODO: remove
double o_testFloat; // TODO: remove

};

Expand Down
1 change: 0 additions & 1 deletion src/algorithms/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ algo_lib = shared_library(
dependencies: services_dep,
link_with: services_lib,
install: true,
install_dir: project_lib_install_dir,
install_rpath: project_lib_rpath,
)

Expand Down
1 change: 0 additions & 1 deletion src/iguana/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ iguana_lib = shared_library(
dependencies: [ fmt_dep, hipo_dep ],
link_with: [ algo_lib, services_lib ],
install: true,
install_dir: project_lib_install_dir,
install_rpath: project_lib_rpath,
)

Expand Down
Loading

0 comments on commit 0b62279

Please sign in to comment.