print "* mapping with regexp",item toadd=True if toadd: print "-> Adding function", myfunc.GetName() storedPdfs.add(myfunc) if options.rename_index != "": catname=options.rename_index print "catname is",catname pdf_cat = ROOT.RooCategory(catname,"remapped") newpdf=ROOT.RooMultiPdf(pdf.GetName(),pdf.GetTitle(),pdf_cat,storedPdfs) ws2=ROOT.RooWorkspace(workspace.GetName(),workspace.GetTitle()) getattr(ws2,'import')(newpdf,ROOT.RooFit.RecycleConflictNodes(),ROOT.RooFit.Silence()) allMembers = wsutils.getAllMembers(workspace) for x in allMembers: if x.GetName() != pdfname: getattr(ws2,'import')(x,ROOT.RooFit.RecycleConflictNodes(),ROOT.RooFit.Silence()) ws2.writeToFile(outname) if options.copy: out=ROOT.TFile.Open(outname,"UPDATE") for w in allworkspaces: if w.GetName() == workspace.GetName():continue w.Write() print "-- DONE --" ws2.pdf(pdfname).Print() print "----------" del ws2
#---------------------------------------- import ROOT gcs = [] wsutils.loadLibraries(options) fin = ROOT.TFile.Open(inputFname) if fin == None or not fin.IsOpen(): print >> sys.stderr, "error opening input file " + inputFname sys.exit(1) ws = findWorkspace(fin) allMembers = wsutils.getAllMembers(ws) #---------- # check that we do not produce any collisions # with the names: no new name must have been # an old name and no two new names must # be the same import re oldNames = [x.GetName() for x in allMembers] newNames = [] numRenames = 0 for name in oldNames:
workspace = wsutils.findSingleWorkspace(fin, options) wsutils.applySetVars(workspace, options.setVars) allItemNames = None allObjs = [] for itemName in ARGV: if options.regex: # always interpret this as a regex if allItemNames == None: # get the names of all items allItemNames = [ x.GetName() for x in wsutils.getAllMembers(workspace) ] import re # use search(..) (not necessarily starting from the beginning) rather # than match(..) for name in allItemNames: mo = re.search(itemName, name) if mo: # don't care about duplicates for the moment obj = workspace.obj(name) assert obj != None allObjs.append(obj)