8#include "InputDataInfo.h"
11#include <TCollection.h>
12#include <TDirectoryFile.h>
18#include <initializer_list>
31 if (file.EndsWith(
".list")) {
32 auto vec = Hal::Std::GetLinesFromFile(file, kTRUE);
33 fFileNames.push_back(vec);
34 }
else if (file.EndsWith(
".xml")) {
35 XMLFile xmlFile(file);
36 auto root = xmlFile.GetRootNode();
37 auto files = root->GetChild(
"files");
38 for (int i = 0; i < files->GetNChildren(); i++) {
39 auto list = files->GetChild(i);
40 fFileNames.push_back(std::vector<TString>());
41 for (int j = 0; j < list->GetNChildren(); i++) {
42 fFileNames[i].push_back(list->GetChild(j)->GetValue());
47 fFileNames[0].push_back(file);
51 InputDataInfo::InputDataInfo(std::initializer_list<TString> fileLists) {
52 fListName = Form(
"initializer_list");
53 for (
auto file : fileLists) {
54 fFileNames.push_back(Hal::Std::GetLinesFromFile(file, kTRUE));
58 InputDataInfo::InputDataInfo(std::vector<std::vector<TString>> files) {
59 fListName = Form(
"2d vector");
63 TString InputDataInfo::GetSafeFile(Int_t level, Int_t entry)
const {
64 if (level + 1 < fFileNames.size()) {
65 if (fFileNames[level + 1].size() > entry)
return fFileNames[level + 1][entry];
70 std::vector<TString> InputDataInfo::GetSafeFiles(Int_t level)
const {
71 if (level + 1 < fFileNames.size()) {
return fFileNames[level + 1]; }
72 return std::vector<TString>();
75 void InputDataInfo::AddFile(TString file) { AddFriend(file, -1); }
77 void InputDataInfo::AddFriend(TString file, Int_t level) {
78 if (fFileNames.size() < level + 2) { fFileNames.resize(level + 2); }
79 fFileNames[level + 1].push_back(file);
82 Int_t InputDataInfo::GetNFiles()
const {
83 if (fFileNames.size() == 0)
return -1;
84 return fFileNames[0].size();
87 Int_t InputDataInfo::GetFriendsLevel()
const {
return fFileNames.size() - 1; }
89 TString InputRootDataInfo::GetChainName(TString file)
const {
90 TFile* ftemp =
new TFile(file);
91 auto list = (TList*) ftemp->GetListOfKeys();
92 for (
int i = 0; i < list->GetEntries(); i++) {
93 TString keyName = ((TKey*) list->At(i))->GetName();
94 auto tree =
dynamic_cast<TTree*
>(ftemp->Get(keyName));
106 void InputRootDataInfo::GuessTrees() {
107 for (
auto& list : fFileNames) {
108 if (Hal::Std::FileExists(list[0]))
109 fTreeNames.push_back(GetChainName(list[0]));
112 fTreeNames.push_back(
" ");
117 InputRootDataInfo::InputRootDataInfo(TString file, TString treename) :
InputDataInfo(file) {
118 if (treename.Length() != 0) {
119 fTreeNames.push_back(treename);
122 if (file.EndsWith(
".xml")) {
123 XMLFile xmlFile(file);
124 auto root = xmlFile.GetRootNode();
125 auto files = root->GetChild(
"files");
126 auto treenames = root->GetChild(
"treenames");
128 for (int i = 0; i < treenames->GetNChildren(); i++) {
129 fTreeNames.push_back(treenames->GetChild(i)->GetValue());
137 if (treeNames.size() != 0) { fTreeNames = Hal::Std::GetVector(treeNames); }
143 if (fChain)
return fChain;
144 if (fTreeNames.size() == 0) { GuessTrees(); }
145 fChain =
new TChain(fTreeNames[0]);
146 for (
auto name : fFileNames[0])
147 fChain->AddFile(name);
148 int entries = fChain->GetEntries();
149 for (
unsigned int i = 1; i < fFileNames.size(); i++) {
150 TChain* minichain =
new TChain(fTreeNames[i]);
151 for (
auto friendName : fFileNames[i])
152 minichain->AddFile(friendName);
153 fChain->AddFriend(minichain);
154 if (minichain->GetEntries() != entries) {
155 Hal::Cout::PrintInfo(
"Warning different number of entries detected in ChainBuilder", Hal::EInfo::kError);
161 void InputDataInfo::Print(Option_t* option)
const {
162 std::vector<TString> header;
163 header.push_back(
"No");
164 header.push_back(
"Main file");
165 for (
int i = 1; i < fFileNames.size(); i++) {
166 header.push_back(Form(
"Friend_%i", i - 1));
170 for (
unsigned int pos = 0; pos < fFileNames[0].size(); pos++) {
171 std::vector<TString> str;
172 str.push_back(Form(
"%i", pos));
173 for (
unsigned int level = 0; level < fFileNames.size(); level++) {
174 if (fFileNames[level].size() > pos) {
175 TString path = fFileNames[level][pos];
176 if (path.Length() > 25) {
177 int crop = path.Length() - 25;
178 path = TString(path(crop, path.Length()));
179 path = Form(
"..%s", path.Data());
191 void InputRootDataInfo::Print(Option_t* option)
const {
192 std::vector<TString> header;
193 header.push_back(
"No");
194 header.push_back(
"Main file");
195 for (
unsigned int i = 1; i < fFileNames.size(); i++) {
196 header.push_back(Form(
"Friend_%i", i - 1));
200 std::vector<TString> line;
201 line.push_back(
"Tree names:");
202 for (
auto tree : fTreeNames) {
203 line.push_back(tree);
206 for (
unsigned int pos = 0; pos < fFileNames[0].size(); pos++) {
207 std::vector<TString> str;
208 str.push_back(Form(
"%i", pos));
209 for (
unsigned int level = 0; level < fFileNames.size(); level++) {
210 if (fFileNames[level].size() > pos) {
211 TString path = fFileNames[level][pos];
212 if (path.Length() > 25) {
213 int crop = path.Length() - 25;
214 path = TString(path(crop, path.Length()));
215 path = Form(
"..%s", path.Data());
static void SetLineLenght(Int_t lenght)
static void PrintInfo(TString text, Hal::EInfo status)
static void Database(Int_t no...)