]>
Commit | Line | Data |
---|---|---|
c5e33610 | 1 | // |
2 | // Class AliMixInputHandlerInfo | |
3 | // | |
4 | // AliMixInputHandlerInfo is interface with mixed | |
5 | // input handlers | |
6 | // | |
7 | // author: | |
8 | // Martin Vala (martin.vala@cern.ch) | |
9 | // | |
10 | #include <TTree.h> | |
11 | #include <TChain.h> | |
12 | #include <TFile.h> | |
13 | #include <TChainElement.h> | |
14 | ||
15 | #include "AliLog.h" | |
16 | #include "AliInputEventHandler.h" | |
17 | ||
18 | #include "AliMixInputHandlerInfo.h" | |
19 | ||
20 | ClassImp(AliMixInputHandlerInfo) | |
21 | ||
22 | //_____________________________________________________________________________ | |
23 | AliMixInputHandlerInfo::AliMixInputHandlerInfo(const char* name, const char* title): TNamed(name, title), | |
24 | fChain(0), | |
25 | fChainEntriesArray(), | |
26 | fZeroEntryNumber(0), | |
27 | fNeedNotify(kFALSE) { | |
28 | // | |
29 | // Default constructor. | |
30 | // | |
31 | } | |
32 | //_____________________________________________________________________________ | |
33 | AliMixInputHandlerInfo::~AliMixInputHandlerInfo() { | |
34 | // | |
35 | // Destructor | |
36 | // | |
37 | if (fChain) delete fChain; | |
38 | } | |
39 | ||
40 | //_____________________________________________________________________________ | |
41 | TChain* AliMixInputHandlerInfo::GetChain() { | |
42 | // | |
43 | // Returns curren chain. When chain is null it will create it | |
44 | // | |
45 | if (!fChain) fChain = new TChain(GetName()); | |
46 | return fChain; | |
47 | } | |
48 | ||
49 | //_____________________________________________________________________________ | |
50 | void AliMixInputHandlerInfo::AddChain(TChain* chain) { | |
51 | // | |
52 | // Add chain | |
53 | // | |
54 | AliDebug(AliLog::kDebug, "<-"); | |
55 | ||
56 | if (!chain) return; | |
57 | ||
58 | if (fChain) delete fChain; | |
59 | fChain = new TChain(GetName()); | |
60 | fChain->Add(chain); | |
61 | ||
62 | AliDebug(AliLog::kDebug, "->"); | |
63 | } | |
64 | ||
65 | //_____________________________________________________________________________ | |
66 | void AliMixInputHandlerInfo::AddTreeToChain(TTree *tree) { | |
67 | // | |
68 | // Adds tree to chain | |
69 | // | |
70 | AliDebug(AliLog::kDebug, Form("%s %lld", tree->GetCurrentFile()->GetName(), tree->GetEntries())); | |
71 | ||
72 | GetChain(); | |
73 | fChain->AddFile(tree->GetCurrentFile()->GetName()); | |
74 | ||
75 | ||
76 | fChainEntriesArray.Set(fChain->GetListOfFiles()->GetEntries()); | |
77 | ||
78 | AliDebug(AliLog::kDebug, Form("Adding %lld to id %d", tree->GetEntries(), fChain->GetListOfFiles()->GetEntries() - 1)); | |
79 | fChainEntriesArray.AddAt(tree->GetEntries(), fChain->GetListOfFiles()->GetEntries() - 1); | |
80 | ||
81 | } | |
82 | ||
83 | //_____________________________________________________________________________ | |
84 | TChainElement* AliMixInputHandlerInfo::GetEntryInTree(Long64_t& entry) { | |
85 | // | |
86 | // Get entry in current tree | |
87 | // | |
88 | fZeroEntryNumber = 0; | |
89 | if (entry < fZeroEntryNumber) { | |
90 | AliError(Form("Num %lld is less then ZeroEntryNumber(%lld)", entry, fZeroEntryNumber)); | |
91 | entry = -1; | |
92 | return 0; | |
93 | } | |
94 | ||
95 | Long64_t sumTree = fZeroEntryNumber; | |
96 | for (Int_t i = 0;i < fChainEntriesArray.GetSize() ;i++) { | |
97 | sumTree += fChainEntriesArray.At(i); | |
98 | if (sumTree > entry) { | |
99 | sumTree = entry - sumTree + fChainEntriesArray.At(i); | |
100 | AliDebug(AliLog::kDebug, Form("Entry in current tree num is %lld with i=%d", sumTree, i)); | |
101 | ||
102 | entry = sumTree; | |
103 | TChainElement *chEl = (TChainElement*) fChain->GetListOfFiles()->At(i); | |
104 | AliDebug(AliLog::kDebug, Form("Real filename is %s %s", chEl->GetName(), chEl->GetTitle())); | |
105 | ||
106 | AliDebug(AliLog::kDebug, Form("And filename is %s %lld", fChain->GetTree()->GetCurrentFile()->GetName(), fChain->GetEntries())); | |
107 | return chEl; | |
108 | } | |
109 | } | |
110 | ||
111 | entry = -1; | |
112 | return 0; | |
113 | } | |
114 | ||
115 | //_____________________________________________________________________________ | |
116 | void AliMixInputHandlerInfo::PrepareEntry(TChainElement *te, Long64_t entry, AliInputEventHandler *eh) { | |
117 | // | |
118 | // Prepare Entry | |
119 | // | |
120 | if (!te) return; | |
121 | ||
122 | if (te) { | |
123 | if (entry < 0) { | |
124 | AliDebug(AliLog::kDebug, Form("We are creating new chain from file %s ...", te->GetTitle())); | |
125 | if (!fChain) { | |
126 | fChain = new TChain(te->GetName()); | |
127 | fChain->AddFile(te->GetTitle()); | |
128 | fChain->GetEntry(0); | |
129 | eh->Init(fChain->GetTree(), "proof"); | |
130 | // eh->Notify(te->GetTitle()); | |
131 | } | |
132 | fNeedNotify = kTRUE; | |
133 | return; | |
134 | } | |
135 | ||
136 | } | |
137 | ||
138 | if (fChain) { | |
139 | AliDebug(AliLog::kDebug, Form("Filename is %s", fChain->GetCurrentFile()->GetName())); | |
140 | TString fn = fChain->GetCurrentFile()->GetName(); | |
141 | if (fn.CompareTo(te->GetTitle())) { | |
142 | AliDebug(AliLog::kDebug, Form("Filename %s is NOT same ...", te->GetTitle())); | |
143 | AliDebug(AliLog::kDebug, Form("We are changing to file %s ...", te->GetTitle())); | |
144 | // change file | |
145 | delete fChain; | |
146 | fChain = new TChain(te->GetName()); | |
147 | fChain->AddFile(te->GetTitle()); | |
148 | fChain->GetEntry(0); | |
149 | eh->Init(fChain->GetTree(), "proof"); | |
150 | ||
151 | eh->Notify(te->GetTitle()); | |
152 | eh->BeginEvent(entry); | |
153 | fChain->GetEntry(entry); | |
154 | fNeedNotify = kFALSE; | |
155 | } else { | |
156 | AliDebug(AliLog::kDebug, Form("We are reusing file %s ...", te->GetTitle())); | |
157 | if (fNeedNotify) eh->Notify(te->GetTitle()); | |
158 | fNeedNotify = kFALSE; | |
159 | AliDebug(AliLog::kDebug, Form("Entry is %lld + GetEntries %lld ...", entry, fChain->GetEntries())); | |
160 | eh->BeginEvent(entry); | |
161 | fChain->GetEntry(entry); | |
162 | // file is in tree fChain already | |
163 | } | |
164 | } | |
165 | ||
166 | AliDebug(AliLog::kDebug, Form("We are USING file %s ...", te->GetTitle())); | |
167 | AliDebug(AliLog::kDebug, Form("We are USING file from fChain->GetTree() %s ...", fChain->GetTree()->GetCurrentFile()->GetName())); | |
168 | ||
169 | // here we have correct chain with 1 tree only | |
170 | AliDebug(AliLog::kDebug, Form("Entry is %lld ...", entry)); | |
171 | ||
172 | } |