ATLAS Offline Software
changerun.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 # Copyright (C) 2002-2020 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 from PyUtils.Helpers import ROOT6Setup
26 ROOT6Setup()
27 
28 ROOT.DataModelAthenaPool.CLHEPConverters.initialize()
29 
30 f1=ROOT.TFile(infile)
31 t1=f1.CollectionTree
32 m1=f1.MetaData
33 
34 cl = ROOT.TClass.GetClass('Analysis::TruthInfo_p1')
35 #ROOT.ROOT.ResetClassVersion(cl, 'Analysis::TruthInfo_p1', 1)
36 
37 f2=ROOT.TFile(outfile, 'RECREATE')
38 t2 = t1.CloneTree (0)
39 m2 = m1.CloneTree (0)
40 
41 kk = [k.GetName() for k in f1.GetListOfKeys()]
42 for k in kk:
43  if k in ['CollectionTree', 'MetaData']: continue
44  o1 = f1.Get (k)
45  o2 = o1.CloneTree()
46  o2.Write()
47 
48 # Hack: suppress errors.
49 def bscan (b):
50  ifo = b.GetInfo()
51  types = ifo.GetTypes()
52  elts = ifo.GetElements()
53  for i in range(ifo.GetNdata()):
54  if elts[i].GetName() == 'm_athenabarcode' and types[i] == 217:
55  types[i] = 17
56  for bb in b.GetListOfBranches():
57  bscan (bb)
58  return
59 for b in t2.GetListOfBranches():
60  bscan (b)
61 
62 oldrun = None
63 for i in range(t1.GetEntries()):
64  t1.GetEntry(i)
65  oldrun = t1.EventInfo_p3_McEventInfo.m_AllTheData[1]
66  t1.EventInfo_p3_McEventInfo.m_AllTheData[1] = newrun
67  t2.Fill()
68 t2.Write()
69 
70 def adjust_run (x):
71  xrun = x >> 32
72  if xrun <= 0 or xrun > 1000000: return x
73  return ((xrun-oldrun) + newrun) * (1<<32) + (x & ((1<<32)-1))
74 
75 
76 for i in range(m1.GetEntries()):
77  m1.GetEntry(i)
78  for b in m1.GetListOfBranches():
79  bn = b.GetName()
80  if bn.startswith ('IOVMetaDataContainer_'):
81  pv = getattr (m1, bn).m_payload.m_payloadVec
82  for p in pv:
83  if p.m_hasRunLumiBlockTime:
84  p.m_start = adjust_run (p.m_start)
85  p.m_stop = adjust_run (p.m_stop)
86  for pa in p.m_attrLists:
87  r = pa.m_range
88  r.m_start = adjust_run (r.m_start)
89  r.m_stop = adjust_run (r.m_stop)
90  m2.Fill()
91 m2.Write()
92 
93 
94 f2.Close()
python.changerun.bscan
def bscan(b)
Definition: changerun.py:49
python.changerun.adjust_run
def adjust_run(x)
Definition: changerun.py:70
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
python.Helpers.ROOT6Setup
def ROOT6Setup(batch=False)
Definition: Tools/PyUtils/python/Helpers.py:19