ATLAS Offline Software
FullCPAlgorithmsTest_CA.py
Go to the documentation of this file.
1 #! /bin/env python3
2 # Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 #
4 # @author Tadej Novak
5 # @author Teng Jian Khoo
6 
7 import sys
8 import os
9 from AnalysisAlgorithmsConfig.ConfigAccumulator import DataType
10 from AnalysisAlgorithmsConfig.FullCPAlgorithmsTest import makeSequence
11 from AthenaConfiguration.AllConfigFlags import initConfigFlags
12 from AthenaConfiguration.ComponentFactory import CompFactory
13 from AthenaConfiguration.MainServicesConfig import MainServicesCfg
14 from AthenaPoolCnvSvc.PoolReadConfig import PoolReadCfg
15 from EventBookkeeperTools.EventBookkeeperToolsConfig import CutFlowSvcCfg
16 
17 flags = initConfigFlags()
18 athArgsParser = flags.getArgumentParser()
19 athArgsParser.add_argument("--input-file", action="append", dest="input_file",
20  default=None,
21  help="Specify the input file")
22 athArgsParser.add_argument("--output-file", action="store", dest="output_file",
23  default=None,
24  help="Specify the output file")
25 athArgsParser.add_argument("--dump-config", action="store", dest="dump_config",
26  default=None,
27  help="Dump the config in a pickle file")
28 athArgsParser.add_argument("--data-type", action="store", dest="data_type",
29  default="data",
30  help="Type of input to run over. Valid options are 'data', 'fullsim', 'fastsim'")
31 athArgsParser.add_argument('--block-config', dest='block_config',
32  action='store_true', default=False,
33  help='Configure the job with block configuration')
34 athArgsParser.add_argument('--text-config', dest='text_config',
35  action='store', default='',
36  help='Configure the job with the provided text configuration')
37 athArgsParser.add_argument('--for-compare', dest='for_compare',
38  action='store_true', default=False,
39  help='Configure the job for comparison of sequences vs blocks')
40 athArgsParser.add_argument('--no-systematics', dest='no_systematics',
41  action='store_true', default=False,
42  help='Configure the job to with no systematics')
43 athArgsParser.add_argument('--physlite', dest='physlite',
44  action='store_true', default=False,
45  help='Run the job on physlite')
46 athArgsParser.add_argument('--only-nominal-or', dest='onlyNominalOR',
47  action='store_true', default=False,
48  help='Only run overlap removal for nominal (skip systematics)')
49 athArgs = flags.fillFromArgs(parser=athArgsParser)
50 
51 dataType = DataType(athArgs.data_type)
52 blockConfig = athArgs.block_config
53 textConfig = athArgs.text_config
54 forCompare = athArgs.for_compare
55 
56 print(f"Running on data type: {dataType.value}")
57 
58 if athArgs.physlite:
59  inputfile = {DataType.Data: 'ASG_TEST_FILE_LITE_DATA',
60  DataType.FullSim: 'ASG_TEST_FILE_LITE_MC',
61  DataType.FastSim: 'ASG_TEST_FILE_LITE_MC_AFII'}
62 else:
63  inputfile = {DataType.Data: 'ASG_TEST_FILE_DATA',
64  DataType.FullSim: 'ASG_TEST_FILE_MC',
65  DataType.FastSim: 'ASG_TEST_FILE_MC_AFII'}
66 
67 # Set up the reading of the input file:
68 if athArgs.input_file:
69  flags.Input.Files = athArgs.input_file[:]
70 else:
71  testFile = os.getenv(inputfile[dataType])
72  flags.Input.Files = [testFile]
73 
74 flags.Exec.FPE = 500
75 flags.Exec.EventPrintoutInterval = 100
76 flags.lock()
77 
78 # Setup main services
79 cfg = MainServicesCfg(flags)
80 # Setup POOL reading
81 cfg.merge(PoolReadCfg(flags))
82 # Setup cutflow service
83 cfg.merge(CutFlowSvcCfg(flags))
84 
85 # Setup the configuration
86 cp_cfg = makeSequence(dataType, blockConfig, textConfig,
87  forCompare=forCompare,
88  noSystematics=athArgs.no_systematics,
89  isPhyslite=athArgs.physlite,
90  autoconfigFromFlags=flags, onlyNominalOR=athArgs.onlyNominalOR,
91  forceEGammaFullSimConfig=True)
92 # Add all algorithms from the sequence to the job.
93 cfg.merge(cp_cfg)
94 
95 # Set up a histogram output file for the job:
96 if blockConfig:
97  outputFile = f"ANALYSIS DATAFILE='FullCPAlgorithmsConfigTest.{dataType.value}.hist.root' OPT='RECREATE'"
98 elif textConfig:
99  outputFile = f"ANALYSIS DATAFILE='FullCPAlgorithmsTextConfigTest.{dataType.value}.hist.root' OPT='RECREATE'"
100 else:
101  outputFile = f"ANALYSIS DATAFILE='FullCPAlgorithmsTest.{dataType.value}.hist.root' OPT='RECREATE'"
102 if athArgs.output_file:
103  outputFile = f"ANALYSIS DATAFILE='{athArgs.output_file}' OPT='RECREATE'"
104 cfg.addService(CompFactory.THistSvc(Output=[outputFile]))
105 
106 cfg.printConfig() # For debugging
107 
108 # dump pickle
109 if athArgs.dump_config:
110  with open(athArgs.dump_config, "wb") as f:
111  cfg.store(f)
112 
113 sc = cfg.run(500)
114 sys.exit(sc.isFailure())
DataType
OFFLINE_FRAGMENTS_NAMESPACE::PointerType DataType
Definition: RoIBResultByteStreamTool.cxx:25
python.ConfigText.makeSequence
def makeSequence(configPath, dataType, algSeq, geometry=None, autoconfigFromFlags=None, isPhyslite=False, noPhysliteBroken=False, noSystematics=None)
Definition: ConfigText.py:243
python.MainServicesConfig.MainServicesCfg
def MainServicesCfg(flags, LoopMgr='AthenaEventLoopMgr')
Definition: MainServicesConfig.py:252
Trk::open
@ open
Definition: BinningType.h:40
python.AllConfigFlags.initConfigFlags
def initConfigFlags()
Definition: AllConfigFlags.py:19
Muon::print
std::string print(const MuPatSegment &)
Definition: MuonTrackSteering.cxx:28
python.EventBookkeeperToolsConfig.CutFlowSvcCfg
def CutFlowSvcCfg(flags, **kwargs)
Definition: EventBookkeeperToolsConfig.py:24
python.PoolReadConfig.PoolReadCfg
def PoolReadCfg(flags)
Definition: PoolReadConfig.py:69