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 "TMathBase.h"
79
80#include <iostream>
81#include <sstream>
82
83#include "TSpinLockGuard.h"
84
86
91
94
95#ifdef R__CHECK_COLLECTION_MULTI_ACCESS
96
97void TCollection::TErrorLock::ConflictReport(std::thread::id holder, const char *accesstype,
98 const TCollection *collection, const char *function)
99{
100
101 auto local = std::this_thread::get_id();
102 std::stringstream cur, loc;
103 if (holder == std::thread::id())
104 cur << "None";
105 else
106 cur << "0x" << std::hex << holder;
107 loc << "0x" << std::hex << local;
108
109 // std::cerr << "Error in " << function << ": Access (" << accesstype << ") to a collection (" <<
110 // collection->IsA()->GetName() << ":" << collection <<
111 // ") from multiple threads at a time. holder=" << "0x" << std::hex << holder << " readers=" << fReadSet.size() <<
112 // "0x" << std::hex << local << std::endl;
113
114 ::Error(function,
115 "Access (%s) to a collection (%s:%p) from multiple threads at a time. holder=%s readers=%lu intruder=%s",
116 accesstype, collection->IsA()->GetName(), collection, cur.str().c_str(), fReadSet.size(), loc.str().c_str());
117
118 std::set<std::thread::id> tmp;
119 for (auto r : fReadSet) tmp.insert(r);
120 for (auto r : tmp) {
121 std::stringstream reader;
122 reader << "0x" << std::hex << r;
123 ::Error(function, " Readers includes %s", reader.str().c_str());
124 }
126}
127
128void TCollection::TErrorLock::Lock(const TCollection *collection, const char *function)
129{
130 auto local = std::this_thread::get_id();
131
132 std::thread::id holder;
133
134 if (fWriteCurrent.compare_exchange_strong(holder, local)) {
135 // fWriteCurrent was the default id and is now local.
137 // std::cerr << "#" << "0x" << std::hex << local << " acquired first " << collection << " lock:" << this <<
138 // std::endl;
139
140 // Now check if there is any readers lingering
142 if (fReadSet.size() > 1 || fReadSet.find(local) != fReadSet.end()) {
143 ConflictReport(std::thread::id(), "WriteLock while ReadLock taken", collection, function);
144 }
145 }
146 } else {
147 // fWriteCurrent was not the default id and is still the 'holder' thread id
148 // this id is now also in the holder variable
149 if (holder == local) {
150 // The holder was actually this thread, no problem there, we
151 // allow re-entrancy.
152 // std::cerr << "#" << "0x" << std::hex << local << " re-entered " << fWriteCurrentRecurse << " " << collection
153 // << " lock:" << this << std::endl;
154 } else {
155 ConflictReport(holder, "WriteLock", collection, function);
156 }
158 }
159}
160
161void TCollection::TErrorLock::Unlock()
162{
163 auto local = std::this_thread::get_id();
164 auto none = std::thread::id();
165
167 if (fWriteCurrentRecurse == 0) {
168 if (fWriteCurrent.compare_exchange_strong(local, none)) {
169 // fWriteCurrent was local and is now none.
170
171 // std::cerr << "#" << "0x" << std::hex << local << " zero and cleaned : " << std::dec << fWriteCurrentRecurse
172 // << " 0x" << std::hex << fWriteCurrent.load() << " lock:" << this << std::endl;
173 } else {
174 // fWriteCurrent was not local, just live it as is.
175
176 // std::cerr << "#" << "0x" << std::hex << local << " zero but somebody else : " << "0x" << std::hex <<
177 // fWriteCurrent.load() << " lock:" << this << std::endl;
178 }
179 } else {
180 // std::cerr << "#" << "0x" << std::hex << local << " still holding " << "0x" << std::hex << fWriteCurrentRecurse
181 // << " lock:" << this << std::endl;
182 }
183
184 // std::cerr << "#" << "0x" << std::hex << local << " ended with : " << std::dec << fWriteCurrentRecurse << " 0x" <<
185 // std::hex << fWriteCurrent.load() << " lock:" << this << std::endl;
186}
187
188void TCollection::TErrorLock::ReadLock(const TCollection *collection, const char *function)
189{
190 auto local = std::this_thread::get_id();
191
192 {
194 fReadSet.insert(local); // this is not thread safe ...
195 }
199 auto holder = fWriteCurrent.load();
200 if (holder != local) ConflictReport(holder, "ReadLock with WriteLock taken", collection, function);
201 }
202}
203
204void TCollection::TErrorLock::ReadUnlock()
205{
206 auto local = std::this_thread::get_id();
207 {
209 fReadSet.erase(local); // this is not thread safe ...
210 }
212}
213
214#endif // R__CHECK_COLLECTION_MULTI_ACCESS
215
216////////////////////////////////////////////////////////////////////////////////
217/// TNamed destructor.
218
220{
221 // Required since we overload TObject::Hash.
223}
224
225////////////////////////////////////////////////////////////////////////////////
226/// Add all objects from collection col to this collection.
227
229{
230 TIter next(col);
231 TObject *obj;
232
233 while ((obj = next()))
234 Add(obj);
235}
236
237////////////////////////////////////////////////////////////////////////////////
238/// Add all arguments to the collection. The list of objects must be
239/// terminated by 0, e.g.: l.AddVector(o1, o2, o3, o4, 0);
240
242{
243 va_list ap;
244 va_start(ap, va_(obj1));
245 TObject *obj;
246
247 Add(va_(obj1));
248 while ((obj = va_arg(ap, TObject *)))
249 Add(obj);
250 va_end(ap);
251}
252
253////////////////////////////////////////////////////////////////////////////////
254/// Make sure all objects in this collection inherit from class cl.
255
257{
258 TObject *obj;
259 TIter next(this);
260 Bool_t error = kFALSE;
261
262 if (!cl) {
263 Error("AssertClass", "class == 0");
264 return kTRUE;
265 }
266
267 for (int i = 0; (obj = next()); i++)
268 if (!obj->InheritsFrom(cl)) {
269 Error("AssertClass", "element %d is not an instance of class %s (%s)",
270 i, cl->GetName(), obj->ClassName());
271 error = kTRUE;
272 }
273 return error;
274}
275
276////////////////////////////////////////////////////////////////////////////////
277/// Browse this collection (called by TBrowser).
278/// If b=0, there is no Browse call TObject::Browse(0) instead.
279/// This means TObject::Inspect() will be invoked indirectly
280
282{
283 TIter next(this);
284 TObject *obj;
285
286 if (b)
287 while ((obj = next())) b->Add(obj);
288 else
290}
291
292////////////////////////////////////////////////////////////////////////////////
293/// Make a clone of an collection using the Streamer facility.
294/// If newname is specified, this will be the name of the new collection.
295
302
303
304////////////////////////////////////////////////////////////////////////////////
305/// Compare two TCollection objects. Returns 0 when equal, -1 when this is
306/// smaller and +1 when bigger (like strcmp()).
307
309{
310 if (this == obj) return 0;
311 return fName.CompareTo(obj->GetName());
312}
313
314////////////////////////////////////////////////////////////////////////////////
315/// Draw all objects in this collection.
316
318{
319 TIter next(this);
321
322 while ((object = next())) {
323 object->Draw(option);
324 }
325}
326
327////////////////////////////////////////////////////////////////////////////////
328/// Dump all objects in this collection.
329
331{
332 TIter next(this);
334
335 while ((object = next())) {
336 object->Dump();
337 }
338}
339
340////////////////////////////////////////////////////////////////////////////////
341/// Find an object in this collection using its name. Requires a sequential
342/// scan till the object has been found. Returns 0 if object with specified
343/// name is not found.
344
346{
347 TIter next(this);
348 TObject *obj;
349
350 while ((obj = next()))
351 if (!strcmp(name, obj->GetName())) return obj;
352 return nullptr;
353}
354
355////////////////////////////////////////////////////////////////////////////////
356/// Find an object in this collection by name.
357
359{
360 return FindObject(name);
361}
362
363////////////////////////////////////////////////////////////////////////////////
364/// Find an object in this collection using the object's IsEqual()
365/// member function. Requires a sequential scan till the object has
366/// been found. Returns 0 if object is not found.
367/// Typically this function is overridden by a more efficient version
368/// in concrete collection classes (e.g. THashTable).
369
371{
372 TIter next(this);
373 TObject *ob;
374
375 while ((ob = next()))
376 if (ob->IsEqual(obj)) return ob;
377 return nullptr;
378}
379
380////////////////////////////////////////////////////////////////////////////////
381/// Return name of this collection.
382/// if no name, return the collection class name.
383
384const char *TCollection::GetName() const
385{
386 if (fName.Length() > 0) return fName.Data();
387 return ClassName();
388}
389
390////////////////////////////////////////////////////////////////////////////////
391/// Increase the collection's capacity by delta slots.
392
394{
395 if (delta < 0) {
396 Error("GrowBy", "delta < 0");
397 delta = Capacity();
398 }
399 return Capacity() + TMath::Range(2, kMaxInt - Capacity(), delta);
400}
401
402////////////////////////////////////////////////////////////////////////////////
403/// Returns true if object is a null pointer.
404
405Bool_t TCollection::IsArgNull(const char *where, const TObject *obj) const
406{
407 return obj ? kFALSE : (Error(where, "argument is a null pointer"), kTRUE);
408}
409
410////////////////////////////////////////////////////////////////////////////////
411/// List (ls) all objects in this collection.
412/// Wildcarding supported, eg option="xxx*" lists only objects
413/// with names xxx*.
414
416{
418 std::cout <<"OBJ: " << IsA()->GetName() << "\t" << GetName() << "\t" << GetTitle() << " : "
419 << Int_t(TestBit(kCanDelete)) << std::endl;
420
421 TRegexp re(option,kTRUE);
422 TIter next(this);
424 char *star = nullptr;
425 if (option) star = (char*)strchr(option,'*');
426
428 while ((object = next())) {
429 if (star) {
430 TString s = object->GetName();
431 if (s != option && s.Index(re) == kNPOS) continue;
432 }
433 object->ls(option);
434 }
436}
437
438////////////////////////////////////////////////////////////////////////////////
439/// 'Notify' all objects in this collection.
441{
442 Bool_t success = true;
443 for (auto obj : *this) success &= obj->Notify();
444 return success;
445}
446
447////////////////////////////////////////////////////////////////////////////////
448/// Paint all objects in this collection.
449
454
455////////////////////////////////////////////////////////////////////////////////
456/// Print the collection header.
457
459{
461 printf("Collection name='%s', class='%s', size=%d\n",
462 GetName(), ClassName(), GetSize());
463}
464
465////////////////////////////////////////////////////////////////////////////////
466/// For given collection entry return the string that is used to
467/// identify the object and, potentially, perform wildcard/regexp
468/// filtering on.
469
471{
472 return entry->GetName();
473}
474
475////////////////////////////////////////////////////////////////////////////////
476/// Print the collection entry.
477
479{
480 TCollection* coll = dynamic_cast<TCollection*>(entry);
481 if (coll) {
482 coll->Print(option, recurse);
483 } else {
485 entry->Print(option);
486 }
487}
488
489////////////////////////////////////////////////////////////////////////////////
490/// Default print for collections, calls Print(option, 1).
491/// This will print the collection header and Print() methods of
492/// all the collection entries.
493///
494/// If you want to override Print() for a collection class, first
495/// see if you can accomplish it by overriding the following protected
496/// methods:
497/// ~~~ {.cpp}
498/// void PrintCollectionHeader(Option_t* option) const;
499/// const char* GetCollectionEntryName(TObject* entry) const;
500/// void PrintCollectionEntry(TObject* entry, Option_t* option, Int_t recurse) const;
501/// ~~~
502/// Otherwise override the `Print(Option_t *option, Int_t)`
503/// variant. Remember to declare:
504/// ~~~ {.cpp}
505/// using TCollection::Print;
506/// ~~~
507/// somewhere close to the method declaration.
508
510{
511 Print(option, 1);
512}
513
514////////////////////////////////////////////////////////////////////////////////
515/// Print the collection header and its elements.
516///
517/// If recurse is non-zero, descend into printing of
518/// collection-entries with recurse - 1.
519/// This means, if recurse is negative, the recursion is infinite.
520///
521/// Option is passed recursively.
522
524{
526
527 if (recurse != 0)
528 {
529 TIter next(this);
531
533 while ((object = next())) {
534 PrintCollectionEntry(object, option, recurse - 1);
535 }
537 }
538}
539
540////////////////////////////////////////////////////////////////////////////////
541/// Print the collection header and its elements that match the wildcard.
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 wildcard is only used on the
548/// first level.
549
551{
553
554 if (recurse != 0)
555 {
556 if (!wildcard) wildcard = "";
559 TIter next(this);
561
563 while ((object = next())) {
565 if (nch == 0 || s == wildcard || s.Index(re) != kNPOS) {
566 PrintCollectionEntry(object, option, recurse - 1);
567 }
568 }
570 }
571}
572
573////////////////////////////////////////////////////////////////////////////////
574/// Print the collection header and its elements that match the regexp.
575///
576/// If recurse is non-zero, descend into printing of
577/// collection-entries with recurse - 1.
578/// This means, if recurse is negative, the recursion is infinite.
579///
580/// Option is passed recursively, but regexp is only used on the
581/// first level.
582
584{
586
587 if (recurse != 0)
588 {
589 TIter next(this);
591
593 while ((object = next())) {
595 if (regexp.MatchB(s)) {
596 PrintCollectionEntry(object, option, recurse - 1);
597 }
598 }
600 }
601}
602
603////////////////////////////////////////////////////////////////////////////////
604/// Remove object from this collection and recursively remove the object
605/// from all other objects (and collections).
606
608{
609 if (!obj) return;
610
611 // Scan list and remove obj in the list itself
612 while (Remove(obj))
613 ;
614
615 // Scan again the list and invoke RecursiveRemove for all objects
616 TIter next(this);
618
619 while ((object = next())) {
620 if (!ROOT::Detail::HasBeenDeleted(object)) object->RecursiveRemove(obj);
621 }
622}
623
624////////////////////////////////////////////////////////////////////////////////
625/// Remove all objects in collection col from this collection.
626
628{
629 TIter next(col);
630 TObject *obj;
631
632 while ((obj = next()))
633 Remove(obj);
634}
635
636////////////////////////////////////////////////////////////////////////////////
637/// Stream all objects in the collection to or from the I/O buffer.
638
640{
642 TObject *obj;
644
645 if (b.IsReading()) {
646 Version_t v = b.ReadVersion(&R__s, &R__c);
647 if (v > 2)
649 if (v > 1)
651 b >> nobjects;
652 for (Int_t i = 0; i < nobjects; i++) {
653 b >> obj;
654 Add(obj);
655 }
656 b.CheckByteCount(R__s, R__c,TCollection::IsA());
657 } else {
658 R__c = b.WriteVersion(TCollection::IsA(), kTRUE);
661 nobjects = GetSize();
662 b << nobjects;
663
664 TIter next(this);
665
666 while ((obj = next())) {
667 b << obj;
668 }
669 b.SetByteCount(R__c, kTRUE);
670 }
671}
672
673////////////////////////////////////////////////////////////////////////////////
674/// Write all objects in this collection. By default all objects in
675/// the collection are written individually (each object gets its
676/// own key). Note, this is recursive, i.e. objects in collections
677/// in the collection are also written individually. To write all
678/// objects using a single key specify a name and set option to
679/// TObject::kSingleKey (i.e. 1).
680
682{
683 if ((option & kSingleKey)) {
685 } else {
687 Int_t nbytes = 0;
688 TIter next(this);
689 TObject *obj;
690 while ((obj = next())) {
691 nbytes += obj->Write(name, option, bufsize);
692 }
693 return nbytes;
694 }
695}
696
697////////////////////////////////////////////////////////////////////////////////
698/// Write all objects in this collection. By default all objects in
699/// the collection are written individually (each object gets its
700/// own key). Note, this is recursive, i.e. objects in collections
701/// in the collection are also written individually. To write all
702/// objects using a single key specify a name and set option to
703/// TObject::kSingleKey (i.e. 1).
704
706{
707 return ((const TCollection*)this)->Write(name,option,bufsize);
708}
709
710////////////////////////////////////////////////////////////////////////////////
711/// Return the globally accessible collection.
712
717
718////////////////////////////////////////////////////////////////////////////////
719/// Set this collection to be the globally accessible collection.
720
725
726////////////////////////////////////////////////////////////////////////////////
727/// Set up for garbage collection.
728
739
740////////////////////////////////////////////////////////////////////////////////
741/// Do the garbage collection.
742
754
755////////////////////////////////////////////////////////////////////////////////
756/// Add to the list of things to be cleaned up.
757
759{
760 {
763 if (!fgEmptyingGarbage) {
764 fgGarbageCollection->Add(obj);
765 return;
766 }
767 }
768 }
769 delete obj;
770}
771
772////////////////////////////////////////////////////////////////////////////////
773/// Set whether this collection is the owner (enable==true)
774/// of its content. If it is the owner of its contents,
775/// these objects will be deleted whenever the collection itself
776/// is deleted. The objects might also be deleted or destructed when Clear
777/// is called (depending on the collection).
778
780{
781 if (enable)
783 else
785}
786
787////////////////////////////////////////////////////////////////////////////////
788/// Set this collection to use a RW lock upon access, making it thread safe.
789/// Return the previous state.
790///
791/// Note: To test whether the usage is enabled do:
792/// collection->TestBit(TCollection::kUseRWLock);
793
795{
796 bool prev = TestBit(TCollection::kUseRWLock);
797 if (enable) {
799 } else {
801 }
802 return prev;
803}
804
805////////////////////////////////////////////////////////////////////////////////
806/// Copy a TIter. This involves allocating a new TIterator of the right
807/// sub class and assigning it with the original.
808
809TIter::TIter(const TIter &iter)
810{
811 if (iter.fIterator) {
812 fIterator = iter.GetCollection()->MakeIterator();
813 fIterator->operator=(*iter.fIterator);
814 } else
815 fIterator = nullptr;
816}
817
818////////////////////////////////////////////////////////////////////////////////
819/// Assigning an TIter to another. This involves allocating a new TIterator
820/// of the right sub class and assigning it with the original.
821
823{
824 if (this != &rhs) {
825 if (rhs.fIterator) {
826 delete fIterator;
827 fIterator = rhs.GetCollection()->MakeIterator();
828 fIterator->operator=(*rhs.fIterator);
829 }
830 }
831 return *this;
832}
833
834////////////////////////////////////////////////////////////////////////////////
835/// Pointing to the first element of the container.
836
838{
839 fIterator->Reset();
840 fIterator->Next();
841 return *this;
842}
843
844////////////////////////////////////////////////////////////////////////////////
845/// Pointing to the element after the last - to a nullptr value in our case.
846
848{
849 return TIter(static_cast<TIterator*>(nullptr));
850}
851
852////////////////////////////////////////////////////////////////////////////////
853/// Return an empty collection for use with nullptr TRangeCast
854
856{
857 static TObjArray sEmpty;
858 return sEmpty;
859}
860
861////////////////////////////////////////////////////////////////////////////////
862/// Return true if 'cl' inherits from 'base'.
863
865{
866 return cl->InheritsFrom(base);
867}
#define SafeDelete(p)
Definition RConfig.hxx:533
#define b(i)
Definition RSha256.hxx:100
bool Bool_t
Boolean (0=false, 1=true) (bool)
Definition RtypesCore.h:77
int Int_t
Signed integer 4 bytes (int)
Definition RtypesCore.h:59
constexpr Int_t kMaxInt
Definition RtypesCore.h:119
short Version_t
Class version identifier (short)
Definition RtypesCore.h:79
constexpr Bool_t kFALSE
Definition RtypesCore.h:108
constexpr Ssiz_t kNPOS
The equivalent of std::string::npos for the ROOT class TString.
Definition RtypesCore.h:131
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
const char Option_t
Option string (const char)
Definition RtypesCore.h:80
#define ClassImp(name)
Definition Rtypes.h:376
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:208
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:4902
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:49
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:97
virtual const char * GetName() const
Returns name of object.
Definition TObject.cxx:458
virtual void Browse(TBrowser *b)
Browse object. May be overridden for another default action.
Definition TObject.cxx:218
R__ALWAYS_INLINE Bool_t TestBit(UInt_t f) const
Definition TObject.h:202
virtual TObject * Clone(const char *newname="") const
Make a clone of an object using the Streamer facility.
Definition TObject.cxx:243
virtual void Streamer(TBuffer &)
Stream an object of class TObject.
Definition TObject.cxx:973
virtual const char * ClassName() const
Returns name of class to which the object belongs.
Definition TObject.cxx:227
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:965
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition TObject.cxx:865
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition TObject.cxx:544
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition TObject.cxx:1072
virtual const char * GetTitle() const
Returns title of object.
Definition TObject.cxx:502
void ResetBit(UInt_t f)
Definition TObject.h:201
@ kCanDelete
if object in a list can be deleted
Definition TObject.h:68
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:2891
static void IndentLevel()
Functions used by ls() to indent an object hierarchy.
Definition TROOT.cxx:2899
static Int_t DecreaseDirLevel()
Decrease the indentation level for ls().
Definition TROOT.cxx:2749
Regular expression class.
Definition TRegexp.h:31
Basic string class.
Definition TString.h:138
Ssiz_t Length() const
Definition TString.h:425
int CompareTo(const char *cs, ECaseCompare cmp=kExact) const
Compare a string to char *cs2.
Definition TString.cxx:465
const char * Data() const
Definition TString.h:384
virtual void Streamer(TBuffer &)
Stream a string object.
Definition TString.cxx:1419
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
Definition TString.h:659
virtual void StackTrace()
Print a stack trace.
Definition TSystem.cxx:745
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:405
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:400
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:303