示例#1
0
def main():

    # Set up the environment:
    import ROOT
    if not ROOT.xAOD.Init("trig_test").isSuccess():
        print("Failed to call xAOD::Init(...)")
        return 1

    # Open an input file for reading:
    FNAME = "/afs/cern.ch/atlas/project/PAT/xAODs/r5787/" \
      "mc14_13TeV.110401.PowhegPythia_P2012_ttbar_nonallhad.merge.AOD." \
      "e2928_s1982_s2008_r5787_r5853_tid01597980_00/" \
      "AOD.01597980._000098.pool.root.1"
    ifile = ROOT.TFile.Open(FNAME, "READ")
    if not ifile:
        print("Couldn't open input file: %s" % FNAME)
        return 1

    # Create the necessary transient objects:
    tree = ROOT.xAOD.MakeTransientTree(ifile, "CollectionTree",
                                       ROOT.xAOD.TEvent.kBranchAccess)
    import xAODRootAccess.GenerateDVIterators
    from xAODRootAccess.TPyStore import TPyStore
    store = TPyStore()

    # Create the tool to be tested:
    tool = ROOT.TrigConf.xAODConfigTool("xAODConfigTool")

    # Load the first event, and check the configuration belonging to it:
    if tree.GetEntry(0) < 0:
        print("Couldn't load the first event of the input file")
        return 1
    if tool.masterKey() != 0 or tool.lvl1PrescaleKey() != 0 or \
      tool.hltPrescaleKey() != 0:
        print("Wrong configuration keys detected")
        return 1
    print("Number of LVL1 items: %i" % tool.ctpConfig().menu().items().size())
    if tool.ctpConfig().menu().items().size() != 105:
        print("Wrong number of LVL1 items loaded")
        return 1
    print("Number of HLT chain: %i" % tool.chains().size())
    if tool.chains().size() != 331:
        print("Wrong number of HLT chains loaded")
        return 1

    # Return gracefully:
    return 0
示例#2
0
def main():

    # Set up the command line option parser:
    from optparse import OptionParser
    parser = OptionParser(usage="%prog [options] [-f] xAOD.pool.root")
    parser.add_option("-f",
                      "--file",
                      dest="fileName",
                      action="store",
                      type="string",
                      default="",
                      help="Path to the file to check")
    parser.add_option("-d",
                      "--chainsdetail",
                      dest="chainsDetail",
                      action="store_true",
                      help="Print detailed chain definitions")
    (options, args) = parser.parse_args()

    # Get the file name(s):
    fileNames = []
    if len(args) > 0:
        fileNames = [arg for arg in args if arg[0] != "-"]
        pass
    if options.fileName != "":
        import os.path
        fileNames.append(
            os.path.expandvars(os.path.expanduser(options.fileName)))
        pass
    if len(fileNames) == 0:
        parser.print_help()
        return 1
    fileNames = set(fileNames)

    # Set up the environment for xAOD access:
    import ROOT
    ROOT.gROOT.Macro("$ROOTCOREDIR/scripts/load_packages.C")

    # Set up a TChain with the input file(s):
    chain = ROOT.TChain("CollectionTree")
    for fname in fileNames:
        chain.Add(fname)
        pass

    # And create the objects used to read this chain:
    tree = ROOT.xAOD.MakeTransientTree(chain, ROOT.xAOD.TEvent.kBranchAccess)
    from xAODRootAccess.TPyStore import TPyStore
    store = TPyStore()

    # Set up the tool used in the printout:
    tool = ROOT.TrigConf.xAODConfigTool("xAODConfigTool")
    if tool.initialize().isFailure():
        print("ERROR Couldn't initialise the trigger configuration tool")
        return 1

    # The keys of the configuration printed last:
    smk = 0
    l1psk = 0
    hltpsk = 0

    # Loop over the events of the file, to encounter all configurations in it:
    for entry in xrange(tree.GetEntries()):
        # Load the event:
        if tree.GetEntry(entry) < 0:
            print("ERROR Failed to load entry %i from the input" % entry)
            return 1
        # Always print the configuration for the first event, or when the
        # configuration changes:
        if ((entry == 0) or (smk != tool.masterKey())
                or (l1psk != tool.lvl1PrescaleKey())
                or (hltpsk != tool.hltPrescaleKey())):
            # Remember the keys:
            smk = tool.masterKey()
            l1psk = tool.lvl1PrescaleKey()
            hltpsk = tool.hltPrescaleKey()
            # Print the basic info:
            print( "Configuration for SMK: %i, L1PSK: %i, HLTPSK: %i" % \
                       ( smk, l1psk, hltpsk ) )
            detailLevel = 1
            if options.chainsDetail:
                detailLevel = 3
                pass
            getattr(tool.ctpConfig().menu(), "print")("", detailLevel)
            getattr(tool.chains(), "print")("", detailLevel)

            pass
        pass

    # Return gracefully:
    return 0
def main():

    # The name of the application:
    APP_NAME = "ut_xaodrootaccess_tpystore_test"

    # Set up a logger object:
    import logging
    logger = logging.getLogger( APP_NAME )
    logger.setLevel( logging.INFO )
    hdlr = logging.StreamHandler( sys.stdout )
    frmt = logging.Formatter( "%(name)-14s%(levelname)8s %(message)s" )
    hdlr.setFormatter( frmt )
    logger.addHandler( hdlr )

    # Set up the environment:
    import ROOT
    if ROOT.gROOT.Macro( "$ROOTCOREDIR/scripts/load_packages.C" ):
        logger.error( "Couldn't load the RootCore packages" )
        return 1
    if ROOT.xAOD.Init( APP_NAME ).isFailure():
        logger.error( "Failed to call xAOD::Init(...)" )
        return 1

    # Create the object to test:
    from xAODRootAccess.TPyStore import TPyStore
    store = TPyStore()

    # Record some basic objects into it:
    auxcont = ROOT.xAOD.AuxContainerBase()
    if not store.record( auxcont,
                         "AuxContainerBase" ).isSuccess():
        logger.error( "Couldn't record xAOD::AuxContainerBase object" )
        return 1
    auxinfo = ROOT.xAOD.AuxInfoBase()
    if not store.record( auxinfo,
                         "AuxInfoBase" ).isSuccess():
        logger.error( "Couldn't record xAOD::AuxInfoBase object" )
        return 1

    # Now check if the store know about them propertly:
    if not store.contains( "AuxContainerBase",
                           ROOT.xAOD.AuxContainerBase ):
        logger.error( "AuxContainerBase not available as "
                      "xAOD::AuxContainerBase" )
        return 1
    if not store.contains( "AuxContainerBase",
                           ROOT.SG.IAuxStore ):
        logger.error( "AuxContainerBase not available as "
                      "SG::IAuxStore" )
        return 1
    if not store.contains( "AuxInfoBase",
                           ROOT.xAOD.AuxInfoBase ):
        logger.error( "AuxInfoBase not available as "
                      "xAOD::AuxInfoBase" )
        return 1
    if not store.contains( "AuxInfoBase",
                           ROOT.SG.IAuxStoreIO ):
        logger.error( "AuxInfoBase not available as "
                      "SG::IAuxStoreIO" )
        return 1
    if store.contains( "AuxContainerBase",
                       ROOT.xAOD.ElectronAuxContainer_v1 ):
        logger.error( "AuxContainerBase available as "
                      "xAOD::ElectronAuxContainer_v1?!?" )
        return 1
    logger.info( "AuxContainerBase/AuxInfoBase containment tests "
                 "succeeded" )

    # Clear the store:
    store.clear()

    # Now the objects shouldn't be there anymore:
    if( store.contains( "AuxContainerBase", ROOT.xAOD.AuxContainerBase ) or
        store.contains( "AuxInfoBase", ROOT.xAOD.AuxInfoBase ) ):
        logger.error( "The objects are still in the store?!?" )
        return 1

    # Finish with a statement:
    logger.info( "All tests succeeded" )

    # Return gracefully:
    return 0
def main():

    # The name of the application:
    APP_NAME = "ut_xaodrootaccess_tpyevent_test"

    # Set up a logger object:
    import logging
    logger = logging.getLogger( APP_NAME )
    logger.setLevel( logging.INFO )
    hdlr = logging.StreamHandler( sys.stdout )
    frmt = logging.Formatter( "%(name)-14s%(levelname)8s %(message)s" )
    hdlr.setFormatter( frmt )
    logger.addHandler( hdlr )

    # Set up the environment:
    import ROOT
    if ROOT.gROOT.Macro( "$ROOTCOREDIR/scripts/load_packages.C" ):
        logger.error( "Couldn't load the RootCore packages" )
        return 1
    if ROOT.xAOD.Init( APP_NAME ).isFailure():
        logger.error( "Failed to call xAOD::Init(...)" )
        return 1

    # Create the objects to test:
    from xAODRootAccess.TPyEvent import TPyEvent
    event = TPyEvent()
    from xAODRootAccess.TPyStore import TPyStore
    store = TPyStore()

    # Create a transient tree from a test file:
    FNAME = "/afs/cern.ch/atlas/project/PAT/xAODs/r5591/" \
            "mc14_8TeV.117050.PowhegPythia_P2011C_ttbar.recon." \
            "AOD.e1727_s1933_s1911_r5591/AOD.01494881._105458.pool.root.1"
    ifile = ROOT.TFile.Open( FNAME, "READ" )
    if not ifile:
        logger.error( "Couldn't open input file: %s" % FNAME )
        return 1
    tree = ROOT.xAOD.MakeTransientTree( ifile )
    if not tree:
        logger.error( "Failed to make transient tree from file: %s" % FNAME )
        return 1

    # Connect the TPyEvent object to an output file:
    ofile = ROOT.TFile.Open( "test.root", "RECREATE" )
    if not ofile:
        logger.error( "Couldn't create test output file" )
        return 1
    if not event.writeTo( ofile ).isSuccess():
        logger.error( "Couldn't connect xAOD::TPyEvent object to the output "
                      "file" )
        return 1

    # Loop over 10 events from the input file:
    for entry in xrange( 10 ):

        # Load the event:
        tree.GetEntry( entry )
        logger.info( "Processing entry %i" % entry )

        # Clear the store:
        store.clear()

        # Copy the EventInfo payload:
        if not event.record( tree.EventInfo,
                             "EventInfo" ).isSuccess():
            logger.error( "Failed to record xAOD::EventInfo from the "
                          "input file" )
            return 1
        if not event.record( tree.EventInfo.getConstStore(),
                             "EventInfoAux." ).isSuccess():
            logger.error( "Faiedl to record xAOD::EventAuxInfo from the "
                          "input file" )
            return 1

        # Check that the electrons can be accessed:
        logger.info( "  Number of electrons: %i" %
                     tree.ElectronCollection.size() )

        # Copy the electrons into the output:
        if not event.record( tree.ElectronCollection,
                             "AllElectrons" ).isSuccess():
            logger.error( "Failed to record xAOD::ElectronContainer from the "
                          "input file" )
            return 1
        if not event.record( tree.ElectronCollection.getConstStore(),
                             "AllElectronsAux." ).isSuccess():
            logger.error( "Failed to record xAOD::ElectronAuxContainer from "
                          "the input file" )
            return 1

        # Create a container of just the central electrons:
        cElectrons = ROOT.xAOD.ElectronContainer_v1()

        # And record the container into the output right away. (In order to get
        # a proper auxiliary container for it.)
        cElectrons.setNonConstStore( event.recordAux( "CentralElectronsAux." ) )
        if not event.record( cElectrons,
                             "CentralElectrons" ).isSuccess():
            logger.error( "Failed to record central electrons into the output" )
            return 1

        # Now put all central electrons into this container, with just a few
        # properties. Since deep copying doesn't work this easily... :-(
        for i in xrange( tree.ElectronCollection.size() ):
            el = tree.ElectronCollection.at( i )
            if abs( el.eta() ) < 1.0:
                newEl = ROOT.xAOD.Electron_v1()
                cElectrons.push_back( newEl )
                newEl.setP4( el.pt(), el.eta(), el.phi(), el.m() )
                pass
            pass

        # Print how many central electrons got selected:
        logger.info( "  Number of central electrons: %i" %
                     cElectrons.size() )

        # Put an object into the transient store:
        trElectrons = ROOT.xAOD.ElectronContainer_v1()
        if not store.record( trElectrons, "TransientElectrons" ).isSuccess():
            logger.error( "Failed to record transient electrons into the "
                          "transient store" )
            return 1

        # Check that it is now available through TPyEvent:
        if not event.contains( "TransientElectrons",
                               ROOT.xAOD.ElectronContainer_v1 ):
            logger.error( "Transient electrons not visible through TPyEvent" )
            return 1

        # Record the event:
        event.fill()
        pass

    # Close the output file:
    if not event.finishWritingTo( ofile ).isSuccess():
        logger.error( "Couldn't call finishWritingTo(...)" )
        return 1
    ofile.Close()

    # Return gracefully:
    return 0
示例#5
0
def main():

    # The name of the application:
    APP_NAME = "ut_xaodrootaccess_tpyevent_test"

    # Set up a logger object:
    import logging
    logger = logging.getLogger(APP_NAME)
    logger.setLevel(logging.INFO)
    hdlr = logging.StreamHandler(sys.stdout)
    frmt = logging.Formatter("%(name)-14s%(levelname)8s %(message)s")
    hdlr.setFormatter(frmt)
    logger.addHandler(hdlr)

    # Set up the environment:
    import ROOT
    if ROOT.gROOT.Macro("$ROOTCOREDIR/scripts/load_packages.C"):
        logger.error("Couldn't load the RootCore packages")
        return 1
    if ROOT.xAOD.Init(APP_NAME).isFailure():
        logger.error("Failed to call xAOD::Init(...)")
        return 1

    # Create the objects to test:
    from xAODRootAccess.TPyEvent import TPyEvent
    event = TPyEvent()
    from xAODRootAccess.TPyStore import TPyStore
    store = TPyStore()

    # Create a transient tree from a test file:
    FNAME = "/afs/cern.ch/atlas/project/PAT/xAODs/r5591/" \
            "mc14_8TeV.117050.PowhegPythia_P2011C_ttbar.recon." \
            "AOD.e1727_s1933_s1911_r5591/AOD.01494881._105458.pool.root.1"
    ifile = ROOT.TFile.Open(FNAME, "READ")
    if not ifile:
        logger.error("Couldn't open input file: %s" % FNAME)
        return 1
    tree = ROOT.xAOD.MakeTransientTree(ifile)
    if not tree:
        logger.error("Failed to make transient tree from file: %s" % FNAME)
        return 1

    # Connect the TPyEvent object to an output file:
    ofile = ROOT.TFile.Open("test.root", "RECREATE")
    if not ofile:
        logger.error("Couldn't create test output file")
        return 1
    if not event.writeTo(ofile).isSuccess():
        logger.error("Couldn't connect xAOD::TPyEvent object to the output "
                     "file")
        return 1

    # Loop over 10 events from the input file:
    for entry in xrange(10):

        # Load the event:
        tree.GetEntry(entry)
        logger.info("Processing entry %i" % entry)

        # Clear the store:
        store.clear()

        # Copy the EventInfo payload:
        if not event.record(tree.EventInfo, "EventInfo").isSuccess():
            logger.error("Failed to record xAOD::EventInfo from the "
                         "input file")
            return 1
        if not event.record(tree.EventInfo.getConstStore(),
                            "EventInfoAux.").isSuccess():
            logger.error("Faiedl to record xAOD::EventAuxInfo from the "
                         "input file")
            return 1

        # Check that the electrons can be accessed:
        logger.info("  Number of electrons: %i" %
                    tree.ElectronCollection.size())

        # Copy the electrons into the output:
        if not event.record(tree.ElectronCollection,
                            "AllElectrons").isSuccess():
            logger.error("Failed to record xAOD::ElectronContainer from the "
                         "input file")
            return 1
        if not event.record(tree.ElectronCollection.getConstStore(),
                            "AllElectronsAux.").isSuccess():
            logger.error("Failed to record xAOD::ElectronAuxContainer from "
                         "the input file")
            return 1

        # Create a container of just the central electrons:
        cElectrons = ROOT.xAOD.ElectronContainer_v1()

        # And record the container into the output right away. (In order to get
        # a proper auxiliary container for it.)
        cElectrons.setNonConstStore(event.recordAux("CentralElectronsAux."))
        if not event.record(cElectrons, "CentralElectrons").isSuccess():
            logger.error("Failed to record central electrons into the output")
            return 1

        # Now put all central electrons into this container, with just a few
        # properties. Since deep copying doesn't work this easily... :-(
        for i in xrange(tree.ElectronCollection.size()):
            el = tree.ElectronCollection.at(i)
            if abs(el.eta()) < 1.0:
                newEl = ROOT.xAOD.Electron_v1()
                cElectrons.push_back(newEl)
                newEl.setP4(el.pt(), el.eta(), el.phi(), el.m())
                pass
            pass

        # Print how many central electrons got selected:
        logger.info("  Number of central electrons: %i" % cElectrons.size())

        # Put an object into the transient store:
        trElectrons = ROOT.xAOD.ElectronContainer_v1()
        if not store.record(trElectrons, "TransientElectrons").isSuccess():
            logger.error("Failed to record transient electrons into the "
                         "transient store")
            return 1

        # Check that it is now available through TPyEvent:
        if not event.contains("TransientElectrons",
                              ROOT.xAOD.ElectronContainer_v1):
            logger.error("Transient electrons not visible through TPyEvent")
            return 1

        # Record the event:
        event.fill()
        pass

    # Close the output file:
    if not event.finishWritingTo(ofile).isSuccess():
        logger.error("Couldn't call finishWritingTo(...)")
        return 1
    ofile.Close()

    # Clean up:
    ROOT.xAOD.ClearTransientTrees()

    # Return gracefully:
    return 0
示例#6
0
def main():

    # The name of the application:
    APP_NAME = "ut_xaodrootaccess_tpyevent_test"

    # Set up a logger object:
    import logging
    logger = logging.getLogger(APP_NAME)
    logger.setLevel(logging.INFO)
    hdlr = logging.StreamHandler(sys.stdout)
    frmt = logging.Formatter("%(name)-14s%(levelname)8s %(message)s")
    hdlr.setFormatter(frmt)
    logger.addHandler(hdlr)

    # Set up the environment:
    import ROOT
    if not ROOT.xAOD.Init(APP_NAME).isSuccess():
        logger.error("Failed to call xAOD::Init(...)")
        return 1

    # Create the objects to test:
    from xAODRootAccess.TPyEvent import TPyEvent
    event = TPyEvent()
    from xAODRootAccess.TPyStore import TPyStore
    store = TPyStore()

    # Create a transient tree from a test file:
    import os
    ifile = ROOT.TFile.Open("$ASG_TEST_FILE_MC", "READ")
    if not ifile:
        logger.error("Couldn't open input file: %s" %
                     os.environ.get("ASG_TEST_FILE_MC", "!ASG_TEST_FILE_MC!"))
        return 1
    tree = ROOT.xAOD.MakeTransientTree(ifile)
    if not tree:
        logger.error("Failed to make transient tree from file: %s" %
                     os.environ.get("ASG_TEST_FILE_MC", "!ASG_TEST_FILE_MC!"))
        return 1
    import xAODRootAccess.GenerateDVIterators

    # Connect the TPyEvent object to an output file:
    ofile = ROOT.TFile.Open("test.root", "RECREATE")
    if not ofile:
        logger.error("Couldn't create test output file")
        return 1
    if not event.writeTo(ofile).isSuccess():
        logger.error("Couldn't connect xAOD::TPyEvent object to the output "
                     "file")
        return 1

    # Loop over 10 events from the input file:
    for entry in xrange(10):

        # Load the event:
        tree.GetEntry(entry)
        logger.info("Processing entry %i" % entry)

        # Clear the store:
        store.clear()

        # Copy the Kt4EMTopoOriginEventShape payload:
        if not event.record(tree.Kt4EMTopoOriginEventShape,
                            "Kt4EMTopoOriginEventShape").isSuccess():
            logger.error("Failed to record xAOD::EventShape from the "
                         "input file")
            return 1
        if not event.record(tree.Kt4EMTopoOriginEventShape.getConstStore(),
                            "Kt4EMTopoOriginEventShapeAux.").isSuccess():
            logger.error("Faiedl to record xAOD::EventShapeAuxInfo from the "
                         "input file")
            return 1

        # Check that the muons can be accessed:
        logger.info("  Number of muons: %i" % tree.Muons.size())

        # Copy the muons into the output:
        if not event.record(tree.Muons, "AllMuons").isSuccess():
            logger.error("Failed to record xAOD::MuonContainer from the "
                         "input file")
            return 1
        if not event.record(tree.Muons.getConstStore(),
                            "AllMuonsAux.").isSuccess():
            logger.error("Failed to record xAOD::MuonAuxContainer from "
                         "the input file")
            return 1

        # Create a container of just the central muons:
        cMuons = ROOT.xAOD.MuonContainer()

        # And record the container into the output right away. (In order to get
        # a proper auxiliary container for it.)
        cMuons.setNonConstStore(event.recordAux("CentralMuonsAux."))
        if not event.record(cMuons, "CentralMuons").isSuccess():
            logger.error("Failed to record central muons into the output")
            return 1

        # Now put all central muons into this container, with just a few
        # properties. Since deep copying doesn't work this easily... :-(
        for mu in tree.Muons:
            if abs(mu.eta()) < 1.0:
                newMu = ROOT.xAOD.Muon()
                cMuons.push_back(newMu)
                newMu.setP4(mu.pt(), mu.eta(), mu.phi())
                pass
            pass

        # Print how many central muons got selected:
        logger.info("  Number of central muons: %i" % cMuons.size())

        # Put an object into the transient store:
        trMuons = ROOT.xAOD.MuonContainer()
        if not store.record(trMuons, "TransientMuons").isSuccess():
            logger.error("Failed to record transient muons into the "
                         "transient store")
            return 1

        # Check that it is now available through TPyEvent:
        if not event.contains("TransientMuons", ROOT.xAOD.MuonContainer):
            logger.error("Transient muons not visible through TPyEvent")
            return 1

        # Record the event:
        event.fill()
        pass

    # Close the output file:
    if not event.finishWritingTo(ofile).isSuccess():
        logger.error("Couldn't call finishWritingTo(...)")
        return 1
    ofile.Close()

    # Clean up:
    ROOT.xAOD.ClearTransientTrees()

    # Return gracefully:
    return 0