1717def get_config (path = None ):
1818 default_path = join (O2DPG_ROOT , "MC" , "config" , "analysis_testing" , "json" , "analyses_config.json" )
1919 if not path :
20- return default_path
20+ path = default_path
21+ else :
22+ if isdir (path ):
23+ # assume to look for analyses_config.json in this directory
24+ path = join (path , "analyses_config.json" )
2125
22- if isdir (path ):
23- # assume to look for analyses_config.json in this directory
24- path = join (path , "analyses_config.json" )
25-
26- if not exists (path ):
27- print (f"WARNING: Cannot locate config for AnalysisQC at custom path { path } . USe default at { default_path } " )
28- return default_path
26+ if not exists (path ):
27+ print (f"WARNING: Cannot locate config for AnalysisQC at custom path { path } . Use default at { default_path } " )
28+ path = default_path
2929
3030 with open (path , "r" ) as f :
3131 return json .load (f )["analyses" ]
@@ -69,25 +69,26 @@ def print_status(enabled):
6969 analyses = get_config (args .config )
7070
7171 for ana in analyses :
72- if ana ["name" ] == args .task :
73- if args .status :
74- print_status (ana ["enabled" ])
75- if args .applicable_to :
76- if ana .get ("valid_mc" , False ):
77- print ("mc" )
78- if ana .get ("valid_data" , False ):
79- print ("data" )
72+ if ana ["name" ] != args .task :
73+ continue
74+ if args .status :
75+ print_status (ana ["enabled" ])
76+ if args .applicable_to :
77+ if ana .get ("valid_mc" , False ):
78+ print ("mc" )
79+ if ana .get ("valid_data" , False ):
80+ print ("data" )
8081
81- return 0
82+ return 0
8283
8384 # analysis not found
84- print (f"UNKNOWN " )
85+ print (f"WARNING: Unknown task { args . task } " )
8586 return 1
8687
8788
8889def show_tasks (args ):
8990 """
90- Browse through analyses and see what is en-/disabled
91+ Browse through analyses and print what is en-/disabled
9192 """
9293 if not args .enabled and not args .disabled :
9394 args .enabled = True
@@ -103,6 +104,13 @@ def show_tasks(args):
103104
104105
105106def validate_output (args ):
107+ """
108+ Validation after running tasks
109+
110+ * check for corresponding *.log_done files from WF runner
111+ * check for exit code in *.log
112+ * check if expected output files are there
113+ """
106114
107115 if not args .config :
108116 # first see if config is not explicitly given, then use the directory where the analyses to check are located
@@ -139,6 +147,7 @@ def validate_output(args):
139147 # expected to have no output
140148 continue
141149
150+ # check if the expected outputs are there
142151 for expected_output in ana ["expected_output" ]:
143152 expected_output = join (analysis_dir , expected_output )
144153 if not exists (expected_output ):
@@ -148,6 +157,7 @@ def validate_output(args):
148157 logfile = join (analysis_dir , f"Analysis_{ analysis_name } .log" )
149158
150159 if exists (logfile ):
160+ # check the exit code in the *.log file
151161 exit_code = "0"
152162 with open (logfile , "r" ) as f :
153163 for line in f :
@@ -159,6 +169,8 @@ def validate_output(args):
159169 break
160170 if exit_code != "0" :
161171 continue
172+
173+ # check if the *.log_done file is there
162174 logfile_done = join (analysis_dir , f"Analysis_{ analysis_name } .log_done" )
163175 if not exists (logfile_done ):
164176 print (f"Apparently, analysis { analysis_name } did not run successfully, { logfile_done } does not exist." )
@@ -168,12 +180,14 @@ def validate_output(args):
168180
169181
170182def main ():
171- """entry point when run directly from command line"""
172- parser = argparse .ArgumentParser (description = 'Modify analysis configuration and write new config' )
183+ """
184+ entry point when run directly from command line
185+ """
186+ parser = argparse .ArgumentParser (description = 'Check, validate or modify analysis configuration' )
173187 sub_parsers = parser .add_subparsers (dest = "command" )
174188
175189 config_parser = argparse .ArgumentParser (add_help = False )
176- config_parser .add_argument ("-c" , "--config" , help = "input configuration to modify " )
190+ config_parser .add_argument ("-c" , "--config" , help = "input configuration to use " )
177191
178192 # modify config
179193 modify_parser = sub_parsers .add_parser ("modify" , parents = [config_parser ])
0 commit comments