Need a unique gift idea?
A Pastebin account makes a great Christmas gift
SHARE
TWEET

Untitled

a guest Mar 18th, 2018 72 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  1. #!/usr/bin/perl -w
  2. #use diagnositcs
  3. #use strict;
  4. use Cwd;
  5.  
  6. $batchname = "Cosmics_smearing20_v01";
  7. $maxEventsPerRun = 1000; #max number of events to process per run (job)
  8. $numRuns = 17; #number of input files
  9. $maxProc = 20; #maximum number of processes allowed at one time for this shell
  10. $waitTime = 3; #time to wait before updating number of processes in seconds
  11.  
  12. $runOffset = 0;
  13. $numRuns = $numRuns+$runOffset;
  14.  
  15. $genheadfile = "prodtext_lariat_PiAbsAndChEx.fcl";
  16. $recoheadfile   = "RecoMC.fcl";
  17. $inTextFileBase = "/scratch/jhugon/cosmicMC/cosmicsPaddles_1MTries_0to300GeV/file";
  18. $smearing = 1.20; #additional smearing proportional to magnitude, before convolution. Log-normal distribution
  19.                   #Set to 1+relative uncertainty, e.g. 1 for 0%, 1.1 for 10%, 1.25 for 25%, 3 for 200%
  20.  
  21. $genOutFileBase = "single_gen"; #base for name of generator output files; needs .root appended
  22. $recoOutFileBase = "Reco2d"; #same for reco
  23. $genFileBase = "prodsingle_lariat";
  24. $recoFileBase = "Reco_MC_nopid";
  25.  
  26. $resultsDir = "/scratch/jhugon/lariat/MC";
  27.  
  28. if(!(-e "$resultsDir/$batchname"))
  29. {
  30.   mkdir "$resultsDir/$batchname" or die "Error: unable to make directory $resultsDir/$batchname\n";
  31. }
  32. $workDir = "$resultsDir/$batchname"; #directory where all output will be stored
  33. $fclDir = "$workDir/fcl"; #name of directory where fhicl files produced in this script will be stored
  34. $genDir = "$workDir/gen"; #directory where generated files will be stored
  35. $recoDir = "$workDir/reco"; #directory where reconstructed files will be stored
  36. $logFileName = "$workDir/logFile";
  37. #prepare working area
  38. if(!(-e $fclDir))
  39. {
  40.   mkdir $fclDir or die "Unable to make $fclDir in $workDir\n";
  41. }
  42. if(!(-e $genDir))
  43. {
  44.   mkdir $genDir or die "Unable to make $genDir in $workDir\n";
  45. }
  46. if(!(-e $recoDir))
  47. {
  48.   mkdir $recoDir or die "Unable to make $recoDir in $workDir\n";
  49. }
  50.  
  51. #produce fcl files
  52. for($it = $runOffset; $it < $numRuns; ++$it)
  53. {
  54.  
  55.   $intextfilename = sprintf("%s%02u",$inTextFileBase,$it);
  56.   $larrunnum = 1000 + $it;
  57.   #produce gen file
  58.   open(GENFILE, ">>$fclDir/$genFileBase\_run\_$it\.fcl");
  59.   print GENFILE "\#include \"$genheadfile\"\n";
  60.   print GENFILE "source.maxEvents: $maxEventsPerRun\n";
  61.   print GENFILE "source.firstRun: $larrunnum\n";
  62.   print GENFILE "physics.producers.generator.InputFileName\: \"$intextfilename\"\n";
  63.   print GENFILE "outputs.out1.fileName: \"$genOutFileBase\_run\_$it\.root\"\n";
  64.   print GENFILE "physics.producers.daq.AdditionalPropSmearPreConv: $smearing\n";
  65.   close(GENFILE);
  66.  
  67.   #produce reco file
  68.   #`cp $templateDir/$recoFile $fclDir/$recoFileBase\_run\_$it\.fcl`;
  69.   open(RECOFILE, ">>$fclDir/$recoFileBase\_run\_$it\.fcl");
  70.   print RECOFILE "\#include \"$recoheadfile\"\n";
  71.   print RECOFILE "source.maxEvents: $maxEventsPerRun\n";
  72.   print RECOFILE "outputs.out1.fileName: \"$recoDir/$recoOutFileBase\_run\_$it\.root\"\n";
  73.   close(RECOFILE);
  74. } # for it
  75.  
  76. print STDOUT "Made fcl files\n";
  77.  
  78. #run jobs up to maximum number of processes
  79. $genJob = $runOffset;
  80. $recoJob = $runOffset;
  81. $numProc = `ps -T | grep lar | grep -v 00:00:00 | wc -l`;
  82. while($recoJob < $numRuns)
  83. {
  84.   sleep($waitTime);
  85.   $numProc = `ps -T | grep lar | grep -v 00:00:00 | wc -l`;
  86.   while(($numProc < $maxProc) && ($recoJob < $numRuns))
  87.   {
  88.     if($genJob < $numRuns)
  89.     {
  90.       print STDOUT "Running gen job $genJob\n";
  91.       `lar -c $fclDir/$genFileBase\_run\_$genJob\.fcl --output $genDir/$genOutFileBase\_run\_$genJob\.root -T $genDir/$genOutFileBase\_run\_$genJob\_hist.root >> $logFileName\_gen\_$genJob.log 2>&1 &`; # or die "Failed to run gen job number $genJob with command lar -c $fclDir/$genFileBase\_run\_$genJob\.fcl > $logFileName 2>&1 &\n";
  92.       print STDOUT "lar job: lar -c $fclDir/$genFileBase\_run\_$genJob\.fcl -T $genDir/$genOutFileBase\_run\_$genJob\.root --output $genDir/$genOutFileBase\_run\_$genJob\_hist.root >> $logFileName\_gen\_$genJob.log 2>&1 &\n";
  93.       #print STDOUT "Finished gen job $genJob\n";
  94.       ++$genJob;
  95.       sleep($waitTime);
  96.       $numProc = `ps -T | grep lar | grep -v 00:00:00 | wc -l`;
  97.     }
  98.     if($recoJob < $numRuns && (-e "$genDir/$genOutFileBase\_run\_$recoJob.root") && (!`lsof $genDir/$genOutFileBase\_run\_$recoJob.root`)) #second condition checks that at least the gen job
  99.     #whose results this reco job needs has finished
  100.     {
  101.       print STDOUT "Running reco job $recoJob\n";
  102.   `lar -c $fclDir/$recoFileBase\_run\_$recoJob\.fcl -T $recoDir/$recoOutFileBase\_run\_$recoJob\_hist\.root $genDir/$genOutFileBase\_run\_$recoJob.root >> $logFileName\_reco\_$recoJob.log 2>&1 &`; # or die "Failed to run reco job number $recoJob\n";
  103.       ++$recoJob;
  104.     }
  105.     sleep($waitTime);
  106.     $numProc = `ps -T | grep lar | grep -v 00:00:00 | wc -l`;
  107.   }
  108.   print STDOUT "Number of running processes is $numProc\n";
  109.   print STDOUT "numRuns: $numRuns genJob: $genJob recoJob: $recoJob\n";
  110. } # while recoJob < numRuns
  111. print STDOUT "Finished while loop over processes and out of loop.  genJob is $genJob and recoJob is $recoJob\.  Process report:\n $numProc\n";
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top