예제 #1
0
def createOutputStream( streamName, fileName = "", asAlg = False ):
   writingTool = AthenaPoolOutputStreamTool( streamName + "Tool" )
   writingTool.DataHeaderSatellites = [ "basic/:EventInfo#*" ]
   outputStream = AthenaOutputStream(
      streamName,
      WritingTool = writingTool,
      ItemList    = [ "EventInfo#*" ]
      )
   outputStream.MetadataStore = svcMgr.MetaDataStore
   outputStream.MetadataItemList = [ "EventStreamInfo#" + streamName, "IOVMetaDataContainer#*" ]
   if asAlg:
      from AthenaCommon.AlgSequence import AlgSequence
      topSequence = AlgSequence()
      topSequence += outputStream
   else:
      theApp.OutStreamType = "AthenaOutputStream"
      theApp.addOutputStream( outputStream )

   if fileName != "":
      outputStream.OutputFile = fileName
      from OutputStreamAthenaPoolConf import MakeEventStreamInfo 
      streamInfoTool = MakeEventStreamInfo( streamName + "_MakeEventStreamInfo" )
      streamInfoTool.Key = streamName
      outputStream.HelperTools = [ streamInfoTool ]
   return outputStream
    def __init__(self, StreamName, FileName):
        AugmentedStreamBase.__init__(self, StreamName)

        #General setup
        from AthenaCommon.AppMgr import theApp
        svcMgr = theApp.serviceMgr()
        from AthenaCommon.AlgSequence import AlgSequence
        topSequence = AlgSequence()

        # BS OutputStream Tool
        from ByteStreamCnvSvc.ByteStreamCnvSvcConf import ByteStreamEventStorageOutputSvc, ByteStreamOutputStreamCopyTool
        self.bsCopyTool = ByteStreamOutputStreamCopyTool(
            "OutputStreamBSCopyTool")
        svcMgr.ToolSvc += self.bsCopyTool

        #default output directory
        import commands
        cmd = 'pwd'
        (statusCode, outDir) = commands.getstatusoutput(cmd)
        outDir += "/"

        # BS output Svc
        from ByteStreamCnvSvc.ByteStreamCnvSvcConf import ByteStreamEventStorageOutputSvc
        self.bsOutputSvc = ByteStreamEventStorageOutputSvc(
            "BSESOutputSvc" + StreamName,
            OutputDirectory=outDir,
            SimpleFileName=FileName)
        svcMgr += self.bsOutputSvc

        # Set BS OutputSvc/InputSvc to BS OutputStream Tool
        self.bsCopyTool.ByteStreamOutputSvc = self.bsOutputSvc
        self.bsCopyTool.ByteStreamInputSvc = svcMgr.ByteStreamInputSvc

        # create AthenaOutputStream for BS Copy and add it to topSequence
        from AthenaServices.AthenaServicesConf import AthenaOutputStream
        self.Stream = AthenaOutputStream(StreamName,
                                         WritingTool=self.bsCopyTool)

        #topSequence += self.Stream #<-- coherent with asAlg=False in OutputStreamAthenaPool.py
        theApp.addOutputStream(self.Stream)
        return
예제 #3
0
def createNtupleOutputStream(streamName,
                             fileName,
                             tupleName="physics",
                             asAlg=False):
    if asAlg:
        from AthenaCommon.AlgSequence import AlgSequence
        topSequence = AlgSequence()
        pass
    else:
        theApp.OutStreamType = "Athena::RootNtupleOutputStream"
        theApp.OutStreamType = "AthenaOutputStream"
        pass

    # Now do standard output stream
    writingTool1 = AthenaRootOutputStreamTool(streamName + "Tool")
    writingTool1.TreeName = tupleName
    #writingTool1.DataHeaderSatellites = [ "basic/:EventInfo#*" ]
    writingTool1.OutputFile = fileName
    #writingTool1.
    cls = AthenaRootNtupleOutputStreamProtect
    #cls = CfgMgr.Athena__RootNtupleOutputStream
    outputStream = cls(
        streamName,
        WritingTool=writingTool1,
        ItemList=[
            "RunNumber",
            "EventNumber",
        ],
        #StrictClidMatching = False,
    )
    if asAlg:
        from AthenaCommon.AlgSequence import AlgSequence
        topSequence += outputStream
    else:
        theApp.addOutputStream(outputStream)

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

    # Now do standard output stream
    writingTool1 = AthenaRootOutputStreamTool(streamName + "Tool")
    writingTool1.TreeName = "CollectionTree"
    outputStream = AthenaOutputStream(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
예제 #5
0
if DetFlags.haveRIO.TRT_on():
    ByteStreamCnvSvc.InitCnvs += ["TRT_RDO_Container"]
if DetFlags.haveRIO.BCM_on():
    ByteStreamCnvSvc.InitCnvs += ["BCM_RDO_Container"]
print(ByteStreamCnvSvc)

# OutputStream
from AthenaServices.AthenaServicesConf import AthenaOutputStream
oStream = AthenaOutputStream("StreamBS",
                             EvtConversionSvc="ByteStreamCnvSvc",
                             OutputFile="ByteStreamEventStorageOutputSvc")

if DetFlags.haveRIO.pixel_on():
    oStream.ItemList += ["PixelRDO_Container#*"]
if DetFlags.haveRIO.SCT_on():
    oStream.ItemList += ["SCT_RDO_Container#*"]
if DetFlags.haveRIO.TRT_on():
    oStream.ItemList += ["TRT_RDO_Container#*"]
if DetFlags.haveRIO.BCM_on():
    oStream.ItemList += ["BCM_RDO_Container#*"]
print(oStream)

# add stream
theApp.addOutputStream(oStream)
theApp.OutStreamType = "AthenaOutputStream"

ByteStreamEventStorageOutputSvc = svcMgr.ByteStreamEventStorageOutputSvc
ByteStreamEventStorageOutputSvc.OutputDirectory = "./"
ByteStreamEventStorageOutputSvc.AppName = "Athena"
ByteStreamEventStorageOutputSvc.FileTag = "csc13"
예제 #6
0
def getStream(type, name):
    # globals in this module
    global svcMgr
    global _streamMap

    # type check
    type = type.upper()
    if type not in ['EVENTSTORAGE', 'TRANSIENT']:
        raise RuntimeError("unsupported StreamType:%s" % type)

    # return existing stream
    if (type, name) in _streamMap:
        return _streamMap[(type, name)]

    # EventStorage
    if type == 'EVENTSTORAGE':
        # OutputSvc
        if not hasattr(svcMgr, "ByteStreamEventStorageOutputSvc"):
            from ByteStreamCnvSvc.ByteStreamCnvSvcConf import ByteStreamEventStorageOutputSvc
            svcMgr += ByteStreamEventStorageOutputSvc()

        # Properties
        ByteStreamCnvSvc = svcMgr.ByteStreamCnvSvc
        ByteStreamCnvSvc.ByteStreamOutputSvcList += [
            "ByteStreamEventStorageOutputSvc"
        ]

        # OutputStream
        from AthenaServices.AthenaServicesConf import AthenaOutputStream
        StreamBS = AthenaOutputStream(
            name,
            EvtConversionSvc="ByteStreamCnvSvc",
            OutputFile="ByteStreamEventStorageOutputSvc",
        )
        theApp.addOutputStream(StreamBS)
        theApp.OutStreamType = "AthenaOutputStream"

        # Define the output as follows:
        ByteStreamEventStorageOutputSvc = svcMgr.ByteStreamEventStorageOutputSvc

        ByteStreamEventStorageOutputSvc.MaxFileMB = 15000
        # maximum number of event (beyond which it creates a new file)
        ByteStreamEventStorageOutputSvc.MaxFileNE = 15000000
        ByteStreamEventStorageOutputSvc.OutputDirectory = "./"
        ByteStreamEventStorageOutputSvc.AppName = "Athena"
        # release variable depends the way the env is configured
        #svcMgr.ByteStreamEventStorageOutputSvc.FileTag = release
        svcMgr.ByteStreamEventStorageOutputSvc.RunNumber = 0
        # does not work
        if hasattr(svcMgr.EventSelector, 'RunNumber'):
            svcMgr.ByteStreamEventStorageOutputSvc.RunNumber = svcMgr.EventSelector.RunNumber

        # decode BSRDOOutput property and overwrite some OutputStream properties if things are there defined
        from AthenaCommon.AthenaCommonFlags import athenaCommonFlags
        props = athenaCommonFlags.BSRDOOutput().split(",")
        if len(props) > 1:
            for p in props:
                if "AppName" in p:
                    svcMgr.ByteStreamEventStorageOutputSvc.AppName = p.split(
                        "=")[1]
                if "OutputDirectory" in p:
                    svcMgr.ByteStreamEventStorageOutputSvc.OutputDirectory = p.split(
                        "=")[1]
                if "FileTag" in p:
                    svcMgr.ByteStreamEventStorageOutputSvc.FileTag = p.split(
                        "=")[1]
                if "Run" in p:
                    svcMgr.ByteStreamEventStorageOutputSvc.RunNumber = int(
                        p.split("=")[1])
        else:
            svcMgr.ByteStreamEventStorageOutputSvc.SimpleFileName = athenaCommonFlags.BSRDOOutput(
            )
        # append
        _streamMap[(type, name)] = StreamBS
        return StreamBS

    elif type == 'TRANSIENT':
        # OutputSvc
        if not hasattr(svcMgr, "ROBDataProviderSvc"):
            from ByteStreamCnvSvcBase.ByteStreamCnvSvcBaseConf import ROBDataProviderSvc
            svcMgr += ROBDataProviderSvc()
        if not hasattr(svcMgr, "ByteStreamRDP_OutputSvc"):
            from ByteStreamCnvSvc.ByteStreamCnvSvcConf import ByteStreamRDP_OutputSvc
            svcMgr += ByteStreamRDP_OutputSvc()

        # Properties
        ByteStreamCnvSvc = svcMgr.ByteStreamCnvSvc
        ByteStreamCnvSvc.ByteStreamOutputSvcList += ["ByteStreamRDP_OutputSvc"]

        # This output stream is created as a regular OutputStream
        from AthenaServices.AthenaServicesConf import AthenaOutputStream
        StreamBS = AthenaOutputStream(
            name,
            EvtConversionSvc="ByteStreamCnvSvc",
            OutputFile="ByteStreamRDP_OutputSvc",
        )
        from AthenaCommon.AlgSequence import AlgSequence
        topSequence = AlgSequence()
        topSequence += StreamBS

        # ByteStreamCnvSvc is an input CnvSvc now.
        EventPersistencySvc = svcMgr.EventPersistencySvc
        EventPersistencySvc.CnvServices += ["ByteStreamCnvSvc"]

        # append
        _streamMap[(type, name)] = StreamBS
        return StreamBS

    else:
        raise RuntimeError("unsupported StreamType:%s" % type)
예제 #7
0
    def  __init__( self, StreamName, FileName, TreeName = None, asAlg = False ):
        """Constructor for the D3PD stream object.

           Arguments:
              StreamName: Logical name of the D3PD stream. Note that beside
                          using it to define the stream in THistSvc, this
                          name is also used as the name of the TTree in the
                          output file in case one is not specified explicitly.
              FileName: Name of the file to write the D3PD TTree into.
              TreeName: Name of the TTree in the output file. If it's not
                        specified, the stream name is used as the tree name.
              asAlg: If set to True, the D3PD::MakerAlg algorithm is added
                     to the job as a regular algorithm. When set to False
                     (default), the D3PD algorithm is added to the application
                     manager as an output stream.
        """
        # Initialize the base class:
        AugmentedStreamBase.__init__( self, StreamName )

        # Check if the user specified a tree name or not:
        if TreeName == None:
            TreeName = StreamName

        # Remember the file and tree names just for bookkeeping:
        self.fileName = FileName
        self.treeName = TreeName

        # We need to add some stuff to the main algorithm sequence:
        from AthenaCommon.AlgSequence import AlgSequence
        topSequence = AlgSequence()

        # Create a sequence where the pre-D3PD-making algorithms are run:
        from D3PDMakerConfig.D3PDMakerFlags import D3PDMakerFlags
        preseq = AlgSequence( D3PDMakerFlags.PreD3PDAlgSeqName(),
                              StopOverride = True )
        if not hasattr( topSequence, D3PDMakerFlags.PreD3PDAlgSeqName() ):
            topSequence += [ preseq ]
            pass
        

        # Add the AANT algorithm for making it possible to back navigate
        # from D3PD events:
        ParentStreamName = StreamName.split( ':' )[ 0 ]
        if StreamName.count( ':' ) != 0:
            if StreamName.count( ':' ) == 1:
                StreamName = StreamName.split( ':' )[ 1 ]
            else:
                raise AttributeError( "Stream name '%s' can't be used!" % StreamName )
        if not hasattr( topSequence, ParentStreamName + "AANTStream" ):
            try:
                from AnalysisTools.AnalysisToolsConf import AANTupleStream
                topSequence += AANTupleStream( ParentStreamName + "AANTStream",
                                               ExtraRefNames = ['StreamRDO',
                                                                'StreamRAW',
                                                                'StreamESD',
                                                                'StreamAOD'],
                                               OutputName = FileName,
                                               WriteInputDataHeader = True,
                                               StreamName = ParentStreamName )
                pass
            except ImportError:
                print(self.Name,": INFO didn't find AnalysisTools.AnalysisToolsConf in release.")
                import traceback
                print(traceback.format_exc())
            pass
        
        # Make sure that THistSvc exists.
        from AthenaCommon.AppMgr import ServiceMgr
        if not hasattr( ServiceMgr, 'THistSvc' ):
            from GaudiSvc.GaudiSvcConf import THistSvc
            ServiceMgr += THistSvc()

        # Check if the requested stream is already defined in THistSvc:
        streamExists = False
        for s in ServiceMgr.THistSvc.Output:
            stream = s.split()[ 0 ]
            if stream == StreamName:
                streamExists = True
                break

        # Add the stream if it's not defined yet:
        if not streamExists:
            ServiceMgr.THistSvc.Output += [ "%s DATAFILE='%s' OPT='RECREATE' CL='%i'" %
                                            ( StreamName, FileName,
                                              D3PDMakerFlags.CompressionLevel() ) ]

        # Finally, create the D3PD::MakerAlg algorithm and add it to the job.
        # Note that here we're specifying that the D3PDMaker code should use
        # ROOT output.
        #
        # If we're adding as an algorithm directly, then pass the parent sequence
        # into MakerAlg(...). MakerAlg(...) will then add itself to the sequence
        # and also set up the accompanying filter sequence. Otherwise, we add it
        # as a stream; in that case we set up backwards compatibility for
        # 'filterSeq'.
        try:
            import D3PDMakerCoreComps
            if asAlg:
                theseq = topSequence
            else:
                theseq = None
                pass
            self.Stream = D3PDMakerCoreComps.MakerAlg( StreamName + "D3PDMaker", seq = theseq,
                                                       file = FileName, stream = ParentStreamName,
                                                       tuplename = TreeName,
                                                       D3PDSvc = "D3PD::RootD3PDSvc" )

            if not asAlg:
                from AthenaCommon.AppMgr import theApp
                theApp.addOutputStream( self.Stream )
                # Backwards compatibility for the filter algoirthm:
                self.filterSeq = _RootStreamFilterHelper( self, topSequence )
                pass
            pass
        except ImportError:
            print(self.Name,": INFO didn't find D3PDMakerCoreComps in release.")
            pass

        return
print              ByteStreamCnvSvc

# OutputStream
from AthenaServices.AthenaServicesConf import AthenaOutputStream
oStream = AthenaOutputStream(
    "StreamBS",
    EvtConversionSvc = "ByteStreamCnvSvc",
    OutputFile = "ByteStreamEventStorageOutputSvc"
    )

oStream.ForceRead = TRUE
if DetFlags.haveRIO.pixel_on():
  oStream.ItemList += [ "PixelRDO_Container#*" ]
if DetFlags.haveRIO.SCT_on():
  oStream.ItemList += [ "SCT_RDO_Container#*" ]
if DetFlags.haveRIO.TRT_on():
  oStream.ItemList += [ "TRT_RDO_Container#*" ]
if DetFlags.haveRIO.BCM_on():
  oStream.ItemList += [ "BCM_RDO_Container#*" ]
print oStream

# add stream
theApp.addOutputStream( oStream )
theApp.OutStreamType ="AthenaOutputStream"

ByteStreamEventStorageOutputSvc = svcMgr.ByteStreamEventStorageOutputSvc
ByteStreamEventStorageOutputSvc.OutputDirectory = "./"
ByteStreamEventStorageOutputSvc.AppName = "Athena"
ByteStreamEventStorageOutputSvc.FileTag = "csc13"

    AppName="Athena",
    FileTag="csc13")
ServiceMgr += ByteStreamFileOutputSvc
print ByteStreamFileOutputSvc

# Conversion Service instance
from ByteStreamCnvSvc.ByteStreamCnvSvcConf import ByteStreamCnvSvc
ByteStreamCnvSvc = ByteStreamCnvSvc(
    "ByteStreamCnvSvc",
    IsSimulation=True,
    ByteStreamOutputSvc="ByteStreamFileOutputSvc")
ByteStreamCnvSvc.InitCnvs += ["PixelRDO_Container"]
ByteStreamCnvSvc.InitCnvs += ["SCT_RDO_Container"]
ByteStreamCnvSvc.InitCnvs += ["TRT_RDO_Container"]
ServiceMgr += ByteStreamCnvSvc
print ByteStreamCnvSvc

# OutputStream
from AthenaServices.AthenaServicesConf import AthenaOutputStream
StreamBS = AthenaOutputStream("StreamBS", EvtConversionSvc="ByteStreamCnvSvc")
# Force reading of output stream (ostream set externally)
StreamBS.ForceRead = TRUE
StreamBS.ItemList += ["TRT_RDO_Container#*"]
StreamBS.ItemList += ["SCT_RDO_Container#*"]
StreamBS.ItemList += ["PixelRDO_Container#*"]
print StreamBS

# add stream
theApp.addOutputStream(StreamBS)
theApp.OutStreamType = "AthenaOutputStream"