O2-DQ User Interface 1.0.0
Loading...
Searching...
No Matches
runTableMakerMC.py
Go to the documentation of this file.
1#!/usr/bin/env python
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/TableProducer/tableMakerMC.cxx
20
21import json
22import logging
23import logging.config
24import os
25from extramodules.converterManager import converterManager
26
27from extramodules.debugSettings import debugSettings
28from extramodules.monitoring import dispArgs
29from extramodules.descriptor import inputDescriptors, outputDescriptors
30from extramodules.dqTranscations import aodFileChecker, centTranscation, forgettedArgsChecker, jsonTypeChecker, mainTaskChecker, trackPropChecker, trackPropTransaction
31from extramodules.configSetter import multiConfigurableSet
32from extramodules.pycacheRemover import runPycacheRemover
33
34from dqtasks.tableMakerMC import TableMakerMC
35
36
39
40centralityTableParameters = [
41 "estRun2V0M", "estRun2SPDtks", "estRun2SPDcls", "estRun2CL0", "estRun2CL1", "estFV0A", "estFT0M", "estFDDM", "estNTPV",
42 ]
43# TODO: Add genname parameter
44
45ft0Parameters = ["processFT0", "processNoFT0", "processOnlyFT0", "processRun2"]
46
47pidParameters = ["pid-el", "pid-mu", "pid-pi", "pid-ka", "pid-pr", "pid-de", "pid-tr", "pid-he", "pid-al",]
48
49booleanSelections = ["true", "false"]
50
51ttreeList = []
52
53# Predefined Search Lists
54centSearch = []
55
56
59
60commonDeps = ["o2-analysis-timestamp", "o2-analysis-event-selection", "o2-analysis-multiplicity-table",]
61barrelDeps = [
62 "o2-analysis-trackselection", "o2-analysis-trackextension", "o2-analysis-pid-tof-base", "o2-analysis-pid-tof",
63 "o2-analysis-pid-tof-full", "o2-analysis-pid-tof-beta", "o2-analysis-pid-tpc-full",
64 ]
65specificDeps = {
66 "processFull": [],
67 "processFullTiny": [],
68 "processFullWithCov": [],
69 "processFullWithCent": ["o2-analysis-centrality-table"],
70 "processBarrelOnly": [],
71 "processBarrelOnlyWithCov": [],
72 "processBarrelOnlyWithV0Bits": ["o2-analysis-dq-v0-selector", "o2-analysis-weak-decay-indices",],
73 "processBarrelOnlyWithEventFilter": ["o2-analysis-dq-filter-pp"],
74 "processBarrelOnlyWithQvector": ["o2-analysis-centrality-table", "o2-analysis-dq-flow",],
75 "processBarrelOnlyWithCent": ["o2-analysis-centrality-table"],
76 "processMuonOnly": [],
77 "processMuonOnlyWithCov": [],
78 "processMuonOnlyWithCent": ["o2-analysis-centrality-table"],
79 "processMuonOnlyWithQvector": ["o2-analysis-centrality-table", "o2-analysis-dq-flow",],
80 "processMuonOnlyWithFilter": ["o2-analysis-dq-filter-pp"]
81 # "processFullWithCentWithV0Bits": ["o2-analysis-centrality-table","o2-analysis-dq-v0-selector", "o2-analysis-weak-decay-indices"],
82 # "processFullWithEventFilterWithV0Bits": ["o2-analysis-dq-filter-pp","o2-analysis-dq-v0-selector", "o2-analysis-weak-decay-indices"],
83 }
84
85
88
89# Definition of all the tables we may write
90tables = {
91 "ReducedEvents": {
92 "table": "AOD/REDUCEDEVENT/0",
93 "treename": "ReducedEvents"
94 },
95 "ReducedEventsExtended": {
96 "table": "AOD/REEXTENDED/0",
97 "treename": "ReducedEventsExtended",
98 },
99 "ReducedEventsVtxCov": {
100 "table": "AOD/REVTXCOV/0",
101 "treename": "ReducedEventsVtxCov",
102 },
103 "ReducedEventsQvector": {
104 "table": "AOD/REQVECTOR/0",
105 "treename": "ReducedEventsQvector",
106 },
107 "ReducedMCEventLabels": {
108 "table": "AOD/REMCCOLLBL/0",
109 "treename": "ReducedMCEventLabels",
110 },
111 "ReducedMCEvents": {
112 "table": "AOD/REMC/0",
113 "treename": "ReducedMCEvents"
114 },
115 "ReducedTracks": {
116 "table": "AOD/REDUCEDTRACK/0",
117 "treename": "ReducedTracks"
118 },
119 "ReducedTracksBarrel": {
120 "table": "AOD/RTBARREL/0",
121 "treename": "ReducedTracksBarrel",
122 },
123 "ReducedTracksBarrelCov": {
124 "table": "AOD/RTBARRELCOV/0",
125 "treename": "ReducedTracksBarrelCov",
126 },
127 "ReducedTracksBarrelPID": {
128 "table": "AOD/RTBARRELPID/0",
129 "treename": "ReducedTracksBarrelPID",
130 },
131 "ReducedTracksBarrelLabels": {
132 "table": "AOD/RTBARRELLABELS/0",
133 "treename": "ReducedTracksBarrelLabels",
134 },
135 "ReducedMCTracks": {
136 "table": "AOD/RTMC/0",
137 "treename": "ReducedMCTracks"
138 },
139 "ReducedMuons": {
140 "table": "AOD/RTMUON/0",
141 "treename": "ReducedMuons"
142 },
143 "ReducedMuonsExtra": {
144 "table": "AOD/RTMUONEXTRA/0",
145 "treename": "ReducedMuonsExtra",
146 },
147 "ReducedMuonsCov": {
148 "table": "AOD/RTMUONCOV/0",
149 "treename": "ReducedMuonsCov"
150 },
151 "ReducedMuonsLabels": {
152 "table": "AOD/RTMUONSLABELS/0",
153 "treename": "ReducedMuonsLabels",
154 },
155 }
156# Tables to be written, per process function
157commonTables = ["ReducedEvents", "ReducedEventsExtended", "ReducedEventsVtxCov"]
158barrelCommonTables = ["ReducedTracks", "ReducedTracksBarrel", "ReducedTracksBarrelPID"]
159muonCommonTables = ["ReducedMuons", "ReducedMuonsExtra"]
160specificTables = {
161 "processFull": [],
162 "processFullTiny": [],
163 "processFullWithCov": ["ReducedTracksBarrelCov", "ReducedMuonsCov"],
164 "processFullWithCent": [],
165 "processBarrelOnly": [],
166 "processBarrelOnlyWithCov": ["ReducedTracksBarrelCov"],
167 "processBarrelOnlyWithV0Bits": [],
168 "processBarrelOnlyWithQvector": ["ReducedEventsQvector"],
169 "processBarrelOnlyWithEventFilter": [],
170 "processBarrelOnlyWithCent": [],
171 "processMuonOnly": [],
172 "processMuonOnlyWithCov": ["ReducedMuonsCov"],
173 "processMuonOnlyWithCent": [],
174 "processMuonOnlyWithQvector": ["ReducedEventsQvector"],
175 "processMuonOnlyWithFilter": [],
176 }
177
178
181
182# init args manually
183initArgs = TableMakerMC()
184initArgs.mergeArgs()
185initArgs.parseArgs()
186
187args = initArgs.parseArgs()
188configuredCommands = vars(args) # for get args
189
190# Debug Settings
191debugSettings(args.debug, args.logFile, fileName = "tableMakerMC.log")
192
193# Transcation management
194forgettedArgsChecker(configuredCommands)
195
196
199
200# add prefix for args.process for table-maker/table-maker-m-c and d-q-filter-p-p
201if args.process is not None:
202 prefix_process = "process"
203 args.process = [prefix_process + sub for sub in args.process]
204
205# add prefix for args.pid for pid selection
206if args.pid is not None:
207 prefix_pid = "pid-"
208 args.pid = [prefix_pid + sub for sub in args.pid]
209
210# add prefix for args.est for centrality-table
211if args.est is not None:
212 prefix_est = "est"
213 args.est = [prefix_est + sub for sub in args.est]
214
215# add prefix for args.FT0 for tof-event-time
216if args.FT0 is not None:
217 prefix_process = "process"
218 args.FT0 = prefix_process + args.FT0
219
220
221
222# Load the configuration file provided as the first parameter
223config = {}
224with open(args.cfgFileName) as configFile:
225 config = json.load(configFile)
226
227jsonTypeChecker(args.cfgFileName)
228
229runOverMC = True
230logging.info("runOverMC : %s, Reduced Tables will be produced for MC", runOverMC)
231
232taskNameInConfig = "table-maker-m-c"
233taskNameInCommandLine = "o2-analysis-dq-table-maker-mc"
234
235mainTaskChecker(config, taskNameInConfig)
236
237
240
241logging.info("Only Select Configured as %s", args.onlySelect)
242if args.onlySelect == "true":
243 logging.info("INTERFACE MODE : JSON Overrider")
244if args.onlySelect == "false":
245 logging.info("INTERFACE MODE : JSON Additional")
246
247# For adding a process function from TableMaker and all process should be added only once so set type used
248tableMakerProcessSearch = set()
249
250for key, value in config.items():
251 if isinstance(value, dict):
252 for value, value2 in value.items():
253
254 # aod
255 if value == "aod-file" and args.aod:
256 config[key][value] = args.aod
257 logging.debug(" - [%s] %s : %s", key, value, args.aod)
258
259 # table-maker/table-maker-m-c process selections
260 if (value in specificDeps.keys()) and args.process:
261 if value in args.process:
262
263 # processOnlyBCs have to always be true
264 if "processOnlyBCs" not in args.process:
265 args.process.append("processOnlyBCs")
266 logging.warning("You forget to add OnlyBCs value in --process parameter! It will automaticaly added.")
267 value2 = "true"
268 config[key][value] = value2
269 logging.debug(" - [%s] %s : %s", key, value, value2)
270
271 for s in config[key].keys():
272 if s in specificDeps.keys():
273 tableMakerProcessSearch.add(s)
274
275 centSearch = [s for s in args.process if "Cent" in s]
276
277 elif args.onlySelect == "true":
278 if value == "processOnlyBCs":
279 config[key][value] = "true"
280 logging.debug(" - [%s] %s : true", key, value)
281 else:
282 value2 = "false"
283 config[key][value] = value2
284 logging.debug(" - [%s] %s : %s", key, value, value2)
285
286 # PID Selections
287 if (value in pidParameters) and args.pid and key != "tof-pid":
288 if value in args.pid:
289 value2 = "1"
290 config[key][value] = value2
291 logging.debug(" - [%s] %s : %s", key, value, value2)
292 elif args.onlySelect == "true":
293 value2 = "-1"
294 config[key][value] = value2
295 logging.debug(" - [%s] %s : %s", key, value, value2)
296
297 # centrality-table
298 if (value in centralityTableParameters) and args.est:
299 if value in args.est:
300 value2 = "1"
301 config[key][value] = value2
302 logging.debug(" - [%s] %s : %s", key, value, value2)
303 elif args.onlySelect == "true":
304 value2 = "-1"
305 config[key][value] = value2
306 logging.debug(" - [%s] %s : %s", key, value, value2)
307
308 # table-maker/table-maker-m-c cfg selections
309 if value == "cfgEventCuts" and args.cfgEventCuts:
310 multiConfigurableSet(config, key, value, args.cfgEventCuts, args.onlySelect)
311 logging.debug(" - [%s] %s : %s", key, value, args.cfgEventCuts)
312 if value == "cfgBarrelTrackCuts" and args.cfgBarrelTrackCuts:
313 multiConfigurableSet(config, key, value, args.cfgBarrelTrackCuts, args.onlySelect)
314 logging.debug(" - [%s] %s : %s", key, value, args.cfgBarrelTrackCuts)
315 if value == "cfgMuonCuts" and args.cfgMuonCuts:
316 multiConfigurableSet(config, key, value, args.cfgMuonCuts, args.onlySelect)
317 logging.debug(" - [%s] %s : %s", key, value, args.cfgMuonCuts)
318 if value == "cfgBarrelLowPt" and args.cfgBarrelLowPt:
319 config[key][value] = args.cfgBarrelLowPt
320 logging.debug(" - [%s] %s : %s", key, value, args.cfgBarrelLowPt)
321 if value == "cfgMuonLowPt" and args.cfgMuonLowPt:
322 config[key][value] = args.cfgMuonLowPt
323 logging.debug(" - [%s] %s : %s", key, value, args.cfgMuonLowPt)
324 if value == "cfgNoQA" and args.cfgNoQA:
325 config[key][value] = args.cfgNoQA
326 logging.debug(" - [%s] %s : %s", key, value, args.cfgNoQA)
327 if value == "cfgDetailedQA" and args.cfgDetailedQA:
328 config[key][value] = args.cfgDetailedQA
329 logging.debug(" - [%s] %s : %s", key, value, args.cfgDetailedQA)
330 if value == "cfgMinTpcSignal" and args.cfgMinTpcSignal:
331 config[key][value] = args.cfgMinTpcSignal
332 logging.debug(" - [%s] %s : %s", key, value, args.cfgMinTpcSignal)
333 if value == "cfgMaxTpcSignal" and args.cfgMaxTpcSignal:
334 config[key][value] = args.cfgMaxTpcSignal
335 logging.debug(" - [%s] %s : %s", key, value, args.cfgMaxTpcSignal)
336 if value == "cfgMCsignals" and args.cfgMCsignals:
337 multiConfigurableSet(config, key, value, args.cfgMCsignals, args.onlySelect)
338 logging.debug(" - [%s] %s : %s", key, value, args.cfgMCsignals)
339
340 # event-selection-task
341 if value == "syst" and args.syst:
342 config[key][value] = args.syst
343 logging.debug(" - [%s] %s : %s", key, value, args.syst)
344 if value == "muonSelection" and args.muonSelection:
345 config[key][value] = args.muonSelection
346 logging.debug(" - [%s] %s : %s", key, value, args.muonSelection)
347 if value == "customDeltaBC" and args.customDeltaBC:
348 config[key][value] = args.customDeltaBC
349 logging.debug(" - [%s] %s : %s", key, value, args.customDeltaBC)
350
351 # multiplicity-table
352 if value == "doVertexZeq" and args.isVertexZeq:
353 if args.isVertexZeq == "true":
354 config[key][value] = "1"
355 config[key]["doDummyZeq"] = "0"
356 logging.debug(" - %s %s : 1", key, value)
357 logging.debug(" - [%s] doDummyZeq : 0", key)
358 if args.isVertexZeq == "false":
359 config[key][value] = "0"
360 config[key]["doDummyZeq"] = "1"
361 logging.debug(" - %s %s : 0", key, value)
362 logging.debug(" - [%s] doDummyZeq : 1", key)
363
364 # tof-pid, tof-pid-full
365 if value == "processWSlice" and args.isWSlice:
366 if args.isWSlice == "true":
367 config[key][value] = "true"
368 config[key]["processWoSlice"] = "false"
369 logging.debug(" - %s %s : true", key, value)
370 logging.debug(" - [%s] processWoSlice : false", key)
371 if args.isWSlice == "false":
372 config[key][value] = "false"
373 config[key]["processWoSlice"] = "true"
374 logging.debug(" - %s %s : false", key, value)
375 logging.debug(" - [%s] processWoSlice : true", key)
376
377 # tof-pid-beta
378 if value == "tof-expreso" and args.tof_expreso:
379 config[key][value] = args.tof_expreso
380 logging.debug(" - [%s] %s : %s", key, value, args.tof_expreso)
381
382 # tof-event-time
383 if (value in ft0Parameters) and args.FT0 and key == "tof-event-time":
384 if value == args.FT0:
385 value2 = "true"
386 config[key][value] = value2
387 logging.debug(" - [%s] %s : %s", key, value, value2)
388 elif value != args.FT0:
389 value2 = "false"
390 config[key][value] = value2
391 logging.debug(" - [%s] %s : %s", key, value, value2)
392
393 # track-propagation
394 if args.isCovariance:
395 if (value == "processStandard" or value == "processCovariance") and args.isCovariance == "false":
396 config[key]["processStandard"] = "true"
397 config[key]["processCovariance"] = "false"
398 logging.debug(" - [%s] processStandart : true", key)
399 logging.debug(" - [%s] processCovariance : false", key)
400 if (value == "processStandard" or value == "processCovariance") and args.isCovariance == "true":
401 config[key]["processStandard"] = "false"
402 config[key]["processCovariance"] = "true"
403 logging.debug(" - [%s] processStandart : false", key)
404 logging.debug(" - [%s] processCovariance : true", key)
405
406 # track-selection
407 if args.itsMatching:
408 config[key][value] = args.itsMatching
409 logging.debug(" - [%s] %s : %s", key, value, args.itsMatching)
410
411# Transactions
412centTranscation(config, args.process, args.syst, centSearch)
413aodFileChecker(args.aod)
414# trackPropTransaction(args.add_track_prop, barrelDeps)
415
416# Regarding to perfomance issues in argcomplete package, we should import later
417from extramodules.getTTrees import getTTrees
418
419# Converter Management
420if args.aod is not None:
421 ttreeList = getTTrees(args.aod)
422else:
423 ttreeList = config["internal-dpl-aod-reader"]["aod-file"]
424
425converterManager(ttreeList, commonDeps)
426trackPropChecker(commonDeps, barrelDeps)
427
428
431
432# Write the updated configuration file into a temporary file
433updatedConfigFileName = "tempConfigTableMakerMC.json"
434
435with open(updatedConfigFileName, "w") as outputFile:
436 json.dump(config, outputFile, indent = 2)
437
438# Check which dependencies need to be run
439depsToRun = {}
440for dep in commonDeps:
441 depsToRun[dep] = 1
442
443for processFunc in specificDeps.keys():
444 if processFunc not in config[taskNameInConfig].keys():
445 continue
446 if config[taskNameInConfig][processFunc] == "true":
447 if "processFull" in processFunc or "processBarrel" in processFunc:
448 for dep in barrelDeps:
449 depsToRun[dep] = 1
450 for dep in specificDeps[processFunc]:
451 depsToRun[dep] = 1
452
453# Check which tables are required in the output
454tablesToProduce = {}
455for table in commonTables:
456 tablesToProduce[table] = 1
457
458if runOverMC:
459 tablesToProduce["ReducedMCEvents"] = 1
460 tablesToProduce["ReducedMCEventLabels"] = 1
461
462for processFunc in specificDeps.keys():
463 if processFunc not in config[taskNameInConfig].keys():
464 continue
465 if config[taskNameInConfig][processFunc] == "true":
466 logging.info("processFunc ========")
467 logging.info("%s", processFunc)
468 if "processFull" in processFunc or "processBarrel" in processFunc:
469 logging.info("common barrel tables==========")
470 for table in barrelCommonTables:
471 logging.info("%s", table)
472 tablesToProduce[table] = 1
473 if runOverMC:
474 tablesToProduce["ReducedTracksBarrelLabels"] = 1
475 if "processFull" in processFunc or "processMuon" in processFunc:
476 logging.info("common muon tables==========")
477 for table in muonCommonTables:
478 logging.info("%s", table)
479 tablesToProduce[table] = 1
480 if runOverMC:
481 tablesToProduce["ReducedMuonsLabels"] = 1
482 if runOverMC:
483 tablesToProduce["ReducedMCTracks"] = 1
484 logging.info("specific tables==========")
485 for table in specificTables[processFunc]:
486 logging.info("%s", table)
487 tablesToProduce[table] = 1
488
489readerConfigFileName = "aodReaderTempConfig.json"
490writerConfigFileName = "aodWriterTempConfig.json"
491
492# Generate the aod-writer output descriptor json file
493outputDescriptors(tablesToProduce, tables)
494inputDescriptors(tablesToProduce, tables)
495
496commandToRun = (
497 taskNameInCommandLine + " --configuration json://" + updatedConfigFileName +
498 " --severity error --shm-segment-size 12000000000 --aod-writer-json " + writerConfigFileName + " -b"
499 )
500if args.aod_memory_rate_limit:
501 commandToRun = (
502 taskNameInCommandLine + " --configuration json://" + updatedConfigFileName +
503 " --severity error --shm-segment-size 12000000000 --aod-memory-rate-limit " + args.aod_memory_rate_limit + " --aod-writer-json " +
504 writerConfigFileName + " -b"
505 )
506
507for dep in depsToRun.keys():
508 commandToRun += " | " + dep + " --configuration json://" + updatedConfigFileName + " -b"
509 logging.debug("%s added your workflow", dep)
510"""
511if args.add_mc_conv:
512 logging.debug("o2-analysis-mc-converter added your workflow")
513 commandToRun += (" | o2-analysis-mc-converter --configuration json://" + updatedConfigFileName + " -b")
514
515if args.add_fdd_conv:
516 commandToRun += (" | o2-analysis-fdd-converter --configuration json://" + updatedConfigFileName + " -b")
517 logging.debug("o2-analysis-fdd-converter added your workflow")
518
519if args.add_track_prop:
520 commandToRun += (" | o2-analysis-track-propagation --configuration json://" + updatedConfigFileName + " -b")
521 logging.debug("o2-analysis-track-propagation added your workflow")
522"""
523
524print("====================================================================================================================")
525logging.info("Command to run:")
526logging.info(commandToRun)
527print("====================================================================================================================")
528logging.info("Tables to produce:")
529logging.info(tablesToProduce.keys())
530print("====================================================================================================================")
531# sys.exit()
532
533# Listing Added Commands
534dispArgs(configuredCommands)
535
536os.system(commandToRun)
537
538runPycacheRemover()