Logo ROOT  
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 "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 = 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 }
TBits::FirstNullBit
UInt_t FirstNullBit(UInt_t startBit=0) const
Return position of first null bit (starting from position 0 and up)
Definition: TBits.cxx:275
TUUID::SetUUIDNumber
void SetUUIDNumber(UInt_t index)
Definition: TUUID.h:80
TProcessUUID::fUUIDs
TList * fUUIDs
Definition: TProcessUUID.h:39
TProcessUUID
Definition: TProcessUUID.h:32
TProcessUUID::TProcessUUID
TProcessUUID()
Default constructor.
Definition: TProcessUUID.cxx:56
TProcessUUID::FindUUID
TObjString * FindUUID(UInt_t number) const
Find the TObjString by slot number.
Definition: TProcessUUID.cxx:128
TList::FindObject
virtual TObject * FindObject(const char *name) const
Find an object in this list using its name.
Definition: TList.cxx:577
TList::Delete
virtual void Delete(Option_t *option="")
Remove all objects from the list AND delete all heap based objects.
Definition: TList.cxx:469
ClassImp
#define ClassImp(name)
Definition: Rtypes.h:364
TObjString.h
TProcessID
Definition: TProcessID.h:74
TProcessID::IncrementCount
Int_t IncrementCount()
Increase the reference count to this object.
Definition: TProcessID.cxx:313
TObject::GetUniqueID
virtual UInt_t GetUniqueID() const
Return the unique object id.
Definition: TObject.cxx:377
TProcessID::fObjects
ROOT::Internal::TAtomicPointer< TObjArray * > fObjects
Reference count to this object (from TFile)
Definition: TProcessID.h:82
TBits
Definition: TBits.h:26
TObjArray::UncheckedAt
TObject * UncheckedAt(Int_t i) const
Definition: TObjArray.h:90
TUUID.h
TObjString
Definition: TObjString.h:28
TProcessUUID::fActive
TBits * fActive
Definition: TProcessUUID.h:40
TList::FirstLink
virtual TObjLink * FirstLink() const
Definition: TList.h:108
THashList
Definition: THashList.h:34
TObject::SetBit
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition: TObject.cxx:696
TObjArray::AddAtAndExpand
virtual void AddAtAndExpand(TObject *obj, Int_t idx)
Add object at position idx.
Definition: TObjArray.cxx:235
TProcessUUID::AddUUID
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 ...
Definition: TProcessUUID.cxx:78
TUUID
Definition: TUUID.h:42
unsigned int
THashList.h
TObjArray::AddAt
virtual void AddAt(TObject *obj, Int_t idx)
Add object at position ids.
Definition: TObjArray.cxx:254
TProcessUUID::RemoveUUID
void RemoveUUID(UInt_t number)
Remove entry number in the list of uuids.
Definition: TProcessUUID.cxx:142
TObjArray.h
TBits.h
TList::Remove
virtual TObject * Remove(TObject *obj)
Remove object from the list.
Definition: TList.cxx:821
TCollection::GetSize
virtual Int_t GetSize() const
Return the capacity of the collection, i.e.
Definition: TCollection.h:182
TList::Add
virtual void Add(TObject *obj)
Definition: TList.h:87
TObject
Definition: TObject.h:37
TBits::SetBitNumber
void SetBitNumber(UInt_t bitnumber, Bool_t value=kTRUE)
Definition: TBits.h:205
TUUID::AsString
const char * AsString() const
Return UUID as string. Copy string immediately since it will be reused.
Definition: TUUID.cxx:562
TProcessUUID::~TProcessUUID
virtual ~TProcessUUID()
Destructor.
Definition: TProcessUUID.cxx:66
TBits::ResetBitNumber
void ResetBitNumber(UInt_t bitnumber)
Definition: TBits.h:234
TObject::kHasUUID
@ kHasUUID
if object has a TUUID (its fUniqueID=UUIDNumber)
Definition: TObject.h:62
TProcessUUID.h
TObject::SetUniqueID
virtual void SetUniqueID(UInt_t uid)
Set the unique object id.
Definition: TObject.cxx:707