Source

mana-core-athenarootcomps / python / OutputStreamAthenaRoot.py

Full commit
## @file OutputStreamAthenaRoot.py
## @brief Helper methods to create output streams
## @author Sebastien Binet <binet@cern.ch>, Peter van Gemmeren <gemmeren@bnl.gov>
## $Id$
###############################################################

import AthenaCommon.CfgMgr as CfgMgr
from AthenaCommon.AppMgr import theApp
from AthenaRootCompsConf import Athena__RootOutputStreamTool as AthenaRootOutputStreamTool

def createNtupleOutputStream(streamName, fileName, tupleName="physics", asAlg = False):
    theApp.OutStreamType = "AthenaOutputStream"
    if asAlg:
        from AthenaCommon.AlgSequence import AlgSequence
        topSequence = AlgSequence()

    # Now do standard output stream
    writingTool1 = AthenaRootOutputStreamTool( streamName + "Tool" )
    writingTool1.TupleName = tupleName
    #writingTool1.DataHeaderSatellites = [ "basic/:EventInfo#*" ]
    writingTool1.OutputFile = fileName
    #writingTool1.
    outputStream = AthenaRootOutputStreamProtect(
        streamName,
        WritingTool = writingTool1,
        #ItemList    = [ "EventInfo#*" ]
        ItemList = ["unsigned int#RunNumber",
                    "unsigned int#EventNumber",]
        )
    if asAlg:
        from AthenaCommon.AlgSequence import AlgSequence
        topSequence += outputStream
    else:
        theApp.addOutputStream( outputStream )

    if fileName != "":
        outputStream.OutputFile = fileName
    return outputStream
        
def createOutputStream( streamName, fileName = "", asAlg = False ):
    from AthenaServices.AthenaServicesConf import AthenaOutputStream
    theApp.OutStreamType = "AthenaOutputStream"
    if asAlg:
        from AthenaCommon.AlgSequence import AlgSequence
        topSequence = AlgSequence()

    # Assure that the file meta data output stream runs before the normal output stream
    if fileName != "":
        from AthenaCommon.AppMgr import ServiceMgr as svcMgr
        """
        writingTool2 = AthenaRootOutputStreamTool( streamName + "_FHTool" )
        metaStream = AthenaOutputStream(
            streamName + "_FH",
            WritingTool = writingTool2,
            ItemList    = [ "EventStreamInfo#" + streamName, "IOVMetaDataContainer#*" ]
            )
        metaStream.WriteOnExecute = False
        metaStream.WriteOnFinalize = True
        metaStream.OutputFile = fileName
        if asAlg:
            topSequence += metaStream
        else:
            theApp.addOutputStream( metaStream )
        """

    # Now do standard output stream
    writingTool1 = AthenaRootOutputStreamTool( streamName + "Tool" )
    writingTool1.TupleName = "CollectionTree"
    outputStream = AthenaRootOutputStreamProtect(
       streamName,
       WritingTool = writingTool1,
       ItemList    = [ "EventInfo#*" ]
       )
    if asAlg:
        from AthenaCommon.AlgSequence import AlgSequence
        topSequence += outputStream
    else:
        theApp.addOutputStream( outputStream )

    if fileName != "":
        outputStream.OutputFile = fileName

    return outputStream

def createOutputConditionStream( streamName, fileName = "" ):
    from RegistrationServices.OutputConditionsAlg import OutputConditionsAlg
    conditionStream = OutputConditionsAlg(
        streamName,
        outputFile = fileName,
        WriteIOV = False
        )
    return conditionStream

## backward compat
#AthenaRootOutputStream          = createOutputStream
#AthenaRootOutputConditionStream = createOutputConditionStream

from AthenaCommon import CfgMgr
class AthenaRootOutputStreamProtect(CfgMgr.AthenaOutputStream):
    def __init__(self, name='Stream1', **kw):
        kw['name'] = kw.get('name', name)
        super(AthenaRootOutputStreamProtect, self).__init__(**kw)
        return

    def _set_output_file(self, fname):
        self._properties['OutputFile'].__set__(self, fname)
        from AthenaServices.AthenaServicesConf import AthenaOutputStream
        AthenaOutputStream("%s_FH" % (self._name,)).OutputFile = fname
        return

    def _get_output_file(self):
        return self._properties['OutputFile'].__get__(self)

    OutputFile = property(_get_output_file, _set_output_file, "fwd doc...")
    pass