Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementing Config Files #91

Merged
merged 36 commits into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
1ba7faf
Added functionality to read from INI file, added ZVertexCut as exampl…
Jan 25, 2024
126a4c2
Added documentation for INIReader
Jan 25, 2024
2d8ea0a
changed from INI to YAML, added example for YAMLReader
Jan 26, 2024
d98b704
Merge branch 'main' into ConfigFileTests
c-dilks Jan 26, 2024
43349b5
fix(ci): install `yaml-cpp`
c-dilks Jan 26, 2024
376e4a2
fix(ci): package versions to summary
c-dilks Jan 26, 2024
3a8c86f
fix(ci): `apt` needs `sudo`
c-dilks Jan 26, 2024
06b597d
ci: send version info directly to summary stream
c-dilks Jan 26, 2024
5db28d6
Revert "ci: send version info directly to summary stream"
c-dilks Jan 26, 2024
ade3eb8
fix(ci): syntax
c-dilks Jan 26, 2024
cfd9286
fix(ci): `pkg_summary` must be last
c-dilks Jan 26, 2024
eae5c79
fix(ci): `working-directory`
c-dilks Jan 26, 2024
2abf54c
fix(ci): package installer must fail correctly
c-dilks Jan 26, 2024
6e79fd3
fix(ci): `yaml-cpp` package name on Linux
c-dilks Jan 26, 2024
0b955af
ci: add tests 02 and 03
c-dilks Jan 27, 2024
ff3e188
fix(ci): dir
c-dilks Jan 27, 2024
8d0204e
fix(ci): `apt update`
c-dilks Jan 27, 2024
d4da0f6
fix: `yes`
c-dilks Jan 27, 2024
01928dc
build: install config files
c-dilks Jan 29, 2024
b0b5410
feat: add `yaml` to `resolve-dependencies.py`
c-dilks Jan 30, 2024
53949fe
fix(build): strip `config`
c-dilks Jan 30, 2024
5292ada
feat: configuration file manager
c-dilks Jan 30, 2024
b5cb161
fix: use `AlgorithmSequence`'s config file manager in each of its alg…
c-dilks Jan 30, 2024
a499686
fix: configuration manager setters and getters
c-dilks Jan 30, 2024
bb7c0cd
ci: revert dependency installation changes
c-dilks Feb 1, 2024
625446e
Merge remote-tracking branch 'origin/main' into ConfigFileTests
c-dilks Feb 1, 2024
eda5771
ci: update `yaml-cpp` installation
c-dilks Feb 1, 2024
f145b57
fix: don't feed example 02 a file
c-dilks Feb 1, 2024
01eed49
fix: don't rely on default `sysconfdir` override
c-dilks Feb 1, 2024
bf09ad3
fix: set AlgorithmSequence's algorithm config file manager in the mos…
c-dilks Feb 2, 2024
f2f5b4f
doc: add `yaml-cpp` to dependency list
c-dilks Feb 9, 2024
56cac3d
fix: spelling
c-dilks Feb 9, 2024
a7ab9b9
refactor: revert `Algorithm` constructor
c-dilks Feb 9, 2024
733c411
refactor!: `Algorithm:GetConfigFileManager` returns lvalue reference
c-dilks Feb 9, 2024
7b7261f
refactor: mindor cleanup
c-dilks Feb 9, 2024
b57017a
fix: option members prefix with `o_`
c-dilks Feb 9, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions .github/install-dependency-packages.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/bin/bash

set -e

PACKAGE_LIST_MACOS=(
fmt
yaml-cpp
tree
)

PACKAGE_LIST_LINUX=(
libyaml-cpp-dev
)

##################################

if [ $# -ne 1 ]; then
echo "USAGE: $0 [runner]" >&2
exit 2
fi
runner=$1

##################################

summary_file=pkg_summary.md
> $summary_file

if [[ "$runner" =~ "macos" ]]; then
echo "[+] On macOS runner"
for pkg in ${PACKAGE_LIST_MACOS[@]}; do
echo "[+] INSTALLING $pkg"
brew install $pkg
if [ ! "$pkg" = "tree" ]; then
echo "| \`$pkg\` | $(brew info $pkg | head -n1) |" >> $summary_file
fi
done
elif [[ "$runner" =~ "ubuntu" ]]; then
echo "[+] On Linux runner"
for pkg in ${PACKAGE_LIST_LINUX[@]}; do
echo "[+] INSTALLING $pkg"
sudo apt -y install $pkg
echo "| \`$pkg\` | $(apt show $pkg | grep -E '^Version:') |" >> $summary_file
done
else
echo "ERROR: runner '$runner' is unknown to $0" >&2
exit 1
fi
34 changes: 11 additions & 23 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,6 @@ jobs:
cmake --build build -j${{ inputs.num_threads }}
cmake --install build
tar czvf hipo{.tar.gz,}
- run: brew install tree
if: ${{ inputs.runner == 'macos-latest' }}
- run: tree hipo
- uses: actions/upload-artifact@v4
with:
name: build_deps_hipo
Expand All @@ -68,8 +65,6 @@ jobs:
cmake --build build -j${{ inputs.num_threads }}
cmake --install build
tar czvf fmt{.tar.gz,}
- run: tree fmt
if: ${{ inputs.runner != 'macos-latest' }}
- uses: actions/upload-artifact@v4
if: ${{ inputs.runner != 'macos-latest' }}
with:
Expand Down Expand Up @@ -108,10 +103,11 @@ jobs:
with:
pattern: build_deps_*
merge-multiple: true
- run: brew install fmt
if: ${{ inputs.runner == 'macos-latest' }}
- name: install dependencies from package manager
run: .github/install-dependency-packages.sh ${{ inputs.runner }}
- name: untar build
run: ls *.tar.gz | xargs -I{} tar xzvf {}
- run: tree
- name: summarize dependencies
run: |
echo '### Dependencies' >> $GITHUB_STEP_SUMMARY
Expand All @@ -120,16 +116,11 @@ jobs:
for dep in python meson ninja ; do
echo "| \`$dep\` | $($dep --version) |" >> $GITHUB_STEP_SUMMARY
done
if [ "${{ inputs.runner }}" = "macos-latest" ]; then
echo "| \`fmt\` | $(brew info fmt | head -n1) |" >> $GITHUB_STEP_SUMMARY
else
if [[ "${{ inputs.runner }}" =~ "ubuntu" ]]; then
echo "| \`fmt\` | ${{ env.fmt_version }} |" >> $GITHUB_STEP_SUMMARY
fi
echo "| \`hipo\` | ${{ env.hipo_version }} |" >> $GITHUB_STEP_SUMMARY
### tree
- run: brew install tree
if: ${{ inputs.runner == 'macos-latest' }}
- run: tree
cat pkg_summary.md | xargs -0 -I{} echo {} >> $GITHUB_STEP_SUMMARY
### build iguana
- name: resolve dependencies
run: |
Expand Down Expand Up @@ -239,8 +230,9 @@ jobs:
with:
pattern: build_deps_*
merge-multiple: true
- run: brew install fmt
if: ${{ inputs.runner == 'macos-latest' }}
- name: install dependencies from package manager
run: .github/install-dependency-packages.sh ${{ inputs.runner }}
working-directory: iguana_src
- name: get iguana build artifacts
uses: actions/download-artifact@v4
with:
Expand All @@ -253,11 +245,7 @@ jobs:
run: |
ls *.tar.gz | xargs -I{} tar xzvf {}
rm -v *.tar.gz
### tree
- run: brew install tree
if: ${{ inputs.runner == 'macos-latest' }}
- name: tree artifacts
run: tree
- run: tree
### set env vars - depends on runner and binding
- name: source environment for Linux and python
if: ${{ inputs.runner == 'ubuntu-latest' && matrix.binding == 'python' }}
Expand Down Expand Up @@ -300,8 +288,8 @@ jobs:
with:
pattern: build_deps_*
merge-multiple: true
- run: brew install fmt
if: ${{ inputs.runner == 'macos-latest' }}
- name: install dependencies from package manager
run: .github/install-dependency-packages.sh ${{ inputs.runner }}
- name: get iguana build artifacts
uses: actions/download-artifact@v4
with:
Expand Down
63 changes: 63 additions & 0 deletions examples/config_files/ex2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#some random single values and arrays
myIntVector:
- 1
- 2
- 3

myDoubleVector:
- 1.1
- 2.2
- 3.3

myStringVector:
- "apple"
- "banana"
- "cherry"

myInt: 42
myDouble: 3.14
myString: "Hello, YAML!"

# ZVertex Cut values for different run periods used as examples
#If you want to have run period dependent cuts please stick to this format.
cuts:
- runs: #RG-A fall2018 inbending
- 4760
- 5419
vals:
- -13.0
- 12.0

- runs: #RG-A fall2018 outbending
- 5420
- 5674
vals:
- -18.0
- 10.0

#Cuts below are just examples:
#No one defined pid/sector dependent cuts on vz
#No one defined RG-B specifict cuts on vz
#single structure probably does not make send
- runs: #RG-B spring2019
- 6141
- 6606
pid:
11:
- -10.0
- 11.0
211:
- -15.0
- 20.0
sector:
5:
- -5
- 5
single: #single values instead of arrays
0: -6
1: 14





105 changes: 105 additions & 0 deletions examples/iguana-example-02-YAMLReader.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
#include <iguana/services/YAMLReader.h>

int main(int argc, char **argv)
{

// parse arguments
int argi = 1;
const char *inFileName = argc > argi ? argv[argi++] : "../../examples/config_files/ex2.yaml";

//Below we access cut values defined for different and different pids.
//There's a series of key we need to use
//First the cutkey relates to the array containing all runperiods.
std::string cutKey="cuts";

//second the runkey relates to each run period.
std::string runKey="runs";

//the pidkey relates to the pid dependent cuts.
//Note we could have sector dependent cuts too (but not both atm).
std::string pidKey="pid";
std::string secKey="sector";

//finally the values key relates to the actual cut values.
std::string valKey="vals";

//If a pid dependence is not specified for a given run period the reader
// will still get the cut values for that run period.
//We could pass any pid value at thsat point.

int runnb = 4768;
int pid=0;
iguana::YAMLReader yamlr(inFileName);
std::vector<double> cutvalues = yamlr.findKeyAtRunAndPIDVector<double>(cutKey,runKey,pidKey,valKey,runnb, pid, {-20.0, 20.0});

std::cout<<"\nFor run "<<runnb<<" no restriction on pid "<<std::endl;
std::cout<<"Cut value low "<<cutvalues[0]<<" high "<<cutvalues[1]<<std::endl;

runnb = 5423;
cutvalues = yamlr.findKeyAtRunAndPIDVector<double>(cutKey,runKey,pidKey,valKey,runnb, pid, {-20.0, 20.0});

std::cout<<"\nFor run "<<runnb<<" no restriction on pid "<<std::endl;
std::cout<<"Cut value low "<<cutvalues[0]<<" high "<<cutvalues[1]<<std::endl;

runnb = 6143;
pid=11;
cutvalues = yamlr.findKeyAtRunAndPIDVector<double>(cutKey,runKey,pidKey,valKey,runnb, pid, {-20.0, 20.0});

std::cout<<"\nFor run "<<runnb<<" and pid "<<pid<<std::endl;
std::cout<<"Cut value low "<<cutvalues[0]<<" high "<<cutvalues[1]<<std::endl;

pid=211;
cutvalues = yamlr.findKeyAtRunAndPIDVector<double>(cutKey,runKey,pidKey,valKey,runnb, pid, {-20.0, 20.0});

std::cout<<"\nFor run "<<runnb<<" and pid "<<pid<<std::endl;
std::cout<<"Cut value low "<<cutvalues[0]<<" high "<<cutvalues[1]<<std::endl;

//now switching to sector key instead of pid
int sector=5;
cutvalues = yamlr.findKeyAtRunAndPIDVector<double>(cutKey,runKey,secKey,valKey, runnb, sector, {-20.0, 20.0});

std::cout<<"\nFor run "<<runnb<<" and sector "<<sector<<std::endl;
std::cout<<"Cut value low "<<cutvalues[0]<<" high "<<cutvalues[1]<<std::endl;

//now getting individual values
int l=0;
int h=1;
double low = yamlr.findKeyAtRunAndPID<double>(cutKey,runKey,"single",valKey, runnb, l, -20);
double high = yamlr.findKeyAtRunAndPID<double>(cutKey,runKey,"single",valKey, runnb, h, 20);

std::cout<<"\nFor run "<<runnb<<std::endl;
std::cout<<"Cut value low "<<low<<" high "<<high<<std::endl;

//Accessing a run that doesn't have a corresponding range returns default
//Same if we did PID or sector that doesn't exist
runnb = 4;
cutvalues = yamlr.findKeyAtRunAndPIDVector<double>(cutKey,runKey,pidKey,valKey,runnb, pid, {-20.0, 20.0});

std::cout<<"\nFor run "<<runnb<<" and pid "<<pid<<std::endl;
std::cout<<"Cut value low "<<cutvalues[0]<<" high "<<cutvalues[1]<<std::endl;

//Now we just get some single values
int mi = yamlr.readValue("myInt",0);
double md = yamlr.readValue("myDouble",0.0);
std::string ms= yamlr.readValue<std::string>("myString","");//force template to use std::string not char const*

std::cout<<"\nSingle values"<<std::endl;
std::cout<<"myInt "<<mi<<" myDouble "<<md<<" myString "<<ms<<std::endl;

//Now we just get some individual arrays
std::vector<int> miv = yamlr.readArray<int>("myIntVector",{});
std::vector<double> mdv = yamlr.readArray<double>("myDoubleVector",{});
std::vector<std::string> msv= yamlr.readArray<std::string>("myStringVector",{});

std::cout<<"\nIndividual Arrays"<<std::endl;
std::cout<<"myIntVector: ";
for(auto& val:miv){std::cout<<val<<" ";}
std::cout<<std::endl;
std::cout<<"myDoubleVector: ";
for(auto& val:mdv){std::cout<<val<<" ";}
std::cout<<std::endl;
std::cout<<"myStringVector: ";
for(auto& val:msv){std::cout<<val<<" ";}
std::cout<<std::endl;

}
55 changes: 55 additions & 0 deletions examples/iguana-example-03-zvertex-filter.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#include <iguana/algorithms/AlgorithmSequence.h>
#include <hipo4/reader.h>
#include <sstream>

// show a bank along with a header
void prettyPrint(std::string header, hipo::bank &bank)
{
fmt::print("{:=^70}\n", " " + header + " ");
bank.show();
}

int main(int argc, char **argv)
{

// parse arguments
int argi = 1;
const char *inFileName = argc > argi ? argv[argi++] : "data.hipo";
const int numEvents = argc > argi ? std::stoi(argv[argi++]) : 1;

// read input file
hipo::reader reader(inFileName);

// set banks
hipo::banklist banks = reader.getBanks({"REC::Particle"});
enum banks_enum
{
b_particle
}; // TODO: users shouldn't have to do this

// iguana algorithm sequence
iguana::AlgorithmSequence seq;

seq.Add("clas12::ZVertexFilter"); // filter by Event Builder PID

// set log levels
seq.SetOption("clas12::ZVertexFilter", "log", "debug");

// set algorithm options - if we don't set these, the default values from config files are used.
// seq.SetOption<std::vector<double>>("clas12::ZVertexFilter", "low&high", {-13.0,12.0});

// start the algorithms
seq.Start(banks);

// run the algorithm sequence on each event
int iEvent = 0;
while (reader.next(banks) && (numEvents == 0 || iEvent++ < numEvents))
{
prettyPrint("BEFORE", banks.at(b_particle));
seq.Run(banks);
prettyPrint("AFTER", banks.at(b_particle));
}

// stop algorithms
seq.Stop();
}
2 changes: 2 additions & 0 deletions examples/meson.build
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
example_sources = [
'iguana-example-00-basic.cc',
'iguana-example-01-bank-rows.cc',
'iguana-example-02-YAMLReader.cc',
'iguana-example-03-zvertex-filter.cc',
]

# add dependencies' libraries to rpath
Expand Down
2 changes: 2 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ project_description = 'Implementation Guardian of Analysis Algorithms'
# resolve dependencies
fmt_dep = dependency('fmt', version: '>=9.1.0', method: 'pkg-config')
hipo_dep = dependency('hipo4', version: '>=4.0.1', method: 'pkg-config')
yamlcpp_dep = dependency('yaml-cpp', version: '>=0.8.0', method: 'pkg-config')
c-dilks marked this conversation as resolved.
Show resolved Hide resolved

# list of dependencies
# FIXME: for users which use LD_LIBRARY_PATH, we should try to keep this list
Expand All @@ -28,6 +29,7 @@ hipo_dep = dependency('hipo4', version: '>=4.0.1', method: 'pkg-config')
full_dep_list = [
hipo_dep,
fmt_dep,
yamlcpp_dep,
]

# dependency libdirs
Expand Down
1 change: 1 addition & 0 deletions src/iguana/algorithms/Algorithm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ namespace iguana {
else if (const auto valPtr(std::get_if<double>(&val)); valPtr) return fmt::format("{} [{}]", *valPtr, "double");
else if (const auto valPtr(std::get_if<std::string>(&val)); valPtr) return fmt::format("{} [{}]", *valPtr, "string");
else if (const auto valPtr(std::get_if<std::vector<int>>(&val)); valPtr) return fmt::format("({}) [{}]", fmt::join(*valPtr,", "), "vector<int>");
else if (const auto valPtr(std::get_if<std::vector<double>>(&val)); valPtr) return fmt::format("({}) [{}]", fmt::join(*valPtr,", "), "vector<double>");
else {
m_log->Error("option '{}' type has no printer defined in Algorithm::PrintOptionValue", key);
return "UNKNOWN";
Expand Down
Loading
Loading