ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Trigger
TrigConfiguration
TrigConfHLTUtils
Root
TrigConfHLTUtils/Root/HLTUtils.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
#include <iostream>
6
#include <stdexcept>
7
#include <algorithm>
8
#include <fstream>
9
10
#include "
TrigConfHLTUtils/HLTUtils.h
"
11
12
using namespace
TrigConf
;
13
14
15
HashStore::~HashStore
() {
16
}
17
18
HashMap::~HashMap
() {
19
}
20
21
22
HLTHash
HLTUtils::string2hash
( std::string_view s,
const
std::string& category )
23
{
24
// Try to find existing hash in category
25
const
std::string
ss
(s);
26
const
auto
icat = s_hashStore.hashCat.find(category);
27
if
(icat != s_hashStore.hashCat.end()) {
// category found
28
const
HashMap
& cat = icat->second;
29
const
auto
ihash = cat.
name2hash
.
find
(
ss
);
30
if
(ihash != cat.
name2hash
.
end
()) {
// hash found
31
return
ihash->second;
32
}
33
}
34
else
{
35
s_hashStore.hashCat.emplace(category, std::make_unique<HashMap>());
36
}
37
38
/*********************************************************************
39
This hash function is derived from the ELF hashing function and
40
unchanged since Run-1. For Phase-II we should really switch to a
41
64 bit hash like CxxUtils::crc64 which is safer (and faster).
42
But we need to take care of backwards compatibility with old data.
43
Original author: Tomasz Bold
44
*********************************************************************/
45
HLTHash
hash
= 0xd2d84a61;
46
for
(
int
i = (
int
)
s
.size()-1; i >= 0; --i )
47
//coverity[INTEGER_OVERFLOW]
48
hash
^= (
hash
>> 5) + s[i] + ( hash << 7 );
49
50
for
(
int
i = 0;
i
< (
int
)
s
.size(); ++
i
)
51
hash ^= ( hash >> 5) +
s
[
i
] + (
hash
<< 7 );
52
/********************************************************************/
53
54
// Try to insert new hash
55
HashMap& cat = s_hashStore.hashCat.at(category);
56
const
auto
& [itr, inserted] = cat.
hash2name
.emplace(hash,
ss
);
57
58
if
( inserted ) {
59
// also update reverse map
60
cat.name2hash.emplace(
ss
, hash);
61
}
62
else
{
63
// There are two cases where insertion into the hash->name map would fail:
64
// 1) another thread entered the same hash/name pair already
65
// 2) there is a hash collision
66
if
( s != itr->second ) {
67
throw
std::domain_error(
"Hash collision in category "
+ category +
68
" for elements "
+ itr->second +
" and "
+
ss
);
69
}
70
}
71
72
return
hash
;
73
}
74
75
const
std::string
HLTUtils::hash2string
(
HLTHash
hash,
const
std::string& category ) {
76
77
const
auto
& icat = s_hashStore.hashCat.find(category);
78
if
(icat == s_hashStore.hashCat.end()) {
79
return
"UNKNOWN CATEGORY"
;
80
}
81
82
const
HashMap& cat = icat->second;
83
const
auto
&
h
= cat.
hash2name
.find(hash);
84
if
(h == cat.
hash2name
.end()) {
85
return
"UNKNOWN HASH ID"
;
86
}
87
88
return
h
->second;
89
}
90
91
void
HLTUtils::hashes2file
(
const
std::string& fileName) {
92
std::ofstream
fout
(fileName);
93
94
for
(
const
auto
[category, hashes] : s_hashStore.hashCat) {
95
fout
<<
s_newCategory
<<
'\n'
<<
category
<<
'\n'
;
96
for
(
const
auto
[hash, nameptr] :
hashes
.hash2name) {
97
std::string
name
(nameptr);
98
std::erase(name,
'\n'
);
// Remove any line breaks
99
fout
<<
hash
<<
'\n'
<<
name
<<
'\n'
;
100
}
101
}
102
}
103
104
void
HLTUtils::file2hashes
(
const
std::string& fileName) {
105
std::ifstream
fin
(fileName);
106
if
(!
fin
.is_open()) {
107
return
;
108
}
109
std::string
line
;
110
std::string
category
;
111
// Note: this method is a to aid with development/debugging.
112
// It won't be used in production code, hence it is light on error checking.
113
while
(std::getline(fin, line)) {
114
if
(line ==
s_newCategory
) {
115
std::getline(fin, category);
116
continue
;
117
}
118
HLTHash
hash
= std::stoul(line);
119
std::string
name
;
120
std::getline(fin, name);
121
HLTHash
check
=
string2hash
(name, category);
122
if
(check != hash) {
123
std::cerr <<
"Inconsistency in file2hashes("
<<
fileName
<<
") function,"
124
" item "
<<
name
<<
" has hash "
<<
hash
<<
" not "
<<
check
<< std::endl;
125
}
126
}
127
}
ss
static Double_t ss
Definition
LArPhysWaveHECTool.cxx:37
HLTUtils.h
CxxUtils::ConcurrentStrMap::find
const_iterator find(const key_type &key) const
Look up an element in the map.
CxxUtils::ConcurrentStrMap::end
const_iterator end() const
Iterator at the end of the map.
TrigConf::HLTUtils::hashes2file
static void hashes2file(const std::string &fileName="hashes2string.txt")
debugging output of internal dictionary
TrigConf::HLTUtils::s_newCategory
static const std::string s_newCategory
In-file identifier.
Definition
TrigConfHLTUtils/TrigConfHLTUtils/HLTUtils.h:60
TrigConf::HLTUtils::string2hash
static HLTHash string2hash(std::string_view, const std::string &category=s_defaultCategory)
hash function translating TE names into identifiers
TrigConf::HLTUtils::hash2string
static const std::string hash2string(HLTHash, const std::string &category=s_defaultCategory)
hash function translating identifiers into names (via internal dictionary)
TrigConf::HLTUtils::file2hashes
static void file2hashes(const std::string &fileName="hashes2string.txt")
debugging output of internal dictionary
fout
static TFile * fout
Definition
listroot.cxx:40
CaloCondBlobAlgs_fillNoiseFromASCII.hash
dict hash
Definition
CaloCondBlobAlgs_fillNoiseFromASCII.py:108
ReweightUtils.category
category
Definition
ReweightUtils.py:15
TrigConf
Forward iterator to traverse the main components of the trigger configuration.
Definition
IDPerfMonZmumu.h:57
TrigConf::HLTHash
uint32_t HLTHash
Definition
TrigConfHLTUtils/TrigConfHLTUtils/HLTUtils.h:19
compute_lumi.fin
fin
Definition
compute_lumi.py:19
dq_defect_bulk_create_defects.line
line
Definition
dq_defect_bulk_create_defects.py:27
extractSporadic.name
name
Definition
extractSporadic.py:101
extractSporadic.h
list h
Definition
extractSporadic.py:96
gridSubmitIDTPM.check
check
submit
Definition
gridSubmitIDTPM.py:45
jobOptions.fileName
fileName
Definition
jobOptions.SuperChic_ALP2.py:39
lumiFormat.i
int i
Definition
lumiFormat.py:85
python.CaloAddPedShiftConfig.int
int
Definition
CaloAddPedShiftConfig.py:45
python.SystemOfUnits.s
float s
Definition
SystemOfUnits.py:147
python.root_lsr_rank.hashes
dict hashes
Definition
root_lsr_rank.py:34
TrigConf::HashMap
Two concurrent maps to store name->hash and hash->name mappings.
Definition
TrigConfHLTUtils/TrigConfHLTUtils/HLTUtils.h:28
TrigConf::HashMap::~HashMap
~HashMap()
Definition
TrigConfHLTUtils/Root/HLTUtils.cxx:18
TrigConf::HashMap::hash2name
Hash2NameMap_t hash2name
hash to name map
Definition
TrigConfHLTUtils/TrigConfHLTUtils/HLTUtils.h:35
TrigConf::HashMap::name2hash
Name2HashMap_t name2hash
name to hash map
Definition
TrigConfHLTUtils/TrigConfHLTUtils/HLTUtils.h:34
TrigConf::HashStore::~HashStore
~HashStore()
Definition
TrigConfHLTUtils/Root/HLTUtils.cxx:15
Generated on
for ATLAS Offline Software by
1.17.0