Commit e9425b35 authored by Lab's avatar Lab
Browse files

now pedestal withing calibration sequence is working

parent 7367207d
#!/usr/bin/env python2.7
from osa.utils.standardhandle import output, verbose, warning, error, stringify, gettag
__all__ = ["calibrationsequence"]
def calibrationsequence(args):
tag = gettag()
# This is the python interface to run sorcerer with the -c option for calibration
# args: <RUN>
import sys
import subprocess
from os.path import join
from osa.utils import options, cliopts
from osa.reports import report
from osa.jobs.job import historylevel
ped_output_file = args[0]
run_ped = args[1]
run_cal = args[2]
historyfile = join(options.directory, 'sequence_' + options.tel_id + '_' + run_cal + '.history')
level, rc = historylevel(historyfile, 'CALIBRATION')
verbose(tag, "Going to level {0}".format(level))
print("historyfile:",historyfile, run_ped)
print("PEDESTAL directory:",options.directory, options.tel_id)
print("level & rc:",level, rc)
if level == 1:
rc = drs4_pedestal(run_ped, ped_output_file, historyfile)
level -=1
verbose(tag, "Going to level {0}".format(level))
# if level == 1:
# rc = calibrate(run_cal, historyfile)
# level -=1
# verbose(tag, "Going to level {0}".format(level))
if level == 0:
verbose(tag, "Job for sequence {0} finished without fatal errors".format(run))
return rc
##############################################################################
#
# DRS4 pedestal
#
##############################################################################
def drs4_pedestal(run_ped, ped_output_file, historyfile):
tag = gettag()
from sys import exit
from os.path import join
import subprocess
from osa.configs.config import cfg
from osa.reports.report import history
from register import register_run_concept_files
from osa.utils.utils import lstdate_to_dir
sequencetextfile = join(options.directory, 'sequence_' + options.tel_id + '_' + run_ped+ '.txt')
bindir = cfg.get('LSTOSA', 'LSTCHAINDIR')
daqdir = cfg.get(options.tel_id, 'RAWDIR')
#carddir = cfg.get('LSTOSA', 'CARDDIR')
inputcard = cfg.get(options.tel_id, 'CALIBRATIONCONFIGCARD')
#configcard = join(carddir, inputcard)
commandargs = [cfg.get('PROGRAM', 'PEDESTAL')]
nightdir = lstdate_to_dir(options.date)
input_file = join(cfg.get('LST1','RAWDIR'),nightdir,
'LST-1.1.Run{0}.'.format(run_ped)+'0000{1}{2}'.format(run_ped,cfg.get('LSTOSA','FITSSUFFIX'),cfg.get('LSTOSA','COMPRESSEDSUFFIX')))
max_events = cfg.get('LSTOSA', 'MAX_PED_EVENTS')
commandargs.append('--input_file=' + input_file)
# commandargs.append( input_file)
commandargs.append('--output_file=' + ped_output_file )
# commandargs.append( ped_output_file )
commandargs.append('--max_events='+ max_events)
print("COMAND for pedestal:",commandargs)
commandconcept = 'drs4_pedestal'
pedestalfile = 'drs4_pedestal'
try:
verbose(tag, "Executing \"{0}\"".format(stringify(commandargs)))
rc = subprocess.call(commandargs)
#except OSError as (ValueError, NameError):
except OSError as ValueError:
history(run_ped, commandconcept, ped_output_file, inputcard, ValueError, historyfile)
error(tag, "Could not execute \"{0}\", {1}".format(stringify(commandargs), NameError), ValueError)
except subprocess.CalledProcessError as Error:
error(tag, Error, rc)
else:
history(run_ped, commandconcept, pedestalfile, inputcard, rc, historyfile)
""" Error handling, for now no nonfatal errors are implemented for CALIBRATION """
if rc != 0:
exit(rc)
return rc
##############################################################################
#
# calibrate
#
##############################################################################
def calibrate(run, historyfile):
tag = gettag()
from sys import exit
from os.path import join
import subprocess
from osa.configs.config import cfg
from osa.reports.report import history
from register import register_run_concept_files
sequencetextfile = join(options.directory, 'sequence_' + options.tel_id + '_' + run + '.txt')
bindir = cfg.get('LSTOSA', 'LSTCHAINDIR')
daqdir = cfg.get(options.tel_id, 'RAWDIR')
#carddir = cfg.get('LSTOSA', 'CARDDIR')
inputcard = cfg.get(options.tel_id, 'CALIBRATIONCONFIGCARD')
#configcard = join(carddir, inputcard)
commandargs = [join(bindir, cfg.get('PROGRAM', 'CALIBRATION'))]
commandargs.append('-r' + calibration_run_id)
commandargs.append('-p' + predestal_run_id)
commandargs.append('-v' + version_lstchain )
print("COMAND for calib:",commandargs)
commandconcept = 'calibration'
calibrationfile = 'new_calib'
try:
verbose(tag, "Executing \"{0}\"".format(stringify(commandargs)))
rc = subprocess.call(commandargs)
#except OSError as (ValueError, NameError):
except OSError as ValueError:
history(run, commandconcept, calibrationfile, inputcard, ValueError, historyfile)
error(tag, "Could not execute \"{0}\", {1}".format(stringify(commandargs), NameError), ValueError)
except subprocess.CalledProcessError as Error:
error(tag, Error, rc)
else:
history(run, commandconcept, calibrationfile, inputcard, rc, historyfile)
""" Error handling, for now no nonfatal errors are implemented for CALIBRATION """
if rc != 0:
exit(rc)
return rc
##############################################################################
#
# MAIN
#
##############################################################################
if __name__ == '__main__':
tag = gettag()
import sys
from osa.utils import options, cliopts
# Set the options through cli parsing
args = cliopts.calibrationsequencecliparsing(sys.argv[0])
# Run the routine
rc = calibrationsequence(args)
sys.exit(rc)
......@@ -28,6 +28,7 @@ DL1-DL2 = hello.py
#SCRATCHDIR = /scratch
# Applications
CALIBRATION = calibration
MAX_PED_EVENTS = 8000
#COMBINEMUON = combinemuons
GRAPH = dot
# File type pattern for DB
......@@ -77,7 +78,7 @@ NIGHTSUMMARYSCRIPT = %(PYTHONDIR)s/create_nightsummary.py
MAXTRYFAILED = 2
[PROGRAM]
PEDESTAL = onsite_create_drs4_pedestal_file
PEDESTAL = lstchain_data_create_drs4_pedestal_file
CALIBRATION = onsite_create_calibration_file
[LST]
......
......@@ -208,7 +208,10 @@ def setsequencecalibfilenames(sequence_list):
for s in sequence_list:
if len(s.parent_list) == 0:
calfile = '666calib.root'
pedfile = '666ped.root'
#pedfile = '666ped.root'
ped_run_string = str(s.previousrun).zfill(5)
pedfile = "drs4_pedestal.Run{0}.0000{1}".\
format(ped_run_string, pedestal_suffix)
drivefile = '666drive.txt'
else:
run_string = str(s.parent_list[0].run).zfill(5)
......@@ -330,11 +333,22 @@ def createjobtemplate(s):
commandargs.append('--stdout=sequence_{0}_$SLURM_JOB_ID.log'.format(s.jobname))
commandargs.append('-d')
commandargs.append(options.date)
if s.type == 'CALIBRATION':
commandargs.append(os.path.join(pedestaldir, nightdir, version, s.pedestal))
ped_run = str(s.previousrun).zfill(5)
commandargs.append(ped_run)
if s.type == 'DATA':
commandargs.append(os.path.join(calibdir, nightdir, version, s.calibration))
commandargs.append(os.path.join(pedestaldir, nightdir, version, s.pedestal))
commandargs.append(os.path.join(calibdir, nightdir, version, 'time_'+ s.calibration))
commandargs.append(os.path.join(drivedir, s.drive))
pedfile = s.pedestal
#commandargs.append(str(s.run).zfill(5))
# if s.type != 'STEREO':
# commandargs.append(options.tel_id)
......@@ -344,7 +358,7 @@ def createjobtemplate(s):
# SLURM assignments
content += "#SBATCH -p compute\n"
content += "#SBATCH --tasks=2\n"
if s.type == DATA:
if s.type == 'DATA':
content += "#SBATCH --array=1-{0}\n".format(len(s.subrun_list))
content += "#SBATCH --cpus-per-task=1\n"
content += "#SBATCH --mem-per-cpu=1600\n"
......
......@@ -68,14 +68,16 @@ def closercliparsing():
# Setting on the usage of night summary
options.nightsum = True
##############################################################################
#
# calibrationsequencecliparsing
# pedestalsequencecliparsing
#
##############################################################################
def calibrationsequencecliparsing(command):
def pedestalsequencecliparsing(command):
tag = standardhandle.gettag()
message = "usage: %prog [-vw] [-c CONFIGFILE] [-d DATE] [-o OUTPUTDIR] [-z] <CAL_RUN_ID> <PED_RUN_ID> <TEL_ID>"
message = "usage: %prog [-vw] [-c CONFIGFILE] [-d DATE] [-o OUTPUTDIR] [-z] <PED_RUN_ID> <TEL_ID>"
parser = OptionParser(usage = message)
parser.add_option("-c", "--config", action = "store", dest = "configfile", default = None,
help = "use specific config file [default cfg/osa.cfg]")
......@@ -94,6 +96,7 @@ def calibrationsequencecliparsing(command):
parser.add_option("--stdout", action = "store", type = "string", dest = "stdout",
help = "file for standard output")
# Parse the command line
(opts, args) = parser.parse_args()
......@@ -112,7 +115,7 @@ def calibrationsequencecliparsing(command):
standardhandle.verbose(tag, "the argument is {0}".format(args))
# Mapping the telescope argument to an option parameter (it might become an option in the future)
if len(args) != 3:
if len(args) != 2:
standardhandle.error(tag, "incorrect number of arguments, type -h for help", 2)
elif args[1] == 'ST':
standardhandle.error(tag, "not yet ready for telescope {0}".format(options.options.tel_id), 2)
......@@ -121,6 +124,66 @@ def calibrationsequencecliparsing(command):
options.tel_id = args[1]
# Setting the default date and directory if needed
options.configfile = set_default_configfile_if_needed(command)
return args
##############################################################################
#
# calibrationsequencecliparsing
#
##############################################################################
def calibrationsequencecliparsing(command):
tag = standardhandle.gettag()
message = "usage: %prog [-vw] [-c CONFIGFILE] [-d DATE] [-o OUTPUTDIR] [-z] <CAL_RUN_ID> <PED_RUN_ID> <TEL_ID>"
parser = OptionParser(usage = message)
parser.add_option("-c", "--config", action = "store", dest = "configfile", default = None,
help = "use specific config file [default cfg/osa.cfg]")
parser.add_option("-d", "--date", action = "store", type = "string", dest = "date",
help = "observation ending date YYYY_MM_DD [default today]")
parser.add_option("-o", "--outputdir", action = "store", type = "string", dest = "directory",
help = "write files to output directory")
parser.add_option("-v", "--verbose", action = "store_true", dest = "verbose", default = False,
help = "make lots of noise for debugging")
parser.add_option("-w", "--warnings", action = "store_true", dest = "warning", default = False,
help = "show useful warnings")
parser.add_option("-z", "--rawzip", action = "store_true", dest = "compressed", default = False,
help = "Use input as compressed raw.gz files")
parser.add_option("--stderr", action = "store", type = "string", dest = "stderr",
help = "file for standard error")
parser.add_option("--stdout", action = "store", type = "string", dest = "stdout",
help = "file for standard output")
# Parse the command line
(opts, args) = parser.parse_args()
# Set global variables
options.configfile = opts.configfile
options.stderr = opts.stderr
options.stdout = opts.stdout
options.date = opts.date
options.directory = opts.directory
options.verbose = opts.verbose
options.warning = opts.warning
options.compressed = opts.compressed
# The standardhandle has to be declared here, since verbose and warnings are options from the cli
standardhandle.verbose(tag, "the options are {0}".format(opts))
standardhandle.verbose(tag, "the argument is {0}".format(args))
# Mapping the telescope argument to an option parameter (it might become an option in the future)
if len(args) != 4:
standardhandle.error(tag, "incorrect number of arguments, type -h for help", 2)
elif args[3] == 'ST':
standardhandle.error(tag, "not yet ready for telescope {0}".format(options.options.tel_id), 2)
elif args[3] != 'LST1' and args[3] != 'LST2':
standardhandle.error(tag, "wrong telescope id, use 'LST1', 'LST2' or 'ST'", 2)
options.tel_id = args[3]
# Setting the default date and directory if needed
options.configfile = set_default_configfile_if_needed(command)
options.date = set_default_date_if_needed()
......
......@@ -8,16 +8,18 @@
# A. Baquero <>, I. Aguado<>
# J. L. Contrera <>
# Last modified on:
# Credits: This script is written and modified following scripts from MAGIC OSA. Hence, a big portion
# Credits: This script is written and modified following scripts from
# MAGIC OSA. Hence, a #big portion
# of the credits goes to the authors of MAGIC OSA.
##############################################################################
#from utils import standardhandle
#from .. import utils
#import sys
#sys.path.append("..")
from osa.utils.standardhandle import output, verbose, warning, error, stringify, gettag
# from utils import standardhandle
# from .. import utils
# import sys
# sys.path.append("..")
from osa.utils.standardhandle import output, verbose, \
warning, error, stringify, gettag
from osa.utils import options, cliopts
#report import start
# report import start
# Only these functions will be considered when building the docs
__all__ = ["sequencer", "single_process", "stereo_process"]
##############################################################################
......@@ -26,10 +28,16 @@ __all__ = ["sequencer", "single_process", "stereo_process"]
#
# This is the main script to be called in crontab
##############################################################################
#def sequencer():
# def sequencer():
def main():
"""Runs the sequencer
"""
Runs the sequencer
"""
tag = gettag()
from osa.reports.report import start
from osa.configs import config
......@@ -53,7 +61,9 @@ def main():
# single_process
#
##############################################################################
def single_process(telescope, process_mode):
"""Runs the single process
Parameters
......@@ -116,7 +126,7 @@ def single_process(telescope, process_mode):
# updatesequencedb(sequence_list)
# actually, submitjobs does not need the queue_list nor veto_list
# job_list = job.submitjobs(sequence_list, queue_list, veto_list)
job_list = job.submitjobs(sequence_list)
# job_list = job.submitjobs(sequence_list)
# combine_muon(job_list)
# # Report
# if is_report_needed:
......@@ -135,7 +145,7 @@ def single_process(telescope, process_mode):
# stereo_process
#
##############################################################################
#def stereo_process(telescope, s1_list, s2_list):
# def stereo_process(telescope, s1_list, s2_list):
# tag = gettag()
# import extract
# import dot
......@@ -173,6 +183,7 @@ def single_process(telescope, process_mode):
# updatelstchainstatus
#
##############################################################################
def updatelstchainstatus(seq_list):
tag = gettag()
from decimal import Decimal
......@@ -191,6 +202,7 @@ def updatelstchainstatus(seq_list):
# getlstchainforsequence
#
##############################################################################
def getlstchainforsequence(s, program):
tag = gettag()
from os.path import join
......@@ -496,5 +508,5 @@ if __name__ == '__main__':
# Set the options through parsing of the command line interface
cliopts.sequencercliparsing(sys.argv[0])
# Run the routine
# sequencer()
# sequencer()
main()
Markdown is supported
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