ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/JOBROBOT/TaskSource
Revision: 1.6
Committed: Fri Jun 9 14:34:59 2006 UTC (18 years, 10 months ago) by gutsche
Branch: MAIN
Changes since 1.5: +2 -1 lines
Log Message:
fixed old edm DBS/DLS mode with new MySQL API (change order of dataset and owner and discard datatier in DLS query, added test

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