All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
run_simTestPulse.py
Go to the documentation of this file.
1 import sys,os,commands,subprocess,time
2 
3 if len(commands.getoutput('which lar').split())>1:
4  sys.stderr.write('No "lar" command found...\n')
5  sys.stderr.flush()
6  sys.exit(1)
7 
8 WORK_DIR='/tmp/%s_fakenews' % os.environ['USER']
9 OUT_FILE ='simTestPulse_full.root'
10 
11 if os.path.isdir(WORK_DIR):
12  sys.stderr.write('Found already-exisitng work dir "%s" ... remove and try re-run!\n' % WORK_DIR)
13  sys.stderr.flush()
14  sys.exit(1)
15 if os.path.isfile(OUT_FILE):
16  sys.stderr.write('Found already-exisitng out file "%s" ... remove and try re-run!\n' % OUT_FILE)
17  sys.stderr.flush()
18  sys.exit(1)
19 
20 os.mkdir(WORK_DIR)
21 
22 proc = subprocess.Popen('cd %s;lar -c simtestpulse_driver.fcl' % WORK_DIR,shell=True,stderr=subprocess.STDOUT,stdout=subprocess.PIPE)
23 state = None
24 time_slept = 0
25 while state is None:
26  state = proc.poll()
27  sys.stdout.write('Running lar... (%-2d [s])\r' % time_slept)
28  sys.stdout.flush()
29  time.sleep(1)
30  time_slept += 1
31 print
32 
33 fout=open('log.txt','w')
34 out,err = proc.communicate()
35 fout.write(out)
36 fout.close()
37 print 'Log file created: log.txt'
38 
39 if not state == 0:
40  sys.stderr.write('Failed running the code (state=%s)! Check log.txt...\n' % str(state))
41  sys.stderr.flush()
42 else:
43  os.system('hadd %s %s/simTestPulse.root %s/simTestPulseAna.root' % (OUT_FILE,WORK_DIR,WORK_DIR))
44  print
45  print 'Output:',OUT_FILE
46  print
47 os.system('rm -r %s' % WORK_DIR)
open(RACETRACK) or die("Could not open file $RACETRACK for writing")