#!/share/lemond/local/bin/perl # # This script runs the whole chain for the # RAM-file creation process. # # written by:J Kuhn, March 97 # # # Define some variable-names (program-names): # =========================================== # $kaon_4vecs = "/home/physgi01/kuhnj/852_source/itape/kaon_4vecs"; $mkitp = "/home/physgi01/kuhnj/852_source/itape/mkitp_kaon"; $sagen = "/home/lemond/e852/bin/SaGen"; $ramview = "/home/physgi01/kuhnj/852_source/esr/ramView"; $add_RAM = "/home/physgi01/kuhnj/852_source/Ram/add_RAM"; $dentist_RAM = "/home/physgi01/kuhnj/852_source/Ram/dentist_RAM"; $convert_RAM = "/home/physgi01/kuhnj/852_source/Ram/convert_RAM"; # # Dispatcher-commands: # ==================== # $dispatcher = "/home/lemond/e852/bin/Dispatcher -o0 -e852"; $disCommand_kp = "/home/lemond/e852/bin/DisCommand -Dloki:10099"; $disCommand_km = "/home/lemond/e852/bin/DisCommand -Dloki:10095"; $feedFromFile = "/home/lemond/e852/bin/feedFromFile"; # # some other variables: # ===================== # $rsh = "/usr/bsd/rsh"; $remote_host = "physgi03.phy.bnl.gov"; $local_dir = `pwd`; chop($local_dir); # # =========================================================== # Subroutine CheckHoles_finished # this subroutine checks whether the hole-filling is complete # =========================================================== # sub CheckHoles_finished { my ($checkFile_name, $pos_size, $pos_name, $end_prog); $checkFile_name = shift(@_); $pos_size = 5; $pos_name = 9; $end_prog = 0; @lines_dir = `ls -l`; chop (@lines_dir); for ($i=0 ; $i<$#lines_dir ; $i++) { @parts_lines = split(/\s+/,$lines_dir[$i]); if ($parts_lines[$pos_name-1] eq $checkFile_name) { if ($parts_lines[$pos_size-1] == 0) { $end_prog = 1; } } } return $end_prog; } # # Create the Four-vectors and the vertices: # ========================================= # print "from RAM_Master-script: Starting kaon_4vecs! \n"; #system("$kaon_4vecs -M3000000 --enableRandomGenerator -ozzzz.test -V3.175,147.3,208.3 -P2.94,12.0 >/dev/null 2>/dev/null"); system("$kaon_4vecs -M30000 --enableRandomGenerator -ozzzz.test -V3.175,147.3,208.3 -P2.685,12.0 >/dev/null 2>/dev/null"); print "from RAM_Master-script: kaon_4vecs done! \n"; print "\n\n"; # # Convert the ASCII-output of 'kaon_4vecs' to itape-format: # (this has to be done twice - for Kminus and Kplus) # ========================================================= # print "from RAM_Master-script: Starting mkitp_kaon! \n"; system("$mkitp -K1 -R12000 zzzz.test > zzzz.test_itp.kp 2>/dev/null"); print "from RAM_Master-script: mkitp_kaon done (Kplus)! \n"; system("$mkitp -K0 -R12000 zzzz.test > zzzz.test_itp.km 2>/dev/null"); print "from RAM_Master-script: mkitp_kaon done(Kminus)! \n\n\n"; # # Start the Dispatcher and feedFromFile: # ====================================== # print "from RAM_Master-script: Starting the Dispatchers! \n"; sleep 2; system("$dispatcher >/dev/null 2>/dev/null \&"); system("$dispatcher -H 10095 >/dev/null 2>/dev/null \&"); print "\n"; # # Wait for the Dispatchers to come up: # $ret_kp = 1; while ($ret_kp) { print "from RAM_Master-script: Checking Dispatcher-status (kplus)..... \n"; $ret_kp = system("$disCommand_kp STATUS? QUIT | grep 'RUNNING' >/dev/null 2>/dev/null"); sleep 2; print "\n"; } print "from RAM_Master-script: Dispatcher (Kplus) is running! \n\n"; sleep 2; $ret_km = 1; while ($ret_km) { print "from RAM_Master-script: Checking Dispatcher-status (kminus)..... \n"; $ret_km = system("$disCommand_km STATUS? QUIT | grep 'RUNNING' >/dev/null 2>/dev/null"); sleep 2; print "\n"; } print "from RAM_Master-script: Dispatcher (Kminus) is running! \n\n"; sleep 2; # # start feedFromFile # print "from RAM_Master-script: Starting feedFromFile \n"; system("feedFromFile -Dloki:10099 zzzz.test_itp.kp >/dev/null 2>/dev/null \&"); system("feedFromFile -Dloki:10095 zzzz.test_itp.km >/dev/null 2>/dev/null \&"); sleep 2; print "from RAM_Master-script: feedFromFile running....\n"; print "\n"; # # As long as we have not reached the end of the # file, run events through SaGen and ramView: # ============================================= # $first_pass = 1; $end_of_file_kp = 1; $end_of_file_km = 1; while ( ($end_of_file_kp) || ($end_of_file_km) ) { if ($first_pass == 1) { # start the SaGen-jobs only once print "from RAM_Master-script: Starting the SaGen/ramView jobs (Kplus)! \n"; print "\tstarting jobs on loki.... \n"; system("$sagen -R12000 -fQ -A0.04 --disableMissingMomentum --enableH9 -o\@'$ramview -G1 -K1 -Rzzzz.ramch_kp_01 --enableWriteOutput -Oxxx.kp_acc -oxxx.kp_veto' -Dloki:10099 >/dev/null 2>/dev/null &"); system("$sagen -R12000 -fQ -A0.04 --disableMissingMomentum --enableH9 -o\@'$ramview -G1 -K1 -Rzzzz.ramch_kp_02' -Dloki:10099 >/dev/null 2>/dev/null &"); system("$sagen -R12000 -fQ -A0.04 --disableMissingMomentum --enableH9 -o\@'$ramview -G1 -K1 -Rzzzz.ramch_kp_03' -Dloki:10099 >/dev/null 2>/dev/null &"); system("$sagen -R12000 -fQ -A0.04 --disableMissingMomentum --enableH9 -o\@'$ramview -G1 -K1 -Rzzzz.ramch_kp_04' -Dloki:10099 >/dev/null 2>/dev/null &"); # # Start jobs on physgi03: # print "\tstarting jobs on physgi03.... \n"; $ret = system("$rsh $remote_host \'$sagen -R12000 -fQ -A0.04 --disableMissingMomentum --enableH9 -o\@\"$ramview -G1 -K1 -R$local_dir/zzzz.ramch_kp_05\" -Dloki:10099\' >/dev/null 2>/dev/null &"); if ($ret) { print "\nProblem executing remote command!!!\n\n"; exit $ret; } $ret = system("$rsh $remote_host \'$sagen -R12000 -fQ -A0.04 --disableMissingMomentum --enableH9 -o\@\"$ramview -G1 -K1 -R$local_dir/zzzz.ramch_kp_06\" -Dloki:10099\' >/dev/null 2>/dev/null &"); if ($ret) { print "\nProblem executing remote command!!!\n\n"; exit $ret; } print "from RAM_Master-script: Starting the SaGen/ramView jobs (Kminus)! \n"; print "\tstarting jobs on loki.... \n"; system("$sagen -R12000 -fQ -A0.04 --disableMissingMomentum --enableH9 -o\@'$ramview -G1 -K0 -Rzzzz.ramch_km_01 --enableWriteOutput -Oxxx.km_acc -oxxx.km_veto' -Dloki:10095 >/dev/null 2>/dev/null &"); system("$sagen -R12000 -fQ -A0.04 --disableMissingMomentum --enableH9 -o\@'$ramview -G1 -K0 -Rzzzz.ramch_km_02' -Dloki:10095 >/dev/null 2>/dev/null &"); system("$sagen -R12000 -fQ -A0.04 --disableMissingMomentum --enableH9 -o\@'$ramview -G1 -K0 -Rzzzz.ramch_km_03' -Dloki:10095 >/dev/null 2>/dev/null &"); system("$sagen -R12000 -fQ -A0.04 --disableMissingMomentum --enableH9 -o\@'$ramview -G1 -K0 -Rzzzz.ramch_km_04' -Dloki:10095 >/dev/null 2>/dev/null &"); # # Start jobs on physgi03: # print "\tstarting jobs on physgi03.... \n"; $ret = system("$rsh $remote_host \'$sagen -R12000 -fQ -A0.04 --disableMissingMomentum --enableH9 -o\@\"$ramview -G1 -K0 -R$local_dir/zzzz.ramch_km_05\" -Dloki:10095\' >/dev/null 2> /dev/null &"); if ($ret) { print "\nProblem executing remote command!!!\n\n"; exit $ret; } $ret = system("$rsh $remote_host \'$sagen -R12000 -fQ -A0.04 --disableMissingMomentum --enableH9 -o\@\"$ramview -G1 -K0 -R$local_dir/zzzz.ramch_km_06\" -Dloki:10095\' >/dev/null 2>/dev/null &"); if ($ret) { print "\nProblem executing remote command!!!\n\n"; exit $ret; } $first_pass = 0; print "\n"; } if ($end_of_file_kp) { print "from RAM_Master-script: Checking for end of file (Kplus) ..... \n"; $end_of_file_kp = system("$disCommand_kp STATUS? QUIT | grep 'NoTape' >/dev/null 2>/dev/null"); } if ($end_of_file_km) { print "from RAM_Master-script: Checking for end of file (Kminus) ..... \n"; $end_of_file_km = system("$disCommand_km STATUS? QUIT | grep 'NoTape' >/dev/null 2>/dev/null"); } sleep 500; print "\n"; if ($end_of_file_kp == 0) { print "from RAM_Master-script: Found end of file (Kplus) ...\n"; } if ($end_of_file_km == 0) { print "from RAM_Master-script: Found end of file (Kminus) ...\n"; } } # # Shutdown the Dispatchers: # if ( !($end_of_file_kp * $end_of_file_km) ) { print "\nfrom RAM_Master-script: Shutting down the Dispatcher! \n"; system("$disCommand_kp EXIT >/dev/null 2>/dev/null"); system("$disCommand_km EXIT >/dev/null 2>/dev/null"); print "\n\n"; } # # Add the different Ramchannel-files # from the Dispatcher-output together: # ==================================== # # # First check how many files there are: # $index = 1; $test = 0; $fnum_kp = 0; while (!$test) { $test = system("ls -l | grep 'ramch_kp_0$index' >/dev/null 2>/dev/null"); $fnum_kp = $index-1; $index++; } print "from RAM_Master-script: Found $fnum_kp Kplus-RAMchannel-files.\n"; $index = 1; $test = 0; $fnum_km = 0; while (!$test) { $test = system("ls -l | grep 'ramch_km_0$index' >/dev/null 2>/dev/null"); $fnum_km = $index-1; $index++; } print "from RAM_Master-script: Found $fnum_km Kminus-RAMchannel-files.\n"; print "\n"; # # Now add the RAMchannel-files from the SaGen/ramView output: # print "from RAM_Master-script: Starting add_RAM (Kplus)! \n"; if ($fnum_kp == 1) { system("$add_RAM -M1 -Ozzzz.ramch_kp_01 -Tzzzz.ramch_kp_01 -ozzzz.ramch_kp_01.h9 >/dev/null 2>/dev/null"); system("$add_RAM -M0 -Ozzzz.ramch_kp_01 -Tzzzz.ramch_kp_01 -ozzzz.ramch_kp_01.tpx1 >/dev/null 2>/dev/null"); } else { $index1 = 1; $index2 = 2; system("$add_RAM -M1 -Ozzzz.ramch_kp_0$index1 -Tzzzz.ramch_kp_0$index2 -ozzzz.ramch_kp_0$index2.h9 >/dev/null 2>/dev/null"); system("$add_RAM -M0 -Ozzzz.ramch_kp_0$index1 -Tzzzz.ramch_kp_0$index2 -ozzzz.ramch_kp_0$index2.tpx1 >/dev/null 2>/dev/null"); while ($index2 < $fnum_kp) { $index1 = $index2; $index2++; system("$add_RAM -M1 -Ozzzz.ramch_kp_0$index1.h9 -Tzzzz.ramch_kp_0$index2 -ozzzz.ramch_kp_0$index2.h9 >/dev/null 2>/dev/null"); system("$add_RAM -M0 -Ozzzz.ramch_kp_0$index1.tpx1 -Tzzzz.ramch_kp_0$index2 -ozzzz.ramch_kp_0$index2.tpx1 >/dev/null 2>/dev/null"); } } print "from RAM_Master-script: add_RAM done (Kplus)! \n\n"; print "from RAM_Master-script: Starting add_RAM (Kminus)! \n"; if ($fnum_km == 1) { system("$add_RAM -M1 -Ozzzz.ramch_km_01 -Tzzzz.ramch_km_01 -ozzzz.ramch_km_01.h9 >/dev/null 2>/dev/null"); system("$add_RAM -M0 -Ozzzz.ramch_km_01 -Tzzzz.ramch_km_01 -ozzzz.ramch_km_01.tpx1 >/dev/null 2>/dev/null"); } else { $index1 = 1; $index2 = 2; system("$add_RAM -M1 -Ozzzz.ramch_km_0$index1 -Tzzzz.ramch_km_0$index2 -ozzzz.ramch_km_0$index2.h9 >/dev/null 2>/dev/null"); system("$add_RAM -M0 -Ozzzz.ramch_km_0$index1 -Tzzzz.ramch_km_0$index2 -ozzzz.ramch_km_0$index2.tpx1 >/dev/null 2>/dev/null"); while ($index2 < $fnum_km) { $index1 = $index2; $index2++; system("$add_RAM -M1 -Ozzzz.ramch_km_0$index1.h9 -Tzzzz.ramch_km_0$index2 -ozzzz.ramch_km_0$index2.h9 >/dev/null 2>/dev/null"); system("$add_RAM -M0 -Ozzzz.ramch_km_0$index1.tpx1 -Tzzzz.ramch_km_0$index2 -ozzzz.ramch_km_0$index2.tpx1 >/dev/null 2>/dev/null"); } } print "from RAM_Master-script: add_RAM done (Kminus)! \n"; print "\n\n"; # # Now start filling the holes: # ============================ # print "from RAM_Master-script: Starting hole-filling! \n\n"; print "\tStarting to fill Kplus/H9 - file.... \n"; $end_dentist = 0; $index = 1; while ( !$end_dentist ) { if ($index == 1) { system("$dentist_RAM -M1 -K1 -izzzz.ramch_kp_0$fnum_kp.h9 -ozzzz.holes_kp_0$index.h9 >/dev/null 2>/dev/null"); system("$add_RAM -M1 -Ozzzz.ramch_kp_0$fnum_kp.h9 -Tzzzz.holes_kp_0$index.h9 -ozzzz.ramch_kp_0$index.h9_filled >/dev/null 2>/dev/null"); } else { $index_prev = $index-1; system("$dentist_RAM -M1 -K1 -izzzz.ramch_kp_0$index_prev.h9_filled -ozzzz.holes_kp_0$index.h9 >/dev/null 2>/dev/null"); system("$add_RAM -M1 -Ozzzz.ramch_kp_0$index_prev.h9_filled -Tzzzz.holes_kp_0$index.h9 -ozzzz.ramch_kp_0$index.h9_filled >/dev/null 2>/dev/null"); } print "\t\tpass $index of hole-filling finished....\n"; $end_dentist = CheckHoles_finished("zzzz.holes_kp_0$index.h9"); $num_kp_h9 = $index; $index++; } print "\t\tDone filling Kplus/H9 - file. \n"; print "\tStarting to fill Kplus/TPX1 - file.... \n"; $end_dentist = 0; $index = 1; while ( !$end_dentist ) { if ($index == 1) { system("$dentist_RAM -M0 -K1 -izzzz.ramch_kp_0$fnum_kp.tpx1 -ozzzz.holes_kp_0$index.tpx1 >/dev/null 2>/dev/null"); system("$add_RAM -M0 -Ozzzz.ramch_kp_0$fnum_kp.tpx1 -Tzzzz.holes_kp_0$index.tpx1 -ozzzz.ramch_kp_0$index.tpx1_filled >/dev/null 2>/dev/null"); } else { $index_prev = $index-1; system("$dentist_RAM -M0 -K1 -izzzz.ramch_kp_0$index_prev.tpx1_filled -ozzzz.holes_kp_0$index.tpx1 >/dev/null 2>/dev/null"); system("$add_RAM -M0 -Ozzzz.ramch_kp_0$index_prev.tpx1_filled -Tzzzz.holes_kp_0$index.tpx1 -ozzzz.ramch_kp_0$index.tpx1_filled >/dev/null 2>/dev/null"); } print "\t\tpass $index of hole-filling finished....\n"; $end_dentist = CheckHoles_finished("zzzz.holes_kp_0$index.tpx1"); $num_kp_tpx1 = $index; $index++; } print "\t\tDone filling Kplus/TPX1 - file. \n"; print "\tStarting to fill Kminus/H9 - file.... \n"; $end_dentist = 0; $index = 1; while ( !$end_dentist ) { if ($index == 1) { system("$dentist_RAM -M1 -K0 -izzzz.ramch_km_0$fnum_km.h9 -ozzzz.holes_km_0$index.h9 >/dev/null 2>/dev/null"); system("$add_RAM -M1 -Ozzzz.ramch_km_0$fnum_km.h9 -Tzzzz.holes_km_0$index.h9 -ozzzz.ramch_km_0$index.h9_filled >/dev/null 2>/dev/null"); } else { $index_prev = $index-1; system("$dentist_RAM -M1 -K0 -izzzz.ramch_km_0$index_prev.h9_filled -ozzzz.holes_km_0$index.h9 >/dev/null 2>/dev/null"); system("$add_RAM -M1 -Ozzzz.ramch_km_0$index_prev.h9_filled -Tzzzz.holes_km_0$index.h9 -ozzzz.ramch_km_0$index.h9_filled >/dev/null 2>/dev/null"); } print "\t\tpass $index of hole-filling finished....\n"; $end_dentist = CheckHoles_finished("zzzz.holes_km_0$index.h9"); $num_km_h9 = $index; $index++; } print "\t\tDone filling Kminus/H9 - file. \n"; print "\tStarting to fill Kminus/TPX1 - file.... \n"; $end_dentist = 0; $index = 1; while ( !$end_dentist ) { if ($index == 1) { system("$dentist_RAM -M0 -K0 -izzzz.ramch_km_0$fnum_km.tpx1 -ozzzz.holes_km_0$index.tpx1 >/dev/null 2>/dev/null"); system("$add_RAM -M0 -Ozzzz.ramch_km_0$fnum_km.tpx1 -Tzzzz.holes_km_0$index.tpx1 -ozzzz.ramch_km_0$index.tpx1_filled >/dev/null 2>/dev/null"); } else { $index_prev = $index-1; system("$dentist_RAM -M0 -Km -izzzz.ramch_km_0$index_prev.tpx1_filled -ozzzz.holes_km_0$index.tpx1 >/dev/null 2>/dev/null"); system("$add_RAM -M0 -Ozzzz.ramch_km_0$index_prev.tpx1_filled -Tzzzz.holes_km_0$index.tpx1 -ozzzz.ramch_km_0$index.tpx1_filled >/dev/null 2>/dev/null"); } print "\t\tpass $index of hole-filling finished....\n"; $end_dentist = CheckHoles_finished("zzzz.holes_km_0$index.tpx1"); $num_km_tpx1 = $index; $index++; } print "\t\tDone filling Kminus/TPX1 - file. \n"; print "\n\n"; # # Add the Kplus- and Kminus-files for each of the 2 RAMs : # ======================================================== # print "from RAM_Master-script: Adding Kplus and Kminus for H9-RAM.... \n"; system("$add_RAM -M1 -Ozzzz.ramch_kp_0$num_kp_h9.h9_filled -Tzzzz.ramch_km_0$num_km_h9.h9_filled -ozzzz.ramch_tot.h9 >/dev/null 2>/dev/null"); print "\t ...done! \n\n"; print "from RAM_Master-script: Adding Kplus and Kminus for TPX1-RAM.... \n"; system("$add_RAM -M0 -Ozzzz.ramch_kp_0$num_kp_tpx1.tpx1_filled -Tzzzz.ramch_km_0$num_km_tpx1.tpx1_filled -ozzzz.ramch_tot.tpx1 >/dev/null 2>/dev/null"); print "\t ...done! \n\n\n"; # # Convert the RAM-files : # ======================= # print "from RAM_Master-script: Converting the H9-RAM....\n"; system("$convert_RAM -M1 -izzzz.ramch_tot.h9 -ozzzz.RAM.h9 >/dev/null 2>/dev/null"); print "\t ...done! \n\n"; print "from RAM_Master-script: Converting the TPX1-RAM....\n"; system("$convert_RAM -M0 -izzzz.ramch_tot.tpx1 -ozzzz.RAM.tpx1 >/dev/null 2>/dev/null"); print "\t ...done! \n\n\n"; print "from RAM_Master-script: script done! \n\n\n"; # # ============== # End of script. # ============== #