Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-11-25 02:29:11

0001 #!/usr/bin/env python3
0002 import urllib
0003 import string
0004 import os
0005 import sys
0006 import subprocess
0007 import time
0008 import optparse
0009 import submitCalibTree.Config
0010 import submitCalibTree.launchJobs
0011 
0012 mailAdd = ""
0013 start = time.strftime("%D %H:%M")
0014 
0015 def mail(STDruns,AAGruns,cleanUpLog):
0016    if mailAdd=="":
0017       print("No email address specified.")
0018       return
0019 
0020    message  = "Production started at %s\n"%start
0021    message += "             ended at %s\n"%time.strftime("%D %H:%M")
0022    message += "\n\n\n"
0023    message += "Std bunch : processed the following runs :\n"
0024    previousRun=0
0025    nJobs=1
0026    runs = {}
0027    for run in STDruns:
0028       if not run[0] in runs.keys():
0029          runs[run[0]]=1
0030       else:
0031          runs[run[0]]+=1
0032 
0033    runsOrdered = sorted(runs.keys())
0034 
0035    for r in runsOrdered:
0036       message+=" Run %s (%s jobs) \n"%(r,runs[r])
0037    message +="\n\n"
0038    message += "Aag bunch : processed the following runs :\n"
0039    runs={}
0040    for run in AAGruns:
0041       if not run[0] in runs.keys():
0042          runs[run[0]]=1
0043       else:
0044          runs[run[0]]+=1
0045    runsOrdered = runs.keys()
0046    runsOrdered.sort()
0047 
0048    for r in runsOrdered:
0049       message+=" Run %s (%s jobs) \n"%(r,runs[r])
0050 
0051    message+="\n\n **** Cleaning report **** \n\n"
0052    message+=cleanUpLog.replace("\"","").replace("'","")
0053    os.system('echo "%s" | mail -s "CalibTree production status" '%message + mailAdd)
0054 
0055 debug = False
0056 for arg in sys.argv:
0057    debug +="debug" in arg.lower()
0058 if debug:
0059    print("DEBUG MODE DETECTED")
0060    print("--> Will not submit jobs")
0061    print("--> Will not modify status files")
0062    print()
0063 
0064 
0065 
0066 #Std bunch:
0067 print("Processing Std bunch")
0068 config = submitCalibTree.Config.configuration(debug=debug)
0069 cleanUpMessage = "Unable to clean up folder. Bad clean-up integrity?"
0070 
0071 if config.integrity:
0072    print("Cleaning up directory...")
0073    cleanUpMessage = subprocess.getstatusoutput("cd %s; python cleanFolders.py; cd -"%config.RUNDIR)[1]
0074    print(cleanUpMessage)
0075    with open("LastRun.txt","r") as lastRun:
0076       for line in lastRun:
0077          line = line.replace("\n","").replace("\r","")
0078          if line.isdigit():
0079             config.firstRun = int(line)
0080 
0081    with open("FailledRun.txt","r") as failled:
0082       for line in failled:
0083          line = line.split()
0084          if len(line)==1:
0085             if line[0].isdigit() and len(line[0])==6:
0086                config.relaunchList.append(line)
0087          elif len(line)==3:
0088             if line[0].isdigit() and line[1].isdigit() and line[2].isdigit and len(line[0])==6:
0089                config.relaunchList.append(line)
0090    if not debug:
0091       with open("FailledRun.txt","w") as failled:
0092          failled.write("")
0093 
0094    lastRunProcessed = submitCalibTree.launchJobs.generateJobs(config)
0095 
0096    print(config.launchedRuns)
0097 
0098    if not debug:
0099       with open("LastRun.txt","w") as lastRun:
0100          lastRun.write(str(lastRunProcessed))
0101 
0102 
0103 
0104 print("Processing AAG")
0105 
0106 
0107 
0108 configAAG = submitCalibTree.Config.configuration(True,debug=debug)
0109 if configAAG.integrity:
0110    with open("LastRun_Aag.txt","r") as lastRun:
0111       for line in lastRun:
0112          line = line.replace("\n","").replace("\r","")
0113          if line.isdigit():
0114             configAAG.firstRun = int(line)
0115 
0116 
0117    with open("FailledRun_Aag.txt","r") as failled:
0118       for line in failled:
0119          line = line.split()
0120          if len(line)==1:
0121             if line[0].isdigit() and len(line[0])==6:
0122                configAAG.relaunchList.append(line)
0123          elif len(line)==3:
0124             if line[0].isdigit() and line[1].isdigit() and line[2].isdigit and len(line[0])==6:
0125                configAAG.relaunchList.append(line)
0126    if not debug:
0127       with open("FailledRun_Aag.txt","w") as failled:
0128          failled.write("")
0129 
0130    lastRunProcessed = submitCalibTree.launchJobs.generateJobs(configAAG)
0131 
0132    if not debug:
0133       with open("LastRun_Aag.txt","w") as lastRun:
0134          lastRun.write(str(lastRunProcessed))
0135 
0136 
0137 mail(config.launchedRuns,configAAG.launchedRuns,cleanUpMessage)