<commit_before>import ROOT

class NtupleChain:
    
    def __init__(self, treeName, files, buffer=None):
        
        self.treeName = treeName
        if type(files) is not list:
            files = [files]
        self.files = files
        self.buffer = buffer
        if self.buffer:
            for name,value in self.buffer.items():
                if name not in dir(self):
                    setattr(self,name,value)
        self.weight = 1.
        self.tree = None
        self.file = None
        self.entry = 0
        self.entries = 0
        
    def _initialize(self):

        if self.tree != None:
            self.tree = None
            self.file.Close()
        if len(self.files) > 0:
            fileName = self.files.pop()
            self.file = ROOT.TFile.Open(fileName)
            if not self.file:
                raise RuntimeError("Could not open file %s"%(fileName))
            self.tree = self.file.Get(self.treeName)
            if not self.tree:
                raise RuntimeError("Tree %s does not exist in file %s"%(self.treeName,fileName))
            # Buggy D3PD:
            if len(self.tree.GetListOfBranches()) == 0:
                # Try the next file:
                print "WARNING: skipping tree with no branches in file %s"%fileName
                return self._initialize()
            self.entry = 0
            self.entries = self.tree.GetEntries()
            if self.buffer != None:
                self.tree.SetBranchStatus("*",False)
                for branch,address in self.buffer.items():
                    if not self.tree.GetBranch(branch):
                        print "WARNING: Skipping file. Branch %s was not found in tree %s in file %s"%(branch,self.treeName,fileName)
                        print "Branches found:"
                        for branch in self.tree.GetListOfBranches():
                            print branch.GetName()
                        return self._initialize()
                    self.tree.SetBranchStatus(branch,True)
                    self.tree.SetBranchAddress(branch,address)
            return True
        return False
    
    def read(self):
        
        if not self.entry < self.entries:
            if not self._initialize():
                return False
        self.tree.GetEntry(self.entry)
        self.weight = self.tree.GetWeight()
        self.entry += 1
        return True<commit_msg>updates<commit_after>import ROOT

class NtupleChain:
    
    def __init__(self, treeName, files, buffer=None):
        
        self.treeName = treeName
        if type(files) is not list:
            files = [files]
        self.files = files
        self.buffer = buffer
        if self.buffer:
            for name,value in self.buffer.items():
                if name not in dir(self):
                    setattr(self,name,value)
        self.weight = 1.
        self.tree = None
        self.file = None
        self.entry = 0
        self.entries = 0
        
    def _initialize(self):

        if self.tree != None:
            self.tree = None
        if self.file != None:
            self.file.Close()
            self.file = None
        if len(self.files) > 0:
            fileName = self.files.pop()
            self.file = ROOT.TFile.Open(fileName)
            if not self.file:
                print "WARNING: Skipping file. Could not open file %s"%(fileName)
                return self._initialize()
            self.tree = self.file.Get(self.treeName)
            if not self.tree:
                print "WARNING: Skipping file. Tree %s does not exist in file %s"%(self.treeName,fileName)
                return self._initialize()
            # Buggy D3PD:
            if len(self.tree.GetListOfBranches()) == 0:
                # Try the next file:
                print "WARNING: skipping tree with no branches in file %s"%fileName
                return self._initialize()
            self.entry = 0
            self.entries = self.tree.GetEntries()
            if self.buffer != None:
                self.tree.SetBranchStatus("*",False)
                for branch,address in self.buffer.items():
                    if not self.tree.GetBranch(branch):
                        print "WARNING: Skipping file. Branch %s was not found in tree %s in file %s"%(branch,self.treeName,fileName)
                        return self._initialize()
                    self.tree.SetBranchStatus(branch,True)
                    self.tree.SetBranchAddress(branch,address)
            return True
        return False
    
    def read(self):
        
        if not self.entry < self.entries:
            if not self._initialize():
                return False
        self.tree.GetEntry(self.entry)
        self.weight = self.tree.GetWeight()
        self.entry += 1
        return True
{'fraction_non_alphanumeric': 0.0925348305260969, 'fraction_numerical': 0.0033270950301517986, 'mean_word_length': 1.4465920651068158, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4282588', 'n_tokens_mistral': 1286, 'n_tokens_neox': 1255, 'n_words': 341}