1 #include "AliHistoListWrapper.h"
6 #include "AliESDInputHandlerRP.h"
7 #include "AliAnalysisManager.h"
9 #include "AliMultiplicity.h"
11 ClassImp(AliHistoListWrapper)
13 AliHistoListWrapper::AliHistoListWrapper():
23 AliHistoListWrapper::AliHistoListWrapper(const char* name, const char* title):
24 TNamed(name,title), fList(0)
33 AliHistoListWrapper::AliHistoListWrapper(const AliHistoListWrapper& obj) :
41 AliHistoListWrapper::~AliHistoListWrapper() {
50 Long64_t AliHistoListWrapper::Merge(TCollection* list)
52 // Merge a list of AliHistoListWrapper objects with this.
53 // Returns the number of merged objects (including this).
55 // We have to make sure that all the list contain the same histos in
56 // the same order. We thus also have to sort the list (sorting is
57 // done by name in TList).
59 // AliInfo("Merging");
67 TIterator* iter = list->MakeIterator();
70 // collections of all histograms
75 while ((obj = iter->Next())) {
76 Bool_t foundDiffinThisIterStep = kFALSE;
78 // Printf("%d - %s",count, obj->GetName());
79 AliHistoListWrapper* entry = dynamic_cast<AliHistoListWrapper*> (obj);
83 TList * hlist = entry->fList;
85 // Check if all histos in this fList are also in the one from entry and viceversa
86 // Use getters to automatically book non defined histos
88 Bool_t areListsDifferent=kTRUE;
90 Int_t max_loops = hlist->GetSize() + fList->GetSize(); // In the worst case all of the histos will be different...
91 while(areListsDifferent) {
92 if(iloop>max_loops) AliFatal("Infinite Loop?");
97 // loop over the largest
99 TIterator * iterlist = 0;
100 TList * thislist = 0; // the list over which I'm iterating
101 TList * otherlist = 0; // the other
103 if (hlist->GetSize() >= fList->GetSize()) {
111 iterlist = thislist->MakeIterator();
113 while ((hist= iterlist->Next())){
114 if(!otherlist->FindObject(hist->GetName())){
115 AliInfo(Form("Adding object %s",hist->GetName()));
116 TH1 * hclone = (TH1*) hist->Clone();
117 if (!hclone->InheritsFrom("TH1")) AliFatal(Form("Found a %s. This class only supports objects inheriting from TH1",hclone->ClassName()));
119 otherlist->Add(hclone);
120 foundDiffinThisIterStep=kTRUE;
124 // re-sort before checking
128 // check if everything is fine
129 areListsDifferent=kFALSE;
130 if (hlist->GetSize() == fList->GetSize()) {
131 Int_t nhist = fList->GetSize();
132 for(Int_t ihist = 0; ihist < nhist; ihist++){
133 if(strcmp(fList->At(ihist)->GetName(),hlist->At(ihist)->GetName())) areListsDifferent = kTRUE;
136 areListsDifferent=kTRUE;
140 // last check: if something is not ok die loudly
141 if (hlist->GetSize() != fList->GetSize()) {
142 AliFatal("Mismatching size!");
144 Int_t nhist = fList->GetSize();
145 for(Int_t ihist = 0; ihist < nhist; ihist++){
146 if(strcmp(fList->At(ihist)->GetName(),hlist->At(ihist)->GetName())){
147 AliFatal(Form("Mismatching histos: %s -> %s", fList->At(ihist)->GetName(),hlist->At(ihist)->GetName()));
151 if (foundDiffinThisIterStep){
152 iter->Reset(); // We found a difference: previous lists could
153 // also be affected... We start from scratch
159 collections.Add(hlist);
165 fList->Merge(&collections);
173 AliHistoListWrapper& AliHistoListWrapper::operator=(const AliHistoListWrapper& wrap) {
175 // Assignment operator
180 TIterator* iter = wrap.fList->MakeIterator();
183 while ((obj = iter->Next())) {
184 fList->Add(obj->Clone());