ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/JOBROBOT/TaskSource
Revision: 1.12
Committed: Thu Jul 6 18:53:22 2006 UTC (18 years, 9 months ago) by gutsche
Branch: MAIN
Changes since 1.11: +3 -1 lines
Log Message:
added London_IC_HEP and Purdue to site specific limit list

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 gutsche 1.9 $self->{SITEMAXQUEUE} = { "cmslcgce.fnal.gov" => 500,
175     "ce01.cmsaf.mit.edu" => 200,
176     "ce04.pic.es" => 500,
177     "red.unl.edu" => 200,
178 gutsche 1.10 "oberon.hep.kbfi.ee" => 500,
179 gutsche 1.9 "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 gutsche 1.10 "grid-ce1.desy.de" => 500,
189 gutsche 1.9 "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 gutsche 1.11 "ce-fzk.gridka.de" => 500,
200 gutsche 1.12 "lcgce01.gridpp.rl.ac.uk" => 500,
201     "gw39.hep.ph.ic.ac.uk" => 200,
202     "lepton.rcac.purdue.edu" => 200 }
203 gutsche 1.8
204 corvo 1.3 }
205 gutsche 1.1
206     # Find out how many jobs are pending for each site. This is
207     # insensitive to the job type, and we only check once in the
208     # beginning to avoid favouring one dataset over another --
209     # once we decide to proceed for a site, we submit jobs for
210     # all datasets.
211     sub getSiteStatus
212     {
213     my ($self) = @_;
214     my %result = ();
215     my $taskrepo = $self->{TASKREPO};
216     foreach my $site (<$taskrepo/*/*>)
217     {
218     my ($sitename) = ($site =~ m|.*/(.*)|);
219     foreach my $d (<$site/*/*>)
220     {
221     if (! -f "$d/JOB_CREATE_LOG.txt")
222     {
223     $result{$sitename}{C} ||= 0;
224     $result{$sitename}{C}++;
225     next;
226     }
227    
228     my $f = (<$d/crab_*/share/db/jobs>)[0];
229     next if ! defined $f;
230    
231     foreach my $status (split(/\n/, &input($f) || ''))
232     {
233     my @statusarray = split("\;", $status);
234     $result{$sitename}{$statusarray[1]} ||= 0;
235     $result{$sitename}{$statusarray[1]}++;
236     }
237     }
238     }
239    
240     return %result;
241     }
242    
243     sub idle
244     {
245     my ($self, @pending) = @_;
246     eval {
247     # Get status of how busy the sites are. We obtain this only once
248     # in order to not favour datasets "early on" in the list.
249     my %sitestats = $self->getSiteStatus ();
250     if (keys %sitestats)
251     {
252     my @load;
253     foreach my $site (sort keys %sitestats)
254     {
255     push (@load, "$site" . join("", map { " $_=$sitestats{$site}{$_}" }
256     sort keys %{$sitestats{$site}}));
257     }
258     &logmsg ("current load: ", join ("; ", @load));
259     }
260    
261     # Invoke links to fetch a formatted web page of published datasets.
262     if ( $self->{MODE} == 2 ) {
263 gutsche 1.5 &logmsg ("DBS/DLS mode\n");
264     #my $cmd = "/localscratch/marco/CrabV1/COMP/JOBROBOT/DBSlistDataset.py";
265     my $cmd = $ENV{PYTHONSCRIPT} . "/DBSlistDataset.py";
266     open (PUBLISHED, "$cmd 2>/dev/null |") or die "cannot run `$cmd': $!\n";
267     while (<PUBLISHED>) {
268     chomp;
269     &timeStart($self->{STARTTIME});
270     # Find out what was published and what we would like to do with it
271     my $datapath = $_;
272     my ($n, $dataset, $datatier, $owner) = split(/\//, $_);
273     next if ($self->{DATASET} && $dataset !~ /$self->{DATASET}/);
274     next if ($self->{OWNER} && $owner !~ /$self->{OWNER}/);
275     #my $cmd = "/localscratch/marco/CrabV1/COMP/JOBROBOT/DLSInfo.py \"$_\" ";
276 gutsche 1.7 my $dlsinput = $owner . "/" . $dataset;
277     my $cmd = $ENV{PYTHONSCRIPT} . "/DLSInfo.py \"$dlsinput\" ";
278 gutsche 1.5 open(SITE, "$cmd 2>/dev/null |") or die "cannot run `$cmd': $!\n";
279     while (<SITE>){
280     &logmsg("$_");
281     my ($site, $events) = split(/\//, $_);
282     next if ($self->{SITE} && $site !~ /$self->{SITE}/);
283     next if ($self->{IGNORE_REGEXP} && $site =~ /$self->{IGNORE_REGEXP}/);
284     next if ($self->{ACCEPT_REGEXP} && $site !~ /$self->{ACCEPT_REGEXP}/);
285     my $whitelist = $site || '.';
286     $self->createTask($datapath, $site, $events, $whitelist, %sitestats);
287     }
288     }
289     } elsif ( $self->{MODE} == 3 ) {
290     &logmsg ("DBS/DLS CMSSW mode\n");
291     my $cmd = $ENV{PYTHONSCRIPT} . "/DBSInfo_EDM.py";
292     open (PUBLISHED, "$cmd 2>/dev/null |") or die "cannot run `$cmd': $!\n";
293     while (<PUBLISHED>) {
294     chomp;
295     &timeStart($self->{STARTTIME});
296     my ($datapath, $fileblock, $totalevents) = split(/ /, $_);
297     my $cmd = $ENV{PYTHONSCRIPT} . "/DLSInfo.py \"$fileblock\" ";
298     open(SITE, "$cmd 2>/dev/null |") or die "cannot run `$cmd': $!\n";
299     while (<SITE>){
300     chomp;
301     my $site = $_;
302     next if ($self->{IGNORE_REGEXP} && $site =~ /$self->{IGNORE_REGEXP}/);
303     next if ($self->{ACCEPT_REGEXP} && $site !~ /$self->{ACCEPT_REGEXP}/);
304     $self->createTaskCMSSW($datapath, $site, $totalevents, %sitestats);
305     }
306     }
307 gutsche 1.1 } else {
308 gutsche 1.4 &logmsg ("RefDB/PubDB mode");
309     my $cmd = "links @{$self->{LINKS_OPTS}} -dump '$self->{URL}'";
310     open (PUBLISHED, "$cmd 2>/dev/null |") or die "cannot run `$cmd': $!\n";
311     while (<PUBLISHED>)
312     {
313     &timeStart($self->{STARTTIME});
314     chomp; next if ! /_/; s/\|/ /g; s/^\s+//; s/\s+$//;
315 gutsche 1.1 # Find out what was published and what we would like to do with it
316 gutsche 1.4 my ($dataset, $owner, $events, $site, $proto) = split(/\s+/, $_);
317     $self->createTaskRefDBPubDB($dataset, $owner, $events, $site, 1, %sitestats);
318 gutsche 1.1 }
319     close (PUBLISHED);
320     }
321     };
322     do { chomp ($@); &alert ($@); } if $@;
323    
324     $self->nap ($self->{WAITTIME});
325     }
326    
327     sub createTask()
328     {
329 corvo 1.3 my ($self) = shift(@_);
330     my ($n, $dataset, $owner, $events, $site, $proto, %sitestats, $datapath, $datatier, $whitelist);
331     if (($self->{MODE}) == 1) {
332     ($dataset, $owner, $events, $site, $proto, $whitelist, %sitestats) = @_;
333     }
334     else {
335     ($datapath, $site, $events, $whitelist, %sitestats) = @_;
336     ($n, $dataset, $datatier, $owner) = split(/\//, $datapath);
337     }
338 gutsche 1.1
339 corvo 1.3 # my ($self, $datapath, $dataset, $datatier, $owner, $mode, %sitestats) = @_;
340 gutsche 1.1
341     my ($app, $tiers, $rc, $nevents, $output);
342     if ($dataset =~ /MBforPU/) {
343     next;
344     } elsif ($owner =~ /Hit/) {
345     $rc = "orcarc.read.simhits";
346     $app = "ExSimHitStatistics";
347     $tiers = "Hit";
348     $output = "simhits.aida";
349     } elsif ($owner =~ /DST/) {
350     if (rand(1) > 1.75) {
351 corvo 1.3 $rc = "orcarc.root.dst";
352     $app = "ExRootAnalysisDST";
353 gutsche 1.1 $output = "test.root";
354     } else {
355 corvo 1.3 $rc = "orcarc.read.dst";
356     $app = "ExDSTStatistics";
357 gutsche 1.1 $output = "dststatistics.aida";
358     }
359     $tiers = "DST,Digi,Hit";
360     } else {
361     if (rand(1) > 1.75) {
362 corvo 1.3 $rc = "orcarc.root.digis";
363     $app = "ExRootAnalysisDigi";
364 gutsche 1.1 $output = "test.root";
365     } else {
366 corvo 1.3 $rc = "orcarc.read.digis";
367     $app = "ExDigiStatistics";
368 gutsche 1.1 $output = "digistatistics.aida";
369     }
370 gutsche 1.5 if ($owner =~ m/nopu/i) {
371     $tiers = "Hit";
372     } else {
373     $tiers = "Digi,Hit";
374     }
375 gutsche 1.1 }
376    
377     # Find out what is already pending for this task. First find all
378     # existing tasks in the repository, the latest generation.
379     my $datestamp = strftime ("%y%m%d", gmtime(time()));
380 gutsche 1.5 my ($shortsite) = ( $site =~ /.(\w+).\w+$/ );
381     my $taskdir = "$self->{TASKREPO}/$datestamp/$shortsite/$app";
382 gutsche 1.1 # OLI: shorten path for condor_g (restriction to 256 characters)
383     # my $taskbase = "$datestamp.$site.$app.$dataset.$owner";
384 gutsche 1.5 my $taskbase = "$datestamp.$shortsite.$dataset.$owner";
385 gutsche 1.1 my @existing = sort { $a <=> $b } map { /.*\.(\d+)$/ } <$taskdir/$taskbase.*>;
386     my $curgen = pop(@existing) || 0;
387     my $nextgen = $curgen + 1;
388    
389     # If the site isn't too busy already, ignore.
390     my $pending = ($sitestats{$site}{S} || 0);
391     $pending += ($sitestats{$site}{C} || 0);
392     next if $pending > $self->{MAX_SITE_QUEUE};
393    
394     # OK to create the task if enough time has passed from previous
395     # task creation, or there is no previous task.
396     if (! -f "$taskdir/$taskbase.$curgen/crab.cfg"
397 corvo 1.3 || (((stat("$taskdir/$taskbase.$curgen/crab.cfg"))[9]
398     < time() - $events * $self->{SECS_PER_EVENT})))
399 gutsche 1.1 {
400 corvo 1.3 my $mydir = $0; $mydir =~ s|/[^/]+$||;
401     my $drop = sprintf("%s.%03d", $taskbase, $nextgen);
402     my $ret = &runcmd ("$mydir/CrabJobs", "-app", $app,
403     "-jobevents", $self->{NEVENT},
404     "-orcarc", "$mydir/$rc",
405     "-owner", $owner,
406     "-dataset", $dataset,
407     "-tiers", $tiers,
408     "-whitelist", $whitelist,
409     "-name", "$taskdir/$drop",
410     "-output", $output,
411     "-jobtype", $self->{JOBTYPE},
412     "-scheduler", $self->{SCHEDULER},
413     "-mode", $self->{MODE});
414     die "$drop: failed to create task: @{[&runerror($ret)]}\n" if $ret;
415 gutsche 1.1
416 corvo 1.3 &output ("$taskdir/$drop/TASK_INIT.txt",
417     &mytimeofday () . "\n");
418    
419     my $dropdir = "$self->{WORKDIR}/$drop";
420     mkdir "$dropdir" || die "$dropdir: cannot create: $!\n";
421     if (&output ("$dropdir/task", "$taskdir/$drop"))
422     {
423     &touch ("$dropdir/done");
424     $self->relayDrop ($drop);
425     &logmsg("stats: $drop @{[&formatElapsedTime($self->{STARTTIME})]} success");
426     }
427     else
428     {
429     &alert ("$drop: failed to create drop");
430     &rmtree ([ "$self->{WORKDIR}/$drop" ]);
431     }
432 gutsche 1.1 }
433     }
434 gutsche 1.4
435 gutsche 1.5 sub createTaskCMSSW()
436     {
437     my ($self) = shift(@_);
438     my ($datasetpath, $site, $totalevents, %sitestats) = @_;
439    
440     my($n, $dataset, $tier, $owner) = split(/\//, $datasetpath);
441    
442     my ($rc, $output);
443     if ($tier =~ /SIM/) {
444     $rc = "sim.cfg";
445     $output = "FrameworkJobReport.xml";
446     } elsif ($tier =~ /GEN/) {
447     $rc = "gen.cfg";
448     $output = "FrameworkJobReport.xml";
449     }
450    
451     # Find out what is already pending for this task. First find all
452     # existing tasks in the repository, the latest generation.
453     my $datestamp = strftime ("%y%m%d", gmtime(time()));
454     my $taskdir = "$self->{TASKREPO}/$datestamp/$site/$tier";
455     my $taskbase = "$datestamp.$site.$dataset.$tier.$owner";
456     my @existing = sort { $a <=> $b } map { /.*\.(\d+)$/ } <$taskdir/$taskbase.*>;
457     my $curgen = pop(@existing) || 0;
458     my $nextgen = $curgen + 1;
459    
460     # If the site isn't too busy already, ignore.
461     my $pending = ($sitestats{$site}{S} || 0);
462     $pending += ($sitestats{$site}{C} || 0);
463 gutsche 1.8 # take site specific or if not found default max site queue
464     my $max_queue = $self->{SITEMAXQUEUE}->{$site} || $self->{MAX_SITE_QUEUE};
465     next if $pending > $max_queue;
466 gutsche 1.5
467     # OK to create the task if enough time has passed from previous
468     # task creation, or there is no previous task.
469     if (! -f "$taskdir/$taskbase.$curgen/crab.cfg"
470     || (((stat("$taskdir/$taskbase.$curgen/crab.cfg"))[9]
471     < time() - $totalevents * $self->{SECS_PER_EVENT})))
472     {
473     my $mydir = $0; $mydir =~ s|/[^/]+$||;
474     my $drop = sprintf("%s.%03d", $taskbase, $nextgen);
475     my $ret = &runcmd ("$mydir/CrabJobsCMSSW",
476     "-cfg", "$mydir/$rc",
477     "-datasetpath", $datasetpath,
478     "-output", $output,
479     "-totalevents", $totalevents,
480     "-whitelist", $site,
481     "-filesperjob", $self->{FILESPERJOB},
482     "-eventsperjob", $self->{NEVENT},
483     "-scheduler", $self->{SCHEDULER},
484     "-jobname", "$taskdir/$drop");
485     die "$drop: failed to create task: @{[&runerror($ret)]}\n" if $ret;
486    
487     &output ("$taskdir/$drop/TASK_INIT.txt",
488     &mytimeofday () . "\n");
489    
490     my $dropdir = "$self->{WORKDIR}/$drop";
491     mkdir "$dropdir" || die "$dropdir: cannot create: $!\n";
492     if (&output ("$dropdir/task", "$taskdir/$drop"))
493     {
494     &touch ("$dropdir/done");
495     $self->relayDrop ($drop);
496     &logmsg("stats: $drop @{[&formatElapsedTime($self->{STARTTIME})]} success");
497     }
498     else
499     {
500     &alert ("$drop: failed to create drop");
501     &rmtree ([ "$self->{WORKDIR}/$drop" ]);
502     }
503     }
504     }
505    
506 gutsche 1.4 sub createTaskRefDBPubDB()
507     {
508    
509     my ($self, $dataset, $owner, $events, $site, $mode, %sitestats) = @_;
510    
511     # Marco
512     next if ($self->{DATASET} && $dataset !~ /$self->{DATASET}/);
513     next if ($self->{OWNER} && $owner !~ /$self->{OWNER}/);
514     # Marco
515     my ($app, $tiers, $rc, $nevents, $output);
516     my $whitelist = $self->{WHITELIST}->{$site} || '.';
517     next if ($self->{IGNORE_REGEXP} && $site =~ /$self->{IGNORE_REGEXP}/);
518     next if ($self->{ACCEPT_REGEXP} && $site !~ /$self->{ACCEPT_REGEXP}/);
519     if ($dataset =~ /MBforPU/) {
520     next;
521     } elsif ($owner =~ /Hit/) {
522     $rc = "orcarc.read.simhits";
523     $app = "ExSimHitStatistics";
524     $tiers = "Hit";
525     $output = "simhits.aida";
526     } elsif ($owner =~ /DST/) {
527     next;
528     if (rand(1) > 1.75) {
529     $rc = "orcarc.root.dst";
530     $app = "ExRootAnalysisDST";
531     $output = "test.root";
532     } else {
533     $rc = "orcarc.read.dst";
534     $app = "ExDSTStatistics";
535     $output = "dststatistics.aida";
536     }
537     $tiers = "DST,Digi,Hit";
538     } else {
539     if (rand(1) > 1.75) {
540     $rc = "orcarc.root.digis";
541     $app = "ExRootAnalysisDigi";
542     $output = "test.root";
543     } else {
544     $rc = "orcarc.read.digis";
545     $app = "ExDigiStatistics";
546     $output = "digistatistics.aida";
547     }
548 gutsche 1.5 if ($owner =~ m/nopu/i) {
549     $tiers = "Hit";
550     } else {
551     $tiers = "Digi,Hit";
552     }
553 gutsche 1.4 }
554    
555     # Find out what is already pending for this task. First find all
556     # existing tasks in the repository, the latest generation.
557     my $datestamp = strftime ("%y%m%d", gmtime(time()));
558     my $taskdir = "$self->{TASKREPO}/$datestamp/$site/$app";
559     # OLI: shorten path for condor_g (restriction to 256 characters)
560     # my $taskbase = "$datestamp.$site.$app.$dataset.$owner";
561     my $taskbase = "$datestamp.$site.$dataset.$owner";
562     my @existing = sort { $a <=> $b } map { /.*\.(\d+)$/ } <$taskdir/$taskbase.*>;
563     my $curgen = pop(@existing) || 0;
564     my $nextgen = $curgen + 1;
565    
566     # If the site isn't too busy already, ignore.
567     my $pending = ($sitestats{$site}{S} || 0);
568     $pending += ($sitestats{$site}{C} || 0);
569     next if $pending > $self->{MAX_SITE_QUEUE};
570    
571     # OK to create the task if enough time has passed from previous
572     # task creation, or there is no previous task.
573     if (! -f "$taskdir/$taskbase.$curgen/crab.cfg"
574     || (((stat("$taskdir/$taskbase.$curgen/crab.cfg"))[9]
575     < time() - $events * $self->{SECS_PER_EVENT})))
576     {
577     my $mydir = $0; $mydir =~ s|/[^/]+$||;
578     my $drop = sprintf("%s.%03d", $taskbase, $nextgen);
579     my $ret = &runcmd ("$mydir/CrabJobs", "-app", $app,
580     "-jobevents", $self->{NEVENT},
581     "-orcarc", "$mydir/$rc",
582     "-owner", $owner,
583     "-dataset", $dataset,
584     "-tiers", $tiers,
585     "-whitelist", $whitelist,
586     "-name", "$taskdir/$drop",
587     "-output", $output,
588     "-jobtype", $self->{JOBTYPE},
589     "-scheduler", $self->{SCHEDULER},
590     "-mode", $mode);
591     die "$drop: failed to create task: @{[&runerror($ret)]}\n" if $ret;
592    
593     &output ("$taskdir/$drop/TASK_INIT.txt",
594     &mytimeofday () . "\n");
595    
596     my $dropdir = "$self->{WORKDIR}/$drop";
597     mkdir "$dropdir" || die "$dropdir: cannot create: $!\n";
598     if (&output ("$dropdir/task", "$taskdir/$drop"))
599     {
600     &touch ("$dropdir/done");
601     $self->relayDrop ($drop);
602     &logmsg("stats: $drop @{[&formatElapsedTime($self->{STARTTIME})]} success");
603     }
604     else
605     {
606     &alert ("$drop: failed to create drop");
607     &rmtree ([ "$self->{WORKDIR}/$drop" ]);
608     }
609     }
610     }