O2-DQ User Interface 1.0.0
Loading...
Searching...
No Matches
runDQEfficiency.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/dqEfficiency.cxx
20
21import json
22import sys
23import logging
24import logging.config
25import os
26from extramodules.configGetter import configGetter
27from extramodules.debugSettings import debugSettings
28
29from extramodules.monitoring import dispArgs
30from extramodules.dqTranscations import aodFileChecker, forgettedArgsChecker, jsonTypeChecker, mainTaskChecker
31from extramodules.configSetter import multiConfigurableSet, processDummySet
32from extramodules.pycacheRemover import runPycacheRemover
33
34from dqtasks.dqEfficiency import DQEfficiency
35
36
39
40booleanSelections = ["true", "false"]
41
42isAnalysisEventSelected = True
43isAnalysisTrackSelected = True
44isAnalysisMuonSelected = True
45isAnalysisSameEventPairingSelected = True
46
47# init args manually
48initArgs = DQEfficiency()
49initArgs.mergeArgs()
50initArgs.parseArgs()
51
52args = initArgs.parseArgs()
53configuredCommands = vars(args) # for get args
54
55# Debug Settings
56debugSettings(args.debug, args.logFile, fileName = "dqEfficiency.log")
57
58# Transcation management
59forgettedArgsChecker(configuredCommands)
60
61# Get Some cfg values provided from --param
62analysisCfg = configGetter(configuredCommands, "analysis")
63processCfg = configGetter(configuredCommands, "process")
64
65# Load the configuration file provided as the first parameter
66config = {}
67with open(args.cfgFileName) as configFile:
68 config = json.load(configFile)
69
70jsonTypeChecker(args.cfgFileName)
71
72taskNameInCommandLine = "o2-analysis-dq-efficiency"
73taskNameInConfig = "analysis-event-selection"
74
75mainTaskChecker(config, taskNameInConfig)
76
77
80
81logging.info("Only Select Configured as %s", args.onlySelect)
82if args.onlySelect == "true":
83 logging.info("INTERFACE MODE : JSON Overrider")
84if args.onlySelect == "false":
85 logging.info("INTERFACE MODE : JSON Additional")
86
87for key, value in config.items():
88 if type(value) == type(config):
89 for value, value2 in value.items():
90
91 # aod
92 if value == "aod-file" and args.aod:
93 config[key][value] = args.aod
94 logging.debug(" - [%s] %s : %s", key, value, args.aod)
95 # reader
96 if value == "aod-reader-json" and args.reader:
97 config[key][value] = args.reader
98 logging.debug(" - [%s] %s : %s", key, value, args.reader)
99
100 # analysis-skimmed-selections
101 if value == "processSkimmed" and args.analysis:
102
103 if key == "analysis-event-selection":
104 if "eventSelection" in analysisCfg:
105 config[key][value] = "true"
106 logging.debug(" - [%s] %s : true", key, value)
107 isAnalysisEventSelected = True
108 if "eventSelection" not in analysisCfg:
109 logging.warning(
110 "YOU MUST ALWAYS CONFIGURE eventSelection value in --analysis parameter!! It is Missing and this issue will fixed by CLI"
111 )
112 config[key][value] = "true"
113 logging.debug(" - [%s] %s : true", key, value)
114
115 if key == "analysis-track-selection":
116 if "trackSelection" in analysisCfg:
117 config[key][value] = "true"
118 logging.debug(" - [%s] %s : true", key, value)
119 isAnalysisTrackSelected = True
120 if "trackSelection" not in analysisCfg and args.onlySelect == "true":
121 config[key][value] = "false"
122 logging.debug(" - [%s] %s : false", key, value)
123
124 if key == "analysis-muon-selection":
125 if "muonSelection" in analysisCfg:
126 config[key][value] = "true"
127 logging.debug(" - [%s] %s : true", key, value)
128 isAnalysisMuonSelected = True
129 if "muonSelection" not in analysisCfg and args.onlySelect == "true":
130 config[key][value] = "false"
131 logging.debug(" - [%s] %s : false", key, value)
132
133 if "sameEventPairing" in analysisCfg:
134 isAnalysisSameEventPairingSelected = True
135 if "sameEventPairing" not in analysisCfg:
136 isAnalysisSameEventPairingSelected = False
137
138 if value == "processDimuonMuonSkimmed" and args.analysis:
139
140 if key == "analysis-dilepton-track":
141 if "dileptonTrackDimuonMuonSelection" in analysisCfg:
142 config[key][value] = "true"
143 logging.debug(" - [%s] %s : true", key, value)
144 if ("dileptonTrackDimuonMuonSelection" not in analysisCfg and args.onlySelect == "true"):
145 config[key][value] = "false"
146 logging.debug(" - [%s] %s : false", key, value)
147
148 if value == "processDielectronKaonSkimmed" and args.analysis:
149
150 if key == "analysis-dilepton-track":
151 if "dileptonTrackDielectronKaonSelection" in analysisCfg:
152 config[key][value] = "true"
153 logging.debug(" - [%s] %s : true", key, value)
154 if ("dileptonTrackDielectronKaonSelection" not in analysisCfg and args.onlySelect == "true"):
155 config[key][value] = "false"
156 logging.debug(" - [%s] %s : false", key, value)
157
158 # QA selections
159 if value == "cfgQA" and args.cfgQA:
160 config[key][value] = args.cfgQA
161 logging.debug(" - [%s] %s : %s", key, value, args.cfgQA)
162
163 # analysis-event-selection
164 if value == "cfgEventCuts" and args.cfgEventCuts:
165 multiConfigurableSet(config, key, value, args.cfgEventCuts, args.onlySelect)
166 logging.debug(" - [%s] %s : %s", key, value, args.cfgEventCuts)
167
168 # analysis-track-selection
169 if value == "cfgTrackCuts" and args.cfgTrackCuts:
170 multiConfigurableSet(config, key, value, args.cfgTrackCuts, args.onlySelect)
171 logging.debug(" - [%s] %s : %s", key, value, args.cfgTrackCuts)
172 if value == "cfgTrackMCSignals" and args.cfgTrackMCSignals:
173 multiConfigurableSet(config, key, value, args.cfgTrackMCSignals, args.onlySelect)
174 logging.debug(" - [%s] %s : %s", key, value, args.cfgTrackMCSignals)
175
176 # analysis-muon-selection
177 if value == "cfgMuonCuts" and args.cfgMuonCuts:
178 multiConfigurableSet(config, key, value, args.cfgMuonCuts, args.onlySelect)
179 logging.debug(" - [%s] %s : %s", key, value, args.cfgMuonCuts)
180 if value == "cfgMuonMCSignals" and args.cfgMuonMCSignals:
181 multiConfigurableSet(config, key, value, args.cfgMuonMCSignals, args.onlySelect)
182 logging.debug(" - [%s] %s : %s", key, value, args.cfgMuonMCSignals)
183
184 # analysis-same-event-pairing
185 if key == "analysis-same-event-pairing" and args.process:
186
187 if not isAnalysisSameEventPairingSelected:
188 logging.warning("You forget to add sameEventPairing option to analysis for Workflow. It Automatically added by CLI.")
189 isAnalysisSameEventPairingSelected = True
190
191 if "JpsiToEE" in processCfg and value == "processJpsiToEESkimmed":
192 if isAnalysisTrackSelected:
193 config[key]["processJpsiToEESkimmed"] = "true"
194 logging.debug(" - [%s] %s : true", key, value)
195 if not isAnalysisTrackSelected:
196 logging.error("trackSelection not found in analysis for processJpsiToEESkimmed -> analysis-same-event-pairing")
197 sys.exit()
198 if ("JpsiToEE" not in processCfg and value == "processJpsiToEESkimmed" and args.onlySelect == "true"):
199 config[key]["processJpsiToEESkimmed"] = "false"
200 logging.debug(" - [%s] %s : false", key, value)
201
202 if "JpsiToMuMu" in processCfg and value == "processJpsiToMuMuSkimmed":
203 if isAnalysisMuonSelected:
204 config[key]["processJpsiToMuMuSkimmed"] = "true"
205 logging.debug(" - [%s] %s : true", key, value)
206 if not isAnalysisMuonSelected:
207 logging.error("muonSelection not found in analysis for processJpsiToMuMuSkimmed -> analysis-same-event-pairing")
208 sys.exit()
209 if ("JpsiToMuMu" not in processCfg and value == "processJpsiToMuMuSkimmed" and args.onlySelect == "true"):
210 config[key]["processJpsiToMuMuSkimmed"] = "false"
211 logging.debug(" - [%s] %s : false", key, value)
212
213 if ("JpsiToMuMuVertexing" in processCfg and value == "processJpsiToMuMuVertexingSkimmed"):
214 if isAnalysisMuonSelected:
215 config[key]["processJpsiToMuMuVertexingSkimmed"] = "true"
216 logging.debug(" - [%s] %s : true", key, value)
217 if not isAnalysisMuonSelected:
218 logging.error(
219 "muonSelection not found in analysis for processJpsiToMuMuVertexingSkimmed -> analysis-same-event-pairing"
220 )
221 sys.exit()
222 if ("JpsiToMuMuVertexing" not in processCfg and value == "processJpsiToMuMuVertexingSkimmed" and args.onlySelect == "true"):
223 config[key]["processJpsiToMuMuVertexingSkimmed"] = "false"
224 logging.debug(" - [%s] %s : false", key, value)
225
226 # If no process function is provided, all SEP process functions are pulled false (for JSON Overrider mode)
227 if (
228 key == "analysis-same-event-pairing" and args.process is None and not isAnalysisSameEventPairingSelected and
229 args.onlySelect == "true"
230 ):
231 config[key]["processJpsiToEESkimmed"] = "false"
232 config[key]["processJpsiToMuMuSkimmed"] = "false"
233 config[key]["processJpsiToMuMuVertexingSkimmed"] = "false"
234
235 # analysis-same-event-pairing
236 if key == "analysis-same-event-pairing":
237 if value == "cfgBarrelMCRecSignals" and args.cfgBarrelMCRecSignals:
238 multiConfigurableSet(config, key, value, args.cfgBarrelMCRecSignals, args.onlySelect)
239 logging.debug(" - [%s] %s : %s", key, value, args.cfgBarrelMCRecSignals)
240
241 if value == "cfgBarrelMCGenSignals" and args.cfgBarrelMCGenSignals:
242 multiConfigurableSet(config, key, value, args.cfgBarrelMCGenSignals, args.onlySelect)
243 logging.debug(" - [%s] %s : %s", key, value, args.cfgBarrelMCGenSignals)
244
245 if value == "cfgFlatTables" and args.cfgFlatTables:
246 config[key][value] = args.cfgFlatTables
247 logging.debug(" - [%s] %s : %s", key, value, args.cfgFlatTables)
248
249 # analysis-dilepton-track
250 if key == "analysis-dilepton-track":
251 if value == "cfgBarrelMCRecSignals" and args.cfgBarrelDileptonMCRecSignals:
252 multiConfigurableSet(config, key, value, args.cfgBarrelDileptonMCRecSignals, args.onlySelect)
253 logging.debug(" - [%s] %s : %s", key, value, args.cfgBarrelDileptonMCRecSignals)
254
255 if value == "cfgBarrelMCGenSignals" and args.cfgBarrelDileptonMCGenSignals:
256 multiConfigurableSet(config, key, value, args.cfgBarrelDileptonMCGenSignals, args.onlySelect)
257 logging.debug(" - [%s] %s : %s", key, value, args.cfgBarrelDileptonMCGenSignals)
258 if value == "cfgLeptonCuts" and args.cfgLeptonCuts:
259 multiConfigurableSet(config, key, value, args.cfgLeptonCuts, args.onlySelect)
260 logging.debug(" - [%s] %s : %s", key, value, args.cfgLeptonCuts)
261
262 if value == "cfgFillCandidateTable" and args.cfgFillCandidateTable:
263 config[key][value] = args.cfgFillCandidateTable
264 logging.debug(" - [%s] %s : %s", key, value, args.cfgFillCandidateTable)
265
266processDummySet(config) # dummy automizer
267aodFileChecker(args.aod)
268
269if args.reader is not None:
270 if not os.path.isfile(args.reader):
271 logging.error("%s File not found in path!!!", args.reader)
272 sys.exit()
273elif not os.path.isfile((config["internal-dpl-aod-reader"]["aod-reader-json"])):
274 logging.error(" %s File not found in path!!!", config["internal-dpl-aod-reader"]["aod-reader-json"])
275 sys.exit()
276
277
280
281# Write the updated configuration file into a temporary file
282updatedConfigFileName = "tempConfigDQEfficiency.json"
283
284with open(updatedConfigFileName, "w") as outputFile:
285 json.dump(config, outputFile, indent = 2)
286
287commandToRun = (taskNameInCommandLine + " --configuration json://" + updatedConfigFileName + " -b" + " --aod-writer-json " + args.writer)
288if args.writer == "false":
289 commandToRun = (taskNameInCommandLine + " --configuration json://" + updatedConfigFileName + " -b")
290
291print("====================================================================================================================")
292logging.info("Command to run:")
293logging.info(commandToRun)
294print("====================================================================================================================")
295
296# Listing Added Commands
297dispArgs(configuredCommands)
298
299os.system(commandToRun)
300
301runPycacheRemover()