ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Database
EventIndex
EventGUIDLookup
python
EventGUIDLookupLib.py
Go to the documentation of this file.
1
#!/usr/bin/env python
2
# Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3
"""
4
EventGUIDLookupLib.py
5
6
Provenance GUID resolution, adapted from the "Self reference and
7
Provenance" block of
8
Database/EventIndex/EventIndexProducer/python/POOL2EI_Lib.py
9
10
- If the requested dataType IS the input file's own dataType, the GUID
11
is in the *self reference* (the current file's own DataHeader entry).
12
- Otherwise, the GUID is in the *ancestor provenance* record for that
13
stream, and only exists at all for the handful of streams POOL2EI_Lib
14
recognizes there (RAW/ESD/AOD/RDO/HITS/EVGEN/Embedding) -- see
15
_KNOWN_ANCESTOR_KEYS.
16
"""
17
18
import
re
19
20
_TOKEN_DB_RE = re.compile(
r'\[DB=([0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-'
21
r'[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12})\]'
)
22
23
# ATLAS data type -> internal DataHeader/provenance stream key
24
_STREAM_KEY = {
25
'RAW'
:
'StreamRAW'
,
26
'ESD'
:
'StreamESD'
,
27
'AOD'
:
'StreamAOD'
,
28
'RDO'
:
'StreamRDO'
,
29
'HITS'
:
'StreamHITS'
,
30
'EVNT'
:
'StreamEVGEN'
,
31
}
32
33
_KNOWN_ANCESTOR_KEYS = (
'StreamRAW'
,
'StreamAOD'
,
'StreamESD'
,
'StreamRDO'
,
34
'StreamHITS'
,
'StreamEVGEN'
,
'EmbeddingStream'
)
35
36
37
def
_streamKey
(dataType):
38
"""Map --dataType/--inputDataType onto the DataHeader key. Types with
39
no fixed internal name (DAOD_PHYS, DAOD_PHYSLITE) fall back to
40
'Stream<dataType>' -- only usable as a self-reference, never as a
41
recognized ancestor key (see _KNOWN_ANCESTOR_KEYS)."""
42
return
_STREAM_KEY.get(dataType,
'Stream'
+ dataType)
43
44
45
def
guid2string
(guid):
46
return
"{:08X}-{:04X}-{:04X}-{:02X}{:02X}-{:02X}{:02X}{:02X}{:02X}{:02X}{:02X}"
.format(
47
guid.data1(), guid.data2(), guid.data3(),
48
ord(guid.data4(0)[0]), ord(guid.data4(1)[0]),
49
ord(guid.data4(2)[0]), ord(guid.data4(3)[0]),
50
ord(guid.data4(4)[0]), ord(guid.data4(5)[0]),
51
ord(guid.data4(6)[0]), ord(guid.data4(7)[0]))
52
53
54
def
token2string
(tk, replace_empty_cntID=False):
55
cntID = tk.contID()
56
if
replace_empty_cntID
and
cntID ==
""
:
57
cntID =
"POOLContainer(DataHeader)"
58
return
"[DB={}][CNT={}][CLID={}][TECH={:08X}][OID={:016X}-{:016X}]"
.format(
59
guid2string
(tk.dbID()), cntID,
guid2string
(tk.classID()),
60
tk.technology(), tk.oid().first, tk.oid().second)
61
62
63
def
_resolveAncestorProvenance
(dh, requestedKey):
64
if
dh.sizeProvenance() == 0:
65
return
None
66
guid =
None
67
prv = dh.beginProvenance()
68
for
_
in
range(dh.sizeProvenance()):
69
key = prv.getKey()
70
if
key.startswith(
"Output"
):
71
key = key[6:]
72
if
key.startswith(
"Input"
):
73
key = key[5:]
74
if
key
in
_KNOWN_ANCESTOR_KEYS
and
key == requestedKey
and
guid
is
None
:
75
tk = prv.getToken()
76
stk =
token2string
(tk, replace_empty_cntID=(key !=
'StreamRAW'
))
77
m = _TOKEN_DB_RE.search(stk)
78
if
m:
79
guid = m.group(1)
80
del tk
81
del key
82
prv += 1
83
del prv
84
return
guid
85
86
87
def
_resolveSelfReference
(dh, requestedKey):
88
if
dh.size() == 0:
89
return
None
90
guid =
None
91
dhe = dh.begin()
92
for
_
in
range(dh.size()):
93
key = dhe.getKey()
94
if
key == requestedKey
and
guid
is
None
:
95
tk = dhe.getToken()
96
stk =
token2string
(tk, replace_empty_cntID=
True
)
97
m = _TOKEN_DB_RE.search(stk)
98
if
m:
99
guid = m.group(1)
100
del tk
101
del key
102
dhe += 1
103
dh.end()
104
return
guid
105
106
107
def
resolveProvenanceGuid
(store, dataType, inputDataType):
108
"""Return the provenance GUID string for `dataType`, given the input
109
file is actually `inputDataType`, for the current event -- call from
110
inside an algorithm's execute(). Returns None if not found."""
111
112
dh = store.retrieve(
'DataHeader'
,
'EventSelector'
)
113
requestedKey =
_streamKey
(dataType)
114
115
if
dataType == inputDataType:
116
return
_resolveSelfReference
(dh, requestedKey)
117
else
:
118
return
_resolveAncestorProvenance
(dh, requestedKey)
EventGUIDLookupLib._streamKey
_streamKey(dataType)
Definition
EventGUIDLookupLib.py:37
EventGUIDLookupLib.resolveProvenanceGuid
resolveProvenanceGuid(store, dataType, inputDataType)
Definition
EventGUIDLookupLib.py:107
EventGUIDLookupLib._resolveAncestorProvenance
_resolveAncestorProvenance(dh, requestedKey)
Definition
EventGUIDLookupLib.py:63
EventGUIDLookupLib._resolveSelfReference
_resolveSelfReference(dh, requestedKey)
Definition
EventGUIDLookupLib.py:87
EventGUIDLookupLib.token2string
token2string(tk, replace_empty_cntID=False)
Definition
EventGUIDLookupLib.py:54
EventGUIDLookupLib.guid2string
guid2string(guid)
Definition
EventGUIDLookupLib.py:45
Generated on
for ATLAS Offline Software by
1.17.0