| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "RCDBReader.h" | ||
| 2 | #include "GlobalParam.h" | ||
| 3 | #include "iguana/algorithms/TypeDefs.h" | ||
| 4 | |||
| 5 | #ifdef USE_RCDB | ||
| 6 | // include the RCDB headers here, to avoid ODR violations | ||
| 7 | #include <RCDB/Connection.h> | ||
| 8 | #endif | ||
| 9 | |||
| 10 | namespace iguana { | ||
| 11 | |||
| 12 | 8 | RCDBReader::RCDBReader(std::string_view name, Logger::Level lev) | |
| 13 |
2/4✓ Branch 3 → 4 taken 8 times.
✗ Branch 3 → 120 not taken.
✓ Branch 4 → 5 taken 8 times.
✗ Branch 4 → 104 not taken.
|
8 | : Object(name, lev) |
| 14 | { | ||
| 15 | #ifdef USE_RCDB | ||
| 16 | |||
| 17 | // choose the RCDB URL, from the following priority ordering | ||
| 18 | // 1. try `GlobalRcdbUrl` | ||
| 19 |
3/6✓ Branch 4 → 5 taken 8 times.
✗ Branch 4 → 104 not taken.
✓ Branch 5 → 6 taken 8 times.
✗ Branch 5 → 74 not taken.
✗ Branch 12 → 13 not taken.
✓ Branch 12 → 24 taken 8 times.
|
16 | m_url = GlobalRcdbUrl(); |
| 20 |
1/2✗ Branch 12 → 13 not taken.
✓ Branch 12 → 24 taken 8 times.
|
8 | if(!m_url.empty()) |
| 21 | ✗ | m_log->Debug("RCDB URL set from 'iguana::GlobalRcdbUrl': {:?}", m_url); | |
| 22 | else { | ||
| 23 | // 2. try env var `RCDB_CONNECTION` | ||
| 24 |
1/2✓ Branch 25 → 26 taken 8 times.
✗ Branch 25 → 34 not taken.
|
8 | if(auto url_ptr{std::getenv("RCDB_CONNECTION")}; url_ptr != nullptr) |
| 25 |
1/2✓ Branch 26 → 27 taken 8 times.
✗ Branch 26 → 104 not taken.
|
16 | m_url = std::string(url_ptr); |
| 26 |
1/2✓ Branch 34 → 35 taken 8 times.
✗ Branch 34 → 46 not taken.
|
8 | if(!m_url.empty()) |
| 27 |
2/6✓ Branch 39 → 40 taken 8 times.
✗ Branch 39 → 86 not taken.
✗ Branch 40 → 41 not taken.
✓ Branch 40 → 43 taken 8 times.
✗ Branch 86 → 87 not taken.
✗ Branch 86 → 89 not taken.
|
16 | m_log->Debug("RCDB URL set from env var 'RCDB_CONNECTION': {:?}", m_url); |
| 28 | else { | ||
| 29 | // 3. fallback to default value | ||
| 30 | ✗ | m_log->Warn("RCDB URL not set; you may choose a URL with the environment variable 'RCDB_CONNECTION' or with the global parameter 'iguana::GlobalRcdbUrl'; for now, let's proceed with the URL set to {:?}", m_default_url); | |
| 31 | m_url = m_default_url; | ||
| 32 | ✗ | m_log->Debug("RCDB URL set from default fallback: {:?}", m_url); | |
| 33 | } | ||
| 34 | } | ||
| 35 | |||
| 36 | // then start the connection | ||
| 37 |
1/4✓ Branch 69 → 70 taken 8 times.
✗ Branch 69 → 104 not taken.
✗ Branch 104 → 105 not taken.
✗ Branch 104 → 107 not taken.
|
8 | m_rcdb_connection = std::make_unique<rcdb::Connection>(m_url, true); |
| 38 | |||
| 39 | #endif | ||
| 40 | 8 | } | |
| 41 | |||
| 42 | ////////////////////////////////////////////////////////////////////////////////// | ||
| 43 | |||
| 44 |
1/2✓ Branch 2 → 3 taken 8 times.
✗ Branch 2 → 5 not taken.
|
16 | RCDBReader::~RCDBReader() = default; |
| 45 | |||
| 46 | ////////////////////////////////////////////////////////////////////////////////// | ||
| 47 | |||
| 48 | 8 | double RCDBReader::GetBeamEnergy(int const runnum) | |
| 49 | { | ||
| 50 | 8 | double const default_value = 10.6; | |
| 51 | // if override value is set, return it | ||
| 52 |
1/2✓ Branch 2 → 3 taken 8 times.
✗ Branch 2 → 21 not taken.
|
8 | if(m_beam_energy_override >= 0) |
| 53 | return m_beam_energy_override; | ||
| 54 | // if it's an MC run (pre real-run numbers), return the override value | ||
| 55 |
1/2✗ Branch 3 → 4 not taken.
✓ Branch 3 → 6 taken 8 times.
|
8 | if(runnum == MC_RUN_NUM) { |
| 56 | if(m_beam_energy_override >= 0) | ||
| 57 | return m_beam_energy_override; | ||
| 58 | else { | ||
| 59 | ✗ | std::call_once(m_error_once, [&]() { m_log->Error("Run number is {}; call `RCDBReader::SetBeamEnergyOverride` to set the beam energy (you can use `GetRCDBReader()` to get an algorithm's `RCDBReader` instance), or check the algorithm's configuration for similar option(s); for now, assuming it is {} GeV", runnum, default_value); }); | |
| 60 | ✗ | return default_value; | |
| 61 | } | ||
| 62 | } | ||
| 63 | // otherwise, query the RCDB | ||
| 64 | #ifdef USE_RCDB | ||
| 65 |
2/4✓ Branch 7 → 8 taken 8 times.
✗ Branch 7 → 22 not taken.
✗ Branch 13 → 14 not taken.
✓ Branch 13 → 16 taken 8 times.
|
16 | auto cnd = m_rcdb_connection->GetCondition(runnum, "beam_energy"); |
| 66 |
1/2✗ Branch 13 → 14 not taken.
✓ Branch 13 → 16 taken 8 times.
|
8 | if(!cnd) { |
| 67 | ✗ | m_log->Error("Failed to find beam energy from RCDB for run {}; assuming it is {} GeV", runnum, default_value); | |
| 68 | ✗ | return default_value; | |
| 69 | } | ||
| 70 |
1/2✓ Branch 16 → 17 taken 8 times.
✗ Branch 16 → 28 not taken.
|
8 | return cnd->ToDouble() / 1e3; // convert [MeV] -> [GeV] |
| 71 | #else | ||
| 72 | std::call_once(m_error_once, [&]() { m_log->Error("RCDB dependency not found; RCDBReader::GetBeamEnergy will return the default value of {} GeV.", default_value); }); | ||
| 73 | return default_value; | ||
| 74 | #endif | ||
| 75 | } | ||
| 76 | |||
| 77 | ////////////////////////////////////////////////////////////////////////////////// | ||
| 78 | |||
| 79 | ✗ | void RCDBReader::SetBeamEnergyOverride(double const beam_energy) | |
| 80 | { | ||
| 81 | ✗ | m_beam_energy_override = beam_energy; | |
| 82 | ✗ | } | |
| 83 | |||
| 84 | } | ||
| 85 |