1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
16 // $Id: AliMergeableCollection.cxx 50593 2011-07-14 17:42:28Z martinez $
19 /// A mergeable object container.
21 /// For each tuple (key1,key2,..,keyN) a (hash)list of mergeable objects is associated.
22 /// Note that key1, key2 (optional), ..., keyN (optional) are strings.
23 /// Those strings should not contain "/" themselves.
25 /// More helper functions might be added in the future (e.g. Project, etc...)
27 #include "AliMergeableCollection.h"
29 ClassImp(AliMergeableCollection)
32 #include "Riostream.h"
34 #include "THashList.h"
37 #include "TObjArray.h"
38 #include "TObjString.h"
45 //_____________________________________________________________________________
46 AliMergeableCollection::AliMergeableCollection(const char* name, const char* title)
47 : TNamed(name,title), fMap(0x0), fMustShowEmptyObject(0), fMapVersion(0), fMessages()
52 //_____________________________________________________________________________
53 AliMergeableCollection::~AliMergeableCollection()
55 /// dtor. Note that the map is owner
56 if ( fMap ) fMap->DeleteAll();
60 //_____________________________________________________________________________
62 AliMergeableCollection::Adopt(TObject* obj)
64 /// Adopt a given object at top level (i.e. no key)
65 return InternalAdopt("",obj);
68 //_____________________________________________________________________________
70 AliMergeableCollection::Adopt(const char* identifier, TObject* obj)
72 /// Adopt a given object, and associate it with pair key
73 TString sidentifier(identifier);
74 if ( ! sidentifier.IsNull() ){
75 if ( ! sidentifier.EndsWith("/") ) sidentifier.Append("/");
76 if ( ! sidentifier.BeginsWith("/") ) sidentifier.Prepend("/");
78 return InternalAdopt(sidentifier.Data(),obj);
81 //_____________________________________________________________________________
82 void AliMergeableCollection::ClearMessages()
84 /// clear pending messages
88 //_____________________________________________________________________________
90 AliMergeableCollection::CreateIterator(Bool_t direction) const
92 /// Create an iterator (must be deleted by the client)
93 return fMap ? new AliMergeableCollectionIterator(this,direction) : 0x0;
96 //_____________________________________________________________________________
97 AliMergeableCollection*
98 AliMergeableCollection::Clone(const char* name) const
100 /// Clone this collection.
101 /// We loose the messages.
103 AliMergeableCollection* newone = new AliMergeableCollection(name,GetTitle());
105 newone->fMap = static_cast<TMap*>(fMap->Clone());
106 newone->fMustShowEmptyObject = fMustShowEmptyObject;
107 newone->fMapVersion = fMapVersion;
112 //_____________________________________________________________________________
114 AliMergeableCollection::Delete(Option_t*)
116 /// Delete all the objects
122 //_____________________________________________________________________________
124 AliMergeableCollection::FindObject(const char* fullIdentifier) const
126 /// Find an object by its full identifier.
128 return GetObject(fullIdentifier);
131 //_____________________________________________________________________________
133 AliMergeableCollection::FindObject(const TObject *object) const
136 AliWarning("This method is awfully inefficient. Please improve it or use FindObject(const char*)");
137 TIter next(CreateIterator());
139 while ( ( obj=next() ) )
141 if ( obj->IsEqual(object) ) return obj;
147 //_____________________________________________________________________________
149 AliMergeableCollection::CreateListOfKeys(Int_t index) const
151 /// Create the list of keys at level index
153 TList* list = new TList;
154 list->SetOwner(kTRUE);
156 TObjArray* ids = SortAllIdentifiers();
160 while ( ( str = static_cast<TObjString*>(next()) ) )
162 TString oneid = GetKey(str->String().Data(),index,kFALSE);
163 if (oneid.Length()>0 && !list->Contains(oneid))
165 list->Add(new TObjString(oneid));
173 //_____________________________________________________________________________
175 AliMergeableCollection::CreateListOfObjectNames(const char* identifier) const
177 /// Create list of object names for /key1/key2/key...
178 /// Returned list must be deleted by client
180 TList* listOfNames = new TList;
181 listOfNames->SetOwner(kTRUE);
186 while ( ( str = static_cast<TObjString*>(next()) ) )
188 TString currIdentifier = str->String();
189 if ( currIdentifier.CompareTo(identifier) ) continue;
191 THashList* list = static_cast<THashList*>(Map()->GetValue(identifier));
193 TIter nextObject(list);
196 while ( ( obj = nextObject() ) )
198 listOfNames->Add(new TObjString(obj->GetName()));
206 //_____________________________________________________________________________
208 AliMergeableCollection::GetIdentifier(const char* fullIdentifier) const
210 /// Extract the identifier from the fullIdentifier
211 TString sfullIdentifier(fullIdentifier);
212 TObjArray* arr = sfullIdentifier.Tokenize("/");
213 TString identifier = "";
214 for ( Int_t istr=0; istr<arr->GetLast(); istr++ ) {
215 identifier += "/" + GetKey(fullIdentifier, istr, kTRUE);
218 identifier.Append("/");
222 //_____________________________________________________________________________
224 AliMergeableCollection::GetKey(const char* identifier, Int_t index, Bool_t idContainsObjName) const
226 /// Extract the index element of the key pair from the fullIdentifier
227 TString sidentifier(identifier);
228 if ( ! idContainsObjName ) sidentifier.Append("/dummy");
229 return InternalDecode(sidentifier.Data(),index);
232 //_____________________________________________________________________________
234 AliMergeableCollection::GetObjectName(const char* fullIdentifier) const
236 /// Extract the object name from an identifier
238 return InternalDecode(fullIdentifier,-1);
242 //_____________________________________________________________________________
244 AliMergeableCollection::GetObject(const char* fullIdentifier) const
246 /// Get object key1/key2/.../objectName:action
248 TObjArray* arr = TString(fullIdentifier).Tokenize(":");
250 TString fullIdWithoutAction(static_cast<TObjString*>(arr->At(0))->String());
253 if ( arr->GetLast() > 0 )
255 action = static_cast<TObjString*>(arr->At(1))->String();
261 return GetObject(GetIdentifier(fullIdWithoutAction).Data(), GetObjectName(fullIdWithoutAction));
268 // if ( action == "PX" && ( (h2 = dynamic_cast<TH2*>(obj)) ) )
270 // return h2->ProjectionX(NormalizeName(identifier.Data(),action.Data()).Data());
272 // else if ( action == "PY" && ( (h2 = dynamic_cast<TH2*>(obj)) ) )
274 // return h2->ProjectionY(NormalizeName(identifier.Data(),action.Data()).Data());
276 // else if ( action == "PFX" && ( (h2 = dynamic_cast<TH2*>(obj)) ) )
278 // return h2->ProfileX(NormalizeName(identifier.Data(),action.Data()).Data());
280 // else if ( action == "PFY" && ( (h2 = dynamic_cast<TH2*>(obj)) ) )
282 // return h2->ProfileY(NormalizeName(identifier.Data(),action.Data()).Data());
288 // AliDebug(1,Form("Object %s not found",sidentifier));
294 //_____________________________________________________________________________
296 AliMergeableCollection::GetObject(const char* identifier,
297 const char* objectName) const
299 /// Get object for (identifier,objectName) triplet
301 TString sidentifier(identifier);
302 if ( ! sidentifier.IsNull() ) {
303 if ( ! sidentifier.BeginsWith("/") ) sidentifier.Prepend("/");
304 if ( ! sidentifier.EndsWith("/") ) sidentifier.Append("/");
306 return InternalObject(sidentifier.Data(),objectName);
309 //_____________________________________________________________________________
310 TObject* AliMergeableCollection::GetSum(const char* idPattern)
313 /// The pattern must be in the form:
314 /// /key1_pattern1 key1_pattern2,key1_pattern,.../key2_pattern1,key2_pattern,.../.../objectName_pattern1,objectName_pattern...
315 /// The logical or between patterns separated by commas is taken
317 TObject* sumObject = 0x0;
319 // Build array of lists of pattern
320 TString idPatternString(idPattern);
321 TObjArray* keyList = idPatternString.Tokenize("/");
322 TObjArray keyMatrix(keyList->GetEntries());
323 keyMatrix.SetOwner();
324 for ( Int_t ikey=0; ikey<keyList->GetEntries(); ikey++ ) {
325 TObjArray* subKeyList = ((TObjString*)keyList->At(ikey))->GetString().Tokenize(",");
326 keyMatrix.AddAt(subKeyList, ikey);
330 TString debugMsg = "Adding objects:";
334 while ( ( str = static_cast<TObjString*>(next()) ) )
336 TString identifier = str->String();
338 Bool_t listMatchPattern = kTRUE;
339 for ( Int_t ikey=0; ikey<keyMatrix.GetEntries()-1; ikey++ ) {
340 TString currKey = GetKey(identifier, ikey, kFALSE);
341 Bool_t matchKey = kFALSE;
342 TObjArray* subKeyList = static_cast<TObjArray*> ( keyMatrix.At(ikey) );
343 for ( Int_t isub=0; isub<subKeyList->GetEntries(); isub++ ) {
344 TString subKeyString = static_cast<TObjString*> (subKeyList->At(isub))->GetString();
345 if ( currKey.Contains(subKeyString.Data()) ) {
349 } // loop on the list of patterns of each key
351 listMatchPattern = kFALSE;
354 } // loop on keys in the idPattern
355 if ( ! listMatchPattern ) continue;
357 THashList* list = static_cast<THashList*>(Map()->GetValue(identifier.Data()));
362 while ( ( obj = nextObj()) )
364 TString currKey = obj->GetName();
365 Bool_t matchKey = kFALSE;
366 TObjArray* subKeyList = static_cast<TObjArray*> ( keyMatrix.Last() );
367 for ( Int_t isub=0; isub<subKeyList->GetEntries(); isub++ ) {
368 TString subKeyString = static_cast<TObjString*> (subKeyList->At(isub))->GetString();
369 if ( currKey.Contains(subKeyString.Data()) ) {
374 if ( ! matchKey ) continue;
375 if ( ! sumObject ) sumObject = obj->Clone();
376 else MergeObject(sumObject, obj);
377 debugMsg += Form(" %s%s",identifier.Data(),obj->GetName());
378 } // loop on objects in list
379 } // loop on identifiers in map
381 AliDebug(1,debugMsg.Data());
386 //_____________________________________________________________________________
387 Bool_t AliMergeableCollection::InternalAdopt(const char* identifier, TObject* obj)
393 Error("Adopt","Cannot adopt a null object");
397 if ( ! obj->IsA()->InheritsFrom(TObject::Class()) ||
398 ! obj->IsA()->GetMethodWithPrototype("Merge", "TCollection*") ) {
399 Error("Adopt","Cannot adopt an object which is not mergeable!");
402 THashList* hlist = 0x0;
404 hlist = static_cast<THashList*>(Map()->GetValue(identifier));
408 hlist = new THashList;
409 hlist->SetOwner(kTRUE);
410 Map()->Add(new TObjString(identifier),hlist);
411 hlist->SetName(identifier);
414 TObject* existingObj = hlist->FindObject(obj->GetName());
418 AliError(Form("Cannot adopt an already existing object : %s -> %s",identifier,existingObj->GetName()));
422 if ( obj->IsA()->InheritsFrom(TH1::Class()) ) (static_cast<TH1*> ( obj ))->SetDirectory(0);
430 //_____________________________________________________________________________
432 AliMergeableCollection::InternalDecode(const char* identifier, Int_t index) const
434 /// Extract the index-th element of the identifier (/key1/key2/.../keyN/objectName)
435 /// object is index=-1 (i.e. last)
437 if ( strlen(identifier) > 0 && identifier[0] != '/' )
439 AliError(Form("identifier %s is malformed (should start with /)",identifier));
443 TObjArray* array = TString(identifier).Tokenize("/");
445 if ( index >= array->GetLast() )
447 AliError(Form("Requiring index %i of identifier %s which only have %i",index, identifier, array->GetLast()));
456 value = static_cast<TObjString*>(array->Last())->String();
458 else if ( index <= array->GetLast() )
460 value = static_cast<TObjString*>(array->At(index))->String();
468 //_____________________________________________________________________________
470 AliMergeableCollection::InternalObject(const char* identifier,
471 const char* objectName) const
473 /// Get object for (identifier,objectName)
480 THashList* hlist = static_cast<THashList*>(Map()->GetValue(identifier));
483 TString msg(Form("Did not find hashlist for identifier=%s dir=%s",identifier,gDirectory ? gDirectory->GetName() : "" ));
484 fMessages[msg.Data()]++;
488 TObject* obj = hlist->FindObject(objectName);
491 TString msg(Form("Did not find objectName=%s in %s",objectName,identifier));
492 fMessages[msg.Data()]++;
498 //_____________________________________________________________________________
499 Bool_t AliMergeableCollection::IsEmptyObject(TObject* obj) const
501 /// Check if object is empty
502 /// (done only for TH1, so far)
504 if ( obj->IsA()->InheritsFrom(TH1::Class()) ) {
505 TH1* histo = static_cast<TH1*> (obj);
506 if ( histo->GetEntries() == 0 ) return kTRUE;
514 //_____________________________________________________________________________
515 TMap* AliMergeableCollection::Map() const
517 /// Wrapper to insure proper key formats (i.e. new vs old)
522 fMap->SetOwnerKeyValue(kTRUE,kTRUE);
527 if ( fMapVersion < 1 )
529 AliInfo("Remapping");
534 while ( ( str = static_cast<TObjString*>(next()) ) )
536 if ( str->String().Contains("./") )
538 TString newkey(str->String());
540 newkey.ReplaceAll("./","");
542 TObject* o = fMap->GetValue(str);
544 TPair* p = fMap->RemoveEntry(str);
547 AliError("oups oups oups");
551 fMap->Add(new TObjString(newkey.Data()),o);
564 //_____________________________________________________________________________
566 AliMergeableCollection::Merge(TCollection* list)
568 // Merge a list of AliMergeableCollection objects with this
569 // Returns the number of merged objects (including this).
573 if (list->IsEmpty()) return 1;
580 while ( ( currObj = next() ) )
582 AliMergeableCollection* mergeCol = dynamic_cast<AliMergeableCollection*>(currObj);
584 AliFatal(Form("object named \"%s\" is a %s instead of an AliMergeableCollection!", currObj->GetName(), currObj->ClassName()));
590 if ( mergeCol->fMap ) mergeCol->Map(); // to insure keys in the new format
592 TIter nextIdentifier(mergeCol->fMap);
593 TObjString* identifier;
595 while ( ( identifier = static_cast<TObjString*>(nextIdentifier()) ) )
597 THashList* otherList = static_cast<THashList*>(mergeCol->fMap->GetValue(identifier->String().Data()));
599 TIter nextObject(otherList);
602 while ( ( obj = nextObject() ) )
604 TString newid(Form("%s%s",identifier->String().Data(),obj->GetName()));
606 TObject* thisObject = GetObject(newid.Data());
610 AliDebug(1,Form("Adopting a new object = %s%s",identifier->String().Data(),obj->GetName()));
612 Bool_t ok = Adopt(identifier->String(), obj->Clone());
616 AliError(Form("Adoption of object %s failed",obj->GetName()));
622 AliDebug(1,Form("Merging object = %s%s",
623 identifier->String().Data(),
626 MergeObject(thisObject, obj);
628 } // loop on objects in map
629 } // loop on identifiers
630 } // loop on collections in list
632 AliDebug(1,Form("count=%d",count));
637 //_____________________________________________________________________________
638 Bool_t AliMergeableCollection::MergeObject(TObject* baseObject, TObject* objToAdd)
640 /// Add objToAdd to baseObject
642 if ( baseObject->IsA()->Class() != objToAdd->IsA()->Class() ) {
643 printf("MergeObject: Cannot add %s to %s", objToAdd->ClassName(), baseObject->ClassName());
646 if ( ! baseObject->IsA()->InheritsFrom(TObject::Class()) ||
647 ! baseObject->IsA()->GetMethodWithPrototype("Merge", "TCollection*") ) {
648 printf("MergeObject: Objects are not mergeable!");
655 TString listArgs = Form("((TCollection*)0x%lx)", (ULong_t)&list);
657 baseObject->Execute("Merge", listArgs.Data(), &error);
661 //_____________________________________________________________________________
662 TString AliMergeableCollection::NormalizeName(const char* identifier,const char* action) const
664 /// Replace / by _ to build a root-compliant histo name
665 TString name(GetName());
671 name.ReplaceAll("/","_");
672 name.ReplaceAll("-","_");
676 //_____________________________________________________________________________
678 AliMergeableCollection::NumberOfObjects() const
680 /// Get the number of objects we hold
681 TIter next(CreateIterator(this));
683 while ( next() ) ++count;
687 //_____________________________________________________________________________
689 AliMergeableCollection::NumberOfKeys() const
691 /// Get the number of keys we have
692 return fMap ? fMap->GetSize() : 0;
695 //_____________________________________________________________________________
697 AliMergeableCollection::Print(Option_t* option) const
699 /// Print all the objects we hold, in a hopefully visually pleasing
702 /// Option can be used to select given part only, using the schema :
704 /// Where the stars are wilcards for /key1/key2/.../objectName
706 /// if * is used it is assumed to be a wildcard for objectName
708 /// For other selections the full syntax /*/*/*/*/* must be used.
710 /// Use "-" as objectName to disable object's name output
712 cout << Form("AliMergeableCollection(%s,%s) : %d keys and %d objects",
713 GetName(),GetTitle(),
714 NumberOfKeys(), NumberOfObjects()) << endl;
716 if (!strlen(option)) return;
718 TObjArray* select = TString(option).Tokenize("/");
720 TString sreObjectName(select->Last()->GetName());
721 TRegexp reObjectName(sreObjectName.Data(),kTRUE);
723 TObjArray* identifiers = SortAllIdentifiers();
725 printf("identifiers entries %i\n", identifiers->GetEntries());
727 TIter nextIdentifier(identifiers);
729 TObjString* sid(0x0);
731 while ( ( sid = static_cast<TObjString*>(nextIdentifier()) ) )
733 Bool_t identifierPrinted(kFALSE);
735 TString identifier(sid->String());
737 Bool_t matchPattern = kTRUE;
738 for ( Int_t isel=0; isel<select->GetLast(); isel++ ) {
739 if ( ! GetKey(identifier.Data(), isel, kFALSE).Contains(TRegexp(select->At(isel)->GetName(),kTRUE)) ) {
740 matchPattern = kFALSE;
744 if ( ! matchPattern ) continue;
746 if ( sreObjectName == "*" ) {
747 identifierPrinted = kTRUE;
748 cout << identifier.Data() << endl;
751 THashList * list = static_cast<THashList*>(Map()->GetValue(sid->String().Data()));
753 names.SetOwner(kTRUE);
754 TIter nextUnsortedObj(list);
756 while ( ( obj = nextUnsortedObj() ) )
758 names.Add(new TObjString(obj->GetName()));
761 TIter nextObjName(&names);
763 while ( ( oname = static_cast<TObjString*>(nextObjName()) ) )
765 TString objName(oname->String());
766 if (objName.Contains(reObjectName) )
768 obj = list->FindObject(objName.Data());
769 if ( IsEmptyObject(obj) && ! fMustShowEmptyObject ) continue;
770 if (!identifierPrinted)
772 cout << identifier.Data() << endl;
773 identifierPrinted = kTRUE;
775 cout << Form(" (%s) %s", obj->ClassName(), obj->GetName());
776 if ( obj->IsA()->InheritsFrom(TH1::Class()) ) {
777 TH1* histo = static_cast<TH1*> (obj);
778 cout << Form(" %s Entries=%d Sum=%g",histo->GetTitle(),Int_t(histo->GetEntries()),histo->GetSumOfWeights());
783 if (!identifierPrinted && sreObjectName=="-" )
785 // to handle the case where we used objectName="-" to disable showing the objectNames,
786 // but we still want to see the matching keys maybe...
787 cout << identifier.Data() << endl;
796 //_____________________________________________________________________________
798 AliMergeableCollection::PrintMessages(const char* prefix) const
800 /// Print pending messages
802 std::map<std::string,int>::const_iterator it;
804 for ( it = fMessages.begin(); it != fMessages.end(); ++it )
806 cout << Form("%s : message %s appeared %5d times",prefix,it->first.c_str(),it->second) << endl;
811 //_____________________________________________________________________________
813 AliMergeableCollection::EstimateSize(Bool_t show) const
815 /// Estimate the memory (in kilobytes) used by some objects
818 // sizeof(TH1) + (nbins+2)*(nbytes_per_bin) +name+title_sizes
819 // if you have errors add (nbins+2)*8
821 TIter next(CreateIterator());
826 while ( ( obj = next() ) )
829 if ( obj->IsA()->InheritsFrom(TH1::Class()) ) {
830 TH1* histo = static_cast<TH1*> (obj);
831 Int_t nbins = (histo->GetNbinsX()+2);
833 if (histo->GetNbinsY()>1)
835 nbins *= (histo->GetNbinsY()+2);
838 if (histo->GetNbinsZ()>1)
840 nbins *= (histo->GetNbinsZ()+2);
843 Bool_t hasErrors = ( histo->GetSumw2N() > 0 );
845 TString cname(histo->ClassName());
847 Int_t nbytesPerBin(0);
849 if (cname.Contains(TRegexp("C$")) ) nbytesPerBin = sizeof(Char_t);
850 if (cname.Contains(TRegexp("S$")) ) nbytesPerBin = sizeof(Short_t);
851 if (cname.Contains(TRegexp("I$")) ) nbytesPerBin = sizeof(Int_t);
852 if (cname.Contains(TRegexp("F$")) ) nbytesPerBin = sizeof(Float_t);
853 if (cname.Contains(TRegexp("D$")) ) nbytesPerBin = sizeof(Double_t);
857 AliError(Form("Could not get the number of bytes per bin for histo %s of class %s. Thus the size estimate will be wrong !",
858 histo->GetName(),histo->ClassName()));
862 thissize = sizeof(histo) + nbins*(nbytesPerBin) + strlen(histo->GetName())
863 + strlen(histo->GetTitle());
865 if ( hasErrors) thissize += nbins*8;
868 AliWarning(Form("Cannot estimate size of %s\n", obj->ClassName()));
876 AliInfo(Form("Size of %30s is %20d bytes",obj->GetName(),thissize));
883 //_____________________________________________________________________________
884 void AliMergeableCollection::PruneEmptyObjects()
886 /// Delete the empty objects
887 /// (Implemented for TH1 only)
892 toBeRemoved.SetOwner(kTRUE);
894 while ( ( key = static_cast<TObjString*>(next()) ) )
896 TString identifier(key->String());
897 THashList* hlist = static_cast<THashList*>(Map()->GetValue(identifier.Data()));
898 TIter nextObject(hlist);
900 while ( ( obj = nextObject() ) )
902 if ( IsEmptyObject(obj) ) toBeRemoved.Add(new TObjString(Form("%s%s",identifier.Data(),obj->GetName())));
906 TIter nextTBR(&toBeRemoved);
907 while ( ( key = static_cast<TObjString*>(nextTBR()) ) )
909 Remove(key->GetString().Data());
910 AliDebug(2,Form("Removing %s", key->GetString().Data()));
914 //_____________________________________________________________________________
915 AliMergeableCollection*
916 AliMergeableCollection::Project(const char* identifier) const
918 /// To be implemented : would create a new collection starting at /key1/key2/...
920 if (!fMap) return 0x0;
922 AliMergeableCollection* mergCol = new AliMergeableCollection(Form("%s %s",GetName(),identifier),
928 while ( ( str = static_cast<TObjString*>(next()) ) )
930 TString currIdentifier = str->String();
931 if ( ! currIdentifier.Contains(identifier) ) continue;
933 THashList* list = static_cast<THashList*>(Map()->GetValue(identifier));
938 while ( ( obj = nextObj()) )
940 TObject* clone = obj->Clone();
942 TString newkey(currIdentifier.Data());
943 newkey.ReplaceAll(identifier,"");
945 if (newkey=="/") newkey="";
947 mergCol->InternalAdopt(newkey.Data(),clone);
954 //_____________________________________________________________________________
956 AliMergeableCollection::Remove(const char* fullIdentifier)
959 /// Remove a given object (given its fullIdentifier=/key1/key2/.../objectName)
961 /// Note that we do *not* remove the /key1/key2/... entry even if there's no
962 /// more object for this triplet.
964 /// Not very efficient. Could be improved ?
967 TString identifier = GetIdentifier(fullIdentifier);
969 THashList* hlist = dynamic_cast<THashList*>(Map()->GetValue(identifier.Data()));
973 AliWarning(Form("Could not get hlist for key=%s",identifier.Data()));
977 TObject* obj = GetObject(fullIdentifier);
980 AliError(Form("Could not find object %s",fullIdentifier));
984 TObject* rmObj = hlist->Remove(obj);
987 AliError("Remove failed");
994 //_____________________________________________________________________________
996 AliMergeableCollection::SortAllIdentifiers() const
998 /// Sort our internal identifiers. Returned array must be deleted.
999 TObjArray* identifiers = new TObjArray;
1000 identifiers->SetOwner(kFALSE);
1004 while ( ( sid = static_cast<TObjString*>(next()) ) )
1006 if ( !identifiers->FindObject(sid->String().Data()) )
1008 identifiers->Add(sid);
1011 identifiers->Sort();
1016 ///////////////////////////////////////////////////////////////////////////////
1018 // AliMergeableCollectionIterator
1020 ///////////////////////////////////////////////////////////////////////////////
1022 class AliMergeableCollectionIterator;
1024 //_____________________________________________________________________________
1025 AliMergeableCollectionIterator::AliMergeableCollectionIterator(const AliMergeableCollection* mcol, Bool_t dir)
1026 : fkMergeableCollection(mcol), fMapIterator(0x0), fHashListIterator(0x0), fDirection(dir)
1031 //_____________________________________________________________________________
1032 AliMergeableCollectionIterator&
1033 AliMergeableCollectionIterator::operator=(const TIterator&)
1035 /// Overriden operator= (imposed by Root's declaration of TIterator ?)
1036 Fatal("TIterator::operator=","Not implementeable"); // because there's no clone in TIterator :-(
1040 //_____________________________________________________________________________
1041 AliMergeableCollectionIterator::~AliMergeableCollectionIterator()
1047 //_____________________________________________________________________________
1048 TObject* AliMergeableCollectionIterator::Next()
1050 /// Advance to next object in the collection
1052 if (!fHashListIterator)
1054 if ( !fMapIterator )
1056 fMapIterator = fkMergeableCollection->fMap->MakeIterator(fDirection);
1058 TObjString* key = static_cast<TObjString*>(fMapIterator->Next());
1064 THashList* list = static_cast<THashList*>(fkMergeableCollection->Map()->GetValue(key->String().Data()));
1065 if (!list) return 0x0;
1066 fHashListIterator = list->MakeIterator(fDirection);
1069 TObject* obj = fHashListIterator->Next();
1073 delete fHashListIterator;
1074 fHashListIterator = 0x0;
1081 //_____________________________________________________________________________
1082 void AliMergeableCollectionIterator::Reset()
1084 /// Reset the iterator
1085 delete fHashListIterator;
1086 delete fMapIterator;