Skip to content

Instantly share code, notes, and snippets.

@lukasheinrich
Last active September 14, 2016 12:31
Show Gist options
  • Save lukasheinrich/820fa315259bf99f205157578eb971bb to your computer and use it in GitHub Desktop.
Save lukasheinrich/820fa315259bf99f205157578eb971bb to your computer and use it in GitHub Desktop.
def generate_prodconf_file(optionsAr,argdata,outputfile,eventtype = None):
templ = '''\
from Gaudi.Configuration import importOptions
{options}
{eventtype}
from ProdConf import ProdConf
ProdConf(
{args}
)
'''
args = ',\n'.join(['='.join([' {}'.format(k),str(v)]) for k,v in argdata.iteritems()])
options = '\n'.join(["importOptions('"+ el + "')" for el in optionsAr.split(';')])
filled_templ = templ.format(
args = args,
options = options,
eventtype = 'eventType = {}'.format(eventtype) if eventtype is not None else ''
)
print filled_templ
with open(outputfile,'w') as f:
f.write(filled_templ)
def generate(
options,
RunNumber,
FirstEventNumber,
DDDBTag,
CondDBTag,
AppInfo,
outputprefix,
eventtype = None,
inputfile = None,
py_outputfilename = 'out.py'
):
outputformats = {
'Gauss':'sim',
'MooreL0':'digi',
'Moore':'digi',
'Boole':'digi',
'Brunel':'dst',
'DaVinci':'dst'
}
Application,AppVersion = AppInfo.split('-')
other_args = dict(
NOfEvents=10,
DDDBTag=DDDBTag,
CondDBTag=CondDBTag,
AppVersion=AppVersion,
XMLSummaryFile='summary.xml',
Application=Application,
OutputFilePrefix=outputprefix,
RunNumber=RunNumber,
XMLFileCatalog='pool_xml_catalog.xml',
FirstEventNumber=FirstEventNumber,
OutputFileTypes=[outputformats[Application]],
)
if Application is not 'Gauss':
other_args.update(**{'InputFiles':'LFN:{filename}'.format(filename = inputfile)})
generate_prodconf_file(options,other_args,py_outputfilename,eventtype = eventtype)
if __name__ == '__main__':
import sys
import json
inputdata = json.load(open(sys.argv[1]))
args = {'py_outputfilename' : sys.argv[2]}
args.update(**inputdata)
generate(**args)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment