#!/apps/python/python-2.7.1/bin/python2.7 import MySQLdb import sys import os import subprocess import time dbhost = "hallddb.jlab.org" dbuser = 'datmon' dbpass = '' dbname = 'data_monitoring' def find(runNumber): result = [] runPeriods=["RunPeriod-2014-10", "RunPeriod-2015-03", "RunPeriod-2015-06"] for runPeriod in runPeriods: inputDirectory = "/mss/halld/%s/rawdata/Run%.6i/" % (runPeriod , runNumber) list = [] try: #list = sorted(os.listdir( inputDirectory)) list = sorted(os.path.join(inputDirectory, f) for f in os.listdir(inputDirectory)) except OSError: continue return list def get_data(options): conn=MySQLdb.connect(host=dbhost, user=dbuser, db=dbname) curs=conn.cursor() curs.execute("SELECT run_num, num_files from run_info WHERE %s" % options) rows=curs.fetchall() conn.close() return rows # main function # This is where the program starts def main(): ######################################################################### # Here is where to define all of the stuff to be passed to the run command Plugins="monitoring_hists" Options="-PEVIO:ENABLE_DISENTANGLING=0 -PJANA:BATCH_MODE=1" # define paths for output MyOutHistDir="/volatile/halld/home/mstaib/" #MyOutLogDir="/work/halld/home/mstaib/" # Not implemented # Pick a number of threads nThreads = 1 #Choose your search options #searchOptions = "run_num>1498 and beam_current>10 and solenoid_current > 1000" searchOptions = "run_num>2400 and run_num<2421 and beam_current>10 and solenoid_current>1000 and collimator_diameter!=\"Blocking\"" #searchOptions += " and trigger_config_file='fcal_bcal_m8.conf'" #2139-2500" maxFiles = 1000 # You can use this to cut on the maximum number of files submitted for each run minFiles = 2 # Use this to cut on the minimum number of files a run must have in order to be submitted Test = 1 # Set Test to 0 to actually submit the jobs ######################################################################### print "=========================================================" print "Launching jobs with plugins: %s" % Plugins print "With options: %s" % Options print "Using %i thread(s)" % nThreads print "=========================================================" print "Searching for runs satisfying: %s" % searchOptions print "=========================================================" # connect to DB and select run numbers records = get_data(searchOptions) #print records for row in records: run_num = row[0] run_num_str = str("%d" % run_num) # find associated files allfiles = "" counter = 0 #for files in sorted(os.listdir( inputDirectory)): for files in find(run_num): if not files.endswith("evio"): continue; if files.find(run_num_str) == -1: continue; counter += 1 if counter > maxFiles: continue; allfiles += files + " " if counter > minFiles: if maxFiles > counter: print "Submitting %i of %s Files for Run %s" % (counter, counter, run_num_str) else: print "Submitting %i of %s Files for Run %s" % (maxFiles, counter, run_num_str) subprocess.call(["SubmitGenericJob.sh",Plugins,Options,run_num_str,str(nThreads),MyOutHistDir,allfiles,str(Test)]) if __name__=="__main__": main()