From 49b6ded015deafacdc51968d8dc2a6338f459833 Mon Sep 17 00:00:00 2001 From: Gordon Watts Date: Fri, 13 Sep 2024 22:51:43 -0700 Subject: [PATCH 1/9] First go at a very simple xAOD example --- examples/func_adl_xAOD_simple.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 examples/func_adl_xAOD_simple.py diff --git a/examples/func_adl_xAOD_simple.py b/examples/func_adl_xAOD_simple.py new file mode 100644 index 00000000..fba9a180 --- /dev/null +++ b/examples/func_adl_xAOD_simple.py @@ -0,0 +1,25 @@ +from servicex import query as q, deliver + + +def func_adl_xaod_simple(): + query = q.FuncADL_ATLASr22() # type: ignore + jets_per_event = query.Select(lambda e: e.Jets()) + jet_info_per_event = jets_per_event.Select( + lambda e: e.Select(lambda j: {'pt': j.pt(), 'eta': j.eta()}) + ) + + spec = { + 'Sample': [{ + 'Name': "func_adl_xAOD_simple", + 'RucioDID': "user.mtost:user.mtost.singletop.p6026.Jun13", + 'Query': jet_info_per_event + }] + } + files = deliver(spec, servicex_name="servicex-uc-af") + assert files is not None, "No files returned from deliver! Internal error" + return files + + +if __name__ == "__main__": + files = func_adl_xaod_simple() + assert len(files['func_adl_xAOD_simple']) == 1 From 532be02f03ad5a2024b11aae075423fabe231295 Mon Sep 17 00:00:00 2001 From: Gordon Watts Date: Sat, 14 Sep 2024 22:19:49 -0700 Subject: [PATCH 2/9] Fix up to use a opendata file for the example. --- examples/func_adl_xAOD_simple.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/examples/func_adl_xAOD_simple.py b/examples/func_adl_xAOD_simple.py index fba9a180..894bb05d 100644 --- a/examples/func_adl_xAOD_simple.py +++ b/examples/func_adl_xAOD_simple.py @@ -1,4 +1,5 @@ -from servicex import query as q, deliver +import logging +from servicex import query as q, deliver, dataset def func_adl_xaod_simple(): @@ -11,7 +12,11 @@ def func_adl_xaod_simple(): spec = { 'Sample': [{ 'Name': "func_adl_xAOD_simple", - 'RucioDID': "user.mtost:user.mtost.singletop.p6026.Jun13", + 'Dataset': dataset.FileList( + [ + "root://eospublic.cern.ch//eos/opendata/atlas/rucio/mc20_13TeV/DAOD_PHYSLITE.37622528._000013.pool.root.1", # noqa: E501 + ] + ), 'Query': jet_info_per_event }] } @@ -21,5 +26,7 @@ def func_adl_xaod_simple(): if __name__ == "__main__": + logging.basicConfig(level=logging.DEBUG) + logging.info("Hi there") files = func_adl_xaod_simple() - assert len(files['func_adl_xAOD_simple']) == 1 + # assert len(files['func_adl_xAOD_simple']) == 1 From c543b899173d7991f562990fe915bdaf975fd66b Mon Sep 17 00:00:00 2001 From: Gordon Watts Date: Sat, 14 Sep 2024 22:21:29 -0700 Subject: [PATCH 3/9] Remove logging --- examples/func_adl_xAOD_simple.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/examples/func_adl_xAOD_simple.py b/examples/func_adl_xAOD_simple.py index 894bb05d..6794ec67 100644 --- a/examples/func_adl_xAOD_simple.py +++ b/examples/func_adl_xAOD_simple.py @@ -26,7 +26,5 @@ def func_adl_xaod_simple(): if __name__ == "__main__": - logging.basicConfig(level=logging.DEBUG) - logging.info("Hi there") files = func_adl_xaod_simple() - # assert len(files['func_adl_xAOD_simple']) == 1 + assert len(files['func_adl_xAOD_simple']) == 1 From fcd01c73a83ee6a3747f7404d37b9c2d6a3a22b0 Mon Sep 17 00:00:00 2001 From: Gordon Watts Date: Sat, 14 Sep 2024 22:45:52 -0700 Subject: [PATCH 4/9] Working example for simple func_adl --- examples/func_adl_xAOD_simple.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/examples/func_adl_xAOD_simple.py b/examples/func_adl_xAOD_simple.py index 6794ec67..353f19f7 100644 --- a/examples/func_adl_xAOD_simple.py +++ b/examples/func_adl_xAOD_simple.py @@ -1,12 +1,14 @@ -import logging from servicex import query as q, deliver, dataset def func_adl_xaod_simple(): query = q.FuncADL_ATLASr22() # type: ignore - jets_per_event = query.Select(lambda e: e.Jets()) + jets_per_event = query.Select(lambda e: e.Jets('AnalysisJets')) jet_info_per_event = jets_per_event.Select( - lambda e: e.Select(lambda j: {'pt': j.pt(), 'eta': j.eta()}) + lambda jets: { + 'pt': jets.Select(lambda j: j.pt()), + 'eta': jets.Select(lambda j: j.eta()) + } ) spec = { From 695f29d4c7d6dd7f9c48e5baaf9f11d497a2c599 Mon Sep 17 00:00:00 2001 From: Gordon Watts Date: Mon, 16 Sep 2024 23:50:10 -0700 Subject: [PATCH 5/9] Minor updates to spelling corrections --- .vscode/settings.json | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.vscode/settings.json b/.vscode/settings.json index 7892e616..1d9c4d7e 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -55,7 +55,9 @@ "nqueries", "ntuples", "numpy", + "opendata", "pathlib", + "PHYSLITE", "pnfs", "posix", "Powheg", From 455ac43b67636f0ecd6276192d60e181a4a23d0d Mon Sep 17 00:00:00 2001 From: Gordon Watts Date: Tue, 17 Sep 2024 00:11:38 -0700 Subject: [PATCH 6/9] Add a typed example --- .vscode/settings.json | 1 + examples/func_adl_xAOD_typed.py | 35 +++++++++++++++++++++++++++++++++ pyproject.toml | 1 + 3 files changed, 37 insertions(+) create mode 100644 examples/func_adl_xAOD_typed.py diff --git a/.vscode/settings.json b/.vscode/settings.json index 1d9c4d7e..2c83d14e 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -96,6 +96,7 @@ "unittests", "URL's", "xaod", + "xaodr", "xrootd" ], "python.analysis.typeCheckingMode": "basic", diff --git a/examples/func_adl_xAOD_typed.py b/examples/func_adl_xAOD_typed.py new file mode 100644 index 00000000..ad149059 --- /dev/null +++ b/examples/func_adl_xAOD_typed.py @@ -0,0 +1,35 @@ +from servicex import deliver, dataset +from func_adl_servicex_xaodr22 import FuncADLQueryPHYSLITE, cpp_float + + +def func_adl_xaod_simple(): + query = FuncADLQueryPHYSLITE() # type: ignore + jets_per_event = query.Select(lambda e: e.Jets('AnalysisJets')) + jet_info_per_event = jets_per_event.Select( + lambda jets: { + 'pt': jets.Select(lambda j: j.pt()), + 'eta': jets.Select(lambda j: j.eta()), + 'emf': jets.Select(lambda j: j.getAttribute[cpp_float]('EMFrac')) # type: ignore + } + ) + + spec = { + 'Sample': [{ + 'Name': "func_adl_xAOD_simple", + 'Dataset': dataset.FileList( + [ + "root://eospublic.cern.ch//eos/opendata/atlas/rucio/mc20_13TeV/DAOD_PHYSLITE.37622528._000013.pool.root.1", # noqa: E501 + ] + ), + 'Query': jet_info_per_event, + 'Codegen': 'atlasr22', + }] + } + files = deliver(spec, servicex_name="servicex-uc-af") + assert files is not None, "No files returned from deliver! Internal error" + return files + + +if __name__ == "__main__": + files = func_adl_xaod_simple() + assert len(files['func_adl_xAOD_simple']) == 1 diff --git a/pyproject.toml b/pyproject.toml index 11b22d37..c9bb94b7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -84,6 +84,7 @@ docs = [ "furo>=2023.5.20", "sphinx-code-include>=1.4.0", "myst-parser>=3.0.1", + "func-adl-servicex-xaodr22", ] develop = [ "servicex[test,docs]", From 0445bf2d9094ea4478db646cf2902d1de2301cea Mon Sep 17 00:00:00 2001 From: Gordon Watts Date: Tue, 17 Sep 2024 20:55:44 -0700 Subject: [PATCH 7/9] Fix up the naming of the typed call --- examples/func_adl_xAOD_typed.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/func_adl_xAOD_typed.py b/examples/func_adl_xAOD_typed.py index ad149059..c8588c9e 100644 --- a/examples/func_adl_xAOD_typed.py +++ b/examples/func_adl_xAOD_typed.py @@ -2,7 +2,7 @@ from func_adl_servicex_xaodr22 import FuncADLQueryPHYSLITE, cpp_float -def func_adl_xaod_simple(): +def func_adl_xaod_typed(): query = FuncADLQueryPHYSLITE() # type: ignore jets_per_event = query.Select(lambda e: e.Jets('AnalysisJets')) jet_info_per_event = jets_per_event.Select( @@ -31,5 +31,5 @@ def func_adl_xaod_simple(): if __name__ == "__main__": - files = func_adl_xaod_simple() + files = func_adl_xaod_typed() assert len(files['func_adl_xAOD_simple']) == 1 From 36e022af81cf3fad02887d343881c715a7181702 Mon Sep 17 00:00:00 2001 From: Gordon Watts Date: Tue, 17 Sep 2024 20:55:53 -0700 Subject: [PATCH 8/9] Add the examles to `examples1.rst` --- docs/examples1.rst | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/docs/examples1.rst b/docs/examples1.rst index 09d695e8..973924aa 100644 --- a/docs/examples1.rst +++ b/docs/examples1.rst @@ -46,6 +46,35 @@ parquet files print(sx2) + +func_adl Example reading xAOD from ATLAS PHYSLITE on OpenData +--------------------------------------------- + +This example loads the $p_T$ and $\eta$ for jets from an xAOD PHYSLITE file found in the ATLAS OpenData release. + +.. .. code-include :: :func:`examples.func_adl_xAOD_simple.func_adl_xaod_simple` + + + +.. .. automethod:: func_adl_xaod_simple +.. .. literalinclude:: ../examples/func_adl_xAOD_simple.py + + +func_adl Example reading xAOD using a Typed Dataset. +--------------------------------------------- + +This example loads the $p_T$ and $\eta$ for jets from an xAOD PHYSLITE file found in the ATLAS OpenData release. +It uses the full type information, allowing one to access everything that could be translated in the xAOD. + +.. .. code-include :: :func:`examples.func_adl_xAOD_typed.func_adl_xaod_typed` + + + +.. .. automethod:: func_adl_xaod_typed +.. .. literalinclude:: ../examples/func_adl_xAOD_typed.py + + + Python Code Generator --------------------- This example is using the python code generator. For this we don't use func_adl, From 802caaa602d436d5ee6346ebce5dfaaa2947a1fa Mon Sep 17 00:00:00 2001 From: Gordon Watts Date: Tue, 17 Sep 2024 21:06:08 -0700 Subject: [PATCH 9/9] Fix up example to properly reference everything! --- docs/examples.rst | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/docs/examples.rst b/docs/examples.rst index 92b031c7..64f8fe7b 100644 --- a/docs/examples.rst +++ b/docs/examples.rst @@ -59,6 +59,34 @@ from the ``CollectionTree`` tree in ATLAS PHYSLITE OpenData Dataset. :language: yaml +Func_ADL xAOD Query Example +~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +The two following examples read columns of data from an ATLAS PHYSLITE xAOD file +(released by the experiment as OpenData). It uses the internal C++ framework, EventLoop, to read this data. +EventLoop can be used to read xAOD files in general, not just PHYSLITE. + +THe first example uses the very simple model that is built into ServiceX: + +.. tabs:: + + .. tab:: *Python Dict* + + .. literalinclude:: ../examples/func_adl_xAOD_simple.py + :language: python + +The second example uses the full type information, allowing one to +access everything that could be translated in the xAOD (including ElementLink following): + +.. tabs:: + + .. tab:: *Python Dict* + + .. literalinclude:: ../examples/func_adl_xAOD_typed.py + :language: python + +For this second example, make sure the extra package `func_adl_servicex_xaodr22` is installed! + Python Function Query Example ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ This example uses an uproot python function to extract the ``AnalysisElectronsAuxDyn.pt`` branch