Skip to content
Snippets Groups Projects
Commit 83de7c25 authored by Vakhtang Tsulaia's avatar Vakhtang Tsulaia
Browse files

Merge branch 'newSkeleton_caScript' into 'main'

add skeleton CA script to skeleton package

See merge request !68862
parents 651daa4f 9c8103e3
No related branches found
No related tags found
1 merge request!68862add skeleton CA script to skeleton package
......@@ -41,6 +41,71 @@ athAlgSeq += CfgMgr.%(klass)s() #adds an instance
include("AthAnalysisBaseComps/SuppressLogging.py") #Optional include to suppress as much athena output as possible. Keep at bottom of joboptions so that it doesn't suppress the logging of the things you have configured above
"""
script_template = """\
#!/usr/bin/env python
# Run this application/script like this:
# run%(klass)s.py --filesInput file.root --evtMax 100
# See --help for more arguments and flag options
from AthenaConfiguration.AllConfigFlags import initConfigFlags
flags = initConfigFlags()
flags._parser = flags.getArgumentParser(description=\"\"\"My Demo Application\"\"\") # an argparse.ArgumentParser
flags.parser().add_argument('--accessMode',default="POOLAccess", # can add arguments to the parser as usual
choices={"POOLAccess","ClassAccess"},help="Input file reading mode (ClassAccess can be faster but is less supported)")
# changes to default flag values (done before fillFromArgs so appears in the --help flag system
flags.Exec.PrintAlgsSequence = True # displays algsequence at start of job
args = flags.fillFromArgs() # parse command line arguments
flags.lock() # lock the flags
# configure main services and input file reading
from AthenaConfiguration.MainServicesConfig import MainServicesCfg
from AthenaConfiguration.Enums import Format
cfg = MainServicesCfg(flags)
if flags.Input.Format is Format.BS:
# read RAW (bytestream)
from ByteStreamCnvSvc.ByteStreamConfig import ByteStreamReadCfg
cfg.merge(ByteStreamReadCfg(flags))
else:
# reading POOL, use argument to decide which read mode
if flags.args().accessMode == "POOLAccess":
from AthenaPoolCnvSvc.PoolReadConfig import PoolReadCfg
cfg.merge(PoolReadCfg(flags))
else:
from AthenaRootComps.xAODEventSelectorConfig import xAODReadCfg,xAODAccessMode
cfg.merge(xAODReadCfg(flags, AccessMode = xAODAccessMode.CLASS_ACCESS))
# configure output ROOT files from Output.HISTOutputs flag (should be of form: "STREAMNAME:file.root")
from AthenaConfiguration.ComponentFactory import CompFactory
if flags.Output.HISTFileName != "":
outputs = []
for file in (flags.Output.HISTFileName if type(flags.Output.HISTFileName)==list else flags.Output.HISTFileName.split(",")):
streamName = file.split(":")[0] if ":" in file else "ANALYSIS"
fileName = file.split(":")[1] if ":" in file else file
outputs += ["{} DATAFILE='{}' OPT='RECREATE'".format(streamName,fileName)]
cfg.addService(CompFactory.THistSvc(Output = outputs))
# add our algorithm
cfg.addEventAlgo(CompFactory.%(klass)s(),sequenceName="AthAlgSeq")
# final cfg tweaks before launching:
cfg.getService("AthenaEventLoopMgr").IntervalInSeconds = 5 # enable processing rate reporting every 5s
# suppress logging from some core services that we usually don't care about hearing from
cfg.getService("MessageSvc").setWarning += ["ClassIDSvc","PoolSvc","AthDictLoaderSvc","AthenaPoolAddressProviderSvc",
"ProxyProviderSvc","DBReplicaSvc","MetaDataSvc","MetaDataStore","AthenaPoolCnvSvc",
"TagMetaDataStore","EventSelector","CoreDumpSvc","AthMasterSeq","EventPersistencySvc",
"ActiveStoreSvc","AthOutSeq","AthRegSeq","FPEAuditor"]
# run the job
if cfg.run().isFailure():
import sys
sys.exit(1)
"""
alg_hdr_template = """\
......@@ -345,10 +410,11 @@ DECLARE_COMPONENT( %(klass)s )
if args.newJobo:
#make the joboptions file too
full_jobo_name = namespace_klass + "JobOptions"
full_script_name = "run" + namespace_klass
full_alg_name = namespace_klass
print(textwrap.dedent("""\
::: create jobo [%(full_jobo_name)s] for alg [%(full_alg_name)s]""" %locals()))
::: create jobo [%(full_jobo_name)s] and script [%(full_script_name)s] for alg [%(full_alg_name)s]""" %locals()))
#following code borrowed from gen_klass
jobo = getattr(Templates, 'jobo_template')
......@@ -366,6 +432,22 @@ DECLARE_COMPONENT( %(klass)s )
o_hdr.flush()
o_hdr.close()
scripto = getattr(Templates, 'script_template')
e = dict( klass=full_alg_name,
inFile=os.environ['ASG_TEST_FILE_MC'],
)
fname = 'scripts/%s.py' % full_script_name
#first check doesn't exist
if os.path.isfile(fname):
print("::: WARNING %s already exists .. will not overwrite" % fname)
else:
o_hdr = open(fname, 'w')
o_hdr.writelines(scripto%e)
o_hdr.flush()
o_hdr.close()
os.chmod(fname, 0o755)
#need to reconfigure cmake so it knows about the new files
#rely on the WorkDir_DIR env var for this
workDir = os.environ.get("WorkDir_DIR")
......
......@@ -70,6 +70,7 @@ def main(args):
os.makedirs(pkg_path+"/"+pkg_name+"/data")
with open(pkg_path+"/"+pkg_name+"/data/ExampleData",'w') as f: f.write("this file will be accessible through PathResolverFindDataFile(\""+pkg_name+"/ExampleData\")")
os.makedirs(pkg_path+"/"+pkg_name+"/util")
os.makedirs(pkg_path+"/"+pkg_name+"/scripts")
except OSError:
print("ERROR while making directories for " % (pkg_path+"/"+pkg_name+"/src"))
return -1
......
# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
# Copyright (C) 2002-2014 CERN for the benefit of the ATLAS collaboration
# @file PyUtils.scripts.cmt_newanalysisalg
# @purpose streamline and ease the creation of new athena algs
......@@ -95,6 +95,7 @@ def main(args):
atlas_install_python_modules( python/*.py )
atlas_install_joboptions( share/*.py )
atlas_install_data( data/* )
atlas_install_scripts( scripts/* )
# You can access your data from code using path resolver, e.g.
# PathResolverFindCalibFile("%(pkg_name)s/file.txt")
......
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