Skip to content

Commit

Permalink
Merge branch 'main' into rcdb-sqlite
Browse files Browse the repository at this point in the history
  • Loading branch information
c-dilks authored Oct 25, 2024
2 parents fae9797 + 30ab73b commit c7913e5
Show file tree
Hide file tree
Showing 34 changed files with 1,335 additions and 169 deletions.
12 changes: 8 additions & 4 deletions CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@
#################################################################################

* @c-dilks
src/iguana/algorithms/clas12/EventBuilderFilter/* @c-dilks
src/iguana/algorithms/clas12/FTEnergyCorrection/* @asligonulacar
src/iguana/algorithms/clas12/FiducialFilter/* @Gregtom3
src/iguana/algorithms/clas12/MomentumCorrection/* @RichCap @c-dilks
src/iguana/algorithms/clas12/ZVertexFilter/* @rtysonCLAS12
src/iguana/algorithms/clas12/PhotonGBTFilter/* @Gregtom3
src/iguana/algorithms/clas12/SectorFinder/* @rtysonCLAS12
src/iguana/algorithms/clas12/FTEnergyCorrection/* @asligonulacar
src/iguana/algorithms/clas12/ZVertexFilter/* @rtysonCLAS12
src/iguana/algorithms/physics/DihadronKinematics/* @c-dilks
src/iguana/algorithms/physics/InclusiveKinematics/* @c-dilks
src/iguana/algorithms/physics/SingleHadronKinematics/* @c-dilks
src/iguana/services/YAMLReader.* @rtysonCLAS12 @c-dilks
src/iguana/algorithms/clas12/PhotonGBTFilter/* @Gregtom3
src/iguana/algorithms/clas12/FiducialFilter/* @Gregtom3
2 changes: 2 additions & 0 deletions doc/gen/Doxyfile.in
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,8 @@ ALIASES += end_doc_example="@}"
# ignore things we don't want to document
ALIASES += doxygen_off="@cond NO_DOC"
ALIASES += doxygen_on="@endcond"
# latex
ALIASES += latex{1}="@f$\1@f$"

# Set the OPTIMIZE_OUTPUT_FOR_C tag to YES if your project consists of C sources
# only. Doxygen will then generate output that is more tailored for C. For
Expand Down
14 changes: 6 additions & 8 deletions examples/config/my_combined_config_file.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,15 @@ example::ExampleAlgorithm:

clas12::ZVertexFilter:

# default cuts
- default:
electron_vz: [ -33.0, 11.0 ]
log: debug # NOTE: you may control algorithm log levels here, like so

#RG-A fall2018 inbending
electron:
- default:
vz: [ -33.0, 11.0 ]
- runs: [ 4760, 5419 ]
electron_vz: [ -13.0, 12.0 ]

#RG-A fall2018 outbending
vz: [ -13.0, 12.0 ]
- runs: [ 5420, 5674 ]
electron_vz: [ -18.0, 10.0 ]
vz: [ -18.0, 10.0 ]

another::Algorithm:
#Cuts below are just examples:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
# Cut values for different run periods
clas12::ZVertexFilter:

# default cuts
- default:
electron_vz: [ -15.0, 15.0 ]
# scattered electron cuts
electron:

# RG-A fall2018 inbending
- runs: [ 4760, 5419 ]
electron_vz: [ -5.0, 3.0 ]
# default cuts
- default:
vz: [ -15.0, 15.0 ]

# RG-A fall2018 outbending
- runs: [ 5420, 5674 ]
electron_vz: [ -8.0, 7.0 ]
# RG-A fall2018 inbending
- runs: [ 4760, 5419 ]
vz: [ -5.0, 3.0 ]

# RG-A fall2018 outbending
- runs: [ 5420, 5674 ]
vz: [ -8.0, 7.0 ]
26 changes: 17 additions & 9 deletions examples/config/my_z_vertex_cuts.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
# Cut values for different run periods
clas12::ZVertexFilter:

# default cuts
- default:
electron_vz: [ -1.5, 1.3 ]
###################################################################################
# NOTE: for convenience, you can also set the log level from the configuration file
log: trace
###################################################################################

# RG-A fall2018 inbending
- runs: [ 4760, 5419 ]
electron_vz: [ -0.5, 0.5 ]
# scattered electron cuts
electron:

# RG-A fall2018 outbending
- runs: [ 5420, 5674 ]
electron_vz: [ -0.8, 0.7 ]
# default cuts
- default:
vz: [ -1.5, 1.3 ]

# RG-A fall2018 inbending
- runs: [ 4760, 5419 ]
vz: [ -0.5, 0.5 ]

# RG-A fall2018 outbending
- runs: [ 5420, 5674 ]
vz: [ -0.8, 0.7 ]
4 changes: 3 additions & 1 deletion examples/iguana_ex_fortran_01_action_functions.f
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ program iguana_ex_fortran_01_action_functions
logical(c_bool) accept(N_MAX) ! filter
real(c_double) qx, qy, qz, qE ! q vector
real(c_double) Q2, x, y, W, nu ! inclusive kinematics
real(c_double) beamPz, targetM ! beam and target
integer(c_int) key_vz_filter ! key for Z-vertex filter
integer(c_int) key_inc_kin ! key for inclusive kinematics
Expand Down Expand Up @@ -273,7 +274,8 @@ program iguana_ex_fortran_01_action_functions
& px(i_ele), py(i_ele), pz(i_ele),
& key_inc_kin,
& qx, qy, qz, qE,
& Q2, x, y, W, nu)
& Q2, x, y, W, nu,
& beamPz, targetM)
print *, '===> inclusive kinematics:'
print *, ' q = (', qx, qy, qz, qE, ')'
print *, ' Q2 = ', Q2
Expand Down
2 changes: 2 additions & 0 deletions meson/this_iguana.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ for arg in "$@"; do
unset arg_githubCI
return 2
;;
source*|.*) # handle callers which cause `$1` to be 'source this_iguana.sh' or '. this_iguana.sh'
;;
*)
echo "ERROR: unknown option '$arg'" >&2
unset arg
Expand Down
1 change: 1 addition & 0 deletions meson/ubsan.supp
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ alignment:hipo::structure::getFloatAt
alignment:hipo::structure::getShortAt
alignment:hipo::structure::getDoubleAt
alignment:hipo::structure::putDoubleAt
alignment:hipo::structure::putIntAt
50 changes: 33 additions & 17 deletions src/iguana/algorithms/Algorithm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@ namespace iguana {
template <typename OPTION_TYPE>
OPTION_TYPE Algorithm::GetOptionScalar(std::string const& key, YAMLReader::node_path_t node_path) const
{
try {
CompleteOptionNodePath(key, node_path);
auto opt = GetCachedOption<OPTION_TYPE>(key);
auto val = opt ? opt.value() : m_yaml_config->GetScalar<OPTION_TYPE>(node_path);
PrintOptionValue(key, val);
return val;
CompleteOptionNodePath(key, node_path);
auto opt = GetCachedOption<OPTION_TYPE>(key);
if(!opt.has_value()) {
opt = m_yaml_config->GetScalar<OPTION_TYPE>(node_path);
}
catch(std::runtime_error const& ex) {
m_log->Error("Failed to `GetOptionScalar` for key '{}'", key);
if(!opt.has_value()) {
m_log->Error("Failed to `GetOptionScalar` for key {:?}", key);
throw std::runtime_error("config file parsing issue");
}
PrintOptionValue(key, opt.value());
return opt.value();
}
template int Algorithm::GetOptionScalar(std::string const& key, YAMLReader::node_path_t node_path) const;
template double Algorithm::GetOptionScalar(std::string const& key, YAMLReader::node_path_t node_path) const;
Expand All @@ -37,17 +37,17 @@ namespace iguana {
template <typename OPTION_TYPE>
std::vector<OPTION_TYPE> Algorithm::GetOptionVector(std::string const& key, YAMLReader::node_path_t node_path) const
{
try {
CompleteOptionNodePath(key, node_path);
auto opt = GetCachedOption<std::vector<OPTION_TYPE>>(key);
auto val = opt ? opt.value() : m_yaml_config->GetVector<OPTION_TYPE>(node_path);
PrintOptionValue(key, val);
return val;
CompleteOptionNodePath(key, node_path);
auto opt = GetCachedOption<std::vector<OPTION_TYPE>>(key);
if(!opt.has_value()) {
opt = m_yaml_config->GetVector<OPTION_TYPE>(node_path);
}
catch(std::runtime_error const& ex) {
m_log->Error("Failed to `GetOptionVector` for key '{}'", key);
if(!opt.has_value()) {
m_log->Error("Failed to `GetOptionVector` for key {:?}", key);
throw std::runtime_error("config file parsing issue");
}
PrintOptionValue(key, opt.value());
return opt.value();
}
template std::vector<int> Algorithm::GetOptionVector(std::string const& key, YAMLReader::node_path_t node_path) const;
template std::vector<double> Algorithm::GetOptionVector(std::string const& key, YAMLReader::node_path_t node_path) const;
Expand Down Expand Up @@ -108,19 +108,35 @@ namespace iguana {

void Algorithm::ParseYAMLConfig()
{

// start YAMLReader instance, if not yet started
if(!m_yaml_config) {
// set config files and directories specified by `::SetConfigFile`, `::SetConfigDirectory`, etc.
o_user_config_file = GetCachedOption<std::string>("config_file").value_or("");
o_user_config_dir = GetCachedOption<std::string>("config_dir").value_or("");
m_log->Debug("Instantiating `YAMLReader`");
m_yaml_config = std::make_unique<YAMLReader>("config|" + m_name);
m_yaml_config->SetLogLevel(m_log->GetLevel());
m_yaml_config->SetLogLevel(m_log->GetLevel()); // synchronize log levels
m_yaml_config->AddDirectory(o_user_config_dir);
m_yaml_config->AddFile(m_default_config_file);
m_yaml_config->AddFile(o_user_config_file);
}
else
m_log->Debug("`YAMLReader` already instantiated for this algorithm; using that");

// parse the files
m_yaml_config->LoadFiles();

// if "log" was not set by `SetOption` (i.e., not in `m_option_cache`)
// - NB: not using `GetCachedOption<T>` here, since `T` can be a few different types for key=='log'
if(m_option_cache.find("log") == m_option_cache.end()) {
// check if 'log' is set in the YAML node for this algorithm
auto log_level_from_yaml = m_yaml_config->GetScalar<std::string>({m_class_name, "log"});
if(log_level_from_yaml) {
m_log->SetLevel(log_level_from_yaml.value());
m_yaml_config->SetLogLevel(log_level_from_yaml.value());
}
}
}

///////////////////////////////////////////////////////////////////////////////
Expand Down
13 changes: 6 additions & 7 deletions src/iguana/algorithms/Algorithm.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,7 @@ namespace iguana {
else
m_log->Error("Option '{}' must be a string or a Logger::Level", key);
}
else
m_option_cache[key] = val;
m_option_cache[key] = val;
return val;
}

Expand Down Expand Up @@ -136,17 +135,17 @@ namespace iguana {
/// @param name the directory name
void SetConfigDirectory(std::string const& name);

protected: // methods

/// Parse YAML configuration files. Sets `m_yaml_config`.
void ParseYAMLConfig();

/// Get the index of a bank in a `hipo::banklist`; throws an exception if the bank is not found
/// @param banks the list of banks this algorithm will use
/// @param bank_name the name of the bank
/// returns the `hipo::banklist` index of the bank
hipo::banklist::size_type GetBankIndex(hipo::banklist& banks, std::string const& bank_name) const noexcept(false);

protected: // methods

/// Parse YAML configuration files. Sets `m_yaml_config`.
void ParseYAMLConfig();

/// Get the reference to a bank from a `hipo::banklist`; optionally checks if the bank name matches the expectation
/// @param banks the `hipo::banklist` from which to get the specified bank
/// @param idx the index of `banks` of the specified bank
Expand Down
18 changes: 18 additions & 0 deletions src/iguana/algorithms/AlgorithmSequence.cc
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,22 @@ namespace iguana {
m_log->Print(level, " - {}", algo->GetName());
}

void AlgorithmSequence::SetConfigFileForEachAlgorithm(std::string const& name)
{
for(auto const& algo : m_sequence)
algo->SetConfigFile(name);
}

void AlgorithmSequence::SetConfigDirectoryForEachAlgorithm(std::string const& name)
{
for(auto const& algo : m_sequence)
algo->SetConfigDirectory(name);
}

void AlgorithmSequence::ForEachAlgorithm(std::function<void(algo_t&)> func)
{
for(auto& algo : m_sequence)
func(algo);
}

}
23 changes: 23 additions & 0 deletions src/iguana/algorithms/AlgorithmSequence.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,29 @@ namespace iguana {
/// @param level the log level of the printout
void PrintSequence(Logger::Level level = Logger::info) const;

/// @brief Set a custom configuration file for each algorithm in the sequence
///
/// Use this function if you have a single configuration file for all the
/// algorithms in your sequence
/// @param name the configuration file name
void SetConfigFileForEachAlgorithm(std::string const& name);

/// @brief Set a custom configuration file directory for each algorithm in the sequence
///
/// Use this function if you have a single configuration file directory for all the
/// algorithms in your sequence
/// @param name the directory name
void SetConfigDirectoryForEachAlgorithm(std::string const& name);

/// @brief Call a function for each algorithm in the sequence
///
/// Use as:
/// ```cpp
/// ForEachAlgorithm([](auto& algo){ algo->...; });
/// ```
/// @param func the function to call for each algorithm `algo`
void ForEachAlgorithm(std::function<void(algo_t&)> func);

private:

/// The sequence of algorithms
Expand Down
2 changes: 1 addition & 1 deletion src/iguana/algorithms/clas12/ZVertexFilter/Algorithm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ namespace iguana::clas12 {
std::lock_guard<std::mutex> const lock(m_mutex); // NOTE: be sure to lock successive `ConcurrentParam::Save` calls !!!
m_log->Trace("-> calling Reload({}, {})", runnum, key);
o_runnum->Save(runnum, key);
o_electron_vz_cuts->Save(GetOptionVector<double>("electron_vz", {GetConfig()->InRange("runs", runnum), "electron_vz"}), key);
o_electron_vz_cuts->Save(GetOptionVector<double>("electron_vz", {"electron", GetConfig()->InRange("runs", runnum), "vz"}), key);
}

bool ZVertexFilter::Filter(double const zvertex, int const pid, int const status, concurrent_key_t key) const
Expand Down
22 changes: 12 additions & 10 deletions src/iguana/algorithms/clas12/ZVertexFilter/Config.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
# Cut values for different run periods
clas12::ZVertexFilter:

# default cuts
- default:
electron_vz: [ -20.0, 20.0 ]
# scattered electron cuts
electron:

# RG-A fall2018 inbending
- runs: [ 4760, 5419 ]
electron_vz: [ -13.0, 12.0 ]
# default cuts
- default:
vz: [ -20.0, 20.0 ]

# RG-A fall2018 outbending
- runs: [ 5420, 5674 ]
electron_vz: [ -18.0, 10.0 ]
# RG-A fall2018 inbending
- runs: [ 4760, 5419 ]
vz: [ -13.0, 12.0 ]

# RG-A fall2018 outbending
- runs: [ 5420, 5674 ]
vz: [ -18.0, 10.0 ]
Loading

0 comments on commit c7913e5

Please sign in to comment.