Skip to content

Commit fe6c414

Browse files
committed
Split get_structure into more helpers
1 parent 04bed65 commit fe6c414

File tree

1 file changed

+20
-17
lines changed

1 file changed

+20
-17
lines changed

servicex_analysis_utils/file_peeking.py

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -142,35 +142,24 @@ def print_structure_from_str(deliver_dict, filter_branch="", save_to_txt=False,
142142
else:
143143
return result_str
144144

145-
146-
def get_structure(dataset, **kwargs):
147-
"""
148-
Utility function.
149-
Creates and sends the ServiceX request from user inputed datasets to retrieve file stucture.
150-
Calls print_structure_from_str()
151-
152-
Parameters:
153-
dataset_dict (dict,str,[str]): The datasets from which to print the file structures.
154-
A custom sample name per dataset can be given in a dict form: {'sample_name':'dataset_id'}
155-
kwargs : Arguments to be propagated to print_structure_from_str
156-
"""
145+
def build_deliver_spec(dataset):
157146
#Servicex query using the PythonFunction backend
158147
query_PythonFunction = servicex.query.PythonFunction().with_uproot_function(run_query)
159148

160149
#Create a dict with sample name for ServiceX query & datasetID
161150
dataset_dict={}
162151
user_in=type(dataset)
152+
163153
if user_in == str:
164154
dataset_dict.update({"Sample":dataset})
165155
elif user_in == list and type(dataset[0]) is str:
166156
for i in range(len(dataset)):
167-
name="Sample"+str(i+1) #write for humans
157+
name="Sample"+str(i+1) #write number for humans
168158
dataset_dict.update({name:dataset[i]})
169159
elif user_in == dict:
170160
dataset_dict=dataset
171161
else:
172162
raise ValueError(f"Unsupported dataset input type: {user_in}.\nInput must be dict ('sample_name':'dataset_id'), str or list of str")
173-
return 0
174163

175164
sample_list = [
176165
{
@@ -181,10 +170,24 @@ def get_structure(dataset, **kwargs):
181170
}
182171
for name, did in dataset_dict.items()
183172
]
184-
185173
spec_python = {"Sample": sample_list}
186174

175+
return spec_python
176+
177+
178+
def get_structure(dataset, **kwargs):
179+
"""
180+
Utility function.
181+
Creates and sends the ServiceX request from user inputed datasets to retrieve file stucture.
182+
Calls print_structure_from_str()
183+
184+
Parameters:
185+
dataset (dict,str,[str]): The datasets from which to print the file structures.
186+
A custom sample name per dataset can be given in a dict form: {'sample_name':'dataset_id'}
187+
kwargs : Arguments to be propagated to print_structure_from_str
188+
"""
189+
spec_python=build_deliver_spec(dataset)
190+
187191
output=servicex.deliver(spec_python)
188192

189-
return print_structure_from_str(output, **kwargs)
190-
193+
return print_structure_from_str(output, **kwargs)

0 commit comments

Comments
 (0)