Line | Branch | Exec | Source |
---|---|---|---|
1 | #include "RCDBReader.h" | ||
2 | #include "GlobalParam.h" | ||
3 | |||
4 | namespace iguana { | ||
5 | |||
6 |
2/4✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
|
6 | RCDBReader::RCDBReader(std::string_view name, Logger::Level lev) : Object(name, lev) |
7 | { | ||
8 | #ifdef USE_RCDB | ||
9 | |||
10 | // choose the RCDB URL, from the following priority ordering | ||
11 | // 1. try `GlobalRcdbUrl` | ||
12 |
3/6✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 6 times.
|
12 | m_url = GlobalRcdbUrl(); |
13 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
6 | if(!m_url.empty()) |
14 | ✗ | m_log->Debug("RCDB URL set from 'iguana::GlobalRcdbUrl': {:?}", m_url); | |
15 | else { | ||
16 | // 2. try env var `RCDB_CONNECTION` | ||
17 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
6 | if(auto url_ptr{std::getenv("RCDB_CONNECTION")}; url_ptr != nullptr) |
18 | ✗ | m_url = std::string(url_ptr); | |
19 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
6 | if(!m_url.empty()) |
20 | ✗ | m_log->Debug("RCDB URL set from env var 'RCDB_CONNECTION': {:?}", m_url); | |
21 | else { | ||
22 | // 3. fallback to default value | ||
23 |
2/4✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
|
6 | 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); |
24 | m_url = m_default_url; | ||
25 |
1/2✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
|
6 | m_log->Debug("RCDB URL set from default fallback: {:?}", m_url); |
26 | } | ||
27 | } | ||
28 | |||
29 | // then start the connection | ||
30 |
1/4✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
6 | m_rcdb_connection = std::make_unique<rcdb::Connection>(m_url, true); |
31 | |||
32 | #endif | ||
33 | 6 | } | |
34 | |||
35 | 6 | double RCDBReader::GetBeamEnergy(int const runnum) | |
36 | { | ||
37 | double const default_value = 10.6; | ||
38 | #ifdef USE_RCDB | ||
39 |
2/4✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
|
12 | auto cnd = m_rcdb_connection->GetCondition(runnum, "beam_energy"); |
40 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
6 | if(!cnd) { |
41 | ✗ | m_log->Error("Failed to find beam energy from RCDB for run {}; assuming it is {} GeV", runnum, default_value); | |
42 | ✗ | return default_value; | |
43 | } | ||
44 |
1/2✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
|
6 | return cnd->ToDouble() / 1e3; // convert [MeV] -> [GeV] |
45 | #else | ||
46 | std::call_once(m_error_once, [&]() { m_log->Error("RCDB dependency not found; RCDBReader::GetBeamEnergy will return the default value of {} GeV.", default_value); }); | ||
47 | return default_value; | ||
48 | #endif | ||
49 | 6 | } | |
50 | |||
51 | } | ||
52 |