Skip to content

Commit 4978a95

Browse files
committed
Add simple script to find corrupted AO2Ds in MC productions
1 parent 5672afa commit 4978a95

File tree

2 files changed

+96
-0
lines changed

2 files changed

+96
-0
lines changed

UTILS/checkCorruptedAO2Ds.C

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#include <TFile.h>
2+
#include <TDirectoryFile.h>
3+
#include <TTree.h>
4+
#include <TTreeReader.h>
5+
#include <TGrid.h>
6+
#include <iostream>
7+
8+
int checkCorruptedAO2Ds(TString infileName = "/alice/sim/2024/LHC24h2/535545/AOD/005/AO2D.root", bool fromAlien = true) {
9+
10+
if (fromAlien) {
11+
TGrid::Connect("alien://");
12+
if (!infileName.Contains("alien://")) {
13+
infileName = "alien://" + infileName;
14+
}
15+
}
16+
17+
auto inFile = TFile::Open(infileName.Data());
18+
if (!inFile || inFile->IsZombie()) {
19+
return -1;
20+
}
21+
22+
// all VLA branches in the AO2Ds.root
23+
std::map<std::string, std::vector<std::string>> branchesToCheck = {
24+
{"O2mcparticle_001", std::vector<std::string>{"fIndexArray_Mothers"}},
25+
{"O2ft0", std::vector<std::string>{"fAmplitudeA", "fChannelA", "fAmplitudeC", "fChannelC"}},
26+
{"O2fv0a", std::vector<std::string>{"fAmplitude", "fChannel"}},
27+
{"O2mccalolabel_001", std::vector<std::string>{"fIndexArrayMcParticles", "fAmplitudeA"}},
28+
{"O2zdc_001", std::vector<std::string>{"fEnergy", "fChannelE", "fAmplitude", "fTime", "fChannelT"}}
29+
};
30+
31+
for (auto const& dirKey : *inFile->GetListOfKeys()) {
32+
if (TString(dirKey->GetName()).Contains("DF")) {
33+
auto df = static_cast<TDirectoryFile*>(inFile->Get(dirKey->GetName()));
34+
std::cout << dirKey->GetName() << std::endl;
35+
for (auto const& pair : branchesToCheck) {
36+
auto tree = static_cast<TTree*>(df->Get(pair.first.data()));
37+
for (auto const& branchName : pair.second) {
38+
auto leaf = static_cast<TLeaf*>(tree->GetLeaf(branchName.data()));
39+
40+
for (int iEntry{0}; iEntry<tree->GetEntries(); ++iEntry) {
41+
if (tree->GetEntry(iEntry) < 0) {
42+
std::cout << "Found corrupted file! DF: " << dirKey->GetName() << " Tree:" << pair.first.data() << " Branch:" << branchName.data() << std::endl;
43+
return -1;
44+
}
45+
}
46+
}
47+
}
48+
}
49+
}
50+
51+
return 0;
52+
}

UTILS/findCorruptedAO2Ds.sh

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/bin/bash
2+
3+
# Simple script to find corrupted AO2Ds using the checkCorruptedAO2Ds.C macro
4+
5+
PRODUCTION=LHC24h2
6+
RUN=* # use * for all runs
7+
NJOBS=90
8+
9+
OUTPUTFILE=corrupted_files_$PRODUCTION.txt
10+
if [ -e "$OUTPUTFILE" ]; then
11+
rm $OUTPUTFILE
12+
fi
13+
14+
# find all files in alien
15+
if [ "$variable" == "*" ]; then
16+
alien_find alien:///alice/sim/2024/${PRODUCTION} 5*/AOD/*/AO2D.root > files_to_check.txt
17+
else
18+
alien_find alien:///alice/sim/2024/${PRODUCTION} ${RUN}/AOD/*/AO2D.root > files_to_check.txt
19+
fi
20+
mapfile -t FILESTOCHECK < files_to_check.txt
21+
22+
# process AO2Ds
23+
process_file() {
24+
IFS='/' read -a num <<< "$1"
25+
INPUT=$1
26+
echo '.x checkCorruptedAO2Ds.C("'${INPUT}'", true)' | root -l -b > log_${num[5]}_${num[7]}
27+
echo '.q'
28+
}
29+
export -f process_file
30+
31+
parallel -j $NJOBS process_file ::: "${FILESTOCHECK[@]}"
32+
33+
# create list of corrupted files
34+
touch $OUTPUTFILE
35+
ERRORSTR="Found corrupted file!"
36+
for FILE in "${FILESTOCHECK[@]}"; do
37+
IFS='/' read -a num <<< "$FILE"
38+
if grep -q "$ERRORSTR" log_${num[5]}_${num[7]}; then
39+
echo $FILE >> $OUTPUTFILE
40+
fi
41+
done
42+
43+
rm files_to_check.txt
44+
rm log*

0 commit comments

Comments
 (0)