ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/OSUT3Analysis/DBTools/scripts/osusub
(Generate patch)

Comparing UserCode/OSUT3Analysis/DBTools/scripts/osusub (file contents):
Revision 1.4 by ahart, Thu Aug 9 06:36:17 2012 UTC vs.
Revision 1.11 by ahart, Thu Jan 17 20:51:46 2013 UTC

# Line 4 | Line 4 | use strict;
4   use Mysql;
5   use File::Copy;
6   use Getopt::Long;
7 + use POSIX;
8  
9   sub printHelp;
10   sub outputPset;
# Line 32 | Line 33 | if (-e $ARGV[2])
33      exit;
34    }
35   mkdir $ARGV[2];
36 < outputRunList ($ARGV[0], $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], $ARGV[3]);
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
# Line 70 | Line 74 | outputRunList
74    my $dataset = shift;
75    my $workingDir = shift;
76  
77 <  my ($location, $nFiles, $status) = getLocation ($dataset);
78 <  if ($status ne "present")
79 <    {
80 <      print "This dataset is not marked as present on the Tier 3!\n";
81 <      exit;
77 >  my $location;
78 >  my $nFiles;
79 >  my $status;
80 >  my $crossSection;
81 >  my $isLocation = 0;
82 >  $isLocation = 1 if -e $dataset;
83 >  if (!$isLocation)
84 >    {
85 >      ($location, $nFiles, $status, $crossSection) = getLocation ($dataset);
86 >      if ($status ne "present")
87 >        {
88 >          print "This dataset is not marked as present on the Tier 3!\n";
89 >          print "Continue anyway? (y/N): ";
90 >          my $response = <STDIN>;
91 >          $response =~ s/\n//g;
92 >          exit if !$response || lc ($response) ne "y";
93 >        }
94 >      if (!(-e $location))
95 >        {
96 >          print "The database does not know where this dataset is!\n";
97 >          exit;
98 >        }
99      }
100 <  if (!(-e $location))
100 >  else
101      {
102 <      print "The database does not know where this dataset is!\n";
82 <      exit;
102 >      $location = $dataset;
103      }
104    opendir (LOCATION, $location);
105    my @files = readdir (LOCATION);
106    closedir (LOCATION);
107 <  if (@files - 2 != $nFiles)
107 >  if (!$isLocation && @files - 2 != $nFiles)
108      {
109        print "Number of files does not match database entry!\n";
110 <      exit;
110 >      print "Continue anyway? (y/N): ";
111 >      my $response = <STDIN>;
112 >      $response =~ s/\n//g;
113 >      exit if !$response || lc ($response) ne "y";
114 >    }
115 >  elsif ($isLocation)
116 >    {
117 >      $nFiles = @files - 2;
118      }
119    open (RUNLIST, ">$workingDir/runList.py");
120    print RUNLIST "runList = [\n";
# Line 101 | Line 128 | outputRunList
128      }
129    print RUNLIST "]";
130    close (RUNLIST);
131 +  if ($crossSection && $crossSection >= 0.0)
132 +    {
133 +      open (CROSS_SECTION, ">$workingDir/crossSectionInPicobarn.txt");
134 +      print CROSS_SECTION "$crossSection\n";
135 +      close (CROSS_SECTION);
136 +    }
137 +
138 +  return $nFiles;
139   }
140  
141   sub
# Line 112 | Line 147 | getLocation
147    my $queryDataset = $dataset;
148    $queryDataset =~ s/\*/%/g;
149    $queryDataset =~ s/(.*)/%$1%/g;
150 <  my $query = "select dataset,user,creationTime,location,nFiles,status from ntuple where dataset like '$queryDataset' and status='present' order by creationTime";
150 >  my $query = "select dataset,user,creationTime,location,nFiles,status,crossSectionInPicobarn from ntuple where dataset like '$queryDataset' order by creationTime";
151    $db->selectdb ("ntuple");
152    $results = $db->query ($query);
153    if ($results->numrows () == 1)
154      {
155        my @row = $results->fetchrow ();
156 <      return ($row[3], $row[4], $row[5]);
156 >      return ($row[3], $row[4], $row[5], $row[6]);
157      }
158    if ($results->numrows () == 0)
159      {
# Line 131 | Line 166 | getLocation
166    for (my $i = 1; $i <= $results->numrows (); $i++)
167      {
168        my @row = $results->fetchrow ();
169 <      $map{"$i"} = [$row[3], $row[4], $row[5]];
169 >      $map{"$i"} = [$row[3], $row[4], $row[5], $row[6]];
170        printf "(%2d) $row[0]\n", $i;
171        print "     created by $row[1] on $row[2]\n";
172      }
# Line 144 | Line 179 | getLocation
179        exit;
180      }
181  
182 <  return ($map{$response}[0], $map{$response}[1], $map{$response}[2]);
182 >  return ($map{$response}[0], $map{$response}[1], $map{$response}[2], $map{$response}[3]);
183   }
184  
185   sub
# Line 152 | Line 187 | outputCondor
187   {
188    my $workingDir = shift;
189    my $nJobs = shift;
190 +  my $dataset = shift;
191  
192    my $cmsRun = `which cmsRun`;
193    open (SUB, ">$workingDir/condor.sub");
# Line 159 | Line 195 | outputCondor
195    print SUB "Executable              = $cmsRun\n";
196    print SUB "Universe                = vanilla\n";
197    print SUB "Getenv                  = True\n";
198 <  print SUB "Arguments               = config_cfg.py $nJobs \$(Process)\n";
198 >  print SUB "Arguments               = config_cfg.py True $nJobs \$(Process) $dataset\n";
199    print SUB "\n";
200    print SUB "Output                  = condor_\$(Process).out\n";
201    print SUB "Error                   = condor_\$(Process).err\n";
202    print SUB "Log                     = condor_\$(Process).log\n";
203    print SUB "\n";
204 +  print SUB "+IsLocalJob             = true\n";
205 +  print SUB "Rank                    = TARGET.IsLocalSlot\n";
206 +  print SUB "\n";
207    print SUB "Queue $nJobs\n";
208  
209    close (SUB);
# Line 177 | Line 216 | printHelp
216    $exeName =~ s/^.*\/([^\/]*)$/$1/;
217  
218    print "Usage: $exeName [OPTION]... DATASET CONFIG DIRECTORY NJOBS\n";
219 +  print "  or:  $exeName [OPTION]... LOCATION CONFIG DIRECTORY NJOBS\n";
220    print "Submits CMSSW jobs to the OSU Tier 3 compute nodes using Condor.\n";
221    print "\n";
222    printf "%-29s%s\n", "  -h, --help", "print this help message";
223    print "\n";
224 <  print "The DATASET must exist in the Tier 3 ntuple database, and CONFIG must be a valid\n";
225 <  print "CMSSW python configuration which can be used with cmsRun. DIRECTORY is a working\n";
224 >  print "The first argument must be either a DATASET registered in the Tier 3 ntuple\n";
225 >  print "database or a LOCATION which exists on disk. CONFIG must be a valid CMSSW\n";
226 >  print "python configuration which can be used with cmsRun. DIRECTORY is a working\n";
227    print "directory that is created and in which all output, both from the CMSSW jobs and\n";
228    print "from Condor, is placed. Finally, NJOBS is the number of Condor jobs that will\n";
229    print "be created.\n";

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines