]>
Commit | Line | Data |
---|---|---|
33438b4c | 1 | /** |
2 | * Create a file collection in a ROOT file | |
3 | * | |
4 | * @param dir Input directory | |
5 | * @param tN Tree name | |
6 | * @param pa File name pattern | |
7 | * @param mc If true, simulations | |
8 | * @param recursive Scan recursively | |
9 | * | |
10 | * @ingroup pwglf_forward_trains_helper | |
11 | */ | |
fdfd93b4 | 12 | void |
13 | CreateFileCollection(const TString& dir="/data/alice/data/ppb/LHC12g/pass1/188359/", | |
14 | const TString& tN="esdTree", | |
871d7b56 | 15 | const TString& pa="AliESD*", |
fdfd93b4 | 16 | Bool_t mc=false, |
17 | Bool_t recursive=false) | |
18 | ) | |
19 | { | |
871d7b56 | 20 | gROOT->LoadMacro("$ALICE_ROOT/PWGLF/FORWARD/trains/ChainBuilder.C+"); |
fdfd93b4 | 21 | |
871d7b56 CHC |
22 | UShort_t flags = 0; |
23 | if (recursive) flags |= ChainBuilder::kRecursive; | |
24 | if (mc) flags |= ChainBuilder::kMC; | |
25 | UShort_t type = ChainBuilder::CheckSource(dir, flags); | |
a19faec0 | 26 | Info("", "type=%d, dir=%s tN=%s pa=%s, flags=0x%x", type, |
27 | dir.Data(), tN.Data(), pa.Data(), flags); | |
871d7b56 | 28 | TChain* chain = ChainBuilder::Create(type, dir, tN, pa, flags); |
fdfd93b4 | 29 | if (!chain) { |
30 | Error("CreateFileCollection", "Failed to make chain"); | |
31 | return; | |
32 | } | |
33 | Int_t port; | |
34 | TString host; | |
35 | { | |
36 | TUrl u(Form("root://%s//foo", gSystem->HostName())); | |
37 | port = u.GetPort() * 10; | |
38 | host = u.GetHostFQDN(); | |
39 | } | |
40 | ||
41 | ||
42 | TFileCollection* fc = new TFileCollection("files"); | |
43 | TObjArray* cEs = chain->GetListOfFiles(); | |
44 | TChainElement* cE = 0; | |
45 | TIter next(cEs); | |
46 | while ((cE= static_cast<TChainElement*>(next()))) { | |
47 | TString fN(cE->GetTitle()); | |
48 | TFile* f = TFile::Open(fN, "READ"); | |
49 | TTree* t = static_cast<TTree*>(f->Get(tN)); | |
50 | ||
51 | fN.Prepend(Form("root://%s:%d/", host.Data(), port)); | |
52 | TFileInfo* fi = new TFileInfo(Form("%s tree:%s,%d", | |
53 | fN.Data(), tN.Data(), t->GetEntries()), | |
54 | f->GetSize()); | |
55 | f->Close(); | |
56 | fc->Add(fi); | |
57 | } | |
58 | fc->Print("F"); | |
59 | ||
60 | TFile* files = TFile::Open("files.root", "RECREATE"); | |
61 | fc->Write(); | |
62 | files->Close(); | |
63 | ||
64 | } | |
33438b4c | 65 | // |
66 | // EOF | |
67 | // |