code: def GuardedTFile(*args, **kwargs):
      
      global guarded_tfile_cls
  
      if not guarded_tfile_cls:
          import ROOT
  
          class GuardedTFile(ROOT.TFile):
  
              def __enter__(self):
                  return self
  
              def __exit__(self, exc_type, exc_value, traceback):
                  if self.IsOpen():
                      self.Close()
  
          guarded_tfile_cls = GuardedTFile
  
      return guarded_tfile_cls(*args, **kwargs)
docs: Factory function that lazily creates the guarded TFile class, and creates and returns an
      instance with all passed *args* and *kwargs*. This is required as we do not want to import ROOT
      in the global scope.