Пример #1
0
def testPerfMon(jobOptName="PerfMonTests/test_perfMonSvc_noopalg.py",
                perfMonFileName="perfmon.noopalg.root",
                evtMax=50000):
    print("")
    print("#" * 80)
    print("## testing PerfMonSvc [%s]" % jobOptName)
    print("                  ==> [%s]... (%i)" % (perfMonFileName, evtMax))

    perfMonFileName = workDir(perfMonFileName)
    refPerfMonFileName = "ref." + os.path.basename(perfMonFileName)
    chkPerfMonFileName = "chk." + os.path.basename(perfMonFileName)
    outPerfMonFileName = "ana." + os.path.basename(perfMonFileName)

    refPerfMonFileName = refPerfMonFileName.replace(".root", ".pmon.gz")
    chkPerfMonFileName = chkPerfMonFileName.replace(".root", ".pmon.gz")

    ## create the reference file
    athena = ChapPy.Athena(jobOptions=[
        ChapPy.JobOptions(jobOptName),
        ChapPy.JobOptionsCmd("jobproperties.PerfMonFlags.OutputFile = '%s'" %
                             refPerfMonFileName)
    ],
                           checkLeak=False,
                           logFile=refPerfMonFileName + ".log")
    athena.EvtMax = evtMax
    sc = athena.run()
    if sc != 0:
        print("ERROR: could not create the 'ref' perfmon file !!")
        return ScOutput(sc, "ERROR")

    ## create the to-be-checked file
    athena = ChapPy.Athena(jobOptions=[
        ChapPy.JobOptions(jobOptName),
        ChapPy.JobOptionsCmd("jobproperties.PerfMonFlags.OutputFile = '%s'" %
                             chkPerfMonFileName)
    ],
                           checkLeak=False,
                           logFile=chkPerfMonFileName + ".log")
    athena.EvtMax = evtMax
    sc = athena.run()
    if sc != 0:
        print("ERROR: could not create the 'chk' perfmon file !!")
        return ScOutput(sc, "ERROR")

    #outPerfMonFileName = "ana." + os.path.basename( perfMonFileName )
    print(" :::running [perfmon.py]...")
    cmd = "perfmon.py %s %s -o %s" % \
          ( chkPerfMonFileName, refPerfMonFileName, outPerfMonFileName )
    sc, out = subprocess.getstatusoutput(cmd)
    if sc != 0:
        print("## Problem while doing [perfmon] !!")
        print(out)
        out = "ERROR"
        return ScOutput(sc, out)

    out = "OK"
    print("## [DONE]")
    return ScOutput(sc, out)
Пример #2
0
def doPostCheck(validationName, refFileName, chkFileName, chkFilter):
    import commands
    print("## Validation of [%s]" % validationName)
    print("## ref:    %s" % refFileName)
    print("## chk:    %s" % chkFileName)
    print("## filter: [%s]" % chkFilter)
    sc, out = commands.getstatusoutput( "cat %s | %s | diff -u %s -" % \
                                        ( chkFileName, chkFilter,
                                          refFileName ) )
    if sc == 0 and len(out) == 0: print("==> Validation [OK]")
    else: print("==> Validation [ERROR]\n", "*" * 80, out, "*" * 80)
    return ScOutput(sc, out)
Пример #3
0
def doValidation(dbFiles, key):
    """Helper function to validate output of jobs against 'registered' ASCII
    files.
    """
    import commands
    from TestTools.iobench import ScOutput
    print("## Validation of ASCII files [%s]:" % key)
    print("## %15s : %s" % ('ref', dbFiles[key]['ref']))
    print("## %15s : %s" % ('chk', dbFiles[key]['chk']))
    sc, out = commands.getstatusoutput(
        "diff %s %s" % (dbFiles[key]['ref'], dbFiles[key]['chk']))
    if sc == 0 and len(out) == 0:
        print("==> Validation [OK]")
    else:
        print("==> Validation [ERROR]")
        pass
    return ScOutput(sc, out)
Пример #4
0
def doReadWriteTest(genName="TruthParticles", evtMax=100):
    ###-----------------------------------------------------
    print("\n")
    print("#" * 80)
    print("## Preparing input data... [%s]" % genName)
    templateJobO = """
OUTPUT='%(OutputFile)s';
DUMP=True;
include( 'McParticleTests/iotest_WriteGenEvent_jobOptions.py' );
"""
    jobOptions = [
        ChapPy.JobOptionsCmd(templateJobO % {
            'OutputFile': workDir("mc.event.%s.pool" % uuid),
        })
    ]
    athena = ChapPy.Athena(jobOptions=jobOptions,
                           logFile=workDir("mc.event.%s.pool.log" % uuid),
                           checkLeak=False)
    athena.EvtMax = evtMax
    sc = athena.run()
    if sc != 0:
        return ScOutput(sc, "ERROR")

    ###-----------------------------------------------------
    print("\n")
    print("#" * 80)
    print("## Testing [writing-%s]..." % genName)
    templateJobO = """
INPUT=['%(InputFile)s'];
OUTPUT= '%(OutputFile)s';
DUMPTUPLE=True;
TUPLEFILENAME='%(TupleFile)s';
include( 'McParticleTests/iotest_WriteTruthParticles_jobOptions.py' );
jobproperties.PerfMonFlags.OutputFile = '%(PmonFile)s';
"""
    jobOptions = [
        ChapPy.JobOptionsCmd(
            templateJobO % {
                'InputFile':
                workDir("mc.event.%s.pool" % uuid),
                'OutputFile':
                outFiles['ref'],
                'TupleFile':
                outFiles['ref'].replace(".pool", ".tuple.root"),
                'PmonFile':
                workDir("write.mcaod.%s.%s.perfmon.pmon.gz" % (genName, uuid)),
            })
    ]

    athena = ChapPy.Athena(jobOptions=jobOptions,
                           logFile=outFiles['ref'] + ".log",
                           checkLeak=False)
    athena.EvtMax = evtMax
    sc = athena.run()
    if sc != 0:
        return ScOutput(sc, "ERROR")
    else:
        inFile = workDir("write.mcaod.%s.%s.perfmon.pmon.gz" % (genName, uuid))
        outFile = workDir("out.write.mcaod.%s.%s.perfmon.root" %
                          (genName, uuid))
        subprocess.getoutput("perfmon.py %s -o %s" % (inFile, outFile))

    ###-----------------------------------------------------
    print("\n")
    print("#" * 80)
    print("## Testing [reading-%s]..." % genName)
    templateJobO = """
INPUT=['%(InputFile)s'];
OUTPUT= '%(OutputFile)s';
DUMPTUPLE=True;
TUPLEFILENAME='%(TupleFile)s';
include( 'McParticleTests/iotest_ReadTruthParticles_jobOptions.py' );
jobproperties.PerfMonFlags.OutputFile = '%(PmonFile)s';
"""
    jobOptions = [
        ChapPy.JobOptionsCmd(
            templateJobO % {
                'InputFile':
                outFiles['ref'],
                'OutputFile':
                outFiles['chk'],
                'TupleFile':
                outFiles['chk'].replace(".pool", ".tuple.root"),
                'PmonFile':
                workDir("read.mcaod.%s.%s.perfmon.pmon.gz" % (genName, uuid)),
            })
    ]
    athena = ChapPy.Athena(jobOptions=jobOptions,
                           logFile=outFiles['chk'] + ".log",
                           checkLeak=False)
    athena.EvtMax = evtMax
    sc = athena.run()
    if sc != 0:
        return ScOutput(sc, "ERROR")
    else:
        inFile = workDir("read.mcaod.%s.%s.perfmon.pmong.gz" % (genName, uuid))
        outFile = workDir("out.read.mcaod.%s.%s.perfmon.root" %
                          (genName, uuid))
        subprocess.getoutput("perfmon.py %s -o %s" % (inFile, outFile))

    ###-----------------------------------------------------
    print("\n")
    print("#" * 80)
    return doMcAodTupleValidation(
        outFiles['ref'].replace(".pool", ".tuple.root"),
        outFiles['chk'].replace(".pool", ".tuple.root"))
Пример #5
0
def doMcAodTupleValidation( refFileName, chkFileName, diffFileName = None ):
    """function to check 2 mcaod tuple files
    """
    import math, os
    from TestTools.iobench import ScOutput

    if not diffFileName:
        diffFileName = os.path.join( os.path.dirname(refFileName),
                                     "diff."+os.path.basename(refFileName) )

    print ("## tuple validation :")
    print ("## -ref:  %s" % refFileName)
    print ("## -chk:  %s" % chkFileName)
    print ("## -diff: %s" % diffFileName)

    import sys
    oldArgs = sys.argv
    sys.argv = sys.argv[:1] + ['-b'] + sys.argv[1:]

    print ("## loading ROOT...")
    import ROOT
    print ("## loading ROOT... [DONE]")
    sys.argv = oldArgs
    del oldArgs
    ROOT.gROOT.SetStyle("Plain")
    ROOT.gStyle.SetOptStat(111111)
    
    print ("## opening tuple files...")
    refFile = ROOT.TFile( refFileName, "READ" )
    chkFile = ROOT.TFile( chkFileName, "READ" )
    print ("## opening tuple files... [DONE]")

    refTree = refFile.Get( "mcaod" )
    chkTree = chkFile.Get( "mcaod" )
    nEntries = refTree.GetEntries()
    print ("## ref tuple [%i] entries" % nEntries)
    print ("## chk tuple [%i] entries" % chkTree.GetEntries())
    assert( nEntries == chkTree.GetEntries() )

    from AthenaCommon.SystemOfUnits import MeV
    nBins = 1000
    xMin  = -0.2*MeV
    xMax  = +0.2*MeV
    histos = {}
    etCones = [ 'etcone%i' % i for i in [10,20,30,40,45,50,60,70] ]
    for etCone in etCones:
        histos[etCone] = ROOT.TH1D( etCone, "[diff] %s" % etCone,
                                    nBins, xMin, xMax )
    hKeys = histos.keys()
    hKeys.sort()
    
    for iEntry in range(nEntries):
        refTree.LoadTree(iEntry)
        nb = refTree.GetEntry(iEntry)
        if nb <= 0:
            print ("## Could not load [ref] entry [%i] !!" % iEntry)
            continue
        chkTree.LoadTree(iEntry)
        nb = chkTree.GetEntry(iEntry)
        if nb <= 0:
            print ("## Could not load [chk] entry [%i] !!" % iEntry)
            continue
        nParts = refTree.nParts
        assert(nParts == chkTree.nParts)
        diff = { 'etcone10' : 0.,
                 'etcone20' : 0.,
                 'etcone30' : 0.,
                 'etcone40' : 0.,
                 'etcone45' : 0.,
                 'etcone50' : 0.,
                 'etcone60' : 0.,
                 'etcone70' : 0.,
                 }
        for iPart in range(nParts):
            for k in diff.keys():
                diff[k] += ( getattr(refTree,k)[iPart] -
                             getattr(chkTree,k)[iPart] )
        for k in diff.keys():
            histos[k].Fill( diff[k], 1. )
                            
    out = []
    nErrors = 0
    canvas = []
    for k in hKeys:
        c = ROOT.TCanvas('c_diff_'+k, 'Differences [%s]' % k )
        canvas.append( c )
        c.cd(0)
        h = histos[k]
        h.SetLineColor( ROOT.kRed )
        h.SetLineWidth( 2 )
        h.Draw()
        data = [ h.GetName(),
                 h.GetMean(), h.GetRMS(),
                 h.GetBinContent(0),
                 h.GetBinContent(h.GetNbinsX()+1) ]
        if math.fabs(data[1]) > .01*MeV or \
           math.fabs(data[2]) > .05*MeV or \
           data[3] > 1. or \
           data[4] > 1. :
            nErrors += 1
        outBeg = len(out)-1
        out += [ "",
                 "== [%s] ==" % data[0],
                 " Mean:   %f MeV" % data[1],
                 " RMS:    %f" % data[2],
                 " U-flow: %f" % data[3],
                 " O-flow: %f" % data[4]
                 ]
        print (os.linesep.join( out[outBeg+1:len(out)] ))
        pass

    pdfFileName = diffFileName.replace(".root", '.ps' )
    pdfOrientation = "Landscape"
    
    canvas[0].Print( pdfFileName + "[", pdfOrientation )
    for c in canvas:
        c.Print( pdfFileName, pdfOrientation )
    canvas[0].Print( pdfFileName + "]", pdfOrientation )
    sc,out = subprocess.getstatusoutput(
        "ps2pdf %s %s" % ( pdfFileName,
                           pdfFileName.replace( ".ps", ".pdf" ) )
        )
    if os.path.exists( pdfFileName ):
        os.remove( pdfFileName )
    
    diffRootFile = ROOT.TFile( diffFileName, "RECREATE" )
    diffRootFile.cd()
    for h in histos.values():
        h.Write()
        pass
    diffRootFile.Close()
    
    if nErrors == 0:
        sc = 0
        print ("==> (tuple) Validation [OK]")
    else:
        sc = 1
        print ("## Errors during validation:",nErrors)
        print ("==> (tuple) Validation [ERROR]")
        
    return ScOutput( sc,os.linesep.join(out) )
Пример #6
0
def doTupleValidation( refFileName, chkFileName, diffFileName = None ):
    """function to check 2 tuple files
    """
    import math, os
    from TestTools.iobench import ScOutput

    if not diffFileName:
        diffFileName = os.path.join( os.path.dirname(refFileName),
                                     "diff."+os.path.basename(refFileName) )

    print ("## tuple validation :")
    print ("## -ref:  %s" % refFileName)
    print ("## -chk:  %s" % chkFileName)
    print ("## -diff: %s" % diffFileName)

    import sys
    oldArgs = sys.argv
    sys.argv = sys.argv[:1] + ['-b'] + sys.argv[1:]

    print ("## loading ROOT...")
    import ROOT
    print ("## loading ROOT... [DONE]")
    sys.argv = oldArgs
    del oldArgs
    ROOT.gROOT.SetStyle("Plain")
    ROOT.gStyle.SetOptStat(111111)
    
    print ("## opening tuple files...")
    refFile = ROOT.TFile( refFileName, "READ" )
    chkFile = ROOT.TFile( chkFileName, "READ" )
    print ("## opening tuple files... [DONE]")

    refTree = refFile.Get( "hepmc" )
    chkTree = chkFile.Get( "hepmc" )
    nEntries = refTree.GetEntries()
    print ("## ref tuple [%i] entries" % nEntries)
    print ("## chk tuple [%i] entries" % chkTree.GetEntries())
    assert( nEntries == chkTree.GetEntries() )

    from AthenaCommon.SystemOfUnits import GeV
    nBins = 1000
    xMin  = -2.*GeV
    xMax  = +2.*GeV
    histos = {}
    histos['px'] = ROOT.TH1D( 'diffPx', "[diff] Px",   nBins, xMin, xMax )
    histos['py'] = ROOT.TH1D( 'diffPy', "[diff] Py",   nBins, xMin, xMax )
    histos['pz'] = ROOT.TH1D( 'diffPz', "[diff] Pz",   nBins, xMin, xMax )
    histos['m' ] = ROOT.TH1D( 'diffM',  "[diff] Mass", nBins, xMin, xMax )
    histos['e' ] = ROOT.TH1D( 'diffEne',"[diff] Ene",  nBins, xMin, xMax )
    hKeys = histos.keys()
    hKeys.sort()
    
    for iEntry in range(nEntries):
        refTree.LoadTree(iEntry)
        nb = refTree.GetEntry(iEntry)
        if nb <= 0:
            print ("## Could not load [ref] entry [%i] !!" % iEntry)
            continue
        chkTree.LoadTree(iEntry)
        nb = chkTree.GetEntry(iEntry)
        if nb <= 0:
            print ("## Could not load [chk] entry [%i] !!" % iEntry)
            continue
        nParts = refTree.nParts
        assert(nParts == chkTree.nParts)
        diff = { 'px' : 0.,
                 'py' : 0.,
                 'pz' : 0.,
                 'm'  : 0.,
                 'e'  : 0. }
        for iPart in range(nParts):
            diff['px'] += ( refTree.px[iPart] - chkTree.px[iPart] )
            diff['py'] += ( refTree.py[iPart] - chkTree.py[iPart] )
            diff['pz'] += ( refTree.pz[iPart] - chkTree.pz[iPart] )
            diff['m' ] += ( refTree.m[iPart]  - chkTree.m[iPart]  )
            diff['e' ] += ( refTree.e[iPart]  - chkTree.e[iPart]  )
        for k in diff.keys():
            histos[k].Fill( diff[k], 1. )
                            
    out = []
    nErrors = 0
    c = ROOT.TCanvas('c_diff', 'Differences')
    c.Divide(2,3)
    i = 1
    for k in hKeys:
        c.cd(i).SetLogy()
        h = histos[k]
        h.SetLineColor( ROOT.kRed )
        h.SetLineWidth( 2 )
        h.Draw()
        i += 1
        data = [ h.GetName(),
                 h.GetMean(), h.GetRMS(),
                 h.GetBinContent(0),
                 h.GetBinContent(h.GetNbinsX()+1) ]
        if math.fabs(data[1]) > .1*GeV or \
           math.fabs(data[2]) > 1.*GeV or \
           data[3] >= 10. or \
           data[4] >= 10. :
            nErrors += 1
        outBeg = len(out)-1
        out += [ "",
                 "== [%s] ==" % data[0],
                 " Mean:   %f MeV" % data[1],
                 " RMS:    %f" % data[2],
                 " U-flow: %f" % data[3],
                 " O-flow: %f" % data[4]
                 ]
        print (os.linesep.join( out[outBeg+1:len(out)] ))
        pass
    c.Print( diffFileName.replace(".root", ".pdf"),
             "Landscape" )
    
    diffRootFile = ROOT.TFile( diffFileName, "RECREATE" )
    diffRootFile.cd()
    for h in histos.values():
        h.Write()
        pass
    diffRootFile.Close()
    
    if nErrors == 0:
        sc = 0
        print ("==> (tuple) Validation [OK]")
    else:
        sc = 1
        print ("## Errors during validation:",nErrors)
        print ("==> (tuple) Validation [ERROR]")
        
    return ScOutput( sc,os.linesep.join(out) )
Пример #7
0
def doFloatValidation( refFileName, chkFileName ):
    """function to check 2 files, taking into account float rounding...
    """
    import math, os
    from TestTools.iobench import ScOutput
    
    print ("## float validation :")
    print ("## -ref: %s" % refFileName)
    print ("## -chk: %s" % chkFileName)

    refFile = open( refFileName, "r" )
    chkFile = open( chkFileName, "r" )

    refFloatPrecision = refFile.readline()
    chkFloatPrecision = chkFile.readline()

    assert( refFloatPrecision == chkFloatPrecision )

    fltPrecision = float( refFloatPrecision.split( "=" )[1].replace("\n","") )
    # in a perfect world this should be: 1.19209e-07
    fltPrecision = [ 1.19209e-06 ] * 3 + [ 1.19209e-02 ] + [ 1.5e2 ]
    #fltPrecision = [1.5e-2, 1.5e-2, 1.5e-2, 1.5e-2, 1.5e-2]
    #fltPrecision = [ 1. ] * 5
    print ("## float precision: %r" % fltPrecision)
    
    out = []
    nErrors = 0
    for refLine,chkLine in zip( refFile, chkFile):
        if refLine.startswith( "#" ) and refLine != chkLine:
            out += [ "==> ERROR:",
                     " ref: %r" % refLine,
                     " chk: %r" % chkLine ]
            nErrors += 1
        if not refLine.startswith( "#" ):
            refFloats = [ float(f.strip()) for f in refLine.split(" ") ]
            chkFloats = [ float(f.strip()) for f in chkLine.split(" ") ]
            if len(chkFloats) != len(refFloats):
                out += [ "==> ERROR:",
                         " ref: %r" % refFloats,
                         " chk: %r" % chkFloats ]
                nErrors += 1
                continue
            for i in range(len(refFloats)):
                refFloat = refFloats[i]
                chkFloat = chkFloats[i]
                # delta = math.fabs(refFloat) - math.fabs(chkFloat)
                delta = (refFloat - chkFloat)/ (float(refFloat) or 1.)
                # delta = refFloat - chkFloat
                if math.fabs( delta ) > fltPrecision[i]:
                    out += ["==> ERROR:",
                            " ref: %r" % refLine,
                            " chk: %r" % chkLine,
                            " del: %r %i" % (delta,i)
                            ]
                    nErrors += 1
                    break
    if nErrors == 0:
        sc = 0
        print ("==> (float) Validation [OK]")
    else:
        sc = 1
        print ("## Errors during validation:",nErrors)
        print ("==> (float) Validation [ERROR]")
        
    return ScOutput( sc,os.linesep.join(out) )
Пример #8
0
def doReadWriteTest(genName="pythia", evtMax=100):
    """A simple wrapper around the read/write tests..."""
    genName = genName.lower()
    ###-----------------------------------------------------
    print ""
    print "#" * 80
    print "## Testing [writing-%s]..." % genName
    templateJobO = """
OUTPUT='%(OutputFile)s';
DUMPTUPLE=True;
GENERATOR='%(Generator)s';
TUPLEFILENAME='%(TupleFile)s';
include( 'McParticleTests/iotest_WriteGenEvent_jobOptions.py' );
jobproperties.PerfMonFlags.OutputFile = '%(PmonFile)s';
"""
    jobOptions = [
        ChapPy.JobOptionsCmd( templateJobO % {
        'OutputFile' : workDir("mc.event.%s.pool" % genName),
        'Generator'  : genName.upper(),
        'TupleFile'  : outFiles['gen_%s' % genName]['ref']\
                       .replace(".pool",".tuple.root"),
        'PmonFile'   : workDir("write.genevent.%s.pmon.gz" % genName),
        } )
        ]

    athena = ChapPy.Athena(jobOptions=jobOptions,
                           logFile=workDir("write.genevent.%s.log" % genName),
                           checkLeak=False)
    athena.EvtMax = evtMax
    sc = athena.run()
    if sc != 0:
        return ScOutput(sc, "ERROR")
    else:
        inFile = workDir("write.genevent.%s.pmon.gz" % genName)
        outFile = workDir("out.write.genevent.%s.pmon.root" % genName)
        print commands.getoutput("perfmon.py %s -o %s" % (inFile, outFile))

    ###-----------------------------------------------------
    print ""
    print "#" * 80
    print "## Testing [ASCII-writing-%s (1)]..." % genName
    templateJobO = """
INPUT=%(InputFile)s;
OUTPUT='%(OutputFile)s';
DUMPTUPLE=True;
GENERATOR='%(Generator)s';
include( 'McParticleAlgs/GenEventAsciiWriter_jobOptions.py' );
"""
    jobOptions = [
        ChapPy.JobOptionsCmd(
            templateJobO % {
                'InputFile': [
                    workDir("mc.event.%s.pool" % genName),
                ],
                'OutputFile': workDir("mc.event.%s.1.ascii" % genName),
                'Generator': genName.upper(),
            })
    ]

    athena = ChapPy.Athena(jobOptions=jobOptions,
                           logFile=workDir("write.genevent.ascii.1.%s.log" %
                                           genName),
                           checkLeak=False)
    athena.EvtMax = evtMax
    sc = athena.run()
    if sc != 0:
        return ScOutput(sc, "ERROR")

    ###-----------------------------------------------------
    print ""
    print "#" * 80
    print "## Testing [ASCII-writing-%s (2)]..." % genName
    templateJobO = """
INPUT=%(InputFile)s;
OUTPUT='%(OutputFile)s';
DUMPTUPLE=True;
GENERATOR='%(Generator)s';
include( 'McParticleAlgs/GenEventAsciiWriter_jobOptions.py' );
"""
    jobOptions = [
        ChapPy.JobOptionsCmd(
            templateJobO % {
                'InputFile': [
                    workDir("mc.event.%s.pool" % genName),
                ],
                'OutputFile': workDir("mc.event.%s.2.ascii" % genName),
                'Generator': genName.upper(),
            })
    ]

    athena = ChapPy.Athena(jobOptions=jobOptions,
                           logFile=workDir("write.genevent.ascii.2.%s.log" %
                                           genName),
                           checkLeak=False)
    athena.EvtMax = evtMax
    sc = athena.run()
    if sc != 0:
        return ScOutput(sc, "ERROR")

    ###-----------------------------------------------------
    print "\n"
    print "#" * 80
    print "## Testing [ASCII-reading-%s]..." % genName
    templateJobO = """
INPUT=%(InputFiles)s;
include( 'McAsciiEventSelector/Example_McAsciiReader_jobOptions.py' );
"""
    jobOptions = [
        ChapPy.JobOptionsCmd( templateJobO % {
        'InputFiles' : [ workDir("mc.event.%s.1.ascii" % genName),
                         workDir("mc.event.%s.2.ascii" % genName),],
        'TupleFile' : outFiles['gen_%s' % genName]['chk']\
                      .replace(".pool",".tuple.root"),
        'PmonFile'  : workDir("read.genevent.%s.pmon.gz" % genName),
        } )
    ]
    athena = ChapPy.Athena(jobOptions=jobOptions,
                           logFile=workDir("read.genevent.%s.log" % genName),
                           checkLeak=False)
    athena.EvtMax = evtMax
    sc = athena.run()
    if sc != 0:
        return ScOutput(sc, "ERROR")

    ###-----------------------------------------------------
    print "\n"
    print "#" * 80
    return ScOutput(0, "OK")
Пример #9
0
def doReadWriteTest(genName="pythia", evtMax=100):
    """A simple wrapper around the read/write tests..."""
    genName = genName.lower()
    ###-----------------------------------------------------
    print("")
    print("#" * 80)
    print("## Testing [writing-%s]..." % genName)
    templateJobO = """
OUTPUT='%(OutputFile)s';
DUMPTUPLE=True;
GENERATOR='%(Generator)s';
TUPLEFILENAME='%(TupleFile)s';
include( 'McParticleTests/iotest_WriteGenEvent_jobOptions.py' );
jobproperties.PerfMonFlags.OutputFile = '%(PmonFile)s';
"""
    jobOptions = [
        ChapPy.JobOptionsCmd( templateJobO % {
        'OutputFile' : workDir("mc.event.%s.%s.pool" % (genName,uuid)),
        'Generator'  : genName.upper(),
        'TupleFile'  : outFiles['gen_%s' % genName]['ref']\
                       .replace(".pool",".tuple.root"),
        'PmonFile'   : workDir("write.genevent.%s.%s.pmon.gz"%(genName,uuid)),
        } )
        ]

    athena = ChapPy.Athena(jobOptions=jobOptions,
                           logFile=workDir("write.genevent.%s.%s.log" %
                                           (genName, uuid)),
                           checkLeak=False)
    athena.EvtMax = evtMax
    sc = athena.run()
    if sc != 0:
        return ScOutput(sc, "ERROR")
    else:
        inFile = workDir("write.genevent.%s.%s.pmon.gz" % (genName, uuid))
        outFile = workDir("out.write.genevent.%s.%s.pmon.root" %
                          (genName, uuid))
        print(subprocess.getoutput("perfmon.py %s -o %s" % (inFile, outFile)))

    ###-----------------------------------------------------
    print("\n")
    print("#" * 80)
    print("## Testing [reading-%s]..." % genName)
    templateJobO = """
INPUT=['%(InputFile)s'];
DUMPTUPLE=True;
TUPLEFILENAME='%(TupleFile)s';
include( 'McParticleTests/iotest_ReadGenEvent_jobOptions.py' );
jobproperties.PerfMonFlags.OutputFile = '%(PmonFile)s';
"""
    jobOptions = [
        ChapPy.JobOptionsCmd( templateJobO % {
        'InputFile' : workDir("mc.event.%s.%s.pool" % (genName,uuid)),
        'TupleFile' : outFiles['gen_%s' % genName]['chk']\
                      .replace(".pool",".tuple.root"),
        'PmonFile'  : workDir("read.genevent.%s.%s.pmon.gz" % (genName,uuid)),
        } )
    ]
    athena = ChapPy.Athena(jobOptions=jobOptions,
                           logFile=workDir("read.genevent.%s.%s.log" %
                                           (genName, uuid)),
                           checkLeak=False)
    athena.EvtMax = evtMax
    sc = athena.run()
    if sc != 0:
        return ScOutput(sc, "ERROR")
    else:
        inFile = workDir("read.genevent.%s.%s.pmon.gz" % (genName, uuid))
        outFile = workDir("out.read.genevent.%s.%s.pmon.root" %
                          (genName, uuid))
        print(subprocess.getoutput("perfmon.py %s -o %s" % (inFile, outFile)))

    ###-----------------------------------------------------
    print("\n")
    print("#" * 80)
    return doTupleValidation(
        outFiles['gen_%s' % genName]['ref'].replace(".pool", ".tuple.root"),
        outFiles['gen_%s' % genName]['chk'].replace(".pool", ".tuple.root"))