Пример #1
0
def writeCurrentFile(rootFile):
    ''' Save a copy of the current script, as a TText, in the current ROOT file
        nothing happens if a ROOT file is not currently open!
    '''
    import sys, os.path
    from ROOT import TString, TText, TFile
    filename = sys.argv[0]
    if (not os.path.exists(filename)):
        m_log.error("Could not open file " + filename + "!")
        return
    s = TString()
    t = TText()
    # Too fresh
    #with open(filename) as input:
    input = open(filename)
    if input:
        for line in input:
            s += line
    t.SetName(os.path.basename(filename))
    t.SetText(0, 0, s.Data())
    f = TFile(rootFile, 'UPDATE')
    t.Write()
    f.Close()
Пример #2
0
    parser = argparse.ArgumentParser()
    parser.add_argument("rootfile", help="ROOT file to embed label in")
    parser.add_argument("labels",
                        metavar='label',
                        nargs="+",
                        help="Label(s) to embed.  Format: key=value")

    args = parser.parse_args()

    for label in args.labels:
        if '=' not in label:
            print "Can't parse %s, you need to specify labels as key=val pars" \
                    % label
            sys.exit(1)

    # Don't import this until we know we need it
    from rootpy import io
    from ROOT import TText

    file = io.open(args.rootfile, 'UPDATE')
    file.cd()

    keep = []
    for label in args.labels:
        key, val = tuple(label.split('='))
        the_label = TText(0, 0, val)
        the_label.SetName(key)
        the_label.Write()
        keep.append(the_label)
    file.Write()