]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGLF/FORWARD/trains/CreateFileCollection.C
Merge branch 'master' of https://git.cern.ch/reps/AliRoot
[u/mrichter/AliRoot.git] / PWGLF / FORWARD / trains / CreateFileCollection.C
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  */
12 void
13 CreateFileCollection(const TString& dir="/data/alice/data/ppb/LHC12g/pass1/188359/",
14                      const TString& tN="esdTree", 
15                      const TString& pa="AliESD*", 
16                      Bool_t mc=false, 
17                      Bool_t recursive=false)
18 )
19 {
20   gROOT->LoadMacro("$ALICE_ROOT/PWGLF/FORWARD/trains/ChainBuilder.C+");
21   
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);
26   Info("", "type=%d", type);
27   TChain* chain = ChainBuilder::Create(type, dir, tN, pa, flags);
28   if (!chain) { 
29     Error("CreateFileCollection", "Failed to make chain");
30     return;
31   }
32   Int_t port;
33   TString host;
34   { 
35     TUrl u(Form("root://%s//foo", gSystem->HostName()));
36     port = u.GetPort() * 10;
37     host = u.GetHostFQDN();
38   }
39   
40
41   TFileCollection* fc  = new TFileCollection("files");
42   TObjArray*       cEs = chain->GetListOfFiles();
43   TChainElement*   cE  = 0;
44   TIter            next(cEs);
45   while ((cE= static_cast<TChainElement*>(next()))) {
46     TString fN(cE->GetTitle());
47     TFile* f = TFile::Open(fN, "READ");
48     TTree* t = static_cast<TTree*>(f->Get(tN));
49     
50     fN.Prepend(Form("root://%s:%d/", host.Data(), port));
51     TFileInfo* fi = new TFileInfo(Form("%s tree:%s,%d", 
52                                        fN.Data(), tN.Data(), t->GetEntries()),
53                                   f->GetSize());
54     f->Close();
55     fc->Add(fi);
56   }
57   fc->Print("F");
58   
59   TFile* files = TFile::Open("files.root", "RECREATE");
60   fc->Write();
61   files->Close();
62   
63 }
64 //
65 // EOF
66 //