ATLAS Offline Software
Loading...
Searching...
No Matches
extract_histogram_tag.cxx
Go to the documentation of this file.
1
3
4#include <regex>
5
6namespace {
7
8// Regular expressions for per-LBN histogram names used over time
9std::regex const lbRegex_run2("^/?run_\\d+/lb_(\\d+)(/.+)$");
10std::regex const lbRegex_run3("^(.+)_LB((\\d+)|\\d+_(\\d+))$");
11
12}
13
14namespace detail {
15
16std::pair<std::string, int> extract_histogram_tag(const std::string& histo_name)
17{
18 std::smatch what;
19 if (std::regex_match(histo_name, what, ::lbRegex_run2)) {
20 try {
21 int tag = std::stoi(what.str(1));
22 return std::make_pair(what[2], tag);
23 } catch(std::exception &ex) {
24 // should not happen but be defensive and just ignore it
25 }
26 }
27 if (std::regex_match(histo_name, what, ::lbRegex_run3)) {
28 std::string const tagStr = what[3].length() > 0 ? what.str(3) : what.str(4);
29 try {
30 int tag = std::stoi(tagStr);
31 return std::make_pair(what[1], tag);
32 } catch(std::exception &ex) {
33 // should not happen but be defensive and just ignore it
34 }
35 }
36 return std::make_pair(histo_name, -1);
37}
38
39} // namespace detail
std::pair< std::string, int > extract_histogram_tag(const std::string &histo_name)
Extract tag/LB number from per-LBN histogram name.