ATLAS Offline Software
Loading...
Searching...
No Matches
TrigConfSvcHelper.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4#include "TrigConfSvcHelper.h"
5
6#include <format>
7#include <vector>
8#include <sstream>
9#include <stdexcept>
10
11namespace TrigConf {
12
13bool isCrestConnection(const std::string& db_connection_string,
14 std::string& crest_server,
15 std::string& crest_api,
16 std::string& dbname)
17{
18 if (!db_connection_string.starts_with("http")) {
19 return false;
20 }
21
22 const std::string& url = db_connection_string;
23 const std::size_t protocol_end = url.find("://");
24
25 std::string protocol;
26 std::size_t host_start = 0;
27
28 if (protocol_end != std::string::npos) {
29 protocol = url.substr(0, protocol_end);
30 host_start = protocol_end + 3;
31 }
32
33 const std::size_t host_end = url.find('/', host_start);
34 const std::string host =
35 (host_end == std::string::npos)
36 ? url.substr(host_start)
37 : url.substr(host_start, host_end - host_start);
38
39 crest_server = protocol.empty()
40 ? host
41 : std::format("{}://{}", protocol, host);
42
43 std::string path =
44 (host_end != std::string::npos) ? url.substr(host_end) : "";
45
46 while (!path.empty() && path.back() == '/') {
47 path.pop_back();
48 }
49
50 std::vector<std::string> path_parts;
51 std::stringstream ss(path);
52 std::string segment;
53
54 while (std::getline(ss, segment, '/')) {
55 if (!segment.empty()) {
56 path_parts.push_back(segment);
57 }
58 }
59
60 if (path_parts.empty()) {
61 throw std::runtime_error(
62 "TrigConfJobOptionsSvc: crest connection '" + db_connection_string +
63 "' is missing the database name.");
64 }
65
66 crest_api.clear();
67 dbname.clear();
68
69 if (path_parts.size() == 1) {
70 dbname = path_parts[0];
71 }
72 else if (path_parts.size() == 2) {
73 crest_api = path_parts[0];
74 dbname = path_parts[1];
75 }
76
77 return true;
78}
79
80} // 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...