Skip to content

Commit

Permalink
Added context manager functionality to DataFile
Browse files Browse the repository at this point in the history
  • Loading branch information
lwpiotr committed Apr 14, 2024
1 parent 363d6c7 commit 2b14d28
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions grand/dataio/root_trees.py
Original file line number Diff line number Diff line change
Expand Up @@ -2686,6 +2686,14 @@ def __init__(self, filename):
# setattr(self, tree_class.get_default_tree_name(), getattr(self, tree_class.get_default_tree_name() + "_l" + str(max_analysis_level)))
self.list_of_trees.append(self.dict_of_trees[max_anal_tree_name])

def __enter__(self):
""" enter() for DataFile as context manager"""
return self

def __exit__(self, exc_type, exc_val, exc_tb):
"""On exiting DataFile as context manager call close function"""
self.close()

def print(self):
"""Prints the information about the TTrees in the file"""

Expand Down

0 comments on commit 2b14d28

Please sign in to comment.