Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TCollection.cxx
Go to the documentation of this file.
1// @(#)root/cont:$Id$
2// Author: Fons Rademakers 13/08/95
3
4/*************************************************************************
5 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12/** \class TCollection
13\ingroup Containers
14Collection abstract base class. This class describes the base
15protocol all collection classes have to implement. The ROOT
16collection classes always store pointers to objects that inherit
17from TObject. They never adopt the objects. Therefore, it is the
18user's responsibility to take care of deleting the actual objects
19once they are not needed anymore. In exceptional cases, when the
20user is 100% sure nothing else is referencing the objects in the
21collection, one can delete all objects and the collection at the
22same time using the Delete() function.
23
24Collections can be iterated using an iterator object (see
25TIterator). Depending on the concrete collection class there may be
26some additional methods of iterating. See the respective classes.
27
28TCollection inherits from TObject since we want to be able to have
29collections of collections.
30
31In a later release the collections may become templatized.
32
33The following describes how you can access the elements in case
34an interface returns a ROOT collection type such as TList or TObjArray.
35These type of ROOT collections hold pointers to TObject. In other words,
36to store an object in a ROOT collection, it must inherit from TObject.
37You can think of a TList as a std::list<TObject*>.
38
39\note For historical reasons, some of ROOT’s interfaces use ROOT’s
40own collection types such as TList and TObjArray. In modern code
41(within ROOT and your own), it's recommended to rather use
42std::array or std::vector etc. from the C++ Standard Library, and
43their standard iterators.
44
45Traditional ways of iterating through these elements rely on the use of
46TIter, R__FOR_EACH, std::for_each, range-based for, TObjLink::Next or
47TList::After, as described in the 6 examples of TList documentation.
48
49However, these ways of retrieval through the parent class TObject* are
50often not useful, since those pointers have to be cast back to the
51correct subclass. For instance, with TTree::GetListOfBranches(),
52you know that the derived class is of type TBranch*. For this purpose,
53ROOT offers a specific tools for range-based for loops: such as
54ROOT::RRangeCast, TRangeStaticCast and TRangeDynCast (in this example):
55
56```{.cpp}
57for (auto br : TRangeDynCast<TBranch>( tree->GetListOfBranches() )) {
58 if (!br) continue;
59 // Use br as a TBranch*
60}
61```
62
63*/
64
65#include "TCollection.h"
66#include "Varargs.h"
67#include "TBuffer.h"
68#include "TClass.h"
69#include "TROOT.h"
70#include "TBrowser.h"
71#include "TObjectTable.h"
72#include "TRegexp.h"
73#include "TPRegexp.h"
74#include "TVirtualMutex.h"
75#include "TError.h"
76#include "TSystem.h"
77#include "TObjArray.h"
78#include <iostream>
79#include <sstream>
80
81#include "TSpinLockGuard.h"
82
84
89
92
93#ifdef R__CHECK_COLLECTION_MULTI_ACCESS
94
95void TCollection::TErrorLock::ConflictReport(std::thread::id holder, const char *accesstype,
96 const TCollection *collection, const char *function)
97{
98
99 auto local = std::this_thread::get_id();
100 std::stringstream cur, loc;
101 if (holder == std::thread::id())
102 cur << "None";
103 else
104 cur << "0x" << std::hex << holder;
105 loc << "0x" << std::hex << local;
106
107 // std::cerr << "Error in " << function << ": Access (" << accesstype << ") to a collection (" <<
108 // collection->IsA()->GetName() << ":" << collection <<
109 // ") from multiple threads at a time. holder=" << "0x" << std::hex << holder << " readers=" << fReadSet.size() <<
110 // "0x" << std::hex << local << std::endl;
111
112 ::Error(function,
113 "Access (%s) to a collection (%s:%p) from multiple threads at a time. holder=%s readers=%lu intruder=%s",
114 accesstype, collection->IsA()->GetName(), collection, cur.str().c_str(), fReadSet.size(), loc.str().c_str());
115
116 std::set<std::thread::id> tmp;
117 for (auto r : fReadSet) tmp.insert(r);
118 for (auto r : tmp) {
119 std::stringstream reader;
120 reader << "0x" << std::hex << r;
121 ::Error(function, " Readers includes %s", reader.str().c_str());
122 }
124}
125
126void TCollection::TErrorLock::Lock(const TCollection *collection, const char *function)
127{
128 auto local = std::this_thread::get_id();
129
130 std::thread::id holder;
131
132 if (fWriteCurrent.compare_exchange_strong(holder, local)) {
133 // fWriteCurrent was the default id and is now local.
135 // std::cerr << "#" << "0x" << std::hex << local << " acquired first " << collection << " lock:" << this <<
136 // std::endl;
137
138 // Now check if there is any readers lingering
140 if (fReadSet.size() > 1 || fReadSet.find(local) != fReadSet.end()) {
141 ConflictReport(std::thread::id(), "WriteLock while ReadLock taken", collection, function);
142 }
143 }
144 } else {
145 // fWriteCurrent was not the default id and is still the 'holder' thread id
146 // this id is now also in the holder variable
147 if (holder == local) {
148 // The holder was actually this thread, no problem there, we
149 // allow re-entrancy.
150 // std::cerr << "#" << "0x" << std::hex << local << " re-entered " << fWriteCurrentRecurse << " " << collection
151 // << " lock:" << this << std::endl;
152 } else {
153 ConflictReport(holder, "WriteLock", collection, function);
154 }
156 }
157}
158
159void TCollection::TErrorLock::Unlock()
160{
161 auto local = std::this_thread::get_id();
162 auto none = std::thread::id();
163
165 if (fWriteCurrentRecurse == 0) {
166 if (fWriteCurrent.compare_exchange_strong(local, none)) {
167 // fWriteCurrent was local and is now none.
168
169 // std::cerr << "#" << "0x" << std::hex << local << " zero and cleaned : " << std::dec << fWriteCurrentRecurse
170 // << " 0x" << std::hex << fWriteCurrent.load() << " lock:" << this << std::endl;
171 } else {
172 // fWriteCurrent was not local, just live it as is.
173
174 // std::cerr << "#" << "0x" << std::hex << local << " zero but somebody else : " << "0x" << std::hex <<
175 // fWriteCurrent.load() << " lock:" << this << std::endl;
176 }
177 } else {
178 // std::cerr << "#" << "0x" << std::hex << local << " still holding " << "0x" << std::hex << fWriteCurrentRecurse
179 // << " lock:" << this << std::endl;
180 }
181
182 // std::cerr << "#" << "0x" << std::hex << local << " ended with : " << std::dec << fWriteCurrentRecurse << " 0x" <<
183 // std::hex << fWriteCurrent.load() << " lock:" << this << std::endl;
184}
185
186void TCollection::TErrorLock::ReadLock(const TCollection *collection, const char *function)
187{
188 auto local = std::this_thread::get_id();
189
190 {
192 fReadSet.insert(local); // this is not thread safe ...
193 }
195
197 auto holder = fWriteCurrent.load();
198 if (holder != local) ConflictReport(holder, "ReadLock with WriteLock taken", collection, function);
201
202void TCollection::TErrorLock::ReadUnlock()
203{
204 auto local = std::this_thread::get_id();
205 {
207 fReadSet.erase(local); // this is not thread safe ...
208 }
210}
211
212#endif // R__CHECK_COLLECTION_MULTI_ACCESS
213
214////////////////////////////////////////////////////////////////////////////////
215/// TNamed destructor.
216
218{
219 // Required since we overload TObject::Hash.
221}
222
223////////////////////////////////////////////////////////////////////////////////
224/// Add all objects from collection col to this collection.
225
227{
228 TIter next(col);
229 TObject *obj;
230
231 while ((obj = next()))
232 Add(obj);
233}
234
235////////////////////////////////////////////////////////////////////////////////
236/// Add all arguments to the collection. The list of objects must be
237/// terminated by 0, e.g.: l.AddVector(o1, o2, o3, o4, 0);
238
240{
241 va_list ap;
242 va_start(ap, va_(obj1));
243 TObject *obj;
244
245 Add(va_(obj1));
246 while ((obj = va_arg(ap, TObject *)))
247 Add(obj);
248 va_end(ap);
249}
250
251////////////////////////////////////////////////////////////////////////////////
252/// Make sure all objects in this collection inherit from class cl.
253
255{
256 TObject *obj;
257 TIter next(this);
258 Bool_t error = kFALSE;
259
260 if (!cl) {
261 Error("AssertClass", "class == 0");
262 return kTRUE;
263 }
264
265 for (int i = 0; (obj = next()); i++)
266 if (!obj->InheritsFrom(cl)) {
267 Error("AssertClass", "element %d is not an instance of class %s (%s)",
268 i, cl->GetName(), obj->ClassName());
269 error = kTRUE;
270 }
271 return error;
272}
273
274////////////////////////////////////////////////////////////////////////////////
275/// Browse this collection (called by TBrowser).
276/// If b=0, there is no Browse call TObject::Browse(0) instead.
277/// This means TObject::Inspect() will be invoked indirectly
278
280{
281 TIter next(this);
282 TObject *obj;
283
284 if (b)
285 while ((obj = next())) b->Add(obj);
286 else
288}
289
290////////////////////////////////////////////////////////////////////////////////
291/// Make a clone of an collection using the Streamer facility.
292/// If newname is specified, this will be the name of the new collection.
293
300
301
302////////////////////////////////////////////////////////////////////////////////
303/// Compare two TCollection objects. Returns 0 when equal, -1 when this is
304/// smaller and +1 when bigger (like strcmp()).
305
307{
308 if (this == obj) return 0;
309 return fName.CompareTo(obj->GetName());
310}
311
312////////////////////////////////////////////////////////////////////////////////
313/// Draw all objects in this collection.
314
316{
317 TIter next(this);
319
320 while ((object = next())) {
321 object->Draw(option);
322 }
323}
324
325////////////////////////////////////////////////////////////////////////////////
326/// Dump all objects in this collection.
327
329{
330 TIter next(this);
332
333 while ((object = next())) {
334 object->Dump();
335 }
336}
337
338////////////////////////////////////////////////////////////////////////////////
339/// Find an object in this collection using its name. Requires a sequential
340/// scan till the object has been found. Returns 0 if object with specified
341/// name is not found.
342
344{
345 TIter next(this);
346 TObject *obj;
347
348 while ((obj = next()))
349 if (!strcmp(name, obj->GetName())) return obj;
350 return nullptr;
351}
352
353////////////////////////////////////////////////////////////////////////////////
354/// Find an object in this collection by name.
355
357{
358 return FindObject(name);
359}
360
361////////////////////////////////////////////////////////////////////////////////
362/// Find an object in this collection using the object's IsEqual()
363/// member function. Requires a sequential scan till the object has
364/// been found. Returns 0 if object is not found.
365/// Typically this function is overridden by a more efficient version
366/// in concrete collection classes (e.g. THashTable).
367
369{
370 TIter next(this);
371 TObject *ob;
372
373 while ((ob = next()))
374 if (ob->IsEqual(obj)) return ob;
375 return nullptr;
376}
377
378////////////////////////////////////////////////////////////////////////////////
379/// Return name of this collection.
380/// if no name, return the collection class name.
381
382const char *TCollection::GetName() const
383{
384 if (fName.Length() > 0) return fName.Data();
385 return ClassName();
386}
387
388////////////////////////////////////////////////////////////////////////////////
389/// Increase the collection's capacity by delta slots.
390
392{
393 if (delta < 0) {
394 Error("GrowBy", "delta < 0");
395 delta = Capacity();
396 }
397 return Capacity() + TMath::Range(2, kMaxInt - Capacity(), delta);
398}
399
400////////////////////////////////////////////////////////////////////////////////
401/// Returns true if object is a null pointer.
402
403Bool_t TCollection::IsArgNull(const char *where, const TObject *obj) const
404{
405 return obj ? kFALSE : (Error(where, "argument is a null pointer"), kTRUE);
406}
407
408////////////////////////////////////////////////////////////////////////////////
409/// List (ls) all objects in this collection.
410/// Wildcarding supported, eg option="xxx*" lists only objects
411/// with names xxx*.
412
414{
416 std::cout <<"OBJ: " << IsA()->GetName() << "\t" << GetName() << "\t" << GetTitle() << " : "
417 << Int_t(TestBit(kCanDelete)) << std::endl;
418
419 TRegexp re(option,kTRUE);
420 TIter next(this);
422 char *star = nullptr;
423 if (option) star = (char*)strchr(option,'*');
424
426 while ((object = next())) {
427 if (star) {
428 TString s = object->GetName();
429 if (s != option && s.Index(re) == kNPOS) continue;
430 }
431 object->ls(option);
432 }
434}
435
436////////////////////////////////////////////////////////////////////////////////
437/// 'Notify' all objects in this collection.
439{
440 Bool_t success = true;
441 for (auto obj : *this) success &= obj->Notify();
442 return success;
443}
444
445////////////////////////////////////////////////////////////////////////////////
446/// Paint all objects in this collection.
447
452
453////////////////////////////////////////////////////////////////////////////////
454/// Print the collection header.
455
457{
459 printf("Collection name='%s', class='%s', size=%d\n",
460 GetName(), ClassName(), GetSize());
461}
462
463////////////////////////////////////////////////////////////////////////////////
464/// For given collection entry return the string that is used to
465/// identify the object and, potentially, perform wildcard/regexp
466/// filtering on.
467
469{
470 return entry->GetName();
471}
472
473////////////////////////////////////////////////////////////////////////////////
474/// Print the collection entry.
475
477{
478 TCollection* coll = dynamic_cast<TCollection*>(entry);
479 if (coll) {
480 coll->Print(option, recurse);
481 } else {
483 entry->Print(option);
484 }
485}
486
487////////////////////////////////////////////////////////////////////////////////
488/// Default print for collections, calls Print(option, 1).
489/// This will print the collection header and Print() methods of
490/// all the collection entries.
491///
492/// If you want to override Print() for a collection class, first
493/// see if you can accomplish it by overriding the following protected
494/// methods:
495/// ~~~ {.cpp}
496/// void PrintCollectionHeader(Option_t* option) const;
497/// const char* GetCollectionEntryName(TObject* entry) const;
498/// void PrintCollectionEntry(TObject* entry, Option_t* option, Int_t recurse) const;
499/// ~~~
500/// Otherwise override the `Print(Option_t *option, Int_t)`
501/// variant. Remember to declare:
502/// ~~~ {.cpp}
503/// using TCollection::Print;
504/// ~~~
505/// somewhere close to the method declaration.
506
508{
509 Print(option, 1);
510}
511
512////////////////////////////////////////////////////////////////////////////////
513/// Print the collection header and its elements.
514///
515/// If recurse is non-zero, descend into printing of
516/// collection-entries with recurse - 1.
517/// This means, if recurse is negative, the recursion is infinite.
518///
519/// Option is passed recursively.
520
522{
524
525 if (recurse != 0)
526 {
527 TIter next(this);
529
531 while ((object = next())) {
532 PrintCollectionEntry(object, option, recurse - 1);
533 }
535 }
536}
537
538////////////////////////////////////////////////////////////////////////////////
539/// Print the collection header and its elements that match the wildcard.
540///
541/// If recurse is non-zero, descend into printing of
542/// collection-entries with recurse - 1.
543/// This means, if recurse is negative, the recursion is infinite.
544///
545/// Option is passed recursively, but wildcard is only used on the
546/// first level.
547
549{
551
552 if (recurse != 0)
553 {
554 if (!wildcard) wildcard = "";
557 TIter next(this);
559
561 while ((object = next())) {
563 if (nch == 0 || s == wildcard || s.Index(re) != kNPOS) {
564 PrintCollectionEntry(object, option, recurse - 1);
565 }
566 }
568 }
569}
570
571////////////////////////////////////////////////////////////////////////////////
572/// Print the collection header and its elements that match the regexp.
573///
574/// If recurse is non-zero, descend into printing of
575/// collection-entries with recurse - 1.
576/// This means, if recurse is negative, the recursion is infinite.
577///
578/// Option is passed recursively, but regexp is only used on the
579/// first level.
580
582{
584
585 if (recurse != 0)
586 {
587 TIter next(this);
589
591 while ((object = next())) {
593 if (regexp.MatchB(s)) {
594 PrintCollectionEntry(object, option, recurse - 1);
595 }
596 }
598 }
599}
600
601////////////////////////////////////////////////////////////////////////////////
602/// Remove object from this collection and recursively remove the object
603/// from all other objects (and collections).
604
606{
607 if (!obj) return;
608
609 // Scan list and remove obj in the list itself
610 while (Remove(obj))
611 ;
612
613 // Scan again the list and invoke RecursiveRemove for all objects
614 TIter next(this);
616
617 while ((object = next())) {
618 if (!ROOT::Detail::HasBeenDeleted(object)) object->RecursiveRemove(obj);
619 }
620}
621
622////////////////////////////////////////////////////////////////////////////////
623/// Remove all objects in collection col from this collection.
624
626{
627 TIter next(col);
628 TObject *obj;
629
630 while ((obj = next()))
631 Remove(obj);
632}
633
634////////////////////////////////////////////////////////////////////////////////
635/// Stream all objects in the collection to or from the I/O buffer.
636
638{
640 TObject *obj;
642
643 if (b.IsReading()) {
644 Version_t v = b.ReadVersion(&R__s, &R__c);
645 if (v > 2)
647 if (v > 1)
649 b >> nobjects;
650 for (Int_t i = 0; i < nobjects; i++) {
651 b >> obj;
652 Add(obj);
653 }
654 b.CheckByteCount(R__s, R__c,TCollection::IsA());
655 } else {
656 R__c = b.WriteVersion(TCollection::IsA(), kTRUE);
659 nobjects = GetSize();
660 b << nobjects;
661
662 TIter next(this);
663
664 while ((obj = next())) {
665 b << obj;
666 }
667 b.SetByteCount(R__c, kTRUE);
668 }
669}
670
671////////////////////////////////////////////////////////////////////////////////
672/// Write all objects in this collection. By default all objects in
673/// the collection are written individually (each object gets its
674/// own key). Note, this is recursive, i.e. objects in collections
675/// in the collection are also written individually. To write all
676/// objects using a single key specify a name and set option to
677/// TObject::kSingleKey (i.e. 1).
678
680{
681 if ((option & kSingleKey)) {
683 } else {
685 Int_t nbytes = 0;
686 TIter next(this);
687 TObject *obj;
688 while ((obj = next())) {
689 nbytes += obj->Write(name, option, bsize);
690 }
691 return nbytes;
692 }
693}
694
695////////////////////////////////////////////////////////////////////////////////
696/// Write all objects in this collection. By default all objects in
697/// the collection are written individually (each object gets its
698/// own key). Note, this is recursive, i.e. objects in collections
699/// in the collection are also written individually. To write all
700/// objects using a single key specify a name and set option to
701/// TObject::kSingleKey (i.e. 1).
702
704{
705 return ((const TCollection*)this)->Write(name,option,bsize);
706}
707
708////////////////////////////////////////////////////////////////////////////////
709/// Return the globally accessible collection.
710
715
716////////////////////////////////////////////////////////////////////////////////
717/// Set this collection to be the globally accessible collection.
718
723
724////////////////////////////////////////////////////////////////////////////////
725/// Set up for garbage collection.
726
737
738////////////////////////////////////////////////////////////////////////////////
739/// Do the garbage collection.
740
752
753////////////////////////////////////////////////////////////////////////////////
754/// Add to the list of things to be cleaned up.
755
757{
758 {
761 if (!fgEmptyingGarbage) {
762 fgGarbageCollection->Add(obj);
763 return;
764 }
765 }
766 }
767 delete obj;
768}
769
770////////////////////////////////////////////////////////////////////////////////
771/// Set whether this collection is the owner (enable==true)
772/// of its content. If it is the owner of its contents,
773/// these objects will be deleted whenever the collection itself
774/// is deleted. The objects might also be deleted or destructed when Clear
775/// is called (depending on the collection).
776
778{
779 if (enable)
781 else
783}
784
785////////////////////////////////////////////////////////////////////////////////
786/// Set this collection to use a RW lock upon access, making it thread safe.
787/// Return the previous state.
788///
789/// Note: To test whether the usage is enabled do:
790/// collection->TestBit(TCollection::kUseRWLock);
791
793{
794 bool prev = TestBit(TCollection::kUseRWLock);
795 if (enable) {
797 } else {
799 }
800 return prev;
801}
802
803////////////////////////////////////////////////////////////////////////////////
804/// Copy a TIter. This involves allocating a new TIterator of the right
805/// sub class and assigning it with the original.
806
807TIter::TIter(const TIter &iter)
808{
809 if (iter.fIterator) {
810 fIterator = iter.GetCollection()->MakeIterator();
811 fIterator->operator=(*iter.fIterator);
812 } else
813 fIterator = nullptr;
814}
815
816////////////////////////////////////////////////////////////////////////////////
817/// Assigning an TIter to another. This involves allocating a new TIterator
818/// of the right sub class and assigning it with the original.
819
821{
822 if (this != &rhs) {
823 if (rhs.fIterator) {
824 delete fIterator;
825 fIterator = rhs.GetCollection()->MakeIterator();
826 fIterator->operator=(*rhs.fIterator);
827 }
828 }
829 return *this;
830}
831
832////////////////////////////////////////////////////////////////////////////////
833/// Pointing to the first element of the container.
834
836{
837 fIterator->Reset();
838 fIterator->Next();
839 return *this;
840}
841
842////////////////////////////////////////////////////////////////////////////////
843/// Pointing to the element after the last - to a nullptr value in our case.
844
846{
847 return TIter(static_cast<TIterator*>(nullptr));
848}
849
850////////////////////////////////////////////////////////////////////////////////
851/// Return an empty collection for use with nullptr TRangeCast
852
854{
855 static TObjArray sEmpty;
856 return sEmpty;
857}
858
859////////////////////////////////////////////////////////////////////////////////
860/// Return true if 'cl' inherits from 'base'.
861
863{
864 return cl->InheritsFrom(base);
865}
#define SafeDelete(p)
Definition RConfig.hxx:541
#define b(i)
Definition RSha256.hxx:100
bool Bool_t
Definition RtypesCore.h:63
int Int_t
Definition RtypesCore.h:45
constexpr Int_t kMaxInt
Definition RtypesCore.h:105
short Version_t
Definition RtypesCore.h:65
constexpr Bool_t kFALSE
Definition RtypesCore.h:94
constexpr Ssiz_t kNPOS
Definition RtypesCore.h:117
constexpr Bool_t kTRUE
Definition RtypesCore.h:93
const char Option_t
Definition RtypesCore.h:66
#define ClassImp(name)
Definition Rtypes.h:374
TVirtualMutex * gCollectionMutex
R__EXTERN TVirtualMutex * gCollectionMutex
Definition TCollection.h:45
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
#define R__FOR_EACH(type, proc)
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
Definition TError.cxx:185
Option_t Option_t option
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t r
char name[80]
Definition TGX11.cxx:110
R__EXTERN TSystem * gSystem
Definition TSystem.h:572
#define R__LOCKGUARD2(mutex)
#define va_(arg)
Definition Varargs.h:35
A spin mutex-as-code-guard class.
const_iterator end() const
Using a TBrowser one can browse all ROOT objects.
Definition TBrowser.h:37
Buffer base class used for serializing objects.
Definition TBuffer.h:43
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition TClass.h:84
Bool_t InheritsFrom(const char *cl) const override
Return kTRUE if this class inherits from a class with name "classname".
Definition TClass.cxx:4971
Collection abstract base class.
Definition TCollection.h:65
virtual TObject * Remove(TObject *obj)=0
virtual void PrintCollectionEntry(TObject *entry, Option_t *option, Int_t recurse) const
Print the collection entry.
void Draw(Option_t *option="") override
Draw all objects in this collection.
Bool_t IsArgNull(const char *where, const TObject *obj) const
Returns true if object is a null pointer.
Bool_t Notify() override
'Notify' all objects in this collection.
void SetCurrentCollection()
Set this collection to be the globally accessible collection.
static TCollection * GetCurrentCollection()
Return the globally accessible collection.
void RecursiveRemove(TObject *obj) override
Remove object from this collection and recursively remove the object from all other objects (and coll...
Int_t Capacity() const
void RemoveAll()
virtual bool UseRWLock(Bool_t enable=true)
Set this collection to use a RW lock upon access, making it thread safe.
static Bool_t fgEmptyingGarbage
Bool_t AssertClass(TClass *cl) const
Make sure all objects in this collection inherit from class cl.
static Int_t fgGarbageStack
void ls(Option_t *option="") const override
List (ls) all objects in this collection.
virtual Int_t GrowBy(Int_t delta) const
Increase the collection's capacity by delta slots.
void Streamer(TBuffer &) override
Stream all objects in the collection to or from the I/O buffer.
virtual void AddAll(const TCollection *col)
Add all objects from collection col to this collection.
const char * GetName() const override
Return name of this collection.
void Dump() const override
Dump all objects in this collection.
Int_t Compare(const TObject *obj) const override
Compare two TCollection objects.
virtual const char * GetCollectionEntryName(TObject *entry) const
For given collection entry return the string that is used to identify the object and,...
TClass * IsA() const override
static void EmptyGarbageCollection()
Do the garbage collection.
virtual void PrintCollectionHeader(Option_t *option) const
Print the collection header.
Int_t Write(const char *name=nullptr, Int_t option=0, Int_t bufsize=0) override
Write all objects in this collection.
virtual void SetOwner(Bool_t enable=kTRUE)
Set whether this collection is the owner (enable==true) of its content.
static TCollection * fgCurrentCollection
TString fName
void Browse(TBrowser *b) override
Browse this collection (called by TBrowser).
virtual void Add(TObject *obj)=0
void Print(Option_t *option="") const override
Default print for collections, calls Print(option, 1).
TObject * FindObject(const char *name) const override
Find an object in this collection using its name.
static TObjectTable * fgGarbageCollection
TObject * Clone(const char *newname="") const override
Make a clone of an collection using the Streamer facility.
void AddVector(TObject *obj1,...)
Add all arguments to the collection.
virtual ~TCollection()
TNamed destructor.
static void StartGarbageCollection()
Set up for garbage collection.
static void GarbageCollect(TObject *obj)
Add to the list of things to be cleaned up.
TObject * operator()(const char *name) const
Find an object in this collection by name.
virtual Int_t GetSize() const
Return the capacity of the collection, i.e.
void Paint(Option_t *option="") override
Paint all objects in this collection.
TIter & Begin()
Pointing to the first element of the container.
const TCollection * GetCollection() const
static TIter End()
Pointing to the element after the last - to a nullptr value in our case.
TIter & operator=(const TIter &rhs)
Assigning an TIter to another.
TIterator * fIterator
Iterator abstract base class.
Definition TIterator.h:30
virtual void Reset()=0
virtual TObject * Next()=0
const char * GetName() const override
Returns name of object.
Definition TNamed.h:47
An array of TObjects.
Definition TObjArray.h:31
This class registers all instances of TObject and its derived classes in a hash table.
Mother of all ROOT objects.
Definition TObject.h:41
@ kSingleKey
write collection with single key
Definition TObject.h:91
virtual const char * GetName() const
Returns name of object.
Definition TObject.cxx:456
virtual void Browse(TBrowser *b)
Browse object. May be overridden for another default action.
Definition TObject.cxx:216
R__ALWAYS_INLINE Bool_t TestBit(UInt_t f) const
Definition TObject.h:199
virtual TObject * Clone(const char *newname="") const
Make a clone of an object using the Streamer facility.
Definition TObject.cxx:241
virtual void Streamer(TBuffer &)
Stream an object of class TObject.
Definition TObject.cxx:906
virtual const char * ClassName() const
Returns name of class to which the object belongs.
Definition TObject.cxx:225
virtual Int_t Write(const char *name=nullptr, Int_t option=0, Int_t bufsize=0)
Write this object to the current directory.
Definition TObject.cxx:898
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition TObject.cxx:798
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition TObject.cxx:542
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition TObject.cxx:1005
virtual const char * GetTitle() const
Returns title of object.
Definition TObject.cxx:500
void ResetBit(UInt_t f)
Definition TObject.h:198
@ kCanDelete
if object in a list can be deleted
Definition TObject.h:62
Bool_t MatchB(const TString &s, const TString &mods="", Int_t start=0, Int_t nMaxMatch=10)
Definition TPRegexp.h:78
static Int_t IncreaseDirLevel()
Increase the indentation level for ls().
Definition TROOT.cxx:2887
static void IndentLevel()
Functions used by ls() to indent an object hierarchy.
Definition TROOT.cxx:2895
static Int_t DecreaseDirLevel()
Decrease the indentation level for ls().
Definition TROOT.cxx:2746
Regular expression class.
Definition TRegexp.h:31
Basic string class.
Definition TString.h:139
Ssiz_t Length() const
Definition TString.h:417
int CompareTo(const char *cs, ECaseCompare cmp=kExact) const
Compare a string to char *cs2.
Definition TString.cxx:457
const char * Data() const
Definition TString.h:376
virtual void Streamer(TBuffer &)
Stream a string object.
Definition TString.cxx:1412
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
Definition TString.h:651
virtual void StackTrace()
Print a stack trace.
Definition TSystem.cxx:734
This class implements a mutex interface.
R__ALWAYS_INLINE bool HasBeenDeleted(const TObject *obj)
Check if the TObject's memory has been deleted.
Definition TObject.h:402
bool ContaineeInheritsFrom(TClass *cl, TClass *base)
Return true if 'cl' inherits from 'base'.
const TCollection & EmptyCollection()
Return an empty collection for use with nullptr TRangeCast.
void CallRecursiveRemoveIfNeeded(TObject &obj)
call RecursiveRemove for obj if gROOT is valid and obj.TestBit(kMustCleanup) is true.
Definition TROOT.h:395
Short_t Range(Short_t lb, Short_t ub, Short_t x)
Returns x if lb < x < up, lb if x < lb and ub if x > ub.
Definition TMathBase.h:302