From 0641070b50af28b20d10d38f6c5506c125f1c5cd Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Tue, 10 Mar 2026 01:00:15 +0000
Subject: [PATCH 1/2] Initial plan


From 1cc50dca0c374e7df52fafcb19b14bc0dae67d23 Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Tue, 10 Mar 2026 01:04:37 +0000
Subject: [PATCH 2/2] Add Rucio/Chaining examples: uproot, TChain, and
 RDataFrame

Co-authored-by: wdconinc <4656391+wdconinc@users.noreply.github.com>
---
 Rucio/Chaining/rdataframe_example.py | 39 ++++++++++++++++++++++++++++
 Rucio/Chaining/tchain_example.py     | 36 +++++++++++++++++++++++++
 Rucio/Chaining/uproot_example.py     | 37 ++++++++++++++++++++++++++
 3 files changed, 112 insertions(+)
 create mode 100644 Rucio/Chaining/rdataframe_example.py
 create mode 100644 Rucio/Chaining/tchain_example.py
 create mode 100644 Rucio/Chaining/uproot_example.py

diff --git a/Rucio/Chaining/rdataframe_example.py b/Rucio/Chaining/rdataframe_example.py
new file mode 100644
index 0000000..c338603
--- /dev/null
+++ b/Rucio/Chaining/rdataframe_example.py
@@ -0,0 +1,39 @@
+from rucio.client import Client
+import ROOT
+
+# Initialize Rucio client
+client = Client()
+
+# Define the dataset DID
+dataset_did = "epic:/RECO/26.02.0/epic_craterlake/SINGLE/e+/500MeV/3to50deg"
+scope, name = dataset_did.split(':', 1)
+
+# Get the list of files in the dataset
+files = list(client.list_files(scope, name))
+dids = [{'scope': f['scope'], 'name': f['name']} for f in files]
+
+# Get one replica PFN for each file in the dataset
+file_paths = [
+    next(iter(replica['pfns']))  # Get first PFN URL (dict keys are the URLs)
+    for replica in client.list_replicas(dids, rse_expression='isopenaccess=true')
+    if replica['pfns']
+]
+
+# Create an RDataFrame with all files in the dataset
+# Replace "events" with the actual tree name
+rdf = ROOT.RDataFrame("events", file_paths)
+
+# Create histogram of EventHeader.eventNumber
+h_eventNumber = rdf.Histo1D(
+    ("h_eventNumber", "Event Number Distribution;Event Number;Count", 100, 0, 100),
+    "EventHeader.eventNumber"
+)
+
+# Draw and save the histogram
+canvas = ROOT.TCanvas("c1", "Event Number Distribution", 800, 600)
+h_eventNumber.Draw()
+canvas.SaveAs("event_number_distribution.png")
+
+# Print total entries
+print(f"Total entries in dataset: {rdf.Count().GetValue()}")
+print("Saved histogram to event_number_distribution.png")
diff --git a/Rucio/Chaining/tchain_example.py b/Rucio/Chaining/tchain_example.py
new file mode 100644
index 0000000..ed85af9
--- /dev/null
+++ b/Rucio/Chaining/tchain_example.py
@@ -0,0 +1,36 @@
+from rucio.client import Client
+import ROOT
+
+# Initialize Rucio client
+client = Client()
+
+# Define the dataset DID
+dataset_did = "epic:/RECO/26.02.0/epic_craterlake/SINGLE/e+/500MeV/3to50deg"
+scope, name = dataset_did.split(':', 1)
+
+# Get the list of files in the dataset
+files = list(client.list_files(scope, name))
+dids = [{'scope': f['scope'], 'name': f['name']} for f in files]
+
+# Get one replica PFN for each file in the dataset
+file_paths = [
+    next(iter(replica['pfns']))  # Get first PFN URL (dict keys are the URLs)
+    for replica in client.list_replicas(dids, rse_expression='isopenaccess=true')
+    if replica['pfns']
+]
+
+# Create a TChain to process all files as a single dataset
+# Replace "events" with the actual tree name in your files
+chain = ROOT.TChain("events")
+
+for file_path in file_paths:
+    chain.Add(file_path)
+
+# Create histogram of EventHeader.eventNumber
+canvas = ROOT.TCanvas("c1", "Event Number Distribution", 800, 600)
+chain.Draw("EventHeader.eventNumber>>h_eventNumber(100)")
+canvas.SaveAs("event_number_distribution.png")
+
+# Print total entries
+print(f"Total entries in dataset: {chain.GetEntries()}")
+print("Saved histogram to event_number_distribution.png")
diff --git a/Rucio/Chaining/uproot_example.py b/Rucio/Chaining/uproot_example.py
new file mode 100644
index 0000000..244e869
--- /dev/null
+++ b/Rucio/Chaining/uproot_example.py
@@ -0,0 +1,37 @@
+from rucio.client import Client
+import uproot
+import matplotlib.pyplot as plt
+import numpy as np
+
+# Initialize Rucio client
+client = Client()
+
+# Define the dataset DID
+dataset_did = "epic:/RECO/26.02.0/epic_craterlake/SINGLE/e+/500MeV/3to50deg"
+scope, name = dataset_did.split(':', 1)
+
+# Get the list of files in the dataset
+files = list(client.list_files(scope, name))
+dids = [{'scope': f['scope'], 'name': f['name']} for f in files]
+
+# Get one replica PFN for each file in the dataset
+file_paths = [
+    next(iter(replica['pfns']))  # Get first PFN URL (dict keys are the URLs)
+    for replica in client.list_replicas(dids, rse_expression='isopenaccess=true')
+    if replica['pfns']
+]
+
+# Collect EventHeader.eventNumber from all files
+event_numbers = []
+for file_path in file_paths:
+    with uproot.open(file_path) as f:
+        tree = f["events"]  # Replace "events" with the actual tree name
+        event_numbers.extend(tree["EventHeader.eventNumber"].array())
+
+# Create histogram
+plt.hist(event_numbers, bins=50)
+plt.xlabel("Event Number")
+plt.ylabel("Count")
+plt.title("EventHeader.eventNumber Distribution")
+plt.savefig("event_number_distribution.png")
+print("Saved histogram to event_number_distribution.png")
