00001
00002 '''
00003 Muck with RootIOCnvSvc's output file map, just to piss it off.
00004 '''
00005
00006 from GaudiPython.GaudiAlgs import GaudiAlgo
00007 from GaudiPython import SUCCESS, FAILURE, Bindings
00008 import os
00009
00010 class OutFrob(GaudiAlgo):
00011 '''
00012 An algorithm that will change the RootIOCnvSvc's output file map.
00013 '''
00014 def __init__(self,name="OutFrob"):
00015 GaudiAlgo.__init__(self,name)
00016 self.count = 0
00017 return
00018
00019 def initialize(self):
00020 sc = GaudiAlgo.initialize(self)
00021 if sc.isFailure():
00022 print 'Failed to initialize GaudiAlgo base class'
00023 return sc
00024 self.rio = self.svc('IRootIOSvc','RootIOCnvSvc')
00025 if not self.rio:
00026 print 'Failed to get RootIOCnvSvc, bogus!'
00027 return FAILURE
00028 self.riop = Bindings.iProperty('RootIOCnvSvc',self.rio)
00029 return SUCCESS
00030
00031 def execute(self):
00032 self.count += 1
00033 print self.count
00034
00035 outstreams = self.riop.OutputStreams
00036 for k,v in outstreams.iteritems():
00037 print '\t%s --> %s'%(k,v)
00038 basenum,ext = os.path.splitext(v)
00039 base,num = basenum.split("_")
00040 newname = '%s_%03d%s'%(base,self.count,ext)
00041 print 'Changing output stream "%s" output file from "%s" to "%s"'%(k,v,newname)
00042 self.rio.associateOutput(newname,k)
00043 continue
00044
00045
00046
00047
00048 return SUCCESS
00049
00050
00051 def configure(argv=None):
00052 from RootIOSvc.RootIOSvcConf import RootIOCnvSvc
00053 rio = RootIOCnvSvc()
00054
00055 from Gaudi.Configuration import ApplicationMgr
00056 theApp = ApplicationMgr()
00057 theApp.ExtSvc.append(rio)
00058
00059 return
00060
00061 def run(app):
00062 alg = OutFrob()
00063 app.addAlgorithm(alg)
00064 return
00065