ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/OSUT3Analysis/DBTools/scripts/osusub
Revision: 1.1
Committed: Wed Jun 6 12:14:37 2012 UTC (12 years, 11 months ago) by ahart
Branch: MAIN
CVS Tags: V00-00-01, V00-00-00
Log Message:
First commit of OSU T3 analysis tools.

File Contents

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