ATLAS Offline Software
Loading...
Searching...
No Matches
RunTileTBDump.py
Go to the documentation of this file.
1#!/usr/bin/env python
2#
3# Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
4#
5'''@file RunTileTBDump.py
6@brief Script to run Tile Reconstrcution/Monitoring for calibration runs
7'''
8
9from TileRecEx import TileInputFiles
10from AthenaConfiguration.Enums import Format
11
12
13epiLog = """
14Examples:
15
16 RunTileTBDump.py --run RUNNUMBER --evtMax 1
17 RunTileTBDump.py --filesInput=FILE1,FILE2 Exec.SkipEvents=100
18
19At least one should provide the following arguments or Athena configuration flags (flags have higher priority):
20 Input file(s), e.g.: --run RUNNUMBER | --filesInput=FILE1,FILE2 | Input.Files="['FILE1','FILE2']"
21"""
22
23
24if __name__=='__main__':
25 import sys
26
27 from AthenaConfiguration.AllConfigFlags import initConfigFlags
28 flags = initConfigFlags()
29
30 parserParents = [flags.getArgumentParser(), TileInputFiles.getArgumentParser(add_help=False)]
31
32 import argparse
33 parser = argparse.ArgumentParser(parents=parserParents, add_help=False, epilog=epiLog, formatter_class=argparse.RawTextHelpFormatter)
34
35 parser.add_argument('--preExec', help='Code to execute before locking configs')
36 parser.add_argument('--postExec', help='Code to execute after setup')
37 parser.add_argument('--printDetailedConfig', action='store_true', help='Print detailed Athena configuration')
38
39 algorithms_group = parser.add_argument_group('TileTBDump and/or TileTBStat aglorithms to run')
40 algorithms_group.add_argument('--stat', action='store_true', help='Run TileTBstat algorithm')
41 algorithms_group.add_argument('--no-dump', action='store_false', dest='dump', help='Do not run TileTBDump algorithm')
42
43 parser.add_argument('--dump-bs-fragments', action='store_true', dest='dump_bs_fragments', help='Dump fragments from ByteStreamInputSvc')
44
45 run_period_group = parser.add_argument_group('LHC Run period')
46 run_period = run_period_group.add_mutually_exclusive_group()
47 run_period.add_argument('--run2', action='store_true', help='LHC Run2 period')
48 run_period.add_argument('--run3', action='store_true', help='LHC Run3 period')
49
50 args, _ = parser.parse_known_args()
51
52 # Setup logs
53 from AthenaCommon.Logging import log
54 from AthenaCommon import Constants
55 log.setLevel(Constants.INFO)
56
57 # Initially the following flags are not set up (they must be provided)
58 flags.Input.Files = []
59
60 # Initial configuration flags from command line arguments (to be used to set up defaults)
61 flags.fillFromArgs(parser=parser)
62
63 # =======>>> Set up the Athena configuration flags to defaults (can be overriden via comand line)
64
65 # Set up the Tile input files
66 if not flags.Input.Files and args.run:
67 flags.Input.Files = TileInputFiles.findFilesFromAgruments(args)
68 if not flags.Input.Files:
69 log.error('Input files must be provided! For example: --filesInput=file1,file2,... or --run RUNNUMBER')
70 sys.exit(-1)
71
72 runNumber = flags.Input.RunNumbers[0]
73
74 # Set up LHC Run period
75 if not any([args.run2, args.run3]):
76 if not flags.Input.isMC:
77 if runNumber >= 411938 or runNumber <= 0 or runNumber == 3:
78 args.run3 = True
79 elif runNumber > 232000 or runNumber == 2:
80 args.run2 = True
81
82 # Set up the DB global conditions tag
83 if flags.Input.Format is Format.BS:
84 if args.run3 or flags.Input.isMC:
85 condDbTag = 'OFLCOND-MC23-SDR-RUN3-01' if flags.Input.isMC else 'CONDBR2-BLKPA-2023-01'
86 detDescrVersion = 'ATLAS-R3S-2021-03-01-00'
87 elif args.run2:
88 condDbTag = 'CONDBR2-BLKPA-2018-16'
89 detDescrVersion = 'ATLAS-R2-2016-01-00-01'
90 else:
91 condDbTag = 'COMCOND-BLKPA-RUN1-06'
92 detDescrVersion = 'ATLAS-R1-2012-03-02-00'
93
94 flags.IOVDb.GlobalTag = condDbTag
95 flags.GeoModel.AtlasVersion = detDescrVersion
96
97
98 # Override default configuration flags from command line arguments
99 flags.fillFromArgs(parser=parser)
100
101 flags.needFlagsCategory('Tile')
102
103 if args.preExec:
104 log.info('Executing preExec: %s', args.preExec)
105 exec(args.preExec)
106
107 flags.lock()
108
109 log.info('=====>>> FINAL CONFIG FLAGS SETTINGS FOLLOW:')
110 flags.dump(pattern='Tile.*|Input.*|Exec.*|IOVDb.[D|G].*', evaluate=True)
111
112 # Initialize configuration object, add accumulator, merge, and run.
113 from AthenaConfiguration.MainServicesConfig import MainServicesCfg
114 cfg = MainServicesCfg(flags)
115
116 # =======>>> Set up the File (BS | POOL) reading
117 if flags.Input.Format is Format.BS:
118 # Configure reading the Tile BS files
119 from TileByteStream.TileByteStreamConfig import TileRawDataReadingCfg
120 cfg.merge( TileRawDataReadingCfg(flags, readMuRcv=False, readBeamElem=args.stat, readLaserObj=args.stat) )
121
122 from AthenaCommon.Constants import VERBOSE
123 if flags.Exec.OutputLevel is VERBOSE:
124 for alg in ['TileDigitsReadAlg', 'TileRawChannelReadAlg']:
125 cfg.getEventAlgo(alg).TileROD_Decoder.VerboseOutput = True
126
127 if args.dump_bs_fragments:
128 cfg.getService('ByteStreamInputSvc').DumpFlag = True
129
130 else:
131 log.error('Input files must be in BS format')
132 sys.exit(-1)
133
134 if args.dump:
135 dump_once = True if args.stat else False
136 from TileTBRec.TileTBDumpConfig import TileTBDumpCfg
137 cfg.merge(TileTBDumpCfg(flags, dumpOnce=dump_once))
138
139 if args.stat:
140 from TileTBRec.TileTBStatConfig import TileTBStatCfg
141 cfg.merge(TileTBStatCfg(flags))
142
143 # =======>>> Any last things to do?
144 if args.postExec:
145 log.info('Executing postExec: %s', args.postExec)
146 exec(args.postExec)
147
148 cfg.printConfig(withDetails=args.printDetailedConfig)
149
150 sc = cfg.run()
151 sys.exit(0 if sc.isSuccess() else 1)
getArgumentParser(**kwargs)
findFilesFromAgruments(args)