Skip to content
Snippets Groups Projects
Commit fffc6d36 authored by Andrea Stano's avatar Andrea Stano
Browse files

Modified GaudiApp interface and module

parent 72a0329c
Branches v31_gaudiApp
No related tags found
No related merge requests found
Pipeline #2853233 failed
......@@ -37,9 +37,9 @@ class GaudiApp(DDInterfaceMixin, LCApplication):
self.randomSeed = -1
self.detectorModel = ''
self.executableName = 'k4run'
self.inputFilesFlag = ''
self.podioOutputFilename = ''
self.argumentList= ''
self.arguments = ''
self.inputFileFlag = ''
self.outputFlag = ''
super(GaudiApp, self).__init__(paramdict)
# Those 5 need to come after default constructor
self._modulename = 'GaudiAppModule'
......@@ -68,43 +68,42 @@ class GaudiApp(DDInterfaceMixin, LCApplication):
self._checkArgs({'randomSeed': types.IntType})
self.randomSeed = randomSeed
def setInputFilesFlag(self, inputFilesFlag):
def setArguments(self, args):
""" Optional: Define the arguments of the script
:param str args: Arguments to pass to the command call
"""
self._checkArgs({'args': types.StringTypes})
self.arguments = args
return S_OK()
def setInputFileFlag(self, inputFileFlag):
""" Optional: Define inputTypeFlag for k4run input files.
:param str inputFilesFlag: type of event files (LCIO, EventDataSvc)
:param str inputFileFlag: type of event files (LCIO, EventDataSvc)
"""
self._checkArgs({'inputFilesFlag': types.StringType})
self.inputFilesFlag = inputFilesFlag
self._checkArgs({'inputFileFlag': types.StringType})
self.inputFileFlag = InputFileFla
def setPodioOutputFilename(self, podioOutputFilename):
""" Optional: Set PodioOutput filename if using PodioOutput for writing events.
:param str podioOutputFilename: name for the PodioOutput file
def setOutputFile(self, ofile, path = None, outputFlag = "--out.filename"):
"""Set the output file
:param str ofile: Output file name. Will overwrite the default. This is
necessary when linking applications (when using :any:`getInputFromApp`)
:param str path: Set the output path for the output file to go. Will not
do anything in a :mod:`~ILCDIRAC.Interfaces.API.NewInterface.UserJob`. Use
:func:`~ILCDIRAC.Interfaces.API.NewInterface.UserJob.UserJob.setOutputData`
of the job for that functionality.
:param str outputFlag: prepend flag to ouput file name (e.g. --PodioOutput.filename)
Default is --out.filename
"""
self._checkArgs({'podioOutputFilename': types.StringType})
self.podioOutputFilename = podioOutputFilename
super(GaudiApp, self).setOutputFile(ofile, path)
def setArgumentList(self, argumentList):
""" Optional: Set list of arguments for the app. Eg: [[key, value],[key, value]]
If file is passed, check lfn: or if exists locally.
:param dict arguments: dict of arguments pairs {key : value}
"""
if not type(argumentList) is dict:
return self._reportError('The argument must be a dict of {"key": "value"}')
for key, val in argumentList.iteritems():
if isinstance(val, basestring):
if val.lower().startswith("lfn:"):
self.inputSB.append(val)
val = os.path.basename(val)
elif val.lower().startswith("file:"):
if not os.path.exists(val[5:]):
return self._reportError('File %s does not exist locally' % val[5:])
self.inputSB.append(val[5:])
val = os.path.basename(argumentList[val][5:])
self.argumentList += " " + key + " " + str(val)
return S_OK()
if outputFlag:
self._checkArgs({'outputFlag': types.StringType})
self.outputFlag = outputFlag
def setStartFrom(self, startfrom):
"""Define from where GaudiApp starts to read in the input file.
......@@ -162,9 +161,6 @@ class GaudiApp(DDInterfaceMixin, LCApplication):
if not res['OK']:
return res
# if not self.detectorModel:
# return S_ERROR("No detectorModel set")
if self._jobtype != 'User':
self._listofoutput.append({"outputFile": "@{OutputFile}", "outputPath": "@{OutputPath}",
"outputDataSE": '@{OutputSE}'})
......@@ -182,30 +178,30 @@ class GaudiApp(DDInterfaceMixin, LCApplication):
md1 = self._createModuleDefinition()
md1.addParameter(Parameter("randomSeed", 0, "int", "", "", False, False,
"Random seed for the generator"))
md1.addParameter(Parameter("detectorModel", "", "string", "", "", False, False,
"Detecor model for simulation"))
md1.addParameter(Parameter("executableName", "", "string", "", "", False, False,
"Name of the executable"))
md1.addParameter(Parameter("startFrom", 0, "int", "", "", False, False,
"From where GaudiAPp starts to read the input file"))
md1.addParameter(Parameter("inputFilesFlag", "", "string", "", "", False, False,
"Flag that define the type of the input files"))
md1.addParameter(Parameter("podioOutputFilename", "", "string", "", "", False, False,
"Name of the PodioOutput file"))
md1.addParameter(Parameter("argumentList", "", "string", "", "", False, False,
"List of arguments to append"))
"From where GaudiApp starts to read the input file"))
md1.addParameter(Parameter("detectorModel", "", "string", "", "", False, False,
"Detecor model for simulation"))
md1.addParameter(Parameter("inputFileFlag", "", "string", "", "", False, False,
"Flag that define the type of the input files (lcio, eventdatasvc, ..)"))
md1.addParameter(Parameter("outputFlag", "", "string", "", "", False, False,
"Flag that define the output file (e.g. PodioOutput)"))
md1.addParameter(Parameter("arguments", "", "string", "", "", False, False,
"Arguments to pass to the script"))
md1.addParameter(Parameter("debug", False, "bool", "", "", False, False, "debug mode"))
return md1
def _applicationModuleValues(self, moduleinstance):
moduleinstance.setValue("randomSeed", self.randomSeed)
moduleinstance.setValue("detectorModel", self.detectorModel)
moduleinstance.setValue("executableName", self.executableName)
moduleinstance.setValue("startFrom", self.startFrom)
moduleinstance.setValue("inputFilesFlag", self.inputFilesFlag)
moduleinstance.setValue("podioOutputFilename", self.podioOutputFilename)
moduleinstance.setValue("argumentList", self.argumentList)
moduleinstance.setValue("detectorModel", self.detectorModel)
moduleinstance.setValue("inputFileFlag", self.inputFileFlag)
moduleinstance.setValue("outputFlag", self.outputFlag)
moduleinstance.setValue('arguments', self.arguments)
moduleinstance.setValue("debug", self.debug)
def _checkWorkflowConsistency(self):
......
......@@ -29,12 +29,12 @@ class GaudiAppModule(DD4hepMixin, ModuleBase):
self.executableName = ''
self.startFrom = 0
self.randomSeed = -1
self.detectorModel = ''
self.inputFilesFlag = ''
self.podioOutputFilename = ''
self.outputFlag = ''
self.compactFile = ''
self.argumentList = ''
self.extraParticles = []
self.detectorModel = ''
self.arguments = ''
self.extraCLIarguments = ''
self.eventstring = ['+++ Initializing event'] # FIXME
def applicationSpecificInputs(self):
......@@ -96,7 +96,7 @@ class GaudiAppModule(DD4hepMixin, ModuleBase):
return res
envScriptPath = res["Value"]
# get the path to the detector model, either local or from the software
# get the path to the detector model, either local or from the software
resXML = self._getDetectorXML()
if not resXML['OK']:
LOG.error("Could not obtain the detector XML file: ", resXML["Message"])
......@@ -119,20 +119,21 @@ class GaudiAppModule(DD4hepMixin, ModuleBase):
# if self.debug:
# self.extraCLIarguments += " --printLevel DEBUG "
cmd = []
if self.InputFile:
if self.inputFilesFlag.lower() == "lcio":
self.extraCLIarguments += ' --LcioEvent.Files ' + ','.join(self.InputFile)
cmd.append("--LcioEvent.Files %s" % (' '.join(self.InputFile)))
elif self.inputFilesFlag.lower() == "eventdatasvc":
self.extraCLIarguments += ' --EventDataSvc.inputs ' + ','.join(self.InputFile)
cmd.append("--EventDataSvc.inputs %s" % (' '.join(self.InputFile)))
if self.podioOutputFilename:
self.extraCLIarguments += " --PodioOutput.filename " + self.podioOutputFilename
if self.outputFlag:
cmd.append("%s %s" % (self.outputFlag, self.OutputFile))
if self.compactFile:
self.extraCLIarguments += " --GeoSvc.detectors " + self.compactFile
cmd.append("--GeoSvc.detectors %s" % (self.compactFile))
if self.argumentList:
self.extraCLIarguments += self.argumentList
if self.arguments:
cmd.append(self.arguments)
scriptName = 'GaudiApp_%s_Run_%s.sh' % (self.applicationVersion, self.STEP_NUMBER)
if os.path.exists(scriptName):
......@@ -149,8 +150,9 @@ class GaudiAppModule(DD4hepMixin, ModuleBase):
script.append('env | sort >> localEnv.log')
script.append('echo gaudiApp:`which %s`' % self.executableName)
script.append('echo =========')
comm = '%(executable)s %(steeringFile)s %(extraArgs)s ' % \
comm = '%(executable)s %(steeringFile)s %(args)s %(extraArgs)s ' % \
dict(executable=self.executableName,
args=' '.join(cmd),
extraArgs=self.extraCLIarguments,
steeringFile=self.SteeringFile,
)
......
#!/bin/env python
# Purpose
# Generate 1000 pions of 10 GeV with the particle gun and process
# through the LAr calorimeter full simulation
# Job options file at
# https://github.com/HEP-FCC/FCCSW/blob/master/Examples/options/geant_fullsim_fccee_lar_pgun.py
from DIRAC.Core.Base import Script
Script.parseCommandLine()
......@@ -10,37 +17,27 @@ from ILCDIRAC.Interfaces.API.NewInterface.Applications import GaudiApp
dIlc = DiracILC()
# inputData = FileCatalog().findFilesByMetadata({'ProdID': 9275, 'DataType': 'SIM'})
# if not inputData['OK']:
# print('ERROR: Failed to find inputData', inputData['Message'])
# exit(1)
# print('Number of Input Data files:', len(inputData['Value']))
# # truncate to 10 files
# inputData = inputData['Value'][:10]
inputData = ['/fcc/user/a/astano/testGaudi/Z_uds_sim.slcio']
job = UserJob()
job.setName("Key4hepTest_%n") # %n will be replaced by the task number
job.setName("GaudiTest")
job.setOutputSandbox("*.log")
job.setOutputData("k4Out.slcio", OutputPath="key4hepTest")
job.setSplitInputData(inputData, numberOfFilesPerJob=1)
job.setCLICConfig('ILCSoft-2020-02-07')
job.setOutputData("output.root", OutputPath="gaudiTest")
ga = GaudiApp()
ga.setVersion('key4hep_nightly')
ga.setExecutable('k4run')
ga.setSteeringFile('clicReconstruction-lcioevent.py')
ga.setInputFilesFlag("LCIO")
ga.setDetectorModel("DetFCCeeIDEA")
# ga.setArgumentList({"--option1": 1 ,
# "--option2": 1.1 ,
# "--option3": "value3" , "--option4": "fileFCCee_DectMaster.xml"})
ga.setSteeringFile('geant_fullsim_fccee_lar_pgun.py')
ga.setDetectorModel("DetFCCeeIDEA-LAr")
ga.setArguments("--GenAlg.MomentumRangeParticleGun.MomentumMin 1000 "
"--GenAlg.MomentumRangeParticleGun.MomentumMax 1000 "
"--GenAlg.MomentumRangeParticleGun.PdgCodes 11")
# ga.setOutputFile("output.root", outputFlag = "--PrependThisFlag.filename")
ga.setOutputFile("output.root")
res = job.append(ga)
if not res['OK']:
print(res['Message'])
exit(1)
job.submit(dIlc, mode='local')
# job.submit(dIlc, mode='local')
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment