Skip to content

Commit eb19ed7

Browse files
More parsers (#181)
* start adding more subparsers * start adding more subparsers * remove early parsing * wip: add more parsers * add attribute error * check before bugfx * bugfix * add more parsing options to instructions * add attribute error for final plots * add attribute error for final plots * remove run-
1 parent ff8ff03 commit eb19ed7

File tree

4 files changed

+78
-21
lines changed

4 files changed

+78
-21
lines changed

README.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,7 @@ variables needs extra fields like `title`, number of bins and range for the
170170
histogram creation. In the example analysis it can be run like this:
171171

172172
```shell
173-
fccanalysis run examples/FCCee/higgs/mH-recoil/mumu/analysis_final.py \
174-
--final
173+
fccanalysis final examples/FCCee/higgs/mH-recoil/mumu/analysis_final.py
175174
```
176175

177176
This will create 2 files per selection `SAMPLENAME_SELECTIONNAME.root` for the
@@ -187,8 +186,7 @@ the rendering of the plots but also ways of combining samples for plotting.
187186
In the example analysis it can be run in the following manner:
188187

189188
```shell
190-
fccanalysis run examples/FCCee/higgs/mH-recoil/mumu/analysis_plots.py \
191-
--plots
189+
fccanalysis plots examples/FCCee/higgs/mH-recoil/mumu/analysis_plots.py
192190
```
193191

194192
Resulting plots will be located the `outdir` defined in the analysis file.

bin/fccanalysis

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,25 @@
44
if __name__ == "__main__":
55
import argparse
66
import sys
7-
parser = argparse.ArgumentParser()
8-
subparsers = parser.add_subparsers()
9-
parser_run = subparsers.add_parser('run', help="run a RDataFrame based FCC analysis")
10-
if len(sys.argv)<2:
11-
print("for usage run fccanalyses --help")
7+
parser = argparse.ArgumentParser('FCCAnalyses parser')
8+
subparsers = parser.add_subparsers(help='types of running modes', dest='command')
9+
parser_run = subparsers.add_parser('run', help="run a RDataFrame based FCC analysis")
10+
parser_run_final = subparsers.add_parser('final', help="run a RDataFrame based FCC analysis final configuration")
11+
parser_run_plots = subparsers.add_parser('plots', help="run a RDataFrame based FCC analysis plot configuration")
12+
13+
from config.Parsers import *
14+
setup_run_parser(parser_run)
15+
setup_run_parser_final(parser_run_final)
16+
setup_run_parser_plots(parser_run_plots)
17+
18+
args = parser.parse_args()
19+
print('===============args bin ',args)
20+
21+
if len(sys.argv)<3:
22+
print("minimal running requirements : fccanalysis <runoption> <analysisfile>")
23+
print("running example : fccanalysis run examples/FCCee/higgs/mH-recoil/mumu/analysis_stage1.py")
24+
print("for running options, try : fccanalysis --help and fccanalysis <runoption> --help")
1225
sys.exit(3)
13-
from config.FCCAnalysisRun import * #such that the dictionary is loaded only if the configuration is ok
14-
run(parser, parser_run)
26+
27+
from config.FCCAnalysisRun import run
28+
run(parser)

config/FCCAnalysisRun.py

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,8 @@ def runStages(args, rdfModule, preprocess):
596596
#run locally
597597
if runBatch == False:
598598
print ('----> Running Locally')
599-
runLocal(rdfModule, chunkList[ch], outputchunk, args)
599+
args.output = outputchunk
600+
runLocal(rdfModule, chunkList[ch], args)
600601

601602
#run on batch
602603
if runBatch == True:
@@ -851,16 +852,19 @@ def setup_run_parser(parser):
851852

852853

853854
#__________________________________________________________
854-
def run(mainparser, subparser):
855+
def run(mainparser, subparser=None):
855856
"""
856857
Set things in motion.
857-
The two parser arguments are a hack to allow running this
858+
The two parser arguments are a hack to allow running this
858859
both as `fccanalysis run` and `python config/FCCAnalysisRun.py`
859860
For the latter case, both are the same (see below).
860861
"""
861-
setup_run_parser(subparser)
862-
args, _ = mainparser.parse_known_args()
863862

863+
if subparser:
864+
print("===================setup subparser")
865+
setup_run_parser(subparser)
866+
args, _ = mainparser.parse_known_args()
867+
print("args in mains code==============================",args)
864868
#check that the analysis file exists
865869
analysisFile = args.pathToAnalysisScript
866870
if not os.path.isfile(analysisFile):
@@ -869,14 +873,28 @@ def run(mainparser, subparser):
869873
sys.exit(3)
870874

871875
#set the RDF ELogLevel
872-
verbosity = ROOT.Experimental.RLogScopedVerbosity(ROOT.Detail.RDF.RDFLogChannel(), getattr(ROOT.Experimental.ELogLevel,args.eloglevel))
873-
876+
try:
877+
verbosity = ROOT.Experimental.RLogScopedVerbosity(ROOT.Detail.RDF.RDFLogChannel(), getattr(ROOT.Experimental.ELogLevel,args.eloglevel))
878+
except AttributeError:
879+
pass
874880
#load the analysis
875881
analysisFile=os.path.abspath(analysisFile)
882+
print ("--------------loading analysis file ",analysisFile)
876883
rdfSpec = importlib.util.spec_from_file_location("rdfanalysis", analysisFile)
877884
rdfModule = importlib.util.module_from_spec(rdfSpec)
878885
rdfSpec.loader.exec_module(rdfModule)
879886

887+
try:
888+
args.command
889+
if args.command == "run": runStages(args, rdfModule, args.preprocess)
890+
elif args.command == "final": runFinal(rdfModule)
891+
elif args.command == "plots": runPlots(analysisFile)
892+
return
893+
except AttributeError:
894+
print("============running the old way")
895+
896+
897+
#below is legacy using the old way of runnig with options in "python config/FCCAnalysisRun.py analysis.py --options
880898
#check if this is final analysis
881899
if args.final:
882900
if args.plots:
@@ -909,12 +927,12 @@ def run(mainparser, subparser):
909927
sys.exit(3)
910928
runStages(args, rdfModule, args.preprocess)
911929

912-
930+
913931
#__________________________________________________________
914932
if __name__ == "__main__":
915933
print("Running this script directly is deprecated, use `fccanalysis run` instead.")
916-
# legacy behavior: allow running this script directly
917-
# with python config/FCCAnalysis.py
934+
# legacy behavior: allow running this script directly
935+
# with python config/FCCAnalysis.py
918936
# and the same behavior as `fccanalysis run`
919937
import argparse
920938
parser = argparse.ArgumentParser()

config/Parsers.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
def setup_run_parser(parser):
2+
publicOptions = parser.add_argument_group('User options')
3+
publicOptions.add_argument("pathToAnalysisScript", help="path to analysis script")
4+
publicOptions.add_argument("--files-list", help="Specify input file to bypass the processList", default=[], nargs='+')
5+
publicOptions.add_argument("--output", help="Specify output file name to bypass the processList and or outputList, default output.root", type=str, default="output.root")
6+
publicOptions.add_argument("--nevents", help="Specify max number of events to process", type=int, default=-1)
7+
publicOptions.add_argument("--test", action='store_true', help="Run over the test file", default=False)
8+
publicOptions.add_argument('--bench', action='store_true', help='Output benchmark results to a JSON file', default=False)
9+
#publicOptions.add_argument("--final", action='store_true', help="Run final analysis (produces final histograms and trees)", default=False)
10+
#publicOptions.add_argument("--plots", action='store_true', help="Run analysis plots", default=False)
11+
publicOptions.add_argument("--preprocess", action='store_true', help="Run preprocessing", default=False)
12+
publicOptions.add_argument("--validate", action='store_true', help="Validate a given production", default=False)
13+
publicOptions.add_argument("--rerunfailed", action='store_true', help="Rerun failed jobs", default=False)
14+
publicOptions.add_argument("--jobdir", help="Specify the batch job directory", type=str, default="output.root")
15+
publicOptions.add_argument("--eloglevel", help="Specify the RDataFrame ELogLevel", type=str, default="kUnset", choices = ['kUnset','kFatal','kError','kWarning','kInfo','kDebug'])
16+
17+
internalOptions = parser.add_argument_group('\033[4m\033[1m\033[91m Internal options, NOT FOR USERS\033[0m')
18+
internalOptions.add_argument("--batch", action='store_true', help="Submit on batch", default=False)
19+
20+
def setup_run_parser_final(parser):
21+
publicOptions = parser.add_argument_group('User final options')
22+
publicOptions.add_argument("pathToAnalysisScript", help="path to analysis_final script")
23+
publicOptions.add_argument("--eloglevel", help="Specify the RDataFrame ELogLevel", type=str, default="kUnset", choices = ['kUnset','kFatal','kError','kWarning','kInfo','kDebug'])
24+
25+
def setup_run_parser_plots(parser):
26+
publicOptions = parser.add_argument_group('User plots options')
27+
publicOptions.add_argument("pathToAnalysisScript", help="path to analysis_plots script")

0 commit comments

Comments
 (0)