Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:45:15

0001 #!/usr/bin/env perl
0002 #     R. Mankel, DESY Hamburg     06-Jul-2007
0003 #     A. Parenti, DESY Hamburg    27-Mar-2008
0004 #
0005 #  Prepare the run script for this job.
0006 #  The main action is to embed the output directory
0007 #  into the script
0008 #
0009 #  Usage:
0010 #
0011 #  mps_script.pl inScript outScript runDir cfgName fileSplit isn mssDir \
0012 #  [CastorPool]
0013 #
0014 # FIXME: Some of the variables here are not used because they are related to
0015 #        CASTOR which is now used only for archival. When this script is
0016 #        translated to python the remaining CASTOR-related parts have to be
0017 #        removed.
0018 
0019 use POSIX;
0020 
0021 $inScript = "undefined";
0022 $outScript = "undefined";
0023 $runDir = "undefined";
0024 $cfgName = "undefined";
0025 $fileSplit = "undefined";
0026 $isn = "undefined";
0027 $mssDirLocal = "undefined"; # not to confuse with mssDir from 'mpslib'.
0028 $castorPool = "undefined";
0029 $cmsCafPool = 0;
0030 
0031 # parse the arguments
0032 while (@ARGV) {
0033   $arg = shift(@ARGV);
0034   if ($arg =~ /\A-/) {  # check for option
0035     if ($arg =~ "h") {
0036       $helpwanted = 1;
0037     }
0038     elsif ($arg =~ "d") {
0039       $localdir = 1;
0040     }
0041     elsif ($arg =~ "u") {
0042       $updateDb = 1;
0043     }
0044     $optionstring = "$optionstring$arg";
0045   }
0046   else {                # parameters not related to options
0047     $i = $i + 1;
0048     if ($i eq 1) {
0049       $inScript = $arg;
0050     }
0051     elsif ($i eq 2) {
0052       $outScript = $arg;
0053     }
0054     elsif ($i eq 3) {
0055       $runDir = $arg;
0056     }
0057     elsif ($i eq 4) {
0058       $cfgName = $arg;
0059     }
0060     elsif ($i eq 5) {
0061       $fileSplit = $arg;
0062     }
0063     elsif ($i eq 6) {
0064       $isn = $arg;
0065     }
0066     elsif ($i eq 7) {
0067       $mssDirLocal = $arg;
0068     }
0069     elsif ($i eq 8) {
0070       $castorPool = $arg;
0071     }
0072   }
0073 }
0074 
0075 if ($isn eq "undefined") {
0076   print "Insufficient information given\n";
0077   exit 1;
0078 }
0079 
0080 # open the input file
0081 open INFILE,"$inScript";
0082 undef $/;  # undefining the INPUT-RECORD_SEPARATOR means slurp whole file
0083 $body = <INFILE>;  # read whole file
0084 close INFILE;
0085 $/ = "\n"; # back to normal
0086 
0087 # replace RUNDIR setting
0088 $nn = ($body =~ m/RUNDIR=(.+)$/m);
0089 if ($nn != 1) {
0090   print "mps_script.pl: no (unambiguous) RUNDIR directive found in runscript\n";
0091   exit 1;
0092 }
0093 $nn = ($body =~ s/RUNDIR=(.+)$/RUNDIR=$runDir/m);
0094 
0095 #replace CMSSW_RELEASE_AREA with evironment variable
0096 $body =~ s/cd\s+CMSSW_RELEASE_AREA/cd $ENV{'CMSSW_BASE'}/g;
0097 
0098 # replace MSSDIR setting
0099 $nn = ($body =~ m/MSSDIR=(.+)$/m);
0100 if ($nn != 1) {
0101   print "mps_script.pl: no (unambiguous) MSSDIR directive found in runscript\n";
0102 }
0103 $nn = ($body =~ s/MSSDIR=(.+)$/MSSDIR=$mssDirLocal/m);
0104 
0105 if ($castorPool ne "undefined") {
0106 # replace MSSDIRPOOL setting...
0107   $nn = ($body =~ s/MSSDIRPOOL=(.*)$/MSSDIRPOOL=$castorPool/m);
0108 } else {
0109 #... or empty the field.
0110   $nn = ($body =~ s/MSSDIRPOOL=(.*)$/MSSDIRPOOL=/m);
0111 }
0112 
0113 # replace the cfg name
0114 $nn = ($body =~ m/cmsRun +([A-Z,a-z,0-9\-\.])/g);
0115 # $nn = ($body =~ m/cmsRun +(.+)/g);
0116 if ($nn <1) {
0117   print "Warning: mps_script matches cfg: $nn\n";
0118 }
0119 # $nn = ($body =~ s/cmsRun\s([A-Za-z0-9]+?\.cfg)/cmsRun $cfgName/g);
0120 # $nn = ($body =~ s/cmsRun +(.+)/cmsRun $cfgName/g);
0121 $nn = ($body =~ s/cmsRun +[a-zA-Z_0-9\-]+\.cfg/cmsRun \$RUNDIR\/$cfgName/g);
0122 
0123 # replace ISN for the root output file
0124 $nrep = ($body =~ s/ISN/$isn/gm);
0125 
0126 # store the output file
0127 open OUTFILE,">$outScript";
0128 print OUTFILE $body;
0129 close OUTFILE;
0130 system "chmod a+x $outScript";
0131 
0132