ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/JOBROBOT/TaskSource
Revision: 1.20
Committed: Thu Jul 20 16:19:18 2006 UTC (18 years, 9 months ago) by gutsche
Branch: MAIN
CVS Tags: JOBROBOT_1_0006
Changes since 1.19: +19 -32 lines
Log Message:
added site limit to site configuration files and let it read in every time

File Contents

# User Rev Content
1 gutsche 1.1 #!/usr/bin/env perl
2    
3     ##H This drop box agent initiates tasks on all published datasets.
4     ##H A task is an application to run on a dataset at a particular site.
5     ##H It keeps a record of tasks created and avoids submitting a task too
6     ##H frequently.
7     ##H
8     ##H Usage:
9     ##H TaskSource
10     ##H -state DIRECTORY [-next NEXT] [-wait SECS] [-url URL-PUBLISHED]
11     ##H [-ignore-sites REGEXP] [-accept-sites REGEXP]
12     ##H [-secs-per-event N] [-max-site-queue N]
13     ##H
14     ##H -state agent state directory, including inbox
15     ##H -next next agent to pass the drops to; can be given several times
16     ##H -wait time to wait in seconds between work scans
17     ##H -url contact string for published datasets
18     ##H -ignore-sites
19     ##H regular expression for sites to ignore; ignore applies before
20     ##H accept, and by default nothing is ignored and everything is
21     ##H accepted. applies to pubdb site names, not the host names of
22     ##H the site.
23     ##H -accept-sites
24     ##H regular expression for sites to accept; ignore applies before
25     ##H accept, and by default nothing is ignored and everything is
26     ##H accepted. applies to pubdb site names, not the host names of
27     ##H the site.
28     ##H -secs-per-event
29     ##H minimum time to allocate for a task, given a number of events
30     ##H in the dataset to process. tasks are not created more often
31     ##H than this.
32     ##H -max-site-queue
33     ##H the high water mark of currently submitted jobs to a site,
34 gutsche 1.8 ##H above which new tasks will not be created. Represents the default
35     ##H taken if site specific values cannot be found
36 gutsche 1.1
37     BEGIN {
38     use strict; use warnings; $^W=1;
39     our $me = $0; $me =~ s|.*/||;
40     our $home = $0; $home =~ s|/[^/]+$||; $home ||= "."; $home .= "/../PHEDEX/Toolkit/Common";
41     unshift(@INC, $home);
42     }
43    
44     ######################################################################
45     use UtilsHelp;
46     my %args = (WAITTIME => 600, SECS_PER_EVENT => 1., MAX_SITE_QUEUE => 10,
47     URL => "http://cmsdoc.cern.ch/cms/production/www/PubDB/GetPublishedCollectionInfoFromRefDB.php");
48     while (scalar @ARGV)
49     {
50     if ($ARGV[0] eq '-state' && scalar @ARGV > 1)
51 corvo 1.3 { shift (@ARGV); $args{DROPDIR}= shift(@ARGV);}
52 gutsche 1.1 elsif ($ARGV[0] eq '-next' && scalar @ARGV > 1)
53 corvo 1.3 { shift (@ARGV); push (@{$args{NEXTDIR}}, shift(@ARGV));}
54 gutsche 1.1 elsif ($ARGV[0] eq '-wait' && scalar @ARGV > 1)
55     { shift (@ARGV); $args{WAITTIME} = shift(@ARGV); }
56     elsif ($ARGV[0] eq '-ignore-sites' && scalar @ARGV > 1)
57     { shift (@ARGV); $args{IGNORE_REGEXP} = shift(@ARGV); }
58     elsif ($ARGV[0] eq '-accept-sites' && scalar @ARGV > 1)
59     { shift (@ARGV); $args{ACCEPT_REGEXP} = shift(@ARGV); }
60 gutsche 1.19 elsif ($ARGV[0] eq '-siteconfig' && scalar @ARGV > 1)
61     { shift (@ARGV); $args{SITECONFIG} = shift(@ARGV); }
62 gutsche 1.1 elsif ($ARGV[0] eq '-secs-per-event' && scalar @ARGV > 1)
63     { shift (@ARGV); $args{SECS_PER_EVENT} = shift(@ARGV); }
64     elsif ($ARGV[0] eq '-max-site-queue' && scalar @ARGV > 1)
65     { shift (@ARGV); $args{MAX_SITE_QUEUE} = shift(@ARGV); }
66     elsif ($ARGV[0] eq '-url' && scalar @ARGV > 1)
67     { shift (@ARGV); $args{URL} = shift(@ARGV); }
68     # Marco
69     elsif ($ARGV[0] eq '-dataset' && scalar @ARGV > 1)
70     { shift (@ARGV); $args{DATASET} = shift(@ARGV); }
71     elsif ($ARGV[0] eq '-owner' && scalar @ARGV > 1)
72     { shift (@ARGV); $args{OWNER} = shift(@ARGV); }
73     elsif ($ARGV[0] eq '-events' && scalar @ARGV > 1)
74     { shift (@ARGV); $args{NEVENT} = shift(@ARGV); }
75     elsif ($ARGV[0] eq '-mode' && scalar @ARGV > 1)
76     { shift (@ARGV); $args{MODE} = shift(@ARGV); }
77     elsif ($ARGV[0] eq '-scheduler' && scalar @ARGV > 1)
78     { shift (@ARGV); $args{SCHEDULER} = shift(@ARGV); }
79     elsif ($ARGV[0] eq '-jobtype' && scalar @ARGV > 1)
80     { shift (@ARGV); $args{JOBTYPE} = shift(@ARGV); }
81 gutsche 1.5 elsif ($ARGV[0] eq '-filesperjob' && scalar @ARGV > 1)
82     { shift (@ARGV); $args{FILESPERJOB} = shift(@ARGV); }
83     elsif ($ARGV[0] eq '-eventsperjob' && scalar @ARGV > 1)
84     { shift (@ARGV); $args{EVENTSPERJOB} = shift(@ARGV); }
85 corvo 1.3 # marco. Added... don't know why...
86     elsif ($ARGV[0] eq '-log' && scalar @ARGV > 1)
87     { shift (@ARGV); $args{LOGFILE} = shift(@ARGV); }
88     # marco.
89 gutsche 1.1 # Marco
90     elsif ($ARGV[0] eq '-h')
91     { &usage(); }
92     else
93     { last; }
94     }
95    
96     if (@ARGV || !$args{DROPDIR} || !$args{URL})
97     {
98     die "Insufficient parameters, use -h for help.\n";
99     }
100    
101     (new TaskSource (%args))->process();
102    
103     ######################################################################
104     # Routines specific to this agent.
105     package TaskSource; use strict; use warnings; use base 'UtilsAgent';
106     use File::Path;
107     use UtilsCommand;
108     use UtilsLogging;
109     use UtilsTiming;
110     use UtilsNet;
111     use POSIX;
112    
113     sub new
114     {
115     my $proto = shift;
116     my $class = ref($proto) || $proto;
117     my $self = $class->SUPER::new(@_);
118     my %params = (SECS_PER_EVENT => undef, # secs/event to delay per dataset
119     MAX_SITE_QUEUE => undef, # max number of jobs per site
120     IGNORE_REGEXP => undef, # regexp of sites to ignore
121     ACCEPT_REGEXP => undef, # regexp of sites to accept
122     DATASET => undef, # specific dataset
123     OWNER => undef, # specific owner
124 gutsche 1.19 SITECONFIG => undef, # path to siteconfig file
125 gutsche 1.5 NEVENT => 500, # number of events per job
126     MODE => 1, # data discovery mode: (1) PudDB/RefDB, (2) DBS/DLS
127     JOBTYPE => "orca", # standard jobtype
128     SCHEDULER => "edg", # standard scheduler
129     FILESPERJOB => 1, # CMSSW: files per job
130     URL => undef); # published dataset url
131 gutsche 1.1 my %args = (@_);
132     map { $self->{$_} = defined $args{$_} ? $args{$_} : $params{$_} } keys %params;
133     bless $self, $class;
134     return $self;
135     }
136    
137     sub init
138     {
139     my ($self) = @_;
140     $self->{TASKREPO} = "$self->{DROPDIR}/tasks";
141     -d "$self->{TASKREPO}"
142     || mkdir "$self->{TASKREPO}"
143     || die "$self->{TASKREPO}: cannot create directory: $!\n";
144    
145     # Determine if links supports -dump-width option
146     $self->{LINKS_OPTS} = [];
147     open (LINKS_HELP, "links -help 2>/dev/null |");
148 gutsche 1.4 if ( grep(/-no-numbering/, <LINKS_HELP>) ) {
149     push(@{$self->{LINKS_OPTS}}, qw(-dump-width 300 -no-numbering 1));
150     } elsif ( grep(/-dump-width/, <LINKS_HELP>) ) {
151     push(@{$self->{LINKS_OPTS}}, qw(-dump-width 300));
152 gutsche 1.1 }
153     close (LINKS_HELP);
154    
155 gutsche 1.4 # Precode whitelist. Should really read this from somewhere...
156    
157     $self->{WHITELIST} = { ASCC => "sinica.edu.tw",
158     NCU => "ncu.edu.tw",
159     FNAL => "fnal.gov",
160     CNAF => "webserver.infn.it",
161     BA => "ba.infn.it",
162     IN2P3=> "in2p3.fr",
163     PIC => "pic.es",
164     T2_SP=> "ciemat.es",
165     RAL => "ral.ac.uk",
166     CERN => "cern.ch",
167     FZK => "fzk.de",
168     DESY => "desy.de",
169     NEBR => "unl.edu",
170     WISC => "wisc.edu",
171     UFL => "ufl.edu",
172     PURDUE => "purdue.edu",
173     UCSD => "ucsd.edu",
174     CALT => "ultralight.org"
175     };
176 gutsche 1.8
177 corvo 1.3 }
178 gutsche 1.1
179     # Find out how many jobs are pending for each site. This is
180     # insensitive to the job type, and we only check once in the
181     # beginning to avoid favouring one dataset over another --
182     # once we decide to proceed for a site, we submit jobs for
183     # all datasets.
184     sub getSiteStatus
185 gutsche 1.18 {
186 gutsche 1.1 my ($self) = @_;
187     my %result = ();
188     my $taskrepo = $self->{TASKREPO};
189     foreach my $site (<$taskrepo/*/*>)
190 gutsche 1.18 {
191 gutsche 1.1 my ($sitename) = ($site =~ m|.*/(.*)|);
192     foreach my $d (<$site/*/*>)
193 gutsche 1.18 {
194 gutsche 1.1 if (! -f "$d/JOB_CREATE_LOG.txt")
195 gutsche 1.18 {
196 gutsche 1.1 $result{$sitename}{C} ||= 0;
197     $result{$sitename}{C}++;
198     next;
199 gutsche 1.18 }
200    
201     my $f = (<$d/crab_*/share/db/jobs>)[0];
202     next if ! defined $f;
203    
204     foreach my $status (split(/\n/, &input($f) || ''))
205     {
206     my @statusarray = split("\;", $status);
207     $result{$sitename}{$statusarray[1]} ||= 0;
208     $result{$sitename}{$statusarray[1]}++;
209     }
210     }
211     }
212    
213 gutsche 1.1 return %result;
214 gutsche 1.18 }
215 gutsche 1.1
216     sub idle
217     {
218     my ($self, @pending) = @_;
219     eval {
220     # Get status of how busy the sites are. We obtain this only once
221     # in order to not favour datasets "early on" in the list.
222     my %sitestats = $self->getSiteStatus ();
223     if (keys %sitestats)
224     {
225     my @load;
226     foreach my $site (sort keys %sitestats)
227     {
228     push (@load, "$site" . join("", map { " $_=$sitestats{$site}{$_}" }
229     sort keys %{$sitestats{$site}}));
230     }
231     &logmsg ("current load: ", join ("; ", @load));
232     }
233    
234     # Invoke links to fetch a formatted web page of published datasets.
235     if ( $self->{MODE} == 2 ) {
236 gutsche 1.5 &logmsg ("DBS/DLS mode\n");
237     #my $cmd = "/localscratch/marco/CrabV1/COMP/JOBROBOT/DBSlistDataset.py";
238     my $cmd = $ENV{PYTHONSCRIPT} . "/DBSlistDataset.py";
239     open (PUBLISHED, "$cmd 2>/dev/null |") or die "cannot run `$cmd': $!\n";
240     while (<PUBLISHED>) {
241     chomp;
242     &timeStart($self->{STARTTIME});
243     # Find out what was published and what we would like to do with it
244     my $datapath = $_;
245     my ($n, $dataset, $datatier, $owner) = split(/\//, $_);
246     next if ($self->{DATASET} && $dataset !~ /$self->{DATASET}/);
247     next if ($self->{OWNER} && $owner !~ /$self->{OWNER}/);
248     #my $cmd = "/localscratch/marco/CrabV1/COMP/JOBROBOT/DLSInfo.py \"$_\" ";
249 gutsche 1.7 my $dlsinput = $owner . "/" . $dataset;
250     my $cmd = $ENV{PYTHONSCRIPT} . "/DLSInfo.py \"$dlsinput\" ";
251 gutsche 1.5 open(SITE, "$cmd 2>/dev/null |") or die "cannot run `$cmd': $!\n";
252     while (<SITE>){
253     &logmsg("$_");
254     my ($site, $events) = split(/\//, $_);
255     next if ($self->{SITE} && $site !~ /$self->{SITE}/);
256     next if ($self->{IGNORE_REGEXP} && $site =~ /$self->{IGNORE_REGEXP}/);
257     next if ($self->{ACCEPT_REGEXP} && $site !~ /$self->{ACCEPT_REGEXP}/);
258     my $whitelist = $site || '.';
259     $self->createTask($datapath, $site, $events, $whitelist, %sitestats);
260     }
261     }
262     } elsif ( $self->{MODE} == 3 ) {
263     &logmsg ("DBS/DLS CMSSW mode\n");
264     my $cmd = $ENV{PYTHONSCRIPT} . "/DBSInfo_EDM.py";
265     open (PUBLISHED, "$cmd 2>/dev/null |") or die "cannot run `$cmd': $!\n";
266     while (<PUBLISHED>) {
267     chomp;
268     &timeStart($self->{STARTTIME});
269     my ($datapath, $fileblock, $totalevents) = split(/ /, $_);
270 gutsche 1.14 my ($dummy,$tempdataset,$dummy2,$dummy3) = split(/\//, $datapath);
271 gutsche 1.15 next if ($self->{DATASET} && $tempdataset !~ /$self->{DATASET}/);
272 gutsche 1.5 my $cmd = $ENV{PYTHONSCRIPT} . "/DLSInfo.py \"$fileblock\" ";
273     open(SITE, "$cmd 2>/dev/null |") or die "cannot run `$cmd': $!\n";
274     while (<SITE>){
275     chomp;
276     my $site = $_;
277     next if ($self->{IGNORE_REGEXP} && $site =~ /$self->{IGNORE_REGEXP}/);
278     next if ($self->{ACCEPT_REGEXP} && $site !~ /$self->{ACCEPT_REGEXP}/);
279 gutsche 1.19 # read in siteconfig dynamically
280     if ( $self->{SITECONFIG} ) {
281     open(siteconfig_file,"$self->{SITECONFIG}");
282     my @line_array = <siteconfig_file>;
283     my $validsites = "(";
284     for (my $i = 0; $i < scalar @line_array; ++$i) {
285     if (defined $line_array[$i] ) {
286     if ( $line_array[$i] !~ /^#/ && $line_array[$i] !~ /^\n/ ) {
287 gutsche 1.20 my ($tempsite, $templimit) = split(/ /,$line_array[$i]);
288 gutsche 1.19 chomp($tempsite);
289     $validsites = $validsites . $tempsite . "|";
290     }
291     }
292     }
293     chop($validsites);
294     $validsites = $validsites . ")";
295     close siteconfig_file;
296     next if ($validsites && $site !~ /$validsites/);
297     }
298 gutsche 1.5 $self->createTaskCMSSW($datapath, $site, $totalevents, %sitestats);
299     }
300     }
301 gutsche 1.1 } else {
302 gutsche 1.4 &logmsg ("RefDB/PubDB mode");
303     my $cmd = "links @{$self->{LINKS_OPTS}} -dump '$self->{URL}'";
304     open (PUBLISHED, "$cmd 2>/dev/null |") or die "cannot run `$cmd': $!\n";
305     while (<PUBLISHED>)
306     {
307     &timeStart($self->{STARTTIME});
308     chomp; next if ! /_/; s/\|/ /g; s/^\s+//; s/\s+$//;
309 gutsche 1.1 # Find out what was published and what we would like to do with it
310 gutsche 1.4 my ($dataset, $owner, $events, $site, $proto) = split(/\s+/, $_);
311     $self->createTaskRefDBPubDB($dataset, $owner, $events, $site, 1, %sitestats);
312 gutsche 1.1 }
313     close (PUBLISHED);
314     }
315     };
316     do { chomp ($@); &alert ($@); } if $@;
317    
318     $self->nap ($self->{WAITTIME});
319     }
320    
321     sub createTask()
322     {
323 corvo 1.3 my ($self) = shift(@_);
324     my ($n, $dataset, $owner, $events, $site, $proto, %sitestats, $datapath, $datatier, $whitelist);
325     if (($self->{MODE}) == 1) {
326     ($dataset, $owner, $events, $site, $proto, $whitelist, %sitestats) = @_;
327     }
328     else {
329     ($datapath, $site, $events, $whitelist, %sitestats) = @_;
330     ($n, $dataset, $datatier, $owner) = split(/\//, $datapath);
331     }
332 gutsche 1.1
333 corvo 1.3 # my ($self, $datapath, $dataset, $datatier, $owner, $mode, %sitestats) = @_;
334 gutsche 1.1
335     my ($app, $tiers, $rc, $nevents, $output);
336     if ($dataset =~ /MBforPU/) {
337     next;
338     } elsif ($owner =~ /Hit/) {
339     $rc = "orcarc.read.simhits";
340     $app = "ExSimHitStatistics";
341     $tiers = "Hit";
342     $output = "simhits.aida";
343     } elsif ($owner =~ /DST/) {
344     if (rand(1) > 1.75) {
345 corvo 1.3 $rc = "orcarc.root.dst";
346     $app = "ExRootAnalysisDST";
347 gutsche 1.1 $output = "test.root";
348     } else {
349 corvo 1.3 $rc = "orcarc.read.dst";
350     $app = "ExDSTStatistics";
351 gutsche 1.1 $output = "dststatistics.aida";
352     }
353     $tiers = "DST,Digi,Hit";
354     } else {
355     if (rand(1) > 1.75) {
356 corvo 1.3 $rc = "orcarc.root.digis";
357     $app = "ExRootAnalysisDigi";
358 gutsche 1.1 $output = "test.root";
359     } else {
360 corvo 1.3 $rc = "orcarc.read.digis";
361     $app = "ExDigiStatistics";
362 gutsche 1.1 $output = "digistatistics.aida";
363     }
364 gutsche 1.5 if ($owner =~ m/nopu/i) {
365     $tiers = "Hit";
366     } else {
367     $tiers = "Digi,Hit";
368     }
369 gutsche 1.1 }
370    
371     # Find out what is already pending for this task. First find all
372     # existing tasks in the repository, the latest generation.
373     my $datestamp = strftime ("%y%m%d", gmtime(time()));
374 gutsche 1.5 my ($shortsite) = ( $site =~ /.(\w+).\w+$/ );
375     my $taskdir = "$self->{TASKREPO}/$datestamp/$shortsite/$app";
376 gutsche 1.1 # OLI: shorten path for condor_g (restriction to 256 characters)
377     # my $taskbase = "$datestamp.$site.$app.$dataset.$owner";
378 gutsche 1.5 my $taskbase = "$datestamp.$shortsite.$dataset.$owner";
379 gutsche 1.1 my @existing = sort { $a <=> $b } map { /.*\.(\d+)$/ } <$taskdir/$taskbase.*>;
380     my $curgen = pop(@existing) || 0;
381     my $nextgen = $curgen + 1;
382    
383     # If the site isn't too busy already, ignore.
384     my $pending = ($sitestats{$site}{S} || 0);
385     $pending += ($sitestats{$site}{C} || 0);
386     next if $pending > $self->{MAX_SITE_QUEUE};
387    
388     # OK to create the task if enough time has passed from previous
389     # task creation, or there is no previous task.
390     if (! -f "$taskdir/$taskbase.$curgen/crab.cfg"
391 corvo 1.3 || (((stat("$taskdir/$taskbase.$curgen/crab.cfg"))[9]
392     < time() - $events * $self->{SECS_PER_EVENT})))
393 gutsche 1.1 {
394 corvo 1.3 my $mydir = $0; $mydir =~ s|/[^/]+$||;
395     my $drop = sprintf("%s.%03d", $taskbase, $nextgen);
396     my $ret = &runcmd ("$mydir/CrabJobs", "-app", $app,
397     "-jobevents", $self->{NEVENT},
398     "-orcarc", "$mydir/$rc",
399     "-owner", $owner,
400     "-dataset", $dataset,
401     "-tiers", $tiers,
402     "-whitelist", $whitelist,
403     "-name", "$taskdir/$drop",
404     "-output", $output,
405     "-jobtype", $self->{JOBTYPE},
406     "-scheduler", $self->{SCHEDULER},
407     "-mode", $self->{MODE});
408     die "$drop: failed to create task: @{[&runerror($ret)]}\n" if $ret;
409 gutsche 1.1
410 corvo 1.3 &output ("$taskdir/$drop/TASK_INIT.txt",
411     &mytimeofday () . "\n");
412    
413     my $dropdir = "$self->{WORKDIR}/$drop";
414     mkdir "$dropdir" || die "$dropdir: cannot create: $!\n";
415     if (&output ("$dropdir/task", "$taskdir/$drop"))
416     {
417     &touch ("$dropdir/done");
418     $self->relayDrop ($drop);
419     &logmsg("stats: $drop @{[&formatElapsedTime($self->{STARTTIME})]} success");
420     }
421     else
422     {
423     &alert ("$drop: failed to create drop");
424     &rmtree ([ "$self->{WORKDIR}/$drop" ]);
425     }
426 gutsche 1.1 }
427     }
428 gutsche 1.4
429 gutsche 1.5 sub createTaskCMSSW()
430     {
431     my ($self) = shift(@_);
432     my ($datasetpath, $site, $totalevents, %sitestats) = @_;
433    
434     my($n, $dataset, $tier, $owner) = split(/\//, $datasetpath);
435    
436     my ($rc, $output);
437     if ($tier =~ /SIM/) {
438     $rc = "sim.cfg";
439     $output = "FrameworkJobReport.xml";
440     } elsif ($tier =~ /GEN/) {
441     $rc = "gen.cfg";
442     $output = "FrameworkJobReport.xml";
443     }
444    
445     # Find out what is already pending for this task. First find all
446     # existing tasks in the repository, the latest generation.
447     my $datestamp = strftime ("%y%m%d", gmtime(time()));
448     my $taskdir = "$self->{TASKREPO}/$datestamp/$site/$tier";
449     my $taskbase = "$datestamp.$site.$dataset.$tier.$owner";
450     my @existing = sort { $a <=> $b } map { /.*\.(\d+)$/ } <$taskdir/$taskbase.*>;
451     my $curgen = pop(@existing) || 0;
452     my $nextgen = $curgen + 1;
453    
454     # If the site isn't too busy already, ignore.
455     my $pending = ($sitestats{$site}{S} || 0);
456     $pending += ($sitestats{$site}{C} || 0);
457 gutsche 1.8 # take site specific or if not found default max site queue
458 gutsche 1.20 # read in from siteconfig file
459     my %sitelimits = ();
460     if ( $self->{SITECONFIG} ) {
461     open(siteconfig_file,"$self->{SITECONFIG}");
462     my @line_array = <siteconfig_file>;
463     for (my $i = 0; $i < scalar @line_array; ++$i) {
464     if (defined $line_array[$i] ) {
465     if ( $line_array[$i] !~ /^#/ && $line_array[$i] !~ /^\n/ ) {
466     my ($tempsite, $templimit) = split(/ /,$line_array[$i]);
467     chomp($tempsite);
468     chomp($templimit);
469     $sitelimits{$tempsite} = $templimit;
470     }
471     }
472     }
473     close siteconfig_file;
474     }
475     my $max_queue = $sitelimits{$site} || $self->{MAX_SITE_QUEUE};
476 gutsche 1.8 next if $pending > $max_queue;
477 gutsche 1.5
478     # OK to create the task if enough time has passed from previous
479     # task creation, or there is no previous task.
480     if (! -f "$taskdir/$taskbase.$curgen/crab.cfg"
481     || (((stat("$taskdir/$taskbase.$curgen/crab.cfg"))[9]
482     < time() - $totalevents * $self->{SECS_PER_EVENT})))
483     {
484     my $mydir = $0; $mydir =~ s|/[^/]+$||;
485     my $drop = sprintf("%s.%03d", $taskbase, $nextgen);
486     my $ret = &runcmd ("$mydir/CrabJobsCMSSW",
487     "-cfg", "$mydir/$rc",
488     "-datasetpath", $datasetpath,
489     "-output", $output,
490     "-totalevents", $totalevents,
491     "-whitelist", $site,
492     "-filesperjob", $self->{FILESPERJOB},
493     "-eventsperjob", $self->{NEVENT},
494     "-scheduler", $self->{SCHEDULER},
495     "-jobname", "$taskdir/$drop");
496     die "$drop: failed to create task: @{[&runerror($ret)]}\n" if $ret;
497    
498 gutsche 1.17 &output ("$taskdir/$drop/TASK_INIT.txt",
499 gutsche 1.5 &mytimeofday () . "\n");
500    
501     my $dropdir = "$self->{WORKDIR}/$drop";
502     mkdir "$dropdir" || die "$dropdir: cannot create: $!\n";
503     if (&output ("$dropdir/task", "$taskdir/$drop"))
504     {
505     &touch ("$dropdir/done");
506     $self->relayDrop ($drop);
507     &logmsg("stats: $drop @{[&formatElapsedTime($self->{STARTTIME})]} success");
508     }
509     else
510     {
511     &alert ("$drop: failed to create drop");
512     &rmtree ([ "$self->{WORKDIR}/$drop" ]);
513     }
514     }
515     }
516    
517 gutsche 1.4 sub createTaskRefDBPubDB()
518     {
519    
520     my ($self, $dataset, $owner, $events, $site, $mode, %sitestats) = @_;
521    
522     # Marco
523     next if ($self->{DATASET} && $dataset !~ /$self->{DATASET}/);
524     next if ($self->{OWNER} && $owner !~ /$self->{OWNER}/);
525     # Marco
526     my ($app, $tiers, $rc, $nevents, $output);
527     my $whitelist = $self->{WHITELIST}->{$site} || '.';
528     next if ($self->{IGNORE_REGEXP} && $site =~ /$self->{IGNORE_REGEXP}/);
529     next if ($self->{ACCEPT_REGEXP} && $site !~ /$self->{ACCEPT_REGEXP}/);
530     if ($dataset =~ /MBforPU/) {
531     next;
532     } elsif ($owner =~ /Hit/) {
533     $rc = "orcarc.read.simhits";
534     $app = "ExSimHitStatistics";
535     $tiers = "Hit";
536     $output = "simhits.aida";
537     } elsif ($owner =~ /DST/) {
538     next;
539     if (rand(1) > 1.75) {
540     $rc = "orcarc.root.dst";
541     $app = "ExRootAnalysisDST";
542     $output = "test.root";
543     } else {
544     $rc = "orcarc.read.dst";
545     $app = "ExDSTStatistics";
546     $output = "dststatistics.aida";
547     }
548     $tiers = "DST,Digi,Hit";
549     } else {
550     if (rand(1) > 1.75) {
551     $rc = "orcarc.root.digis";
552     $app = "ExRootAnalysisDigi";
553     $output = "test.root";
554     } else {
555     $rc = "orcarc.read.digis";
556     $app = "ExDigiStatistics";
557     $output = "digistatistics.aida";
558     }
559 gutsche 1.5 if ($owner =~ m/nopu/i) {
560     $tiers = "Hit";
561     } else {
562     $tiers = "Digi,Hit";
563     }
564 gutsche 1.4 }
565    
566     # Find out what is already pending for this task. First find all
567     # existing tasks in the repository, the latest generation.
568     my $datestamp = strftime ("%y%m%d", gmtime(time()));
569     my $taskdir = "$self->{TASKREPO}/$datestamp/$site/$app";
570     # OLI: shorten path for condor_g (restriction to 256 characters)
571     # my $taskbase = "$datestamp.$site.$app.$dataset.$owner";
572     my $taskbase = "$datestamp.$site.$dataset.$owner";
573     my @existing = sort { $a <=> $b } map { /.*\.(\d+)$/ } <$taskdir/$taskbase.*>;
574     my $curgen = pop(@existing) || 0;
575     my $nextgen = $curgen + 1;
576    
577     # If the site isn't too busy already, ignore.
578     my $pending = ($sitestats{$site}{S} || 0);
579     $pending += ($sitestats{$site}{C} || 0);
580     next if $pending > $self->{MAX_SITE_QUEUE};
581    
582     # OK to create the task if enough time has passed from previous
583     # task creation, or there is no previous task.
584     if (! -f "$taskdir/$taskbase.$curgen/crab.cfg"
585     || (((stat("$taskdir/$taskbase.$curgen/crab.cfg"))[9]
586     < time() - $events * $self->{SECS_PER_EVENT})))
587     {
588     my $mydir = $0; $mydir =~ s|/[^/]+$||;
589     my $drop = sprintf("%s.%03d", $taskbase, $nextgen);
590     my $ret = &runcmd ("$mydir/CrabJobs", "-app", $app,
591     "-jobevents", $self->{NEVENT},
592     "-orcarc", "$mydir/$rc",
593     "-owner", $owner,
594     "-dataset", $dataset,
595     "-tiers", $tiers,
596     "-whitelist", $whitelist,
597     "-name", "$taskdir/$drop",
598     "-output", $output,
599     "-jobtype", $self->{JOBTYPE},
600     "-scheduler", $self->{SCHEDULER},
601     "-mode", $mode);
602     die "$drop: failed to create task: @{[&runerror($ret)]}\n" if $ret;
603    
604     &output ("$taskdir/$drop/TASK_INIT.txt",
605     &mytimeofday () . "\n");
606    
607     my $dropdir = "$self->{WORKDIR}/$drop";
608     mkdir "$dropdir" || die "$dropdir: cannot create: $!\n";
609     if (&output ("$dropdir/task", "$taskdir/$drop"))
610     {
611     &touch ("$dropdir/done");
612     $self->relayDrop ($drop);
613     &logmsg("stats: $drop @{[&formatElapsedTime($self->{STARTTIME})]} success");
614     }
615     else
616     {
617     &alert ("$drop: failed to create drop");
618     &rmtree ([ "$self->{WORKDIR}/$drop" ]);
619     }
620     }
621     }