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('--text-config', dest='text_config',
32  action='store', default=None,
33  help='Configure the job with the provided text configuration')
34 athArgsParser.add_argument('--no-systematics', dest='no_systematics',
35  action='store_true', default=False,
36  help='Configure the job to with no systematics')
37 athArgsParser.add_argument('--physlite', dest='physlite',
38  action='store_true', default=False,
39  help='Run the job on physlite')
40 athArgsParser.add_argument('--run', action='store', dest='run',
41  default=2, type=int,
42  help='Run number for the inputs')
43 athArgsParser.add_argument('--only-nominal-or', dest='onlyNominalOR',
44  action='store_true', default=False,
45  help='Only run overlap removal for nominal (skip systematics)')
46 athArgsParser.add_argument('--bleeding-edge', dest='bleeding_edge',
47  action='store_true', default=False,
48  help='Run on the latest bleeding edge input (usually from the CI output)')
49 athArgs = flags.fillFromArgs(parser=athArgsParser)
50 
51 dataType = DataType(athArgs.data_type)
52 textConfig = athArgs.text_config
53 
54 if textConfig:
55  from PathResolver import PathResolver
56  textConfig = PathResolver.FindCalibFile(textConfig)
57 
58 print(f"Running on data type: {dataType.value}")
59 
60 if athArgs.physlite:
61  if athArgs.run==3:
62  inputfile = {DataType.Data: 'ASG_TEST_FILE_LITE_RUN3_DATA',
63  DataType.FullSim: 'ASG_TEST_FILE_LITE_RUN3_MC',
64  DataType.FastSim: 'ASG_TEST_FILE_LITE_RUN3_MC_FASTSIM'}
65  elif athArgs.run==2:
66  inputfile = {DataType.Data: 'ASG_TEST_FILE_LITE_DATA',
67  DataType.FullSim: 'ASG_TEST_FILE_LITE_MC',
68  DataType.FastSim: 'ASG_TEST_FILE_LITE_MC_FASTSIM'}
69 else:
70  if athArgs.run==3:
71  inputfile = {DataType.Data: 'ASG_TEST_FILE_RUN3_DATA',
72  DataType.FullSim: 'ASG_TEST_FILE_RUN3_MC',
73  DataType.FastSim: 'ASG_TEST_FILE_RUN3_MC_FASTSIM'}
74  elif athArgs.run==2:
75  inputfile = {DataType.Data: 'ASG_TEST_FILE_DATA',
76  DataType.FullSim: 'ASG_TEST_FILE_MC',
77  DataType.FastSim: 'ASG_TEST_FILE_MC_FASTSIM'}
78 
79 # Set up the reading of the input file:
80 if athArgs.input_file:
81  flags.Input.Files = athArgs.input_file[:]
82 else:
83  testFile = os.getenv(inputfile[dataType])
84  flags.Input.Files = [testFile]
85 
86 flags.Exec.FPE = 500
87 flags.Exec.EventPrintoutInterval = 100
88 if flags.PerfMon.doFullMonMT or flags.PerfMon.doFastMonMT:
89  flags.PerfMon.OutputJSON="perfmonmt_CPAnalysis.json"
90 flags.lock()
91 
92 # Setup main services
93 cfg = MainServicesCfg(flags)
94 # Setup POOL reading
95 cfg.merge(PoolReadCfg(flags))
96 # Setup cutflow service
97 cfg.merge(CutFlowSvcCfg(flags))
98 
99 # Setup the configuration
100 cp_cfg = makeSequence(dataType, yamlPath=textConfig,
101  noSystematics=athArgs.no_systematics,
102  isPhyslite=athArgs.physlite,
103  autoconfigFromFlags=flags, onlyNominalOR=athArgs.onlyNominalOR,
104  forceEGammaFullSimConfig=True,
105  bleedingEdge=athArgs.bleeding_edge)
106 # Add all algorithms from the sequence to the job.
107 cfg.merge(cp_cfg)
108 
109 # Set up a histogram output file for the job:
110 if textConfig:
111  outputFile = f"ANALYSIS DATAFILE='FullCPAlgorithmsTextConfigTest.{dataType.value}.hist.root' OPT='RECREATE'"
112 else:
113  outputFile = f"ANALYSIS DATAFILE='FullCPAlgorithmsConfigTest.{dataType.value}.hist.root' OPT='RECREATE'"
114 if athArgs.output_file:
115  outputFile = f"ANALYSIS DATAFILE='{athArgs.output_file}' OPT='RECREATE'"
116 cfg.addService(CompFactory.THistSvc(Output=[outputFile]))
117 
118 cfg.printConfig() # For debugging
119 
120 # dump pickle
121 if athArgs.dump_config:
122  with open(athArgs.dump_config, "wb") as f:
123  cfg.store(f)
124 if flags.Exec.MaxEvents>0:
125  sc=cfg.run(flags.Exec.MaxEvents)
126 else:
127  sc = cfg.run(500)
128 sys.exit(sc.isFailure())
PathResolver::FindCalibFile
static std::string FindCalibFile(const std::string &logical_file_name)
Definition: PathResolver.h:108
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:309
python.MainServicesConfig.MainServicesCfg
def MainServicesCfg(flags, LoopMgr='AthenaEventLoopMgr')
Definition: MainServicesConfig.py:260
print
void print(char *figname, TCanvas *c1)
Definition: TRTCalib_StrawStatusPlots.cxx:25
Trk::open
@ open
Definition: BinningType.h:40
python.AllConfigFlags.initConfigFlags
def initConfigFlags()
Definition: AllConfigFlags.py:19
python.EventBookkeeperToolsConfig.CutFlowSvcCfg
def CutFlowSvcCfg(flags, **kwargs)
Definition: EventBookkeeperToolsConfig.py:24
python.PoolReadConfig.PoolReadCfg
def PoolReadCfg(flags)
Definition: PoolReadConfig.py:69