/af-bnl:localgroupdisk-migrationfrom af-bnl
Migrates ROOT files to BNL LOCALGROUPDISK via Rucio with pre-flight checks, replication monitoring, and symlink farm creation. Supports full pipeline or standalone phases.
Ships in af-bnl. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
End-to-end migration of a directory of ROOT files to BNL LOCALGROUPDISK. Handles pre-flight checks, upload to scratchdisk, replication, symlink farm creation, and optional codebase path adaptation with safe rollback.
For a partial workflow (run one phase standalone — e.g. you already replicated and only need the symlink farm, or you just want to re-check your proxy, or resume monitoring an existing rule), follow the bundled reference for that phase instead of the full pipeline:
references/preflight.md — the 5 prerequisite checks, standalonereferences/check-rule.md — monitor a Rucio rule ID to OK/STUCKreferences/build-symlinks.md — build a symlink farm from an
already-replicated datasetArguments:
$source_dir — absolute path to the directory containing .root files$dataset_name — Rucio dataset name (no scope prefix), e.g.
powheg_cc_evgen_truthIf any argument is missing, ask the user before proceeding.
If the user's message includes any of these phrases (case-insensitive): "no confirmation", "no confirm", "autonomous", "proceed without confirmation", "all steps without confirmation", "no questions" — then skip all interactive prompts and use defaults:
_orig guard (Step 7): does not stop — a pre-existing
${source_dir}_orig is never overwritten; the backup goes to a unique nameThe one exception to "no questions": the Final step always asks whether to
delete the $BACKUP_DIR backup (never automatic — irreversible and the only
rollback path). This runs once, at the very end, after all work is done.
The user can pre-answer individual decision points in their message (e.g., "using same-path swap" or "upload only"). Honor explicit choices over defaults. Autonomous mode only suppresses the prompt — all checks, verifications, and error stops still run.
_orig and places the farm at the original path (atomic swap via staging
directory).user.<account> — derived from rucio whoami.root://dcgftp.usatlas.bnl.gov:1094/ — strip this to get the
local pnfs path for symlinks.All rucio and voms-proxy-* commands below require the ATLAS environment.
Bootstrap it once per shell as documented in the setupatlas skill (sources
ALRB, exposes lsetup), then set up Rucio:
# Bootstrap per the setupatlas skill, then:
lsetup rucio >/dev/null 2>&1
In a non-interactive shell where the setupATLAS alias is not defined, source
ALRB directly first (see the setupatlas skill for details):
export ATLAS_LOCAL_ROOT_BASE=/cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase
source $ATLAS_LOCAL_ROOT_BASE/user/atlasLocalSetup.sh >/dev/null 2>&1
lsetup rucio >/dev/null 2>&1
Subsequent code blocks assume the environment is already set up.
Before starting, run all checks below and report a summary table. STOP if any
check is FAIL. Full detail on each check (exact failure modes, what to tell the
user) is in references/preflight.md — read it when troubleshooting a FAIL.
rucio whoami 2>/dev/null # 1. account name (used as user.<account> scope)
voms-proxy-info --all 2>&1 # 2. >2h remaining; VOMS must include /atlas/usatlas
rucio list-rses 2>/dev/null | grep -i "BNL-OSG2" # 3. expect BNL-OSG2_LOCALGROUPDISK + _SCRATCHDISK
ACCOUNT=$(rucio whoami 2>/dev/null | grep "account" | awk '{print $2}')
rucio list-account-limits $ACCOUNT 2>/dev/null | grep -E "BNL-OSG2_(LOCALGROUPDISK|SCRATCHDISK)" # 4. quotas
rucio list-account-usage $ACCOUNT 2>/dev/null | grep BNL-OSG2_SCRATCHDISK
ls /pnfs/usatlas.bnl.gov/LOCALGROUPDISK/ 2>&1 | head -3 # 5. pnfs mount (not atlaslocalgroupdisk)
If Check 2's proxy is <2h or missing /atlas/usatlas, tell the user to run
voms-proxy-init -voms atlas:/atlas/usatlas -valid 96:00 (the explicit group is
required). If Check 4's LGD quota is missing, the user needs /atlas/usatlas
VOMS group membership from https://atlas-auth.cern.ch/.
Report pre-flight results as a summary table:
| Check | Status | Details |
|---|---|---|
| Rucio account | OK/FAIL | account name |
| Grid proxy | OK/WARN/FAIL | time remaining, VOMS groups |
| RSE names | OK/FAIL | confirmed names |
| LGD quota | OK/FAIL | limit |
| Scratchdisk | OK/FAIL | limit, used |
| pnfs mount | OK/FAIL | path |
STOP if any check is FAIL.
Execute sequentially. Stop on any error and report. Derive $SCOPE from the
Rucio account (e.g., account jdoe → $SCOPE = user.jdoe).
Step 1 — Survey source files:
ls -1 "$source_dir"/*.root | head -5
ls -1 "$source_dir"/*.root | wc -l
du -sh "$source_dir"
Check for non-.root files:
find "$source_dir" -maxdepth 1 -type f ! -name '*.root' 2>/dev/null
If any non-.root files are found, warn the user:
Warning:
$source_dircontains non-.rootfiles that will NOT be included in the migration:<list of files>If your analysis code expects these files (metadata, logs, config), the symlink farm will be missing them and your code may break. Options:
- Proceed anyway — only
.rootfiles will be migrated- Abort — manually handle the extra files first
In autonomous mode: proceed with warning noted in output.
Report: number of .root files, total size, any non-.root files. Confirm with
the user before proceeding.
Step 2 — Check for DID conflicts:
Check every .root file, not just the first — a collision on any one of
them must be caught before upload:
for f in "$source_dir"/*.root; do
rucio list-dids "$SCOPE:$(basename "$f")" 2>/dev/null
done
If any file already exists as a DID under the user's scope, STOP and warn. Options: (a) reuse existing DID if it has a scratchdisk replica — skip to Step 4; (b) rename with a suffix (last resort).
Step 3 — Upload to scratchdisk:
rucio upload --rse BNL-OSG2_SCRATCHDISK --scope $SCOPE \
"$source_dir"/*.root
Source files are NOT modified or deleted. ~30s per 4 GB file. For
50 files, upload in batches. STOP on any error — nothing to clean up.
Step 4 — Create dataset and attach files:
rucio add-dataset $SCOPE:$dataset_name
rucio list-dids "$SCOPE:*" --type FILE --short 2>/dev/null | tail -5
rucio attach $SCOPE:$dataset_name $SCOPE:<file_pattern>
Verify: rucio list-files $SCOPE:$dataset_name should show all files.
Step 5 — Add replication rule:
RULE_ID=$(rucio add-rule $SCOPE:$dataset_name 1 \
BNL-OSG2_LOCALGROUPDISK)
echo "Rule ID: $RULE_ID"
Step 5b — Wait for replication:
Poll rucio rule-info $RULE_ID every 2 minutes with the Monitor tool
(timeout: 3600000, i.e. 1 hour, re-running on timeout) until State reaches
OK or STUCK. The exact polling script and STUCK-recovery guidance (a STUCK
rule doesn't always mean permanent failure — check the Error: field) are in
references/check-rule.md. FTS queue waits of 1–12 hours before any progress
are normal; if it reaches STUCK, report the error and STOP.
Decision Point 1 — Migration mode (after replication reaches OK):
- Upload + symlink swap (default) — build a symlink farm for transparent local access
- Upload only — data is on LOCALGROUPDISK, stop here
Upload only → no symlink farm and no backup. Go to the Final step (summary only; no cleanup decision).
Decision Point 2 — Symlink placement:
- Same-path swap (default) — rename
source_dirtosource_dir_orig, place symlink farm atsource_dir. Analysis code works without any changes.- Different path — place symlink farm at a separate location (user provides the path).
Same-path swap → set $farm_dir = $source_dir, go to Phase 2. Different path →
ask user for $farm_dir, go to Decision Point 3.
Decision Point 3 — Code integration (different-path only):
- Full integration (default) — build symlink farm, scan codebase for references to the old path, update code, test with safe rollback. All changes on a git branch (
lgd-migrate-<dataset>).- Symlink only — build symlink farm at the new path, no code changes.
Symlink only → go to Phase 2 (skip rename step). Full integration → go to Phase 3.
Step 6 — Get PFNs:
rucio list-file-replicas $SCOPE:$dataset_name \
--protocols root --pfns --rses BNL-OSG2_LOCALGROUPDISK \
> /tmp/pfns_${dataset_name}.txt
Step 7 — Build symlink farm:
If same-path swap ($farm_dir == $source_dir):
Build the farm in a staging directory first, then do an atomic swap.
Guard checks (these never stop the run — the only _orig decision is the
deletion at the very end, see the Final step):
${source_dir}_lgd_staging exists (leftover), remove it.$BACKUP_DIR that does not clobber any existing
one, so a leftover ${source_dir}_orig from a previous migration is never
overwritten and never halts the run:BACKUP_DIR="${source_dir}_orig"
[ -e "$BACKUP_DIR" ] && BACKUP_DIR="${source_dir}_orig.$(date +%Y%m%d_%H%M%S)"
echo "Backup directory: $BACKUP_DIR"
Build the staging farm:
STAGING="${source_dir}_lgd_staging"
mkdir -p "$STAGING"
while read -r pfn; do
pnfs_path="${pfn#root://dcgftp.usatlas.bnl.gov:1094/}"
filename=$(basename "$pnfs_path")
ln -s "$pnfs_path" "$STAGING/$filename"
done < /tmp/pfns_${dataset_name}.txt
Verify staging count before swapping:
ORIG_COUNT=$(ls -1 "$source_dir"/*.root 2>/dev/null | wc -l)
FARM_COUNT=$(ls -1 "$STAGING" | wc -l)
echo "Original: $ORIG_COUNT files, Farm: $FARM_COUNT symlinks"
If counts match, perform the swap:
mv "$source_dir" "$BACKUP_DIR"
mv "$STAGING" "$source_dir"
If the second mv fails, immediately restore:
mv "$BACKUP_DIR" "$source_dir"
rm -rf "$STAGING"
If different path:
mkdir -p "$farm_dir"
while read -r pfn; do
pnfs_path="${pfn#root://dcgftp.usatlas.bnl.gov:1094/}"
filename=$(basename "$pnfs_path")
ln -s "$pnfs_path" "$farm_dir/$filename"
done < /tmp/pfns_${dataset_name}.txt
Step 8 — Verify:
Symlink count matches source file count: ls -1 "$farm_dir" | wc -l
Spot-check one symlink resolves:
ls -la "$farm_dir"/$(ls "$farm_dir" | head -1)
ROOT readability check:
root -b -l -q -e '
auto f=TFile::Open("'"$farm_dir"'/$(ls $farm_dir | head -1)");
cout << (f && !f->IsZombie() ? "OK" : "FAIL") << endl;'
Step 8b — Smoke test (same-path swap only):
Three checks compare the backup $BACKUP_DIR (original local files, renamed in
Step 7) against the farm $farm_dir (symlinks to the LOCALGROUPDISK replicas).
Run them in order and STOP at the first failure. The smoke test PASSES only if
all three pass.
(1) Filename set — nothing dropped, added, or duplicated:
diff <(cd "$BACKUP_DIR" && ls -1 *.root | sort) \
<(cd "$farm_dir" && ls -1 *.root | sort) \
&& echo "FILENAMES MATCH" || echo "FILENAMES MISMATCH"
(2) Per-file TTree entry counts — compared file-by-file (not a single chained total, so offsetting errors across files cannot cancel). Reads only TTree metadata, so it is fast even for large datasets:
root -b -l -q -e '
#include <TSystemDirectory.h>
#include <TSystemFile.h>
#include <TFile.h>
#include <TTree.h>
#include <TKey.h>
#include <iostream>
using namespace std;
TString od = "'"$BACKUP_DIR"'", fd = "'"$farm_dir"'";
TSystemDirectory dir(od, od);
TIter nf(dir.GetListOfFiles());
TSystemFile *sf; bool ok = true;
while ((sf = (TSystemFile*)nf())) {
TString fn = sf->GetName();
if (sf->IsDirectory() || !fn.EndsWith(".root")) continue;
TFile *forig = TFile::Open(od+"/"+fn), *ff = TFile::Open(fd+"/"+fn);
if (!forig || forig->IsZombie() || !ff || ff->IsZombie()) {
cout << fn << ": FAIL open" << endl; ok = false; continue; }
TIter nk(forig->GetListOfKeys()); TKey *k;
while ((k = (TKey*)nk())) {
if (TString(k->GetClassName()) != "TTree") continue;
TString tn = k->GetName();
TTree *to = (TTree*)forig->Get(tn), *tf = (TTree*)ff->Get(tn);
Long64_t no = to ? to->GetEntries() : -1;
Long64_t ne = tf ? tf->GetEntries() : -2;
if (no != ne) {
cout << fn << ":" << tn << " orig=" << no << " farm=" << ne
<< " MISMATCH" << endl; ok = false; }
}
forig->Close(); ff->Close();
}
cout << (ok ? "PER-FILE COUNTS MATCH" : "PER-FILE COUNTS MISMATCH") << endl;
'
(3) Content checksum (adler32) — authoritative byte-level check. Rucio
registers an adler32 per file at upload and FTS verifies the replica against it
before the rule reaches OK, so comparing each local source file's adler32
to its Rucio-registered adler32 proves source ≡ replica without re-reading
from LOCALGROUPDISK:
# Rucio-registered checksums (NAME + ADLER32 columns)
rucio list-files $SCOPE:$dataset_name 2>/dev/null
# Local source checksums (xrdadler32 ships with xrootd; `lsetup xrootd` if absent)
for f in "$BACKUP_DIR"/*.root; do
printf '%s %s\n' "$(basename "$f")" "$(xrdadler32 "$f" | awk '{print $1}')"
done
Every file's local adler32 must equal its Rucio-registered adler32. To compare
the farm replicas directly instead (reads from LOCALGROUPDISK, slower), run
xrdadler32 "$farm_dir"/*.root and match against the source values.
Checks (1)+(3) together guarantee file-by-file content equality; (2) is a fast, checksum-free cross-check.
$BACKUP_DIR deletion decision is deferred to the Final step.
Proceed there.mv "$farm_dir" "${farm_dir}_lgd"; mv "$BACKUP_DIR" "$source_dir".DONE for Phase 2 → go to the Final step.
All changes are on a rollback-safe git branch.
Step 6 — Save working tree state:
git status --porcelain
If dirty, ask: (a) Commit first (recommended), or (b) Stash. Record
STASH_CREATED and stash ref if applicable.
Step 6b — Create migration branch:
BASE_BRANCH=$(git symbolic-ref --short HEAD)
git checkout -b lgd-migrate-${dataset_name}
Record $BASE_BRANCH — used for rollback (never hardcode main).
Step 7 — Get PFNs and build symlink farm:
Same as Phase 2 Steps 6–8, different-path variant (do NOT rename $source_dir).
Step 8 — Find and update path references:
Search the codebase for references to $source_dir. Do not stop at literal
string matches — handle these edge cases:
base_dir + subdir + filename. Search for directory
basename, parent name, and representative filenames..cfg, .json, .yaml, .sh, job submission
files.~/, $HOME, or symlinks resolving to
$source_dir.For each match, classify the hit and propose the edit. Present the list to the
user for confirmation before applying. Show git diff --stat after editing.
If no references found, ask the user which file defines the path. If unknown,
exit with manual instructions and skip to Step 10 with Test result: SKIPPED.
Step 9 — Test run:
Level 1 — ROOT-level verification (always run): Open a sample file, verify not zombie, compare TTree entry counts via TChain between original and farm. MISMATCH → STOP and roll back.
Level 2 — Analysis-level test (if code was changed): Attempt compilation (ACLiC for ROOT macros, framework build system otherwise). If possible without disruption, run minimal test in a temp directory (never overwrite original outputs). If test would require Condor or long runtime, report:
Verified: compilation OK, TChain entry counts match (<N> entries).
Not tested: full analysis run (requires <reason>).
Recommended: run <specific command> and compare output.
Step 9b — Finalize or roll back:
If tests pass: commit changes, restore stash (report conflicts if any), suggest
merging lgd-migrate-<dataset> into $BASE_BRANCH.
If tests fail: report error, revert all changes, delete branch, restore stash, report:
## Migration test FAILED: <dataset_name>
- Error: <error output>
- Rollback: all code changes reverted, branch deleted
- Stash: <restored / restored with conflicts / none>
- Symlink farm at $farm_dir still intact (harmless)
- Original files at $source_dir unchanged
DONE for Phase 3 → go to the Final step. (Phase 3 keeps the source dir in
place and creates no $BACKUP_DIR, so the Final step only writes the summary.)
Every path ends here. Write the migration summary, then make the backup-cleanup decision. This is the last action of the run, and in autonomous mode it is the only question asked — nothing earlier stops for it.
Summary (include the fields that apply to the path taken):
## LOCALGROUPDISK Migration: <dataset_name>
- Source: $source_dir (<N> files, <size>)
- Dataset: $SCOPE:$dataset_name
- Rule ID: $RULE_ID
- Symlink farm: $farm_dir
- Backup (same-path swap only): $BACKUP_DIR
- Code files modified (full integration only): <list or "none">
- Test result (full integration only): PASS / FAIL / SKIPPED
- Branch (full integration only): lgd-migrate-<dataset> (base: $BASE_BRANCH)
Backup cleanup — only when a same-path swap created $BACKUP_DIR
(upload-only and different-path runs have no backup; skip this and finish):
The original files are preserved at $BACKUP_DIR. Deleting it is irreversible
and it is the only rollback path, so it is never deleted automatically. Ask
the user — a plain question, not a stop, in every mode including autonomous:
$BACKUP_DIR, and that removing it
reclaims the local/pnfs space the migration was likely meant to free.$BACKUP_DIR now (then report
space freed), or (b) keep it and remove it manually later.Suppose you have 25 Monte Carlo ROOT files (98 GB total) at
/pnfs/usatlas.bnl.gov/users/<you>/mc_sample/ and want them on LOCALGROUPDISK
with a symlink farm at the original path.
/af-bnl:localgroupdisk-migration /pnfs/usatlas.bnl.gov/users/<you>/mc_sample mc_sample_truth
.root files, 98 GB.rucio upload --rse BNL-OSG2_SCRATCHDISK — ~12 min.user.<you>:mc_sample_truth, 25 files attached.mc_sample_orig, creates symlinks at
the original path.mc_sample_orig is retained
(never auto-deleted) and the run ends by asking whether to delete it now or
leave it for manual removal.After migration: analysis code reads from the same path — no changes needed. No grid proxy required.
| Step | Problem | What happens |
|---|---|---|
| 2 | Database error (dup DID) | Stops, offers reuse or rename |
| 5 | insufficient quota | Stops, directs to ATLAS IAM for VOMS group |
| 5b | Rule stuck at 0/N for hours | Normal FTS queue delay; skill documents expected timing |
| 8 | Symlinks don't resolve | Checks pnfs mount; reports if unavailable |
| 8 | Crash between rename and build | Farm built in staging dir first, then atomic swap |
| 8 | ROOT can't open file | Reports failure; original at $BACKUP_DIR is intact |
| 8 | Code search finds nothing | Asks user; exits with manual instructions if unknown |
| 9 | Test fails after code edits | Rolls back all changes, deletes branch, restores stash |
| 9b | Stash pop has merge conflict | Reports conflicting files, asks user to resolve |
references/preflight.md and references/check-rule.md for the specific
failure modes of the pre-flight checks and replication polling.At no point are source files modified or deleted. Full rollback:
rm -rf "$farm_dir"
mv "$BACKUP_DIR" "$source_dir" # if same-path swap
rucio delete-rule $RULE_ID
rucio erase $SCOPE:$dataset_name
# If full integration:
git checkout "$BASE_BRANCH" -- .
git checkout "$BASE_BRANCH"
git branch -D lgd-migrate-${dataset_name}
-valid 96:00 since FTS can take up to 12 hours.BNL-OSG2_LOCALGROUPDISK, BNL-OSG2_SCRATCHDISK (note
hyphen/underscore positions)./pnfs/usatlas.bnl.gov/LOCALGROUPDISK/./pnfs/usatlas.bnl.gov/LOCALGROUPDISK/rucio/user/<username>/<2-char-hash>/<2-char-hash>/<filename>.rucio upload copies files — source is never modified or deleted.What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
Other plugins' skills for the same job
npx claudepluginhub usatlas/marketplace --plugin af-bnl