|
ROOT
Reference Guide |
|
Go to the documentation of this file.
12 #ifndef ROOT_TCollection
13 #define ROOT_TCollection
57 #ifdef R__CHECK_COLLECTION_MULTI_ACCESS
60 #include <unordered_multiset>
65 #ifdef R__CHECK_COLLECTION_MULTI_ACCESS
69 std::atomic<std::thread::id> fWriteCurrent;
70 std::atomic<size_t> fWriteCurrentRecurse;
71 std::atomic<size_t> fReadCurrentRecurse;
72 std::unordered_multiset<std::thread::id> fReadSet;
73 std::atomic_flag fSpinLockFlag;
75 void Lock(
const TCollection *collection,
const char *
function);
79 void ReadLock(
const TCollection *collection,
const char *
function);
84 const char *
function);
87 TErrorLock() : fWriteCurrent(), fWriteCurrentRecurse(0), fReadCurrentRecurse(0)
89 std::atomic_flag_clear(&fSpinLockFlag);
96 WriteGuard(TErrorLock &lock,
const TCollection *collection,
const char *
function) : fLock(&lock)
98 fLock->Lock(collection,
function);
100 ~WriteGuard() { fLock->Unlock(); }
107 ReadGuard(TErrorLock &lock,
const TCollection *collection,
const char *
function) : fLock(&lock)
109 fLock->ReadLock(collection,
function);
111 ~ReadGuard() { fLock->ReadUnlock(); }
115 mutable TErrorLock fLock;
117 #define R__COLLECTION_WRITE_GUARD() TCollection::TErrorLock::WriteGuard wg(fLock, this, __PRETTY_FUNCTION__)
118 #define R__COLLECTION_READ_GUARD() TCollection::TErrorLock::ReadGuard rg(fLock, this, __PRETTY_FUNCTION__)
120 #define R__COLLECTION_ITER_GUARD(collection) \
121 TCollection::TErrorLock::ReadGuard rg(collection->fLock, collection, __PRETTY_FUNCTION__)
125 #define R__COLLECTION_WRITE_GUARD()
126 #define R__COLLECTION_READ_GUARD()
127 #define R__COLLECTION_ITER_GUARD(collection)
173 virtual void Dump()
const ;
178 virtual const char *
GetName()
const;
243 :
fIterator(col ? col->MakeIterator(dir) : 0) { }
262 return !(*
this == aIter);
293 template <
class Containee>
295 static_assert(std::is_base_of<TObject, Containee>::value,
"Containee type must inherit from TObject");
335 template <
class Containee>
337 static_assert(std::is_base_of<TObject, Containee>::value,
"Containee type must inherit from TObject");
349 return static_cast<Containee *
>(obj);
423 #if defined (_REENTRANT) || defined (WIN32)
425 #define R__COLL_COND_MUTEX(mutex) this->IsUsingRWLock() ? mutex : nullptr
427 #define R__COLLECTION_READ_LOCKGUARD(mutex) ::ROOT::TReadLockGuard _R__UNIQUE_(R__readguard)(R__COLL_COND_MUTEX(mutex))
428 #define R__COLLECTION_READ_LOCKGUARD_NAMED(name,mutex) ::ROOT::TReadLockGuard _NAME2_(R__readguard,name)(R__COLL_COND_MUTEX(mutex))
430 #define R__COLLECTION_WRITE_LOCKGUARD(mutex) ::ROOT::TWriteLockGuard _R__UNIQUE_(R__readguard)(R__COLL_COND_MUTEX(mutex))
431 #define R__COLLECTION_WRITE_LOCKGUARD_NAMED(name,mutex) ::ROOT::TWriteLockGuard _NAME2_(R__readguard,name)(R__COLL_COND_MUTEX(mutex))
435 #define R__COLLECTION_READ_LOCKGUARD(mutex) (void)mutex
436 #define R__COLLECTION_COLLECTION_READ_LOCKGUARD_NAMED(name,mutex) (void)mutex
438 #define R__COLLECTION_WRITE_LOCKGUARD(mutex) (void)mutex
439 #define R__COLLECTION_WRITE_LOCKGUARD_NAMED(name,mutex) (void)mutex
448 #define R__FOR_EACH(type,proc) \
449 SetCurrentCollection(); \
450 TIter _NAME3_(nxt_,type,proc)(TCollection::GetCurrentCollection()); \
451 type *_NAME3_(obj_,type,proc); \
452 while ((_NAME3_(obj_,type,proc) = (type*) _NAME3_(nxt_,type,proc)())) \
453 _NAME3_(obj_,type,proc)->proc
TTypedIter< T > end() const
TTypedIter< T > begin() const
virtual Bool_t IsFolder() const
Returns kTRUE in case object contains browsable objects (like containers or lists of other objects).
Using a TBrowser one can browse all ROOT objects.
This class registers all instances of TObject and its derived classes in a hash table.
R__ALWAYS_INLINE Bool_t TestBit(UInt_t f) const
virtual void Print(Option_t *option="") const
Default print for collections, calls Print(option, 1).
Bool_t IsSortable() const
virtual Option_t * GetOption() const
Int_t Compare(const TObject *obj) const
Compare two TCollection objects.
virtual void Clear(Option_t *option="")=0
Bool_t IsArgNull(const char *where, const TObject *obj) const
Returns true if object is a null pointer.
virtual Int_t Write(const char *name=0, Int_t option=0, Int_t bufsize=0)
Write all objects in this collection.
virtual Int_t GetEntries() const
R__EXTERN TVirtualMutex * gCollectionMutex
virtual TIterator * MakeReverseIterator() const
ULong_t Hash() const
Return hash value for this object.
ClassDefInline(TRangeDynCastIterator, 0)
Internal help class implmenting an iterator for TRangeDynCast.
static Containee * StaticCast(TObject *obj)
virtual TObject * Remove(TObject *obj)=0
virtual void Delete(Option_t *option="")=0
Delete this object.
virtual const char * GetCollectionEntryName(TObject *entry) const
For given collection entry return the string that is used to identify the object and,...
TRangeDynCast(const TCollection *col)
virtual void SetOwner(Bool_t enable=kTRUE)
Set whether this collection is the owner (enable==true) of its content.
virtual void Draw(Option_t *option="")
Draw all objects in this collection.
virtual TObject * Clone(const char *newname="") const
Make a clone of an collection using the Streamer facility.
TIter & Begin()
Pointing to the first element of the container.
This class implements a mutex interface.
UInt_t Hash(ECaseCompare cmp=kExact) const
Return hash value.
TTypedIter is a typed version of TIter.
const TCollection & EmptyCollection()
Return an empty collection for use with nullptr TRangeCast.
Containee * operator()()=delete
TRangeDynCast is an adaptater class that allows the typed iteration through a TCollection.
Bool_t Contains(const char *name) const
Containee * operator*() const
void AddVector(TObject *obj1,...)
Add all arguments to the collection.
virtual void AddAll(const TCollection *col)
Add all objects from collection col to this collection.
Option_t * GetOption() const
TTypedIter(const TIter &iter)
Iterator abstract base class.
TIterCategory(TIterator *it)
TIter & operator=(const TIter &rhs)
Assigning an TIter to another.
const Bool_t kIterBackward
static TCollection * fgCurrentCollection
static TIterCategory End()
const Bool_t kIterForward
ClassDefInline(TTypedIter, 0)
const TCollection & fCollection
TRangeDynCastIterator(const TIter &iter)
Bool_t Contains(const TObject *obj) const
static void StartGarbageCollection()
Set up for garbage collection.
virtual const TCollection * GetCollection() const =0
virtual bool UseRWLock()
Set this collection to use a RW lock upon access, making it thread safe.
virtual Bool_t Notify()
'Notify' all objects in this collection.
ROOT::Internal::TRangeDynCastIterator< T > end() const
R__ALWAYS_INLINE Bool_t IsUsingRWLock() const
virtual void Dump() const
Dump all objects in this collection.
static Bool_t fgEmptyingGarbage
Bool_t operator!=(const TIter &aIter) const
static void GarbageCollect(TObject *obj)
Add to the list of things to be cleaned up.
TRangeStaticCast is an adaptater class that allows the typed iteration through a TCollection.
const TCollection & fCollection
virtual Int_t GrowBy(Int_t delta) const
Increase the collection's capacity by delta slots.
virtual void PrintCollectionEntry(TObject *entry, Option_t *option, Int_t recurse) const
Print the collection entry.
void SetCurrentCollection()
Set this collection to be the globally accessible collection.
void Browse(TBrowser *b)
Browse this collection (called by TBrowser).
virtual TIterator * MakeIterator(Bool_t dir=kIterForward) const =0
virtual void Paint(Option_t *option="")
Paint all objects in this collection.
TCollection(const TCollection &)
virtual Bool_t IsEmpty() const
void operator=(const TCollection &)
virtual void RecursiveRemove(TObject *obj)
Remove object from this collection and recursively remove the object from all other objects (and coll...
virtual TObject * Next()=0
virtual void PrintCollectionHeader(Option_t *option) const
Print the collection header.
static TCollection * GetCurrentCollection()
Return the globally accessible collection.
static void EmptyGarbageCollection()
Do the garbage collection.
TRangeStaticCast(const TCollection &col)
static TIter End()
Pointing to the element after the last - to a nullptr value in our case.
TRangeStaticCast(const TCollection *col)
TRangeDynCast(const TCollection &col)
ROOT::Internal::TRangeDynCastIterator< T > begin() const
virtual Int_t GetSize() const
Return the capacity of the collection, i.e.
TClass instances represent classes, structs and namespaces in the ROOT type system.
virtual ~TCollection()
TNamed destructor.
TObject * operator()(const char *name) const
Find an object in this collection by name.
void SetName(const char *name)
static TObjectTable * fgGarbageCollection
Mother of all ROOT objects.
#define ClassDef(name, id)
Bool_t operator==(const TIter &aIter) const
virtual void Add(TObject *obj)=0
Bool_t AssertClass(TClass *cl) const
Make sure all objects in this collection inherit from class cl.
TIterCategory(const TCollection *col, Bool_t dir=kIterForward)
virtual TObject ** GetObjectRef(const TObject *obj) const =0
bool ContaineeInheritsFrom(TClass *cl, TClass *base)
Return true if 'cl' inherits from 'base'.
static Int_t fgGarbageStack
const TCollection * GetCollection() const
virtual void ls(Option_t *option="") const
List (ls) all objects in this collection.
Collection abstract base class.
TObject * operator*() const
virtual const char * GetName() const
Return name of this collection.
virtual TObject * FindObject(const char *name) const
Find an object in this collection using its name.
Containee * operator*() const
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
TRangeDynCastIterator()=default