Skip to content

Commit

Permalink
Check for metadata existence in ROOT file (#219)
Browse files Browse the repository at this point in the history
otherwise it's probably corrupt so raise error
  • Loading branch information
pdeperio authored and feigaodm committed Mar 23, 2018
1 parent bd23400 commit ea6bbf2
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion hax/minitree_formats.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,15 @@ class ROOTFormat(MinitreeDataFormat):
def load_metadata(self):
# This is NOT the same as paxroot.get_metadata, that's for pax ROOT files...
minitree_f = ROOT.TFile(self.path)
minitree_metadata = json.loads(minitree_f.Get('metadata').GetTitle())

metadata_object = minitree_f.Get('metadata')

# Corrupt file where metadata did not get saved
if metadata_object is None:
minitree_f.Close()
raise RuntimeError("Metadata non-existent/corrupt file: %s" % self.path)

minitree_metadata = json.loads(metadata_object.GetTitle())
minitree_f.Close()
return minitree_metadata

Expand Down

0 comments on commit ea6bbf2

Please sign in to comment.