1 | import os
|
---|
2 | import argparse
|
---|
3 | import subprocess
|
---|
4 | import time
|
---|
5 |
|
---|
6 | if (os.environ.get('CONFIG_HAWC') == None):
|
---|
7 | print "Did not find HAWC enviroment (try hawc-sw)!"
|
---|
8 | exit()
|
---|
9 |
|
---|
10 | parser = argparse.ArgumentParser()
|
---|
11 | parser.add_argument("-p", "--path", dest="path", help="Search path (recursive!) for trigger files (xcd)",type=str,required=True)
|
---|
12 | parser.add_argument("-s", "--strip", action="store_true", help="Only strip all files in path", required=False)
|
---|
13 | parser.add_argument("-r", "--reco", action="store_true", help="Only reconstruct all files in path", required=False)
|
---|
14 | parser.add_argument("-c", "--root", action="store_true", help="Only convert all files to root in path", required=False)
|
---|
15 | parser.add_argument("-j", "--proc", dest="proc", help="Number of processes (max. cores + 1)",type=int , required=False)
|
---|
16 | parser.add_argument("--filter", dest="filter", help="Only use files containing string FILTER", type=str, required=False)
|
---|
17 | parser.add_argument("--channel", dest="channel", help="Specify a channel for the trigger flag (Default: 31,E16C)",type=int , required=False)
|
---|
18 |
|
---|
19 | args = parser.parse_args()
|
---|
20 |
|
---|
21 | channel_id = 31
|
---|
22 | max_proc = 2
|
---|
23 |
|
---|
24 | if args.channel:
|
---|
25 | channel_id = args.channel
|
---|
26 |
|
---|
27 | if args.proc:
|
---|
28 | max_proc = args.proc
|
---|
29 |
|
---|
30 | print """
|
---|
31 | ************************************
|
---|
32 | * *
|
---|
33 | * Welcome to HAWCs Eye *
|
---|
34 | * *
|
---|
35 | * Filter and reconstruction tool *
|
---|
36 | * *
|
---|
37 | * Version 1.0 01.08.2017 *
|
---|
38 | * *
|
---|
39 | ************************************
|
---|
40 |
|
---|
41 | Search path: {}
|
---|
42 | Channel ID : {}
|
---|
43 | """.format(args.path,channel_id)
|
---|
44 |
|
---|
45 | process_list = []
|
---|
46 | if not args.reco and not args.root:
|
---|
47 | strip_flist = []
|
---|
48 | #Search for .xcd files in args.path without "strp" or "reco" in the filename
|
---|
49 | for root,dirs,files in os.walk(args.path):
|
---|
50 | if args.filter is None:
|
---|
51 | for xcdfile in [xcdf for xcdf in files if (('.xcd' in xcdf[-4:]) and not ('strp' in xcdf) and not ('reco' in xcdf))]:
|
---|
52 | strip_flist.append(root+"/"+xcdfile)
|
---|
53 | else:
|
---|
54 | for xcdfile in [xcdf for xcdf in files if (('.xcd' in xcdf[-4:]) and not ('strp' in xcdf) and not ('reco' in xcdf) and (args.filter in xcdf))]:
|
---|
55 | strip_flist.append(root+"/"+xcdfile)
|
---|
56 |
|
---|
57 |
|
---|
58 | #Filter files for a hit in channel_id
|
---|
59 | for xcdfile in strip_flist:
|
---|
60 | process_string = 'xcdf select "trig.channelID_4Edge == {}" -o {}_strp.xcd {}'.format(channel_id,xcdfile[:-4],xcdfile)
|
---|
61 | print "Starting: " + process_string
|
---|
62 | process_list.append(subprocess.Popen(process_string,shell=True))
|
---|
63 | while([status.poll() for status in process_list].count(None) >= max_proc):
|
---|
64 | time.sleep(0.2)
|
---|
65 |
|
---|
66 | #Wait for all strip processes to finish:
|
---|
67 | while([status.poll() for status in process_list].count(None) > 0):
|
---|
68 | time.sleep(0.2)
|
---|
69 | #Reset process list:
|
---|
70 | process_list = []
|
---|
71 |
|
---|
72 | if not args.strip and not args.root:
|
---|
73 | reco_flist = []
|
---|
74 | #Search for .xcd files in args.path with "strp" in the filename
|
---|
75 | for root,dirs,files in os.walk(args.path):
|
---|
76 | if args.filter is None:
|
---|
77 | for xcdfile in [xcdf for xcdf in files if (('.xcd' in xcdf[-4:]) and ('strp' in xcdf[-8:-4]))]:
|
---|
78 | reco_flist.append(root+"/"+xcdfile)
|
---|
79 | else:
|
---|
80 | for xcdfile in [xcdf for xcdf in files if (('.xcd' in xcdf[-4:]) and ('strp' in xcdf[-8:-4]) and (args.filter in xcdf))]:
|
---|
81 | reco_flist.append(root+"/"+xcdfile)
|
---|
82 |
|
---|
83 | #Reco strp files:
|
---|
84 | for xcdfile in reco_flist:
|
---|
85 | if (args.filter == None):
|
---|
86 | process_string = 'offline-reconstructor --input {} -o {}_reco.xcd'.format(xcdfile,xcdfile[:-9])
|
---|
87 | else:
|
---|
88 | process_string = 'offline-reconstructor --input {} -o {}_reco.xcd'.format(xcdfile,xcdfile[:-4])
|
---|
89 | print "Starting: " + process_string
|
---|
90 | process_list.append(subprocess.Popen(process_string,shell=True))
|
---|
91 | while([status.poll() for status in process_list].count(None) >= max_proc):
|
---|
92 | time.sleep(0.2)
|
---|
93 |
|
---|
94 | #Wait for all reconstruction processes to finish
|
---|
95 | while([status.poll() for status in process_list].count(None) > 0):
|
---|
96 | time.sleep(0.2)
|
---|
97 |
|
---|
98 | #Reset process list:
|
---|
99 | process_list = []
|
---|
100 |
|
---|
101 | if not args.strip and not args.reco:
|
---|
102 | root_flist = []
|
---|
103 | #Search for .xcd files in args.path with "reco" in the filename
|
---|
104 | for root,dirs,files in os.walk(args.path):
|
---|
105 | if args.filter is None:
|
---|
106 | for xcdfile in [xcdf for xcdf in files if (('.xcd' in xcdf[-4:]) and ('reco' in xcdf))]:
|
---|
107 | root_flist.append(root+"/"+xcdfile)
|
---|
108 | else:
|
---|
109 | for xcdfile in [xcdf for xcdf in files if (('.xcd' in xcdf[-4:]) and ('reco' in xcdf) and (args.filter in xcdf))]:
|
---|
110 | root_flist.append(root+"/"+xcdfile)
|
---|
111 |
|
---|
112 | #xcd to root files:
|
---|
113 | for xcdfile in root_flist:
|
---|
114 | process_string = 'xcdf-root --input {} -o {}.root'.format(xcdfile,xcdfile[:-4])
|
---|
115 | print "Starting: " + process_string
|
---|
116 | process_list.append(subprocess.Popen(process_string,shell=True))
|
---|
117 | while([status.poll() for status in process_list].count(None) >= max_proc):
|
---|
118 | time.sleep(0.2)
|
---|
119 |
|
---|
120 | #Wait for all files beeing converted
|
---|
121 | while([status.poll() for status in process_list].count(None) > 0):
|
---|
122 | time.sleep(0.2)
|
---|