ATLAS Offline Software
ScanHistFile.py
Go to the documentation of this file.
1 #!/bin/env python
2 
3 # Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
4 #copied from DQPostProcessi.py and modified
5 # Sami Kama
6 from __future__ import print_function
7 import sys
8 def _dolsrwrapper(fname):
9  import ROOT
10  rf = ROOT.TFile.Open(fname, 'READ')
11  if not rf or not rf.IsOpen():
12  print(' %s is empty or not accessible' % fname)
13  return 3
14  if rf.TestBit(ROOT.TFile.kRecovered):
15  print(" %s is recovered. It means it was corrupt" % fname)
16  return 7
17  cleancache = ROOT.gROOT.MustClean(); ROOT.gROOT.SetMustClean(False)
18  RV=_dolsr(rf)
19  print("dolsr returned %s "%(RV))
20  rf.Close()
21  ROOT.gROOT.SetMustClean(cleancache)
22  return RV
23 def _dolsr(dir):
24  import ROOT
25  resultdir = dir.Get('Results'); statusobj = None
26  if resultdir:
27  statusobj = resultdir.Get('Status')
28  if statusobj:
29  l = statusobj.GetListOfKeys()
30  l[0].GetName()
31  keys = dir.GetListOfKeys()
32  for key in keys:
33  name = key.GetName()
34  #print "Reading key named %s"%name
35  keyClass=ROOT.TClass.GetClass(key.GetClassName())
36  if keyClass.InheritsFrom('TDirectory'):
37  dirobj = key.ReadObj()
38  resultdir = dirobj.Get('Results'); statusobj = None
39  if resultdir:
40  statusobj = resultdir.Get('Status')
41  # is a check? is a summary? or recurse?
42  if name[-1] == '_' and resultdir:
43  hist = dir.Get(name[:-1])
44  subkeys = resultdir.GetListOfKeys()
45  for subkey in subkeys:
46  ressub = subkey.GetName()
47  if ressub not in ('Status', 'Reference', 'ResultObject') and ROOT.TClass.GetClass(subkey.GetClassName()).InheritsFrom('TDirectory'):
48  subObj=subkey.ReadObj()
49  l = subObj.GetListOfKeys()
50  l[0].GetName()
51  # status flag
52  l = statusobj.GetListOfKeys()
53  l[0].GetName()
54 
55  else:
56  _dolsr(dirobj)
57  del dirobj
58  elif keyClass.InheritsFrom("TTree"):
59  currObj=key.ReadObj()
60  if currObj is None:
61  print("WARNING TTree Object \"%s\" in file:directory \"%s\" is corrupt "\
62  "keylen=%s numbytes=%s objlen=%s fseekkey=%s"%(name,dir.GetPath(),key.GetKeylen(),
63  key.GetNbytes(),key.GetObjlen(),key.GetSeekKey()))
64  return 9
65  else:
66  nentries=currObj.GetEntriesFast()
67  #print "Scanning tree Object \"%s\" in file:directory \"%s\" is corrupt "\
68  #"keylen=%s numbytes=%s objlen=%s fseekkey=%s "%(name,dir.GetPath(),key.GetKeylen(),
69  # key.GetNbytes(),key.GetObjlen(),key.GetSeekKey()),
70  #print "Scanning tree %s"%name,
71  for j in range(nentries):
72  ientry=currObj.LoadTree(j)
73  if ientry<0:
74  break
75  nb=currObj.GetEntry(j)
76  if nb<=0:
77  continue
78  #print " Done"
79  currObj.Delete()
80  del currObj
81  else:
82  currObj=key.ReadObj()
83  if currObj is None:
84  print("WARNING Object \"%s\" in file:directory \"%s\" is corrupt "\
85  "keylen=%s numbytes=%s objlen=%s fseekkey=%s"%(name,dir.GetPath(),key.GetKeylen(),
86  key.GetNbytes(),key.GetObjlen(),key.GetSeekKey()))
87  return 5
88  currObj.Delete()
89  del currObj
90  return 0
91 def scanFiles(globstr='testOutFile*'):
92  RV=_dolsrwrapper(globstr)
93  return RV
94 if __name__ == "__main__" :
95  if len(sys.argv)<2:
96  RV=scanFiles()
97  else:
98  RV=scanFiles("%s"%(sys.argv[1]))
99  sys.exit(RV)
ScanHistFile.scanFiles
def scanFiles(globstr='testOutFile *')
Definition: ScanHistFile.py:91
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
ScanHistFile._dolsr
def _dolsr(dir)
Definition: ScanHistFile.py:23
ScanHistFile._dolsrwrapper
def _dolsrwrapper(fname)
Definition: ScanHistFile.py:8
dbg::print
void print(std::FILE *stream, std::format_string< Args... > fmt, Args &&... args)
Definition: SGImplSvc.cxx:70