Logo ROOT  
Reference Guide
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*/
33
34#include "TCollection.h"
35#include "Riostream.h"
36#include "Varargs.h"
37#include "TBuffer.h"
38#include "TClass.h"
39#include "TROOT.h"
40#include "TBrowser.h"
41#include "TObjectTable.h"
42#include "TRegexp.h"
43#include "TPRegexp.h"
44#include "TVirtualMutex.h"
45#include "TError.h"
46#include "TSystem.h"
47#include "TObjArray.h"
48#include <sstream>
49
50#include "TSpinLockGuard.h"
51
53
58
61
62#ifdef R__CHECK_COLLECTION_MULTI_ACCESS
63
64void TCollection::TErrorLock::ConflictReport(std::thread::id holder, const char *accesstype,
65 const TCollection *collection, const char *function)
66{
67
68 auto local = std::this_thread::get_id();
69 std::stringstream cur, loc;
70 if (holder == std::thread::id())
71 cur << "None";
72 else
73 cur << "0x" << std::hex << holder;
74 loc << "0x" << std::hex << local;
75
76 // std::cerr << "Error in " << function << ": Access (" << accesstype << ") to a collection (" <<
77 // collection->IsA()->GetName() << ":" << collection <<
78 // ") from multiple threads at a time. holder=" << "0x" << std::hex << holder << " readers=" << fReadSet.size() <<
79 // "0x" << std::hex << local << std::endl;
80
82 "Access (%s) to a collection (%s:%p) from multiple threads at a time. holder=%s readers=%lu intruder=%s",
83 accesstype, collection->IsA()->GetName(), collection, cur.str().c_str(), fReadSet.size(), loc.str().c_str());
84
85 std::set<std::thread::id> tmp;
86 for (auto r : fReadSet) tmp.insert(r);
87 for (auto r : tmp) {
88 std::stringstream reader;
89 reader << "0x" << std::hex << r;
90 ::Error(function, " Readers includes %s", reader.str().c_str());
91 }
93}
94
95void TCollection::TErrorLock::Lock(const TCollection *collection, const char *function)
96{
97 auto local = std::this_thread::get_id();
98
99 std::thread::id holder;
100
101 if (fWriteCurrent.compare_exchange_strong(holder, local)) {
102 // fWriteCurrent was the default id and is now local.
103 ++fWriteCurrentRecurse;
104 // std::cerr << "#" << "0x" << std::hex << local << " acquired first " << collection << " lock:" << this <<
105 // std::endl;
106
107 // Now check if there is any readers lingering
108 if (fReadCurrentRecurse) {
109 if (fReadSet.size() > 1 || fReadSet.find(local) != fReadSet.end()) {
110 ConflictReport(std::thread::id(), "WriteLock while ReadLock taken", collection, function);
111 }
112 }
113 } else {
114 // fWriteCurrent was not the default id and is still the 'holder' thread id
115 // this id is now also in the holder variable
116 if (holder == local) {
117 // The holder was actually this thread, no problem there, we
118 // allow re-entrancy.
119 // std::cerr << "#" << "0x" << std::hex << local << " re-entered " << fWriteCurrentRecurse << " " << collection
120 // << " lock:" << this << std::endl;
121 } else {
122 ConflictReport(holder, "WriteLock", collection, function);
123 }
124 ++fWriteCurrentRecurse;
125 }
126}
127
128void TCollection::TErrorLock::Unlock()
129{
130 auto local = std::this_thread::get_id();
131 auto none = std::thread::id();
132
133 --fWriteCurrentRecurse;
134 if (fWriteCurrentRecurse == 0) {
135 if (fWriteCurrent.compare_exchange_strong(local, none)) {
136 // fWriteCurrent was local and is now none.
137
138 // std::cerr << "#" << "0x" << std::hex << local << " zero and cleaned : " << std::dec << fWriteCurrentRecurse
139 // << " 0x" << std::hex << fWriteCurrent.load() << " lock:" << this << std::endl;
140 } else {
141 // fWriteCurrent was not local, just live it as is.
142
143 // std::cerr << "#" << "0x" << std::hex << local << " zero but somebody else : " << "0x" << std::hex <<
144 // fWriteCurrent.load() << " lock:" << this << std::endl;
145 }
146 } else {
147 // std::cerr << "#" << "0x" << std::hex << local << " still holding " << "0x" << std::hex << fWriteCurrentRecurse
148 // << " lock:" << this << std::endl;
149 }
150
151 // std::cerr << "#" << "0x" << std::hex << local << " ended with : " << std::dec << fWriteCurrentRecurse << " 0x" <<
152 // std::hex << fWriteCurrent.load() << " lock:" << this << std::endl;
153}
154
155void TCollection::TErrorLock::ReadLock(const TCollection *collection, const char *function)
156{
157 auto local = std::this_thread::get_id();
158
159 {
160 ROOT::Internal::TSpinLockGuard guard(fSpinLockFlag);
161 fReadSet.insert(local); // this is not thread safe ...
162 }
163 ++fReadCurrentRecurse;
164
165 if (fWriteCurrentRecurse) {
166 auto holder = fWriteCurrent.load();
167 if (holder != local) ConflictReport(holder, "ReadLock with WriteLock taken", collection, function);
168 }
169}
170
171void TCollection::TErrorLock::ReadUnlock()
172{
173 auto local = std::this_thread::get_id();
174 {
175 ROOT::Internal::TSpinLockGuard guard(fSpinLockFlag);
176 fReadSet.erase(local); // this is not thread safe ...
177 }
178 --fReadCurrentRecurse;
179}
180
181#endif // R__CHECK_COLLECTION_MULTI_ACCESS
182
183////////////////////////////////////////////////////////////////////////////////
184/// TNamed destructor.
185
187{
188 // Required since we overload TObject::Hash.
190}
191
192////////////////////////////////////////////////////////////////////////////////
193/// Add all objects from collection col to this collection.
194
197 TIter next(col);
199
200 while ((obj = next()))
201 Add(obj);
202}
203
204////////////////////////////////////////////////////////////////////////////////
205/// Add all arguments to the collection. The list of objects must be
206/// terminated by 0, e.g.: l.AddVector(o1, o2, o3, o4, 0);
207
209{
210 va_list ap;
211 va_start(ap, va_(obj1));
212 TObject *obj;
213
214 Add(va_(obj1));
215 while ((obj = va_arg(ap, TObject *)))
216 Add(obj);
217 va_end(ap);
218}
219
220////////////////////////////////////////////////////////////////////////////////
221/// Make sure all objects in this collection inherit from class cl.
222
224{
225 TObject *obj;
226 TIter next(this);
227 Bool_t error = kFALSE;
228
229 if (!cl) {
230 Error("AssertClass", "class == 0");
231 return kTRUE;
232 }
233
234 for (int i = 0; (obj = next()); i++)
235 if (!obj->InheritsFrom(cl)) {
236 Error("AssertClass", "element %d is not an instance of class %s (%s)",
237 i, cl->GetName(), obj->ClassName());
238 error = kTRUE;
239 }
240 return error;
241}
242
243////////////////////////////////////////////////////////////////////////////////
244/// Browse this collection (called by TBrowser).
245/// If b=0, there is no Browse call TObject::Browse(0) instead.
246/// This means TObject::Inspect() will be invoked indirectly
247
249{
250 TIter next(this);
251 TObject *obj;
252
253 if (b)
254 while ((obj = next())) b->Add(obj);
255 else
257}
258
259////////////////////////////////////////////////////////////////////////////////
260/// Make a clone of an collection using the Streamer facility.
261/// If newname is specified, this will be the name of the new collection.
262
263TObject *TCollection::Clone(const char *newname) const
264{
265 TCollection *new_collection = (TCollection*)TObject::Clone(newname);
266 if (newname && strlen(newname)) new_collection->SetName(newname);
267 return new_collection;
268}
269
270
271////////////////////////////////////////////////////////////////////////////////
272/// Compare two TCollection objects. Returns 0 when equal, -1 when this is
273/// smaller and +1 when bigger (like strcmp()).
274
276{
277 if (this == obj) return 0;
278 return fName.CompareTo(obj->GetName());
279}
280
281////////////////////////////////////////////////////////////////////////////////
282/// Draw all objects in this collection.
283
285{
286 TIter next(this);
288
289 while ((object = next())) {
290 object->Draw(option);
291 }
292}
293
294////////////////////////////////////////////////////////////////////////////////
295/// Dump all objects in this collection.
296
298{
299 TIter next(this);
301
302 while ((object = next())) {
303 object->Dump();
304 }
305}
306
307////////////////////////////////////////////////////////////////////////////////
308/// Find an object in this collection using its name. Requires a sequential
309/// scan till the object has been found. Returns 0 if object with specified
310/// name is not found.
311
313{
314 TIter next(this);
315 TObject *obj;
316
317 while ((obj = next()))
318 if (!strcmp(name, obj->GetName())) return obj;
319 return 0;
320}
321
322////////////////////////////////////////////////////////////////////////////////
323/// Find an object in this collection by name.
324
326{
327 return FindObject(name);
328}
329
330////////////////////////////////////////////////////////////////////////////////
331/// Find an object in this collection using the object's IsEqual()
332/// member function. Requires a sequential scan till the object has
333/// been found. Returns 0 if object is not found.
334/// Typically this function is overridden by a more efficient version
335/// in concrete collection classes (e.g. THashTable).
336
338{
339 TIter next(this);
340 TObject *ob;
341
342 while ((ob = next()))
343 if (ob->IsEqual(obj)) return ob;
344 return 0;
345}
346
347////////////////////////////////////////////////////////////////////////////////
348/// Return name of this collection.
349/// if no name, return the collection class name.
350
351const char *TCollection::GetName() const
352{
353 if (fName.Length() > 0) return fName.Data();
354 return ClassName();
355}
356
357////////////////////////////////////////////////////////////////////////////////
358/// Increase the collection's capacity by delta slots.
359
361{
362 if (delta < 0) {
363 Error("GrowBy", "delta < 0");
364 delta = Capacity();
365 }
366 return Capacity() + TMath::Range(2, kMaxInt - Capacity(), delta);
367}
368
369////////////////////////////////////////////////////////////////////////////////
370/// Returns true if object is a null pointer.
371
372Bool_t TCollection::IsArgNull(const char *where, const TObject *obj) const
373{
374 return obj ? kFALSE : (Error(where, "argument is a null pointer"), kTRUE);
375}
376
377////////////////////////////////////////////////////////////////////////////////
378/// List (ls) all objects in this collection.
379/// Wildcarding supported, eg option="xxx*" lists only objects
380/// with names xxx*.
381
382void TCollection::ls(Option_t *option) const
383{
385 std::cout <<"OBJ: " << IsA()->GetName() << "\t" << GetName() << "\t" << GetTitle() << " : "
386 << Int_t(TestBit(kCanDelete)) << std::endl;
387
388 TRegexp re(option,kTRUE);
389 TIter next(this);
391 char *star = 0;
392 if (option) star = (char*)strchr(option,'*');
393
395 while ((object = next())) {
396 if (star) {
397 TString s = object->GetName();
398 if (s != option && s.Index(re) == kNPOS) continue;
399 }
400 object->ls(option);
401 }
403}
404
405////////////////////////////////////////////////////////////////////////////////
406/// 'Notify' all objects in this collection.
408{
409 Bool_t success = true;
410 for (auto obj : *this) success &= obj->Notify();
411 return success;
412}
413
414////////////////////////////////////////////////////////////////////////////////
415/// Paint all objects in this collection.
416
418{
419 this->R__FOR_EACH(TObject,Paint)(option);
420}
421
422////////////////////////////////////////////////////////////////////////////////
423/// Print the collection header.
424
426{
428 printf("Collection name='%s', class='%s', size=%d\n",
429 GetName(), ClassName(), GetSize());
430}
431
432////////////////////////////////////////////////////////////////////////////////
433/// For given collection entry return the string that is used to
434/// identify the object and, potentially, perform wildcard/regexp
435/// filtering on.
436
438{
439 return entry->GetName();
440}
441
442////////////////////////////////////////////////////////////////////////////////
443/// Print the collection entry.
444
445void TCollection::PrintCollectionEntry(TObject* entry, Option_t* option, Int_t recurse) const
446{
447 TCollection* coll = dynamic_cast<TCollection*>(entry);
448 if (coll) {
449 coll->Print(option, recurse);
450 } else {
452 entry->Print(option);
453 }
454}
455
456////////////////////////////////////////////////////////////////////////////////
457/// Default print for collections, calls Print(option, 1).
458/// This will print the collection header and Print() methods of
459/// all the collection entries.
460///
461/// If you want to override Print() for a collection class, first
462/// see if you can accomplish it by overriding the following protected
463/// methods:
464/// ~~~ {.cpp}
465/// void PrintCollectionHeader(Option_t* option) const;
466/// const char* GetCollectionEntryName(TObject* entry) const;
467/// void PrintCollectionEntry(TObject* entry, Option_t* option, Int_t recurse) const;
468/// ~~~
469/// Otherwise override the `Print(Option_t *option, Int_t)`
470/// variant. Remember to declare:
471/// ~~~ {.cpp}
472/// using TCollection::Print;
473/// ~~~
474/// somewhere close to the method declaration.
475
476void TCollection::Print(Option_t *option) const
477{
478 Print(option, 1);
479}
480
481////////////////////////////////////////////////////////////////////////////////
482/// Print the collection header and its elements.
483///
484/// If recurse is non-zero, descend into printing of
485/// collection-entries with recurse - 1.
486/// This means, if recurse is negative, the recursion is infinite.
487///
488/// Option is passed recursively.
489
490void TCollection::Print(Option_t *option, Int_t recurse) const
491{
492 PrintCollectionHeader(option);
493
494 if (recurse != 0)
495 {
496 TIter next(this);
498
500 while ((object = next())) {
501 PrintCollectionEntry(object, option, recurse - 1);
502 }
504 }
505}
506
507////////////////////////////////////////////////////////////////////////////////
508/// Print the collection header and its elements that match the wildcard.
509///
510/// If recurse is non-zero, descend into printing of
511/// collection-entries with recurse - 1.
512/// This means, if recurse is negative, the recursion is infinite.
513///
514/// Option is passed recursively, but wildcard is only used on the
515/// first level.
516
517void TCollection::Print(Option_t *option, const char* wildcard, Int_t recurse) const
518{
519 PrintCollectionHeader(option);
520
521 if (recurse != 0)
522 {
523 if (!wildcard) wildcard = "";
524 TRegexp re(wildcard, kTRUE);
525 Int_t nch = strlen(wildcard);
526 TIter next(this);
528
530 while ((object = next())) {
532 if (nch == 0 || s == wildcard || s.Index(re) != kNPOS) {
533 PrintCollectionEntry(object, option, recurse - 1);
534 }
535 }
537 }
538}
539
540////////////////////////////////////////////////////////////////////////////////
541/// Print the collection header and its elements that match the regexp.
542///
543/// If recurse is non-zero, descend into printing of
544/// collection-entries with recurse - 1.
545/// This means, if recurse is negative, the recursion is infinite.
546///
547/// Option is passed recursively, but regexp is only used on the
548/// first level.
549
550void TCollection::Print(Option_t *option, TPRegexp& regexp, Int_t recurse) const
551{
552 PrintCollectionHeader(option);
553
554 if (recurse != 0)
555 {
556 TIter next(this);
558
560 while ((object = next())) {
562 if (regexp.MatchB(s)) {
563 PrintCollectionEntry(object, option, recurse - 1);
564 }
565 }
567 }
568}
569
570////////////////////////////////////////////////////////////////////////////////
571/// Remove object from this collection and recursively remove the object
572/// from all other objects (and collections).
573
575{
576 if (!obj) return;
577
578 // Scan list and remove obj in the list itself
579 while (Remove(obj))
580 ;
581
582 // Scan again the list and invoke RecursiveRemove for all objects
583 TIter next(this);
585
586 while ((object = next())) {
587 if (object->TestBit(kNotDeleted)) object->RecursiveRemove(obj);
588 }
589}
590
591////////////////////////////////////////////////////////////////////////////////
592/// Remove all objects in collection col from this collection.
593
595{
596 TIter next(col);
597 TObject *obj;
598
599 while ((obj = next()))
600 Remove(obj);
601}
602
603////////////////////////////////////////////////////////////////////////////////
604/// Stream all objects in the collection to or from the I/O buffer.
605
606void TCollection::Streamer(TBuffer &b)
607{
608 Int_t nobjects;
609 TObject *obj;
610 UInt_t R__s, R__c;
611
612 if (b.IsReading()) {
613 Version_t v = b.ReadVersion(&R__s, &R__c);
614 if (v > 2)
615 TObject::Streamer(b);
616 if (v > 1)
617 fName.Streamer(b);
618 b >> nobjects;
619 for (Int_t i = 0; i < nobjects; i++) {
620 b >> obj;
621 Add(obj);
622 }
623 b.CheckByteCount(R__s, R__c,TCollection::IsA());
624 } else {
625 R__c = b.WriteVersion(TCollection::IsA(), kTRUE);
626 TObject::Streamer(b);
627 fName.Streamer(b);
628 nobjects = GetSize();
629 b << nobjects;
630
631 TIter next(this);
632
633 while ((obj = next())) {
634 b << obj;
635 }
636 b.SetByteCount(R__c, kTRUE);
637 }
638}
639
640////////////////////////////////////////////////////////////////////////////////
641/// Write all objects in this collection. By default all objects in
642/// the collection are written individually (each object gets its
643/// own key). Note, this is recursive, i.e. objects in collections
644/// in the collection are also written individually. To write all
645/// objects using a single key specify a name and set option to
646/// TObject::kSingleKey (i.e. 1).
647
648Int_t TCollection::Write(const char *name, Int_t option, Int_t bsize) const
649{
650 if ((option & kSingleKey)) {
651 return TObject::Write(name, option, bsize);
652 } else {
653 option &= ~kSingleKey;
654 Int_t nbytes = 0;
655 TIter next(this);
656 TObject *obj;
657 while ((obj = next())) {
658 nbytes += obj->Write(name, option, bsize);
659 }
660 return nbytes;
661 }
662}
663
664////////////////////////////////////////////////////////////////////////////////
665/// Write all objects in this collection. By default all objects in
666/// the collection are written individually (each object gets its
667/// own key). Note, this is recursive, i.e. objects in collections
668/// in the collection are also written individually. To write all
669/// objects using a single key specify a name and set option to
670/// TObject::kSingleKey (i.e. 1).
671
672Int_t TCollection::Write(const char *name, Int_t option, Int_t bsize)
673{
674 return ((const TCollection*)this)->Write(name,option,bsize);
675}
676
677////////////////////////////////////////////////////////////////////////////////
678/// Return the globally accessible collection.
679
681{
682 return fgCurrentCollection;
683}
684
685////////////////////////////////////////////////////////////////////////////////
686/// Set this collection to be the globally accesible collection.
687
689{
690 fgCurrentCollection = this;
691}
692
693////////////////////////////////////////////////////////////////////////////////
694/// Set up for garbage collection.
695
697{
699 if (!fgGarbageCollection) {
702 fgGarbageStack = 0;
703 }
705}
706
707////////////////////////////////////////////////////////////////////////////////
708/// Do the garbage collection.
709
711{
719 }
720}
721
722////////////////////////////////////////////////////////////////////////////////
723/// Add to the list of things to be cleaned up.
724
726{
727 {
730 if (!fgEmptyingGarbage) {
732 return;
733 }
734 }
735 }
736 delete obj;
737}
738
739////////////////////////////////////////////////////////////////////////////////
740/// Set whether this collection is the owner (enable==true)
741/// of its content. If it is the owner of its contents,
742/// these objects will be deleted whenever the collection itself
743/// is delete. The objects might also be deleted or destructed when Clear
744/// is called (depending on the collection).
745
747{
748 if (enable)
750 else
752}
753
754////////////////////////////////////////////////////////////////////////////////
755/// Set this collection to use a RW lock upon access, making it thread safe.
756/// Return the previous state.
757///
758/// Note: To test whether the usage is enabled do:
759/// collection->TestBit(TCollection::kUseRWLock);
760
762{
763 bool prev = TestBit(TCollection::kUseRWLock);
765 return prev;
766}
767
768////////////////////////////////////////////////////////////////////////////////
769/// Copy a TIter. This involves allocating a new TIterator of the right
770/// sub class and assigning it with the original.
771
772TIter::TIter(const TIter &iter)
773{
774 if (iter.fIterator) {
776 fIterator->operator=(*iter.fIterator);
777 } else
778 fIterator = 0;
779}
780
781////////////////////////////////////////////////////////////////////////////////
782/// Assigning an TIter to another. This involves allocating a new TIterator
783/// of the right sub class and assigning it with the original.
784
786{
787 if (this != &rhs) {
788 if (rhs.fIterator) {
789 delete fIterator;
791 fIterator->operator=(*rhs.fIterator);
792 }
793 }
794 return *this;
795}
796
797////////////////////////////////////////////////////////////////////////////////
798/// Pointing to the first element of the container.
799
801{
802 fIterator->Reset();
803 fIterator->Next();
804 return *this;
805}
806
807////////////////////////////////////////////////////////////////////////////////
808/// Pointing to the element after the last - to a nullptr value in our case.
809
811{
812 return TIter(static_cast<TIterator*>(nullptr));
813}
814
815////////////////////////////////////////////////////////////////////////////////
816/// Return an empty collection for use with nullptr TRangeCast
817
819{
820 static TObjArray sEmpty;
821 return sEmpty;
822}
823
824////////////////////////////////////////////////////////////////////////////////
825/// Return true if 'cl' inherits from 'base'.
826
828{
829 return cl->InheritsFrom(base);
830}
ROOT::R::TRInterface & r
Definition: Object.C:4
#define SafeDelete(p)
Definition: RConfig.hxx:543
#define b(i)
Definition: RSha256.hxx:100
const Ssiz_t kNPOS
Definition: RtypesCore.h:113
int Int_t
Definition: RtypesCore.h:43
const Int_t kMaxInt
Definition: RtypesCore.h:101
short Version_t
Definition: RtypesCore.h:63
unsigned int UInt_t
Definition: RtypesCore.h:44
const Bool_t kFALSE
Definition: RtypesCore.h:90
bool Bool_t
Definition: RtypesCore.h:61
const Bool_t kTRUE
Definition: RtypesCore.h:89
const char Option_t
Definition: RtypesCore.h:64
#define ClassImp(name)
Definition: Rtypes.h:361
TVirtualMutex * gCollectionMutex
Definition: TCollection.cxx:52
#define R__FOR_EACH(type, proc)
Definition: TCollection.h:448
void Error(const char *location, const char *msgfmt,...)
XFontStruct * id
Definition: TGX11.cxx:108
char name[80]
Definition: TGX11.cxx:109
R__EXTERN TSystem * gSystem
Definition: TSystem.h:556
#define R__LOCKGUARD2(mutex)
#define va_(arg)
Definition: Varargs.h:41
A spin mutex-as-code-guard class.
Using a TBrowser one can browse all ROOT objects.
Definition: TBrowser.h:37
Buffer base class used for serializing objects.
Definition: TBuffer.h:42
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition: TClass.h:80
Bool_t InheritsFrom(const char *cl) const
Return kTRUE if this class inherits from a class with name "classname".
Definition: TClass.cxx:4837
Collection abstract base class.
Definition: TCollection.h:63
virtual void Dump() const
Dump all objects in this collection.
virtual TObject * Remove(TObject *obj)=0
virtual TIterator * MakeIterator(Bool_t dir=kIterForward) const =0
virtual void ls(Option_t *option="") const
List (ls) all objects in this collection.
virtual Bool_t Notify()
'Notify' all objects in this collection.
virtual TObject * FindObject(const char *name) const
Find an object in this collection using its name.
virtual void PrintCollectionEntry(TObject *entry, Option_t *option, Int_t recurse) const
Print the collection entry.
Bool_t IsArgNull(const char *where, const TObject *obj) const
Returns true if object is a null pointer.
virtual const char * GetName() const
Return name of this collection.
void SetCurrentCollection()
Set this collection to be the globally accesible collection.
static TCollection * GetCurrentCollection()
Return the globally accessible collection.
Int_t Capacity() const
Definition: TCollection.h:165
void RemoveAll()
Definition: TCollection.h:202
virtual void Print(Option_t *option="") const
Default print for collections, calls Print(option, 1).
static Bool_t fgEmptyingGarbage
Definition: TCollection.h:134
virtual bool UseRWLock()
Set this collection to use a RW lock upon access, making it thread safe.
Bool_t AssertClass(TClass *cl) const
Make sure all objects in this collection inherit from class cl.
static Int_t fgGarbageStack
Definition: TCollection.h:135
virtual Int_t GrowBy(Int_t delta) const
Increase the collection's capacity by delta slots.
void SetName(const char *name)
Definition: TCollection.h:204
virtual void AddAll(const TCollection *col)
Add all objects from collection col to this collection.
virtual void Draw(Option_t *option="")
Draw all objects in this collection.
virtual void RecursiveRemove(TObject *obj)
Remove object from this collection and recursively remove the object from all other objects (and coll...
void Browse(TBrowser *b)
Browse this collection (called by TBrowser).
virtual const char * GetCollectionEntryName(TObject *entry) const
For given collection entry return the string that is used to identify the object and,...
static void EmptyGarbageCollection()
Do the garbage collection.
virtual void PrintCollectionHeader(Option_t *option) const
Print the collection header.
virtual void SetOwner(Bool_t enable=kTRUE)
Set whether this collection is the owner (enable==true) of its content.
static TCollection * fgCurrentCollection
Definition: TCollection.h:132
TString fName
Definition: TCollection.h:147
virtual void Add(TObject *obj)=0
virtual TObject * Clone(const char *newname="") const
Make a clone of an collection using the Streamer facility.
Int_t Compare(const TObject *obj) const
Compare two TCollection objects.
static TObjectTable * fgGarbageCollection
Definition: TCollection.h:133
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.
virtual void Paint(Option_t *option="")
Paint all objects in this collection.
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.
Definition: TCollection.h:182
virtual Int_t Write(const char *name=0, Int_t option=0, Int_t bufsize=0)
Write all objects in this collection.
TIter & Begin()
Pointing to the first element of the container.
const TCollection * GetCollection() const
Definition: TCollection.h:250
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
Definition: TCollection.h:236
Iterator abstract base class.
Definition: TIterator.h:30
virtual void Reset()=0
virtual TObject * Next()=0
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
An array of TObjects.
Definition: TObjArray.h:37
This class registers all instances of TObject and its derived classes in a hash table.
Definition: TObjectTable.h:35
void Delete(Option_t *opt="")
Delete all objects stored in the TObjectTable.
void Add(TObject *obj)
Add an object to the object table.
Mother of all ROOT objects.
Definition: TObject.h:37
virtual Bool_t Notify()
This method must be overridden to handle object notification.
Definition: TObject.cxx:506
virtual Int_t Write(const char *name=0, Int_t option=0, Int_t bufsize=0)
Write this object to the current directory.
Definition: TObject.cxx:796
virtual Bool_t IsEqual(const TObject *obj) const
Default equal comparison (objects are equal if they have the same address in memory).
Definition: TObject.cxx:483
@ kSingleKey
write collection with single key
Definition: TObject.h:87
virtual const char * GetName() const
Returns name of object.
Definition: TObject.cxx:357
virtual void Browse(TBrowser *b)
Browse object. May be overridden for another default action.
Definition: TObject.cxx:119
R__ALWAYS_INLINE Bool_t TestBit(UInt_t f) const
Definition: TObject.h:187
virtual TObject * Clone(const char *newname="") const
Make a clone of an object using the Streamer facility.
Definition: TObject.cxx:144
@ kNotDeleted
object has not been deleted
Definition: TObject.h:78
virtual const char * ClassName() const
Returns name of class to which the object belongs.
Definition: TObject.cxx:128
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition: TObject.cxx:694
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition: TObject.cxx:443
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:891
virtual const char * GetTitle() const
Returns title of object.
Definition: TObject.cxx:401
virtual void Print(Option_t *option="") const
This method must be overridden when a class wants to print itself.
Definition: TObject.cxx:550
void ResetBit(UInt_t f)
Definition: TObject.h:186
@ kCanDelete
if object in a list can be deleted
Definition: TObject.h:58
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:2773
static void IndentLevel()
Functions used by ls() to indent an object hierarchy.
Definition: TROOT.cxx:2781
static Int_t DecreaseDirLevel()
Decrease the indentation level for ls().
Definition: TROOT.cxx:2677
Regular expression class.
Definition: TRegexp.h:31
Basic string class.
Definition: TString.h:131
Ssiz_t Length() const
Definition: TString.h:405
int CompareTo(const char *cs, ECaseCompare cmp=kExact) const
Compare a string to char *cs2.
Definition: TString.cxx:418
const char * Data() const
Definition: TString.h:364
virtual void StackTrace()
Print a stack trace.
Definition: TSystem.cxx:730
This class implements a mutex interface.
Definition: TVirtualMutex.h:34
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 function(const Char_t *name_, T fun, const Char_t *docstring=0)
Definition: RExports.h:151
void CallRecursiveRemoveIfNeeded(TObject &obj)
call RecursiveRemove for obj if gROOT is valid and obj.TestBit(kMustCleanup) is true.
Definition: TROOT.h:395
static constexpr double s
Short_t Range(Short_t lb, Short_t ub, Short_t x)
Definition: TMathBase.h:244