|
| 1 | +// Checks which strangeness tables (and which versions) are present in a derived AO2D |
| 2 | +// and reports which steps of the V0 tutorial (o2-analysistutorial-lf-strangeness-derived-v0-*) can run. |
| 3 | +// |
| 4 | +// Usage: root -l -b -q 'checkTables.C("data/AO2D.root")' or something like root -l -b -q "checkTables.C(\"$(cat input_data.txt)\")" |
| 5 | + |
| 6 | +#include <TDirectory.h> |
| 7 | +#include <TFile.h> |
| 8 | +#include <TKey.h> |
| 9 | +#include <TString.h> |
| 10 | + |
| 11 | +#include <algorithm> |
| 12 | +#include <iostream> |
| 13 | +#include <string> |
| 14 | +#include <vector> |
| 15 | + |
| 16 | +struct RequiredTable { |
| 17 | + std::string base; // tree name without version, e.g. "o2straevsels" |
| 18 | + int version; // version required by the current O2Physics data model |
| 19 | + int firstStep; // first step that uses it (-1 = skeleton) |
| 20 | + std::string hint; // converter to use if the version in the file is older |
| 21 | +}; |
| 22 | + |
| 23 | +int findVersion(TDirectory* dir, const std::string& base) |
| 24 | +{ |
| 25 | + int found = -1; |
| 26 | + TIter next(dir->GetListOfKeys()); |
| 27 | + while (TKey* key = static_cast<TKey*>(next())) { |
| 28 | + TString name = key->GetName(); |
| 29 | + name.ToLower(); |
| 30 | + if (name == base.c_str()) { |
| 31 | + found = std::max(found, 0); |
| 32 | + } else if (name.BeginsWith((base + "_").c_str())) { |
| 33 | + TString v = name(base.size() + 1, name.Length()); |
| 34 | + if (v.IsDigit()) { |
| 35 | + found = std::max(found, v.Atoi()); |
| 36 | + } |
| 37 | + } |
| 38 | + } |
| 39 | + return found; |
| 40 | +} |
| 41 | + |
| 42 | +void checkTables(const char* fname = "data/AO2D.root") |
| 43 | +{ |
| 44 | + const std::vector<RequiredTable> required = { |
| 45 | + {"o2stracollision", 0, -1, ""}, |
| 46 | + {"o2straevsels", 6, -1, "o2-analysis-lf-straevselsconverterN (chain up to straevselsconverter6)"}, |
| 47 | + {"o2v0core", 0, 0, ""}, |
| 48 | + {"o2v0extra", 0, 2, ""}, |
| 49 | + {"o2dautrackextra", 3, 2, "o2-analysis-lf-stradautracksextraconverterN (up to stradautracksextraconverter3)"}, |
| 50 | + {"o2dautracktpcpid", 1, 2, "o2-analysis-lf-stradautrackstpcpidconverter"}, |
| 51 | + // step 3: tables read as input by the helper task strangenesstofpid, |
| 52 | + // not by the analysis itself: the tutorial only uses V0s |
| 53 | + {"o2strastamps", 1, 3, "o2-analysis-lf-strastampsconverter"}, |
| 54 | + {"o2straevtimes", 1, 3, "o2-analysis-lf-stradautrackstofpidconverter3"}, |
| 55 | + {"o2dautracktofpid", 3, 3, "o2-analysis-lf-stradautrackstofpidconverterN (up to stradautrackstofpidconverter4)"}, |
| 56 | + {"o2v0collref", 0, 3, ""}, |
| 57 | + {"o2casccore", 0, 3, ""}, |
| 58 | + {"o2cascextra", 0, 3, ""}, |
| 59 | + {"o2casccollref", 0, 3, ""}, |
| 60 | + // step 4: MC |
| 61 | + {"o2v0coremclabel", 0, 4, ""}, |
| 62 | + {"o2v0mccore", 2, 4, "o2-analysis-lf-v0coresconverter / v0coresconverter2"}, |
| 63 | + {"o2v0mccollref", 0, 4, ""}, |
| 64 | + {"o2stracolllabels", 0, 4, ""}, |
| 65 | + {"o2stramccollision", 2, 4, "o2-analysis-lf-stramccollisionconverter / stramccollisionconverter2"}, |
| 66 | + }; |
| 67 | + |
| 68 | + TFile* f = TFile::Open(fname); |
| 69 | + if (!f || f->IsZombie()) { |
| 70 | + std::cout << "Cannot open " << fname << std::endl; |
| 71 | + return; |
| 72 | + } |
| 73 | + TDirectory* df = nullptr; |
| 74 | + TIter next(f->GetListOfKeys()); |
| 75 | + while (TKey* key = static_cast<TKey*>(next())) { |
| 76 | + if (TString(key->GetName()).BeginsWith("DF_")) { |
| 77 | + df = f->GetDirectory(key->GetName()); |
| 78 | + break; |
| 79 | + } |
| 80 | + } |
| 81 | + if (!df) { |
| 82 | + std::cout << "No DF_* folder in " << fname << std::endl; |
| 83 | + return; |
| 84 | + } |
| 85 | + |
| 86 | + std::cout << "\nTrees in " << df->GetName() << ":\n"; |
| 87 | + TIter nextTree(df->GetListOfKeys()); |
| 88 | + while (TKey* key = static_cast<TKey*>(nextTree())) { |
| 89 | + std::cout << " " << key->GetName() << "\n"; |
| 90 | + } |
| 91 | + |
| 92 | + int firstBrokenStep = 99; // first step that cannot run, even with converters |
| 93 | + int firstConverterStep = 99; // first step that needs converters |
| 94 | + std::cout << "\nTables required by the tutorial:\n"; |
| 95 | + for (const auto& t : required) { |
| 96 | + int v = findVersion(df, t.base); |
| 97 | + TString status = "ok"; |
| 98 | + if (v < 0) { |
| 99 | + status = "MISSING"; |
| 100 | + firstBrokenStep = std::min(firstBrokenStep, t.firstStep); |
| 101 | + } else if (v < t.version) { |
| 102 | + status = Form("v%d < v%d required", v, t.version); |
| 103 | + firstConverterStep = std::min(firstConverterStep, t.firstStep); |
| 104 | + } else if (v > t.version) { |
| 105 | + status = Form("v%d > v%d: O2Physics is older than the data, update it", v, t.version); |
| 106 | + firstBrokenStep = std::min(firstBrokenStep, t.firstStep); |
| 107 | + } |
| 108 | + TString step = t.firstStep < 0 ? "skeleton" : Form("step%d", t.firstStep); |
| 109 | + std::cout << Form(" %-20s (from %-8s) %s", t.base.c_str(), step.Data(), status.Data()); |
| 110 | + if (status != "ok" && !t.hint.empty() && v >= 0) { |
| 111 | + std::cout << "\n -> " << t.hint; |
| 112 | + } |
| 113 | + std::cout << "\n"; |
| 114 | + } |
| 115 | + |
| 116 | + std::cout << "\nSummary:\n"; |
| 117 | + for (int s = -1; s <= 4; s++) { |
| 118 | + TString name = s < 0 ? "skeleton" : Form("step%d", s); |
| 119 | + TString res = s >= firstBrokenStep ? "CANNOT run with this file" |
| 120 | + : s >= firstConverterStep ? "ok, but converters are needed" |
| 121 | + : "ok"; |
| 122 | + std::cout << Form(" %-8s %s\n", name.Data(), res.Data()); |
| 123 | + } |
| 124 | + std::cout << std::endl; |
| 125 | + f->Close(); |
| 126 | +} |
0 commit comments