forked from AliceO2Group/O2DPG
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreadAO2Ds.C
More file actions
71 lines (69 loc) · 3.13 KB
/
Copy pathreadAO2Ds.C
File metadata and controls
71 lines (69 loc) · 3.13 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
70
71
int readAO2Ds(const char* filename = "AO2D.root")
{
int retCode = 0;
TFile* f = new TFile(filename);
int nkeysfile = f->GetNkeys();
TList* lkeysfile = f->GetListOfKeys();
std::vector<int> vectNEntriesPerDF;
int nDFs = 0;
for (int ik = 0; ik < nkeysfile; ++ik) {
TKey* k = (TKey*)lkeysfile->At(ik);
TString cnameKeyInFile = k->GetClassName();
TString onameKeyInFile = k->GetName();
if (cnameKeyInFile != "TDirectoryFile" && !onameKeyInFile.BeginsWith("DF_")) {
continue;
}
++nDFs;
TDirectoryFile* d = (TDirectoryFile*)f->Get(onameKeyInFile.Data());
int nkeysdir = d->GetNkeys();
vectNEntriesPerDF.push_back(nkeysdir);
std::cout << "\nDirectory = " << onameKeyInFile.Data() << " has " << nkeysdir << " tables:" << std::endl;
TList* lkeysdir = d->GetListOfKeys();
std::vector<std::pair<std::string, int>> vectNEntriesPerTree;
for (int ikdir = 0; ikdir < nkeysdir; ++ikdir) {
TKey* kdir = (TKey*)lkeysdir->At(ikdir);
TString cnameKeyInDir = kdir->GetClassName();
TString onameKeyInDir = kdir->GetName();
if (cnameKeyInDir != "TTree") {
continue;
}
if (ikdir < nkeysdir - 1) {
std::cout << onameKeyInDir.Data() << " ";
} else {
std::cout << onameKeyInDir.Data() << std::endl;
}
TTree* t = (TTree*)d->Get(onameKeyInDir.Data());
// Check that every branch has the same number of entries as the tree itself.
// A mismatch indicates a corrupted or truncated write.
long long treeEntries = t->GetEntries();
for (auto* b : *t->GetListOfBranches()) {
auto* br = (TBranch*)b;
if (br->GetEntries() != treeEntries) {
printf("MISMATCH %s/%s branch %s: tree=%lld branch=%lld\n",
onameKeyInFile.Data(), onameKeyInDir.Data(), br->GetName(), treeEntries, br->GetEntries());
retCode |= 4;
}
}
if (onameKeyInDir.BeginsWith("O2track") && !onameKeyInDir.Contains("O2tracked") && !onameKeyInDir.Contains("O2trackqa")) {
vectNEntriesPerTree.push_back({onameKeyInDir.Data(), t->GetEntries()});
}
}
if (all_of(vectNEntriesPerTree.begin(), vectNEntriesPerTree.end(), [&](std::pair<std::string, int> i) { return i.second == vectNEntriesPerTree[0].second; })) {
std::cout << "In current DF (" << onameKeyInFile.Data() << "), all tracks tables (starting with O2track) have the same number of entries!" << std::endl;
} else {
std::cout << "In current DF (" << onameKeyInFile.Data() << "), NOT all tracks tables (starting with O2track) have the same number of entries!" << std::endl;
retCode = 1;
}
for (auto& item : vectNEntriesPerTree) {
std::cout << "table " << item.first << " has " << item.second << " entries" << std::endl;
}
}
std::cout << "Number of DFs found in AOD file = " << nDFs << std::endl;
if (std::equal(vectNEntriesPerDF.begin() + 1, vectNEntriesPerDF.end(), vectNEntriesPerDF.begin())) {
std::cout << "All DFs have the same number of tables" << std::endl;
} else {
std::cout << "NOT all DFs have the same number of tables" << std::endl;
retCode = retCode + 2;
}
return retCode;
}