def __init__(self, name, seq=topSequence, file=None, stream=None, tuplename=None, TuplePath=None, preD3PDAlgSeqName=D3PDMakerFlags.PreD3PDAlgSeqName(), streamNameRoot=None, clevel=D3PDMakerFlags.CompressionLevel(), **kwargs): """MakerAlg constructor. See the class documentation for a full description. """ if streamNameRoot == None: streamNameRoot = 'D3PD' # Work around initialization order issue. if seq: seq.__iadd__(D3PDMakerCoreComps.DummyInitAlg(name + 'DummyInit'), index=0) # If the tuple path wasn't supplied, build it from the other args. if TuplePath == None: # tuple name defaults to the algorithm name. if tuplename == None: tuplename = name if stream == None: # If no stream was given, infer it from the file. # This creates the stream if needed. if file == None: raise TypeError("Neither stream nor file specified " "for tuple %s" % tuplename) stream = _stream_from_file(file, seq, tuplename, streamNameRoot, clevel) TuplePath = '/%s/%s' % (stream, tuplename) # Create the algorithm Configurable. D3PDMakerCoreCompsConf.D3PD__MakerAlg.__init__(self, name, TuplePath=TuplePath, **kwargs) # Ensure configuration parameters are set. if (D3PDMakerFlags.AutoFlush() != -1 and self.D3PDSvc.getFullName() == 'D3PD::RootD3PDSvc'): from D3PDMakerRoot.D3PDMakerRootConf import D3PD__RootD3PDSvc rootsvc = D3PD__RootD3PDSvc() rootsvc.AutoFlush = D3PDMakerFlags.AutoFlush() from AthenaCommon.AppMgr import ServiceMgr ServiceMgr += rootsvc # Add to the supplied sequence. if seq: # But first, add a sequence for algorithms that should run # before D3PD making, if it's not already there. preseq = AlgSequence(preD3PDAlgSeqName) if not hasattr(seq, preD3PDAlgSeqName): seq += [preseq] # We don't want to do filtering in the presequence. preseq.StopOverride = True # Now set up another sequence for filtering. # Unlike the presequence, there should be a unique one of these # per algorithm. We also need to break out an additional # sequence to which users can add, and to wrap the whole # thing in a sequence to prevent a failed filter # decision from stopping other algorithms. # Like this: # # ALG_FilterAlgorithmsWrap (StopOverride = True) # ALG_FilterAlgorithmsHolder # ALG_FilterAlgorithms # ALG # Dummy alg, to reset filter flag suffix = D3PDMakerFlags.FilterAlgSeqSuffix() wrap = AlgSequence(name + suffix + 'Wrap', StopOverride=True) holder = AlgSequence(name + suffix + 'Holder') self.filterSeq = AlgSequence(name + suffix) holder += self.filterSeq holder += self wrap += holder wrap += PyAthena.Alg(name + 'Dummy') seq += wrap # Create a unique collection getter registry tool for this tree. from AthenaCommon.AppMgr import ToolSvc self._registry = \ D3PDMakerCoreComps.CollectionGetterRegistryTool (self.name() + '_CollectionGetterRegistry') ToolSvc += self._registry return
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