Skip to content
Snippets Groups Projects
Commit babd2cb7 authored by Tadej Novak's avatar Tadej Novak
Browse files

Merge branch 'fwinkl_20230214T102644' into 'master'

athenaHLT: remove usage of python include when running from DB/JSON

See merge request atlas/athena!60669
parents 1f2c38a8 38268528
No related merge requests found
......@@ -286,7 +286,7 @@ def HLTMPPy_cfgdict(args):
})
# Special case for running from a json file
if os.path.splitext(args.jobOptions)[1].lower()=='.json':
cdict['trigger']['pythonSetupFile'] = 'TrigPSC/TrigPSCPythonDbSetup.py'
cdict['trigger']['pythonSetupFile'] = 'TrigPSC.TrigPSCPythonDbSetup'
else:
cdict['trigger'].update({
'module': 'DBPython',
......
/*
Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
*/
/**
......@@ -37,10 +37,16 @@ namespace psc {
/**
* @brief Include a python file via AthenaCommon.Include
* @param pyFileName File name
* @param showIncludes Trace included files
* @return Success/Failure
*/
bool pyInclude (const std::string& pyFileName);
/**
* @brief Execute a python file (via include or import)
* @param pyFileName File name
* @return Success/Failure
*/
bool execFile (const std::string& pyFileName);
/**
* @brief Very simple timer class
......
# Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
# Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
###############################################################
## @file TrigPSCPythonDbSetup.py
## @brief Minimal Python setup for running from TrigDB
## @brief Minimal Python setup for running from DB/JSON
## @author Frank Winklmeier
###############################################################
## This is a very minimal Python setup. It is only used when running
## with athenaHLT from the DB. It is not used in a partition!
## This modules provides a minimal Python setup. It is used when running
## with athenaHLT from DB/JSON. It is not used in a partition!
## Besides providing basic python bindings it also takes care of
## switching the OutputLevel in case the "-l" option was used.
## !!! Do NOT import theApp. It will screw up the configuration !!!
import builtins
printfunc = getattr(builtins,'print')
def setTHistSvcOutput():
"""Helper to set THistSvc.Output"""
## Do this only in a function to not pollute the global namespace
from TriggerJobOpts.TriggerHistSvcConfig import setTHistSvcOutput
output = []
setTHistSvcOutput(output)
setattr(iProperty("THistSvc"),"Output",output)
return
### logging and messages -----------------------------------------------------
from AthenaCommon.Logging import *
from AthenaCommon.Constants import *
from TrigPSC import PscConfig
logLevel=PscConfig.optmap['LOGLEVEL'].split(',')[0]
## Minimal Python bindings
from GaudiPython import *
from GaudiPython import InterfaceCast, gbl
from GaudiPython.Bindings import iProperty
from TrigCommon.TrigPyHelper import trigApp
from TrigPSC import PscConfig
from TrigServices.TriggerUnixStandardSetup import _Conf
## If HLT PSK is set on command line read it from DB instead of COOL (ATR-25974)
if PscConfig.forcePSK:
trigApp.changeJobProperties('HLTPrescaleCondAlg', 'Source', 'DB')
## Set OutputLevel in JobOptionsSvc if "-l" option was used in athenaHLT
logLevel = PscConfig.optmap['LOGLEVEL'].split(',')[0]
if logLevel!="INFO":
outputLevel = int(locals()[logLevel])
trigApp.service("MessageSvc", gbl.IMessageSvc).setOutputLevel(outputLevel)
trigApp.changeJobProperties('.*', 'OutputLevel', str(locals()[logLevel]))
## For running with offline THistSvc from online DB
from TrigServices.TriggerUnixStandardSetup import _Conf
if not _Conf.useOnlineTHistSvc:
isvcMgr = InterfaceCast(gbl.ISvcManager)(gbl.Gaudi.svcLocator())
## Change service type from TrigMonTHistSvc to THistSvc
isvcMgr.declareSvcType("THistSvc","THistSvc")
setTHistSvcOutput()
## Some cleanup
del _Conf
del logLevel
## Set standard output files
from TriggerJobOpts.TriggerHistSvcConfig import setTHistSvcOutput
output = []
setTHistSvcOutput(output)
setattr(iProperty("THistSvc"), "Output", output)
/*
Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
*/
/**
......@@ -244,22 +244,12 @@ bool psc::Psc::configure(const ptree& config)
}
Py_DECREF(pModule);
}
// Setup the file inclusion
std::vector<std::string> pyCmds;
pyCmds.push_back("from AthenaCommon.Include import include");
// have C++ bool representation be recognized in python:
pyCmds.push_back("true, false = True, False");
if ( !psc::Utils::execPython(pyCmds) ) {
ERS_PSC_ERROR("Athena 'include' setup failed.");
return false;
}
}
if ( jobOptConfig ) {
// Do the python setup (including user job options)
std::string pyBasicFile = m_config->getOption("PYTHONSETUPFILE") ;
if ( !psc::Utils::pyInclude(pyBasicFile) ) {
if ( !psc::Utils::execFile(pyBasicFile) ) {
ERS_PSC_ERROR("Basic Python configuration failed.");
return false;
}
......@@ -292,8 +282,8 @@ bool psc::Psc::configure(const ptree& config)
if ( needPython ) {
// only used in athenaHLT, but not in partition running
std::string pyBasicFile = m_config->getOption("PYTHONSETUPFILE", /*quiet*/true) ;
if ( pyBasicFile != "" ) {
if ( !psc::Utils::pyInclude(pyBasicFile) ) {
if ( !pyBasicFile.empty() ) {
if ( !psc::Utils::execFile(pyBasicFile) ) {
ERS_PSC_ERROR("Basic Python configuration failed.");
return false;
}
......
/*
Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
*/
/**
......@@ -23,7 +23,7 @@
bool psc::Utils::execPython (const std::string& pyCmd)
{
ERS_DEBUG(1, pyCmd );
ERS_DEBUG(1, pyCmd );
if ( PyRun_SimpleString(const_cast<char*>(pyCmd.c_str())) != 0 ) {
ERS_PSC_ERROR("Error executing " << pyCmd);
return false;
......@@ -51,6 +51,14 @@ bool psc::Utils::pyInclude (const std::string& pyFileName)
}
bool psc::Utils::execFile (const std::string& pyFileName)
{
if (pyFileName.find(".py")!=std::string::npos)
return pyInclude(pyFileName);
else
return psc::Utils::execPython("import " + pyFileName);
}
//--------------------------------------------------------------------------------
// ScopeTimer class
//--------------------------------------------------------------------------------
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment