93#ifdef R__CHECK_COLLECTION_MULTI_ACCESS
95void TCollection::TErrorLock::ConflictReport(std::thread::id holder,
const char *accesstype,
96 const TCollection *collection,
const char *function)
99 auto local = std::this_thread::get_id();
100 std::stringstream cur, loc;
101 if (holder == std::thread::id())
104 cur <<
"0x" << std::hex << holder;
105 loc <<
"0x" << std::hex << local;
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());
116 std::set<std::thread::id> tmp;
117 for (
auto r : fReadSet) tmp.insert(
r);
119 std::stringstream reader;
120 reader <<
"0x" << std::hex <<
r;
121 ::Error(function,
" Readers includes %s", reader.str().c_str());
126void TCollection::TErrorLock::Lock(
const TCollection *collection,
const char *function)
128 auto local = std::this_thread::get_id();
130 std::thread::id holder;
132 if (fWriteCurrent.compare_exchange_strong(holder, local)) {
134 ++fWriteCurrentRecurse;
139 if (fReadCurrentRecurse) {
140 if (fReadSet.size() > 1 || fReadSet.find(local) != fReadSet.end()) {
141 ConflictReport(std::thread::id(),
"WriteLock while ReadLock taken", collection, function);
147 if (holder == local) {
153 ConflictReport(holder,
"WriteLock", collection, function);
155 ++fWriteCurrentRecurse;
159void TCollection::TErrorLock::Unlock()
161 auto local = std::this_thread::get_id();
162 auto none = std::thread::id();
164 --fWriteCurrentRecurse;
165 if (fWriteCurrentRecurse == 0) {
166 if (fWriteCurrent.compare_exchange_strong(local, none)) {
186void TCollection::TErrorLock::ReadLock(
const TCollection *collection,
const char *function)
188 auto local = std::this_thread::get_id();
192 fReadSet.insert(local);
194 ++fReadCurrentRecurse;
196 if (fWriteCurrentRecurse) {
197 auto holder = fWriteCurrent.load();
198 if (holder != local) ConflictReport(holder,
"ReadLock with WriteLock taken", collection, function);
202void TCollection::TErrorLock::ReadUnlock()
204 auto local = std::this_thread::get_id();
207 fReadSet.erase(local);
209 --fReadCurrentRecurse;
231 while ((obj = next()))
242 va_start(ap,
va_(obj1));
246 while ((obj = va_arg(ap,
TObject *)))
261 Error(
"AssertClass",
"class == 0");
265 for (
int i = 0; (obj = next()); i++)
267 Error(
"AssertClass",
"element %d is not an instance of class %s (%s)",
285 while ((obj = next()))
b->Add(obj);
297 if (newname && strlen(newname)) new_collection->
SetName(newname);
298 return new_collection;
308 if (
this == obj)
return 0;
320 while ((
object = next())) {
321 object->Draw(option);
333 while ((
object = next())) {
348 while ((obj = next()))
373 while ((ob = next()))
374 if (ob->
IsEqual(obj))
return ob;
394 Error(
"GrowBy",
"delta < 0");
422 char *star =
nullptr;
423 if (option) star = (
char*)strchr(option,
'*');
426 while ((
object = next())) {
429 if (s != option && s.
Index(re) ==
kNPOS)
continue;
441 for (
auto obj : *
this) success &= obj->Notify();
459 printf(
"Collection name='%s', class='%s', size=%d\n",
480 coll->
Print(option, recurse);
483 entry->
Print(option);
531 while ((
object = next())) {
554 if (!wildcard) wildcard =
"";
556 Int_t nch = strlen(wildcard);
561 while ((
object = next())) {
563 if (nch == 0 || s == wildcard || s.
Index(re) !=
kNPOS) {
591 while ((
object = next())) {
617 while ((
object = next())) {
630 while ((obj = next()))
650 for (
Int_t i = 0; i < nobjects; i++) {
664 while ((obj = next())) {
667 b.SetByteCount(R__c,
kTRUE);
688 while ((obj = next())) {
689 nbytes += obj->
Write(
name, option, bufsize);
int Int_t
Signed integer 4 bytes (int).
short Version_t
Class version identifier (short).
unsigned int UInt_t
Unsigned integer 4 bytes (unsigned int).
bool Bool_t
Boolean (0=false, 1=true) (bool).
constexpr Ssiz_t kNPOS
The equivalent of std::string::npos for the ROOT class TString.
const char Option_t
Option string (const char).
externTVirtualMutex * gCollectionMutex
#define R__FOR_EACH(type, proc)
Error("WriteTObject","The current directory (%s) is not associated with a file. The object (%s) has not been written.", GetName(), objname)
#define R__LOCKGUARD2(mutex)
A spin mutex-as-code-guard class.
Using a TBrowser one can browse all ROOT objects.
Buffer base class used for serializing objects.
TClass instances represent classes, structs and namespaces in the ROOT type system.
Bool_t InheritsFrom(const char *cl) const override
Return kTRUE if this class inherits from a class with name "classname".
Collection abstract base class.
virtual TObject * Remove(TObject *obj)=0
virtual TIterator * MakeIterator(Bool_t dir=kIterForward) const =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...
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 SetName(const char *name)
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.
TCollection(const TCollection &)=delete
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
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.
Iterator abstract base class.
const char * GetName() const override
Returns name of object.
This class registers all instances of TObject and its derived classes in a hash table.
virtual Bool_t IsEqual(const TObject *obj) const
Default equal comparison (objects are equal if they have the same address in memory).
Bool_t TestBit(UInt_t f) const
virtual const char * GetName() const
Returns name of object.
virtual void Browse(TBrowser *b)
Browse object. May be overridden for another default action.
virtual TObject * Clone(const char *newname="") const
Make a clone of an object using the Streamer facility.
virtual void Streamer(TBuffer &)
Stream an object of class TObject.
virtual const char * ClassName() const
Returns name of class to which the object belongs.
virtual Int_t Write(const char *name=nullptr, Int_t option=0, Int_t bufsize=0)
Write this object to the current directory.
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
virtual const char * GetTitle() const
Returns title of object.
@ kSingleKey
write collection with single key
virtual void Print(Option_t *option="") const
This method must be overridden when a class wants to print itself.
TObject()
TObject constructor.
@ kCanDelete
if object in a list can be deleted
Bool_t MatchB(const TString &s, const TString &mods="", Int_t start=0, Int_t nMaxMatch=10)
static Int_t IncreaseDirLevel()
Increase the indentation level for ls().
static void IndentLevel()
Functions used by ls() to indent an object hierarchy.
static Int_t DecreaseDirLevel()
Decrease the indentation level for ls().
Regular expression class.
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
This class implements a mutex interface.
bool HasBeenDeleted(const TObject *obj)
Check if the TObject's memory has been deleted.
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.
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.