forked from AliceO2Group/O2DPG
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheckCorruptedAO2Ds.C
More file actions
69 lines (59 loc) · 2.79 KB
/
checkCorruptedAO2Ds.C
File metadata and controls
69 lines (59 loc) · 2.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <TFile.h>
#include <TDirectoryFile.h>
#include <TTree.h>
#include <TTreeReader.h>
#include <TGrid.h>
#include <iostream>
#include <TError.h>
#include <cstring>
bool gWarningDetected = false; // Global flag to track the warning
void MyErrorHandler(int level, Bool_t abort, const char *location, const char *msg) {
if (strstr(msg, "repair") != nullptr) {
gWarningDetected = true;
}
DefaultErrorHandler(level, abort, location, msg); // Call ROOT’s default handler
}
int checkCorruptedAO2Ds(TString infileName = "/alice/sim/2024/LHC24h2/535545/AOD/005/AO2D.root", bool fromAlien = true) {
SetErrorHandler(MyErrorHandler);
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", "fVx", "fIndexMcCollisions"}},
{"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;
}
if (gWarningDetected) {
std::cout << "Found file in need of repair! DF: " << dirKey->GetName() << " Tree:" << pair.first.data() << " Branch:" << branchName.data() << std::endl;
return -2;
}
}
}
}
}
}
return 0;
}