forked from kdlong/AnalysisDatasetManager
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmodifySets.py
More file actions
executable file
·230 lines (193 loc) · 6.44 KB
/
modifySets.py
File metadata and controls
executable file
·230 lines (193 loc) · 6.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
#!/usr/bin/env python
import os
import json
import argparse
from modifyHelper import *
"""
Weird code I wrote to set global variables of analysis etc.
Call the ana(), sel(), inp() and it takes care of finding choices
and picking a choice
TODO: allow ability to add ana, sel, inp, etc
"""
Analysis=""
InputTier=""
Selection=""
def ana():
global Analysis
if Analysis != "":
return Analysis
else:
anaList = getAnalysis()
if len(anaList) == 0:
print "Can't find analysis!"
exit(0)
elif len(anaList) == 1:
Analysis = anaList[0]
else:
Analysis = menu("Choose an Analysis to Modify", anaList)
return Analysis
def inp():
global InputTier
if InputTier != "":
return InputTier
else:
inputList = getInputs(ana())
if len(inputList) == 0:
print "Can't find InputTier!"
exit(0)
elif len(inputList) == 1:
InputTier = inputList[0]
else:
InputTier = menu("Choose an InputTier to Modify", inputList)
return InputTier
def sel():
global Selection
if Selection != "":
return Selection
else:
selList = getSelections(ana())
if len(selList) == 0:
print "Can't find selection!"
exit(0)
elif len(selList) == 1:
Selection = selList[0]
else:
Selection = menu("Choose an Selection to Modify", selList)
return Selection
def menu(beginText, lister):
"""
Takes list of options and print text and chooses one of those options
Does all of the checking that it's a valid choice so it return only
good options
"""
print beginText
returnText = ""
half = int((len(lister)+1)/2)
for i in xrange(int((len(lister))/2)):
print "%2s: %-25s %2s: %-25s" % (i+1, lister[i], i+half+1, lister[i+half])
if len(lister) % 2 == 1:
print "%2s: %-25s" % (half, lister[half-1])
ans=True
while ans:
ans=raw_input("$ ")
try:
choice = int(ans)
if choice <= len(lister) and choice > 0:
returnText = lister[choice-1]
break
else:
print("\nNot Valid Choice Try again")
except ValueError:
print("\nNot Valid Choice Try again")
print
return returnText
#################################################################
# Main functions used for setting up Adding things to the files #
# based on the names in the main menu. #
# NOTE: capital "Add" used to note this is a menu option #
#################################################################
def AddHistogram(ana, sel):
inpVars = []
questions = ["What is the Name of the Histogram: ",
"What is the Number of bins: ",
"What is the low value: ",
"What is the high value: ",
"What is the X Axis Name: ",
"What is the Y Axis Name: ",
]
for q in questions:
try:
answer = raw_input(q)
except SyntaxError:
answer = ""
inpVars.append(answer)
addPlotObject(ana, sel, inpVars)
def AddFile(ana, inp, file_path):
#### to do
groups=getGroups(ana)
groups.append("New Group")
group_choice = menu("Which group will this go with?", groups)
if group_choice == "New Group":
group_choice = raw_input("What is abbreviated name of the Group: ")
addPlotGroup(ana, group_choice)
print
mcList = getMCNames()
mcList.sort()
mcList.append("New Name")
mc_choice = menu("What do you want to name it", mcList)
if mc_choice == "New Name":
mc_choice = raw_input("What do you want the new Name to be: ")
addMCItem(mc_choice)
print
addFileInfo(ana, inp, mc_choice, group_choice, file_path)
addMember(ana, group_choice, mc_choice)
return
############################
# ___ ___ ___ __ __ __ #
# ||\\//|| // \\ || ||\ || #
# || \/ || ||=|| || ||\\|| #
# || || || || || || \|| #
############################
parser = argparse.ArgumentParser()
parser.add_argument("-s", "--selection", type=str, default="",
help="Name of selection to make, "
" as defined in Cuts/<analysis>/<selection>.json")
parser.add_argument("-a", "--analysis", type=str, required=False, default="",
help="Analysis name, used in selecting the cut json")
parser.add_argument("-i", "--input_tier", type=str, default="",required=False)
parser.add_argument("--AddFile", type=str, default="",
help="Go straight to AddFile and add filename given")
parser.add_argument("--AddHistogram", action='store_true',
help="Go straight to AddHistogram and add filename given")
args = parser.parse_args()
Analysis = args.analysis
Selection = args.selection
InputTier = args.input_tier
if args.AddFile:
AddFile(ana(), inp(), args.AddFile)
exit(0)
elif args.AddHistogram:
AddHistogram(ana(), sel())
exit(0)
#############
# Main Menu #
#############
actionList = ["Add a File", "Add a Histogram", "List Data", "List MC", "List Histograms", "Quit"]
while True:
action = menu("What action do you want to do?", actionList)
# Add a file
if action == "Add a File":
file_path=raw_input("What is the File Path: ")
AddFile(ana(), inp(), file_path)
# Add a Histogram
elif action == "Add a Histogram":
AddHistogram(ana(), sel())
# List Data
elif action == "List Data":
files = getFiles(ana(), inp())
for val in files:
if "data" in val:
print val
print
# List MC
elif action == "List MC":
files = getFiles(ana(), inp())
for val in files:
if "data" not in val:
print val
print
# List Histograms
elif action == "List Histograms":
hists = getHistograms(ana(), sel())
hists.append("END")
while True:
histChoice = menu("Look at histogram info? (END to return to menu)", hists)
if histChoice == hists[-1]:
break
else:
print json.dumps(getHistogramInfo(Analysis, Selection, histChoice), indent=2)
print
# Quit
elif action == actionList[-1]:
print actionList[-1]
break