ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/OSUT3Analysis/DBTools/scripts/osusub
Revision: 1.2
Committed: Thu Jun 14 17:42:30 2012 UTC (12 years, 10 months ago) by ahart
Branch: MAIN
CVS Tags: V00-00-02
Changes since 1.1: +10 -6 lines
Log Message:
Allow fuzzy dataset names for osudb and osusub. First commit of AnaTools directory.

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