From 5869eb1b695e2c0ba60b1cfcdf18d866c507170d Mon Sep 17 00:00:00 2001 From: Fabrizio Date: Tue, 5 Nov 2024 14:21:04 +0100 Subject: [PATCH] Add simple script to find corrupted AO2Ds in MC productions (#1783) --- UTILS/checkCorruptedAO2Ds.C | 52 +++++++++++++++++++++++++++++++++++++ UTILS/findCorruptedAO2Ds.sh | 44 +++++++++++++++++++++++++++++++ 2 files changed, 96 insertions(+) create mode 100644 UTILS/checkCorruptedAO2Ds.C create mode 100755 UTILS/findCorruptedAO2Ds.sh diff --git a/UTILS/checkCorruptedAO2Ds.C b/UTILS/checkCorruptedAO2Ds.C new file mode 100644 index 000000000..85cbf0098 --- /dev/null +++ b/UTILS/checkCorruptedAO2Ds.C @@ -0,0 +1,52 @@ +#include +#include +#include +#include +#include +#include + +int checkCorruptedAO2Ds(TString infileName = "/alice/sim/2024/LHC24h2/535545/AOD/005/AO2D.root", bool fromAlien = true) { + + if (fromAlien) { + TGrid::Connect("alien://"); + if (!infileName.Contains("alien://")) { + infileName = "alien://" + infileName; + } + } + + auto inFile = TFile::Open(infileName.Data()); + if (!inFile || inFile->IsZombie()) { + return -1; + } + + // all VLA branches in the AO2Ds.root + std::map> branchesToCheck = { + {"O2mcparticle_001", std::vector{"fIndexArray_Mothers"}}, + {"O2ft0", std::vector{"fAmplitudeA", "fChannelA", "fAmplitudeC", "fChannelC"}}, + {"O2fv0a", std::vector{"fAmplitude", "fChannel"}}, + {"O2mccalolabel_001", std::vector{"fIndexArrayMcParticles", "fAmplitudeA"}}, + {"O2zdc_001", std::vector{"fEnergy", "fChannelE", "fAmplitude", "fTime", "fChannelT"}} + }; + + for (auto const& dirKey : *inFile->GetListOfKeys()) { + if (TString(dirKey->GetName()).Contains("DF")) { + auto df = static_cast(inFile->Get(dirKey->GetName())); + std::cout << dirKey->GetName() << std::endl; + for (auto const& pair : branchesToCheck) { + auto tree = static_cast(df->Get(pair.first.data())); + for (auto const& branchName : pair.second) { + auto leaf = static_cast(tree->GetLeaf(branchName.data())); + + for (int iEntry{0}; iEntryGetEntries(); ++iEntry) { + if (tree->GetEntry(iEntry) < 0) { + std::cout << "Found corrupted file! DF: " << dirKey->GetName() << " Tree:" << pair.first.data() << " Branch:" << branchName.data() << std::endl; + return -1; + } + } + } + } + } + } + + return 0; +} \ No newline at end of file diff --git a/UTILS/findCorruptedAO2Ds.sh b/UTILS/findCorruptedAO2Ds.sh new file mode 100755 index 000000000..fd4ebfccb --- /dev/null +++ b/UTILS/findCorruptedAO2Ds.sh @@ -0,0 +1,44 @@ +#!/bin/bash + +# Simple script to find corrupted AO2Ds using the checkCorruptedAO2Ds.C macro + +PRODUCTION=LHC24h2 +RUN=* # use * for all runs +NJOBS=90 + +OUTPUTFILE=corrupted_files_$PRODUCTION.txt +if [ -e "$OUTPUTFILE" ]; then + rm $OUTPUTFILE +fi + +# find all files in alien +if [ "$variable" == "*" ]; then + alien_find alien:///alice/sim/2024/${PRODUCTION} 5*/AOD/*/AO2D.root > files_to_check.txt +else + alien_find alien:///alice/sim/2024/${PRODUCTION} ${RUN}/AOD/*/AO2D.root > files_to_check.txt +fi +mapfile -t FILESTOCHECK < files_to_check.txt + +# process AO2Ds +process_file() { + IFS='/' read -a num <<< "$1" + INPUT=$1 + echo '.x checkCorruptedAO2Ds.C("'${INPUT}'", true)' | root -l -b > log_${num[5]}_${num[7]} + echo '.q' +} +export -f process_file + +parallel -j $NJOBS process_file ::: "${FILESTOCHECK[@]}" + +# create list of corrupted files +touch $OUTPUTFILE +ERRORSTR="Found corrupted file!" +for FILE in "${FILESTOCHECK[@]}"; do + IFS='/' read -a num <<< "$FILE" + if grep -q "$ERRORSTR" log_${num[5]}_${num[7]}; then + echo $FILE >> $OUTPUTFILE + fi +done + +rm files_to_check.txt +rm log* \ No newline at end of file