ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/JOBROBOT/TaskSource
Revision: 1.10
Committed: Mon Jul 3 15:50:34 2006 UTC (18 years, 9 months ago) by gutsche
Branch: MAIN
Changes since 1.9: +2 -2 lines
Log Message:
changed limit for DESY and Estonia to 500

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