ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/OSUT3Analysis/Configuration/scripts/submitToCondor.py
Revision: 1.11
Committed: Fri Jul 12 14:40:31 2013 UTC (11 years, 9 months ago) by jbrinson
Content type: text/x-python
Branch: MAIN
CVS Tags: V02-03-02
Changes since 1.10: +0 -2 lines
Log Message:
removed q and t options

File Contents

# Content
1 #!/usr/bin/env python
2 import os
3 import sys
4 import datetime
5 import shutil
6 import re
7 import subprocess
8 import signal
9 import fcntl
10 from optparse import OptionParser
11
12 from OSUT3Analysis.Configuration.configurationOptions import *
13 from OSUT3Analysis.Configuration.processingUtilities import *
14
15 parser = OptionParser()
16 parser = set_commandline_arguments(parser)
17
18 parser.remove_option("-o")
19 parser.remove_option("-n")
20 parser.remove_option("-u")
21 parser.remove_option("-e")
22 parser.remove_option("-r")
23 parser.remove_option("-R")
24 parser.remove_option("-d")
25 parser.remove_option("-b")
26 parser.remove_option("--2D")
27 parser.remove_option("-y")
28 parser.remove_option("-p")
29
30 parser.add_option("-s", "--skimDir", dest="skimDir",
31 help="condor directory containing skim")
32 parser.add_option("-a", "--skimChannel", dest="skimChannel",
33 help="channel from skim to use")
34 parser.add_option("-d", "--mergeDaemon", action="store_true", dest="mergeDaemon", default=False,
35 help="launch a daemon to merge output when jobs are done")
36
37 (arguments, args) = parser.parse_args()
38
39 if (arguments.skimDir and not arguments.skimChannel) or (not arguments.skimDir and arguments.skimChannel):
40 print "Both the skim directory (--skimDir) and channel (--skimChannel) must be given."
41 exit ()
42
43 if arguments.localConfig:
44 sys.path.append(os.getcwd())
45 exec("from " + arguments.localConfig.rstrip('.py') + " import *")
46
47 condor_dir = set_condor_submit_dir(arguments)
48 short_condor_dir = condor_dir
49 short_condor_dir = re.sub (r".*/([^/]*)", r"\1", short_condor_dir)
50 short_condor_dir = list (short_condor_dir)
51 short_condor_dir[0] = short_condor_dir[0].upper ()
52 short_condor_dir = "".join (short_condor_dir)
53
54 if not os.path.exists (condor_dir):
55 os.system("mkdir %s" % (condor_dir))
56
57 split_datasets = split_composite_datasets(datasets, composite_dataset_definitions)
58
59 clusters = ""
60 for dataset in split_datasets:
61 output_dir = "%s/%s" % (condor_dir, dataset)
62 skim_dir = ""
63 skim_channel_dir = ""
64 command = "osusub -l %s -m %d -p %s %s %s %s %s" % (dataset, maxEvents[dataset], short_condor_dir, dataset_names[dataset], config_file, output_dir, nJobs[dataset])
65 if arguments.skimDir:
66 skim_dir = "condor/" + arguments.skimDir + "/" + dataset
67 skim_channel_dir = "condor/" + arguments.skimDir + "/" + dataset + "/" + arguments.skimChannel
68 if os.path.exists (skim_channel_dir):
69 command = "osusub -d %s -l %s -m %d -p %s %s %s %s %s" % (dataset_names[dataset], dataset, maxEvents[dataset], short_condor_dir, skim_channel_dir, config_file, output_dir, nJobs[dataset])
70 else:
71 print dataset + "/" + arguments.skimChannel + " not in skim directory. Skipping."
72 continue
73 print command
74 pid = os.getpid ()
75 p0 = subprocess.Popen (command.split (), bufsize=1, stdout=subprocess.PIPE)
76 flags = fcntl.fcntl (p0.stdout.fileno (), fcntl.F_GETFL, 0)
77 fcntl.fcntl (p0.stdout.fileno (), fcntl.F_SETFL, flags | os.O_NONBLOCK)
78 output = ""
79 while p0.poll () is None:
80 try:
81 tmpOutput = p0.stdout.read (1024)
82 print tmpOutput,
83 output += tmpOutput
84 except IOError:
85 pass
86 tmpOutput = p0.stdout.read (1024)
87 print tmpOutput,
88 output += tmpOutput
89 output = re.sub (r"[\f\n\r]", r"", output)
90 output = re.sub (r".*submitted to cluster (.*)\..*$", r"\1", output)
91 clusters += " " + output
92 if arguments.skimDir and os.path.exists (skim_channel_dir + "/skimNumberOfEvents.txt") and os.path.exists (skim_dir + "/numberOfEvents.txt") and os.path.exists (skim_dir + "/crossSectionInPicobarn.txt"):
93 shutil.copy (skim_channel_dir + "/skimNumberOfEvents.txt", output_dir + "/skimNumberOfEvents.txt")
94 shutil.copy (skim_dir + "/numberOfEvents.txt", output_dir + "/originalNumberOfEvents.txt")
95 f = open (skim_channel_dir + "/skimNumberOfEvents.txt", "r")
96 skimNumberOfEvents = float (f.read ().rstrip ())
97 f.close ()
98 f = open (skim_dir + "/numberOfEvents.txt", "r")
99 numberOfEvents = float (f.read ().rstrip ())
100 f.close ()
101 f = open (skim_dir + "/crossSectionInPicobarn.txt", "r")
102 crossSectionInPicobarn = float (f.read ().rstrip ())
103 f.close ()
104 if numberOfEvents:
105 crossSectionInPicobarn *= skimNumberOfEvents / numberOfEvents
106 else:
107 crossSectionInPicobarn *= skimNumberOfEvents * numberOfEvents
108 f = open (output_dir + "/crossSectionInPicobarn.txt", "w")
109 f.write (str (crossSectionInPicobarn) + "\n")
110 f.close ()
111
112 if arguments.mergeDaemon:
113 command = "mergeOutput.py"
114 if arguments.condorDir:
115 command += " -c " + arguments.condorDir
116 pid = os.fork ()
117 if not pid:
118 signal.signal (signal.SIGHUP, signal.SIG_IGN)
119 pid = os.getpid ()
120 if arguments.localConfig:
121 shutil.copy (arguments.localConfig, "mergeDaemonOptions_" + str (pid) + ".py")
122 command += " -l mergeDaemonOptions_" + str (pid) + ".py"
123 os.execvp ("mergeDaemon.pl", ["mergeDaemon.pl", command] + clusters.split ())
124 else:
125 print "\nMerging daemon PID: " + str (pid)