ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
InnerDetector
InDetConditions
PixelConditionsAlgorithms
src
StringUtilities.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
#include "
StringUtilities.h
"
6
#include <charconv>
//for std::from_chars
7
#include <algorithm>
//for std::find_if
8
#include <stdexcept>
//for std::runtime_error
9
10
/*
11
original implementation used two string streams. A more complete std::regex_iterator
12
version was tried but results in a x4 increase in parsing time for 164 elements.
13
This version is approx ten times faster than the original implementation (local tests)
14
and is robust against small variations in the format, e.g. actual delimiters used.
15
*/
16
17
namespace
PixelConditionsAlgorithms
{
18
std::vector<std::pair<int, int>>
//module hash, module status
19
parseDeadMapString
(
const
std::string & s){
20
std::vector<std::pair<int, int>> result;
21
//the Trigger_athenaHLT_v1Cosmic CI test returns a pair of empty braces, "{}"; trap this
22
//in fact the minimal useful string would be {"d":d}, where d is a digit
23
if
(s.size()<7)
return
result;
24
//a valid string is json, enclosed in braces.
25
const
bool
is_valid = (s.front() ==
'{'
) and (s.back() ==
'}'
);
26
if
(not is_valid)
return
result;
27
auto
is_digit=[](
const
char
c)->
bool
{
28
return
(c>=
'0'
) and (c<=
'9'
);
29
};
30
auto
is_quote=[](
const
char
c)->
bool
{
31
return
(c==
'"'
);
32
};
33
const
auto
*pc=s.data();
34
const
auto
*
const
pcEnd=pc+s.size();
35
int
hash{};
36
int
status{};
37
static
constexpr
std::errc success{};
38
39
//database strings look like : {"12":0,"19":0,"53":0,"64":256}
40
for
(;pc<pcEnd;++pc){
41
//fast-forward to the first quote
42
pc=std::find_if(pc,pcEnd,is_quote);
43
//the following converts everything up to the first non-digit character
44
//the ptr is pointing to the first non-digit character (which should be a quote)
45
const
auto
&[ptr, errCode] = std::from_chars(++pc, pcEnd, hash);
46
if
(errCode!= success){
47
throw
std::runtime_error(
"Bad hash conversion from database string in PixelConditionsAlgorithms::parseDeadMapString:"
+s+
"."
);
48
}
49
//fast-forward to the next digit
50
pc=std::find_if(ptr,pcEnd,is_digit);
51
const
auto
&[ptr2, errCode2] = std::from_chars(pc, pcEnd, status);
52
if
(errCode2!= success){
53
throw
std::runtime_error(
"Bad status conversion from database string in PixelConditionsAlgorithms::parseDeadMapString:"
+s+
"."
);
54
}
55
pc=ptr2;
56
result.emplace_back(hash, status);
57
}
58
59
//
60
return
result;
61
}
62
63
}
StringUtilities.h
PixelConditionsAlgorithms
Definition
StringUtilities.cxx:17
PixelConditionsAlgorithms::parseDeadMapString
std::vector< std::pair< int, int > > parseDeadMapString(const std::string &s)
Definition
StringUtilities.cxx:19
Generated on
for ATLAS Offline Software by
1.17.0