| # Gaudi Framework, version v21r7 |

Home |  | Generated: 22 Jan 2010

# CollectionMerge.py

Go to the documentation of this file.

    00001 import os, sys, gaudimodule
    00002
    00003 class CollectionMerge:
    00004   def __init__(self):
    00005     self.merger_input  = []
    00006     self.merger_output = []
    00007     self.input         = []
    00008     self.output        = []
    00009     self.appMgr = gaudimodule.AppMgr()
    00010     self.appMgr.EvtMax = 1
    00011     self.appMgr.EvtSel = 'NONE'
    00012     self.appMgr.Dlls   += ['GaudiPoolDb']
    00013     self.appMgr.ExtSvc += ['PoolDbCacheSvc','TagCollectionSvc']
    00014     self.appMgr.service('PoolRootEvtCnvSvc').DbType     = 'POOL_ROOT'
    00015     self.appMgr.service('PoolRootKeyEvtCnvSvc').DbType  = 'POOL_ROOTKEY'
    00016     self.appMgr.service('PoolRootTreeEvtCnvSvc').DbType = 'POOL_ROOTTREE'
    00017     self.appMgr.service('PoolDbCacheSvc').Dlls          = ['lcg_RootStorageSvc','lcg_XMLCatalog','SealSTLDict']
    00018     self.appMgr.service('PoolDbCacheSvc').OutputLevel   = 4
    00019     self.appMgr.topAlg += ['CollectionCloneAlg']
    00020     self.collSvc = self.appMgr.service('TagCollectionSvc')
    00021     self.merger=self.appMgr.algorithm('CollectionCloneAlg')
    00022     self.merger.EvtTupleSvc = 'TagCollectionSvc'
    00023
    00024   def finalize(self):
    00025     self.appMgr.finalize()
    00026     self.appMgr.exit()
    00027
    00028   def defineInput(self,tuple,file,typ='POOL_ROOTTREE'):
    00029     num_input = len(self.input)
    00030     log_name = 'INPUT_'+str(num_input)
    00031     tup_name = log_name+'/'+tuple
    00032     self.merger_input.append(tup_name)
    00033     self.input.append(log_name + " DATAFILE='"+file+"' OPT='READ' TYP='"+typ+"'")
    00034
    00035   def defineOutput(self,tuple,file,selector=None,criteria=None,opt='RECREATE',typ='POOL_ROOTTREE'):
    00036     self.output = ['OUTPUT' + " DATAFILE='"+file+"' OPT='"+opt+"' TYP='"+typ+"'"]
    00037     self.merger_output = "DATA='OUTPUT/"+tuple+"'"
    00038     if ( criteria is not None ):
    00039       self.merger_output  = self.merger_output  + " SEL='"+criteria+"'"
    00040     if ( selector is not None ):
    00041       self.merger_output  = self.merger_output  + " FUN='"+selector+"'"
    00042     print self.merger_output
    00043
    00044   def execute(self, do_finalize=1):
    00045     self.collSvc.Input = self.input
    00046     self.collSvc.Output = self.output
    00047     self.merger.Input = self.merger_input
    00048     self.merger.Output = self.merger_output
    00049     self.appMgr.initialize()
    00050     self.appMgr.algorithm('CollectionCloneAlg').execute()
    00051     if ( do_finalize ):
    00052       self.finalize()
    00053
    00054 if __name__ == '__main__':
    00055   o = CollectionMerge()
    00056   o.defineInput('Dir1/Dir2/Dir3/Collection','PFN:MyEvtCollection0.root')
    00057   o.defineInput('Dir1/Dir2/Dir3/Collection','PFN:MyEvtCollection1.root')
    00058   o.defineInput('Dir1/Dir2/Dir3/Collection','PFN:MyEvtCollection2.root')
    00059   o.defineInput('Dir1/Dir2/Dir3/Collection','PFN:MyEvtCollection3.root')
    00060   o.defineOutput(tuple='Merged',criteria='Ntrack>80',file='PFN:NewCollection.root',opt='RECREATE')
    00061   o.execute()
    00062   sys.exit()