95def SetupVP1():
96 from AthenaConfiguration.Enums import Format
97 from AthenaCommon.Logging import logging
99
100
101 _logger = logging.getLogger("VP1")
102 _logger.setLevel(VERBOSE)
103
104 from AthenaConfiguration.AllConfigFlags import initConfigFlags
105
106 flags = initConfigFlags()
107 flags.Concurrency.NumThreads = 0
108
109
110
111
112
113
114
115 parser = flags.getArgumentParser()
116 parser.prog = "vp1"
117 parser.description = """
118 VP1, or Virtual Point 1, is the interactive 3D event display for the ATLAS experiment at CERN.
119 Detailed documentation can be found at the webpage: https://atlas-vp1.web.cern.ch/atlas-vp1
120 but below are the flags that can be used to configure VP1 (most are standard Athena flags, but some are VP1-specific).
121 """
122 parser.description = """
123 So for example, to run VP1 on a file: vp1 [options] myESD.pool.root"""
124
125 group = parser.add_argument_group("VP1 specific")
126 group.add_argument(
127 "--fix-snapshots", action="store_true",
128 help="Enable the temporary Linux GLX zero pixel-limit workaround (requires a C compiler).",
129 )
130 group.add_argument(
131 "Filename",
132 nargs='?',
133 help="Input file to pass to VP1 (i.e. vp1 myESD.pool.root as an alternative to vp1 --filesInput=[])",
134 metavar="File name",
135 )
136 group.add_argument(
137 "--config",
138 nargs="*",
139 help="Config file to use for VP1. If not specified, the default configuration will be used.",
140 )
141 group.add_argument(
142 "--verboseAthena",
143 action="store_true",
144 help="If false, tell Athena to suppress INFO messages and below.",
145 )
146 group.add_argument(
147 "--online", action="store_true", help="Use this flag for running VP1 at P1."
148 )
149 group.add_argument(
150 "--cruise",
151 type=int,
152 help="Start in cruise mode, changing events after N seconds.",
153 )
154
155 group.add_argument(
156 "--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."
157 )
158
159 group.add_argument(
160 "--batch",
161 action="store_true",
162 help="Run VP1 in 'batch' mode with a given configuration file.",
163 )
164 group.add_argument(
165 "--batch-all-events",
166 action="store_true",
167 help="Process all events in the input data file in '-batch' mode. Use this together with '-batch'.",
168 )
169 group.add_argument(
170 "--batch-n-events",
171 type=int,
172 help="Process 'N' events in the input data file in '-batch' mode. Use this together with '-batch'.",
173 )
174 group.add_argument(
175 "--batch-output-folder",
176 help="Specify an output folder to store the event displays produced with the '-batch' option.",
177 )
178 group.add_argument(
179 "--batch-random-config",
180 action="store_true",
181 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'.",
182 )
183
184 group.add_argument(
185 "--live", action="store_true", help="Run on live events from point 1."
186 )
187 group.add_argument(
188 "--livelocal",
189 action="store_true",
190 help="Run on live events from point 1 in local directory.",
191 )
192 group.add_argument(
193 "--eventsrc",
194 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).",
195 )
196 group.add_argument(
197 "--extraevtsrcdir",
198 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).",
199 )
200 group.add_argument(
201 "--eventcpy",
202 help="Directory to keep local copies of processed event files. If --eventsrc is set, then -eventcpy will default to /tmp/emoyse/vp1events/6897 .",
203 )
204
205
206
207 args = flags.fillFromArgs(parser=parser)
208
209 if args.help:
211
212 import sys
213 sys.exit()
214
215
216 if args.Filename and (
217 flags.Input.Files == []
218 or flags.Input.Files == ["_ATHENA_GENERIC_INPUTFILE_NAME_"]
219 ):
220 flags.Input.Files = [args.Filename]
221
222 _logger.verbose("+ About to set flags related to the input")
223
224
225
226 vp1config = {}
227
228
229
230
231 vp1_empty_input = False
232
233
234 if (flags.Input.Files == [] or flags.Input.Files == ["_ATHENA_GENERIC_INPUTFILE_NAME_"]):
235 if not args.phaseII:
236 from Campaigns.Utils import Campaign
237 from AthenaConfiguration.TestDefaults import defaultGeometryTags
238
239 vp1_empty_input = True
240
241
242
243
244
245
246
247
248 flags.Input.ProjectName = "mc20_13TeV"
249 flags.Input.RunNumbers = [330000]
250 flags.Input.TimeStamps = [1]
251 flags.Input.TypedCollections = []
252
253
254 flags.IOVDb.GlobalTag = "OFLCOND-MC23-SDR-RUN3-02"
255 flags.Input.isMC = True
256 flags.Input.MCCampaign = Campaign.Unknown
257 flags.GeoModel.AtlasVersion = defaultGeometryTags.RUN3
258 elif args.phaseII:
259 _logger.verbose("Phase-II mode!")
260 from Campaigns.Utils import Campaign
261 from AthenaConfiguration.TestDefaults import defaultConditionsTags, defaultGeometryTags
262 vp1_empty_input = True
263 flags.Input.ProjectName = "mc21_14TeV"
264 flags.Input.RunNumbers = [601229]
265 flags.Input.TimeStamps = [1]
266 flags.Input.TypedCollections = []
267
268
269 flags.IOVDb.GlobalTag = defaultConditionsTags.RUN4_MC
270 flags.Input.isMC = True
271 flags.Input.MCCampaign = Campaign.Unknown
272 flags.GeoModel.AtlasVersion = defaultGeometryTags.RUN4
273
274
275
276
277
278 else:
279
280 if args.phaseII:
281 _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")
282 import sys
283 sys.exit(2)
284
285
286 from os import path
287
288 for file in flags.Input.Files:
289 if not path.exists(flags.Input.Files[0]):
290 _logger.warning("Input file '%s' does not exist", file)
291 import sys
292 sys.exit(1)
293
294 vp1config.setdefault("EmptyInput", vp1_empty_input)
295
296
297 if args.online:
298 flags.Common.isOnline = args.online
299 elif "HLTP" in flags.IOVDb.GlobalTag:
301 "HLTP detected in the global tag, but --online mode is not enabled. Enabling it now."
302 )
303 flags.Common.isOnline = True
304
305 _logger.verbose("+ ... Input flags done")
306
307 _logger.verbose("+ About to set the detector flags")
308
309 from AthenaConfiguration.DetectorConfigFlags import setupDetectorFlags
310
311 setupDetectorFlags(
312 flags,
313 None,
314 use_metadata=not vp1_empty_input,
315 toggle_geometry=True,
316 keep_beampipe=True,
317 )
318 _logger.verbose("+ ... Detector flags done")
319
320
321 flags.lock()
322
323
324 flags.dump()
325
326
327
328
329
330
331
332
333
334 _logger.verbose("+ Setup main services, and input file reading")
335
336 from AthenaConfiguration.MainServicesConfig import MainServicesCfg
337
338 cfg = MainServicesCfg(flags)
339
340 if not vp1_empty_input:
341
342
343 if flags.Input.Format is Format.POOL:
344 from AthenaPoolCnvSvc.PoolReadConfig import PoolReadCfg
345
346 cfg.merge(PoolReadCfg(flags))
347
348 if "EventInfo" not in flags.Input.Collections:
349 from xAODEventInfoCnv.xAODEventInfoCnvConfig import EventInfoCnvAlgCfg
350 cfg.merge(EventInfoCnvAlgCfg(flags))
351
352 from TrkConfig.TrackCollectionReadConfig import TrackCollectionReadCfg
353 cfg.merge(TrackCollectionReadCfg(flags, "Tracks"))
354
355
356 from TrkConfig.AtlasExtrapolatorConfig import AtlasExtrapolatorCfg
357 toolAtlasExtrapolator = cfg.popToolsAndMerge(AtlasExtrapolatorCfg(flags))
358 cfg.addPublicTool(toolAtlasExtrapolator)
359 vp1config.setdefault("ExtrapolatorTool", toolAtlasExtrapolator)
360
361
362 from TrkEventCnvTools.TrkEventCnvToolsConfig import TrkEventCnvSuperToolCfg
363 cfg.merge(TrkEventCnvSuperToolCfg(flags))
364
365
366 if flags.Input.isMC and "xAOD::TruthEventContainer#TruthEvents" not in flags.Input.TypedCollections:
367
368 from xAODTruthCnv.xAODTruthCnvConfig import GEN_AOD2xAODCfg
369 cfg.merge(GEN_AOD2xAODCfg(flags))
370
371 _logger.verbose("+ ... Main services done")
372
373 _logger.verbose("+ About to setup geometry")
374 configureGeometry(flags, cfg)
375 _logger.verbose("+ ... Geometry done")
376
377
378 if not args.verboseAthena:
379
380 _logger.warning("From here, we are suppressing most messages from Athena.")
381 _logger.info("To see more, use the --verboseAthena flag; e.g., 'vp1 myESD.root --verboseAthena'")
382 msgService = cfg.getService("MessageSvc")
383 msgService.OutputLevel = 4
384
385 if args.cruise:
386 vp1config.setdefault("InitialCruiseMode", "EVENT")
387 vp1config.setdefault("InitialCruiseModePeriod", args.cruise)
388
389 if args.config:
390 print(
"Using config file", args.config)
391 vp1config.setdefault("InitialInputVP1Files", args.config)
392
393
394 if args.batch:
395 setup_batch_mode(args)
396
397
398 if args.eventsrc:
399 vp1config.setdefault("MultipleFilesON", True)
400
401 if args.live or args.livelocal:
402 setup_live_mode(args, vp1config)
403
404
405 cfg.merge(VP1AlgCfg(flags, **vp1config))
406 cfg.run()
407
408
void print(char *figname, TCanvas *c1)