From 50d6373ec9ebcb383ac63405e82c32821b652c44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADt=20Ku=C4=8Dera?= Date: Tue, 24 Oct 2023 12:00:38 +0200 Subject: [PATCH 1/4] Add scripts for derived-data handling --- exec/extract_df.py | 52 +++++++++++++++++++++++++++++++++++++++++++++ exec/get_parents.py | 21 ++++++++++++++++++ 2 files changed, 73 insertions(+) create mode 100644 exec/extract_df.py create mode 100644 exec/get_parents.py diff --git a/exec/extract_df.py b/exec/extract_df.py new file mode 100644 index 00000000..61075729 --- /dev/null +++ b/exec/extract_df.py @@ -0,0 +1,52 @@ +""" +Script to extract data frames from AO2D.root files with information about parent files +""" + +import sys +from ROOT import TFile, TObject + +# print(f"Name of the script : {sys.argv[0]=}") +# print(f"Arguments of the script : {sys.argv[1:]=}") + +# DF range +df_first = 0 +df_last = 0 + +for f in sys.argv[1:]: + df_i = 0 # DF counter + file_in = TFile.Open(f) + file_out = TFile.Open(f.replace(".root", "_edit.root"), "recreate") + for key in file_in.GetListOfKeys(): + key_name = key.GetName() + obj = file_in.Get(key_name) + if not obj: + continue + if key_name == "parentFiles": + print(f"Writing object {key_name}") + file_out.cd() + res = obj.Write(key_name, TObject.kSingleKey) + if not res: + print(f"Failed to write {key_name}") + # DF directory + elif obj.ClassName() == "TDirectoryFile": + if df_first <= df_i <= df_last: + print(f"Writing object {key_name}") + # Create the DF directory + dir_obj = file_out.mkdir(key_name) + if not dir_obj: + print(f"Failed to create dir {key_name}") + dir_obj.cd() + # Write trees in the DF directory + for key_sub in obj.GetListOfKeys(): + key_sub_name = key_sub.GetName() + obj_sub = obj.Get(key_sub_name) + if not obj_sub: + continue + print(f"Writing object {key_name}/{key_sub_name}") + if obj_sub.ClassName() == "TTree": + res = obj_sub.CloneTree().Write() + else: + res = obj_sub.Write() + if not res: + print(f"Failed to write {key_name}/{key_sub_name}") + df_i += 1 diff --git a/exec/get_parents.py b/exec/get_parents.py new file mode 100644 index 00000000..6407b7f5 --- /dev/null +++ b/exec/get_parents.py @@ -0,0 +1,21 @@ +import sys +from ROOT import TFile + +for f in sys.argv[1:]: + file = TFile.Open(f) + print(f) + list_parents = [] + map = file.Get("parentFiles") + # map.Print() + # Loop over data frames + for key in map: + # Get the parent file path + # print(map.GetValue(key)) + list_parents.append(str(map.GetValue(key))) + # Remove duplicities and sort + print(len(list_parents)) + list_parents = list(dict.fromkeys(list_parents)) + list_parents.sort() + # Print out list of parents + for p in list_parents: + print(p) From 79350a8c3e9ff57173fec664eed120853404d8be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADt=20Ku=C4=8Dera?= Date: Tue, 24 Oct 2023 13:47:27 +0200 Subject: [PATCH 2/4] Ignore ROOT import error --- exec/extract_df.py | 2 +- exec/get_parents.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/exec/extract_df.py b/exec/extract_df.py index 61075729..fae8dcb2 100644 --- a/exec/extract_df.py +++ b/exec/extract_df.py @@ -3,7 +3,7 @@ """ import sys -from ROOT import TFile, TObject +from ROOT import TFile, TObject # pylint: disable=import-error # print(f"Name of the script : {sys.argv[0]=}") # print(f"Arguments of the script : {sys.argv[1:]=}") diff --git a/exec/get_parents.py b/exec/get_parents.py index 6407b7f5..27d629f8 100644 --- a/exec/get_parents.py +++ b/exec/get_parents.py @@ -1,5 +1,5 @@ import sys -from ROOT import TFile +from ROOT import TFile # pylint: disable=import-error for f in sys.argv[1:]: file = TFile.Open(f) From 921236aeb62ca54a5a6d5a749719c95ce5c62384 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Tue, 24 Oct 2023 14:10:48 +0200 Subject: [PATCH 3/4] [MegaLinter] Apply linters automatic fixes (#12) Co-authored-by: vkucera --- exec/extract_df.py | 1 + exec/get_parents.py | 1 + 2 files changed, 2 insertions(+) diff --git a/exec/extract_df.py b/exec/extract_df.py index fae8dcb2..9d2d1757 100644 --- a/exec/extract_df.py +++ b/exec/extract_df.py @@ -3,6 +3,7 @@ """ import sys + from ROOT import TFile, TObject # pylint: disable=import-error # print(f"Name of the script : {sys.argv[0]=}") diff --git a/exec/get_parents.py b/exec/get_parents.py index 27d629f8..3c488a98 100644 --- a/exec/get_parents.py +++ b/exec/get_parents.py @@ -1,4 +1,5 @@ import sys + from ROOT import TFile # pylint: disable=import-error for f in sys.argv[1:]: From ac0a2a11bdaff7f6062373af21e731b1ff2c2a50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADt=20Ku=C4=8Dera?= <26327373+vkucera@users.noreply.github.com> Date: Thu, 12 Feb 2026 18:56:37 +0100 Subject: [PATCH 4/4] Fixes --- exec/extract_df.py | 12 ++++-------- exec/get_parents.py | 12 +++++++++--- 2 files changed, 13 insertions(+), 11 deletions(-) mode change 100644 => 100755 exec/extract_df.py mode change 100644 => 100755 exec/get_parents.py diff --git a/exec/extract_df.py b/exec/extract_df.py old mode 100644 new mode 100755 index 9d2d1757..5b16b4d0 --- a/exec/extract_df.py +++ b/exec/extract_df.py @@ -1,14 +1,13 @@ +#!/usr/bin/env python3 + """ -Script to extract data frames from AO2D.root files with information about parent files +Extract data frames from AO2D.root files with information about parent files. """ import sys from ROOT import TFile, TObject # pylint: disable=import-error -# print(f"Name of the script : {sys.argv[0]=}") -# print(f"Arguments of the script : {sys.argv[1:]=}") - # DF range df_first = 0 df_last = 0 @@ -44,10 +43,7 @@ if not obj_sub: continue print(f"Writing object {key_name}/{key_sub_name}") - if obj_sub.ClassName() == "TTree": - res = obj_sub.CloneTree().Write() - else: - res = obj_sub.Write() + res = obj_sub.CloneTree().Write() if obj_sub.ClassName() == "TTree" else obj_sub.Write() if not res: print(f"Failed to write {key_name}/{key_sub_name}") df_i += 1 diff --git a/exec/get_parents.py b/exec/get_parents.py old mode 100644 new mode 100755 index 3c488a98..043194b6 --- a/exec/get_parents.py +++ b/exec/get_parents.py @@ -1,3 +1,9 @@ +#!/usr/bin/env python3 + +""" +Get paths to parent files from derived AO2D.root files. +""" + import sys from ROOT import TFile # pylint: disable=import-error @@ -6,13 +12,13 @@ file = TFile.Open(f) print(f) list_parents = [] - map = file.Get("parentFiles") + obj_map = file.Get("parentFiles") # map.Print() # Loop over data frames - for key in map: + for key in obj_map: # Get the parent file path # print(map.GetValue(key)) - list_parents.append(str(map.GetValue(key))) + list_parents.append(str(obj_map.GetValue(key))) # Remove duplicities and sort print(len(list_parents)) list_parents = list(dict.fromkeys(list_parents))