{ "cells": [ { "cell_type": "markdown", "id": "eada1107-1957-4868-b9a2-326ce0663b43", "metadata": {}, "source": [ "# Accessing files in different storage locations" ] }, { "cell_type": "markdown", "id": "f27d9e7e-5f1b-4630-843a-3025741b690c", "metadata": {}, "source": [ "In this demo, we demonstrate how data can be accessed from different storage spaces available to a Purdue Analysis Facility user. Copies of the same ROOT file have been placed in different storage locations, in this example they are accessed via `uproot.open()`." ] }, { "cell_type": "code", "execution_count": 1, "id": "76288510-3239-4606-89b2-47156171644c", "metadata": { "tags": [] }, "outputs": [], "source": [ "import uproot\n", "import time\n", "\n", "def test_file_access(path, filename):\n", " '''\n", " This function opens a NanoAOD file at a given path\n", " and prints the pT of the first muon found in that file,\n", " as well as the time taken to access the file.\n", " '''\n", "\n", " print(f\"Accessing file at {path}{filename}\")\n", " start = time.time()\n", " with uproot.open(path+filename)[\"Events\"] as file:\n", " pt = file[\"Muon_pt\"].array()[0][0]\n", " print(\"First muon pT: \", round(pt, 2), \"GeV\")\n", "\n", " dt = round(time.time()-start, 2)\n", " print(f\"Time elapsed: {dt}s.\")\n", " print()\n" ] }, { "cell_type": "markdown", "id": "865c3159-8061-4123-b80f-c5c3945f300f", "metadata": { "tags": [] }, "source": [ "### 0. Local files" ] }, { "cell_type": "code", "execution_count": 2, "id": "c187c93a-8479-4f77-a1ea-5c5306b79108", "metadata": { "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Accessing file at ./data/test_nanoaod.root\n", "First muon pT: 82.55 GeV\n", "Time elapsed: 3.91s.\n", "\n" ] } ], "source": [ "test_file_access(\"./data/\", \"test_nanoaod.root\")" ] }, { "cell_type": "markdown", "id": "050e19bc-955e-4a75-a4e4-c92e81a0f09c", "metadata": { "tags": [] }, "source": [ "### 1. Purdue Depot\n", "The Purdue Depot storage is writeable for Purdue users, but read-only for external users." ] }, { "cell_type": "code", "execution_count": 3, "id": "a1d9210a-18fd-4312-b7b1-38d6f6d1fe06", "metadata": { "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Accessing file at /depot/cms/hmm/test_nanoaod_depot.root\n", "First muon pT: 82.55 GeV\n", "Time elapsed: 0.87s.\n", "\n", "Accessing file at ~/depot/hmm/test_nanoaod_depot.root\n", "First muon pT: 82.55 GeV\n", "Time elapsed: 0.71s.\n", "\n" ] } ], "source": [ "# Choice of two paths - the mount point and the symlink in home directory\n", "# (the latter is convenient for access via the file browser).\n", "\n", "filename = \"test_nanoaod_depot.root\"\n", "test_file_access(\"/depot/cms/hmm/\", filename)\n", "test_file_access(\"~/depot/hmm/\", filename)" ] }, { "cell_type": "markdown", "id": "7b3e85b1-65b3-490e-93cb-5e7d8be5cb12", "metadata": { "tags": [] }, "source": [ "### 2. Purdue EOS\n", "Purdue EOS storage is mounted as read-only FS; however, Purdue users can write to their EOS directories using `gfal` commands [(see instrictions here)](https://www.physics.purdue.edu/Tier2/user-info/tutorials/dfs_commands.php)." ] }, { "cell_type": "code", "execution_count": 4, "id": "ac050d04-e2ad-431f-a216-1ff943fa92a0", "metadata": { "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Accessing file at /eos/purdue/store/user/dkondrat/test_nanoaod_eos_purdue.root\n", "First muon pT: 82.55 GeV\n", "Time elapsed: 0.82s.\n", "\n", "Accessing file at ~/eos-purdue/store/user/dkondrat/test_nanoaod_eos_purdue.root\n", "First muon pT: 82.55 GeV\n", "Time elapsed: 0.79s.\n", "\n" ] } ], "source": [ "# Choice of two paths - the mount point and the symlink in home directory\n", "# (the latter is convenient for access via the file browser).\n", "\n", "filename = \"test_nanoaod_eos_purdue.root\"\n", "test_file_access(\"/eos/purdue/store/user/dkondrat/\", filename)\n", "test_file_access(\"~/eos-purdue/store/user/dkondrat/\", filename)" ] }, { "cell_type": "markdown", "id": "6d7241ef-7e41-45c0-8b21-c4c53f70a8e4", "metadata": { "tags": [] }, "source": [ "### 3. CERN EOS (CERNBox)\n", "\n", "