ATLAS Offline Software
Loading...
Searching...
No Matches
TrigConfSvcHelper.cxx
Go to the documentation of this file.
1#include "TrigConfSvcHelper.h"
2
3#include <format>
4#include <vector>
5#include <sstream>
6
7namespace TrigConf {
8
9bool isCrestConnection(const std::string& db_connection_string,
10 std::string& crest_server, std::string& crest_api, std::string& dbname) {
11 // Implementation of the function
12 if(!db_connection_string.starts_with("http")) {
13 return false;
14 }
15
16 std::string url = db_connection_string;
17 std::size_t protocol_end = url.find("://");
18 std::string protocol;
19
20 // --- 1. Extract protocol ---
21 if (protocol_end != std::string::npos) {
22 protocol = url.substr(0, protocol_end);
23 } else {
24 protocol = ""; // no protocol given
25 protocol_end = -3; // so that host_start = 0 below
26 }
27
28 // --- 2. Extract host ---
29 std::size_t host_start = protocol_end + 3;
30 std::size_t host_end = url.find('/', host_start);
31 std::string host = (host_end == std::string::npos) ? \
32 url.substr(host_start) : url.substr(host_start, host_end - host_start);
33 // server is protocol + host
34 crest_server = std::format("{}://{}", protocol, host);
35
36 // --- 3. Extract path ---
37 std::string path = (host_end != std::string::npos) ? url.substr(host_end) : "";
38
39 // --- 4. Remove trailing slashes ---
40 while (!path.empty() && path.back() == '/')
41 path.pop_back();
42
43 // --- 5. Split path into non-empty parts ---
44 std::vector<std::string> path_parts;
45 std::stringstream ss(path);
46 std::string segment;
47
48 while (std::getline(ss, segment, '/')) {
49 if (!segment.empty()) {
50 path_parts.push_back(segment);
51 }
52 }
53 if(path_parts.empty()) {
54 throw std::runtime_error("TrigConfJobOptionsSvc: crest connection '" + db_connection_string + "' is missing the database name.");
55 }
56 crest_api = "";
57 dbname = "";
58 if(path_parts.size()==1) {
59 dbname = path_parts[0];
60 } else if(path_parts.size()==2) {
61 crest_api = path_parts[0];
62 dbname = path_parts[1];
63 }
64 return true;
65}
66
67} // namespace TrigConf
static Double_t ss
Forward iterator to traverse the main components of the trigger configuration.
Definition Config.h:22
bool isCrestConnection(const std::string &db_connection_string, std::string &crest_server, std::string &crest_api, std::string &dbname)
Function to interpret the trigger connection string for CREST connections Format of the connections s...