A collection is a group of related objects. You will find it easier to manage a large number of items as a collection. For example, collections of points and lines might be managed by a graphics pad. A vertex will have a collection of tracks. A detector geometry contains collections of shapes, materials, rotation matrices and sub-detectors. Collections act as flexible alternatives to traditional data structures of computer science such as arrays, lists, and trees.
Collections can be thought of as polymorphic containers that can contain different types of elements. For this release of the ROOT system, elements to be placed in collections must be instances of classes. These may be classes defined by you or provided by ROOT. Collection elements must be instances of classes descending from TObject. The dependence of collections on TObject may disappear in the future when all C++ compilers used with the ROOT system fully support templates. In the mean time, knowing the role TObject plays in collections can be helpful.
In general you don't need to worry about TObject. Many ROOT classes have TObject as an ancestor. In fact, collections themselves are descendants of TObject. This makes it possible for collections to contain other collections (subcollections) in a tree structure. Such trees are used in the ROOT system to implement components of the graphics system (graphics pads containing pads), geometries (detectors in detectors), etc.
The basic protocol TObject defines for collection elements is shown below:
IsEqual() Compare() IsSortable() Hash()
How to use and override these member functions is shown in the example program.
Both a TObjArray as well as a TOrdCollection can be sorted using their Sort() member function (assuming the stored items are sortable).