Hi Diego, TClonesArrays are typically used to store "repeatedly" many the same objects. Typicaly during analysis you use a TClonesArray to store for each event all track objects, i.e. the same clonesarray is re-used by each event object to store its tracks. If you don't have such a problem you better use a TObjArray (or TOrdCollection, etc.). Assuming you want to use a clonesarray, you can use it to store objects with different lenghts (i.e. objects that allocate additional arrays or objects). In such a case be sure that you specify when creating the clonesarray the last argument kTRUE. TClonesArray(Text_t *classname, Int_t size = 1000, Bool_t call_dtor = kFALSE); In that case the destructor of your objects is called whenever you call TClonesArray::Delete(). This does not delete the space of the clone object, only the space allocated extra in the ctor of the clone objects. TObjArray and TClonesArray both use TSeqCollection::QSort() for sorting. QSort indirectly compares two objects using your class' own Compare(TObject *) function. In this Compare function you do what you like. For some more on collection classes see: http://root.cern.ch/root/Collection1.html Cheers, Fons. > > Hello Rooters. > It's a week that I fight with TClonesArrays... and now I have a simple > question for you. > In the documentation I read that, when you plan to put in a TObjArray all > objects of the same class, you'd better to use TClonesArray instead. > Well, I have a list of objects of the same type, so I decided to use > TClonesArray. But now, it's clear for me that my objects will have in > general different lenghts (thay contain other arrays of objects, of which > I don't know a priori the dimension). > Then the question: should I use TObjArray instead? > > It's not the end. > I'd like to have ordered arrays. In TObjArray we find the function > virtual Bool_t IsSortable() const { return kFALSE; }. > TClonesArray inherits from TObjArray, so I could redefine it to > virtual Bool_t IsSortable() const { return kTUE; }. > In addition, TClonesArray has a Sort() function, that sorts the elements > guided by their fSize (their dimension, roughly speaking). > This is not what I need. My classes have a data member that I would like > to use as an index for the sorting. > > I guess I must write my own algorithm for this sorting, using TObjArray > instead of TClonesArray. Do you think there is another possibility? > > Best regards > > Diego Casadei > casadei@bo.infn.it > casadei@cern.ch > -- Org: CERN, European Laboratory for Particle Physics. Mail: 1211 Geneve 23, Switzerland Phone: +41 22 7679248 E-Mail: Fons.Rademakers@cern.ch Fax: +41 22 7677910
This archive was generated by hypermail 2b29 : Tue Jan 04 2000 - 00:34:32 MET