-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathrunTableMaker_withAssoc.py
executable file
·280 lines (245 loc) · 12.2 KB
/
runTableMaker_withAssoc.py
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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
#!/usr/bin/env python3
from ast import parse
import sys
import json
import os
import argparse
parser = argparse.ArgumentParser(description='Arguments to pass')
parser.add_argument('cfgFileName', metavar='text', default='config.json', help='config file name')
parser.add_argument('-runData', help="Run over data", action="store_true")
parser.add_argument('-runMC', help="Run over MC", action="store_true")
parser.add_argument('--arg', help='Configuration argument')
parser.add_argument('--add_mc_conv', help="Add the converter from mcparticle to mcparticle+001", action="store_true")
parser.add_argument('--add_fdd_conv', help="Add the fdd converter", action="store_true")
parser.add_argument('--add_zdc_conv', help="Add the zdc converter", action="store_true")
parser.add_argument('--add_bc_conv', help="Add the BC converter", action="store_true")
parser.add_argument('--add_track_prop', help="Add track propagation to the innermost layer (TPC or ITS)", action="store_true")
parser.add_argument("--add_weakdecay_ind", help = "Add Converts V0 and cascade version 000 to 001", action = "store_true")
parser.add_argument("--add_col_conv", help = "Add the converter from collision to collision+001", action = "store_true")
parser.add_argument("--add_track_extra_conv", help = "Add the converter from track_extra to track_extra+001", action = "store_true")
parser.add_argument("--add_mft_conv", help = "Add the converter from mfttrack_001 to mfttrack", action = "store_true")
extrargs = parser.parse_args()
commonDeps = ["o2-analysis-timestamp", "o2-analysis-event-selection", "o2-analysis-multiplicity-table"]
#commonDeps = ["o2-analysis-timestamp", "o2-analysis-event-selection"]
barrelDeps = ["o2-analysis-trackselection", "o2-analysis-trackextension","o2-analysis-pid-tof-base", "o2-analysis-pid-tof", "o2-analysis-pid-tof-full", "o2-analysis-pid-tof-beta", "o2-analysis-pid-tpc-base", "o2-analysis-pid-tpc-full", "o2-analysis-track-to-collision-associator"]
#barrelDeps = ["o2-analysis-trackselection","o2-analysis-pid-tof-base", "o2-analysis-pid-tof", "o2-analysis-pid-tof-full", "o2-analysis-pid-tof-beta", "o2-analysis-pid-tpc-full"]
muonDeps = ["o2-analysis-fwdtrackextension", "o2-analysis-fwdtrack-to-collision-associator"]
#muonDeps = ["o2-analysis-fwdtrackextension"]
specificDeps = {
"processPP": [],
"processPPBarrelOnly": [],
"processPPMuonOnly": [],
"processPPMuonMFT": [],
"processPPWithFilter": ["o2-analysis-dq-filter-pp-with-association"],
"processPPWithFilterBarrelOnly": ["o2-analysis-dq-filter-pp-with-association"],
"processPPWithFilterMuonOnly": ["o2-analysis-dq-filter-pp-with-association"],
"processPPWithFilterMuonMFT": ["o2-analysis-dq-filter-pp-with-association"],
"processPbPb": [],
"processPbPbBarrelOnly": [],
"processPbPbMuonOnly": [],
"processPbPbMuonMFT": []
}
# Definition of all the tables we may write
tables = {
"ReducedEvents" : {"table": "AOD/REDUCEDEVENT/0"},
"ReducedEventsExtended" : {"table": "AOD/REEXTENDED/0"},
"ReducedEventsVtxCov" : {"table": "AOD/REVTXCOV/0"},
"ReducedEventsQvector" : {"table": "AOD/REQVECTOR/0"},
"ReducedEventsMultPV" : {"table": "AOD/REMULTPV/0"},
"ReducedEventsMultAll" : {"table": "AOD/REMULTALL/0"},
"ReducedTracks" : {"table": "AOD/REDUCEDTRACK/0"},
"ReducedTracksBarrel" : {"table": "AOD/RTBARREL/0"},
"ReducedTracksBarrelCov" : {"table": "AOD/RTBARRELCOV/0"},
"ReducedTracksBarrelPID" : {"table": "AOD/RTBARRELPID/0"},
"ReducedTracksBarrelLabels" : {"table": "AOD/RTBARRELLABELS/0"},
"ReducedMuons" : {"table": "AOD/REDUCEDMUON/0"},
"ReducedMuonsExtra" : {"table": "AOD/RTMUONEXTRA/0"},
"ReducedMuonsCov" : {"table": "AOD/RTMUONCOV/0"},
"ReducedMuonsLabels" : {"table": "AOD/RTMUONSLABELS/0"},
"DalitzBits" : {"table": "AOD/DALITZBITS/0"},
"ReducedMFTTracks" : {"table": "AOD/REDUCEDMFT/0"},
"ReducedMFTTracksExtra" : {"table": "AOD/RMFTEXTRA/0"},
"ReducedTracksAssoc" : {"table": "AOD/RTASSOC/0"},
"ReducedMuonsAssoc" : {"table": "AOD/RMASSOC/0"},
"ReducedMFTAssoc" : {"table": "AOD/RMFTASSOC/0"},
"ReducedMCEvents" : {"table": "AOD/REDUCEDMCEVENT/0"},
"ReducedMCEventLabels" : {"table": "AOD/REMCCOLLBL/0"},
"ReducedMCTracks" : {"table": "AOD/REDUCEDMCTRACK/0"},
"ReducedTracksBarrelLabels" : {"table": "AOD/RTBARRELLABELS/0"},
"ReducedMuonsLabels" : {"table": "AOD/RTMUONSLABELS/0"}
}
# Tables to be written, per process function
commonTables = ["ReducedEvents", "ReducedEventsExtended", "ReducedEventsVtxCov", "ReducedEventsMultPV", "ReducedEventsMultAll"]
barrelCommonTables = ["ReducedTracks","ReducedTracksBarrel","ReducedTracksBarrelPID", "ReducedTracksBarrelCov", "ReducedTracksAssoc"]
muonCommonTables = ["ReducedMuons", "ReducedMuonsExtra", "ReducedMuonsAssoc", "ReducedMuonsCov"]
#muonCommonTables = ["ReducedMuons", "ReducedMuonsExtra", "ReducedMFTTracks", "ReducedMFTTracksExtra", "ReducedMuonsAssoc", "ReducedMFTAssoc"]
specificTables = {
"processPP": ["ReducedMFTTracks", "ReducedMFTTracksExtra", "ReducedMFTAssoc"],
"processPPBarrelOnly": [],
"processPPMuonOnly": ["ReducedMFTTracks", "ReducedMFTTracksExtra", "ReducedMFTAssoc"],
"processPPMuonMFT": ["ReducedMFTTracks", "ReducedMFTTracksExtra", "ReducedMFTAssoc"],
"processPPWithFilter": ["ReducedMFTTracks", "ReducedMFTTracksExtra", "ReducedMFTAssoc"],
"processPPWithFilterBarrelOnly": [],
"processPPWithFilterMuonOnly": [],
"processPPWithFilterMuonMFT": ["ReducedMFTTracks", "ReducedMFTTracksExtra", "ReducedMFTAssoc"],
"processPbPb": ["ReducedMFTTracks", "ReducedMFTTracksExtra", "ReducedMFTAssoc"],
"processPbPbBarrelOnly": [],
"processPbPbMuonOnly": [],
"processPbPbMuonMFT": ["ReducedMFTTracks", "ReducedMFTTracksExtra", "ReducedMFTAssoc"]
}
# Make some checks on provided arguments
if len(sys.argv) < 3:
print("ERROR: Invalid syntax! The command line should look like this:")
print(" ./runTableMaker.py <yourConfig.json> <runData|runMC> [task:param:value] ...")
sys.exit()
# Load the configuration file provided as the first parameter
config = {}
with open(extrargs.cfgFileName) as configFile:
config = json.load(configFile)
# Check whether we run over data or MC
if not (extrargs.runMC or extrargs.runData):
print("ERROR: You have to specify either runMC or runData !")
sys.exit()
runOverMC = False
if (extrargs.runMC):
runOverMC = True
print("runOverMC ",runOverMC)
# Delete trackextension dependency if track-propagation dependency provided (for compatibility)
if extrargs.add_track_prop:
barrelDeps.remove("o2-analysis-trackextension")
if extrargs.arg != "" and extrargs.arg is not None:
args = [line.split(':') for line in extrargs.arg.split(',') if line]
for threeIndex in args:
if len(threeIndex) != 3:
print("ERROR: Wrong parameter syntax for --arg: ", threeIndex, " in ", extrargs.arg)
print("Correct syntax: task:param:value,task:param:value ... ")
print("Example: --arg table-maker:processBarrelOnly:true")
sys.exit()
for arg in args:
config[arg[0]][arg[1]] = arg[2]
taskNameInConfig = "table-maker"
taskNameInCommandLine = "o2-analysis-dq-table-maker-with-assoc"
if runOverMC == True:
taskNameInConfig = "table-maker-m-c"
taskNameInCommandLine = "o2-analysis-dq-table-maker-mc-with-assoc"
if not taskNameInConfig in config:
print("ERROR: Task to be run not found in the configuration file!")
sys.exit()
# Write the updated configuration file into a temporary file
updatedConfigFileName = "tempConfig.json"
with open(updatedConfigFileName,'w') as outputFile:
json.dump(config, outputFile, indent = 2)
# Check which dependencies need to be run
depsToRun = {}
for dep in commonDeps:
depsToRun[dep] = 1
for processFunc in specificDeps.keys():
if not processFunc in config[taskNameInConfig].keys():
continue
if config[taskNameInConfig][processFunc] == "true":
if "processPP" in processFunc or "processPbPb" in processFunc:
for dep in barrelDeps:
depsToRun[dep] = 1
for dep in muonDeps:
depsToRun[dep] = 1
if "BarrelOnly" in processFunc:
for dep in muonDeps:
depsToRun[dep] = 0
if "Muon" in processFunc:
for dep in barrelDeps:
depsToRun[dep] = 0
for dep in specificDeps[processFunc]:
depsToRun[dep] = 1
# Check which tables are required in the output
tablesToProduce = {}
for table in commonTables:
tablesToProduce[table] = 1
if runOverMC == True:
tablesToProduce["ReducedMCEvents"] = 1
tablesToProduce["ReducedMCEventLabels"] = 1
for processFunc in specificDeps.keys():
if not processFunc in config[taskNameInConfig].keys():
continue
if config[taskNameInConfig][processFunc] == "true":
print("processFunc ========")
print(processFunc)
if "processPP" in processFunc or "processPbPb" in processFunc:
print("common barrel tables==========")
for table in barrelCommonTables:
print(table)
tablesToProduce[table] = 1
for table in muonCommonTables:
print(table)
tablesToProduce[table] = 1
if runOverMC == True:
tablesToProduce["ReducedTracksBarrelLabels"] = 1
tablesToProduce["ReducedMuonsLabels"] = 1
if "BarrelOnly" in processFunc:
print("common muon tables==========")
for table in muonCommonTables:
print(table)
tablesToProduce[table] = 0
if runOverMC == True:
tablesToProduce["ReducedMuonsLabels"] = 0
if "Muon" in processFunc:
print("common muon tables==========")
for table in barrelCommonTables:
print(table)
tablesToProduce[table] = 0
if runOverMC == True:
tablesToProduce["ReducedTracksBarrelLabels"] = 0
if runOverMC == True:
tablesToProduce["ReducedMCTracks"] = 1
print("specific tables==========")
for table in specificTables[processFunc]:
print(table)
tablesToProduce[table] = 1
# Generate the aod-writer output descriptor json file
writerConfig = {}
writerConfig["OutputDirector"] = {
"debugmode": True,
"resfile": "reducedAod",
"resfilemode": "RECREATE",
"ntfmerge": 1,
"OutputDescriptors": []
}
iTable = 0
for table in tablesToProduce.keys():
writerConfig["OutputDirector"]["OutputDescriptors"].insert(iTable, tables[table])
iTable += 1
writerConfigFileName = "aodWriterTempConfig.json"
with open(writerConfigFileName,'w') as writerConfigFile:
json.dump(writerConfig, writerConfigFile, indent = 2)
print(writerConfig)
#sys.exit()
commandToRun = taskNameInCommandLine + " --configuration json://" + updatedConfigFileName + " --severity error --shm-segment-size 12000000000 --aod-writer-json " + writerConfigFileName + " -b"
for dep in depsToRun.keys():
if depsToRun[dep]:
commandToRun += " | " + dep + " --configuration json://" + updatedConfigFileName + " -b"
if extrargs.add_mc_conv:
commandToRun += " | o2-analysis-mc-converter --configuration json://" + updatedConfigFileName + " -b"
if extrargs.add_fdd_conv:
commandToRun += " | o2-analysis-fdd-converter --configuration json://" + updatedConfigFileName + " -b"
if extrargs.add_zdc_conv:
commandToRun += " | o2-analysis-zdc-converter --configuration json://" + updatedConfigFileName + " -b"
if extrargs.add_bc_conv:
commandToRun += " | o2-analysis-bc-converter --configuration json://" + updatedConfigFileName + " -b"
if extrargs.add_track_prop:
commandToRun += " | o2-analysis-track-propagation --configuration json://" + updatedConfigFileName + " -b"
if extrargs.add_weakdecay_ind:
commandToRun += " | o2-analysis-weak-decay-indices --configuration json://" + updatedConfigFileName + " -b"
if extrargs.add_col_conv:
commandToRun += " | o2-analysis-collision-converter --configuration json://" + updatedConfigFileName + " -b"
if extrargs.add_track_extra_conv:
commandToRun += " | o2-analysis-tracks-extra-converter --configuration json://" + updatedConfigFileName + " -b"
if extrargs.add_mft_conv:
commandToRun += " | o2-analysis-mft-tracks-converter --configuration json://" + updatedConfigFileName + " -b"
print("====================================================================================================================")
print("Command to run:")
print(commandToRun)
print("====================================================================================================================")
print("Tables to produce:")
print(tablesToProduce.keys())
print("====================================================================================================================")
#sys.exit()
os.system(commandToRun)