@@ -33,9 +33,9 @@ def run_query(input_filenames=None):
33
33
import uproot
34
34
import awkward as ak
35
35
"""
36
- Helper. Open a file and return one array containing a single string that describes the DataSet root file structure.
37
36
Sent to ServiceX python transformers.
38
-
37
+ Open a file and return one array containing a single string that describes the DataSet root file structure.
38
+
39
39
The string will be formatted like:
40
40
"Tree: TreeName1; TBranch: Branchname1 ; dtype: BranchType1, TBranch: Branchname2 ; dtype: BranchType2, ...
41
41
Tree: TreeName2; TBranch: Branchname1 ; dtype: BranchType1, ..."
@@ -92,11 +92,12 @@ def print_structure_from_str(deliver_dict, filter_branch="", save_to_txt=False,
92
92
93
93
Parameters:
94
94
deliver_dict (dict): ServiceX deliver output (keys: sample names, values: file paths or URLs).
95
- filter_branch (str): If provided, only branches containing this string are included.
95
+ filter_branch (str): If provided, only branches containing this string are included in the output .
96
96
save_to_txt (bool): If True, saves output to a text file instead of returning it.
97
+ do_print (bool): If True, dumps the ouput to the terminal and returns None. Not called if save_to_txt is True
97
98
98
99
Returns:
99
- str: The formatted file structure.
100
+ result_str ( str) : The formatted file structure.
100
101
"""
101
102
output_lines = []
102
103
output_lines .append (f"\n File structure of all samples with branch filter '{ filter_branch } ':" )
@@ -139,13 +140,24 @@ def print_structure_from_str(deliver_dict, filter_branch="", save_to_txt=False,
139
140
with open ("samples_structure.txt" , "w" ) as f :
140
141
f .write (result_str )
141
142
return "File structure saved to 'samples_structure.txt'."
142
- if do_print :
143
+ elif do_print :
143
144
print (result_str )
144
145
return
145
146
else :
146
147
return result_str
147
148
148
149
def build_deliver_spec (dataset ):
150
+ """
151
+ Helper to build the servicex.deliver dict configuration.
152
+ Supports multiple inputs for multiple sample queries.
153
+
154
+ Parameters:
155
+ dataset (str, [str], or dict): Rucio DIDs to be checked by the servicex workers.
156
+ If dict, custom names can be inputed
157
+
158
+ Returns:
159
+ spec_python (dict): The specification for the python function query containing Name, Query, Dataset, NFiles
160
+ """
149
161
#Servicex query using the PythonFunction backend
150
162
query_PythonFunction = servicex .query .PythonFunction ().with_uproot_function (run_query )
151
163
@@ -175,14 +187,13 @@ def build_deliver_spec(dataset):
175
187
]
176
188
spec_python = {"Sample" : sample_list }
177
189
178
- return spec_python
179
-
190
+ return spec_python
180
191
181
192
def get_structure (dataset , ** kwargs , raw = False ):
182
193
"""
183
194
Utility function.
184
195
Creates and sends the ServiceX request from user inputed datasets to retrieve file stucture.
185
- Calls print_structure_from_str()
196
+ Calls print_structure_from_str() to get the structure in a user-friendly format
186
197
187
198
Parameters:
188
199
dataset (dict,str,[str]): The datasets from which to print the file structures.
@@ -193,7 +204,4 @@ def get_structure(dataset, **kwargs, raw=False):
193
204
194
205
output = servicex .deliver (spec_python )
195
206
196
- if raw :
197
- return array_from_str (output )
198
-
199
207
return print_structure_from_str (output , ** kwargs )
0 commit comments