O2-DQ User Interface 1.0.0
Loading...
Searching...
No Matches
runFilterPP.py
Go to the documentation of this file.
1#!/usr/bin/env python3
2# PYTHON_ARGCOMPLETE_OK
3# -*- coding: utf-8 -*-
4
5# Copyright 2019-2020 CERN and copyright holders of ALICE O2.
6# See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
7# All rights not expressly granted are reserved.
8#
9# This software is distributed under the terms of the GNU General Public
10# License v3 (GPL Version 3), copied verbatim in the file "COPYING".
11#
12# In applying this license CERN does not waive the privileges and immunities
13# granted to it by virtue of its status as an Intergovernmental Organization
14# or submit itself to any jurisdiction.
15
16# \Author: ionut.cristian.arsene@cern.ch
17# \Interface: cevat.batuhan.tolon@cern.ch
18
19# Orginal Task: https://github.com/AliceO2Group/O2Physics/blob/master/PWGDQ/Tasks/filterPP.cxx
20
21import json
22import logging
23import logging.config
24import os
25from extramodules.converterManager import converterManager
26from extramodules.debugSettings import debugSettings
27
28from extramodules.monitoring import dispArgs
29from extramodules.dqTranscations import aodFileChecker, forgettedArgsChecker, jsonTypeChecker, filterSelsTranscation, mainTaskChecker, trackPropChecker, trackPropTransaction
30from extramodules.configSetter import multiConfigurableSet
31from extramodules.pycacheRemover import runPycacheRemover
32
33from dqtasks.filterPP import DQFilterPPTask
34
35
38
39centralityTableParameters = [
40 "estRun2V0M", "estRun2SPDtks", "estRun2SPDcls", "estRun2CL0", "estRun2CL1", "estFV0A", "estFT0M", "estFDDM", "estNTPV",
41 ]
42# TODO: Add genname parameter
43
44ft0Parameters = ["processFT0", "processNoFT0", "processOnlyFT0", "processRun2"]
45
46pidParameters = ["pid-el", "pid-mu", "pid-pi", "pid-ka", "pid-pr", "pid-de", "pid-tr", "pid-he", "pid-al"]
47
48ttreeList = []
49
50
53
54commonDeps = [
55 "o2-analysis-timestamp", "o2-analysis-event-selection", "o2-analysis-multiplicity-table", "o2-analysis-trackselection",
56 "o2-analysis-trackextension", "o2-analysis-pid-tof-base", "o2-analysis-pid-tof", "o2-analysis-pid-tof-full", "o2-analysis-pid-tof-beta",
57 "o2-analysis-pid-tpc-full",
58 ]
59
60# init args manually
61initArgs = DQFilterPPTask()
62initArgs.mergeArgs()
63initArgs.parseArgs()
64
65args = initArgs.parseArgs()
66configuredCommands = vars(args) # for get args
67
68# Debug Settings
69debugSettings(args.debug, args.logFile, fileName = "filterPP.log")
70
71forgettedArgsChecker(configuredCommands)
72
73
76
77# add prefix for args.pid for pid selection
78if args.pid is not None:
79 prefix_pid = "pid-"
80 args.pid = [prefix_pid + sub for sub in args.pid]
81
82# add prefix for args.FT0 for tof-event-time
83if args.FT0 is not None:
84 prefix_process = "process"
85 args.FT0 = prefix_process + args.FT0
86
87
88
89# Load the configuration file provided as the first parameter
90config = {}
91with open(args.cfgFileName) as configFile:
92 config = json.load(configFile)
93
94jsonTypeChecker(args.cfgFileName)
95
96taskNameInConfig = "d-q-filter-p-p-task"
97taskNameInCommandLine = "o2-analysis-dq-filter-pp"
98
99mainTaskChecker(config, taskNameInConfig)
100
101
104
105logging.info("Only Select Configured as %s", args.onlySelect)
106if args.onlySelect == "true":
107 logging.info("INTERFACE MODE : JSON Overrider")
108if args.onlySelect == "false":
109 logging.info("INTERFACE MODE : JSON Additional")
110
111for key, value in config.items():
112 if isinstance(value, dict):
113 for value, value2 in value.items():
114
115 # aod
116 if value == "aod-file" and args.aod:
117 config[key][value] = args.aod
118 logging.debug(" - [%s] %s : %s", key, value, args.aod)
119
120 # DQ Selections for muons and barrel tracks
121 if value == "processSelection" and args.process:
122 for keyCfg, valueCfg in configuredCommands.items():
123 if valueCfg is not None: # Cleaning None types, because can"t iterate in None type
124 if keyCfg == "process": # Only Select key for analysis
125
126 if key == "d-q-barrel-track-selection":
127 if "barrelTrackSelection" in valueCfg:
128 config[key][value] = "true"
129 logging.debug(" - [%s] %s : true", key, value)
130 if ("barrelTrackSelection" not in valueCfg and args.onlySelect == "true"):
131 config[key][value] = "false"
132 logging.debug(" - [%s] %s : false", key, value)
133
134 if key == "d-q-muons-selection":
135 if "muonSelection" in valueCfg:
136 config[key][value] = "true"
137 logging.debug(" - [%s] %s : true", key, value)
138 if "muonSelection" not in valueCfg and args.onlySelect == "true":
139 config[key][value] = "false"
140 logging.debug(" - [%s] %s : false", key, value)
141
142 # DQ Selections event
143 if value == "processEventSelection" and args.process:
144 for keyCfg, valueCfg in configuredCommands.items():
145 if valueCfg is not None: # Cleaning None types, because can"t iterate in None type
146 if keyCfg == "process": # Only Select key for analysis
147
148 if key == "d-q-event-selection-task":
149 if "eventSelection" in valueCfg:
150 config[key][value] = "true"
151 logging.debug(" - [%s] %s : true", key, value)
152 if "eventSelection" not in valueCfg:
153 logging.warning(
154 "YOU MUST ALWAYS CONFIGURE eventSelection value in --process parameter!! It is Missing and this issue will fixed by CLI"
155 )
156 config[key][value] = "true"
157 logging.debug(" - [%s] %s : true", key, value)
158
159 # DQ Tiny Selection for barrel track
160 if value == "processSelectionTiny" and args.process:
161 for keyCfg, valueCfg in configuredCommands.items():
162 if valueCfg is not None: # Cleaning None types, because can"t iterate in None type
163 if keyCfg == "process": # Only Select key for analysis
164
165 if key == "d-q-barrel-track-selection":
166 if "barrelTrackSelectionTiny" in valueCfg:
167 config[key][value] = "true"
168 logging.debug(" - [%s] %s : true", key, value)
169 if ("barrelTrackSelectionTiny" not in valueCfg and args.onlySelect == "true"):
170 config[key][value] = "false"
171 logging.debug(" - [%s] %s : false", key, value)
172
173 # DQ Tiny Selection for filterPP
174 if value == "processFilterPPTiny" and args.process:
175 for keyCfg, valueCfg in configuredCommands.items():
176 if valueCfg is not None: # Cleaning None types, because can"t iterate in None type
177 if keyCfg == "process": # Only Select key for analysis
178
179 if key == "d-q-filter-p-p-task":
180 if "filterPPSelectionTiny" in valueCfg:
181 config[key][value] = "true"
182 config[key]["processFilterPP"] = "false"
183 logging.debug(" - [%s] %s : true", key, value)
184 logging.debug(" - [%s] processFilterPP : false", key)
185 if ("filterPPSelectionTiny" not in valueCfg and args.onlySelect == "true"):
186 config[key][value] = "false"
187 config[key]["processFilterPP"] = "true"
188 logging.debug(" - [%s] %s : false", key, value)
189 logging.debug(" - [%s] processFilterPP : true", key)
190
191 # Filter PP Selections
192 if value == "cfgBarrelSels" and args.cfgBarrelSels:
193 multiConfigurableSet(config, key, value, args.cfgBarrelSels, args.onlySelect)
194 logging.debug(" - [%s] %s : %s", key, value, args.cfgBarrelSels)
195 if value == "cfgMuonSels" and args.cfgMuonSels:
196 multiConfigurableSet(config, key, value, args.cfgMuonSels, args.onlySelect)
197 logging.debug(" - [%s] %s : %s", key, value, args.cfgMuonSels)
198
199 # DQ Cuts
200 if value == "cfgEventCuts" and args.cfgEventCuts:
201 multiConfigurableSet(config, key, value, args.cfgEventCuts, args.onlySelect)
202 logging.debug(" - [%s] %s : %s", key, value, args.cfgEventCuts)
203 if value == "cfgBarrelTrackCuts" and args.cfgBarrelTrackCuts:
204 multiConfigurableSet(config, key, value, args.cfgBarrelTrackCuts, args.onlySelect)
205 logging.debug(" - [%s] %s : %s", key, value, args.cfgBarrelTrackCuts)
206 if value == "cfgMuonsCuts" and args.cfgMuonsCuts:
207 multiConfigurableSet(config, key, value, args.cfgMuonsCuts, args.onlySelect)
208 logging.debug(" - [%s] %s : %s", key, value, args.cfgMuonsCuts)
209
210 # QA Options
211 if value == "cfgWithQA" and args.cfgWithQA:
212 config[key][value] = args.cfgWithQA
213 logging.debug(" - [%s] %s : %s", key, value, args.cfgWithQA)
214
215 # PID Selections
216 if (value in pidParameters) and args.pid and key != "tof-pid":
217 if value in args.pid:
218 value2 = "1"
219 config[key][value] = value2
220 logging.debug(" - [%s] %s : %s", key, value, value2)
221 elif args.onlySelect == "true":
222 value2 = "-1"
223 config[key][value] = value2
224 logging.debug(" - [%s] %s : %s", key, value, value2)
225
226 # event-selection
227 if value == "syst" and args.syst:
228 config[key][value] = args.syst
229 logging.debug(" - [%s] %s : %s", key, value, args.syst)
230 if value == "muonSelection" and args.muonSelection:
231 config[key][value] = args.muonSelection
232 logging.debug(" - [%s] %s : %s", key, value, args.muonSelection)
233 if value == "customDeltaBC" and args.customDeltaBC:
234 config[key][value] = args.customDeltaBC
235 logging.debug(" - [%s] %s : %s", key, value, args.customDeltaBC)
236
237 # multiplicity-table
238 if value == "doVertexZeq" and args.isVertexZeq:
239 if args.isVertexZeq == "true":
240 config[key][value] = "1"
241 config[key]["doDummyZeq"] = "0"
242 logging.debug(" - %s %s : 1", key, value)
243 logging.debug(" - [%s] doDummyZeq : 0", key)
244 if args.isVertexZeq == "false":
245 config[key][value] = "0"
246 config[key]["doDummyZeq"] = "1"
247 logging.debug(" - %s %s : 0", key, value)
248 logging.debug(" - [%s] doDummyZeq : 1", key)
249
250 # tof-pid, tof-pid-full
251 if value == "processWSlice" and args.isWSlice:
252 if args.isWSlice == "true":
253 config[key][value] = "true"
254 config[key]["processWoSlice"] = "false"
255 logging.debug(" - %s %s : true", key, value)
256 logging.debug(" - [%s] processWoSlice : false", key)
257 if args.isWSlice == "false":
258 config[key][value] = "false"
259 config[key]["processWoSlice"] = "true"
260 logging.debug(" - %s %s : false", key, value)
261 logging.debug(" - [%s] processWoSlice : true", key)
262
263 # tof-pid-beta
264 if value == "tof-expreso" and args.tof_expreso:
265 config[key][value] = args.tof_expreso
266 logging.debug(" - [%s] %s : %s", key, value, args.tof_expreso)
267
268 # tof-event-time
269 if (value in ft0Parameters) and args.FT0 and key == "tof-event-time":
270 if value == args.FT0:
271 value2 = "true"
272 config[key][value] = value2
273 logging.debug(" - [%s] %s : %s", key, value, value2)
274 elif value != args.FT0:
275 value2 = "false"
276 config[key][value] = value2
277 logging.debug(" - [%s] %s : %s", key, value, value2)
278
279 # track-selection
280 if args.itsMatching:
281 config[key][value] = args.itsMatching
282 logging.debug(" - [%s] %s : %s", key, value, args.itsMatching)
283
284 if value == "processDummy" and args.autoDummy:
285 if config["d-q-barrel-track-selection"]["processSelection"] == "true":
286 config["d-q-barrel-track-selection"]["processDummy"] = "false"
287 if config["d-q-barrel-track-selection"]["processSelection"] == "false":
288 config["d-q-barrel-track-selection"]["processDummy"] = "true"
289
290 if config["d-q-muons-selection"]["processSelection"] == "true":
291 config["d-q-muons-selection"]["processDummy"] = "false"
292 if config["d-q-muons-selection"]["processSelection"] == "false":
293 config["d-q-muons-selection"]["processDummy"] = "true"
294
295 if config["d-q-event-selection-task"]["processEventSelection"] == "true":
296 config["d-q-event-selection-task"]["processDummy"] = "false"
297 if config["d-q-event-selection-task"]["processEventSelection"] == "false":
298 config["d-q-event-selection-task"]["processDummy"] = "true"
299
300 if config["d-q-filter-p-p-task"]["processFilterPP"] == "true":
301 config["d-q-filter-p-p-task"]["processDummy"] = "false"
302 if config["d-q-filter-p-p-task"]["processFilterPP"] == "false":
303 config["d-q-filter-p-p-task"]["processDummy"] = "true"
304
305# Transactions
306filterSelsTranscation(args.cfgBarrelSels, args.cfgMuonSels, args.cfgBarrelTrackCuts, args.cfgMuonsCuts, configuredCommands)
307aodFileChecker(args.aod)
308# trackPropTransaction(args.add_track_prop, commonDeps)
309
310# Regarding to perfomance issues in argcomplete package, we should import later
311from extramodules.getTTrees import getTTrees
312
313# Converter Management
314if args.aod is not None:
315 ttreeList = getTTrees(args.aod)
316else:
317 ttreeList = config["internal-dpl-aod-reader"]["aod-file"]
318
319converterManager(ttreeList, commonDeps)
320trackPropChecker(commonDeps, commonDeps)
321
322
325
326# Write the updated configuration file into a temporary file
327updatedConfigFileName = "tempConfigFilterPP.json"
328
329with open(updatedConfigFileName, "w") as outputFile:
330 json.dump(config, outputFile, indent = 2)
331
332# Check which dependencies need to be run
333depsToRun = {}
334for dep in commonDeps:
335 depsToRun[dep] = 1
336
337commandToRun = (
338 taskNameInCommandLine + " --configuration json://" + updatedConfigFileName + " --severity error --shm-segment-size 12000000000 -b"
339 )
340for dep in depsToRun.keys():
341 commandToRun += " | " + dep + " --configuration json://" + updatedConfigFileName + " -b"
342 logging.debug("%s added your workflow", dep)
343
344if args.add_mc_conv:
345 logging.debug("o2-analysis-mc-converter added your workflow")
346 commandToRun += (" | o2-analysis-mc-converter --configuration json://" + updatedConfigFileName + " -b")
347
348if args.add_fdd_conv:
349 commandToRun += (" | o2-analysis-fdd-converter --configuration json://" + updatedConfigFileName + " -b")
350 logging.debug("o2-analysis-fdd-converter added your workflow")
351
352if args.add_track_prop:
353 commandToRun += (" | o2-analysis-track-propagation --configuration json://" + updatedConfigFileName + " -b")
354 logging.debug("o2-analysis-track-propagation added your workflow")
355
356print("====================================================================================================================")
357logging.info("Command to run:")
358logging.info(commandToRun)
359print("====================================================================================================================")
360
361# Listing Added Commands
362dispArgs(configuredCommands)
363
364os.system(commandToRun)
365
366runPycacheRemover()