ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 This class is a specialized TProcessID managing the list of UUIDs.
14 In addition to TProcessID, this object has the following members:
15 
16  - fUUIDs : a THashList of TUUIDs in string format (using a TObjString)
17  - fActive : a TBits table with one bit per TUUID in the table
18 
19 When a new TUUID is entered into the list fUUIDs, it is assigned
20 the first free slot in the list of bits and the TUUID UUIDNumber
21 is set to this slot number.
22 
23 When a TUUID is removed from the list, the corresponding bit
24 is reset in fActive.
25 
26 The object corresponding to a TUUID at slot I can be found
27 via fObjects->At(I).
28 
29 One can use two mechanisms to find the object corresponding to a TUUID:
30 
31  1. the input is the TUUID.AsString. One can find the corresponding
32  TObjString object objs in fUUIDs via THashList::FindObject(name).
33  The slot number is then objs->GetUniqueID().
34  2. The input is the UUIDNumber. The slot number is UIUIDNumber
35 
36 When a TRef points to an object having a TUUID, both the TRef and the
37 referenced object have their bit kHasUUID set. In this case, the pointer
38 TProcessID *fPID in TRef points to the unique object TProcessUUID.
39 The TRef uniqueID is directly the UUIDNumber=slot number.
40 */
41 
42 #include "TROOT.h"
43 #include "TProcessUUID.h"
44 #include "THashList.h"
45 #include "TBits.h"
46 #include "TObjString.h"
47 #include "TUUID.h"
48 
50 
51 ////////////////////////////////////////////////////////////////////////////////
52 /// Default constructor.
53 
55 {
56  fUUIDs = new THashList(100,3);
57  fActive = new TBits(100);
58  IncrementCount();
59 }
60 
61 ////////////////////////////////////////////////////////////////////////////////
62 /// Destructor.
63 
65 {
66  fUUIDs->Delete();
67  delete fUUIDs; fUUIDs = 0;
68  delete fActive; fActive = 0;
69 }
70 
71 ////////////////////////////////////////////////////////////////////////////////
72 /// Add uuid to the table of UUIDs
73 /// The TObject *obj has its uniqueID set to the UUID number
74 /// return entry number in the table
75 
77 {
78  UInt_t number;
79  const char *uuids = uuid.AsString();
80  TObjString *objs = (TObjString*)fUUIDs->FindObject(uuids);
81  if (objs) {
82  number = objs->GetUniqueID();
83  uuid.SetUUIDNumber(number);
84  objs->SetUniqueID(number);
85  obj->SetUniqueID(number);
86  obj->SetBit(kHasUUID);
87  if (number >= (UInt_t)fObjects->GetSize()) fObjects->AddAtAndExpand(obj,number);
88  if (fObjects->UncheckedAt(number) == 0) fObjects->AddAt(obj,number);
89  return number;
90  }
91 
92  objs = new TObjString(uuids);
93  fUUIDs->Add(objs);
94  number = fActive->FirstNullBit();
95  uuid.SetUUIDNumber(number);
96  objs->SetUniqueID(number);
97  obj->SetUniqueID(number);
98  obj->SetBit(kHasUUID);
99  fActive->SetBitNumber(number);
100  fObjects->AddAtAndExpand(obj,number);
101  return number;
102 }
103 
104 ////////////////////////////////////////////////////////////////////////////////
105 /// Add uuid with name uuids to the table of UUIDs
106 /// return entry number in the table
107 
108 UInt_t TProcessUUID::AddUUID(const char *uuids)
109 {
110 
111  TObjString *objs = (TObjString*)fUUIDs->FindObject(uuids);
112  if (objs) return objs->GetUniqueID();
113 
114  UInt_t number;
115  objs = new TObjString(uuids);
116  fUUIDs->Add(objs);
117  number = fActive->FirstNullBit();
118  objs->SetUniqueID(number);
119  fActive->SetBitNumber(number);
120  return number;
121 }
122 
123 ////////////////////////////////////////////////////////////////////////////////
124 /// Find the TObjString by slot number
125 
127 {
128  TObjLink *lnk = fUUIDs->FirstLink();
129  while (lnk) {
130  TObject *obj = lnk->GetObject();
131  if (obj->GetUniqueID() == number) return (TObjString*)obj;
132  lnk = lnk->Next();
133  }
134  return 0;
135 }
136 
137 ////////////////////////////////////////////////////////////////////////////////
138 /// Remove entry number in the list of uuids
139 
141 {
142  if (number > (UInt_t)fObjects->GetSize()) return;
143  TObjLink *lnk = fUUIDs->FirstLink();
144  while (lnk) {
145  TObject *obj = lnk->GetObject();
146  if (obj->GetUniqueID() == number) {
147  fUUIDs->Remove(lnk);
148  delete obj;
149  fActive->ResetBit(number);
150  fObjects->AddAt(0,number);
151  return;
152  }
153  lnk = lnk->Next();
154  }
155 }
virtual void Delete(Option_t *option="")
Remove all objects from the list AND delete all heap based objects.
Definition: TList.cxx:405
This class is a specialized TProcessID managing the list of UUIDs.
Definition: TProcessUUID.h:34
Collectable string class.
Definition: TObjString.h:32
virtual TObject * FindObject(const char *name) const
Find an object in this list using its name.
Definition: TList.cxx:497
TList * fUUIDs
Definition: TProcessUUID.h:41
UInt_t FirstNullBit(UInt_t startBit=0) const
Return position of first null bit (starting from position 0 and up)
Definition: TBits.cxx:261
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition: TObject.cxx:732
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:44
THashList implements a hybrid collection class consisting of a hash table and a list to store TObject...
Definition: THashList.h:36
A TProcessID identifies a ROOT job in a unique way in time and space.
Definition: TProcessID.h:34
ClassImp(TProcessUUID) TProcessUUID
Default constructor.
virtual void SetUniqueID(UInt_t uid)
Set the unique object id.
Definition: TObject.cxx:743
TObject * UncheckedAt(Int_t i) const
Definition: TObjArray.h:91
virtual void AddAtAndExpand(TObject *obj, Int_t idx)
Add object at position idx.
Definition: TObjArray.cxx:222
TObjArray * fObjects
Reference count to this object (from TFile)
Definition: TProcessID.h:42
virtual TObject * Remove(TObject *obj)
Remove object from the list.
Definition: TList.cxx:675
unsigned int UInt_t
Definition: RtypesCore.h:42
const char * AsString() const
Return UUID as string. Copy string immediately since it will be reused.
Definition: TUUID.cxx:536
TBits * fActive
Definition: TProcessUUID.h:42
virtual TObjLink * FirstLink() const
Definition: TList.h:101
virtual void AddAt(TObject *obj, Int_t idx)
Add object at position ids.
Definition: TObjArray.cxx:239
virtual Int_t GetSize() const
Definition: TCollection.h:95
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 ...
virtual UInt_t GetUniqueID() const
Return the unique object id.
Definition: TObject.cxx:433
Mother of all ROOT objects.
Definition: TObject.h:58
Container of bits.
Definition: TBits.h:33
virtual void Add(TObject *obj)
Definition: TList.h:81
void SetUUIDNumber(UInt_t index)
Definition: TUUID.h:82
void ResetBit(UInt_t f)
Definition: TObject.h:172
TObject * obj
void SetBitNumber(UInt_t bitnumber, Bool_t value=kTRUE)
Definition: TBits.h:198
void RemoveUUID(UInt_t number)
Remove entry number in the list of uuids.