2 // Class AliMixInputHandlerInfo
4 // AliMixInputHandlerInfo is interface with mixed
8 // Martin Vala (martin.vala@cern.ch)
13 #include <TChainElement.h>
16 #include "AliInputEventHandler.h"
18 #include "AliMixInputHandlerInfo.h"
20 ClassImp(AliMixInputHandlerInfo)
22 //_____________________________________________________________________________
23 AliMixInputHandlerInfo::AliMixInputHandlerInfo(const char *name, const char *title): TNamed(name, title),
30 // Default constructor.
33 //_____________________________________________________________________________
34 AliMixInputHandlerInfo::~AliMixInputHandlerInfo()
39 if (fChain) delete fChain;
42 //_____________________________________________________________________________
43 TChain *AliMixInputHandlerInfo::GetChain()
46 // Returns curren chain. When chain is null it will create it
48 if (!fChain) fChain = new TChain(GetName());
52 //_____________________________________________________________________________
53 void AliMixInputHandlerInfo::AddChain(TChain *chain)
58 AliDebug(AliLog::kDebug + 5, "<-");
60 if (fChain) delete fChain;
61 fChain = new TChain(GetName());
63 AliDebug(AliLog::kDebug + 5, "->");
66 //_____________________________________________________________________________
67 void AliMixInputHandlerInfo::AddTreeToChain(const char *path)
70 // Adds tree in to chain
72 AliDebug(AliLog::kDebug + 5, Form("<- %s", path));
74 fChain->AddFile(path);
75 AliDebug(AliLog::kDebug + 3, Form("Num files in fChain %d", fChain->GetListOfFiles()->GetEntries()));
76 Long64_t sumTree = fZeroEntryNumber;
77 for (Int_t i = 0; i < fChainEntriesArray.GetSize() ; i++) sumTree += fChainEntriesArray.At(i);
78 fChain->LoadTree(sumTree);
79 Int_t lastIndex = fChain->GetListOfFiles()->GetEntries();
80 AliDebug(AliLog::kDebug + 3, Form("Num files in fChain %d", lastIndex));
81 fChainEntriesArray.Set(lastIndex);
82 AliDebug(AliLog::kDebug + 3, Form("Adding %lld to id %d", fChain->GetTree()->GetEntries(), lastIndex - 1));
83 fChainEntriesArray.AddAt((Int_t)fChain->GetTree()->GetEntries(), (Int_t)lastIndex - 1);
84 AliDebug(AliLog::kDebug + 5, Form("-> %s", path));
87 //_____________________________________________________________________________
88 TChainElement *AliMixInputHandlerInfo::GetEntryInTree(Long64_t &entry)
91 // Get entry in current tree
93 AliDebug(AliLog::kDebug + 5, Form("<- %lld", entry));
95 if (entry < fZeroEntryNumber) {
96 AliError(Form("Num %lld is less then ZeroEntryNumber(%lld)", entry, fZeroEntryNumber));
98 AliDebug(AliLog::kDebug + 5, "->");
101 Long64_t sumTree = fZeroEntryNumber;
102 for (Int_t i = 0; i < fChainEntriesArray.GetSize() ; i++) {
103 sumTree += fChainEntriesArray.At(i);
104 if (sumTree > entry) {
105 sumTree = entry - sumTree + fChainEntriesArray.At(i);
106 AliDebug(AliLog::kDebug + 1, Form("Entry in current tree num is %lld with i=%d", sumTree, i));
108 AliDebug(AliLog::kDebug + 5, "->");
109 return (TChainElement *) fChain->GetListOfFiles()->At(i);
113 AliDebug(AliLog::kDebug + 5, "->");
117 //_____________________________________________________________________________
118 void AliMixInputHandlerInfo::PrepareEntry(TChainElement *te, Long64_t entry, AliInputEventHandler *eh, Option_t *opt)
123 AliDebug(AliLog::kDebug + 5, Form("<- %lld", entry));
125 AliDebug(AliLog::kDebug + 5, "-> te is null");
129 AliDebug(AliLog::kDebug, Form("We are creating new chain from file %s ...", te->GetTitle()));
131 fChain = new TChain(te->GetName());
132 fChain->AddFile(te->GetTitle());
135 eh->Init(fChain->GetTree(), opt);
138 AliDebug(AliLog::kDebug + 5, "->");
142 AliDebug(AliLog::kDebug, Form("Filename is %s", fChain->GetTree()->GetCurrentFile()->GetName()));
143 TString fn = fChain->GetTree()->GetCurrentFile()->GetName();
144 if (fn.CompareTo(te->GetTitle())) {
145 AliDebug(AliLog::kDebug, Form("Filename %s is NOT same ...", te->GetTitle()));
146 AliDebug(AliLog::kDebug, Form("We are changing to file %s ...", te->GetTitle()));
149 fChain = new TChain(te->GetName());
150 fChain->AddFile(te->GetTitle());
153 eh->Init(fChain->GetTree(), opt);
154 eh->Notify(te->GetTitle());
155 fChain->GetEntry(entry);
156 eh->BeginEvent(entry);
157 fNeedNotify = kFALSE;
159 AliDebug(AliLog::kDebug, Form("We are reusing file %s ...", te->GetTitle()));
160 if (fNeedNotify) eh->Notify(te->GetTitle());
161 fNeedNotify = kFALSE;
162 AliDebug(AliLog::kDebug, Form("Entry is %lld fChain->GetEntries %lld ...", entry, fChain->GetEntries()));
163 fChain->GetEntry(entry);
164 eh->BeginEvent(entry);
165 // file is in tree fChain already
168 AliDebug(AliLog::kDebug, Form("We are USING file %s ...", te->GetTitle()));
169 AliDebug(AliLog::kDebug, Form("We are USING file from fChain->GetTree() %s ...", fChain->GetTree()->GetCurrentFile()->GetName()));
170 // here we have correct chain with 1 tree only
171 AliDebug(AliLog::kDebug + 5, "->");
174 //_____________________________________________________________________________
175 Long64_t AliMixInputHandlerInfo::GetEntries()
178 // Returns number of entries
180 if (fChain) return fChain->GetEntries();