Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files 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 \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 
51 ClassImp(TProcessUUID);
52 
53 ////////////////////////////////////////////////////////////////////////////////
54 /// Default constructor.
55 
56 TProcessUUID::TProcessUUID() : TProcessID()
57 {
58  fUUIDs = new THashList(100,3);
59  fActive = new TBits(100);
60  IncrementCount();
61 }
62 
63 ////////////////////////////////////////////////////////////////////////////////
64 /// Destructor.
65 
66 TProcessUUID::~TProcessUUID()
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 
78 UInt_t TProcessUUID::AddUUID(TUUID &uuid, TObject *obj)
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 
128 TObjString *TProcessUUID::FindUUID(UInt_t number) const
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 
142 void TProcessUUID::RemoveUUID(UInt_t number)
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 }