-
Notifications
You must be signed in to change notification settings - Fork 155
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add simple script to find corrupted AO2Ds in MC productions (#1783)
- Loading branch information
Showing
2 changed files
with
96 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#include <TFile.h> | ||
#include <TDirectoryFile.h> | ||
#include <TTree.h> | ||
#include <TTreeReader.h> | ||
#include <TGrid.h> | ||
#include <iostream> | ||
|
||
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<std::string, std::vector<std::string>> branchesToCheck = { | ||
{"O2mcparticle_001", std::vector<std::string>{"fIndexArray_Mothers"}}, | ||
{"O2ft0", std::vector<std::string>{"fAmplitudeA", "fChannelA", "fAmplitudeC", "fChannelC"}}, | ||
{"O2fv0a", std::vector<std::string>{"fAmplitude", "fChannel"}}, | ||
{"O2mccalolabel_001", std::vector<std::string>{"fIndexArrayMcParticles", "fAmplitudeA"}}, | ||
{"O2zdc_001", std::vector<std::string>{"fEnergy", "fChannelE", "fAmplitude", "fTime", "fChannelT"}} | ||
}; | ||
|
||
for (auto const& dirKey : *inFile->GetListOfKeys()) { | ||
if (TString(dirKey->GetName()).Contains("DF")) { | ||
auto df = static_cast<TDirectoryFile*>(inFile->Get(dirKey->GetName())); | ||
std::cout << dirKey->GetName() << std::endl; | ||
for (auto const& pair : branchesToCheck) { | ||
auto tree = static_cast<TTree*>(df->Get(pair.first.data())); | ||
for (auto const& branchName : pair.second) { | ||
auto leaf = static_cast<TLeaf*>(tree->GetLeaf(branchName.data())); | ||
|
||
for (int iEntry{0}; iEntry<tree->GetEntries(); ++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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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* |