ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
PhysicsAnalysis
D3PDMaker
D3PDMakerTest
python
changerun.py
Go to the documentation of this file.
1
#!/usr/bin/env python
2
3
# Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
4
5
import
sys
6
7
if
len(sys.argv) < 4:
8
print
(
"""Change the run number in a pool file.
9
Probably only works correctly for simple, single-run MC files.
10
11
Usage: changerun.py NEWRUN INFILE OUTFILE
12
"""
)
13
14
newrun = int (sys.argv[1])
15
infile = sys.argv[2]
16
outfile = sys.argv[3]
17
18
19
# Prevent AthenaBarCodeImpl from trying to create JobIDSvc.
20
import
os
21
import
uuid
22
os.environ[
'_ATHENABARCODEIMPL_JOBUUID'
] = uuid.uuid1().hex
23
24
import
ROOT
25
26
ROOT.DataModelAthenaPool.CLHEPConverters.initialize()
27
28
f1=ROOT.TFile(infile)
29
t1=f1.CollectionTree
30
m1=f1.MetaData
31
32
cl = ROOT.TClass.GetClass(
'Analysis::TruthInfo_p1'
)
33
#ROOT.ROOT.ResetClassVersion(cl, 'Analysis::TruthInfo_p1', 1)
34
35
f2=ROOT.TFile(outfile,
'RECREATE'
)
36
t2 = t1.CloneTree (0)
37
m2 = m1.CloneTree (0)
38
39
kk = [k.GetName()
for
k
in
f1.GetListOfKeys()]
40
for
k
in
kk:
41
if
k
in
[
'CollectionTree'
,
'MetaData'
]:
continue
42
o1 = f1.Get (k)
43
o2 = o1.CloneTree()
44
o2.Write()
45
46
# Hack: suppress errors.
47
def
bscan
(b):
48
ifo = b.GetInfo()
49
types = ifo.GetTypes()
50
elts = ifo.GetElements()
51
for
i
in
range(ifo.GetNdata()):
52
if
elts[i].GetName() ==
'm_athenabarcode'
and
types[i] == 217:
53
types[i] = 17
54
for
bb
in
b.GetListOfBranches():
55
bscan (bb)
56
return
57
for
b
in
t2.GetListOfBranches():
58
bscan (b)
59
60
oldrun =
None
61
for
i
in
range(t1.GetEntries()):
62
t1.GetEntry(i)
63
oldrun = t1.EventInfo_p3_McEventInfo.m_AllTheData[1]
64
t1.EventInfo_p3_McEventInfo.m_AllTheData[1] = newrun
65
t2.Fill()
66
t2.Write()
67
68
def
adjust_run
(x):
69
xrun = x >> 32
70
if
xrun <= 0
or
xrun > 1000000:
return
x
71
return
((xrun-oldrun) + newrun) * (1<<32) + (x & ((1<<32)-1))
72
73
74
for
i
in
range(m1.GetEntries()):
75
m1.GetEntry(i)
76
for
b
in
m1.GetListOfBranches():
77
bn = b.GetName()
78
if
bn.startswith (
'IOVMetaDataContainer_'
):
79
pv = getattr (m1, bn).m_payload.m_payloadVec
80
for
p
in
pv:
81
if
p.m_hasRunLumiBlockTime:
82
p.m_start = adjust_run (p.m_start)
83
p.m_stop = adjust_run (p.m_stop)
84
for
pa
in
p.m_attrLists:
85
r = pa.m_range
86
r.m_start = adjust_run (r.m_start)
87
r.m_stop = adjust_run (r.m_stop)
88
m2.Fill()
89
m2.Write()
90
91
92
f2.Close()
python.changerun.adjust_run
adjust_run(x)
Definition
changerun.py:68
python.changerun.bscan
bscan(b)
Definition
changerun.py:47
Generated on
for ATLAS Offline Software by
1.17.0