def get_ntuples(self): f = ROOT.TFile(self.filename) nt = f.Get(self.tuplename) SetOwnership(nt, False) ntd = f.Get(self.tuplename + 'D') SetOwnership(ntd, False) return f, nt, ntd
def get_ntuples(self): f = ROOT.TFile(self.filename) nt = f.Get(self.tuplename) SetOwnership(nt, False) ntd = f.Get(self.tuplename + 'D') SetOwnership(ntd, False) # Read first entry for ds in nt, ntd: ds.GetEntry(0) return f, nt, ntd
def setUpClass(cls): cls.dir0 = ROOT.TDirectory("dir0", "dir0") h = ROOT.TH1F("h", "h", cls.nbins, cls.xmin, cls.xmax) SetOwnership(h, False) # this must be there otherwise the histogram is not attached to dir0 h.SetDirectory(cls.dir0) dir1 = cls.dir0.mkdir("dir1") dir1.cd() h1 = ROOT.TH1F("h1", "h1", cls.nbins, cls.xmin, cls.xmax) SetOwnership(h1, False) dir2 = dir1.mkdir("dir2") dir2.cd() h2 = ROOT.TH1F("h2", "h2", cls.nbins, cls.xmin, cls.xmax) SetOwnership(h2, False)
def _setitem_pyz(self, idx, val): # Parameters: # - self: collection where to set item/s # - idx: index/slice of the item/s # - val: value to assign # Slice if isinstance(idx, slice): # The value we assign has to be iterable try: _ = iter(val) except TypeError: raise TypeError('can only assign an iterable') indices = idx.indices(len(self)) it = iter(range(*indices)) for elem in val: # Prevent this new Python proxy from owning the C++ object # Otherwise we get an 'already deleted' error in # TList::Clear when the application ends SetOwnership(elem, False) try: i = next(it) self[i] = elem except StopIteration: # No more indices in range, just append self.append(elem) # Number else: idx = _check_index(self, idx) self.RemoveAt(idx) self.AddAt(val, idx)
def get_file_and_tree(self): f = ROOT.TFile(self.filename) t = f.Get(self.treename) # Prevent double deletion of the tree (Python and C++ TFile) SetOwnership(t, False) return f, t
def create_file_and_tree(self): f = ROOT.TFile(self.filename, 'RECREATE') t = ROOT.TTree(self.treename, self.treename) # Prevent double deletion of the tree (Python and C++ TFile) SetOwnership(t, False) return f, t
def create_tcollection(self): c = ROOT.TList() for _ in range(self.num_elems): o = ROOT.TObject() # Prevent immediate deletion of C++ TObjects SetOwnership(o, False) c.Add(o) return c
def create_tseqcollection(self): sc = ROOT.TList() for i in reversed(range(self.num_elems)): o = ROOT.TObjString(str(i)) # Prevent immediate deletion of C++ TObjStrings SetOwnership(o, False) sc.Add(o) return sc
def setUpClass(cls): f = ROOT.TFile.Open(cls.filename, "RECREATE") h = ROOT.TH1F("h", "h", cls.nbins, cls.xmin, cls.xmax) SetOwnership(h, False) f.WriteObject(h, "h") dir1 = f.mkdir("dir1") dir1.cd() h1 = ROOT.TH1F("h1", "h1", cls.nbins, cls.xmin, cls.xmax) SetOwnership(h1, False) h1.Write() dir2 = dir1.mkdir("dir2") dir2.cd() h2 = ROOT.TH1F("h2", "h2", cls.nbins, cls.xmin, cls.xmax) SetOwnership(h2, False) h2.Write() f.Close()
def get_tree_and_chain(self): f = ROOT.TFile(self.filename) t = f.Get(self.treename) # Prevent double deletion of the tree (Python and C++ TFile) SetOwnership(t, False) c = ROOT.TChain(self.treename) c.Add(self.filename) c.Add(self.filename) # Read first entry for ds in t, c: ds.GetEntry(0) return f, t, c
def addClone(self, arg, silent=False): clonedArg = self._addClone(arg, silent) # There are two overloads of RooAbsCollection::addClone(): # # - RooAbsArg *addClone(const RooAbsArg& var, bool silent=false); # - void addClone(const RooAbsCollection& list, bool silent=false); # # In the case of the RooAbsArg overload, we need to tell Python that it # doesn't own the returned pointer. That's because the function name # contains "Clone", which makes cppyy guess that the returned pointer # points to a clone owned by the caller. In the case of the # RooAbsCollection input, the return value will be `None` and we don't # need to change any ownership flags (in fact, calling # SetOwnership(None, False) would cause a crash). if clonedArg is not None: SetOwnership(clonedArg, False)
def _init(self, *args): # Parameters: # self: Object being initialized # args: arguments for __init__ self._original__init__(*args) # TSlider is a special case, since it is appended to gPad already # in one of its constructors, after setting kCanDelete. # Therefore, we need to set the ownership here and not in Draw # (TSlider does not need to be drawn). This is ROOT-10095. if self.TestBit(kCanDelete): SetOwnership(self, False) # We have already set the ownership while initializing, # so we do not need the custom Draw inherited from TPad to # do it again in case it is executed. self.Draw = self._OriginalDraw
def _Draw(self, *args): # Parameters: # self: Object being drawn # args: arguments for Draw self._OriginalDraw(*args) # When drawing a TPad, it gets added to the list of primititves of its # mother TPad (fMother) with kCanDelete == 1. This means that, when # fMother is destructed, it will attempt to destroy its child TPad too. # To prevent a double delete, here we instruct the Python proxy of the # child C++ TPad being drawn not to destroy the latter (ROOT-10060). # # A similar principle is applied to TButton, TColorWheel, TPolyLine3D, # TPolyMarker and TPolyMarker3D, whose kCanDelete bit is set in one of # their constructors. Later, when being drawn, they are appended to # the list of primitives of gPad. if self.TestBit(kCanDelete): SetOwnership(self, False) self.Draw = self._OriginalDraw
def addOwned(self, arg, silent=False): """The RooAbsCollection::addOwned() function is pythonized with the command argument pythonization. The keywords must correspond to the CmdArgs of the function.""" self._addOwned(arg, silent) SetOwnership(arg, False)
def get_tree(self): f = ROOT.TFile(self.filename) t = f.Get(self.treename) SetOwnership(t, False) return f, t
def addClone(self, arg, silent=False): clonedArg = self._addClone(arg, silent) SetOwnership(clonedArg, False)
def addOwned(self, arg, silent=False): self._addOwned(arg, silent) SetOwnership(arg, False)