Commit ce417c9d authored by Jose Enrique.Ruiz's avatar Jose Enrique.Ruiz
Browse files

add granularity filter as optional input argument

parent 3c8f1da1
......@@ -497,10 +497,12 @@ def rawcopycliparsing(command):
##############################################################################
def provprocessparsing():
tag = standardhandle.gettag()
message = "usage: %prog [-c CONFIGFILE] <RUN_NUMBER> <DATEFOLDER> <SUBFOLDER>"
message = "usage: %prog [-c CONFIGFILE] [-f PROCESS] <RUN_NUMBER> <DATEFOLDER> <SUBFOLDER>"
parser = OptionParser(usage=message)
parser.add_option("-c", "--config", action="store", dest="configfile", default="cfg/sequencer.cfg",
help="use specific config file [default cfg/sequencer.cfg]")
parser.add_option("-f", "--filter", action="store", dest="filter", default="",
help="filter by process granularity [r0_to_dl1 or dl1_to_dl2]")
parser.add_option("-q", action="store_true", dest="quit", help="use this flag to reset session and remove log file")
# Parse the command line
......@@ -508,12 +510,15 @@ def provprocessparsing():
# Checking arguments
if len(args) != 3:
standardhandle.error(tag, "incorrect number of arguments, type -h for help", 2)
if opts.filter != "r0_to_dl1" and opts.filter != "dl1_to_dl2" and opts.filter != "":
standardhandle.error(tag, "incorrect value for --filter argument, type -h for help", 2)
# Set global variables
options.run = args[0]
options.datefolder = args[1]
options.subfolder = args[2]
options.configfile = opts.configfile
options.filter = opts.filter
options.quit = opts.quit
return options, tag
......
......@@ -16,6 +16,7 @@ def parse_variables(class_instance):
# -c cfg/sequencer.cfg
# -d 2020_02_18
# -o /fefs/aswg/data/real/DL1/20200218/v0.4.3_v00/
# --prod_id v0.4.3_v00
# /fefs/aswg/data/real/calibration/20200218/v00/calibration.Run02006.0000.hdf5
# /fefs/aswg/data/real/calibration/20200218/v00/drs4_pedestal.Run02005.0000.fits
# /fefs/aswg/data/real/calibration/20191124/v00/time_calibration.Run01625.0000.hdf5
......
......@@ -42,7 +42,7 @@ def copy_used_file(src, out, tag_handle):
standardhandle.warning(tag_handle, f"{ex}")
def parse_lines_log(run_number, tag_handle):
def parse_lines_log(filter_step, run_number, tag_handle):
"""Filter content in log file to produce a run wise session log."""
filtered = []
with open(LOG_FILENAME, "r") as f:
......@@ -57,6 +57,8 @@ def parse_lines_log(run_number, tag_handle):
tag_activity, tag_run = session_tag.split(":")
if int(tag_run) == int(run_number):
keep = True
if filter_step != "" and filter_step != tag_activity:
keep = False
if keep:
filtered.append(line)
return filtered
......@@ -159,6 +161,7 @@ if __name__ == "__main__":
# 02006
# v0.4.3_v00
# -c cfg/sequencer.cfg
# -f r0_to_dl1
# -q
options, tag = cliopts.provprocessparsing()
......@@ -166,7 +169,9 @@ if __name__ == "__main__":
pathRO = cfg.get("LST1", "RAWDIR")
pathDL1 = cfg.get("LST1", "ANALYSISDIR")
pathDL2 = cfg.get("LST1", "DL2DIR")
GRANULARITY = {"r0_to_dl1": pathDL1} # "dl1_to_dl2", "r0_to_dl2
GRANULARITY = {"r0_to_dl1": pathDL1, "dl1_to_dl2": pathDL2}
if options.filter:
GRANULARITY = {options.filter: GRANULARITY[options.filter]}
# check LOG_FILENAME exists
if not Path(LOG_FILENAME).exists():
......@@ -182,7 +187,7 @@ if __name__ == "__main__":
session_log_filename = f"{base_filename}.log"
# parse LOG_FILENAME content for a specific run
parsed_content = parse_lines_log(options.run, tag)
parsed_content = parse_lines_log(options.filter, options.run, tag)
# create temporal session log file
with open(session_log_filename, 'w') as f:
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment