O2-DQ User Interface 1.0.0
Loading...
Searching...
No Matches
runDQFlow.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/dqFlow.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, mainTaskChecker, trackPropChecker, trackPropTransaction
30from extramodules.configSetter import multiConfigurableSet
31from extramodules.pycacheRemover import runPycacheRemover
32
33from dqtasks.dqFlow import AnalysisQvector
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
48booleanSelections = ["true", "false"]
49
50ttreeList = []
51
52
55
56commonDeps = [
57 "o2-analysis-timestamp", "o2-analysis-event-selection", "o2-analysis-multiplicity-table", "o2-analysis-centrality-table",
58 "o2-analysis-trackselection", "o2-analysis-trackextension", "o2-analysis-pid-tof-base", "o2-analysis-pid-tof-full",
59 "o2-analysis-pid-tof-beta", "o2-analysis-pid-tpc-full",
60 ]
61
62# init args manually
63initArgs = AnalysisQvector()
64initArgs.mergeArgs()
65initArgs.parseArgs()
66
67args = initArgs.parseArgs()
68configuredCommands = vars(args) # for get args
69
70# Debug Settings
71debugSettings(args.debug, args.logFile, fileName = "dqFlow.log")
72
73forgettedArgsChecker(configuredCommands)
74
75
78
79# add prefix for args.pid for pid selection
80if args.pid is not None:
81 prefix_pid = "pid-"
82 args.pid = [prefix_pid + sub for sub in args.pid]
83
84# add prefix for args.est for centrality table
85if args.est is not None:
86 prefix_est = "est"
87 args.est = [prefix_est + sub for sub in args.est]
88
89# add prefix for args.FT0 for tof-event-time
90if args.FT0 is not None:
91 prefix_process = "process"
92 args.FT0 = prefix_process + args.FT0
93
94
95
96# Load the configuration file provided as the first parameter
97config = {}
98with open(args.cfgFileName) as configFile:
99 config = json.load(configFile)
100
101jsonTypeChecker(args.cfgFileName)
102
103taskNameInConfig = "analysis-qvector"
104taskNameInCommandLine = "o2-analysis-dq-flow"
105
106mainTaskChecker(config, taskNameInConfig)
107
108
111
112logging.info("Only Select Configured as %s", args.onlySelect)
113if args.onlySelect == "true":
114 logging.info("INTERFACE MODE : JSON Overrider")
115if args.onlySelect == "false":
116 logging.info("INTERFACE MODE : JSON Additional")
117
118for key, value in config.items():
119 if type(value) == type(config):
120 for value, value2 in value.items():
121
122 # aod
123 if value == "aod-file" and args.aod:
124 config[key][value] = args.aod
125 logging.debug(" - [%s] %s : %s", key, value, args.aod)
126
127 # analysis-qvector selections
128 if value == "cfgBarrelTrackCuts" and args.cfgBarrelTrackCuts:
129 multiConfigurableSet(config, key, value, args.cfgBarrelTrackCuts, args.onlySelect)
130 logging.debug(" - [%s] %s : %s", key, value, args.cfgBarrelTrackCuts)
131 if value == "cfgMuonCuts" and args.cfgMuonCuts:
132 multiConfigurableSet(config, key, value, args.cfgMuonCuts, args.onlySelect)
133 logging.debug(" - [%s] %s : %s", key, value, args.cfgMuonCuts)
134 if value == "cfgEventCuts" and args.cfgEventCuts:
135 multiConfigurableSet(config, key, value, args.cfgEventCuts, args.onlySelect)
136 logging.debug(" - [%s] %s : %s", key, value, args.cfgEventCuts)
137 if value == "cfgWithQA" and args.cfgWithQA:
138 config[key][value] = args.cfgWithQA
139 logging.debug(" - [%s] %s : %s", key, value, args.cfgWithQA)
140 if value == "cfgCutPtMin" and args.cfgCutPtMin:
141 config[key][value] = args.cfgCutPtMin
142 logging.debug(" - [%s] %s : %s", key, value, args.cfgCutPtMin)
143 if value == "cfgCutPtMax" and args.cfgCutPtMax:
144 config[key][value] = args.cfgCutPtMax
145 logging.debug(" - [%s] %s : %s", key, value, args.cfgCutPtMax)
146 if value == "cfgCutEta" and args.cfgCutEta:
147 config[key][value] = args.cfgCutEta
148 logging.debug(" - [%s] %s : %s", key, value, args.cfgCutEta)
149 if value == "cfgEtaLimit" and args.cfgEtaLimit:
150 config[key][value] = args.cfgEtaLimit
151 logging.debug(" - [%s] %s : %s", key, value, args.cfgEtaLimit)
152 if value == "cfgNPow" and args.cfgNPow:
153 config[key][value] = args.cfgNPow
154 logging.debug(" - [%s] %s : %s", key, value, args.cfgNPow)
155 if value == "cfgEfficiency" and args.cfgEfficiency:
156 config[key][value] = args.cfgEfficiency
157 logging.debug(" - [%s] %s : %s", key, value, args.cfgEfficiency)
158 if value == "cfgAcceptance" and args.cfgAcceptance:
159 config[key][value] = args.cfgAcceptance
160 logging.debug(" - [%s] %s : %s", key, value, args.cfgAcceptance)
161
162 # PID Selections
163 if (value in pidParameters) and args.pid and key != "tof-pid":
164 if value in args.pid:
165 value2 = "1"
166 config[key][value] = value2
167 logging.debug(" - [%s] %s : %s", key, value, value2)
168 elif args.onlySelect == "true":
169 value2 = "-1"
170 config[key][value] = value2
171 logging.debug(" - [%s] %s : %s", key, value, value2)
172
173 # centrality table
174 if (value in centralityTableParameters) and args.est:
175 if value in args.est:
176 value2 = "1"
177 config[key][value] = value2
178 logging.debug(" - [%s] %s : %s", key, value, value2)
179 elif args.onlySelect == "true":
180 value2 = "-1"
181 config[key][value] = value2
182 logging.debug(" - [%s] %s : %s", key, value, value2)
183
184 # event-selection-task
185 if value == "syst" and args.syst:
186 config[key][value] = args.syst
187 logging.debug(" - [%s] %s : %s", key, value, args.syst)
188 if value == "muonSelection" and args.muonSelection:
189 config[key][value] = args.muonSelection
190 logging.debug(" - [%s] %s : %s", key, value, args.muonSelection)
191 if value == "customDeltaBC" and args.customDeltaBC:
192 config[key][value] = args.customDeltaBC
193 logging.debug(" - [%s] %s : %s", key, value, args.customDeltaBC)
194
195 # multiplicity-table
196 if value == "doVertexZeq" and args.isVertexZeq:
197 if args.isVertexZeq == "true":
198 config[key][value] = "1"
199 config[key]["doDummyZeq"] = "0"
200 logging.debug(" - %s %s : 1", key, value)
201 logging.debug(" - [%s] doDummyZeq : 0", key)
202 if args.isVertexZeq == "false":
203 config[key][value] = "0"
204 config[key]["doDummyZeq"] = "1"
205 logging.debug(" - %s %s : 0", key, value)
206 logging.debug(" - [%s] doDummyZeq : 1", key)
207
208 # tof-pid, tof-pid-full
209 if value == "processWSlice" and args.isWSlice:
210 if args.isWSlice == "true":
211 config[key][value] = "true"
212 config[key]["processWoSlice"] = "false"
213 logging.debug(" - %s %s : true", key, value)
214 logging.debug(" - [%s] processWoSlice : false", key)
215 if args.isWSlice == "false":
216 config[key][value] = "false"
217 config[key]["processWoSlice"] = "true"
218 logging.debug(" - %s %s : false", key, value)
219 logging.debug(" - [%s] processWoSlice : true", key)
220
221 # tof-pid-beta
222 if value == "tof-expreso" and args.tof_expreso:
223 config[key][value] = args.tof_expreso
224 logging.debug(" - [%s] %s : %s", key, value, args.tof_expreso)
225
226 # tof-event-time
227 if (value in ft0Parameters) and args.FT0 and key == "tof-event-time":
228 if value == args.FT0:
229 value2 = "true"
230 config[key][value] = value2
231 logging.debug(" - [%s] %s : %s", key, value, value2)
232 elif value != args.FT0:
233 value2 = "false"
234 config[key][value] = value2
235 logging.debug(" - [%s] %s : %s", key, value, value2)
236
237 # track-selection
238 if args.itsMatching:
239 config[key][value] = args.itsMatching
240 logging.debug(" - [%s] %s : %s", key, value, args.itsMatching)
241
242aodFileChecker(args.aod)
243# trackPropTransaction(args.add_track_prop, commonDeps)
244
245# Regarding to perfomance issues in argcomplete package, we should import later
246from extramodules.getTTrees import getTTrees
247
248# Converter Management
249if args.aod is not None:
250 ttreeList = getTTrees(args.aod)
251else:
252 ttreeList = config["internal-dpl-aod-reader"]["aod-file"]
253
254converterManager(ttreeList, commonDeps)
255trackPropChecker(commonDeps, commonDeps)
256
257
260
261# Write the updated configuration file into a temporary file
262updatedConfigFileName = "tempConfigDQFlow.json"
263with open(updatedConfigFileName, "w") as outputFile:
264 json.dump(config, outputFile, indent = 2)
265
266# Check which dependencies need to be run
267depsToRun = {}
268for dep in commonDeps:
269 depsToRun[dep] = 1
270
271commandToRun = (
272 taskNameInCommandLine + " --configuration json://" + updatedConfigFileName + " --severity error --shm-segment-size 12000000000 -b"
273 )
274for dep in depsToRun.keys():
275 commandToRun += " | " + dep + " --configuration json://" + updatedConfigFileName + " -b"
276 logging.debug("%s added your workflow", dep)
277"""
278if args.add_mc_conv:
279 logging.debug("o2-analysis-mc-converter added your workflow")
280 commandToRun += (" | o2-analysis-mc-converter --configuration json://" + updatedConfigFileName + " -b")
281
282if args.add_fdd_conv:
283 commandToRun += (" | o2-analysis-fdd-converter --configuration json://" + updatedConfigFileName + " -b")
284 logging.debug("o2-analysis-fdd-converter added your workflow")
285
286if args.add_track_prop:
287 commandToRun += (" | o2-analysis-track-propagation --configuration json://" + updatedConfigFileName + " -b")
288 logging.debug("o2-analysis-track-propagation added your workflow")
289"""
290
291print("====================================================================================================================")
292logging.info("Command to run:")
293logging.info(commandToRun)
294print("====================================================================================================================")
295
296# Listing Added Commands
297dispArgs(configuredCommands)
298
299os.system(commandToRun)
300
301runPycacheRemover()