From e7a7c25e2135b6b5aac05ec4712f51698c4642b9 Mon Sep 17 00:00:00 2001 From: Andre Sailer <andre.philippe.sailer@cern.ch> Date: Fri, 20 Jul 2018 11:08:46 +0200 Subject: [PATCH] DDSim: move addParametersToRunHeader to Meta helper --- DDG4/python/DDSim/DD4hepSimulation.py | 44 +------------------------ DDG4/python/DDSim/Helper/Meta.py | 47 ++++++++++++++++++++++++++- 2 files changed, 47 insertions(+), 44 deletions(-) diff --git a/DDG4/python/DDSim/DD4hepSimulation.py b/DDG4/python/DDSim/DD4hepSimulation.py index 9c4fb52e3..dac758cde 100644 --- a/DDG4/python/DDSim/DD4hepSimulation.py +++ b/DDG4/python/DDSim/DD4hepSimulation.py @@ -332,7 +332,7 @@ class DD4hepSimulation(object): # Configure I/O if self.outputFile.endswith(".slcio"): lcOut = simple.setupLCIOOutput('LcioOutput', self.outputFile) - lcOut.RunHeader = self.__addParametersToRunHeader() + lcOut.RunHeader = self.meta.addParametersToRunHeader(self) lcOut.EventParametersString, lcOut.EventParametersInt, lcOut.EventParametersFloat = self.meta.parseEventParameters() lcOut.RunNumberOffset = self.meta.runNumberOffset if self.meta.runNumberOffset > 0 else 0 lcOut.EventNumberOffset = self.meta.eventNumberOffset if self.meta.eventNumberOffset > 0 else 0 @@ -575,48 +575,6 @@ class DD4hepSimulation(object): self._errorMessages.append( "ERROR: printLevel '%s' unknown" % level ) return -1 - def __addParametersToRunHeader( self ): - """add the parameters to the (lcio) run Header""" - runHeader = {} - parameters = vars(self) - for parName, parameter in parameters.iteritems(): - if isinstance( parameter, ConfigHelper ): - options = parameter.getOptions() - for opt,optionsDict in options.iteritems(): - runHeader["%s.%s"%(parName, opt)] = str(optionsDict['default']) - else: - runHeader[parName] = str(parameter) - - ### steeringFile content - if self.steeringFile and os.path.exists(self.steeringFile) and os.path.isfile(self.steeringFile): - with open(self.steeringFile) as sFile: - runHeader["SteeringFileContent"] = sFile.read() - - ### macroFile content - if self.macroFile and os.path.exists(self.macroFile) and os.path.isfile(self.macroFile): - with open(self.macroFile) as mFile: - runHeader["MacroFileContent"] = mFile.read() - - ### add command line - if self._argv: - runHeader["CommandLine"] = " ".join(self._argv) - - ### add current working directory (where we call from) - runHeader["WorkingDirectory"] = os.getcwd() - - ### ILCSoft, LCGEo location from environment variables, names from init_ilcsoft.sh - runHeader["ILCSoft_location"] = os.environ.get("ILCSOFT", "Unknown") - runHeader["lcgeo_location"] = os.environ.get("lcgeo_DIR", "Unknown") - - ### add date - runHeader["DateUTC"] = str(datetime.datetime.utcnow())+" UTC" - - ### add User - import getpass - runHeader["User"] = getpass.getuser() - - return runHeader - def __setupSensitiveDetectors(self, detectors, setupFuction, defaultFilter=None): """ attach sensitive detector actions for all subdetectors can be steered with the `Action` ConfigHelpers diff --git a/DDG4/python/DDSim/Helper/Meta.py b/DDG4/python/DDSim/Helper/Meta.py index 611912d80..600e80ab4 100644 --- a/DDG4/python/DDSim/Helper/Meta.py +++ b/DDG4/python/DDSim/Helper/Meta.py @@ -1,5 +1,8 @@ """Helper object for configuring the LCIO output file (meta)""" +import datetime +import os + from DDSim.Helper.ConfigHelper import ConfigHelper class Meta( ConfigHelper ): @@ -45,4 +48,46 @@ class Meta( ConfigHelper ): elif ptype.lower() == "i": intParameters[pname] = pvalue return stringParameters, intParameters, floatParameters - \ No newline at end of file + + @staticmethod + def addParametersToRunHeader(sim): + """add the parameters to the (lcio) run Header""" + runHeader = {} + parameters = vars(sim) + for parName, parameter in parameters.iteritems(): + if isinstance( parameter, ConfigHelper ): + options = parameter.getOptions() + for opt,optionsDict in options.iteritems(): + runHeader["%s.%s"%(parName, opt)] = str(optionsDict['default']) + else: + runHeader[parName] = str(parameter) + + ### steeringFile content + if sim.steeringFile and os.path.exists(sim.steeringFile) and os.path.isfile(sim.steeringFile): + with open(sim.steeringFile) as sFile: + runHeader["SteeringFileContent"] = sFile.read() + + ### macroFile content + if sim.macroFile and os.path.exists(sim.macroFile) and os.path.isfile(sim.macroFile): + with open(sim.macroFile) as mFile: + runHeader["MacroFileContent"] = mFile.read() + + ### add command line + if sim._argv: + runHeader["CommandLine"] = " ".join(sim._argv) + + ### add current working directory (where we call from) + runHeader["WorkingDirectory"] = os.getcwd() + + ### ILCSoft, LCGEo location from environment variables, names from init_ilcsoft.sh + runHeader["ILCSoft_location"] = os.environ.get("ILCSOFT", "Unknown") + runHeader["lcgeo_location"] = os.environ.get("lcgeo_DIR", "Unknown") + + ### add date + runHeader["DateUTC"] = str(datetime.datetime.utcnow())+" UTC" + + ### add User + import getpass + runHeader["User"] = getpass.getuser() + + return runHeader -- GitLab