/
inflateTree_main.cpp
92 lines (75 loc) · 2.05 KB
/
inflateTree_main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include "TFile.h"
#include "TTree.h"
#include "TStopwatch.h"
#include <iostream>
void inflateTree(const char *name = "h42",
const char *in = "root://eospps.cern.ch///eos/ppsscratch/test/h1big.root",
const char *out = "/tmp/h1big.root", Int_t fact = 1)
{
TStopwatch sw;
sw.Start();
// Get the input tree from the input file
TFile *fin = TFile::Open(in);
if (!fin || fin->IsZombie()) {
Printf("inflateTree", "could not open input file: %s", in);
return;
}
TTree *tin = (TTree *) fin->Get(name);
if (!tin) {
Printf("inflateTree", "could not find tree '%s' in %s", name, in);
delete fin;
return;
}
Long64_t nin = tin->GetEntriesFast();
Printf("Input tree '%s' has %lld entries", name, nin);
// Create output file
TFile *fout = TFile::Open(out, "RECREATE", 0, 1);
if (!fout || fout->IsZombie()) {
Printf("inflateTree", "could not open input file: %s", in);
delete fin;
return;
}
// Clone the header of the initial tree
TTree *tout= (TTree *) tin->CloneTree(0);
tout->SetMaxTreeSize(19000000000);
// Duplicate all entries once
#if 0
Int_t nc = fact;
while (nc--) {
Printf("Writing copy %d ...", fact - nc);
tout->CopyEntries(tin);
}
#else
for (Long64_t i = 0; i < nin; ++i) {
if (tin->LoadTree(i) < 0) {
break;
}
tin->GetEntry(i);
Int_t nc = fact;
while (nc--) {
tout->Fill();
}
if (i > 0 && !(i%1000)) {
Printf("%d copies of %lld entries filled ...", fact, i);
}
}
#endif
// Finalize the writing out
tout->Write();
// print perf stats
sw.Stop();
std::cout << "Drawing. Realtime: " << sw.RealTime() << std::endl;
std::cout << "Drawing. Cputime : " << sw.CpuTime() << std::endl;
tin->PrintCacheStats();
// Close the files
fout->Close();
fin->Close();
// Cleanup
delete fout;
delete fin;
}
int main(int argc, char** argv){
//gDebug=0x02;
inflateTree("h42", argv[1]);
return 0;
}