ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/JOBROBOT/TaskSource
Revision: 1.11
Committed: Mon Jul 3 19:53:44 2006 UTC (18 years, 9 months ago) by gutsche
Branch: MAIN
Changes since 1.10: +2 -1 lines
Log Message:
added RAL to Robot2

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