ATLAS Offline Software
VP1AlgConfig.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
2 
3 from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
4 from AthenaConfiguration.ComponentFactory import CompFactory
5 
6 # from AthenaConfiguration.Enums import Format
7 
8 
9 def 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 
79 def 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 
91 def SetupVP1():
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  # Batch
147  group.add_argument(
148  "--batch",
149  action="store_true",
150  help="Run VP1 in 'batch' mode with a given configuration file.",
151  )
152  group.add_argument(
153  "--batch-all-events",
154  action="store_true",
155  help="Process all events in the input data file in '-batch' mode. Use this together with '-batch'.",
156  )
157  group.add_argument(
158  "--batch-n-events",
159  type=int,
160  help="Process 'N' events in the input data file in '-batch' mode. Use this together with '-batch'.",
161  )
162  group.add_argument(
163  "--batch-output-folder",
164  help="Specify an output folder to store the event displays produced with the '-batch' option.",
165  )
166  group.add_argument(
167  "--batch-random-config",
168  action="store_true",
169  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'.",
170  )
171  # Live / Livelocal
172  group.add_argument(
173  "--live", action="store_true", help="Run on live events from point 1."
174  )
175  group.add_argument(
176  "--livelocal",
177  action="store_true",
178  help="Run on live events from point 1 in local directory.",
179  )
180  group.add_argument(
181  "--eventsrc",
182  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).",
183  )
184  group.add_argument(
185  "--extraevtsrcdir",
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  "--eventcpy",
190  help="Directory to keep local copies of processed event files. If --eventsrc is set, then -eventcpy will default to /tmp/emoyse/vp1events/6897 .",
191  )
192  # group.add_argument('--nocleanupeventcpy', action='store_true', help="Prevent removal of eventcpy directory after athena process finishes.")
193  # Commented, because I'm not sure how to implement this safely.
194 
195  args = flags.fillFromArgs(parser=parser)
196 
197  if args.help:
198  print(args)
199  # No point doing more here, since we just want to print the help.
200  import sys
201  sys.exit()
202 
203  # Support the positional version of passing file name e.g. vp1 myESD.pool.root
204  if args.Filename and (
205  flags.Input.Files == []
206  or flags.Input.Files == ["_ATHENA_GENERIC_INPUTFILE_NAME_"]
207  ):
208  flags.Input.Files = [args.Filename]
209 
210  _logger.verbose("+ About to set flags related to the input")
211 
212  # Empty input is not normal for Athena, so we will need to check
213  # this repeatedly below
214  vp1_empty_input = False
215  # This covers the use case where we launch VP1
216  # without input files; e.g., to check the detector description
217  if flags.Input.Files == [] or flags.Input.Files == [
218  "_ATHENA_GENERIC_INPUTFILE_NAME_"
219  ]:
220  from Campaigns.Utils import Campaign
221  from AthenaConfiguration.TestDefaults import defaultGeometryTags
222 
223  vp1_empty_input = True
224  # NB Must set e.g. ConfigFlags.Input.Runparse_args() Number and
225  # ConfigFlags.Input.TimeStamp before calling the
226  # MainServicesCfg to avoid it attempting auto-configuration
227  # from an input file, which is empty in this use case.
228  # If you don't have it, it (and/or other Cfg routines) complains and crashes.
229  # See also:
230  # https://acode-browser1.usatlas.bnl.gov/lxr/source/athena/InnerDetector/InDetConditions/SCT_ConditionsAlgorithms/python/SCT_DCSConditionsTestAlgConfig.py#0023
231  flags.Input.ProjectName = "mc20_13TeV"
232  flags.Input.RunNumbers = [330000]
233  flags.Input.TimeStamps = [1]
234  flags.Input.TypedCollections = []
235 
236  # set default CondDB and Geometry version
237  flags.IOVDb.GlobalTag = "OFLCOND-MC23-SDR-RUN3-02"
238  flags.Input.isMC = True
239  flags.Input.MCCampaign = Campaign.Unknown
240  flags.GeoModel.AtlasVersion = defaultGeometryTags.RUN3
241  else:
242  # Now just check file exists, or fail gracefully
243  from os import path
244 
245  for file in flags.Input.Files:
246  if not path.exists(flags.Input.Files[0]):
247  _logger.warning("Input file", file, "does not exist")
248  import sys
249  sys.exit(1)
250 
251  # Set the online flag if we are running at P1
252  if args.online:
253  flags.Common.isOnline = args.online
254  elif "HLTP" in flags.IOVDb.GlobalTag:
255  print(
256  "HLTP detected in the global tag, but --online mode is not enabled. Enabling it now."
257  )
258  flags.Common.isOnline = True
259 
260  _logger.verbose("+ ... Input flags done")
261 
262  _logger.verbose("+ About to set the detector flags")
263  # So we can now set up the geometry flags from the input
264  from AthenaConfiguration.DetectorConfigFlags import setupDetectorFlags
265 
267  flags,
268  None,
269  use_metadata=not vp1_empty_input,
270  toggle_geometry=True,
271  keep_beampipe=True,
272  )
273  _logger.verbose("+ ... Detector flags done")
274 
275  # finalize setting flags: lock them.
276  flags.lock()
277 
278  # DEBUG -- inspect the flags
279  flags.dump()
280  # flags._loadDynaFlags('GeoModel')
281  # flags._loadDynaFlags('Detector')
282  # flags.dump('Detector.(Geometry|Enable)', True)
283 
284  # ++++ Now we setup the actual configuration ++++
285 
286  # NB Must have set ConfigFlags.Input.RunNumber and
287  # ConfigFlags.Input.TimeStamp before calling to avoid
288  # attempted auto-configuration from an input file.
289  _logger.verbose("+ Setup main services, and input file reading")
290 
291  from AthenaConfiguration.MainServicesConfig import MainServicesCfg
292 
293  cfg = MainServicesCfg(flags)
294 
295  if not vp1_empty_input:
296  # Only do this if we have input files, otherwise flags will try to read metadata
297  # Check if we are reading from POOL and setupo convertors if so
298  if flags.Input.Format is Format.POOL:
299  from AthenaPoolCnvSvc.PoolReadConfig import PoolReadCfg
300 
301  cfg.merge(PoolReadCfg(flags))
302  # Check if running on legacy inputs
303  if "EventInfo" not in flags.Input.Collections:
304  from xAODEventInfoCnv.xAODEventInfoCnvConfig import EventInfoCnvAlgCfg
305  cfg.merge(EventInfoCnvAlgCfg(flags))
306 
307  from TrkConfig.TrackCollectionReadConfig import TrackCollectionReadCfg
308  cfg.merge(TrackCollectionReadCfg(flags, "Tracks"))
309 
310  from TrkConfig.AtlasExtrapolationEngineConfig import AtlasExtrapolationEngineCfg
311  AtlasExtrapolationEngine = cfg.getPrimaryAndMerge(AtlasExtrapolationEngineCfg(flags))
312  cfg.addPublicTool(AtlasExtrapolationEngine)
313 
314  from TrkEventCnvTools.TrkEventCnvToolsConfig import TrkEventCnvSuperToolCfg
315  cfg.merge(TrkEventCnvSuperToolCfg(flags))
316 
317 
318  if flags.Input.isMC and "xAOD::TruthEventContainer#TruthEvents" not in flags.Input.TypedCollections:
319  # AOD2xAOD Truth conversion
320  from xAODTruthCnv.xAODTruthCnvConfig import GEN_AOD2xAODCfg
321  cfg.merge(GEN_AOD2xAODCfg(flags))
322 
323  _logger.verbose("+ ... Main services done")
324 
325  _logger.verbose("+ About to setup geometry")
326  configureGeometry(flags, cfg)
327  _logger.verbose("+ ... Geometry done")
328 
329  # Setup some VP1 specific stuff
330  vp1config = {}
331  if not args.verboseAthena:
332  # Suppress the output from Athena
333  print("Suppressing most messages from Athena.")
334  print("To see more, set the --verboseAthena flag to true.")
335  msgService = cfg.getService("MessageSvc")
336  msgService.OutputLevel = 4
337 
338  if args.cruise:
339  vp1config.setdefault("InitialCruiseMode", "EVENT")
340  vp1config.setdefault("InitialCruiseModePeriod", args.cruise)
341 
342  if args.config:
343  print("Using config file", args.config)
344  vp1config.setdefault("InitialInputVP1Files", args.config)
345 
346  # Batch mode
347  if args.batch:
348  setup_batch_mode(args)
349 
350  # Event copying and live
351  if args.eventsrc:
352  vp1config.setdefault("MultipleFilesON", True)
353 
354  if args.live or args.livelocal:
355  setup_live_mode(args, vp1config)
356 
357  # configure VP1
358  cfg.merge(VP1AlgCfg(flags, **vp1config))
359  cfg.run()
360 
361 
362 def setup_live_mode(args, vp1config):
363  vp1config.setdefault("MultipleFilesON", True)
364  if args.eventcpy:
365  vp1config.setdefault("vp1Alg.MFLocalCopyDir", args.eventcpy)
366  if args.extraevtsrcdir:
367  vp1config.setdefault("MFAvailableLocalInputDirectories", args.extraevtsrcdir)
368  if args.live:
369  vp1config.setdefault(
370  "MFSourceDir",
371  "https://atlas-live.cern.ch/event_files/L1MinBias/vp1fileinfo.txt",
372  )
373  elif args.livelocal:
374  vp1config.setdefault("MFSourceDir", "/VP1_events/")
375 
376 
378  # BATCH-MODE
379  # If "--batch" is True, then set the corresponding env var.
380  # The GUI of VP1 will not be shown, but the config file will be taken
381  # and in the end a render of the 3D window will be saved as PNG file.
382  import os
383 
384  if args.batch:
385  os.putenv("VP1_BATCHMODE", "1")
386  if args.batch_all_events:
387  os.putenv("VP1_BATCHMODE_ALLEVENTS", "1")
388  if args.batch_n_events:
389  os.putenv("VP1_BATCHMODE_NEVENTS", str(args.batch_n_events))
390  if args.batch_output_folder:
391  os.putenv("VP1_BATCHMODE_OUT_FOLDER", args.batch_output_folder)
392  if args.batch_random_config:
393  os.putenv("VP1_BATCHMODE_RANDOMCONFIG", "1")
394 
395 
396 if __name__ == "__main__":
397  # Run with e.g.
398  # python -m VP1Algs.VP1AlgConfig --filesInput=myESD_ca.pool.root
399  SetupVP1()
400  import sys
401 
402  sys.exit()
python.AtlasExtrapolationEngineConfig.AtlasExtrapolationEngineCfg
def AtlasExtrapolationEngineCfg(flags, name='Extrapolation', nameprefix='Atlas')
Definition: AtlasExtrapolationEngineConfig.py:14
python.JetAnalysisCommon.ComponentAccumulator
ComponentAccumulator
Definition: JetAnalysisCommon.py:302
BeamPipeGMConfig.BeamPipeGeometryCfg
def BeamPipeGeometryCfg(flags)
Definition: BeamPipeGMConfig.py:5
TRT_GeoModelConfig.TRT_ReadoutGeometryCfg
def TRT_ReadoutGeometryCfg(flags)
Definition: TRT_GeoModelConfig.py:55
xAODTruthCnvConfig.GEN_AOD2xAODCfg
def GEN_AOD2xAODCfg(flags, name="GEN_AOD2xAOD", **kwargs)
Definition: xAODTruthCnvConfig.py:15
python.InDetServMatGeoModelConfig.InDetServiceMaterialCfg
def InDetServiceMaterialCfg(flags)
Definition: InDetServMatGeoModelConfig.py:8
VP1AlgConfig.setup_batch_mode
def setup_batch_mode(args)
Definition: VP1AlgConfig.py:377
VP1AlgConfig.setup_live_mode
def setup_live_mode(args, vp1config)
Definition: VP1AlgConfig.py:362
VP1AlgConfig.SetupVP1
def SetupVP1()
Definition: VP1AlgConfig.py:91
python.TrkEventCnvToolsConfig.TrkEventCnvSuperToolCfg
def TrkEventCnvSuperToolCfg(flags, name='EventCnvSuperTool', **kwargs)
Definition: TrkEventCnvToolsConfig.py:51
VP1AlgConfig.VP1AlgCfg
def VP1AlgCfg(flags, name="VP1AlgCA", **kwargs)
Definition: VP1AlgConfig.py:79
VP1AlgConfig.getATLASVersion
def getATLASVersion()
Definition: VP1AlgConfig.py:69
SCT_GeoModelConfig.SCT_ReadoutGeometryCfg
def SCT_ReadoutGeometryCfg(flags)
Definition: SCT_GeoModelConfig.py:42
python.MainServicesConfig.MainServicesCfg
def MainServicesCfg(flags, LoopMgr='AthenaEventLoopMgr')
Definition: MainServicesConfig.py:260
Constants
some useful constants -------------------------------------------------—
HGTD_GeoModelConfig.HGTD_ReadoutGeometryCfg
def HGTD_ReadoutGeometryCfg(flags)
Definition: python/HGTD_GeoModelConfig.py:23
LArGMConfig.LArGMCfg
def LArGMCfg(flags)
Definition: LArGMConfig.py:8
PixelGeoModelConfig.PixelReadoutGeometryCfg
def PixelReadoutGeometryCfg(flags)
Definition: PixelGeoModelConfig.py:42
python.DetectorConfigFlags.setupDetectorFlags
def setupDetectorFlags(flags, custom_list=None, use_metadata=False, toggle_geometry=False, validate_only=False, keep_beampipe=False)
Definition: DetectorConfigFlags.py:289
ITkPixelGeoModelConfig.ITkPixelReadoutGeometryCfg
def ITkPixelReadoutGeometryCfg(flags, setGeometryAlignable=False, setAlignmentFolderName="/Indet/Align")
Definition: ITkPixelGeoModelConfig.py:39
python.MuonGeometryConfig.MuonGeoModelCfg
def MuonGeoModelCfg(flags)
Definition: MuonGeometryConfig.py:28
ITkStripGeoModelConfig.ITkStripReadoutGeometryCfg
def ITkStripReadoutGeometryCfg(flags, setGeometryAlignable=False, setAlignmentFolderName="/Indet/Align")
Definition: ITkStripGeoModelConfig.py:39
python.AllConfigFlags.initConfigFlags
def initConfigFlags()
Definition: AllConfigFlags.py:19
str
Definition: BTagTrackIpAccessor.cxx:11
dbg::print
void print(std::FILE *stream, std::format_string< Args... > fmt, Args &&... args)
Definition: SGImplSvc.cxx:70
python.xAODEventInfoCnvConfig.EventInfoCnvAlgCfg
def EventInfoCnvAlgCfg(flags, name="EventInfoCnvAlg", inputKey="McEventInfo", outputKey="EventInfo", disableBeamSpot=False, **kwargs)
Definition: xAODEventInfoCnvConfig.py:11
python.PoolReadConfig.PoolReadCfg
def PoolReadCfg(flags)
Definition: PoolReadConfig.py:69
python.TrackCollectionReadConfig.TrackCollectionReadCfg
def TrackCollectionReadCfg(flags, key)
Definition: TrackCollectionReadConfig.py:28
VP1AlgConfig.configureGeometry
def configureGeometry(flags, cfg)
Definition: VP1AlgConfig.py:9
TileGMConfig.TileGMCfg
def TileGMCfg(flags)
Definition: TileGMConfig.py:7