ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/OSUT3Analysis/DBTools/scripts/osusub
Revision: 1.8
Committed: Fri Nov 23 11:17:44 2012 UTC (12 years, 5 months ago) by ahart
Branch: MAIN
Changes since 1.7: +3 -2 lines
Log Message:
Add a third argument in the condor submission file which is the dataset name.

File Contents

# Content
1 #!/usr/bin/env perl
2
3 use strict;
4 use Mysql;
5 use File::Copy;
6 use Getopt::Long;
7 use POSIX;
8
9 sub printHelp;
10 sub outputPset;
11 sub outputRunList;
12 sub getLocation;
13 sub outputCondor;
14
15 our $db = Mysql->connect ("cmshead", "ntuple", "osuT3User");
16
17 my %opt;
18 Getopt::Long::Configure ("bundling");
19 GetOptions (\%opt, "help|h");
20 my $argc = @ARGV;
21
22 printHelp () if $opt{"help"};
23 printHelp () if $argc != 4;
24 if (!(-e $ARGV[1]))
25 {
26 print "\"$ARGV[1]\" does not exist!\n";
27 exit;
28 }
29 if (-e $ARGV[2])
30 {
31 print "Directory \"$ARGV[2]\" already exists!\n";
32 print "Please delete it or specify another working directory.\n";
33 exit;
34 }
35 mkdir $ARGV[2];
36 my $nFiles = outputRunList ($ARGV[0], $ARGV[2]);
37 my $nJobs = $ARGV[3];
38 my $realNJobs = ceil ($nFiles / ceil ($nFiles / $nJobs));
39 outputPset ($ARGV[2]);
40 outputCondor ($ARGV[2], $realNJobs, $ARGV[0]);
41 copy ($ARGV[1], "$ARGV[2]/userConfig_cfg.py");
42 chdir $ARGV[2];
43 print "Submitting $realNJobs jobs to run on $nFiles files.\n";
44 system ("condor_submit condor.sub");
45
46 sub
47 outputPset
48 {
49 my $workingDir = shift;
50
51 open (PSET, ">$workingDir/config_cfg.py");
52
53 print PSET "import FWCore.ParameterSet.Config as cms\n";
54 print PSET "import OSUT3Analysis.DBTools.osusub_cfg as osusub\n";
55 print PSET "import re\n";
56 print PSET "import userConfig_cfg as pset\n";
57 print PSET "\n";
58 print PSET "fileName = pset.process.TFileService.fileName\n";
59 print PSET "fileName = fileName.pythonValue ()\n";
60 print PSET "fileName = fileName[1:(len (fileName) - 1)]\n";
61 print PSET "fileName = re.sub (r'^(.*)\\.([^\\.]*)\$', r'\\1_' + str (osusub.jobNumber) + r'.\\2', fileName)\n";
62 print PSET "pset.process.TFileService.fileName = fileName\n";
63 print PSET "\n";
64 print PSET "pset.process.source.fileNames = cms.untracked.vstring (osusub.runList)\n";
65 print PSET "pset.process.maxEvents.input = cms.untracked.int32 (-1)\n";
66 print PSET "process = pset.process\n";
67
68 close (PSET);
69 }
70
71 sub
72 outputRunList
73 {
74 my $dataset = shift;
75 my $workingDir = shift;
76
77 my ($location, $nFiles, $status, $crossSection) = getLocation ($dataset);
78 if ($status ne "present")
79 {
80 print "This dataset is not marked as present on the Tier 3!\n";
81 exit;
82 }
83 if (!(-e $location))
84 {
85 print "The database does not know where this dataset is!\n";
86 exit;
87 }
88 opendir (LOCATION, $location);
89 my @files = readdir (LOCATION);
90 closedir (LOCATION);
91 if (@files - 2 != $nFiles)
92 {
93 print "Number of files does not match database entry!\n";
94 exit;
95 }
96 open (RUNLIST, ">$workingDir/runList.py");
97 print RUNLIST "runList = [\n";
98 for (my $i = 0; $i < @files; $i++)
99 {
100 next if $files[$i] eq ".";
101 next if $files[$i] eq "..";
102 print RUNLIST "'file:$location/$files[$i]'";
103 print RUNLIST "," if $i + 1 != @files;
104 print RUNLIST "\n";
105 }
106 print RUNLIST "]";
107 close (RUNLIST);
108 if ($crossSection && $crossSection >= 0.0)
109 {
110 open (CROSS_SECTION, ">$workingDir/crossSectionInPicobarn.txt");
111 print CROSS_SECTION "$crossSection\n";
112 close (CROSS_SECTION);
113 }
114
115 return $nFiles;
116 }
117
118 sub
119 getLocation
120 {
121 my $dataset = shift;
122
123 my $results;
124 my $queryDataset = $dataset;
125 $queryDataset =~ s/\*/%/g;
126 $queryDataset =~ s/(.*)/%$1%/g;
127 my $query = "select dataset,user,creationTime,location,nFiles,status,crossSectionInPicobarn from ntuple where dataset like '$queryDataset' and status='present' order by creationTime";
128 $db->selectdb ("ntuple");
129 $results = $db->query ($query);
130 if ($results->numrows () == 1)
131 {
132 my @row = $results->fetchrow ();
133 return ($row[3], $row[4], $row[5], $row[6]);
134 }
135 if ($results->numrows () == 0)
136 {
137 print "Dataset does not exist on the Tier 3!\n";
138 exit;
139 }
140 my %map;
141 print "Found multiple datasets matching\n";
142 print "\"$dataset\":\n";
143 for (my $i = 1; $i <= $results->numrows (); $i++)
144 {
145 my @row = $results->fetchrow ();
146 $map{"$i"} = [$row[3], $row[4], $row[5], $row[6]];
147 printf "(%2d) $row[0]\n", $i;
148 print " created by $row[1] on $row[2]\n";
149 }
150 print "\nWhich dataset would you like to use?: ";
151 my $response = <STDIN>;
152 $response =~ s/[ \t\n]//g;
153 if (!(exists $map{$response}))
154 {
155 print "Your selection \"$response\" was not a valid option! Quitting.\n";
156 exit;
157 }
158
159 return ($map{$response}[0], $map{$response}[1], $map{$response}[2], $map{$response}[3]);
160 }
161
162 sub
163 outputCondor
164 {
165 my $workingDir = shift;
166 my $nJobs = shift;
167 my $dataset = shift;
168
169 my $cmsRun = `which cmsRun`;
170 open (SUB, ">$workingDir/condor.sub");
171
172 print SUB "Executable = $cmsRun\n";
173 print SUB "Universe = vanilla\n";
174 print SUB "Getenv = True\n";
175 print SUB "Arguments = config_cfg.py $nJobs \$(Process) $dataset\n";
176 print SUB "\n";
177 print SUB "Output = condor_\$(Process).out\n";
178 print SUB "Error = condor_\$(Process).err\n";
179 print SUB "Log = condor_\$(Process).log\n";
180 print SUB "\n";
181 print SUB "+IsLocalJob = true\n";
182 print SUB "Rank = TARGET.IsLocalSlot\n";
183 print SUB "\n";
184 print SUB "Queue $nJobs\n";
185
186 close (SUB);
187 }
188
189 sub
190 printHelp
191 {
192 my $exeName = $0;
193 $exeName =~ s/^.*\/([^\/]*)$/$1/;
194
195 print "Usage: $exeName [OPTION]... DATASET CONFIG DIRECTORY NJOBS\n";
196 print "Submits CMSSW jobs to the OSU Tier 3 compute nodes using Condor.\n";
197 print "\n";
198 printf "%-29s%s\n", " -h, --help", "print this help message";
199 print "\n";
200 print "The DATASET must exist in the Tier 3 ntuple database, and CONFIG must be a valid\n";
201 print "CMSSW python configuration which can be used with cmsRun. DIRECTORY is a working\n";
202 print "directory that is created and in which all output, both from the CMSSW jobs and\n";
203 print "from Condor, is placed. Finally, NJOBS is the number of Condor jobs that will\n";
204 print "be created.\n";
205
206 exit;
207 }