Skip to content

Commit 61c7114

Browse files
committed
simplify serivex import
1 parent a827352 commit 61c7114

File tree

1 file changed

+15
-17
lines changed

1 file changed

+15
-17
lines changed

servicex_analysis_utils/file_peeking.py

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2727
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2828

29-
import servicex
29+
from servicex import deliver, query, dataset
3030
import uproot
3131
import numpy as np
3232
import awkward as ak
@@ -78,35 +78,33 @@ def is_tree(obj):
7878
return ak.Array([json_str])
7979

8080

81-
def build_deliver_spec(dataset):
81+
def build_deliver_spec(datasets):
8282
"""
8383
Helper to build the servicex.deliver configuration.
8484
Supports multiple inputs for multiple sample queries.
8585
8686
Parameters:
87-
dataset (str, [str], or dict): Rucio DIDs to be checked by the servicex workers.
87+
datasets (str, [str], or dict): Rucio DIDs to be checked by the servicex workers.
8888
If dict, custom names can be inputed
8989
9090
Returns:
9191
spec_python (dict): The specification for the python function query containing Name, Query, Dataset, NFiles
9292
"""
9393
# Servicex query using the PythonFunction backend
94-
query_PythonFunction = servicex.query.PythonFunction().with_uproot_function(
95-
run_query
96-
)
94+
query_PythonFunction = query.PythonFunction().with_uproot_function(run_query)
9795

9896
# Create a dict with sample name for ServiceX query & datasetID
9997
dataset_dict = {}
100-
user_in = type(dataset)
98+
user_in = type(datasets)
10199

102100
if user_in == str:
103-
dataset_dict.update({"Sample": dataset})
104-
elif user_in == list and type(dataset[0]) is str:
105-
for i in range(len(dataset)):
101+
dataset_dict.update({"Sample": datasets})
102+
elif user_in == list and type(datasets[0]) is str:
103+
for i in range(len(datasets)):
106104
name = "Sample" + str(i + 1) # write number for humans
107-
dataset_dict.update({name: dataset[i]})
105+
dataset_dict.update({name: datasets[i]})
108106
elif user_in == dict:
109-
dataset_dict = dataset
107+
dataset_dict = datasets
110108
else:
111109
raise ValueError(
112110
f"Unsupported dataset input type: {user_in}.\nInput must be dict ('sample_name':'dataset_id'), str or list of str"
@@ -116,7 +114,7 @@ def build_deliver_spec(dataset):
116114
{
117115
"NFiles": 1,
118116
"Name": name,
119-
"Dataset": servicex.dataset.Rucio(did),
117+
"Dataset": dataset.Rucio(did),
120118
"Query": query_PythonFunction,
121119
}
122120
for name, did in dataset_dict.items()
@@ -257,20 +255,20 @@ def str_to_array(encoded_json_str):
257255
return ak.Array(reconstructed_data).type
258256

259257

260-
def get_structure(dataset, array_out=False, **kwargs):
258+
def get_structure(datasets, array_out=False, **kwargs):
261259
"""
262260
Utility function.
263261
Creates and sends the ServiceX request from user inputed datasets to retrieve file stucture.
264262
Calls print_structure_from_str() to dump the structure in a user-friendly format
265263
266264
Parameters:
267-
dataset (dict,str,[str]): The datasets from which to print the file structures.
265+
datasets (dict,str,[str]): The datasets from which to print the file structures.
268266
A custom sample name per dataset can be given in a dict form: {'sample_name':'dataset_id'}
269267
kwargs : Arguments to be propagated to print_structure_from_str
270268
"""
271-
spec_python = build_deliver_spec(dataset)
269+
spec_python = build_deliver_spec(datasets)
272270

273-
output = servicex.deliver(spec_python)
271+
output = deliver(spec_python)
274272

275273
if array_out == True:
276274
all_arrays = {}

0 commit comments

Comments
 (0)