Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TProcessUUID.cxx
Go to the documentation of this file.
1// @(#)root/base:$Id$
2// Author: Rene Brun 06/07/2002
3
4/*************************************************************************
5 * Copyright (C) 1995-2001, 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 TProcessUUID
13\ingroup Base
14
15This class is a specialized TProcessID managing the list of UUIDs.
16In addition to TProcessID, this object has the following members:
17
18 - fUUIDs : a THashList of TUUIDs in string format (using a TObjString)
19 - fActive : a TBits table with one bit per TUUID in the table
20
21When a new TUUID is entered into the list fUUIDs, it is assigned
22the first free slot in the list of bits and the TUUID UUIDNumber
23is set to this slot number.
24
25When a TUUID is removed from the list, the corresponding bit
26is reset in fActive.
27
28The object corresponding to a TUUID at slot I can be found
29via fObjects->At(I).
30
31One can use two mechanisms to find the object corresponding to a TUUID:
32
33 1. the input is the TUUID.AsString. One can find the corresponding
34 TObjString object objs in fUUIDs via THashList::FindObject(name).
35 The slot number is then objs->GetUniqueID().
36 2. The input is the UUIDNumber. The slot number is UIUIDNumber
37
38When a TRef points to an object having a TUUID, both the TRef and the
39referenced object have their bit kHasUUID set. In this case, the pointer
40TProcessID *fPID in TRef points to the unique object TProcessUUID.
41The TRef uniqueID is directly the UUIDNumber=slot number.
42*/
43
44#include "TProcessUUID.h"
45#include "THashList.h"
46#include "TBits.h"
47#include "TObjString.h"
48#include "TObjArray.h"
49#include "TUUID.h"
50
51
52////////////////////////////////////////////////////////////////////////////////
53/// Default constructor.
54
56{
57 fUUIDs = new THashList(100,3);
58 fActive = new TBits(100);
60}
61
62////////////////////////////////////////////////////////////////////////////////
63/// Destructor.
64
66{
67 fUUIDs->Delete();
68 delete fUUIDs; fUUIDs = nullptr;
69 delete fActive; fActive = nullptr;
70}
71
72////////////////////////////////////////////////////////////////////////////////
73/// Add uuid to the table of UUIDs
74/// The TObject *obj has its uniqueID set to the UUID number
75/// return entry number in the table
76
78{
79 UInt_t number;
80 const char *uuids = uuid.AsString();
82 if (objs) {
83 number = objs->GetUniqueID();
84 uuid.SetUUIDNumber(number);
85 objs->SetUniqueID(number);
86 obj->SetUniqueID(number);
87 obj->SetBit(kHasUUID);
88 if (number >= (UInt_t)fObjects->GetSize()) fObjects->AddAtAndExpand(obj,number);
89 if (fObjects->UncheckedAt(number) == nullptr) fObjects->AddAt(obj,number);
90 return number;
91 }
92
93 objs = new TObjString(uuids);
94 fUUIDs->Add(objs);
95 number = fActive->FirstNullBit();
96 uuid.SetUUIDNumber(number);
97 objs->SetUniqueID(number);
98 obj->SetUniqueID(number);
99 obj->SetBit(kHasUUID);
100 fActive->SetBitNumber(number);
101 fObjects->AddAtAndExpand(obj,number);
102 return number;
103}
104
105////////////////////////////////////////////////////////////////////////////////
106/// Add uuid with name uuids to the table of UUIDs
107/// return entry number in the table
108
110{
111
113 if (objs) return objs->GetUniqueID();
114
115 UInt_t number;
116 objs = new TObjString(uuids);
117 fUUIDs->Add(objs);
118 number = fActive->FirstNullBit();
119 objs->SetUniqueID(number);
120 fActive->SetBitNumber(number);
121 return number;
122}
123
124////////////////////////////////////////////////////////////////////////////////
125/// Find the TObjString by slot number
126
128{
130 while (lnk) {
131 TObject *obj = lnk->GetObject();
132 if (obj->GetUniqueID() == number) return (TObjString*)obj;
133 lnk = lnk->Next();
134 }
135 return nullptr;
136}
137
138////////////////////////////////////////////////////////////////////////////////
139/// Remove entry number in the list of uuids
140
142{
143 if (number > (UInt_t)fObjects->GetSize()) return;
145 while (lnk) {
146 TObject *obj = lnk->GetObject();
147 if (obj->GetUniqueID() == number) {
148 fUUIDs->Remove(lnk);
149 delete obj;
150 fActive->ResetBitNumber(number);
151 fObjects->AddAt(nullptr,number);
152 return;
153 }
154 lnk = lnk->Next();
155 }
156}
Container of bits.
Definition TBits.h:26
void ResetBitNumber(UInt_t bitnumber)
Definition TBits.h:235
UInt_t FirstNullBit(UInt_t startBit=0) const
Return position of first null bit (starting from position 0 and up)
Definition TBits.cxx:274
void SetBitNumber(UInt_t bitnumber, Bool_t value=kTRUE)
Definition TBits.h:206
virtual Int_t GetSize() const
Return the capacity of the collection, i.e.
THashList implements a hybrid collection class consisting of a hash table and a list to store TObject...
Definition THashList.h:34
TObject * FindObject(const char *name) const override
Find an object in this list using its name.
Definition TList.cxx:575
void Add(TObject *obj) override
Definition TList.h:81
TObject * Remove(TObject *obj) override
Remove object from the list.
Definition TList.cxx:819
virtual TObjLink * FirstLink() const
Definition TList.h:102
void Delete(Option_t *option="") override
Remove all objects from the list AND delete all heap based objects.
Definition TList.cxx:467
void AddAt(TObject *obj, Int_t idx) override
Add object at position ids.
virtual void AddAtAndExpand(TObject *obj, Int_t idx)
Add object at position idx.
TObject * UncheckedAt(Int_t i) const
Definition TObjArray.h:84
Collectable string class.
Definition TObjString.h:28
Mother of all ROOT objects.
Definition TObject.h:41
virtual UInt_t GetUniqueID() const
Return the unique object id.
Definition TObject.cxx:475
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition TObject.cxx:864
virtual void SetUniqueID(UInt_t uid)
Set the unique object id.
Definition TObject.cxx:875
@ kHasUUID
if object has a TUUID (its fUniqueID=UUIDNumber)
Definition TObject.h:72
A TProcessID identifies a ROOT job in a unique way in time and space.
Definition TProcessID.h:74
Int_t IncrementCount()
Increase the reference count to this object.
ROOT::Internal::TAtomicPointer< TObjArray * > fObjects
Reference count to this object (from TFile)
Definition TProcessID.h:82
TList * fUUIDs
UInt_t AddUUID(TUUID &uuid, TObject *obj)
Add uuid to the table of UUIDs The TObject *obj has its uniqueID set to the UUID number return entry ...
virtual ~TProcessUUID()
Destructor.
TBits * fActive
TProcessUUID()
Default constructor.
void RemoveUUID(UInt_t number)
Remove entry number in the list of uuids.
TObjString * FindUUID(UInt_t number) const
Find the TObjString by slot number.
This class defines a UUID (Universally Unique IDentifier), also known as GUIDs (Globally Unique IDent...
Definition TUUID.h:42
void SetUUIDNumber(UInt_t index)
Definition TUUID.h:80
const char * AsString() const
Return UUID as string. Copy string immediately since it will be reused.
Definition TUUID.cxx:570