ATLAS Offline Software
xAODHistSize.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 
4 from __future__ import print_function
5 import sys
6 import ROOT
7 import argparse
8 import subprocess
9 from array import array
10 
11 def checkxAODSize(xAODFiles, histfile, addgraphlabel=False):
12 
13  # Set output HIST filename
14  histfilename = histfile if histfile else "hist.root"
15 
16  # Loop over xAODFiles and extract Total size/event in kB with checkxAOD
17  sizes = []
18  for filename in xAODFiles:
19  cmd = ['checkxAOD', filename]
20  outlog = subprocess.Popen(cmd, stdout = subprocess.PIPE)
21  lines = str(outlog.communicate()).split("\\n")
22  # Set some variable to start values
23  iline = 0
24  for line in lines:
25  # Parse CSV lines with domain sizes
26  if line.startswith("CSV"):
27  domainlist = lines[iline+1].strip().split(",")
28  domainsize = lines[iline+2].strip().split(",")
29  domaindict = dict(zip(domainlist, domainsize))
30  iline = iline + 1
31  sizes.append(float(domaindict['Total']))
32 
33  # Open existing histogram file and add size/event infos
34  hfile = ROOT.TFile( histfilename, 'UPDATE', 'ROOT file with histograms' )
35  hfile.cd()
36  hfile.mkdir("Sizes")
37  hfile.cd("Sizes")
38 
39  # Histogram with "Total" checkxAOD sizes
40  hsize = ROOT.TH1F('hist PHYSLITE PHYS AOD event size', 'hist PHYSLITE PHYS AOD event size', len(sizes), -0.5, len(sizes)-0.5 )
41  for i in range(0,len(sizes)):
42  hsize.Fill(i, sizes[i])
43  hsize.Write()
44 
45  # The same "Total" checkxAOD size in a TGraph
46  xbins = [*range(len(sizes))]
47  x, y = array( 'd' ), array( 'd' )
48  for i in range(len(sizes)):
49  x.append(xbins[i])
50  y.append(sizes[i])
51 
52  grsize = ROOT.TGraph(len(sizes),x,y)
53  grsize.SetTitle('graph PHYSLITE PHYS AOD file size')
54  grsize.SetName('graph PHYSLITE PHYS AOD file size')
55 
56  # Add xaxis label names to TGraph
57  if addgraphlabel:
58  xbinsLabel = [ 'PHYSLITE %3.1f'%sizes[0],
59  'PHYS %3.1f'%sizes[1],
60  'AOD %3.1f'%sizes[2] ]
61 
62  graxis = grsize.GetXaxis()
63  for ibin in range(0,len(sizes)):
64  tmpbin = graxis.FindBin(ibin)
65  graxis.SetBinLabel(tmpbin, xbinsLabel[ibin])
66  graxis.Draw("AP")
67 
68  grsize.Write()
69  hfile.Close()
70 
71  return
72 
73 def main():
74  parser = argparse.ArgumentParser(
75  description="Extracts a few basic quantities from the xAOD file and dumps them into a hist ROOT file")
76  parser.add_argument("--xAODFiles", help="xAOD filenames (comma separated) for size/event check",
77  action="store", default=None)
78  parser.add_argument("--outputHISTFile", help="histogram output filename",
79  action="store", default=None)
80  parser.add_argument("--addgraphlabel", help="Add PHYSLITE PHYS AOD x-Axis graph label and size",
81  action="store_true", default=False)
82 
83  args = parser.parse_args()
84 
85  if len(sys.argv) < 2:
86  parser.print_help()
87  sys.exit(1)
88 
89  # Create input filelist
90  filelist = args.xAODFiles.split(',')
91 
92  # Call checkxAOD
93  checkxAODSize(filelist, args.outputHISTFile, args.addgraphlabel)
94 
95  return 0
96 
97 if __name__ == "__main__":
98 
99  main()
python.xAODHistSize.checkxAODSize
def checkxAODSize(xAODFiles, histfile, addgraphlabel=False)
Definition: xAODHistSize.py:11
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
array
python.xAODHistSize.main
def main()
Definition: xAODHistSize.py:73
str
Definition: BTagTrackIpAccessor.cxx:11
readCCLHist.float
float
Definition: readCCLHist.py:83
Trk::split
@ split
Definition: LayerMaterialProperties.h:38