File indexing completed on 2025-01-18 09:12:08
0001
0002
0003 import os
0004 import json
0005
0006 import acts
0007 from acts import MaterialMapJsonConverter
0008 from acts.examples.odd import getOpenDataDetector
0009 from acts.examples import (
0010 WhiteBoard,
0011 AlgorithmContext,
0012 ProcessCode,
0013 CsvTrackingGeometryWriter,
0014 ObjTrackingGeometryWriter,
0015 JsonSurfacesWriter,
0016 JsonMaterialWriter,
0017 JsonFormat,
0018 )
0019
0020
0021 def runGeometry(
0022 trackingGeometry,
0023 decorators,
0024 outputDir,
0025 events=1,
0026 outputObj=True,
0027 outputCsv=True,
0028 outputJson=True,
0029 ):
0030 for ievt in range(events):
0031 eventStore = WhiteBoard(name=f"EventStore#{ievt}", level=acts.logging.INFO)
0032 ialg = 0
0033
0034 context = AlgorithmContext(ialg, ievt, eventStore)
0035
0036 for cdr in decorators:
0037 r = cdr.decorate(context)
0038 if r != ProcessCode.SUCCESS:
0039 raise RuntimeError("Failed to decorate event context")
0040
0041 if outputCsv:
0042
0043
0044 writer = CsvTrackingGeometryWriter(
0045 level=acts.logging.INFO,
0046 trackingGeometry=trackingGeometry,
0047 outputDir=os.path.join(outputDir, "csv"),
0048 writePerEvent=True,
0049 )
0050 writer.write(context)
0051
0052 if outputObj:
0053 writer = ObjTrackingGeometryWriter(
0054 level=acts.logging.INFO, outputDir=os.path.join(outputDir, "obj")
0055 )
0056 writer.write(context, trackingGeometry)
0057
0058 if outputJson:
0059
0060
0061 writer = JsonSurfacesWriter(
0062 level=acts.logging.INFO,
0063 trackingGeometry=trackingGeometry,
0064 outputDir=os.path.join(outputDir, "json"),
0065 writePerEvent=True,
0066 writeSensitive=True,
0067 )
0068 writer.write(context)
0069
0070 jmConverterCfg = MaterialMapJsonConverter.Config(
0071 processSensitives=True,
0072 processApproaches=True,
0073 processRepresenting=True,
0074 processBoundaries=True,
0075 processVolumes=True,
0076 processNonMaterial=True,
0077 context=context.geoContext,
0078 )
0079
0080 jmw = JsonMaterialWriter(
0081 level=acts.logging.VERBOSE,
0082 converterCfg=jmConverterCfg,
0083 fileName=os.path.join(outputDir, "geometry-map"),
0084 writeFormat=JsonFormat.Json,
0085 )
0086
0087 jmw.write(trackingGeometry)
0088
0089
0090 if "__main__" == __name__:
0091
0092
0093 detector = getOpenDataDetector()
0094 trackingGeometry = detector.trackingGeometry()
0095 decorators = detector.contextDecorators()
0096
0097 runGeometry(trackingGeometry, decorators, outputDir=os.getcwd())
0098
0099
0100
0101
0102
0103
0104
0105
0106