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
52
53////////////////////////////////////////////////////////////////////////////////
54/// Default constructor.
55
57{
58 fUUIDs = new THashList(100,3);
59 fActive = new TBits(100);
61}
62
63////////////////////////////////////////////////////////////////////////////////
64/// Destructor.
65
67{
68 fUUIDs->Delete();
69 delete fUUIDs; fUUIDs = nullptr;
70 delete fActive; fActive = nullptr;
71}
72
73////////////////////////////////////////////////////////////////////////////////
74/// Add uuid to the table of UUIDs
75/// The TObject *obj has its uniqueID set to the UUID number
76/// return entry number in the table
77
79{
80 UInt_t number;
81 const char *uuids = uuid.AsString();
82 TObjString *objs = (TObjString*)fUUIDs->FindObject(uuids);
83 if (objs) {
84 number = objs->GetUniqueID();
85 uuid.SetUUIDNumber(number);
86 objs->SetUniqueID(number);
87 obj->SetUniqueID(number);
88 obj->SetBit(kHasUUID);
89 if (number >= (UInt_t)fObjects->GetSize()) fObjects->AddAtAndExpand(obj,number);
90 if (fObjects->UncheckedAt(number) == nullptr) fObjects->AddAt(obj,number);
91 return number;
92 }
93
94 objs = new TObjString(uuids);
95 fUUIDs->Add(objs);
96 number = fActive->FirstNullBit();
97 uuid.SetUUIDNumber(number);
98 objs->SetUniqueID(number);
99 obj->SetUniqueID(number);
100 obj->SetBit(kHasUUID);
101 fActive->SetBitNumber(number);
102 fObjects->AddAtAndExpand(obj,number);
103 return number;
104}
105
106////////////////////////////////////////////////////////////////////////////////
107/// Add uuid with name uuids to the table of UUIDs
108/// return entry number in the table
109
111{
112
113 TObjString *objs = (TObjString*)fUUIDs->FindObject(uuids);
114 if (objs) return objs->GetUniqueID();
115
116 UInt_t number;
117 objs = new TObjString(uuids);
118 fUUIDs->Add(objs);
119 number = fActive->FirstNullBit();
120 objs->SetUniqueID(number);
121 fActive->SetBitNumber(number);
122 return number;
123}
124
125////////////////////////////////////////////////////////////////////////////////
126/// Find the TObjString by slot number
127
129{
130 TObjLink *lnk = fUUIDs->FirstLink();
131 while (lnk) {
132 TObject *obj = lnk->GetObject();
133 if (obj->GetUniqueID() == number) return (TObjString*)obj;
134 lnk = lnk->Next();
135 }
136 return nullptr;
137}
138
139////////////////////////////////////////////////////////////////////////////////
140/// Remove entry number in the list of uuids
141
143{
144 if (number > (UInt_t)fObjects->GetSize()) return;
145 TObjLink *lnk = fUUIDs->FirstLink();
146 while (lnk) {
147 TObject *obj = lnk->GetObject();
148 if (obj->GetUniqueID() == number) {
149 fUUIDs->Remove(lnk);
150 delete obj;
151 fActive->ResetBitNumber(number);
152 fObjects->AddAt(nullptr,number);
153 return;
154 }
155 lnk = lnk->Next();
156 }
157}
#define ClassImp(name)
Definition Rtypes.h:364
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:275
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
virtual void Add(TObject *obj)
Definition TList.h:81
virtual TObject * Remove(TObject *obj)
Remove object from the list.
Definition TList.cxx:822
virtual TObject * FindObject(const char *name) const
Find an object in this list using its name.
Definition TList.cxx:578
virtual TObjLink * FirstLink() const
Definition TList.h:102
virtual void Delete(Option_t *option="")
Remove all objects from the list AND delete all heap based objects.
Definition TList.cxx:470
virtual void AddAtAndExpand(TObject *obj, Int_t idx)
Add object at position idx.
TObject * UncheckedAt(Int_t i) const
Definition TObjArray.h:84
virtual void AddAt(TObject *obj, Int_t idx)
Add object at position ids.
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:447
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition TObject.cxx:766
virtual void SetUniqueID(UInt_t uid)
Set the unique object id.
Definition TObject.cxx:777
@ kHasUUID
if object has a TUUID (its fUniqueID=UUIDNumber)
Definition TObject.h:66
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
This class is a specialized TProcessID managing the list of UUIDs.
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