#!/usr/bin/perl -w

use strict;

##### Modify this part ################

my $nStart = 1;
my $nStop  = 8;  #nStop<=63

my $macro1 = "histMk_3D_BpBm_Dlnu_D0KPi.C";
my $macro2 = "histMk_3D_B0B0_Dlnu_DchKPiPi.C";
my $macro3 = "histMk_3D_BpBm_Dlnu_0th_D0KPi.C";
my $macro4 = "histMk_3D_BpBm_Dlnu_1st_D0KPi.C";
my $macro5 = "histMk_3D_BpBm_Dlnu_2nd_D0KPi.C";
my $macro6 = "histMk_3D_B0B0_Dlnu_0th_DchKPiPi.C";
my $macro7 = "histMk_3D_B0B0_Dlnu_1st_DchKPiPi.C";
my $macro8 = "histMk_3D_B0B0_Dlnu_2nd_DchKPiPi.C";
my $macro9 = "histMk_3D_BpBm_Dstar_D0KPi.C";
my $macro10 = "histMk_3D_B0B0_Dstar_D0KPi.C";
my $macro11 = "histMk_3D_B0B0_Dstar_DchKPiPi.C";
my $macro12 = "histMk_3D_BpBm_D0star_D0KPi.C";
my $macro13 = "histMk_3D_B0B0_D0star_D0KPi.C";
my $macro14 = "histMk_3D_BpBm_D0star_DchKPiPi.C";
my $macro15 = "histMk_3D_B0B0_D0star_DchKPiPi.C";
my $macro16 = "histMk_3D_BpBm_D1prime_D0KPi.C";
my $macro17 = "histMk_3D_B0B0_D1prime_D0KPi.C";
my $macro18 = "histMk_3D_BpBm_D1prime_DchKPiPi.C";
my $macro19 = "histMk_3D_B0B0_D1prime_DchKPiPi.C";
my $macro20 = "histMk_3D_BpBm_D1_D0KPi.C";
my $macro21 = "histMk_3D_B0B0_D1_D0KPi.C";
my $macro22 = "histMk_3D_BpBm_D1_DchKPiPi.C";
my $macro23 = "histMk_3D_B0B0_D1_DchKPiPi.C";
my $macro24 = "histMk_3D_BpBm_D2star_D0KPi.C";
my $macro25 = "histMk_3D_B0B0_D2star_D0KPi.C";
my $macro26 = "histMk_3D_BpBm_D2star_DchKPiPi.C";
my $macro27 = "histMk_3D_B0B0_D2star_DchKPiPi.C";
my $macro28 = "histMk_3D_BpBm_DPi_D0KPi.C";
my $macro29 = "histMk_3D_B0B0_DPi_D0KPi.C";
my $macro30 = "histMk_3D_BpBm_DPi_DchKPiPi.C";
my $macro31 = "histMk_3D_B0B0_DPi_DchKPiPi.C";
my $macro32 = "histMk_3D_BpBm_DstarPi_D0KPi.C";
my $macro33 = "histMk_3D_B0B0_DstarPi_D0KPi.C";
my $macro34 = "histMk_3D_BpBm_DstarPi_DchKPiPi.C";
my $macro35 = "histMk_3D_B0B0_DstarPi_DchKPiPi.C";
my $macro36 = "histMk_3D_BpBm_DiffB_D0KPi.C";
my $macro37 = "histMk_3D_B0B0_DiffB_D0KPi.C";
my $macro38 = "histMk_3D_BpBm_DiffB_DchKPiPi.C";
my $macro39 = "histMk_3D_B0B0_DiffB_DchKPiPi.C";
my $macro40 = "histMk_3D_BpBm_CascL_D0KPi.C";
my $macro41 = "histMk_3D_B0B0_CascL_D0KPi.C";
my $macro42 = "histMk_3D_BpBm_CascL_DchKPiPi.C";
my $macro43 = "histMk_3D_B0B0_CascL_DchKPiPi.C";
my $macro44 = "histMk_3D_BpBm_LMisID_D0KPi.C";
my $macro45 = "histMk_3D_B0B0_LMisID_D0KPi.C";
my $macro46 = "histMk_3D_BpBm_LMisID_DchKPiPi.C";
my $macro47 = "histMk_3D_B0B0_LMisID_DchKPiPi.C";
my $macro48 = "histMk_3D_BpBm_Comb_D0KPi.C";
my $macro49 = "histMk_3D_B0B0_Comb_D0KPi.C";
my $macro50 = "histMk_3D_BpBm_Comb_DchKPiPi.C";
my $macro51 = "histMk_3D_B0B0_Comb_DchKPiPi.C";
my $macro52 = "histMk_3D_ccbar_RealD_D0KPi.C";
my $macro53 = "histMk_3D_ccbar_RealD_DchKPiPi.C";
my $macro54 = "histMk_3D_ccbar_Cont_D0KPi.C";
my $macro55 = "histMk_3D_ccbar_Cont_DchKPiPi.C";
my $macro56 = "histMk_3D_uds_Cont_D0KPi.C";
my $macro57 = "histMk_3D_uds_Cont_DchKPiPi.C";
my $macro58 = "histMk_3D_tautau_Cont_D0KPi.C";
my $macro59 = "histMk_3D_tautau_Cont_DchKPiPi.C";
my $macro60 = "histMk_3D_OnPeak_data_D0KPi.C";
my $macro61 = "histMk_3D_OnPeak_data_DchKPiPi.C";
my $macro62 = "histMk_3D_OffPeak_data_D0KPi.C";
my $macro63 = "histMk_3D_OffPeak_data_DchKPiPi.C";

my $jobNameBase = "runHistMk";

#######################################

my $workDir = "/home1x/hep/khamano/releases/BToDlnu-a26_16.1.5/workdir";
my $scrDir = "./runRoot";
#my $logDir = "/home1x/OtherMounts/hep03/khamano/log";
my $logDir = "log";
my $queue = "express";
my $walt = "walltime=05:00:00";
#my $queue = "general";
#my $walt = "walltime=48:00:00";

###################################################################

chdir "$workDir";

my $macro = "histMk_DMass_DataMC.C";
my $script = "runRootJobs-1.pl";
my $jobName = "rootJob-1";

my $j = $nStart;
while ($j <= $nStop) {
    if ($j==1) {
	$macro = $macro1;
	$script = "$jobNameBase-1.pl";
	$jobName = "rootJob-1";
    }
    if ($j==2) {
	$macro = $macro2;
	$script = "$jobNameBase-2.pl";
	$jobName = "rootJob-2";
    }
    if ($j==3) {
	$macro = $macro3;
	$script = "$jobNameBase-3.pl";
	$jobName = "rootJob-3";
    }
    if ($j==4) {
	$macro = $macro4;
	$script = "$jobNameBase-4.pl";
	$jobName = "rootJob-4";
    }
    if ($j==5) {
	$macro = $macro5;
	$script = "$jobNameBase-5.pl";
	$jobName = "rootJob-5";
    }
    if ($j==6) {
	$macro = $macro6;
	$script = "$jobNameBase-6.pl";
	$jobName = "rootJob-6";
    }
    if ($j==7) {
	$macro = $macro7;
	$script = "$jobNameBase-7.pl";
	$jobName = "rootJob-7";
    }
    if ($j==8) {
	$macro = $macro8;
	$script = "$jobNameBase-8.pl";
	$jobName = "rootJob-8";
    }
    if ($j==9) {
	$macro = $macro9;
	$script = "$jobNameBase-9.pl";
	$jobName = "rootJob-9";
    }
    if ($j==10) {
	$macro = $macro10;
	$script = "$jobNameBase-10.pl";
	$jobName = "rootJob-10";
    }
    if ($j==11) {
	$macro = $macro11;
	$script = "$jobNameBase-11.pl";
	$jobName = "rootJob-11";
    }
    if ($j==12) {
	$macro = $macro12;
	$script = "$jobNameBase-12.pl";
	$jobName = "rootJob-12";
    }
    if ($j==13) {
	$macro = $macro13;
	$script = "$jobNameBase-13.pl";
	$jobName = "rootJob-13";
    }
    if ($j==14) {
	$macro = $macro14;
	$script = "$jobNameBase-14.pl";
	$jobName = "rootJob-14";
    }
    if ($j==15) {
	$macro = $macro15;
	$script = "$jobNameBase-15.pl";
	$jobName = "rootJob-15";
    }
    if ($j==16) {
	$macro = $macro16;
	$script = "$jobNameBase-16.pl";
	$jobName = "rootJob-16";
    }
    if ($j==17) {
	$macro = $macro17;
	$script = "$jobNameBase-17.pl";
	$jobName = "rootJob-17";
    }
    if ($j==18) {
	$macro = $macro18;
	$script = "$jobNameBase-18.pl";
	$jobName = "rootJob-18";
    }
    if ($j==19) {
	$macro = $macro19;
	$script = "$jobNameBase-19.pl";
	$jobName = "rootJob-19";
    }
    if ($j==20) {
	$macro = $macro20;
	$script = "$jobNameBase-20.pl";
	$jobName = "rootJob-20";
    }
    if ($j==21) {
	$macro = $macro21;
	$script = "$jobNameBase-21.pl";
	$jobName = "rootJob-21";
    }
    if ($j==22) {
	$macro = $macro22;
	$script = "$jobNameBase-22.pl";
	$jobName = "rootJob-22";
    }
    if ($j==23) {
	$macro = $macro23;
	$script = "$jobNameBase-23.pl";
	$jobName = "rootJob-23";
    }
    if ($j==24) {
	$macro = $macro24;
	$script = "$jobNameBase-24.pl";
	$jobName = "rootJob-24";
    }
    if ($j==25) {
	$macro = $macro25;
	$script = "$jobNameBase-25.pl";
	$jobName = "rootJob-25";
    }
    if ($j==26) {
	$macro = $macro26;
	$script = "$jobNameBase-26.pl";
	$jobName = "rootJob-26";
    }
    if ($j==27) {
	$macro = $macro27;
	$script = "$jobNameBase-27.pl";
	$jobName = "rootJob-27";
    }
    if ($j==28) {
	$macro = $macro28;
	$script = "$jobNameBase-28.pl";
	$jobName = "rootJob-28";
    }
    if ($j==29) {
	$macro = $macro29;
	$script = "$jobNameBase-29.pl";
	$jobName = "rootJob-29";
    }
    if ($j==30) {
	$macro = $macro30;
	$script = "$jobNameBase-30.pl";
	$jobName = "rootJob-30";
    }
    if ($j==31) {
	$macro = $macro31;
	$script = "$jobNameBase-31.pl";
	$jobName = "rootJob-31";
    }
    if ($j==32) {
	$macro = $macro32;
	$script = "$jobNameBase-32.pl";
	$jobName = "rootJob-32";
    }
    if ($j==33) {
	$macro = $macro33;
	$script = "$jobNameBase-33.pl";
	$jobName = "rootJob-33";
    }
    if ($j==34) {
	$macro = $macro34;
	$script = "$jobNameBase-34.pl";
	$jobName = "rootJob-34";
    }
    if ($j==35) {
	$macro = $macro35;
	$script = "$jobNameBase-35.pl";
	$jobName = "rootJob-35";
    }
    if ($j==36) {
	$macro = $macro36;
	$script = "$jobNameBase-36.pl";
	$jobName = "rootJob-36";
    }
    if ($j==37) {
	$macro = $macro37;
	$script = "$jobNameBase-37.pl";
	$jobName = "rootJob-37";
    }
    if ($j==38) {
	$macro = $macro38;
	$script = "$jobNameBase-38.pl";
	$jobName = "rootJob-38";
    }
    if ($j==39) {
	$macro = $macro39;
	$script = "$jobNameBase-39.pl";
	$jobName = "rootJob-39";
    }
    if ($j==40) {
	$macro = $macro40;
	$script = "$jobNameBase-40.pl";
	$jobName = "rootJob-40";
    }
    if ($j==41) {
	$macro = $macro41;
	$script = "$jobNameBase-41.pl";
	$jobName = "rootJob-41";
    }
    if ($j==42) {
	$macro = $macro42;
	$script = "$jobNameBase-42.pl";
	$jobName = "rootJob-42";
    }
    if ($j==43) {
	$macro = $macro43;
	$script = "$jobNameBase-43.pl";
	$jobName = "rootJob-43";
    }
    if ($j==44) {
	$macro = $macro44;
	$script = "$jobNameBase-44.pl";
	$jobName = "rootJob-44";
    }
    if ($j==45) {
	$macro = $macro45;
	$script = "$jobNameBase-45.pl";
	$jobName = "rootJob-45";
    }
    if ($j==46) {
	$macro = $macro46;
	$script = "$jobNameBase-46.pl";
	$jobName = "rootJob-46";
    }
    if ($j==47) {
	$macro = $macro47;
	$script = "$jobNameBase-47.pl";
	$jobName = "rootJob-47";
    }
    if ($j==48) {
	$macro = $macro48;
	$script = "$jobNameBase-48.pl";
	$jobName = "rootJob-48";
    }
    if ($j==49) {
	$macro = $macro49;
	$script = "$jobNameBase-49.pl";
	$jobName = "rootJob-49";
    }
    if ($j==50) {
	$macro = $macro50;
	$script = "$jobNameBase-50.pl";
	$jobName = "rootJob-50";
    }
    if ($j==51) {
	$macro = $macro51;
	$script = "$jobNameBase-51.pl";
	$jobName = "rootJob-51";
    }
    if ($j==52) {
	$macro = $macro52;
	$script = "$jobNameBase-52.pl";
	$jobName = "rootJob-52";
    }
    if ($j==53) {
	$macro = $macro53;
	$script = "$jobNameBase-53.pl";
	$jobName = "rootJob-53";
    }
    if ($j==54) {
	$macro = $macro54;
	$script = "$jobNameBase-54.pl";
	$jobName = "rootJob-54";
    }
    if ($j==55) {
	$macro = $macro55;
	$script = "$jobNameBase-55.pl";
	$jobName = "rootJob-55";
    }
    if ($j==56) {
	$macro = $macro56;
	$script = "$jobNameBase-56.pl";
	$jobName = "rootJob-56";
    }
    if ($j==57) {
	$macro = $macro57;
	$script = "$jobNameBase-57.pl";
	$jobName = "rootJob-57";
    }
    if ($j==58) {
	$macro = $macro58;
	$script = "$jobNameBase-58.pl";
	$jobName = "rootJob-58";
    }
    if ($j==59) {
	$macro = $macro59;
	$script = "$jobNameBase-59.pl";
	$jobName = "rootJob-59";
    }
    if ($j==60) {
	$macro = $macro60;
	$script = "$jobNameBase-60.pl";
	$jobName = "rootJob-60";
    }
    if ($j==61) {
	$macro = $macro61;
	$script = "$jobNameBase-61.pl";
	$jobName = "rootJob-61";
    }
    if ($j==62) {
	$macro = $macro62;
	$script = "$jobNameBase-62.pl";
	$jobName = "rootJob-62";
    }
    if ($j==63) {
	$macro = $macro63;
	$script = "$jobNameBase-63.pl";
	$jobName = "rootJob-63";
    }

    # Create script file to run
    open(SCRIN, ">$scrDir/$script") or die;
    print SCRIN "\#\!/usr/bin/perl -w\n";
    print SCRIN "chdir \"$workDir\"\;\n";
    print SCRIN "my \$cmd = \"bbrroot -b -q ./$macro\"\;\n";
    print SCRIN "print STDERR \"'\$cmd' ...\\n\"\;\n";
    print SCRIN "system(\$cmd)\;\n";
    print SCRIN "exit\;\n";
    close SCRIN;

    # Make submit command
    my $subCmd ="qsub -q $queue -l $walt -V -N $jobName -e $logDir -o $logDir $scrDir/$script";
    
    print STDERR "'$subCmd' ...\n";
    system($subCmd);

    $j++;
    sleep 1;
}

exit;
