#!usr/bin/python import os import sys import thread import time #command line parameters run=2 fileName="control.in" pram=0 for arg in sys.argv: if arg=="-h": print " -h[help], -r[number of runs], -i[input file] \n\n" sys.exit() if arg=="-r": run=sys.argv[pram+1] if arg=="-i": fileName=sys.argv[pram+1] pram=pram+1 #---------------------------------------------------------- def fill(): if not TRIG_flag=="default": FILE.write("TRIG " + str(TRIG) + "\n") if not Emax_flag=="default": if not Emin_flag=="default": FILE.write("BEAM " + str(Emax) + " " + str(Epeak )+ " " + str(Emin) + "\n") else: FILE.write("BEAM " + str(Emax) + " " + str(Epeak ) + "\n") if not OUTFILE_flag=="default": FILE.write("OUTFILE " + OUTFILE + "\n") if not POSTSMEAR_flag=="default": FILE.write("POSTSMEAR " + str(POSTSMEAR) + "\n") if not DELETEUNSMEARED_flag=="default": FILE.write("DELETEUNSMEARED " + str(DELETEUNSMEARED) + "\n") if not particle_flag=="default": FILE.write("KINE " + str(particle) + " " + str(momentum) + " " + str(theta) + " " + str(phi) + " " + str(delta_momentum) + " " + str(delta_theta) + " " + str(delta_phi) + "\n") if not vertex_x_flag=="default": FILE.write("SCAP " + str(vertex_x) + " " + str(vertex_y) + " " + str(vertex_z) + "\n") if not fhalo_flag=="default": FILE.write("HALO " + str(fhalo) + "\n") if not BGRATE_flag=="default": FILE.write("BGRATE " + str(BGRATE) + "\n") if not t1_flag=="default": FILE.write("BGGATE " + str(t1) + " " + str(t2) + "\n") if not RNDM1_flag=="default": FILE.write("RNDM " + str(RNDM1) + " " + str(ID) + "\n") if not cutgam_flag=="default": tempString="CUTS " + str(cutgam) + " " + str(cutele) + " " + str(cutneu) + " " + str(cuthad) + " " + str(cutmuo) if not bcute_flag=="default": tempString+= " " + str(bcute) if not bcutm_flag=="default": tempString+= " " + str(bcutm) if not dcute_flag=="default": tempString+= " " + str(dcute) if not dcutm_flag=="default": tempString+= " " + str(dcutm) if not ppcutm_flag=="default": tempString+= " " + str(ppcutm) if not tofmax_flag=="default": tempString+= " " + str(tofmax) if not gcuts_flag=="default": tempString+= " " + str(gcuts) FILE.write(tempString + "\n") if not SWIT_1_flag=="default": FILE.write("SWIT " + str(SWIT_1) + " " + str(SWIT_2) + " " + str(SWIT_3) + " " + str(SWIT_4) + " " + str(SWIT_5) + " " + str(SWIT_6) + " " + str(SWIT_7) + " " + str(SWIT_8) + " " + str(SWIT_9) + "\n") if not on_off_flag=="default": FILE.write("GELH " + str(on_off) + " " + str(ecut) + " " + str(scale) + " " + str(mode) + " " + str(thresh) + "\n") if not HADR_flag=="default": FILE.write("HADR " + str(HADR) + "\n") if not CKOV_flag=="default": FILE.write("CKOV " + str(CKOV) + "\n") if not LABS_flag=="default": FILE.write("LABS " + str(LABS) + "\n") if not ABAN_flag=="default": FILE.write("ABAN " + str(ABAN) + "\n") if not first_flag=="default": FILE.write("DEBU " + str(first) + " " + str(last) + " " + str(step) + "\n") if not NOSECONDARIES_flag=="default": FILE.write("NOSECONDARIES " + str(NOSECONDARIES) + "\n") if not TRAJECTORIES_flag=="default": FILE.write("TRAJECTORIES " + str(TRAJECTORIES) + "\n") if not SAVEHITS_flag=="default": FILE.write("SAVEHITS " + str(SAVEHITS) + "\n") if not SHOWERSINCOL_flag=="default": FILE.write("SHOWERSINCOL " + str(SHOWERSINCOL) + "\n") #------------------------------------------------------------------ #functions and variables def case1(): global TRIG;TRIG=int(temp[1]);global TRIG_flag;TRIG_flag="user"; def case2(): global Emax;Emax=float(temp[1]);global Emax_flag;Emax_flag="user" global Epeak;Epeak=float(temp[2]);global Epeak_flag;Epeak_flag="user" if (len(temp)>3): global Emin;Emin=float(temp[3]);global Emin_flag;Emin_flag="user" def case3(): global OUTFILE;OUTFILE=temp[1];global OUTFILE_flag;OUTFILE_flag="user" def case4(): global POSTSMEAR;POSTSMEAR=int(temp[1]);global POSTSMEAR_flag;POSTSMEAR_flag="user" def case5(): global DELETEUNSMEARED;DELETEUNSMEARED=int(temp[1]);global DELETEUNSMEARED_flag;DELETEUNSMEARED_flag="user" def case6(): global particle;particle=int(temp[1]);global particle_flag;particle_flag="user" global momentum;momentum=float(temp[2]);global momentum_flag;momentum_flag="user" global theta;theta=float(temp[3]);global theta_flag;theta_flag="user" global phi;phi=float(temp[4]);global phi_flag;phi_flag="user" global delta_momentum;delta_momentum=float(temp[5]);global delta_momentum_flag;delta_momentum_flag="user" global delta_theta;delta_theta=float(temp[6]);global delta_theta_flag;delta_theta_flag="user" global delta_phi;delta_phi=float(temp[7]);global delta_phi_flag;delta_phi_flag="user" def case7(): global vertex_x;vertex_x=float(temp[1]);global vertex_x_flag;vertex_x_flag="user" global vertex_y;vertex_y=float(temp[2]);global vertex_y_flag;vertex_y_flag="user" global vertex_z;vertex_z=float(temp[3]);global vertex_z_flag;vertex_z_flag="user" def case8(): global fhalo;fhalo=float(temp[1]);global fhalo_flag;fhalo_flag="user" def case9(): global BGRATE;BGRATE=float(temp[1]);global BGRATE_flag;BGRATE_flag="user" def case10(): global t1;t1=float(temp[1]);global t1_flag;t1_flag="user" global t2;t2=float(temp[2]);global t2_flag;t2_flag="user" def case11(): global RNDM1;RNDM1=int(temp[1]);global RNDM1_flag;RNDM1_flag="user" if (len(temp)>2): global RNDM2;RNDM2=int(temp[2]);global RNDM2_flag;RNDM2_flag="user" def case12(): global cutgam;cutgam=float(temp[1]);global cutgam_flag;cutgam_flag="user" global cutele;cutele=float(temp[2]);global cutele_flag;cutele_flag="user" global cutneu;cutneu=float(temp[3]);global cutneu_flag;cutneu_flag="user" global cuthad;cuthad=float(temp[4]);global cuthad_flag;cuthad_flag="user" global cutmuo;cutmuo=float(temp[5]);global cutmuo_flag;cutmuo_flag="user" if (len(temp)>6): global bcute;bcute=float(temp[6]);global bcute_flag;bcute_flag="user" if (len(temp)>7): global bcutm;bcutm=float(temp[7]);global bcutm_flag;bcutm_flag="user" if (len(temp)>8): global dcute;dcute=float(temp[8]);global dcute_flag;dcute_flag="user" if (len(temp)>9): global dcutm;dcutm=float(temp[9]);global dcutm_flag;dcutm_flag="user" if (len(temp)>10): global ppcutm;ppcutm=float(temp[10]);global ppcutm_flag;ppcutm_flag="user" if (len(temp)>11): global tofmax;tofmax=float(temp[11]);global tofmax_flag;tofmax_flag="user" if (len(temp)>12): global gcuts;gcuts=float(temp[12]);global gcuts_flag;gcuts_flag="user" def case13(): global SWIT_1;SWIT_1=int(temp[1]);global SWIT_1_flag;SWIT_1_flag="user" global SWIT_2;SWIT_2=int(temp[2]);global SWIT_2_flag;SWIT_2_flag="user" global SWIT_3;SWIT_3=int(temp[3]);global SWIT_3_flag;SWIT_3_flag="user" global SWIT_4;SWIT_4=int(temp[4]);global SWIT_4_flag;SWIT_4_flag="user" global SWIT_5;SWIT_5=int(temp[5]);global SWIT_5_flag;SWIT_5_flag="user" global SWIT_6;SWIT_6=int(temp[6]);global SWIT_6_flag;SWIT_6_flag="user" global SWIT_7;SWIT_7=int(temp[7]);global SWIT_7_flag;SWIT_7_flag="user" global SWIT_8;SWIT_8=int(temp[8]);global SWIT_8_flag;SWIT_8_flag="user" global SWIT_9;SWIT_9=int(temp[9]);global SWIT_9_flag;SWIT_9_flag="user" def case14(): global on_off;on_off=int(temp[1]);global on_off_flag;on_off_flag="user" global ecut;ecut=float(temp[2]);global ecut_flag;ecut_flag="user" global scale;scale=float(temp[3]);global scale_flag;scale_flag="user" global mode;mode=int(temp[4]);global mode_flag;mode_flag="user" global thresh;thresh=float(temp[5]);global thresh_flag;thresh_flag="user" def case15(): global HADR;HADR=int(temp[1]);global HADR_flag;HADR_flag="user" def case16(): global CKOV;CKOV=int(temp[1]);global CKOV_flag;CKOV_flag="user" def case17(): global LABS;LABS=int(temp[1]);global LABS_flag;LABS_flag="user" def case18(): global ABAN;ABAN=int(temp[1]);global ABAB_flag;ABAN_flag="user" def case19(): global first;first=int(temp[1]);global first_flag;first_flag="user" global last;last=int(temp[2]);global last_flag;last_flag="user" global step;step=int(temp[3]);global step_flag;step_flag="user" def case20(): global NOSECONDARIES;NOSECONDARIES=int(temp[1]);global NOSECONDARIES_flag;NOSECONDARIES_flag="user" def case21(): global TRAJECTORIES;TRAJECTORIES=int(temp[1]);global TRAJECTORIES_flag;TRAJECTORIES_flag="user" def case22(): global SAVEHITS;SAVEHITS=int(temp[1]);global SAVEHITS_flag;SAVEHITS_flag="user" def case23(): global SHOWERSINCOL;SHOWERSINCOL=int(temp[1]);global SHOWERSINCOL_flag;SHOWERSINCOL_flag="user" def end(): end=0 #default values TRIG=1000; TRIG_flag="default" Emax=12.; Emax_flag="default" Epeak=9.; Epeak_flag="default" Emin=None; Emin_flag="default" OUTFILE='hdgeant.hddm'; OUTFILE_flag="default" POSTSMEAR=0; POSTSMEAR_flag="default" DELETEUNSMEARED=0; DELETEUNSMEARED_flag="default" particle=101; particle_flag="default" momentum=9.0; momentum_flag="default" theta=10.; theta_flag="default" phi=0.; phi_flag="default" delta_momentum=0.; delta_momentum_flag="default" delta_theta=3.; delta_theta_flag="default" delta_phi=360.; delta_phi_flag="default" vertex_x=0.; vertex_x_flag="default" vertex_y=0.; vertex_y_flag="default" vertex_z=0; vertex_z_flag="default" fhalo=5e-5; fhalo_flag="default" BGRATE=1.10; BGRATE_flag="default" t1=-200.; t1_flag="default" t2=200.; t2_flag="default" RNDM1=121; RNDM1_flag="default" RNDM2=None; RNDM2_flag="default" cutgam=1e-4; cutgam_flag="default" cutele=1e-4; cutele_flag="default" cutneu=1e-3; cutneu_flag="default" cuthad=1e-3; cuthad_flag="default" cutmuo=1e-4; cutmuo_flag="default" bcute=None; bcute_flag="default" bcutm=None; bcutm_flag="default" dcute=None; dcute_flag="default" dcutm=None; dcutm_flag="default" ppcutm=None; ppcutm_flag="default" tofmax=None; tofmax_flag="default" gcuts=None; gcuts_flag="default" SWIT_1=0; SWIT_1_flag="default" SWIT_2=0; SWIT_2_flag="default" SWIT_3=0; SWIT_3_flag="default" SWIT_4=0; SWIT_4_flag="default" SWIT_5=0; SWIT_5_flag="default" SWIT_6=0; SWIT_6_flag="default" SWIT_7=0; SWIT_7_flag="default" SWIT_8=0; SWIT_8_flag="default" SWIT_9=0; SWIT_9_flag="default" on_off=1; on_off_flag="default" ecut=0.2; ecut_flag="default" scale=1.0; scale_flag="default" mode=4; mode_flag="default" thresh=0.160; thresh_flag="default" HADR=1; HADR_flag="default" CKOV=1; CKOV_flag="default" LABS=1; LABS_flag="default" ABAN=1; ABAN_flag="default" first=1; first_flag="default" last=10; last_flag="default" step=1000; step_flag="default" NOSECONDARIES=0; NOSECONDARIES_flag="default" TRAJECTORIES=0; TRAJECTORIES_flag="default" SAVEHITS=0; SAVEHITS_flag="defalut" SHOWERSINCOL=0; SHOWERSINCOL_flag="default" cases = { "TRIG":case1, "BEAM":case2, "OUTFILE":case3, "POSTSMEAR":case4, "DELETEUNSMEARED":case5, "KINE":case6, "SCAP":case7, "HALO":case8, "BGRATE":case9, "BGGATE":case10, "RNDM":case11, "CUTS":case12, "SWIT":case13, "GELH":case14, "HADR":case15, "CKOV":case16, "LABS":case17, "ABAN":case18, "DEBU":case19, "NOSECONDARIES":case20, "TRAJECTORIES":case21, "SAVEHITS":case22, "SHOWERSINCOL":case23, "END":end} #------------------------------------------------------------ #call def call(): RUNNER = open("runner.py","w") RUNNER.write("import os\n") RUNNER.write("newFile = 'pid'\n") RUNNER.write("FILE = open(newFile,\"w\")\n") RUNNER.write("FILE.write(str(os.getpid()))\n") RUNNER.write("FILE.close()\n") RUNNER.close() os.system("python runner.py") #------------------------------------------------------------ #read in file for line in open(fileName,'r').readlines(): if not line[0]=='c': temp = line.split() if not len(temp)==0: cases[temp[0]]() #------------------------------------------------------------ #write new file ID=os.getpid() curdir=os.getcwd() newdir = curdir + '/new_mhdgeant_' + str(os.getpid()) if not os.path.isdir(newdir): os.mkdir(newdir) os.chdir(newdir) curdir=os.getcwd() for i in range(int(run)): newdir = "%(#)03d" %{"#":(i+1)} if not os.path.isdir(newdir): os.mkdir(newdir) os.chdir(newdir) newFile = 'control.in' FILE = open(newFile,"w") fill() FILE.close() child_pid = os.fork() if child_pid == 0: call() sys.exit() os.chdir(curdir) ID=ID+1