ATLAS Offline Software
Loading...
Searching...
No Matches
VP1AlgConfig.py
Go to the documentation of this file.
1# Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
2
3from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
4from AthenaConfiguration.ComponentFactory import CompFactory
5
6# from AthenaConfiguration.Enums import Format
7
8
9def configureGeometry(flags, cfg):
10 if flags.Detector.GeometryBpipe:
11 from BeamPipeGeoModel.BeamPipeGMConfig import BeamPipeGeometryCfg
12
13 cfg.merge(BeamPipeGeometryCfg(flags))
14
15 if flags.Detector.GeometryPixel:
16 from PixelGeoModel.PixelGeoModelConfig import PixelReadoutGeometryCfg
17
18 cfg.merge(PixelReadoutGeometryCfg(flags))
19
20 if flags.Detector.GeometrySCT:
21 from SCT_GeoModel.SCT_GeoModelConfig import SCT_ReadoutGeometryCfg
22
23 cfg.merge(SCT_ReadoutGeometryCfg(flags))
24
25 if flags.Detector.GeometryTRT:
26 from TRT_GeoModel.TRT_GeoModelConfig import TRT_ReadoutGeometryCfg
27
28 cfg.merge(TRT_ReadoutGeometryCfg(flags))
29
30 if flags.Detector.GeometryITkPixel:
31 from PixelGeoModelXml.ITkPixelGeoModelConfig import ITkPixelReadoutGeometryCfg
32
33 cfg.merge(ITkPixelReadoutGeometryCfg(flags))
34
35 if flags.Detector.GeometryITkStrip:
36 from StripGeoModelXml.ITkStripGeoModelConfig import ITkStripReadoutGeometryCfg
37
38 cfg.merge(ITkStripReadoutGeometryCfg(flags))
39
40 if flags.Detector.GeometryHGTD:
41 from HGTD_GeoModelXml.HGTD_GeoModelConfig import HGTD_ReadoutGeometryCfg
42
43 cfg.merge(HGTD_ReadoutGeometryCfg(flags))
44
45 if flags.Detector.GeometryLAr:
46 from LArGeoAlgsNV.LArGMConfig import LArGMCfg
47
48 cfg.merge(LArGMCfg(flags))
49
50 if flags.Detector.GeometryTile:
51 from TileGeoModel.TileGMConfig import TileGMCfg
52
53 cfg.merge(TileGMCfg(flags))
54
55 if flags.Detector.GeometryMuon:
56 from MuonConfig.MuonGeometryConfig import MuonGeoModelCfg
57
58 cfg.merge(MuonGeoModelCfg(flags))
59
60 # Trigger the build of the InDetServMat geometry
61 # if any ID subsystems have been enabled
62 if flags.Detector.GeometryID:
63 from InDetServMatGeoModel.InDetServMatGeoModelConfig import (
64 InDetServiceMaterialCfg)
65 cfg.merge(InDetServiceMaterialCfg(flags))
66
67
68
70 import os
71
72 if "AtlasVersion" in os.environ:
73 return os.environ["AtlasVersion"]
74 if "AtlasBaseVersion" in os.environ:
75 return os.environ["AtlasBaseVersion"]
76 return "Unknown"
77
78
79def VP1AlgCfg(flags, name="VP1AlgCA", **kwargs):
80 # This is based on a few old-style configuation files:
81 # JiveXML_RecEx_config.py
82 # JiveXML_jobOptionBase.py
83 result = ComponentAccumulator()
84
85 kwargs.setdefault("AtlasRelease", getATLASVersion())
86 the_alg = CompFactory.VP1Alg(name="VP1EventDisplayAlg", **kwargs)
87 result.addEventAlgo(the_alg, primary=True)
88 return result
89
90
92 from AthenaConfiguration.Enums import Format
93 from AthenaCommon.Logging import logging
94 from AthenaCommon.Constants import VERBOSE
95
96 # ++++ Firstly we setup flags ++++
97 _logger = logging.getLogger("VP1")
98 _logger.setLevel(VERBOSE)
99
100 from AthenaConfiguration.AllConfigFlags import initConfigFlags
101
102 flags = initConfigFlags()
103 flags.Concurrency.NumThreads = 0
104
105 # ^ VP1 will not work with the scheduler, since its condition/data dependencies are not known in advance
106 # More in details: the scheduler needs to know BEFORE the event, what the dependencies of each Alg are.
107 # So for VP1, no dependencies are declared, which means the conditions data is not there.
108 # So when I load tracks, the geometry is missing and it crashes.
109 # Turning off the scheduler (with NumThreads=0) fixes this.
110
111 parser = flags.getArgumentParser()
112 parser.prog = "vp1"
113 parser.description = """
114 VP1, or Virtual Point 1, is the interactive 3D event display for the ATLAS experiment at CERN.
115 Detailed documentation can be found at the webpage: https://atlas-vp1.web.cern.ch/atlas-vp1
116 but below are the flags that can be used to configure VP1 (most are standard Athena flags, but some are VP1-specific).
117 """
118 parser.description = """
119 So for example, to run VP1 on a file: vp1 [options] myESD.pool.root"""
120 # Add VP1-specific arguments here, but remember you can also directly pass flags in form <flagName>=<value>.
121 group = parser.add_argument_group("VP1 specific")
122 group.add_argument(
123 "Filename",
124 nargs='?',
125 help="Input file to pass to VP1 (i.e. vp1 myESD.pool.root as an alternative to vp1 --filesInput=[])",
126 metavar="File name",
127 )
128 group.add_argument(
129 "--config",
130 nargs="*",
131 help="Config file to use for VP1. If not specified, the default configuration will be used.",
132 )
133 group.add_argument(
134 "--verboseAthena",
135 action="store_true",
136 help="If false, tell Athena to suppress INFO messages and below.",
137 )
138 group.add_argument(
139 "--online", action="store_true", help="Use this flag for running VP1 at P1."
140 )
141 group.add_argument(
142 "--cruise",
143 type=int,
144 help="Start in cruise mode, changing events after N seconds.",
145 )
146 # Phase-II
147 group.add_argument(
148 "--phaseII", action="store_true", help="Launch VP1 with the current default Run4 geometry tag for Phase-II [that is, it sets 'flags.GeoModel.AtlasVersion = defaultGeometryTags.RUN4']. It cannot be used when running VP1 on a data file, otherwise it interferes with the auto-configuration from the metadata stored in the file."
149 )
150 # Batch
151 group.add_argument(
152 "--batch",
153 action="store_true",
154 help="Run VP1 in 'batch' mode with a given configuration file.",
155 )
156 group.add_argument(
157 "--batch-all-events",
158 action="store_true",
159 help="Process all events in the input data file in '-batch' mode. Use this together with '-batch'.",
160 )
161 group.add_argument(
162 "--batch-n-events",
163 type=int,
164 help="Process 'N' events in the input data file in '-batch' mode. Use this together with '-batch'.",
165 )
166 group.add_argument(
167 "--batch-output-folder",
168 help="Specify an output folder to store the event displays produced with the '-batch' option.",
169 )
170 group.add_argument(
171 "--batch-random-config",
172 action="store_true",
173 help="Run VP1 in 'batch' mode; for each single event a configuration file will be randomly picked out of the configuration files provided by the user. Use this together with '-batch'.",
174 )
175 # Live / Livelocal
176 group.add_argument(
177 "--live", action="store_true", help="Run on live events from point 1."
178 )
179 group.add_argument(
180 "--livelocal",
181 action="store_true",
182 help="Run on live events from point 1 in local directory.",
183 )
184 group.add_argument(
185 "--eventsrc",
186 help="Directory to take single event files from (do not specify input files in this case). To get files from a web server (i.e. live events), put instead the url to the file residing in the same directory (most users should just use the --live option instead).",
187 )
188 group.add_argument(
189 "--extraevtsrcdir",
190 help="Directory to take single event files from (do not specify input files in this case). To get files from a web server (i.e. live events), put instead the url to the file residing in the same directory (most users should just use the -live option instead).",
191 )
192 group.add_argument(
193 "--eventcpy",
194 help="Directory to keep local copies of processed event files. If --eventsrc is set, then -eventcpy will default to /tmp/emoyse/vp1events/6897 .",
195 )
196 # group.add_argument('--nocleanupeventcpy', action='store_true', help="Prevent removal of eventcpy directory after athena process finishes.")
197 # Commented, because I'm not sure how to implement this safely, yet -- TODO.
198
199 args = flags.fillFromArgs(parser=parser)
200
201 if args.help:
202 print(args)
203 # No point doing more here, since we just want to print the help.
204 import sys
205 sys.exit()
206
207 # Support the positional version of passing file name e.g. vp1 myESD.pool.root
208 if args.Filename and (
209 flags.Input.Files == []
210 or flags.Input.Files == ["_ATHENA_GENERIC_INPUTFILE_NAME_"]
211 ):
212 flags.Input.Files = [args.Filename]
213
214 _logger.verbose("+ About to set flags related to the input")
215
216
217 # This dict stores the variables to set the VP1Alg properties
218 vp1config = {}
219
220
221 # Empty input is not normal for Athena, so we will need to check
222 # this repeatedly below
223 vp1_empty_input = False
224 # This covers the use case where we launch VP1
225 # without input files; e.g., to check the detector description
226 if (flags.Input.Files == [] or flags.Input.Files == ["_ATHENA_GENERIC_INPUTFILE_NAME_"]):
227 if not args.phaseII:
228 from Campaigns.Utils import Campaign
229 from AthenaConfiguration.TestDefaults import defaultGeometryTags
230
231 vp1_empty_input = True
232 vp1config.setdefault("EmptyInput", vp1_empty_input)
233
234 # NB Must set e.g. ConfigFlags.Input.Runparse_args() Number and
235 # ConfigFlags.Input.TimeStamp before calling the
236 # MainServicesCfg to avoid it attempting auto-configuration
237 # from an input file, which is empty in this use case.
238 # If you don't have it, it (and/or other Cfg routines) complains and crashes.
239 # See also:
240 # https://acode-browser1.usatlas.bnl.gov/lxr/source/athena/InnerDetector/InDetConditions/SCT_ConditionsAlgorithms/python/SCT_DCSConditionsTestAlgConfig.py#0023
241 flags.Input.ProjectName = "mc20_13TeV"
242 flags.Input.RunNumbers = [330000]
243 flags.Input.TimeStamps = [1]
244 flags.Input.TypedCollections = []
245
246 # set default CondDB and Geometry version
247 flags.IOVDb.GlobalTag = "OFLCOND-MC23-SDR-RUN3-02"
248 flags.Input.isMC = True
249 flags.Input.MCCampaign = Campaign.Unknown
250 flags.GeoModel.AtlasVersion = defaultGeometryTags.RUN3
251 elif args.phaseII:
252 _logger.verbose("Phase-II mode!")
253 from Campaigns.Utils import Campaign
254 from AthenaConfiguration.TestDefaults import defaultGeometryTags
255 vp1_empty_input = True
256 flags.Input.ProjectName = "mc21_14TeV"
257 flags.Input.RunNumbers = [601229]
258 flags.Input.TimeStamps = [1]
259 flags.Input.TypedCollections = []
260
261 # set default CondDB and Geometry version
262 flags.IOVDb.GlobalTag = "OFLCOND-MC16-SDR-15"
263 flags.Input.isMC = True
264 flags.Input.MCCampaign = Campaign.Unknown
265 flags.GeoModel.AtlasVersion = defaultGeometryTags.RUN4
266
267
268 # Here we consider the use case where we launch VP1
269 # with input data files
270 # (such as ESD, HITS, RDO, or any other pool.root file)
271 else:
272
273 if args.phaseII:
274 _logger.error("VP1: The use of the `--phaseII` flag with input data file is not supported. When you run VP1 on input data file, metadata are taken from the data file itself. Please remove `--phaseII` and relaunch. However, if needed, you can still steer Athena by using the standard Athena flags and options. Exiting...\n")
275 import sys
276 sys.exit(2)
277
278 # Now just check file exists, or fail gracefully
279 from os import path
280
281 for file in flags.Input.Files:
282 if not path.exists(flags.Input.Files[0]):
283 _logger.warning("Input file '%s' does not exist", file)
284 import sys
285 sys.exit(1)
286
287 # Set the online flag if we are running at P1
288 if args.online:
289 flags.Common.isOnline = args.online
290 elif "HLTP" in flags.IOVDb.GlobalTag:
291 print(
292 "HLTP detected in the global tag, but --online mode is not enabled. Enabling it now."
293 )
294 flags.Common.isOnline = True
295
296 _logger.verbose("+ ... Input flags done")
297
298 _logger.verbose("+ About to set the detector flags")
299 # So we can now set up the geometry flags from the input
300 from AthenaConfiguration.DetectorConfigFlags import setupDetectorFlags
301
302 setupDetectorFlags(
303 flags,
304 None,
305 use_metadata=not vp1_empty_input,
306 toggle_geometry=True,
307 keep_beampipe=True,
308 )
309 _logger.verbose("+ ... Detector flags done")
310
311 # finalize setting flags: lock them.
312 flags.lock()
313
314 # DEBUG -- inspect the flags
315 flags.dump()
316 # flags._loadDynaFlags('GeoModel')
317 # flags._loadDynaFlags('Detector')
318 # flags.dump('Detector.(Geometry|Enable)', True)
319
320 # ++++ Now we setup the actual configuration ++++
321
322 # NB Must have set ConfigFlags.Input.RunNumber and
323 # ConfigFlags.Input.TimeStamp before calling to avoid
324 # attempted auto-configuration from an input file.
325 _logger.verbose("+ Setup main services, and input file reading")
326
327 from AthenaConfiguration.MainServicesConfig import MainServicesCfg
328
329 cfg = MainServicesCfg(flags)
330
331 if not vp1_empty_input:
332 # Only do this if we have input files, otherwise flags will try to read metadata
333 # Check if we are reading from POOL and setupo convertors if so
334 if flags.Input.Format is Format.POOL:
335 from AthenaPoolCnvSvc.PoolReadConfig import PoolReadCfg
336
337 cfg.merge(PoolReadCfg(flags))
338 # Check if running on legacy inputs
339 if "EventInfo" not in flags.Input.Collections:
340 from xAODEventInfoCnv.xAODEventInfoCnvConfig import EventInfoCnvAlgCfg
341 cfg.merge(EventInfoCnvAlgCfg(flags))
342
343 from TrkConfig.TrackCollectionReadConfig import TrackCollectionReadCfg
344 cfg.merge(TrackCollectionReadCfg(flags, "Tracks"))
345
346
347 from TrkConfig.AtlasExtrapolatorConfig import AtlasExtrapolatorCfg
348 toolAtlasExtrapolator = cfg.popToolsAndMerge(AtlasExtrapolatorCfg(flags))
349 cfg.addPublicTool(toolAtlasExtrapolator)
350 vp1config.setdefault("ExtrapolatorTool", toolAtlasExtrapolator)
351
352
353 from TrkEventCnvTools.TrkEventCnvToolsConfig import TrkEventCnvSuperToolCfg
354 cfg.merge(TrkEventCnvSuperToolCfg(flags))
355
356
357 if flags.Input.isMC and "xAOD::TruthEventContainer#TruthEvents" not in flags.Input.TypedCollections:
358 # AOD2xAOD Truth conversion
359 from xAODTruthCnv.xAODTruthCnvConfig import GEN_AOD2xAODCfg
360 cfg.merge(GEN_AOD2xAODCfg(flags))
361
362 _logger.verbose("+ ... Main services done")
363
364 _logger.verbose("+ About to setup geometry")
365 configureGeometry(flags, cfg)
366 _logger.verbose("+ ... Geometry done")
367
368 # Setup some VP1 specific stuff
369 if not args.verboseAthena:
370 # Suppress the output from Athena
371 _logger.warning("From here, we are suppressing most messages from Athena.")
372 _logger.info("To see more, use the --verboseAthena flag; e.g., 'vp1 myESD.root --verboseAthena'")
373 msgService = cfg.getService("MessageSvc")
374 msgService.OutputLevel = 4
375
376 if args.cruise:
377 vp1config.setdefault("InitialCruiseMode", "EVENT")
378 vp1config.setdefault("InitialCruiseModePeriod", args.cruise)
379
380 if args.config:
381 print("Using config file", args.config)
382 vp1config.setdefault("InitialInputVP1Files", args.config)
383
384 # Batch mode
385 if args.batch:
386 setup_batch_mode(args)
387
388 # Event copying and live
389 if args.eventsrc:
390 vp1config.setdefault("MultipleFilesON", True)
391
392 if args.live or args.livelocal:
393 setup_live_mode(args, vp1config)
394
395 # configure VP1
396 cfg.merge(VP1AlgCfg(flags, **vp1config))
397 cfg.run()
398
399
400def setup_live_mode(args, vp1config):
401 vp1config.setdefault("MultipleFilesON", True)
402 if args.eventcpy:
403 vp1config.setdefault("vp1Alg.MFLocalCopyDir", args.eventcpy)
404 if args.extraevtsrcdir:
405 vp1config.setdefault("MFAvailableLocalInputDirectories", args.extraevtsrcdir)
406 if args.live:
407 vp1config.setdefault(
408 "MFSourceDir",
409 "https://atlas-live.cern.ch/event_files/L1MinBias/vp1fileinfo.txt",
410 )
411 elif args.livelocal:
412 vp1config.setdefault("MFSourceDir", "/VP1_events/")
413
414
416 # BATCH-MODE
417 # If "--batch" is True, then set the corresponding env var.
418 # The GUI of VP1 will not be shown, but the config file will be taken
419 # and in the end a render of the 3D window will be saved as PNG file.
420 import os
421
422 if args.batch:
423 os.putenv("VP1_BATCHMODE", "1")
424 if args.batch_all_events:
425 os.putenv("VP1_BATCHMODE_ALLEVENTS", "1")
426 if args.batch_n_events:
427 os.putenv("VP1_BATCHMODE_NEVENTS", str(args.batch_n_events))
428 if args.batch_output_folder:
429 os.putenv("VP1_BATCHMODE_OUT_FOLDER", args.batch_output_folder)
430 if args.batch_random_config:
431 os.putenv("VP1_BATCHMODE_RANDOMCONFIG", "1")
432
433
434if __name__ == "__main__":
435 # Run with e.g.
436 # python -m VP1Algs.VP1AlgConfig --filesInput=myESD_ca.pool.root
437 SetupVP1()
438 import sys
439
440 sys.exit()
void print(char *figname, TCanvas *c1)
configureGeometry(flags, cfg)
VP1AlgCfg(flags, name="VP1AlgCA", **kwargs)
setup_batch_mode(args)
setup_live_mode(args, vp1config)