Logo ROOT   6.21/01
Reference Guide
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 
15 This class is a specialized TProcessID managing the list of UUIDs.
16 In 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 
21 When a new TUUID is entered into the list fUUIDs, it is assigned
22 the first free slot in the list of bits and the TUUID UUIDNumber
23 is set to this slot number.
24 
25 When a TUUID is removed from the list, the corresponding bit
26 is reset in fActive.
27 
28 The object corresponding to a TUUID at slot I can be found
29 via fObjects->At(I).
30 
31 One 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 
38 When a TRef points to an object having a TUUID, both the TRef and the
39 referenced object have their bit kHasUUID set. In this case, the pointer
40 TProcessID *fPID in TRef points to the unique object TProcessUUID.
41 The TRef uniqueID is directly the UUIDNumber=slot number.
42 */
43 
44 #include "TROOT.h"
45 #include "TProcessUUID.h"
46 #include "THashList.h"
47 #include "TBits.h"
48 #include "TObjString.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 = 0;
70  delete fActive; fActive = 0;
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) == 0) 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 
110 UInt_t TProcessUUID::AddUUID(const char *uuids)
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 0;
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(0,number);
153  return;
154  }
155  lnk = lnk->Next();
156  }
157 }
virtual UInt_t GetUniqueID() const
Return the unique object id.
Definition: TObject.cxx:375
ROOT::Internal::TAtomicPointer< TObjArray * > fObjects
Reference count to this object (from TFile)
Definition: TProcessID.h:77
virtual void Delete(Option_t *option="")
Remove all objects from the list AND delete all heap based objects.
Definition: TList.cxx:467
This class is a specialized TProcessID managing the list of UUIDs.
Definition: TProcessUUID.h:32
Collectable string class.
Definition: TObjString.h:28
TProcessUUID()
Default constructor.
TList * fUUIDs
Definition: TProcessUUID.h:39
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition: TObject.cxx:694
virtual TObject * FindObject(const char *name) const
Find an object in this list using its name.
Definition: TList.cxx:575
This class defines a UUID (Universally Unique IDentifier), also known as GUIDs (Globally Unique IDent...
Definition: TUUID.h:42
THashList implements a hybrid collection class consisting of a hash table and a list to store TObject...
Definition: THashList.h:34
A TProcessID identifies a ROOT job in a unique way in time and space.
Definition: TProcessID.h:69
virtual void SetUniqueID(UInt_t uid)
Set the unique object id.
Definition: TObject.cxx:705
virtual void AddAtAndExpand(TObject *obj, Int_t idx)
Add object at position idx.
Definition: TObjArray.cxx:234
virtual TObject * Remove(TObject *obj)
Remove object from the list.
Definition: TList.cxx:819
if object has a TUUID (its fUniqueID=UUIDNumber)
Definition: TObject.h:62
Int_t IncrementCount()
Increase the reference count to this object.
Definition: TProcessID.cxx:311
unsigned int UInt_t
Definition: RtypesCore.h:42
TBits * fActive
Definition: TProcessUUID.h:40
virtual void AddAt(TObject *obj, Int_t idx)
Add object at position ids.
Definition: TObjArray.cxx:253
virtual TObjLink * FirstLink() const
Definition: TList.h:108
TObject * UncheckedAt(Int_t i) const
Definition: TObjArray.h:90
#define ClassImp(name)
Definition: Rtypes.h:365
virtual ~TProcessUUID()
Destructor.
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 ...
const char * AsString() const
Return UUID as string. Copy string immediately since it will be reused.
Definition: TUUID.cxx:560
Mother of all ROOT objects.
Definition: TObject.h:37
Container of bits.
Definition: TBits.h:27
virtual void Add(TObject *obj)
Definition: TList.h:87
void ResetBitNumber(UInt_t bitnumber)
Definition: TBits.h:235
void SetUUIDNumber(UInt_t index)
Definition: TUUID.h:80
virtual Int_t GetSize() const
Return the capacity of the collection, i.e.
Definition: TCollection.h:182
TObjString * FindUUID(UInt_t number) const
Find the TObjString by slot number.
void SetBitNumber(UInt_t bitnumber, Bool_t value=kTRUE)
Definition: TBits.h:206
void RemoveUUID(UInt_t number)
Remove entry number in the list of uuids.
UInt_t FirstNullBit(UInt_t startBit=0) const
Return position of first null bit (starting from position 0 and up)
Definition: TBits.cxx:275