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