Exemple #1
0
def main():

    from DIRAC.Core.Base import Script

    Script.registerSwitch("I:", "infile=", "Input file", setInfile)
    Script.registerSwitch("O:", "outfile=", "Output file", setOutfile)
    Script.registerSwitch("T:", "tellist=", "Configuration file",
                          setConfigfile)
    Script.registerSwitch("V:", "version=", "HAP Version", setVersion)

    Script.parseCommandLine(ignoreErrors=True)

    if infile == None or outfile == None or configfile == None or version == None:
        Script.showHelp()
        DIRAC.exit(-1)

    DIRAC.gLogger.notice('Executing a Hap Application')

    from CTADIRAC.Core.Workflow.Modules.HapApplication import HapApplication
    from CTADIRAC.Core.Utilities.SoftwareInstallation import checkSoftwarePackage
    from CTADIRAC.Core.Utilities.SoftwareInstallation import installSoftwarePackage
    from CTADIRAC.Core.Utilities.SoftwareInstallation import getSoftwareEnviron
    from CTADIRAC.Core.Utilities.SoftwareInstallation import localArea
    from CTADIRAC.Core.Utilities.SoftwareInstallation import sharedArea

    ha = HapApplication()

    HapPack = 'HAP/' + version + '/HAP'

    packs = ['HESS/v0.1/lib', 'HESS/v0.1/root', HapPack]

    for package in packs:
        DIRAC.gLogger.notice('Checking:', package)
        if sharedArea:
            if checkSoftwarePackage(package, sharedArea())['OK']:
                DIRAC.gLogger.notice('Package found in Shared Area:', package)
                continue
        if localArea:
            if checkSoftwarePackage(package, localArea())['OK']:
                DIRAC.gLogger.notice('Package found in Local Area:', package)
                continue
            if installSoftwarePackage(package, localArea())['OK']:
                continue
        DIRAC.gLogger.error('Check Failed for software package:', package)
        return DIRAC.S_ERROR('%s not available' % package)

    ha.setSoftwarePackage(HapPack)

    ha.hapArguments = ['-file', infile, '-o', outfile, '-tellist', configfile]

    res = ha.execute()

    if not res['OK']:
        DIRAC.exit(-1)

    DIRAC.exit()
Exemple #2
0
def install_CorsikaSimtelPack(version, build_dir):

    from CTADIRAC.Core.Utilities.SoftwareInstallation import checkSoftwarePackage
    from CTADIRAC.Core.Utilities.SoftwareInstallation import installSoftwarePackage
    from CTADIRAC.Core.Utilities.SoftwareInstallation import installSoftwareEnviron
    from CTADIRAC.Core.Utilities.SoftwareInstallation import sharedArea
    from CTADIRAC.Core.Utilities.SoftwareInstallation import workingArea
    from DIRAC.Core.Utilities.Subprocess import systemCall

    packs = [CorsikaSimtelPack]
    for package in packs:
        DIRAC.gLogger.notice('Checking:', package)
        if sharedArea:
            if checkSoftwarePackage(package, sharedArea())['OK']:
                DIRAC.gLogger.notice('Package found in Shared Area:', package)
                installSoftwareEnviron(package, workingArea(), build_dir)
                packageTuple = package.split('/')
                corsika_subdir = os.path.join(sharedArea(), packageTuple[0],
                                              version)
                cmd = 'cp -u -r ' + corsika_subdir + '/* .'
                if (os.system(cmd)):
                    DIRAC.exit(-1)
                continue
        if workingArea:
            print 'workingArea is %s ' % workingArea()
            if installSoftwarePackage(package, workingArea(),
                                      extract=False)['OK']:
                fd = open('run_compile.sh', 'w')
                fd.write("""#! /bin/sh      
current_dir=%s
mkdir sim sim-sc3
(cd sim && tar zxvf ${current_dir}/corsika_simhessarray.tar.gz && ./build_all prod2 qgs2)
(cd sim-sc3 && tar zxvf ${current_dir}/corsika_simhessarray.tar.gz && ./build_all sc3 qgs2)"""
                         % (workingArea()))
                fd.close()
                os.system('chmod u+x run_compile.sh')
                #os.system('cat run_compile.sh')
                cmdTuple = ['./run_compile.sh']
                ret = systemCall(0, cmdTuple, sendOutput)
                if not ret['OK']:
                    DIRAC.gLogger.error('Failed to compile')
                    DIRAC.exit(-1)
                installSoftwareEnviron(package, workingArea(), build_dir)
                continue

        DIRAC.gLogger.error('Software package not correctly installed')
        DIRAC.exit(-1)

    return DIRAC.S_OK
Exemple #3
0
def install_CorsikaSimtelPack(version):

    from CTADIRAC.Core.Utilities.SoftwareInstallation import checkSoftwarePackage
    from CTADIRAC.Core.Utilities.SoftwareInstallation import installSoftwarePackage
    from CTADIRAC.Core.Utilities.SoftwareInstallation import installSoftwareEnviron
    from CTADIRAC.Core.Utilities.SoftwareInstallation import sharedArea
    from CTADIRAC.Core.Utilities.SoftwareInstallation import workingArea
    from DIRAC.Core.Utilities.Subprocess import systemCall

    CorsikaSimtelPack = os.path.join('corsika_simhessarray', version,
                                     'corsika_simhessarray')

    packs = [CorsikaSimtelPack]
    for package in packs:
        DIRAC.gLogger.notice('Checking:', package)
        if sharedArea:
            if checkSoftwarePackage(package, sharedArea())['OK']:
                DIRAC.gLogger.notice('Package found in Shared Area:', package)
                installSoftwareEnviron(package, workingArea())
                packageTuple = package.split('/')
                corsika_subdir = sharedArea(
                ) + '/' + packageTuple[0] + '/' + version
                cmd = 'cp -u -r ' + corsika_subdir + '/* .'
                os.system(cmd)
                continue
        if workingArea:
            if installSoftwarePackage(package, workingArea())['OK']:
                ############## compile #############################
                if 'sc3' in version:
                    compilation_opt = 'sc3'
                else:
                    compilation_opt = 'prod2'

                DIRAC.gLogger.notice('Compiling with option:', compilation_opt)
                cmdTuple = ['./build_all', compilation_opt, 'qgs2']
                ret = systemCall(0, cmdTuple, sendOutput)
                if not ret['OK']:
                    DIRAC.gLogger.error('Failed to execute build')
                    DIRAC.exit(-1)
                continue
        DIRAC.gLogger.error('Check Failed for software package:', package)
        DIRAC.gLogger.error('Software package not available')
        DIRAC.exit(-1)
Exemple #4
0
def main():

    from DIRAC.Core.Base import Script

    #### eventio_cta options ##########################################
    Script.registerSwitch("T:", "tellist=", "Tellist", setTellist)
    Script.registerSwitch("F:", "Nfirst_mcevt=", "Nfirst_mcevt",
                          setNfirst_mcevt)
    Script.registerSwitch("L:", "Nlast_mcevt=", "Nlast_mcevt", setNlast_mcevt)
    ## add other eventio_cta options ################################
    #  Script.registerSwitch( "N:", "num=", "Num", setNum)
    ##  Script.registerSwitch( "L:", "limitmc=", "Limitmc", setLimitmc)
    #  Script.registerSwitch( "S:", "telidoffset=", "Telidoffset", setTelidoffset)
    Script.registerSwitch("P:", "pixelslices=", "setPixelslices (true/false)",
                          setPixelslices)
    Script.registerSwitch("p:", "run_number=",
                          "Run Number (set automatically)", setRunNumber)
    ### other options ###############################################
    Script.registerSwitch("V:", "version=", "HAP version", setVersion)

    Script.parseCommandLine(ignoreErrors=True)

    args = Script.getPositionalArgs()

    if len(args) < 1:
        Script.showHelp()

    if tellist == None or version == None:
        Script.showHelp()
        jobReport.setApplicationStatus('Options badly specified')
        DIRAC.exit(-1)

    from CTADIRAC.Core.Workflow.Modules.HapApplication import HapApplication
    from CTADIRAC.Core.Workflow.Modules.HapRootMacro import HapRootMacro
    from CTADIRAC.Core.Utilities.SoftwareInstallation import checkSoftwarePackage
    from CTADIRAC.Core.Utilities.SoftwareInstallation import installSoftwarePackage
    from CTADIRAC.Core.Utilities.SoftwareInstallation import getSoftwareEnviron
    from CTADIRAC.Core.Utilities.SoftwareInstallation import localArea
    from CTADIRAC.Core.Utilities.SoftwareInstallation import sharedArea
    from DIRAC.Core.Utilities.Subprocess import systemCall
    from DIRAC.WorkloadManagementSystem.Client.JobReport import JobReport

    jobID = os.environ['JOBID']
    jobID = int(jobID)
    jobReport = JobReport(jobID)

    HapPack = 'HAP/' + version + '/HAP'

    packs = ['HESS/v0.2/lib', 'HESS/v0.3/root', HapPack]

    for package in packs:
        DIRAC.gLogger.notice('Checking:', package)
        if sharedArea:
            if checkSoftwarePackage(package, sharedArea())['OK']:
                DIRAC.gLogger.notice('Package found in Shared Area:', package)
                continue
        if localArea:
            if checkSoftwarePackage(package, localArea())['OK']:
                DIRAC.gLogger.notice('Package found in Local Area:', package)
                continue
            if installSoftwarePackage(package, localArea())['OK']:
                continue
        DIRAC.gLogger.error('Check Failed for software package:', package)
        DIRAC.gLogger.error('Software package not available')
        DIRAC.exit(-1)

    telconf = os.path.join(localArea(),
                           'HAP/%s/config/%s' % (version, tellist))

    ha = HapApplication()
    ha.setSoftwarePackage(HapPack)
    ha.hapExecutable = 'eventio_cta'

    fileout = 'raw_' + part_type + '_run' + run_number + '.root'
    infile = build_infile()
    ha.hapArguments = ['-file', infile, '-o', fileout, '-tellist', telconf]

    try:
        ha.hapArguments.extend(
            ['-Nfirst_mcevt', Nfirst_mcevt, '-Nlast_mcevt', Nlast_mcevt])
    except NameError:
        DIRAC.gLogger.info('Nfirst_mcevt/Nlast_mcevt options are not used')

    try:
        if (pixelslices == 'true'):
            ha.hapArguments.extend(['-pixelslices'])
    except NameError:
        DIRAC.gLogger.info('pixelslices option is not used')

    DIRAC.gLogger.notice('Executing Hap Converter Application')
    res = ha.execute()

    if not res['OK']:
        DIRAC.gLogger.error('Failed to execute eventio_cta Application')
        jobReport.setApplicationStatus('eventio_cta: Failed')
        DIRAC.exit(-1)

    if not os.path.isfile(fileout):
        error = 'raw file was not created:'
        DIRAC.gLogger.error(error, fileout)
        jobReport.setApplicationStatus('eventio_cta: RawData not created')
        DIRAC.exit(-1)

###################### Check RAW DATA: step0 #######################
    hr = HapRootMacro()
    hr.setSoftwarePackage(HapPack)

    DIRAC.gLogger.notice('Executing RAW check step0')
    hr.rootMacro = '/hapscripts/dst/Open_Raw.C+'
    outfilestr = '"' + fileout + '"'
    args = [outfilestr]
    DIRAC.gLogger.notice('Open_Raw macro Arguments:', args)
    hr.rootArguments = args
    DIRAC.gLogger.notice('Executing Hap Open_Raw macro')
    res = hr.execute()

    if not res['OK']:
        DIRAC.gLogger.error('Open_Raw: Failed')
        DIRAC.exit(-1)


#####################Check RAW DATA: step1 ##################
    DIRAC.gLogger.notice('Executing Raw Check step1')

    ret = getSoftwareEnviron(HapPack)
    if not ret['OK']:
        error = ret['Message']
        DIRAC.gLogger.error(error, HapPack)
        DIRAC.exit(-1)

    hapEnviron = ret['Value']
    hessroot = hapEnviron['HESSROOT']
    check_script = hessroot + '/hapscripts/dst/check_raw.csh'
    cmdTuple = [check_script]
    ret = systemCall(0, cmdTuple, sendOutput)

    if not ret['OK']:
        DIRAC.gLogger.error('Failed to execute RAW Check step1')
        jobReport.setApplicationStatus('Check_raw: Failed')
        DIRAC.exit(-1)

    status, stdout, stderr = ret['Value']
    if status == 1:
        jobReport.setApplicationStatus(
            'RAW Check step1: Big problem during RAW production')
        DIRAC.gLogger.error('Check_raw: Big problem during RAW production')
        DIRAC.exit(-1)

    DIRAC.exit()
Exemple #5
0
def main():

    from DIRAC.Core.Base import Script

    ### make_CTA_DST options ###############################################
    Script.registerSwitch("T:", "tellist=", "Tellist", setTellist)
    Script.registerSwitch("N:", "nevent=", "Nevent", setNevent)
    Script.registerSwitch("p:", "run_number=",
                          "Run Number (set automatically)", setRunNumber)
    ### other options ###############################################
    Script.registerSwitch("V:", "version=", "HAP version", setVersion)

    Script.parseCommandLine(ignoreErrors=True)

    args = Script.getPositionalArgs()

    if len(args) < 1:
        Script.showHelp()

    if tellist == None or version == None:
        Script.showHelp()
        jobReport.setApplicationStatus('Options badly specified')
        DIRAC.exit(-1)

    from CTADIRAC.Core.Workflow.Modules.HapRootMacro import HapRootMacro
    from CTADIRAC.Core.Utilities.SoftwareInstallation import checkSoftwarePackage
    from CTADIRAC.Core.Utilities.SoftwareInstallation import installSoftwarePackage
    from CTADIRAC.Core.Utilities.SoftwareInstallation import getSoftwareEnviron
    from CTADIRAC.Core.Utilities.SoftwareInstallation import localArea
    from CTADIRAC.Core.Utilities.SoftwareInstallation import sharedArea
    from DIRAC.Core.Utilities.Subprocess import systemCall
    from DIRAC.WorkloadManagementSystem.Client.JobReport import JobReport

    jobID = os.environ['JOBID']
    jobID = int(jobID)
    jobReport = JobReport(jobID)

    HapPack = 'HAP/' + version + '/HAP'

    packs = ['HESS/v0.2/lib', 'HESS/v0.3/root', HapPack]

    for package in packs:
        DIRAC.gLogger.notice('Checking:', package)
        if sharedArea:
            if checkSoftwarePackage(package, sharedArea())['OK']:
                DIRAC.gLogger.notice('Package found in Shared Area:', package)
                continue
        if localArea:
            if checkSoftwarePackage(package, localArea())['OK']:
                DIRAC.gLogger.notice('Package found in Local Area:', package)
                continue
            if installSoftwarePackage(package, localArea())['OK']:
                continue
        DIRAC.gLogger.error('Check Failed for software package:', package)
        DIRAC.gLogger.error('Software package not available')
        DIRAC.exit(-1)

    hr = HapRootMacro()
    hr.setSoftwarePackage(HapPack)

    telconf = os.path.join(localArea(),
                           'HAP/%s/config/%s' % (version, tellist))
    infile = build_infile()
    infilestr = '"' + infile + '"'
    telconfstr = '"' + telconf + '"'
    args = [str(int(run_number)), infilestr, telconfstr]

    try:
        args.extend([nevent])
    except NameError:
        DIRAC.gLogger.info('nevent arg not used')

    DIRAC.gLogger.notice('make_CTA_DST macro Arguments:', args)
    hr.rootMacro = '/hapscripts/dst/make_CTA_DST.C+'
    hr.rootArguments = args
    DIRAC.gLogger.notice('Executing Hap make_CTA_DST macro')
    res = hr.execute()

    if not res['OK']:
        DIRAC.gLogger.error('Failed to execute make_CTA_DST macro')
        jobReport.setApplicationStatus('Failure during make_CTA_DST')
        DIRAC.exit(-1)

############ check existance of output file ####
    filedst = 'dst_CTA_%08d' % int(run_number) + '.root'

    if not os.path.isfile(filedst):
        DIRAC.gLogger.error('dst file not found:', filedst)
        jobReport.setApplicationStatus('make_CTA_DST.C: DST file not created')
        DIRAC.exit(-1)

    fileout = 'dst_' + part_type + '_run' + run_number + '.root'
    cmd = 'mv ' + filedst + ' ' + fileout
    os.system(cmd)

    ###################Check std out #############################
    DIRAC.gLogger.notice('Executing DST Check step0')

    ret = getSoftwareEnviron(HapPack)
    if not ret['OK']:
        error = ret['Message']
        DIRAC.gLogger.error(error, HapPack)
        DIRAC.exit(-1)

    hapEnviron = ret['Value']
    hessroot = hapEnviron['HESSROOT']
    check_script = hessroot + '/hapscripts/dst/check_dst0.csh'
    cmdTuple = [check_script]
    ret = systemCall(0, cmdTuple, sendOutput)

    if not ret['OK']:
        DIRAC.gLogger.error('Failed to execute DST Check step0')
        jobReport.setApplicationStatus('Check_dst0: Failed')
        DIRAC.exit(-1)

    status, stdout, stderr = ret['Value']
    if status == 1:
        jobReport.setApplicationStatus(
            'Check_dst0: Big problem during the DST production')
        DIRAC.gLogger.error(
            'DST Check step0 reports: Big problem during the DST production')
        DIRAC.exit(-1)
    if status == 2:
        jobReport.setApplicationStatus('Check_dst0: No triggered events')
        DIRAC.gLogger.notice('DST Check step0 reports: No triggered events')
        DIRAC.exit()

############# run the CheckDST macro #################
    DIRAC.gLogger.notice('Executing DST check step1')
    hr.rootMacro = '/hapscripts/dst/CheckDST.C+'
    fileoutstr = '"' + fileout + '"'
    args = [fileoutstr]
    DIRAC.gLogger.notice('CheckDST macro Arguments:', args)
    hr.rootArguments = args
    DIRAC.gLogger.notice('Executing Hap CheckDST macro')
    res = hr.execute()

    if not res['OK']:
        DIRAC.gLogger.error('Failure during DST Check step1')
        jobReport.setApplicationStatus('Check_dst1: Failed')
        DIRAC.exit(-1)


#######################Check std out of CheckDST macro ##########################
    DIRAC.gLogger.notice('Executing DST Check step2')
    check_script = hessroot + '/hapscripts/dst/check_dst2.csh'
    cmdTuple = [check_script]
    ret = systemCall(0, cmdTuple, sendOutput)

    if not ret['OK']:
        DIRAC.gLogger.error('Failed to execute DST Check step2')
        jobReport.setApplicationStatus('Check_dst2: Failed')
        DIRAC.exit(-1)

    status, stdout, stderr = ret['Value']
    if status == 1:
        jobReport.setApplicationStatus(
            'DST Check step2: Big problem during the DST production')
        DIRAC.gLogger.error(
            'DST Check step2 reports: Big problem during the DST production')
        DIRAC.exit(-1)
    if status == 2:
        jobReport.setApplicationStatus('DST Check step2: No triggered events')
        DIRAC.gLogger.notice('DST Check step2 reports: No triggered events')
        DIRAC.exit()

    DIRAC.exit()
Exemple #6
0
def main():

    from DIRAC.Core.Base import Script

    Script.registerSwitch("T:", "template=", "Corsika Template")
    Script.registerSwitch("p:", "run_number=",
                          "Do not use: Run Number automatically set")
    Script.registerSwitch("E:", "executable=",
                          "Executable (Use SetExecutable)")
    Script.registerSwitch("v:", "version=", "Version (Use setVersion)")
    Script.registerSwitch("D:", "dcta=", "dcta")
    Script.registerSwitch("I:", "icta=", "icta")
    Script.registerSwitch("C:", "c_cta=", "c_cta")

    Script.parseCommandLine(ignoreErrors=False)

    ## default values ##############
    run_number = None
    template = None
    executable = None
    version = None

    ### set switch values ###
    for switch in Script.getUnprocessedSwitches():
        if switch[0] == "run_number" or switch[0] == "p":
            run_number = switch[1].split('ParametricParameters=')[1]
        elif switch[0] == "template" or switch[0] == "T":
            template = switch[1]
        elif switch[0] == "executable" or switch[0] == "E":
            executable = switch[1]
        elif switch[0] == "version" or switch[0] == "v":
            version = switch[1]

    if version == None or executable == None or run_number == None or template == None:
        Script.showHelp()
        jobReport.setApplicationStatus('Missing options')
        DIRAC.exit(-1)

    from CTADIRAC.Core.Workflow.Modules.CorsikaApp import CorsikaApp
    from CTADIRAC.Core.Utilities.SoftwareInstallation import checkSoftwarePackage
    from CTADIRAC.Core.Utilities.SoftwareInstallation import installSoftwarePackage
    from CTADIRAC.Core.Utilities.SoftwareInstallation import installSoftwareEnviron
    from CTADIRAC.Core.Utilities.SoftwareInstallation import getSoftwareEnviron
    from CTADIRAC.Core.Utilities.SoftwareInstallation import localArea
    from CTADIRAC.Core.Utilities.SoftwareInstallation import sharedArea
    from CTADIRAC.Core.Utilities.SoftwareInstallation import workingArea
    from DIRAC.Core.Utilities.Subprocess import systemCall
    from DIRAC.WorkloadManagementSystem.Client.JobReport import JobReport

    jobID = os.environ['JOBID']
    jobID = int(jobID)
    jobReport = JobReport(jobID)

    CorsikaSimtelPack = 'corsika_simhessarray/' + version + '/corsika_simhessarray'

    packs = [CorsikaSimtelPack]

    for package in packs:
        DIRAC.gLogger.notice('Checking:', package)
        if sharedArea:
            if checkSoftwarePackage(package, sharedArea())['OK']:
                DIRAC.gLogger.notice('Package found in Shared Area:', package)
                installSoftwareEnviron(package, workingArea())
                packageTuple = package.split('/')
                corsika_subdir = sharedArea(
                ) + '/' + packageTuple[0] + '/' + version
                cmd = 'cp -u -r ' + corsika_subdir + '/* .'
                os.system(cmd)
                continue
        if workingArea:
            if checkSoftwarePackage(package, workingArea())['OK']:
                DIRAC.gLogger.notice('Package found in Local Area:', package)
                continue
            if installSoftwarePackage(package, workingArea())['OK']:
                ############## compile #############################
                cmdTuple = ['./build_all', 'prod2', 'qgs2']
                ######### special case for Astri ############################
                if version == 'prod-2_08072014_to':
                    ############## compile #############################
                    fd = open('run_compile.sh', 'w')
                    fd.write("""#! /bin/sh  
source ./build_all prod2 qgs2
#
echo " Let's check that build_all did its work " 
ls -alFsh 
echo "+++++++++++++++++++++++++++++++++++++++++++++++++"
echo " Let's see what files are in the corsika-run directory " 
ls -alFsh ./corsika-run
#
if [ ! -x ./corsika-run/corsika ]
then 
    echo " ERROR: Corsika executable found. Exit " 
    exit 1
fi
echo "+++++++++++++++++++++++++++++++++++++++++++++++++"
#
echo " Now let's try to compile hessio according to Federico's recipe "
cd ./hessioxxx 
make clean 
make EXTRA_DEFINES="-DCTA_PROD2 -DWITH_LOW_GAIN_CHANNEL"
# 
echo " Let's see what files are in the lib directory " 
ls -alFsh ./lib
#
if [ ! -f ./lib/libhessio.so ]
then 
    echo " ERROR: libhessio library not found. Exit " 
    exit 1
fi
echo "+++++++++++++++++++++++++++++++++++++++++++++++++"
#
cd .. # come back to original dir
# 
echo " Now let's try to compile simtel according to Federico's recipe "
cd ./sim_telarray
make clean 
make EXTRA_DEFINES="-DCTA_PROD2 -DWITH_LOW_GAIN_CHANNEL"
make install 
# 
echo " Let's see what files are in the bin directory " 
ls -alFsh ./bin
#
if [ ! -x ./bin/sim_telarray ]
then 
    echo " ERROR: sim_telarray excutable not found. Exit " 
    exit 1
fi
echo "+++++++++++++++++++++++++++++++++++++++++++++++++"
#
echo " Everything was compiled and linked properly" """)
                    fd.close()
                    os.system('chmod u+x run_compile.sh')
                    cmdTuple = ['./run_compile.sh']
##########################################################################
                ret = systemCall(0, cmdTuple, sendOutput)
                if not ret['OK']:
                    DIRAC.gLogger.error('Failed to execute build')
                    DIRAC.exit(-1)
                continue

        DIRAC.gLogger.error('Check Failed for software package:', package)
        DIRAC.gLogger.error('Software package not available')
        DIRAC.exit(-1)

###### execute corsika ###############
    cs = CorsikaApp()
    cs.setSoftwarePackage(CorsikaSimtelPack)
    cs.csExe = executable
    cs.csArguments = ['--run-number', run_number, '--run', 'corsika', template]
    corsikaReturnCode = cs.execute()

    if corsikaReturnCode != 0:
        DIRAC.gLogger.error('Failed to execute corsika Application')
        jobReport.setApplicationStatus('Corsika Application: Failed')
        DIRAC.exit(-1)

###### rename corsika file #################################
    rundir = 'run' + run_number
    corsikaKEYWORDS = ['TELFIL']
    dictCorsikaKW = fileToKWDict(template, corsikaKEYWORDS)
    corsikafilename = rundir + '/' + dictCorsikaKW['TELFIL'][0]
    destcorsikafilename = 'corsika_run' + run_number + '.corsika.gz'
    cmd = 'mv ' + corsikafilename + ' ' + destcorsikafilename
    os.system(cmd)

    ### create corsika tar ####################
    corsika_tar = 'corsika_run' + run_number + '.tar.gz'
    filetar1 = rundir + '/' + 'input'
    filetar2 = rundir + '/' + 'DAT' + run_number + '.dbase'
    filetar3 = rundir + '/run' + str(int(run_number)) + '.log'
    cmdTuple = ['/bin/tar', 'zcf', corsika_tar, filetar1, filetar2, filetar3]
    DIRAC.gLogger.notice('Executing command tuple:', cmdTuple)
    ret = systemCall(0, cmdTuple, sendOutput)
    if not ret['OK']:
        DIRAC.gLogger.error('Failed to execute tar')
        DIRAC.exit(-1)

###### execute sim_telarray ###############
    ret = getSoftwareEnviron(CorsikaSimtelPack)
    if not ret['OK']:
        error = ret['Message']
        DIRAC.gLogger.error(error, CorsikaSimtelPack)
        DIRAC.exit(-1)

    corsikaEnviron = ret['Value']
    cmdTuple = ['sim_telarray']
    # add input file argument for sim_telarray  ###################
    inputfile = 'input_file=' + destcorsikafilename
    inputfileopt = ['-C', inputfile]
    cmdTuple.extend(inputfileopt)
    # add output file argument for sim_telarray
    destsimtelfilename = 'simtel_run' + run_number + '.simtel.gz'
    outputfile = 'output_file=' + destsimtelfilename
    outputfileopt = ['-C', outputfile]
    cmdTuple.extend(outputfileopt)
    # add histo argument for sim_telarray
    desthistofilename = 'simtel_run' + run_number + '.hdata.gz'
    histofile = 'histogram_file=' + desthistofilename
    histofileopt = ['-C', histofile]
    cmdTuple.extend(histofileopt)

    # add other arguments for sim_telarray specified by user ######
    simtelparfile = open('simtel.par', 'r').readlines()

    for line in simtelparfile:
        for word in line.split():
            cmdTuple.append(word)

    DIRAC.gLogger.notice('Executing command tuple:', cmdTuple)
    ret = systemCall(0, cmdTuple, sendSimtelOutput, env=corsikaEnviron)

    if not ret['OK']:
        DIRAC.gLogger.error('Failed to execute:', simexe)
        DIRAC.exit(-1)

    DIRAC.exit()
Exemple #7
0
def main():

    from DIRAC import gLogger
    from DIRAC.Core.Base import Script
    Script.parseCommandLine()

    from CTADIRAC.Core.Utilities.SoftwareInstallation import checkSoftwarePackage
    from CTADIRAC.Core.Utilities.SoftwareInstallation import installSoftwarePackage
    from CTADIRAC.Core.Utilities.SoftwareInstallation import installSoftwareEnviron
    from CTADIRAC.Core.Utilities.SoftwareInstallation import sharedArea
    from CTADIRAC.Core.Utilities.SoftwareInstallation import workingArea
    from CTADIRAC.Core.Utilities.SoftwareInstallation import createSharedArea
    from DIRAC.Core.Utilities.Subprocess import systemCall

    DIRAC.gLogger.notice('Platform is:')

    os.system('dirac-platform')

    args = Script.getPositionalArgs()
    version = args[0]

    area = sharedArea()

    if area:
        gLogger.notice('Using Shared Area at:', area)
        # if defined, check that it really exists
        if not os.path.isdir(area):
            gLogger.error('Missing Shared Area Directory:', area)
            if createSharedArea() == True:
                gLogger.notice('Shared Area created')
            else:
                gLogger.error('Failed to create Shared Area Directory:', area)
                DIRAC.exit(-1)
    else:
        if createSharedArea() == True:
            gLogger.notice('Shared Area created')
        else:
            gLogger.error('Failed to create Shared Area Directory:', area)
            DIRAC.exit(-1)

    ctoolsPack = os.path.join('ctools', version, 'ctools')

    packs = [ctoolsPack]

    for package in packs:
        DIRAC.gLogger.notice('Checking:', package)
        packageTuple = package.split('/')
        if sharedArea:
            if checkSoftwarePackage(package, sharedArea())['OK']:
                DIRAC.gLogger.notice('Package found in Shared Area:', package)
                continue
            if installSoftwarePackage(package, sharedArea())['OK']:

                if not os.path.isdir(
                        os.path.join(sharedArea(), packageTuple[0],
                                     packageTuple[1])):
                    DIRAC.gLogger.error(
                        'Software package missing in the shared area')
                    DIRAC.exit(-1)

                continue

        DIRAC.gLogger.error('Software package not correctly installed')
        DIRAC.exit(-1)

    DIRAC.exit()
Exemple #8
0
def install_CorsikaSimtelPack(version):

    from CTADIRAC.Core.Utilities.SoftwareInstallation import checkSoftwarePackage
    from CTADIRAC.Core.Utilities.SoftwareInstallation import installSoftwarePackage
    from CTADIRAC.Core.Utilities.SoftwareInstallation import installSoftwareEnviron
    from CTADIRAC.Core.Utilities.SoftwareInstallation import sharedArea
    from CTADIRAC.Core.Utilities.SoftwareInstallation import workingArea
    from DIRAC.Core.Utilities.Subprocess import systemCall

    CorsikaSimtelPack = 'corsika_simhessarray/' + version + '/corsika_simhessarray'
    packs = [CorsikaSimtelPack]
    for package in packs:
        DIRAC.gLogger.notice('Checking:', package)
        if sharedArea:
            if checkSoftwarePackage(package, sharedArea())['OK']:
                DIRAC.gLogger.notice('Package found in Shared Area:', package)
                installSoftwareEnviron(package, workingArea())
                packageTuple = package.split('/')
                corsika_subdir = sharedArea(
                ) + '/' + packageTuple[0] + '/' + version
                cmd = 'cp -u -r ' + corsika_subdir + '/* .'
                os.system(cmd)
                continue
        if workingArea:
            if checkSoftwarePackage(package, workingArea())['OK']:
                DIRAC.gLogger.notice('Package found in Local Area:', package)
                continue
            if installSoftwarePackage(package, workingArea())['OK']:
                ############## compile #############################
                if version == 'prod-2_22072013_tox':
                    ############### compile tox ################
                    fd = open('run_compile.sh', 'w')
                    fd.write("""#! /bin/sh  
./build_all prod2 qgs2

# If the code was already there, we just clean but do not remove it.                                 
if [ -d "hessioxxx" ]; then
   (cd hessioxxx && make clean && make EXTRA_DEFINES='-DH_MAX_TEL=55 -DH_MAX_PIX=1984 -DH_MAX_SECTORS=13100 -DNO_LOW_GAIN')
fi

# If the code was already there, we just clean but do not remove it.                                 
if [ -d "sim_telarray" ]; then
   (cd sim_telarray && make clean && make EXTRA_DEFINES='-DH_MAX_TEL=55 -DH_MAX_PIX=1984 -DH_MAX_SECTORS=13100 -DNO_LOW_GAIN' install)
fi""")
                    fd.close()
                    os.system('chmod u+x run_compile.sh')
                    cmdTuple = ['./run_compile.sh']


##########################################
                else:
                    cmdTuple = ['./build_all', 'prod2', 'qgs2']

                ret = systemCall(0, cmdTuple, sendOutput)
                if not ret['OK']:
                    DIRAC.gLogger.error('Failed to execute build')
                    DIRAC.exit(-1)
                continue
        DIRAC.gLogger.error('Check Failed for software package:', package)
        DIRAC.gLogger.error('Software package not available')
        DIRAC.exit(-1)
Exemple #9
0
def main():

    from DIRAC.Core.Base import Script
    ### DoCtaIrf options ##########################################################
    Script.registerSwitch("A:", "analysis=", "Analysis Type", setAnalysisType)
    Script.registerSwitch("C:", "cuts=", "Cuts Config", setCutsConfig)
    Script.registerSwitch("R:", "runlist=", "Runlist", setRunlist)
    Script.registerSwitch("Z:", "zenith=", "Zenith", setZenith)
    Script.registerSwitch("O:", "offset=", "Offset", setOffset)
    Script.registerSwitch("M:", "energy=", "Energy Method", setEnergyMethod)
    Script.registerSwitch("T:", "arrayconfig=", "Array Configuration",
                          setArrayConfig)
    Script.registerSwitch("P:", "particle=", "Particle Type", setParticleType)
    ## other options
    Script.registerSwitch("V:", "version=", "HAP version", setVersion)

    Script.parseCommandLine(ignoreErrors=True)

    args = Script.getPositionalArgs()
    if len(args) < 1:
        Script.showHelp()

    from CTADIRAC.Core.Workflow.Modules.HapApplication import HapApplication
    from CTADIRAC.Core.Workflow.Modules.HapRootMacro import HapRootMacro
    from CTADIRAC.Core.Utilities.SoftwareInstallation import checkSoftwarePackage
    from CTADIRAC.Core.Utilities.SoftwareInstallation import installSoftwarePackage
    from CTADIRAC.Core.Utilities.SoftwareInstallation import getSoftwareEnviron
    from CTADIRAC.Core.Utilities.SoftwareInstallation import localArea
    from CTADIRAC.Core.Utilities.SoftwareInstallation import sharedArea
    from DIRAC.Core.Utilities.Subprocess import systemCall
    from DIRAC.WorkloadManagementSystem.Client.JobReport import JobReport

    jobID = os.environ['JOBID']
    jobID = int(jobID)
    jobReport = JobReport(jobID)

    ha = HapApplication()

    HapPack = 'HAP/' + version + '/HAP'

    packs = ['HESS/v0.2/lib', 'HESS/v0.3/root', HapPack]

    for package in packs:
        DIRAC.gLogger.notice('Checking:', package)
        if sharedArea:
            if checkSoftwarePackage(package, sharedArea())['OK']:
                DIRAC.gLogger.notice('Package found in Shared Area:', package)
                continue
        if localArea:
            if checkSoftwarePackage(package, localArea())['OK']:
                DIRAC.gLogger.notice('Package found in Local Area:', package)
                continue
            if installSoftwarePackage(package, localArea())['OK']:
                continue
        DIRAC.gLogger.error('Check Failed for software package:', package)
        DIRAC.gLogger.error('Software package not available')
        DIRAC.exit(-1)

    ha.setSoftwarePackage(HapPack)

    ha.hapExecutable = 'DoCtaIrf'

    runlistdir = os.environ['PWD']

    build_infile(runlist)

    ha.hapArguments = [
        analysistype, cutsconfig, runlistdir, runlist, zenith, offset,
        arrayconfig, energymethod, particle
    ]

    DIRAC.gLogger.notice('Executing Hap Application')
    res = ha.execute()

    if not res['OK']:
        DIRAC.gLogger.error('Failed to execute Hap Application')
        jobReport.setApplicationStatus('Hap Application: Failed')
        DIRAC.exit(-1)

###################### Check TTree Output File #######################
    outfile = 'MVAFile_' + runlist + ".root"

    if not os.path.isfile(outfile):
        error = 'TTree file was not created:'
        DIRAC.gLogger.error(error, outfile)
        jobReport.setApplicationStatus('DoCtaIrf: TTree file not created')
        DIRAC.exit(-1)

###################### Quality Check for TTree Output File: step0######################
    hr = HapRootMacro()
    hr.setSoftwarePackage(HapPack)

    DIRAC.gLogger.notice('Executing TTree check step0')
    hr.rootMacro = '/hapscripts/mva/Open_TT.C+'
    outfilestr = '"' + outfile + '"'
    args = [outfilestr]
    DIRAC.gLogger.notice('Open_TT macro Arguments:', args)
    hr.rootArguments = args
    DIRAC.gLogger.notice('Executing Hap Open_TT macro')
    res = hr.execute()

    if not res['OK']:
        DIRAC.gLogger.error('Open_TT: Failed')
        DIRAC.exit(-1)

#########################Quality Check for TTree Output File: step1####################
    DIRAC.gLogger.notice('Executing TTree check step1')

    ret = getSoftwareEnviron(HapPack)
    if not ret['OK']:
        error = ret['Message']
        DIRAC.gLogger.error(error, HapPack)
        DIRAC.exit(-1)

    hapEnviron = ret['Value']
    hessroot = hapEnviron['HESSROOT']

    check_script = hessroot + '/hapscripts/mva/check_TT.csh'

    cmdTuple = [check_script]
    ret = systemCall(0, cmdTuple, sendOutput)

    if not ret['OK']:
        DIRAC.gLogger.error('Failed to execute TTree Check step1')
        jobReport.setApplicationStatus('Check_TTree: Failed')
        DIRAC.exit(-1)


#############################################

    DIRAC.exit()
Exemple #10
0
def main():

    from DIRAC.Core.Base import Script
    Script.initialize()

    DIRAC.gLogger.notice('Platform is:')
    os.system('dirac-platform')
    from DIRAC.DataManagementSystem.Client.DataManager import DataManager
    from CTADIRAC.Core.Workflow.Modules.EvnDispApp import EvnDispApp
    from CTADIRAC.Core.Utilities.SoftwareInstallation import checkSoftwarePackage
    from CTADIRAC.Core.Utilities.SoftwareInstallation import installSoftwarePackage
    from CTADIRAC.Core.Utilities.SoftwareInstallation import installSoftwareEnviron
    from CTADIRAC.Core.Utilities.SoftwareInstallation import sharedArea
    from CTADIRAC.Core.Utilities.SoftwareInstallation import workingArea
    from DIRAC.Core.Utilities.Subprocess import systemCall
    from DIRAC.WorkloadManagementSystem.Client.JobReport import JobReport

    jobID = os.environ['JOBID']
    jobID = int(jobID)
    jobReport = JobReport(jobID)

    version = sys.argv[3]
    DIRAC.gLogger.notice('Version:', version)

    EvnDispPack = os.path.join('evndisplay', version, 'evndisplay')

    packs = [EvnDispPack]

    for package in packs:
        DIRAC.gLogger.notice('Checking:', package)
        if checkSoftwarePackage(package, sharedArea())['OK']:
            DIRAC.gLogger.notice('Package found in Shared Area:', package)
            installSoftwareEnviron(package, sharedArea())
            continue
        else:
            installSoftwarePackage(package, workingArea())
            DIRAC.gLogger.notice('Package found in workingArea:', package)
            continue

        DIRAC.gLogger.error('Check Failed for software package:', package)
        DIRAC.gLogger.error('Software package not available')
        DIRAC.exit(-1)

    ed = EvnDispApp()
    ed.setSoftwarePackage(EvnDispPack)

    dstFileLFNList = sys.argv[-1].split('ParametricParameters={')[1].split(
        '}')[0].replace(',', ' ')

    args = []
    i = 0
    for word in dstFileLFNList.split():
        i = i + 1
        dstfile = os.path.basename(word)
        ###### execute evndisplay stage1 ###############
        executable = sys.argv[5]
        logfileName = executable + '_' + str(i) + '.log'
        args = ['-sourcefile', dstfile, '-outputdirectory', 'outdir']
        # add other arguments for evndisp specified by user ######
        evndispparfile = open('evndisp.par', 'r').readlines()
        for line in evndispparfile:
            for word in line.split():
                args.append(word)

        execute_module(ed, executable, args)

        for name in glob.glob('outdir/*.root'):
            evndispOutFile = name.split('.root')[0] + '_' + str(
                jobID) + '_evndisp.root'
            cmd = 'mv ' + name + ' ' + os.path.basename(evndispOutFile)
            if (os.system(cmd)):
                DIRAC.exit(-1)

########### quality check on Log #############################################
        cmd = 'mv ' + executable + '.log' + ' ' + logfileName
        if (os.system(cmd)):
            DIRAC.exit(-1)
        fd = open('check_log.sh', 'w')
        fd.write("""#! /bin/sh
if grep -i "error" %s; then
exit 1
fi
if grep "Final checks on result file (seems to be OK):" %s; then
exit 0
else
exit 1
fi
""" % (logfileName, logfileName))
        fd.close()

        os.system('chmod u+x check_log.sh')
        cmd = './check_log.sh'
        DIRAC.gLogger.notice('Executing system call:', cmd)
        if (os.system(cmd)):
            jobReport.setApplicationStatus('EvnDisp Log Check Failed')
            DIRAC.exit(-1)


##################################################################
########### remove the dst file #############################################
        cmd = 'rm ' + dstfile
        if (os.system(cmd)):
            DIRAC.exit(-1)

    DIRAC.exit()
Exemple #11
0
def main():

    from DIRAC.Core.Base import Script
    ### DoCtaIrf options ##########################################################
    Script.registerSwitch("A:", "analysis=", "Analysis Type", setAnalysisType)
    Script.registerSwitch("C:", "cuts=", "Cuts Config", setCutsConfig)
    Script.registerSwitch("R:", "runlist=", "Runlist", setRunlist)
    Script.registerSwitch("Z:", "zenith=", "Zenith", setZenith)
    Script.registerSwitch("O:", "offset=", "Offset", setOffset)
    Script.registerSwitch("M:", "energy=", "Energy Method", setEnergyMethod)
    Script.registerSwitch("T:", "arrayconfig=", "Array Configuration",
                          setArrayConfig)
    Script.registerSwitch("P:", "particle=", "Particle Type", setParticleType)
    ## other options
    Script.registerSwitch("V:", "version=", "HAP version", setVersion)

    Script.parseCommandLine(ignoreErrors=True)

    args = Script.getPositionalArgs()
    if len(args) < 1:
        Script.showHelp()

    from CTADIRAC.Core.Workflow.Modules.HapApplication import HapApplication
    from CTADIRAC.Core.Utilities.SoftwareInstallation import checkSoftwarePackage
    from CTADIRAC.Core.Utilities.SoftwareInstallation import installSoftwarePackage
    from CTADIRAC.Core.Utilities.SoftwareInstallation import getSoftwareEnviron
    from CTADIRAC.Core.Utilities.SoftwareInstallation import localArea
    from CTADIRAC.Core.Utilities.SoftwareInstallation import sharedArea
    from DIRAC.Core.Utilities.Subprocess import systemCall
    from DIRAC.WorkloadManagementSystem.Client.JobReport import JobReport

    jobID = os.environ['JOBID']
    jobID = int(jobID)
    jobReport = JobReport(jobID)

    ha = HapApplication()

    HapPack = 'HAP/' + version + '/HAP'

    packs = ['HESS/v0.2/lib', 'HESS/v0.3/root', HapPack]

    for package in packs:
        DIRAC.gLogger.notice('Checking:', package)
        if sharedArea:
            if checkSoftwarePackage(package, sharedArea())['OK']:
                DIRAC.gLogger.notice('Package found in Shared Area:', package)
                continue
        if localArea:
            if checkSoftwarePackage(package, localArea())['OK']:
                DIRAC.gLogger.notice('Package found in Local Area:', package)
                continue
            if installSoftwarePackage(package, localArea())['OK']:
                continue
        DIRAC.gLogger.error('Check Failed for software package:', package)
        DIRAC.gLogger.error('Software package not available')
        DIRAC.exit(-1)

    ha.setSoftwarePackage(HapPack)

    ha.hapExecutable = 'DoCtaIrf'

    runlistdir = os.environ['PWD']

    build_infile(runlist)

    ha.hapArguments = [
        analysistype, cutsconfig, runlistdir, runlist, zenith, offset,
        arrayconfig, energymethod, particle
    ]

    DIRAC.gLogger.notice('Executing Hap Application')
    res = ha.execute()

    if not res['OK']:
        DIRAC.gLogger.error('Failed to execute Hap Application')
        jobReport.setApplicationStatus('Hap Application: Failed')
        DIRAC.exit(-1)

    DIRAC.exit()
Exemple #12
0
def main():

    from DIRAC import gLogger
    from DIRAC.Core.Base import Script
    Script.parseCommandLine(ignoreErrors=True)

    from CTADIRAC.Core.Utilities.SoftwareInstallation import checkSoftwarePackage
    from CTADIRAC.Core.Utilities.SoftwareInstallation import installSoftwarePackage
    from CTADIRAC.Core.Utilities.SoftwareInstallation import installSoftwareEnviron
    from CTADIRAC.Core.Utilities.SoftwareInstallation import localArea
    from CTADIRAC.Core.Utilities.SoftwareInstallation import sharedArea
    from CTADIRAC.Core.Utilities.SoftwareInstallation import getSoftwareEnviron
    from CTADIRAC.Core.Utilities.SoftwareInstallation import workingArea
    from DIRAC.Core.Utilities.Subprocess import systemCall

    args = Script.getPositionalArgs()
    version = args[0]
    CorsikaSimtelPack = 'corsika_simhessarray/' + version + '/corsika_simhessarray'

    packs = [CorsikaSimtelPack]

    for package in packs:
        DIRAC.gLogger.notice('Checking:', package)
        if sharedArea:
            if checkSoftwarePackage(package, sharedArea())['OK']:
                DIRAC.gLogger.notice('Package found in Shared Area:', package)
                installSoftwareEnviron(package, workingArea())
                packageTuple = package.split('/')
                corsika_subdir = sharedArea(
                ) + '/' + packageTuple[0] + '/' + version
                cmd = 'cp -u -r ' + corsika_subdir + '/* .'
                os.system(cmd)
                continue
        if workingArea:
            if checkSoftwarePackage(package, workingArea())['OK']:
                DIRAC.gLogger.notice('Package found in Local Area:', package)
                continue
            if installSoftwarePackage(package, workingArea())['OK']:
                ############## compile #############################
                if version == 'clean_23012012':
                    cmdTuple = ['./build_all', 'ultra', 'qgs2']
                elif version in [
                        'prod-2_21122012', 'prod-2_08032013', 'prod-2_06052013'
                ]:
                    cmdTuple = ['./build_all', 'prod2', 'qgs2']
                ret = systemCall(0, cmdTuple, sendOutput)
                if not ret['OK']:
                    DIRAC.gLogger.error('Failed to compile')
                    DIRAC.exit(-1)
                continue

        DIRAC.gLogger.error('Check Failed for software package:', package)
        DIRAC.gLogger.error('Software package not available')
        DIRAC.exit(-1)

    ret = getSoftwareEnviron(CorsikaSimtelPack)
    if not ret['OK']:
        error = ret['Message']
        DIRAC.gLogger.error(error, CorsikaSimtelPack)
        DIRAC.exit(-1)

    corsikaEnviron = ret['Value']

    executable_file = args[1]
    cmd = 'chmod u+x ' + executable_file
    os.system(cmd)

    cmdTuple = args[1:]

    DIRAC.gLogger.notice('Executing command tuple:', cmdTuple)
    ret = systemCall(0, cmdTuple, sendOutput, env=corsikaEnviron)

    if not ret['OK']:
        DIRAC.gLogger.error('Failed to execute read_hess:', ret['Message'])
        DIRAC.exit(-1)

    status, stdout, stderr = ret['Value']
    if status:
        DIRAC.gLogger.error('read_hess execution reports Error:', status)
        DIRAC.gLogger.error(stdout)
        DIRAC.gLogger.error(stderr)
        DIRAC.exit(-1)

    DIRAC.exit()
Exemple #13
0
def main():

  from DIRAC.Core.Base import Script

  Script.registerSwitch( "p:", "run_number=", "Run Number", setRunNumber )
  Script.registerSwitch( "R:", "run=", "Run", setRun )
  Script.registerSwitch( "P:", "config_path=", "Config Path", setConfigPath )
  Script.registerSwitch( "T:", "template=", "Template", setTemplate )
  Script.registerSwitch( "E:", "executable=", "Executable", setExecutable )
  Script.registerSwitch( "V:", "version=", "Version", setVersion )
  Script.registerSwitch( "M:", "mode=", "Mode", setMode )
  
  Script.parseCommandLine( ignoreErrors = True )
  args = Script.getPositionalArgs()

  if len( args ) < 1:
    Script.showHelp()
  
  if version == None or executable == None or run_number == None or run == None or template == None:
    Script.showHelp()
    jobReport.setApplicationStatus('Options badly specified')
    DIRAC.exit( -1 )

  from CTADIRAC.Core.Workflow.Modules.CorsikaApp import CorsikaApp
  from CTADIRAC.Core.Utilities.SoftwareInstallation import checkSoftwarePackage
  from CTADIRAC.Core.Utilities.SoftwareInstallation import installSoftwarePackage
  from CTADIRAC.Core.Utilities.SoftwareInstallation import installSoftwareEnviron
  from CTADIRAC.Core.Utilities.SoftwareInstallation import localArea
  from CTADIRAC.Core.Utilities.SoftwareInstallation import sharedArea
  from CTADIRAC.Core.Utilities.SoftwareInstallation import workingArea
  from DIRAC.Core.Utilities.Subprocess import systemCall
  from DIRAC.WorkloadManagementSystem.Client.JobReport import JobReport

  jobID = os.environ['JOBID']
  jobID = int( jobID )
  jobReport = JobReport( jobID )

  CorsikaSimtelPack = 'corsika_simhessarray/' + version + '/corsika_simhessarray'

  packs = [CorsikaSimtelPack]

  for package in packs:
    DIRAC.gLogger.notice( 'Checking:', package )
    if sharedArea:
      if checkSoftwarePackage( package, sharedArea() )['OK']:
        DIRAC.gLogger.notice( 'Package found in Shared Area:', package )
        installSoftwareEnviron( package, workingArea() )
        packageTuple =  package.split('/')
        corsika_subdir = sharedArea() + '/' + packageTuple[0] + '/' + version
        cmd = 'cp -r ' + corsika_subdir + '/* .'        
        os.system(cmd)
        continue
    if workingArea:
      if checkSoftwarePackage( package, workingArea() )['OK']:
        DIRAC.gLogger.notice( 'Package found in Local Area:', package )
        continue
      if installSoftwarePackage( package, workingArea() )['OK']:
      ############## compile #############################
        if version == 'clean_23012012':
          cmdTuple = ['./build_all','ultra','qgs2']
        elif version in ['prod-2_21122012','prod-2_08032013','prod-2_06052013']:
          cmdTuple = ['./build_all','prod2','qgs2']
        ret = systemCall( 0, cmdTuple, sendOutput)
        if not ret['OK']:
          DIRAC.gLogger.error( 'Failed to execute build')
          DIRAC.exit( -1 )
        continue

    DIRAC.gLogger.error( 'Check Failed for software package:', package )
    DIRAC.gLogger.error( 'Software package not available')
    DIRAC.exit( -1 )  


  cs = CorsikaApp()

  cs.setSoftwarePackage(CorsikaSimtelPack)

  cs.csExe = executable

  cs.csArguments = ['--run-number',run_number,'--run',run,template]

  corsikaReturnCode = cs.execute()
  
  if corsikaReturnCode != 0:
    DIRAC.gLogger.error( 'Failed to execute corsika Application')
    jobReport.setApplicationStatus('Corsika Application: Failed')
    DIRAC.exit( -1 )
    
###### rename corsika file #################################
  rundir = 'run' + run_number
  corsikaKEYWORDS = ['TELFIL']
  dictCorsikaKW = fileToKWDict(template,corsikaKEYWORDS)
  corsikafilename = rundir + '/' + dictCorsikaKW['TELFIL'][0]
  destcorsikafilename = 'corsika_run' + run_number + '.corsika.gz'
  cmd = 'mv ' + corsikafilename + ' ' + destcorsikafilename
  os.system(cmd)
 
  ### create corsika tar ####################
  corsika_tar = 'corsika_run' + run_number + '.tar.gz'
  filetar1 = rundir + '/'+'input'
  filetar2 = rundir + '/'+ 'DAT' + run_number + '.dbase'
  filetar3 = rundir + '/run' + str(int(run_number)) + '.log'
  cmdTuple = ['/bin/tar','zcf',corsika_tar, filetar1,filetar2,filetar3]
  DIRAC.gLogger.notice( 'Executing command tuple:', cmdTuple )
  ret = systemCall( 0, cmdTuple, sendOutput)
  if not ret['OK']:
    DIRAC.gLogger.error( 'Failed to execute tar')
    DIRAC.exit( -1 )
    
  DIRAC.exit()
Exemple #14
0
def main():

    from DIRAC.Core.Base import Script

    Script.registerSwitch("p:", "inputfile=", "Input File", setInputFile)
    Script.registerSwitch("E:", "simtelExecName=", "SimtelExecName",
                          setExecutable)
    Script.registerSwitch("S:", "simtelConfig=", "SimtelConfig", setConfig)
    Script.registerSwitch("V:", "version=", "Version", setVersion)
    Script.registerSwitch("D:", "storage_element=", "Storage Element",
                          setStorageElement)

    from DIRAC.Resources.Catalog.FileCatalogClient import FileCatalogClient
    from DIRAC.Resources.Catalog.FileCatalog import FileCatalog

    Script.parseCommandLine()
    DIRAC.gLogger.setLevel('INFO')

    global fcc, fcL, storage_element

    from CTADIRAC.Core.Utilities.SoftwareInstallation import checkSoftwarePackage
    from CTADIRAC.Core.Utilities.SoftwareInstallation import installSoftwarePackage
    from CTADIRAC.Core.Utilities.SoftwareInstallation import installSoftwareEnviron
    from CTADIRAC.Core.Utilities.SoftwareInstallation import localArea
    from CTADIRAC.Core.Utilities.SoftwareInstallation import sharedArea
    from CTADIRAC.Core.Utilities.SoftwareInstallation import workingArea
    from DIRAC.Core.Utilities.Subprocess import systemCall
    from DIRAC.WorkloadManagementSystem.Client.JobReport import JobReport

    jobID = os.environ['JOBID']
    jobID = int(jobID)
    jobReport = JobReport(jobID)

    CorsikaSimtelPack = 'corsika_simhessarray/' + version + '/corsika_simhessarray'

    packs = [CorsikaSimtelPack]

    for package in packs:
        DIRAC.gLogger.notice('Checking:', package)
        if sharedArea:
            if checkSoftwarePackage(package, sharedArea())['OK']:
                DIRAC.gLogger.notice('Package found in Shared Area:', package)
                installSoftwareEnviron(package, workingArea())
                packageTuple = package.split('/')
                corsika_subdir = sharedArea(
                ) + '/' + packageTuple[0] + '/' + version
                cmd = 'cp -u -r ' + corsika_subdir + '/* .'
                os.system(cmd)
                continue

        DIRAC.gLogger.error('Check Failed for software package:', package)
        DIRAC.gLogger.error('Software package not available')
        DIRAC.exit(-1)

###########
## Checking MD coherence
    fc = FileCatalog('LcgFileCatalog')
    res = fc._getCatalogConfigDetails('DIRACFileCatalog')
    print 'DFC CatalogConfigDetails:', res
    res = fc._getCatalogConfigDetails('LcgFileCatalog')
    print 'LCG CatalogConfigDetails:', res

    fcc = FileCatalogClient()
    fcL = FileCatalog('LcgFileCatalog')

    from DIRAC.Interfaces.API.Dirac import Dirac
    dirac = Dirac()
    ############################

    #############
    # CLAUDIA: simtelConfigFile should be built from ???
    #simtelConfigFilesPath = 'sim_telarray/multi'
    #simtelConfigFile = simtelConfigFilesPath + '/multi_cta-ultra5.cfg'
    #createGlobalsFromConfigFiles(simtelConfigFile)
    createGlobalsFromConfigFiles()
    #######################
    ## files spread in 1000-runs subDirectories

    corsikaFileName = os.path.basename(corsikaFileLFN)
    run_number = corsikaFileName.split('run')[1].split('.corsika.gz')[
        0]  # run001412.corsika.gz

    runNum = int(run_number)
    subRunNumber = '%03d' % runNum
    runNumModMille = runNum % 1000
    runNumTrunc = (runNum - runNumModMille) / 1000
    runNumSeriesDir = '%03dxxx' % runNumTrunc
    print 'runNumSeriesDir=', runNumSeriesDir

    f = open('DISABLE_WATCHDOG_CPU_WALLCLOCK_CHECK', 'w')
    f.close()

    ##### If storage element is IN2P3-tape save simtel file on disk ###############
    if storage_element == 'CC-IN2P3-Tape':
        storage_element = 'CC-IN2P3-Disk'

############ Producing SimTel File
######################Building simtel Directory Metadata #######################

    resultCreateSimtelDirMD = createSimtelFileSystAndMD()
    if not resultCreateSimtelDirMD['OK']:
        DIRAC.gLogger.error('Failed to create simtelArray Directory MD')
        jobReport.setApplicationStatus(
            'Failed to create simtelArray Directory MD')
        DIRAC.gLogger.error(
            'Metadata coherence problem, no simtelArray File produced')
        DIRAC.exit(-1)
    else:
        print 'simtel Directory MD successfully created'

#### execute simtelarray ################
#  fd = open('run_sim.sh', 'w' )
#  fd.write( """#! /bin/sh
#echo "go for sim_telarray"
#. ./examples_common.sh
#export CORSIKA_IO_BUFFER=800MB
#zcat %s | $SIM_TELARRAY_PATH/run_sim_%s""" % (corsikaFileName, simtelExecName))
#  fd.close()

#### execute simtelarray ################
    fd = open('run_sim.sh', 'w')
    fd.write("""#! /bin/sh  
export SVNPROD2=$PWD
export SVNTAG=SVN-PROD2
export CORSIKA_IO_BUFFER=800MB
./grid_prod2-repro.sh %s %s""" % (corsikaFileName, simtelConfig))
    fd.close()

    os.system('chmod u+x run_sim.sh')

    cmdTuple = ['./run_sim.sh']
    ret = systemCall(0, cmdTuple, sendOutputSimTel)
    simtelReturnCode, stdout, stderr = ret['Value']

    if (os.system('grep Broken simtel.log')):
        print 'not broken'
    else:
        print 'broken'

        # Tag corsika File if Broken Pipe
        corsikaTagMD = {}
        corsikaTagMD['CorsikaToReprocess'] = 'CorsikaToReprocess'
        result = fcc.setMetadata(corsikaFileLFN, corsikaTagMD)
        print "result setMetadata=", result
        if not result['OK']:
            print 'ResultSetMetadata:', result['Message']

        jobReport.setApplicationStatus('Broken pipe')
        DIRAC.exit(-1)

    if not ret['OK']:
        DIRAC.gLogger.error('Failed to execute run_sim.sh')
        DIRAC.gLogger.error('run_sim.sh status is:', simtelReturnCode)
        DIRAC.exit(-1)

## putAndRegister simtel data/log/histo Output File:
    simtelFileName = particle + '_' + str(thetaP) + '_' + str(
        phiP) + '_alt' + str(obslev) + '_' + 'run' + run_number + '.simtel.gz'
    cfg = simtelExecName
    if simtelExecName == "cta-prod2-nsbx3":
        cfg = "cta-prod2"
    cmd = 'mv Data/sim_telarray/' + cfg + '/0.0deg/Data/*.simtel.gz ' + simtelFileName
    if (os.system(cmd)):
        DIRAC.exit(-1)

    simtelOutFileDir = os.path.join(simtelDirPath, 'Data', runNumSeriesDir)
    simtelOutFileLFN = os.path.join(simtelOutFileDir, simtelFileName)
    simtelRunNumberSeriesDirExist = fcc.isDirectory(
        simtelOutFileDir)['Value']['Successful'][simtelOutFileDir]
    newSimtelRunFileSeriesDir = (
        simtelRunNumberSeriesDirExist != True
    )  # if new runFileSeries, will need to add new MD

    simtelLogFileName = particle + '_' + str(thetaP) + '_' + str(
        phiP) + '_alt' + str(obslev) + '_' + 'run' + run_number + '.log.gz'
    cmd = 'mv Data/sim_telarray/' + cfg + '/0.0deg/Log/*.log.gz ' + simtelLogFileName
    if (os.system(cmd)):
        DIRAC.exit(-1)
    simtelOutLogFileDir = os.path.join(simtelDirPath, 'Log', runNumSeriesDir)
    simtelOutLogFileLFN = os.path.join(simtelOutLogFileDir, simtelLogFileName)

    simtelHistFileName = particle + '_' + str(thetaP) + '_' + str(
        phiP) + '_alt' + str(obslev) + '_' + 'run' + run_number + '.hdata.gz'
    cmd = 'mv Data/sim_telarray/' + cfg + '/0.0deg/Histograms/*.hdata.gz ' + simtelHistFileName
    if (os.system(cmd)):
        DIRAC.exit(-1)
    simtelOutHistFileDir = os.path.join(simtelDirPath, 'Histograms',
                                        runNumSeriesDir)
    simtelOutHistFileLFN = os.path.join(simtelOutHistFileDir,
                                        simtelHistFileName)

    ################################################
    DIRAC.gLogger.notice('Put and register simtel File in LFC and DFC:',
                         simtelOutFileLFN)
    ret = dirac.addFile(simtelOutFileLFN, simtelFileName, storage_element)

    res = CheckCatalogCoherence(simtelOutFileLFN)
    if res != DIRAC.S_OK:
        DIRAC.gLogger.error('Job failed: Catalog Coherence problem found')
        jobReport.setApplicationStatus('OutputData Upload Error')
        DIRAC.exit(-1)

    if not ret['OK']:
        DIRAC.gLogger.error('Error during addFile call:', ret['Message'])
        jobReport.setApplicationStatus('OutputData Upload Error')
        DIRAC.exit(-1)
######################################################################

    DIRAC.gLogger.notice('Put and register simtel Log File in LFC and DFC:',
                         simtelOutLogFileLFN)
    ret = dirac.addFile(simtelOutLogFileLFN, simtelLogFileName,
                        storage_element)

    res = CheckCatalogCoherence(simtelOutLogFileLFN)
    if res != DIRAC.S_OK:
        DIRAC.gLogger.error('Job failed: Catalog Coherence problem found')
        jobReport.setApplicationStatus('OutputData Upload Error')
        DIRAC.exit(-1)

    if not ret['OK']:
        DIRAC.gLogger.error('Error during addFile call:', ret['Message'])
        jobReport.setApplicationStatus('OutputData Upload Error')
        DIRAC.exit(-1)
######################################################################

    DIRAC.gLogger.notice('Put and register simtel Histo File in LFC and DFC:',
                         simtelOutHistFileLFN)
    ret = dirac.addFile(simtelOutHistFileLFN, simtelHistFileName,
                        storage_element)

    res = CheckCatalogCoherence(simtelOutHistFileLFN)
    if res != DIRAC.S_OK:
        DIRAC.gLogger.error('Job failed: Catalog Coherence problem found')
        jobReport.setApplicationStatus('OutputData Upload Error')
        DIRAC.exit(-1)

    if not ret['OK']:
        DIRAC.gLogger.error('Error during addFile call:', ret['Message'])
        jobReport.setApplicationStatus('OutputData Upload Error')
        DIRAC.exit(-1)
######################################################################

    if newSimtelRunFileSeriesDir:
        insertRunFileSeriesMD(simtelOutFileDir, runNumTrunc)
        insertRunFileSeriesMD(simtelOutLogFileDir, runNumTrunc)
        insertRunFileSeriesMD(simtelOutHistFileDir, runNumTrunc)


###### simtel File level metadata ############################################

    simtelFileMD = {}
    simtelFileMD['runNumber'] = int(run_number)
    simtelFileMD['jobID'] = jobID
    simtelFileMD['simtelReturnCode'] = simtelReturnCode

    result = fcc.setMetadata(simtelOutFileLFN, simtelFileMD)
    print "result setMetadata=", result
    if not result['OK']:
        print 'ResultSetMetadata:', result['Message']

    result = fcc.setMetadata(simtelOutLogFileLFN, simtelFileMD)
    print "result setMetadata=", result
    if not result['OK']:
        print 'ResultSetMetadata:', result['Message']

    result = fcc.setMetadata(simtelOutHistFileLFN, simtelFileMD)
    print "result setMetadata=", result
    if not result['OK']:
        print 'ResultSetMetadata:', result['Message']

    result = fcc.addFileAncestors(
        {simtelOutFileLFN: {
            'Ancestors': [corsikaFileLFN]
        }})
    print 'result addFileAncestor:', result

    result = fcc.addFileAncestors(
        {simtelOutLogFileLFN: {
            'Ancestors': [corsikaFileLFN]
        }})
    print 'result addFileAncestor:', result

    result = fcc.addFileAncestors(
        {simtelOutHistFileLFN: {
            'Ancestors': [corsikaFileLFN]
        }})
    print 'result addFileAncestor:', result

    result = fcc.setMetadata(simtelOutFileLFN, simtelFileMD)
    if not result['OK']:
        print 'ResultSetMetadata:', result['Message']

    DIRAC.exit()
Exemple #15
0
def install_CorsikaSimtelPack(version):

    from CTADIRAC.Core.Utilities.SoftwareInstallation import checkSoftwarePackage
    from CTADIRAC.Core.Utilities.SoftwareInstallation import installSoftwarePackage
    from CTADIRAC.Core.Utilities.SoftwareInstallation import installSoftwareEnviron
    from CTADIRAC.Core.Utilities.SoftwareInstallation import sharedArea
    from CTADIRAC.Core.Utilities.SoftwareInstallation import workingArea
    from DIRAC.Core.Utilities.Subprocess import systemCall

    CorsikaSimtelPack = 'corsika_simhessarray/' + version + '/corsika_simhessarray'
    packs = [CorsikaSimtelPack]
    for package in packs:
        DIRAC.gLogger.notice('Checking:', package)
        if sharedArea:
            if checkSoftwarePackage(package, sharedArea())['OK']:
                DIRAC.gLogger.notice('Package found in Shared Area:', package)
                installSoftwareEnviron(package, workingArea())
                packageTuple = package.split('/')
                corsika_subdir = sharedArea(
                ) + '/' + packageTuple[0] + '/' + version
                cmd = 'cp -u -r ' + corsika_subdir + '/* .'
                os.system(cmd)
                continue
        if workingArea:
            if checkSoftwarePackage(package, workingArea())['OK']:
                DIRAC.gLogger.notice('Package found in Local Area:', package)
                continue
            if installSoftwarePackage(package, workingArea())['OK']:
                ############## compile #############################
                cmdTuple = ['./build_all', 'prod2', 'qgs2']
                ######### special case for Astri ############################
                if version == 'prod-2_08072014_to':
                    ############## compile #############################
                    fd = open('run_compile.sh', 'w')
                    fd.write("""#! /bin/sh  
source ./build_all prod2 qgs2
#
echo " Let's check that build_all did its work " 
ls -alFsh 
echo "+++++++++++++++++++++++++++++++++++++++++++++++++"
echo " Let's see what files are in the corsika-run directory " 
ls -alFsh ./corsika-run
#
if [ ! -x ./corsika-run/corsika ]
then 
    echo " ERROR: Corsika executable found. Exit " 
    exit 1
fi
echo "+++++++++++++++++++++++++++++++++++++++++++++++++"
#
echo " Now let's try to compile hessio according to Federico's recipe "
cd ./hessioxxx 
make clean 
make EXTRA_DEFINES="-DCTA_PROD2 -DWITH_LOW_GAIN_CHANNEL"
# 
echo " Let's see what files are in the lib directory " 
ls -alFsh ./lib
#
if [ ! -f ./lib/libhessio.so ]
then 
    echo " ERROR: libhessio library not found. Exit " 
    exit 1
fi
echo "+++++++++++++++++++++++++++++++++++++++++++++++++"
#
cd .. # come back to original dir
# 
echo " Now let's try to compile simtel according to Federico's recipe "
cd ./sim_telarray
make clean 
make EXTRA_DEFINES="-DCTA_PROD2 -DWITH_LOW_GAIN_CHANNEL"
make install 
# 
echo " Let's see what files are in the bin directory " 
ls -alFsh ./bin
#
if [ ! -x ./bin/sim_telarray ]
then 
    echo " ERROR: sim_telarray excutable not found. Exit " 
    exit 1
fi
echo "+++++++++++++++++++++++++++++++++++++++++++++++++"
#
echo " Everything was compiled and linked properly" """)
                    fd.close()
                    os.system('chmod u+x run_compile.sh')
                    cmdTuple = ['./run_compile.sh']


##########################################################################

                ret = systemCall(0, cmdTuple, sendOutput)
                if not ret['OK']:
                    DIRAC.gLogger.error('Failed to execute build')
                    DIRAC.exit(-1)
                continue
        DIRAC.gLogger.error('Check Failed for software package:', package)
        DIRAC.gLogger.error('Software package not available')
        DIRAC.exit(-1)
Exemple #16
0
def main():

  from DIRAC import gLogger
  from DIRAC.Core.Base import Script
  Script.parseCommandLine()

  from CTADIRAC.Core.Utilities.SoftwareInstallation import checkSoftwarePackage
  from CTADIRAC.Core.Utilities.SoftwareInstallation import sharedArea
  from CTADIRAC.Core.Utilities.SoftwareInstallation import createSharedArea
  from DIRAC.Core.Utilities.Subprocess import systemCall

  args = Script.getPositionalArgs()
  version = args[0]
  
  area = sharedArea()


  if area:
    gLogger.notice( 'Using Shared Area at:', area)    
  else:
    if createSharedArea() == True:
      gLogger.notice( 'Shared Area created:', sharedArea())
      if (os.mkdir( os.path.join(sharedArea(),'corsika_simhessarray'))):
        gLogger.error( 'Failed to create corsika_simhessarray Directory')
        DIRAC.exit( -1 )
      gLogger.notice( 'corsika_simhessarray Directory created')
    else:
      gLogger.error( 'Failed to create Shared Area Directory')
      DIRAC.exit ( -1 )

  CorsikaSimtelPack = os.path.join('corsika_simhessarray', version, 'corsika_simhessarray')

  packs = [CorsikaSimtelPack]

  for package in packs:
    DIRAC.gLogger.notice( 'Checking:', package )
    packageTuple = package.split( '/' )
#    if sharedArea:
    if checkSoftwarePackage( package, sharedArea() )['OK']:
      DIRAC.gLogger.notice( 'Package found in Shared Area:', package )
      continue
#      if installSoftwarePackage( package, sharedArea() )['OK']:
      ############## compile #############################
    installdir = os.path.join( sharedArea(), packageTuple[0], packageTuple[1])
    fd = open('run_compile.sh', 'w' )
    fd.write( """#!/bin/sh      
current_dir=${PWD}
package=%s
installdir=%s
if ! [ -d ${package} ]; then
mkdir ${package}
fi
mkdir ${installdir} 
cd ${installdir} 
mkdir sim sim-sc3
(cd sim && tar zxvf ${current_dir}/corsika_simhessarray.tar.gz && ./build_all prod2 qgs2)
(cd sim-sc3 && tar zxvf ${current_dir}/corsika_simhessarray.tar.gz && ./build_all sc3 qgs2)""" % (packageTuple[0],installdir))
    fd.close()
    os.system('chmod u+x run_compile.sh')
    if(os.system('./run_compile.sh')):
      DIRAC.gLogger.error( 'Failed to compile')
      DIRAC.exit( -1 )
    continue

    DIRAC.gLogger.error( 'Software package not correctly installed')
    DIRAC.exit( -1 )  

  DIRAC.exit()
Exemple #17
0
def main():

  from DIRAC.Core.Base import Script
  Script.initialize() 

  DIRAC.gLogger.notice('Platform is:')
  os.system('dirac-platform')
  from DIRAC.DataManagementSystem.Client.DataManager import DataManager
  from CTADIRAC.Core.Workflow.Modules.EvnDispApp import EvnDispApp
  from CTADIRAC.Core.Utilities.SoftwareInstallation import checkSoftwarePackage
  from CTADIRAC.Core.Utilities.SoftwareInstallation import installSoftwarePackage
  from CTADIRAC.Core.Utilities.SoftwareInstallation import installSoftwareEnviron
  from CTADIRAC.Core.Utilities.SoftwareInstallation import sharedArea
  from CTADIRAC.Core.Utilities.SoftwareInstallation import workingArea
  from DIRAC.Core.Utilities.Subprocess import systemCall
  from DIRAC.WorkloadManagementSystem.Client.JobReport import JobReport

  jobID = os.environ['JOBID']
  jobID = int( jobID )
  jobReport = JobReport( jobID )

  version = sys.argv[3]
  DIRAC.gLogger.notice( 'Version:', version )

  EvnDispPack = os.path.join('evndisplay',version,'evndisplay')

  packs = [EvnDispPack]

  for package in packs:
    DIRAC.gLogger.notice( 'Checking:', package )
    if checkSoftwarePackage( package, sharedArea() )['OK']:
      DIRAC.gLogger.notice( 'Package found in Shared Area:', package )
      installSoftwareEnviron( package, sharedArea() )
#      cmd = 'cp -r ' + os.path.join(sharedArea(),'evndisplay',version,'EVNDISP.CTA.runparameter') + ' .'
#      if(os.system(cmd)):
#        DIRAC.exit( -1 )
#      cmd = 'cp -r ' + os.path.join(sharedArea(),'evndisplay',version,'Calibration') + ' .'
#      if(os.system(cmd)):
#        DIRAC.exit( -1 )
      continue
    else:
      installSoftwarePackage( package, workingArea() )
      DIRAC.gLogger.notice( 'Package found in workingArea:', package )
      continue

    DIRAC.gLogger.error( 'Check Failed for software package:', package )
    DIRAC.gLogger.error( 'Software package not available')
    DIRAC.exit( -1 )  

  ed = EvnDispApp()
  ed.setSoftwarePackage(EvnDispPack)

########## Use of trg mask file #######################
  usetrgfile = sys.argv[7]
  DIRAC.gLogger.notice( 'Usetrgfile:', usetrgfile )

####### Use of multiple inputs per job ###
  simtelFileLFNList = sys.argv[-1].split('ParametricParameters={')[1].split('}')[0].replace(',',' ')
  # first element of the list
  simtelFileLFN = simtelFileLFNList.split(' ')[0]  
  ## convert the string into a list and get the basename
  simtelFileList = []
  for word in simtelFileLFNList.split():
    simtelFileList.append(os.path.basename(word))

####  Parse the Layout List #################
  layoutList = parseLayoutList(sys.argv[9])
#############################################

####  Loop over the Layout List #################
  for layout in layoutList: 
    args = []
########## download trg mask file #######################
    if usetrgfile == 'True':
      trgmaskFileLFN = simtelFileLFN.replace( 'simtel.gz', 'trgmask.gz' )
      DIRAC.gLogger.notice( 'Trying to download the trgmask File', trgmaskFileLFN )
      result = DataManager().getFile( trgmaskFileLFN )
      if not result['OK']:
        DIRAC.gLogger.error( 'Failed to download trgmakfile:', result )
        jobReport.setApplicationStatus( 'Trgmakfile download Error' )
        DIRAC.exit( -1 )
      args.extend( ['-t', os.path.basename( trgmaskFileLFN )] )
############################################################
###### execute evndisplay converter ##################
    executable = sys.argv[5]

############ dst file Name ############################
    run_number = simtelFileList[-1].split( 'run' )[1].split( '.simtel.gz' )[0]
    runNum = int( run_number )
    subRunNumber = '%06d' % runNum
    particle = simtelFileList[-1].split( '_' )[0]
    if 'ptsrc' in simtelFileList[-1]:
      particle = particle + '_' + 'ptsrc'
    dstfile = particle + '_run' + subRunNumber + '_' + str( jobID ) + '_' + os.path.basename( layout ) + '_dst.root'
###########################################

    logfileName = executable + '_' + layout + '.log'
    layout = os.path.join( 'EVNDISP.CTA.runparameter/DetectorGeometry', layout )
    DIRAC.gLogger.notice( 'Layout is:', layout )

  # add other arguments for evndisplay converter specified by user ######
    converterparfile = open( 'converter.par', 'r' ).readlines()
    for line in converterparfile:
      for word in line.split():
        args.append( word )
#########################################################
    args.extend( ['-a', layout] )
    args.extend( ['-o', dstfile] )
    args.extend( simtelFileList )
    execute_module( ed, executable, args )
########### check existence of DST file ###############
    if not os.path.isfile( dstfile ):
      DIRAC.gLogger.error( 'DST file Missing:', dstfile )
      jobReport.setApplicationStatus( 'DST file Missing' )
      DIRAC.exit( -1 )

########### quality check on Log #############################################
    cmd = 'mv ' + executable + '.log' + ' ' + logfileName
    if( os.system( cmd ) ):
      DIRAC.exit( -1 )

    fd = open( 'check_log.sh', 'w' )
    fd.write( """#! /bin/sh
MCevts=$(grep writing  %s | grep "MC events" | awk '{print $2}')
if [ $MCevts -gt 0 ]; then
    exit 0
else
    echo "MCevts is zero"
    exit -1
fi
""" % (logfileName))
    fd.close()

    os.system( 'chmod u+x check_log.sh' )
    cmd = './check_log.sh'
    DIRAC.gLogger.notice( 'Executing system call:', cmd )
    if( os.system( cmd ) ):
      jobReport.setApplicationStatus( 'Converter Log Check Failed' )
      DIRAC.exit( -1 )

   ####  Check the mode #################
    mode = sys.argv[11]
    if( mode == 'convert_standalone' ):
      #DIRAC.exit()
      continue

###### execute evndisplay stage1 ###############
    executable = 'evndisp'
    logfileName = executable + '_' + os.path.basename( layout ) + '.log'

    args = ['-sourcefile', dstfile, '-outputdirectory', 'outdir']
  # add other arguments for evndisp specified by user ######
    evndispparfile = open( 'evndisp.par', 'r' ).readlines()
    for line in evndispparfile:
      for word in line.split():
        args.append( word )

    execute_module( ed, executable, args )

    for name in glob.glob( 'outdir/*.root' ):
      evndispOutFile = name.split( '.root' )[0] + '_' + str( jobID ) + '_' + os.path.basename( layout ) + '_evndisp.root'
      cmd = 'mv ' + name + ' ' + os.path.basename( evndispOutFile )
      if( os.system( cmd ) ):
        DIRAC.exit( -1 )

########### quality check on Log #############################################
    cmd = 'mv ' + executable + '.log' + ' ' + logfileName
    if( os.system( cmd ) ):
      DIRAC.exit( -1 )
    fd = open( 'check_log.sh', 'w' )
    fd.write( """#! /bin/sh
if grep -i "error" %s; then
exit 1
fi
if grep "Final checks on result file (seems to be OK):" %s; then
exit 0
else
exit 1
fi
""" % (logfileName,logfileName))
    fd.close()

    os.system( 'chmod u+x check_log.sh' )
    cmd = './check_log.sh'
    DIRAC.gLogger.notice( 'Executing system call:', cmd )
    if( os.system( cmd ) ):
      jobReport.setApplicationStatus( 'EvnDisp Log Check Failed' )
      DIRAC.exit( -1 )
##################################################################
########### remove the converted dst file #############################################
    cmd = 'rm ' + dstfile
    if( os.system( cmd ) ):
      DIRAC.exit( -1 )
 
  DIRAC.exit()