GCC Code Coverage Report


Directory: ./
File: src/iguana/services/RCDBReader.cc
Date: 2025-06-06 22:09:53
Exec Total Coverage
Lines: 13 18 72.2%
Functions: 2 2 100.0%
Branches: 16 56 28.6%

Line Branch Exec Source
1 #include "RCDBReader.h"
2 #include "GlobalParam.h"
3
4 namespace iguana {
5
6
2/4
✓ Branch 0 (3→4) taken 8 times.
✗ Branch 1 (3→120) not taken.
✓ Branch 2 (4→5) taken 8 times.
✗ Branch 3 (4→104) not taken.
8 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 (4→5) taken 8 times.
✗ Branch 1 (4→104) not taken.
✓ Branch 2 (5→6) taken 8 times.
✗ Branch 3 (5→74) not taken.
✗ Branch 4 (12→13) not taken.
✓ Branch 5 (12→24) taken 8 times.
16 m_url = GlobalRcdbUrl();
13
1/2
✗ Branch 0 (12→13) not taken.
✓ Branch 1 (12→24) taken 8 times.
8 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 (25→26) taken 8 times.
✗ Branch 1 (25→34) not taken.
8 if(auto url_ptr{std::getenv("RCDB_CONNECTION")}; url_ptr != nullptr)
18
1/2
✓ Branch 0 (26→27) taken 8 times.
✗ Branch 1 (26→104) not taken.
16 m_url = std::string(url_ptr);
19
1/2
✓ Branch 0 (34→35) taken 8 times.
✗ Branch 1 (34→46) not taken.
8 if(!m_url.empty())
20
2/6
✓ Branch 0 (39→40) taken 8 times.
✗ Branch 1 (39→86) not taken.
✗ Branch 2 (40→41) not taken.
✓ Branch 3 (40→43) taken 8 times.
✗ Branch 4 (86→87) not taken.
✗ Branch 5 (86→89) not taken.
16 m_log->Debug("RCDB URL set from env var 'RCDB_CONNECTION': {:?}", m_url);
21 else {
22 // 3. fallback to default value
23 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 m_log->Debug("RCDB URL set from default fallback: {:?}", m_url);
26 }
27 }
28
29 // then start the connection
30
1/4
✓ Branch 0 (69→70) taken 8 times.
✗ Branch 1 (69→104) not taken.
✗ Branch 2 (104→105) not taken.
✗ Branch 3 (104→107) not taken.
8 m_rcdb_connection = std::make_unique<rcdb::Connection>(m_url, true);
31
32 #endif
33 8 }
34
35 8 double RCDBReader::GetBeamEnergy(int const runnum)
36 {
37 double const default_value = 10.6;
38 #ifdef USE_RCDB
39
2/4
✓ Branch 0 (3→4) taken 8 times.
✗ Branch 1 (3→17) not taken.
✗ Branch 2 (9→10) not taken.
✓ Branch 3 (9→12) taken 8 times.
16 auto cnd = m_rcdb_connection->GetCondition(runnum, "beam_energy");
40
1/2
✗ Branch 0 (9→10) not taken.
✓ Branch 1 (9→12) taken 8 times.
8 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 (12→13) taken 8 times.
✗ Branch 1 (12→23) not taken.
8 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 }
50
51 }
52