26
26
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27
27
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
28
29
- import servicex
29
+ from servicex import deliver , query , dataset
30
30
import uproot
31
31
import numpy as np
32
32
import awkward as ak
@@ -78,35 +78,33 @@ def is_tree(obj):
78
78
return ak .Array ([json_str ])
79
79
80
80
81
- def build_deliver_spec (dataset ):
81
+ def build_deliver_spec (datasets ):
82
82
"""
83
83
Helper to build the servicex.deliver configuration.
84
84
Supports multiple inputs for multiple sample queries.
85
85
86
86
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.
88
88
If dict, custom names can be inputed
89
89
90
90
Returns:
91
91
spec_python (dict): The specification for the python function query containing Name, Query, Dataset, NFiles
92
92
"""
93
93
# 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 )
97
95
98
96
# Create a dict with sample name for ServiceX query & datasetID
99
97
dataset_dict = {}
100
- user_in = type (dataset )
98
+ user_in = type (datasets )
101
99
102
100
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 )):
106
104
name = "Sample" + str (i + 1 ) # write number for humans
107
- dataset_dict .update ({name : dataset [i ]})
105
+ dataset_dict .update ({name : datasets [i ]})
108
106
elif user_in == dict :
109
- dataset_dict = dataset
107
+ dataset_dict = datasets
110
108
else :
111
109
raise ValueError (
112
110
f"Unsupported dataset input type: { user_in } .\n Input must be dict ('sample_name':'dataset_id'), str or list of str"
@@ -116,7 +114,7 @@ def build_deliver_spec(dataset):
116
114
{
117
115
"NFiles" : 1 ,
118
116
"Name" : name ,
119
- "Dataset" : servicex . dataset .Rucio (did ),
117
+ "Dataset" : dataset .Rucio (did ),
120
118
"Query" : query_PythonFunction ,
121
119
}
122
120
for name , did in dataset_dict .items ()
@@ -257,20 +255,20 @@ def str_to_array(encoded_json_str):
257
255
return ak .Array (reconstructed_data ).type
258
256
259
257
260
- def get_structure (dataset , array_out = False , ** kwargs ):
258
+ def get_structure (datasets , array_out = False , ** kwargs ):
261
259
"""
262
260
Utility function.
263
261
Creates and sends the ServiceX request from user inputed datasets to retrieve file stucture.
264
262
Calls print_structure_from_str() to dump the structure in a user-friendly format
265
263
266
264
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.
268
266
A custom sample name per dataset can be given in a dict form: {'sample_name':'dataset_id'}
269
267
kwargs : Arguments to be propagated to print_structure_from_str
270
268
"""
271
- spec_python = build_deliver_spec (dataset )
269
+ spec_python = build_deliver_spec (datasets )
272
270
273
- output = servicex . deliver (spec_python )
271
+ output = deliver (spec_python )
274
272
275
273
if array_out == True :
276
274
all_arrays = {}
0 commit comments