diff --git a/Control/AthenaConfiguration/python/AthConfigFlags.py b/Control/AthenaConfiguration/python/AthConfigFlags.py index 72857c51b2bbed00ee5efcc74a3c28edc6ff7a7b..12ba8defa33909d35452297b1cd08a64a7c246b8 100644 --- a/Control/AthenaConfiguration/python/AthConfigFlags.py +++ b/Control/AthenaConfiguration/python/AthConfigFlags.py @@ -262,20 +262,26 @@ class AthConfigFlags(object): f.get(self) return - - def fillFromArgs(self,listOfArgs=None): - """ - - Used to set flags from command-line parameters, like ConfigFlags.fillFromArgs(sys.argv[1:]) - """ - import argparse,sys + # scripts calling AthConfigFlags.fillFromArgs can extend this parser, and pass their version to fillFromArgs + def getArgumentParser(self): + import argparse parser= argparse.ArgumentParser() parser.add_argument("-d","--debug",default=None,help="attach debugger (gdb) before run, <stage>: conf, init, exec, fini") parser.add_argument("--evtMax",type=int,default=None,help="Max number of events to process") parser.add_argument("--skipEvents",type=int,default=None,help="Number of events to skip") parser.add_argument("--filesInput",default=None,help="Input file(s)") parser.add_argument("-l", "--loglevel",default=None,help="logging level (ALL, VERBOSE, DEBUG,INFO, WARNING, ERROR, or FATAL") + return parser + # parser argument must be an ArgumentParser returned from getArgumentParser() + def fillFromArgs(self,listOfArgs=None,parser=None): + """ + + Used to set flags from command-line parameters, like ConfigFlags.fillFromArgs(sys.argv[1:]) + """ + import sys + if parser is None: + parser = self.getArgumentParser() (args,leftover)=parser.parse_known_args(listOfArgs or sys.argv[1:]) #First, handle athena.py-like arguments: diff --git a/Control/AthenaMonitoring/share/Run3DQTestingDriver.py b/Control/AthenaMonitoring/share/Run3DQTestingDriver.py index 120d5aded063972edd98d1e0fdfd0ffcd69366d5..fc30f1f78ab8d0694d5923bdac761ce78c64f63b 100755 --- a/Control/AthenaMonitoring/share/Run3DQTestingDriver.py +++ b/Control/AthenaMonitoring/share/Run3DQTestingDriver.py @@ -12,18 +12,22 @@ if __name__=='__main__': import sys + from AthenaConfiguration.AllConfigFlags import ConfigFlags from argparse import ArgumentParser - parser = ArgumentParser() + parser = ConfigFlags.getArgumentParser() parser.add_argument('--preExec', help='Code to execute before locking configs') parser.add_argument('--postExec', help='Code to execute after setup') parser.add_argument('--dqOffByDefault', action='store_true', help='Set all DQ steering flags to False, user must then switch them on again explicitly') + # keep for compatibility reasons + parser.add_argument('--inputFiles', + help='Comma-separated list of input files (alias for --filesInput)') + # keep for compatibility reasons parser.add_argument('--maxEvents', type=int, - help='Maximum number of events to process') - parser.add_argument('--loglevel', type=int, default=3, - help='Verbosity level') - parser.add_argument('flags', nargs='*', help='Config flag overrides') - args = parser.parse_args() + help='Maximum number of events to process (alias for --evtMax)') + parser.add_argument('--printDetailedConfig', action='store_true', + help='Print detailed Athena configuration') + args, _ = parser.parse_known_args() # Setup the Run III behavior from AthenaCommon.Configurable import Configurable @@ -35,15 +39,22 @@ if __name__=='__main__': log.setLevel(INFO) # Set the Athena configuration flags - from AthenaConfiguration.AllConfigFlags import ConfigFlags from AthenaConfiguration.AutoConfigFlags import GetFileMD - ConfigFlags.Input.Files = ['/cvmfs/atlas-nightlies.cern.ch/repo/data/data-art/Tier0ChainTests/q431/21.0/myESD.pool.root'] + # default input if nothing specified + ConfigFlags.Input.Files = ['/cvmfs/atlas-nightlies.cern.ch/repo/data/data-art/AthenaMonitoring/q431/21.0/f946/myESD.pool.root'] ConfigFlags.Output.HISTFileName = 'ExampleMonitorOutput.root' if args.dqOffByDefault: from AthenaMonitoring.DQConfigFlags import allSteeringFlagsOff allSteeringFlagsOff() - ConfigFlags.fillFromArgs(args.flags) + ConfigFlags.fillFromArgs(parser=parser) + # override Input.Files with result from our own arguments + # if --filesInput was specified as well (!) this will override + if args.inputFiles is not None: + ConfigFlags.Input.Files = args.inputFiles.split(',') + # if --evtMax was specified as well this will override + if args.maxEvents is not None: + ConfigFlags.Exec.MaxEvents = args.maxEvents isReadingRaw = (GetFileMD(ConfigFlags.Input.Files).get('file_type', 'POOL') == 'BS') if isReadingRaw: if ConfigFlags.DQ.Environment not in ('tier0', 'tier0Raw', 'online'): @@ -85,7 +96,7 @@ if __name__=='__main__': from AthenaConfiguration.MainServicesConfig import MainServicesCfg from AthenaPoolCnvSvc.PoolReadConfig import PoolReadCfg cfg = MainServicesCfg(ConfigFlags) - + if isReadingRaw: # attempt to start setting up reco ... from CaloRec.CaloRecoConfig import CaloRecoCfg @@ -113,9 +124,7 @@ if __name__=='__main__': log.info('Executing postExec: %s', args.postExec) exec(args.postExec) - # If you want to turn on more detailed messages ... - # exampleMonitorAcc.getEventAlgo('ExampleMonAlg').OutputLevel = 2 # DEBUG - cfg.printConfig(withDetails=False) # set True for exhaustive info + cfg.printConfig(withDetails=args.printDetailedConfig) # set True for exhaustive info - sc = cfg.run(args.maxEvents, args.loglevel) + sc = cfg.run() sys.exit(0 if sc.isSuccess() else 1)