ATLAS Offline Software
Loading...
Searching...
No Matches
MuonConfigUtils.py
Go to the documentation of this file.
1# Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
2
3
4
5def setupHistSvcCfg(flags, outFile: str, outStream: str, autoFlush: int = -30000000, autoSave: int = -30000000):
6 from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
7 result = ComponentAccumulator()
8 if len(outFile) == 0:
9 raise ValueError("The output file must not be empty")
10 if len(outStream) == 0:
11 raise ValueError("The outstream must not be empty")
12
13 from AthenaConfiguration.ComponentFactory import CompFactory
14 histSvc = CompFactory.THistSvc(Output=[f"{outStream} DATAFILE='{outFile}', OPT='RECREATE'"], AutoFlush=autoFlush, AutoSave=autoSave)
15 print(f"Register new stream {outStream} piped to {outFile}")
16 result.addService(histSvc, primary=True)
17 return result
18
19def executeTest(cfg):
20 cfg.printConfig(withDetails=True, summariseProps=True)
21 if not cfg.run().isSuccess(): exit(1)
22
24 from AthenaCommon.Logging import logging
25 log = logging.getLogger('GeometryConfiguration')
26
27 if not flags.GeoModel.AtlasVersion:
28 if not flags.GeoModel.SQLiteDB:
29 raise ValueError("Default tag configuration only works for SQLite")
30
31 from AthenaConfiguration.TestDefaults import defaultGeometryTags
32 flags.GeoModel.AtlasVersion = defaultGeometryTags.RUN2
33 from AthenaConfiguration.Enums import LHCPeriod
34 if flags.GeoModel.Run == LHCPeriod.Run3:
35 flags.GeoModel.AtlasVersion = defaultGeometryTags.RUN3
36 elif flags.GeoModel.Run == LHCPeriod.Run4:
37 flags.GeoModel.AtlasVersion = defaultGeometryTags.RUN4
38 else:
39 raise ValueError(f"Invalid run period {flags.GeoModel.Run}")
40
41 configureCondTag(flags)
42
43 log.info(f"Setup {flags.GeoModel.AtlasVersion} geometry loading {flags.GeoModel.SQLiteDBFullPath}")
44 log.info(f"Use conditions tag {flags.IOVDb.GlobalTag}")
45
47 if not flags.GeoModel.AtlasVersion:
48 raise ValueError("No ATLAS version is configured")
49
50 from AthenaConfiguration.Enums import LHCPeriod
51 from AthenaConfiguration.TestDefaults import defaultConditionsTags
52 if flags.GeoModel.Run == LHCPeriod.Run2:
53 flags.IOVDb.GlobalTag = defaultConditionsTags.RUN2_MC if flags.Input.isMC else defaultConditionsTags.RUN2_DATA
54 elif flags.GeoModel.Run == LHCPeriod.Run3:
55 flags.IOVDb.GlobalTag = defaultConditionsTags.RUN3_MC if flags.Input.isMC else defaultConditionsTags.RUN3_DATA
56 elif flags.GeoModel.Run == LHCPeriod.Run4:
57 flags.IOVDb.GlobalTag = defaultConditionsTags.RUN4_MC
58 else:
59 raise ValueError(f"Invalid run period {flags.GeoModel.Run}")
60
61
62def prepareInput(flags, inputTokens : list) :
63 flags.Input.Files = []
64
66 from os import path, listdir
67 for fileArg in inputTokens:
68 if path.isdir(fileArg):
69 flags.Input.Files += [ "{dir}/{file}".format(dir=fileArg, file=y) for y in listdir(fileArg) ]
70 else:
71 if fileArg[fileArg.rfind(".")+1 :]not in ["txt", "conf"]:
72 flags.Input.Files+=[fileArg]
73 else:
74 with open(fileArg) as inStream:
75 #Check if the input is a string of comma separated files, and if it is, split it into a list
76 if isinstance(inStream, str) and "," in inStream:
77 flags.Input.Files += inStream.split(",")
78 else:
79 flags.Input.Files+=[ line.strip() for line in inStream if line[0]!='#']
80
81
83 """
84 Setup flags necessary for Muon standalone.
85 """
86 from AthenaConfiguration.AllConfigFlags import initConfigFlags
87 flags = initConfigFlags()
88 flags.Detector.GeometryMDT = True
89 flags.Detector.GeometryTGC = True
90
91 flags.Detector.GeometryRPC = True
92 # TODO: disable these for now, to be determined if needed
93 flags.Detector.GeometryCalo = False
94 flags.Detector.GeometryID = False
95
96 # FIXME This is temporary. I think it can be removed with some other refactoring
97 flags.Muon.makePRDs = False
98
99 flags.Exec.MaxEvents = 20 # Set default to 20 if not overridden
100 flags.Scheduler.ShowDataDeps = True
101 flags.Scheduler.CheckDependencies = True
102 flags.Scheduler.ShowDataFlow = True
103 flags.Scheduler.ShowControlFlow = True
104 flags.Concurrency.NumThreads = 1
105 flags.Concurrency.NumConcurrentEvents = 1
106 flags.Exec.FPE= 500
107
108 flags.fillFromArgs()
109
110 if flags.Input.Files == ['_ATHENA_GENERIC_INPUTFILE_NAME_'] or len(flags.Input.Files) == 0:
111 # If something is set from an arg (i.e. the command line), this takes priority
112 from AthenaConfiguration.TestDefaults import defaultTestFiles
113 flags.Input.Files = defaultTestFiles.ESD_RUN3_MC
114
115 configureCondTag(flags)
116
117 from AthenaConfiguration.DetectorConfigFlags import setupDetectorFlags
118 setupDetectorFlags(flags)
119
120 if flags.Output.ESDFileName == '':
121 flags.Output.ESDFileName='newESD.pool.root'
122
123 flags.lock()
124 flags.dump(evaluate = True)
125 return flags
126
128 # When running from a pickled file, athena inserts some services automatically. So only use this if running now.
129
130 from AthenaConfiguration.MainServicesConfig import MainServicesCfg
131 cfg = MainServicesCfg(flags)
132 msgService = cfg.getService('MessageSvc')
133 msgService.Format = "S:%s E:%e % F%128W%S%7W%R%T %0W%M"
134 msgService.debugLimit = 2147483647
135 msgService.verboseLimit = 2147483647
136 msgService.infoLimit = 2147483647
137
138
139 from AthenaConfiguration.Enums import Format
140 if not flags.Input.Files:
141 # No input file --- skip setting up event reading.
142 pass
143 elif flags.Input.Format is Format.POOL:
144 from AthenaPoolCnvSvc.PoolReadConfig import PoolReadCfg
145 cfg.merge(PoolReadCfg(flags))
146 elif flags.Input.Format == Format.BS:
147 from ByteStreamCnvSvc.ByteStreamConfig import ByteStreamReadCfg
148 cfg.merge(ByteStreamReadCfg(flags))
149
150 if flags.Input.isMC:
151 if ("TruthEvents" in flags.Input.Collections):
152 from xAODTruthCnv.RedoTruthLinksConfig import RedoTruthLinksAlgCfg
153 cfg.merge( RedoTruthLinksAlgCfg(flags) )
154 elif ("TruthEvent" in flags.Input.Collections):
155 from xAODTruthCnv.xAODTruthCnvConfig import GEN_AOD2xAODCfg
156 cfg.merge(GEN_AOD2xAODCfg(flags))
157
158
159 from MuonConfig.MuonGeometryConfig import MuonGeoModelCfg
160 cfg.merge(MuonGeoModelCfg(flags))
161 from MuonConfig.MuonGeometryConfig import MuonIdHelperSvcCfg
162 cfg.merge(MuonIdHelperSvcCfg(flags))
163
164 return cfg
165
166def SetupMuonStandaloneOutput(cfg, flags, itemsToRecord):
167 # Set up output
168 from OutputStreamAthenaPool.OutputStreamConfig import OutputStreamCfg, outputStreamName
169
170 cfg.merge( OutputStreamCfg( flags, 'ESD', ItemList=itemsToRecord) )
171 outstream = cfg.getEventAlgo(outputStreamName("ESD"))
172 outstream.ForceRead = True
173
174 # Fix for ATLASRECTS-5151
175 from TrkEventCnvTools.TrkEventCnvToolsConfig import (
176 TrkEventCnvSuperToolCfg)
177 cfg.merge(TrkEventCnvSuperToolCfg(flags))
178
void print(char *figname, TCanvas *c1)
configureDefaultTags(flags)
setupHistSvcCfg(flags, str outFile, str outStream, int autoFlush=-30000000, int autoSave=-30000000)
Configuration snippet to setup the THistSvc.
SetupMuonStandaloneOutput(cfg, flags, itemsToRecord)
prepareInput(flags, list inputTokens)