Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 11:56:36

0001 #!/usr/bin/env perl
0002 #     G. Fluck, Uni Hamburg    13-May-2009
0003 #     $Revision: 1.3 $ by $Author: jbehr $
0004 #     $Date: 2012/09/10 13:10:37 $
0005 #
0006 #  Setup an extra pede
0007 #
0008 #  Usage:
0009 #
0010 #  mps_setupm.pl 
0011 
0012 BEGIN {
0013 use File::Basename;
0014 unshift(@INC, dirname($0)."/mpslib");
0015 }
0016 use Mpslib;
0017 
0018 my $chosenMerge = -1;
0019 my $onlyactivejobs = -1;
0020 my $ignoredisabledjobs = -1;
0021 
0022 ## parse the arguments
0023 my $i = 0;
0024 while (@ARGV) {
0025   $arg = shift(@ARGV);
0026   if ($arg =~ /\A-/) {  # check for option 
0027     if ($arg =~ "h") {
0028       $helpwanted = 1;
0029     }
0030     elsif ($arg =~ "a") {
0031       $onlyactivejobs = 1;
0032     }
0033     elsif ($arg =~ "d") {
0034       $ignoredisabledjobs = 1;
0035     }
0036     else {
0037     print "\nWARNING: Unknown option: ".$arg."\n\n";
0038     $helpwanted = 1;
0039     }
0040 #    elsif ($arg =~ "u") {
0041 #      $updateDb = 1;
0042   }
0043   else {  # parameters not related to options
0044     $i = $i + 1;
0045     if ($i eq 1) {
0046     $chosenMerge = $arg;
0047     if ($chosenMerge < 0) { # not allowed (but probably interpreted as option before...)!
0048         $helpwanted = 1;
0049     }
0050     }
0051 #    if ($i eq 2) {
0052 #      $cfgTemplate = $arg;
0053 #    }
0054   }
0055 }
0056 
0057 
0058 if ( $helpwanted != 0 ) {
0059   print "Usage:\n  mps_setupm.pl [options] [mergeJobId]";
0060   print "\nDescription:\n  Sets up an additional merge job (so needs a setup merge job).";
0061   print "\n  Configuration is copied from";
0062   print "\n    - last previous merge job if 'mergeJobId' is NOT specified,";
0063   print "\n    - job directory 'jobm<mergeJobId>' otherwise (so: mergeJobId >= 0).";
0064   print "\n  Do not forget to edit the configuration file starting the new job.";
0065   print "\nKnown options:";
0066   print "\n  -h   This help.\n";
0067   print "\n  -a   Use only active jobs (jobs with state = 'ok').\n";
0068   print "\n  -d   Ignore disabled jobs.\n";
0069 
0070   exit 1;
0071 }
0072 
0073 read_db();
0074 
0075 # check for existing merge job?
0076 if ($driver ne "merge") {
0077     print "Needs previously setup merge job.\n";
0078     exit 1;
0079 }
0080 
0081 my $iOldMerge = @JOBDIR-1; # merge job where to copy from: here default to last one
0082 if ($chosenMerge >= 0) {
0083     $iOldMerge = $nJobs + $chosenMerge; # nJobs counts mille jobs
0084 }
0085 if ($iOldMerge >= @JOBDIR) {
0086     print "Cannot find previous merge job, exit!\n";
0087     exit 1;
0088 }
0089 my $nMerge = @JOBDIR - $nJobs; # 'index' of this merge job to achieve jobm, jobm1, jobm2, ...
0090 
0091 # add a new merge job entry. 
0092 $theJobDir = "jobm".$nMerge;
0093 push @JOBDIR,$theJobDir;
0094 push @JOBID,"";
0095 push @JOBSTATUS,"SETUP";
0096 push @JOBNTRY,0;
0097 push @JOBRUNTIME,0;
0098 push @JOBNEVT,0;
0099 push @JOBHOST,"";
0100 push @JOBINCR,0;
0101 push @JOBREMARK,"";
0102 push @JOBSP1,"";
0103 push @JOBSP2,"";
0104 push @JOBSP3,"";
0105 
0106 # create the directory and set up contents
0107 print "Create dir jobData/$theJobDir\n";
0108 system "rm -rf jobData/$theJobDir";
0109 system "mkdir jobData/$theJobDir";
0110 system "ln -s `readlink -e .TrackerTree.root` jobData/$theJobDir/";
0111 
0112 # build the absolute job directory path (needed by mps_scriptm)
0113 $thePwd = `pwd`;
0114 chomp $thePwd;
0115 $theJobData = "$thePwd/jobData";
0116 
0117 # copy merge job cfg from last merge job
0118 print "cp -p jobData/$JOBDIR[$iOldMerge]/alignment_merge.py $theJobData/$theJobDir\n";
0119 system "cp -p jobData/$JOBDIR[$iOldMerge]/alignment_merge.py $theJobData/$theJobDir";
0120 
0121 # copy weights configuration from last merge job
0122 system "cp -p jobData/$JOBDIR[$iOldMerge]/.weights.pkl $theJobData/$theJobDir";
0123 
0124 my $tmpc = "";
0125 $tmpc = " -c" if($onlyactivejobs == 1);
0126 
0127 # create merge job script
0128 print "mps_scriptm.pl${tmpc} $mergeScript jobData/$theJobDir/theScript.sh $theJobData/$theJobDir alignment_merge.py $nJobs $mssDir $mssDirPool\n";
0129 system "mps_scriptm.pl${tmpc} $mergeScript jobData/$theJobDir/theScript.sh $theJobData/$theJobDir alignment_merge.py $nJobs $mssDir $mssDirPool";
0130 
0131 # Write to DB
0132 write_db();
0133 
0134 if($onlyactivejobs == 1 || $ignoredisabledjobs == 1) {
0135   print "try to open <$theJobData/$theJobDir/alignment_merge.py\n";
0136   open INFILE,"$theJobData/$theJobDir/alignment_merge.py" || die "error: $!\n";
0137   undef $/;
0138   my $filebody = <INFILE>;  # read whole file
0139   close INFILE;
0140   # build list of binary files
0141   my $binaryList = "";
0142   my $iIsOk = 1;
0143   for (my $i=1; $i<=$nJobs; ++$i) {
0144     my $sep = ",\n                ";
0145     if ($iIsOk == 1) { $sep = "\n                " ;}
0146 
0147     next if ( $ignoredisabledjobs == 1 && $JOBSTATUS[$i-1] =~ /DISABLED/gi );
0148     next if ( $onlyactivejobs == 1 && $JOBSTATUS[$i-1] ne "OK");
0149     ++$iIsOk;
0150 
0151     my $newName = sprintf "milleBinary%03d.dat",$i;
0152     if($JOBSP2[$i-1] ne "" && defined $JOBSP2[$i-1])
0153       {
0154         my $weight = $JOBSP2[$i-1];
0155         print "Adding $newName to list of binary files using weight $weight\n";
0156         $binaryList = "$binaryList$sep\'$newName -- $weight\'";
0157       }
0158     else
0159       {
0160         print "Adding $newName to list of binary files\n";
0161         $binaryList = "$binaryList$sep\'$newName\'";
0162       }
0163 
0164    # print "Adding $newName to list of binary files\n";
0165    # $binaryList = "$binaryList$sep\'$newName\'";
0166   }
0167   my $nn  = ($filebody =~ s/mergeBinaryFiles\s*=\s*\[(.|\n)*?\]/mergeBinaryFiles = \[$binaryList\]/);
0168   $nn += ($filebody =~ s/mergeBinaryFiles = cms.vstring\(\)/mergeBinaryFiles = \[$binaryList\]/);
0169   # build list of tree files
0170   my $treeList = "";
0171   $iIsOk = 1;
0172   for (my $i=1; $i<=$nJobs; ++$i) {
0173     my $sep = ",\n                ";
0174     if ($iIsOk == 1) { $sep = "\n                " ;}
0175     next if ( $ignoredisabledjobs == 1 && $JOBSTATUS[$i-1] =~ /DISABLED/gi );
0176     if ($JOBSTATUS[$i-1] ne "OK" && $onlyactivejobs == 1) {next;}
0177     ++$iIsOk;
0178     my $newName = sprintf "treeFile%03d.root",$i;
0179     $treeList = "$treeList$sep\'$newName\'";
0180   }
0181   # replace list of tree files
0182   $nn = ($filebody =~ s/mergeTreeFiles\s*=\s*\[(.|\n)*?\]/mergeTreeFiles = \[$treeList\]/);
0183   #print "$filebody\n";
0184   # store the output file
0185   open OUTFILE,">$theJobData/$theJobDir/alignment_merge.py";
0186   print OUTFILE $filebody;
0187   close OUTFILE;
0188 }