ATLAS Offline Software
Loading...
Searching...
No Matches
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
5import sys
6
7if len(sys.argv) < 4:
8 print ("""Change the run number in a pool file.
9Probably only works correctly for simple, single-run MC files.
10
11Usage: changerun.py NEWRUN INFILE OUTFILE
12""")
13
14newrun = int (sys.argv[1])
15infile = sys.argv[2]
16outfile = sys.argv[3]
17
18
19# Prevent AthenaBarCodeImpl from trying to create JobIDSvc.
20import os
21import uuid
22os.environ['_ATHENABARCODEIMPL_JOBUUID'] = uuid.uuid1().hex
23
24import ROOT
25
26ROOT.DataModelAthenaPool.CLHEPConverters.initialize()
27
28f1=ROOT.TFile(infile)
29t1=f1.CollectionTree
30m1=f1.MetaData
31
32cl = ROOT.TClass.GetClass('Analysis::TruthInfo_p1')
33#ROOT.ROOT.ResetClassVersion(cl, 'Analysis::TruthInfo_p1', 1)
34
35f2=ROOT.TFile(outfile, 'RECREATE')
36t2 = t1.CloneTree (0)
37m2 = m1.CloneTree (0)
38
39kk = [k.GetName() for k in f1.GetListOfKeys()]
40for 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.
47def 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
57for b in t2.GetListOfBranches():
58 bscan (b)
59
60oldrun = None
61for 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()
66t2.Write()
67
68def 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
74for 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()
89m2.Write()
90
91
92f2.Close()