ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/OSUT3Analysis/DBTools/scripts/osusub
Revision: 1.3
Committed: Tue Jul 31 14:17:11 2012 UTC (12 years, 9 months ago) by ahart
Branch: MAIN
CVS Tags: V00-00-03
Changes since 1.2: +3 -4 lines
Log Message:
Connect to the database once, and check that dataset is present.

File Contents

# User Rev Content
1 ahart 1.1 #!/usr/bin/env perl
2    
3     use strict;
4     use Mysql;
5     use File::Copy;
6     use Getopt::Long;
7 ahart 1.2
8 ahart 1.1 sub printHelp;
9     sub outputPset;
10     sub outputRunList;
11     sub getLocation;
12     sub outputCondor;
13    
14 ahart 1.3 our $db = Mysql->connect ("cmshead", "ntuple", "osuT3User");
15 ahart 1.1
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 ahart 1.2 my $queryDataset = $dataset;
113     $queryDataset =~ s/\*/%/g;
114     $queryDataset =~ s/(.*)/%$1%/g;
115 ahart 1.3 my $query = "select dataset,user,creationTime,location,nFiles,status from ntuple where dataset like '$queryDataset' and status='present' order by lastUpdateTime";
116 ahart 1.1 $db->selectdb ("ntuple");
117     $results = $db->query ($query);
118     if ($results->numrows () == 1)
119     {
120     my @row = $results->fetchrow ();
121 ahart 1.2 return ($row[3], $row[4], $row[5]);
122 ahart 1.1 }
123     if ($results->numrows () == 0)
124     {
125     print "Dataset does not exist on the Tier 3!\n";
126     exit;
127     }
128     my %map;
129     print "Found multiple datasets matching\n";
130     print "\"$dataset\":\n";
131     for (my $i = 1; $i <= $results->numrows (); $i++)
132     {
133     my @row = $results->fetchrow ();
134 ahart 1.2 $map{"$i"} = [$row[3], $row[4], $row[5]];
135     printf "(%2d) $row[0]\n", $i;
136     print " created by $row[1] on $row[2]\n";
137 ahart 1.1 }
138     print "\nWhich dataset would you like to use?: ";
139     my $response = <STDIN>;
140     $response =~ s/[ \t\n]//g;
141     if (!(exists $map{$response}))
142     {
143     print "Your selection \"$response\" was not a valid option! Quitting.\n";
144     exit;
145     }
146    
147     return ($map{$response}[0], $map{$response}[1], $map{$response}[2]);
148     }
149    
150     sub
151     outputCondor
152     {
153     my $workingDir = shift;
154     my $nJobs = shift;
155    
156     my $cmsRun = `which cmsRun`;
157     open (SUB, ">$workingDir/condor.sub");
158    
159     print SUB "Executable = $cmsRun\n";
160     print SUB "Universe = vanilla\n";
161     print SUB "Getenv = True\n";
162     print SUB "Arguments = config_cfg.py $nJobs \$(Process)\n";
163     print SUB "\n";
164     print SUB "Output = condor_\$(Process).out\n";
165     print SUB "Error = condor_\$(Process).err\n";
166     print SUB "Log = condor_\$(Process).log\n";
167     print SUB "\n";
168     print SUB "Queue $nJobs\n";
169    
170     close (SUB);
171     }
172    
173     sub
174     printHelp
175     {
176     my $exeName = $0;
177     $exeName =~ s/^.*\/([^\/]*)$/$1/;
178    
179 ahart 1.3 print "Usage: $exeName [OPTION]... DATASET CONFIG DIRECTORY NJOBS\n";
180 ahart 1.1 print "Submits CMSSW jobs to the OSU Tier 3 compute nodes using Condor.\n";
181     print "\n";
182     printf "%-29s%s\n", " -h, --help", "print this help message";
183     print "\n";
184     print "The DATASET must exist in the Tier 3 ntuple database, and CONFIG must be a valid\n";
185     print "CMSSW python configuration which can be used with cmsRun. DIRECTORY is a working\n";
186     print "directory that is created and in which all output, both from the CMSSW jobs and\n";
187     print "from Condor, is placed. Finally, NJOBS is the number of Condor jobs that will\n";
188     print "be created.\n";
189    
190     exit;
191     }