ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/JOBROBOT/TaskSource
Revision: 1.8
Committed: Sun Jul 2 22:16:00 2006 UTC (18 years, 9 months ago) by gutsche
Branch: MAIN
Changes since 1.7: +32 -2 lines
Log Message:
deactivated resubmission

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