Skip to content
Snippets Groups Projects
Commit 092c3422 authored by Adam Edward Barton's avatar Adam Edward Barton
Browse files

Merge branch 'FPGATrackSimCleanUp' into 'main'

Fix unit tests after legacy config cleanup

See merge request atlas/athena!70719
parents 87436d98 682c3fca
No related branches found
No related tags found
No related merge requests found
# Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
# Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
# Declare the package name:
atlas_subdir( FPGATrackSimConfTools )
......@@ -35,10 +35,6 @@ atlas_add_test( FPGATrackSimRegionSlices_test
INCLUDE_DIRS ${ROOT_INCLUDE_DIRS}
LINK_LIBRARIES ${ROOT_LIBRARIES} FPGATrackSimConfToolsLib )
atlas_add_test( FPGATrackSimEventSelectionSvc_test
SCRIPT python -m FPGATrackSimConfTools.FPGATrackSimConfigCompInit
POST_EXEC_SCRIPT noerror.sh )
atlas_add_test( FPGATrackSimConfigFlags_test
SCRIPT python -m FPGATrackSimConfTools.FPGATrackSimConfigFlags
POST_EXEC_SCRIPT noerror.sh )
......
# Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
'''
@author Riley Xu - riley.xu@cern.ch
@date Feb 23rd 2021
@brief This file declares functions to configure FPGATrackSimConfig components
'''
def getRegionIndex(map_tag):
'''
Note the region member of the tag is a string
'''
try:
return int(map_tag['region'])
except ValueError:
return map_tag['regionNames'].index(map_tag['region'])
def getRegionName(map_tag):
return map_tag['regionNames'][getRegionIndex(map_tag)]
def getSampleType(map_tag):
return map_tag['sampleType']
def getWithPU(map_tag):
return map_tag['withPU']
def addEvtSelSvc(map_tag,name=""):
'''
Creates and returns a FPGATrackSimEventSelectionSvc object, configured with the specified tags.
This function adds the returned map service instance to SvcMgr.
'''
from AthenaCommon.Constants import INFO
import FPGATrackSimConfTools.FPGATrackSimConfToolsConf as Config
if name :
ES = Config.FPGATrackSimEventSelectionSvc(name)
else :
ES = Config.FPGATrackSimEventSelectionSvc()
ES.regionID = getRegionIndex(map_tag)
ES.regions = map_tag['slices']
ES.sampleType = getSampleType(map_tag)
ES.withPU = getWithPU(map_tag)
ES.OutputLevel=INFO
from AthenaCommon.AppMgr import ServiceMgr
#global ServiceMgr
ServiceMgr += ES
return ES
if __name__=='__main__':
from AthenaCommon.Logging import log
from AthenaCommon.Constants import DEBUG
log.setLevel(DEBUG)
import FPGATrackSimConfTools.FPGATrackSimTagConfig as FPGATrackSimTagConfig
tags = FPGATrackSimTagConfig.getTags(stage='bank')
map_tag = tags['map']
ES = addEvtSelSvc(map_tag)
ES.sampleType="singleMuons"
print(ES)
# Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
'''
@author Riley Xu - rixu@cern.ch
@date March 3rd 2020
@brief This file declares functions to make and configure the map service.
'''
import os
from PyJobTransforms.trfUtils import findFile
from PyJobTransforms.trfLogger import msg
from FPGATrackSimMaps.FPGATrackSimMapsConf import FPGATrackSimMappingSvc, FPGATrackSimHitFilteringTool
import FPGATrackSimConfTools.FPGATrackSimConfigCompInit as FPGATrackSimConfig
def findFileWithTest(datapath,filename):
retv = findFile(datapath,filename)
if retv is None:
msg.info(datapath)
raise OSError(2, "Couldn't find file", filename)
return retv
def addMapSvc(tag):
'''
Creates and returns a FPGATrackSimMapSvc object, configured with the specified tag.
This function adds the returned map service instance to SvcMgr, and ALSO ADDS
the EventSelectionSvc, which the map svc depends on
'''
FPGATrackSimConfig.addEvtSelSvc(tag)
MyFPGATrackSimMappingSvc = FPGATrackSimMappingSvc()
filepaths = [
'pmap',
'rmap',
'modulemap',
'subrmap',
'NNmap',
]
formats = {
'region': FPGATrackSimConfig.getRegionIndex(tag),
'regionName': FPGATrackSimConfig.getRegionName(tag),
}
for param in filepaths:
if tag['formatted']:
path = tag[param].format(**formats)
else:
path = tag[param]
setattr(MyFPGATrackSimMappingSvc, param, path)
MyFPGATrackSimMappingSvc.mappingType = tag['mappingType']
MyFPGATrackSimMappingSvc.layerOverride = tag['layerOverride']
from AthenaCommon.AppMgr import ServiceMgr
ServiceMgr += MyFPGATrackSimMappingSvc
return MyFPGATrackSimMappingSvc
def addHitFilteringTool(tag):
'''
Creates and adds the hit filtering tool to the tool svc
'''
HitFilteringTool = FPGATrackSimHitFilteringTool()
for param in HitFilteringTool.__slots__:
if param in tag:
setattr(HitFilteringTool, param, tag[param])
from AthenaCommon.AppMgr import ToolSvc
ToolSvc += HitFilteringTool
return HitFilteringTool
def getNSubregions(tag):
formats = {
'region': FPGATrackSimConfig.getRegionIndex(tag),
'regionName': FPGATrackSimConfig.getRegionName(tag),
}
if tag['formatted']:
path = tag['subrmap'].format(**formats)
else:
path = tag['subrmap']
path = findFile(os.environ['DATAPATH'], path)
with open(path, 'r') as f:
fields = f.readline().split()
assert(fields[0] == 'towers')
return int(fields[1])
def _applyTag(MyFPGATrackSimMappingSvc, tag):
'''
Helper function that sets the filepaths of the MapSvc using the supplied tag
'''
# Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
from PyJobTransforms.trfUtils import findFile
from PyJobTransforms.trfLogger import msg
import os
def findFileWithTest(datapath,filename):
retv = findFile(datapath,filename)
if retv is None:
msg.info(datapath)
raise OSError(2, "Couldn't find file", filename)
return retv
def getRegionIndex(map_tag):
'''
Note the region member of the tag is a string
'''
try:
return int(map_tag['region'])
except ValueError:
return map_tag['regionNames'].index(map_tag['region'])
def getRegionName(map_tag):
return map_tag['regionNames'][getRegionIndex(map_tag)]
def getSampleType(map_tag):
return map_tag['sampleType']
def getWithPU(map_tag):
return map_tag['withPU']
def getNSubregions(tag):
formats = {
'region': getRegionIndex(tag),
'regionName': getRegionName(tag),
}
if tag['formatted']:
path = tag['subrmap'].format(**formats)
else:
path = tag['subrmap']
path = findFile(os.environ['DATAPATH'], path)
with open(path, 'r') as f:
fields = f.readline().split()
assert(fields[0] == 'towers')
return int(fields[1])
\ No newline at end of file
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