Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-10-25 09:32:17

0001 #!/usr/bin/env perl
0002 #     R. Mankel, DESY Hamburg     06-Jul-2007
0003 #     A. Parenti, DESY Hamburg    27-Mar-2008
0004 #     $Revision: 1.8 $
0005 #     $Date: 2011/06/15 14:51:45 $
0006 #
0007 #  Prepare the run script for the merge job.
0008 #  The main action is to embed the output directory
0009 #  into the script
0010 #
0011 #  Usage:
0012 #
0013 #  mps_scriptm.pl [-c] inScript outScript runDir cfgName njobs mssDir \
0014 #  [CastorPool]
0015 #
0016 
0017 BEGIN {
0018 use File::Basename;
0019 unshift(@INC, dirname($0)."/mpslib");
0020 }
0021 use Mpslib;
0022 use POSIX;
0023 
0024 $inScript = "undefined";
0025 $outScript = "undefined";
0026 $runDir = "undefined";
0027 $cfgName = "undefined";
0028 $nJobs = "undefined";
0029 $mssDirLocal = "undefined"; # not to confuse with mssDir from 'mpslib'.
0030 $castorPool = "undefined";
0031 
0032 
0033 # parse the arguments
0034 while (@ARGV) {
0035   $arg = shift(@ARGV);
0036   if ($arg =~ /\A-/) {  # check for option 
0037     if ($arg =~ "h") {
0038       $helpwanted = 1;
0039     }
0040     elsif ($arg =~ "c") {
0041 # Check which jobs are "OK" and write just them to the cfg file
0042       $checkok = 1;
0043     }
0044     elsif ($arg =~ "d") {
0045       $localdir = 1;
0046     }
0047     elsif ($arg =~ "u") {
0048       $updateDb = 1;
0049     }
0050     $optionstring = "$optionstring$arg";
0051   }
0052   else {                # parameters not related to options
0053     $i = $i + 1;
0054     if ($i eq 1) {
0055       $inScript = $arg;
0056     }
0057     elsif ($i eq 2) {
0058       $outScript = $arg;
0059     }
0060     elsif ($i eq 3) {
0061       $runDir = $arg;
0062     }
0063     elsif ($i eq 4) {
0064       $cfgName = $arg;
0065     }
0066     elsif ($i eq 5) {
0067       $nJobs = $arg;
0068     }
0069     elsif ($i eq 6) {
0070       $mssDirLocal = $arg;
0071     }
0072     elsif ($i eq 7) {
0073       $castorPool = $arg;
0074     }
0075   }
0076 }
0077 
0078 if ($cfgName eq "undefined") {
0079   print "Insufficient information given\n";
0080   exit 1;
0081 }
0082 
0083 if ($checkok == 1) {
0084   read_db();
0085 }
0086 
0087 # open the input file
0088 open INFILE,"$inScript";
0089 undef $/;  # undefining the INPUT-RECORD_SEPARATOR means slurp whole file
0090 $body = <INFILE>;  # read whole file
0091 close INFILE;
0092 $/ = "\n"; # back to normal
0093 
0094 # replace RUNDIR setting
0095 $nn = ($body =~ m/RUNDIR=(.+)$/m);
0096 if ($nn != 1) {
0097   print "mps_script.pl: no (unambiguous) RUNDIR directive found in runscript\n";
0098   exit 1;
0099 }
0100 $nn = ($body =~ s/RUNDIR=(.+)$/RUNDIR=$runDir/m);
0101 
0102 # replace the cfg name
0103 $nn = ($body =~ s/CONFIG_FILE=(.*)$/CONFIG_FILE=\$RUNDIR\/$cfgName/m);
0104 if ($nn <1) {
0105   print "Warning: mps_script matches cfg: $nn\n";
0106 }
0107 
0108 #replace CMSSW_RELEASE_AREA with evironment variable
0109 $body =~ s/cd\s+CMSSW_RELEASE_AREA/cd $ENV{'CMSSW_BASE'}/g;
0110 
0111 # replace MSSDIR setting
0112 $nn = ($body =~ m/MSSDIR=(.+)$/m);
0113 if ($nn != 1) {
0114   print "mps_script.pl: no (unambiguous) MSSDIR directive found in runscript\n";
0115 }
0116 $nn = ($body =~ s/MSSDIR=(.+)$/MSSDIR=$mssDirLocal/m);
0117 
0118 if ($castorPool ne "undefined") {
0119 # replace MSSDIRPOOL setting...
0120   $nn = ($body =~ s/MSSDIRPOOL=(.*)$/MSSDIRPOOL=$castorPool/m);
0121 } else {
0122 #... or empty the field.
0123   $nn = ($body =~ s/MSSDIRPOOL=(.*)$/MSSDIRPOOL=/m);
0124 }
0125 
0126 # now we have to expand lines that contain the ISN directive
0127 @LINES = split "\n",$body;
0128 
0129 foreach $theLine (@LINES) {
0130   if ($theLine =~ m/ISN/) {
0131     $newBlock = "";
0132     for ($i = 1; $i <= $nJobs; ++$i) {
0133 
0134       if ($checkok==1 && @JOBSTATUS[$i-1] ne "OK") {next;}
0135 
0136       $newLine = $theLine;
0137       $isnRep = sprintf "%03d",$i;
0138       $newLine =~ s/ISN/$isnRep/g;
0139       if ($i != 1) { $newBlock = $newBlock . "\n"; }
0140       $newBlock = $newBlock . $newLine;
0141     }
0142     $theLine = $newBlock;
0143   } 
0144 }
0145 $body = join "\n",@LINES;
0146 
0147 # store the output file
0148 open OUTFILE,">$outScript";
0149 print OUTFILE $body;
0150 close OUTFILE;
0151 system "chmod a+x $outScript";
0152 
0153