00001 // @(#)root/base:$Id: TProcessUUID.cxx 33608 2010-05-25 11:08:00Z brun $ 00002 // Author: Rene Brun 06/07/2002 00003 00004 /************************************************************************* 00005 * Copyright (C) 1995-2001, Rene Brun and Fons Rademakers. * 00006 * All rights reserved. * 00007 * * 00008 * For the licensing terms see $ROOTSYS/LICENSE. * 00009 * For the list of contributors see $ROOTSYS/README/CREDITS. * 00010 *************************************************************************/ 00011 00012 ////////////////////////////////////////////////////////////////////////// 00013 // 00014 // TProcessUUID 00015 // 00016 // This class is a specialized TProcessID managing the list of UUIDs. 00017 // In addition to TProcessID, this object has the following members: 00018 // - fUUIDs : a TList of TUUIDs in string format (using a TObjString) 00019 // - fActive : a TBits table with one bit per TUUID in the table 00020 // When a new TUUID is entered into the list fUUIDs, it is assigned 00021 // the first free slot in the list of bits and the TUUID UUIDNumber 00022 // is set to this slot number. 00023 // When a TUUID is removed from the list, the corresponding bit 00024 // is reset in fActive. 00025 // The object corresponding to a TUUID at slot I can be found 00026 // via fObjects->At(I). 00027 // One can use two mechanisms to find the object corresponding to a TUUID: 00028 // 1- the input is the TUUID.AsString. One can find the corresponding 00029 // TObjString object objs in fUUIDs via TList::FindObject(name). 00030 // The slot number is then objs->GetUniqueID(). 00031 // 2- The input is the UUIDNumber. The slot number is UIUIDNumber 00032 // 00033 // When a TRef points to an object having a TUUID, both the TRef and the 00034 // referenced object have their bit kHasUUID set. In this case, the pointer 00035 // TProcessID *fPID in TRef points to the unique object TProcessUUID. 00036 // The TRef uniqueID is directly the UUIDNumber=slot number. 00037 // 00038 ////////////////////////////////////////////////////////////////////////// 00039 00040 #include "TROOT.h" 00041 #include "TProcessUUID.h" 00042 #include "THashList.h" 00043 #include "TBits.h" 00044 #include "TObjString.h" 00045 #include "TUUID.h" 00046 00047 ClassImp(TProcessUUID) 00048 00049 //______________________________________________________________________________ 00050 TProcessUUID::TProcessUUID() : TProcessID() 00051 { 00052 // Default constructor. 00053 00054 fUUIDs = new TList(); 00055 fActive = new TBits(100); 00056 IncrementCount(); 00057 } 00058 00059 //______________________________________________________________________________ 00060 TProcessUUID::~TProcessUUID() 00061 { 00062 // Destructor. 00063 fUUIDs->Delete(); 00064 delete fUUIDs; fUUIDs = 0; 00065 delete fActive; fActive = 0; 00066 } 00067 00068 //______________________________________________________________________________ 00069 UInt_t TProcessUUID::AddUUID(TUUID &uuid, TObject *obj) 00070 { 00071 // Add uuid to the table of UUIDs 00072 // The TObject *obj has its uniqueID set to the UUID number 00073 // return entry number in the table 00074 00075 00076 UInt_t number; 00077 const char *uuids = uuid.AsString(); 00078 TObjString *objs = (TObjString*)fUUIDs->FindObject(uuids); 00079 if (objs) { 00080 number = objs->GetUniqueID(); 00081 uuid.SetUUIDNumber(number); 00082 objs->SetUniqueID(number); 00083 obj->SetUniqueID(number); 00084 obj->SetBit(kHasUUID); 00085 if (number >= (UInt_t)fObjects->GetSize()) fObjects->AddAtAndExpand(obj,number); 00086 if (fObjects->UncheckedAt(number) == 0) fObjects->AddAt(obj,number); 00087 return number; 00088 } 00089 00090 objs = new TObjString(uuids); 00091 fUUIDs->Add(objs); 00092 number = fActive->FirstNullBit(); 00093 uuid.SetUUIDNumber(number); 00094 objs->SetUniqueID(number); 00095 obj->SetUniqueID(number); 00096 obj->SetBit(kHasUUID); 00097 fActive->SetBitNumber(number); 00098 fObjects->AddAtAndExpand(obj,number); 00099 return number; 00100 } 00101 00102 //______________________________________________________________________________ 00103 UInt_t TProcessUUID::AddUUID(const char *uuids) 00104 { 00105 // Add uuid with name uuids to the table of UUIDs 00106 // return entry number in the table 00107 00108 00109 TObjString *objs = (TObjString*)fUUIDs->FindObject(uuids); 00110 if (objs) return objs->GetUniqueID(); 00111 00112 UInt_t number; 00113 objs = new TObjString(uuids); 00114 fUUIDs->Add(objs); 00115 number = fActive->FirstNullBit(); 00116 objs->SetUniqueID(number); 00117 fActive->SetBitNumber(number); 00118 return number; 00119 } 00120 00121 //______________________________________________________________________________ 00122 TObjString *TProcessUUID::FindUUID(UInt_t number) const 00123 { 00124 //Find the TObjString by slot number 00125 00126 TObjLink *lnk = fUUIDs->FirstLink(); 00127 while (lnk) { 00128 TObject *obj = lnk->GetObject(); 00129 if (obj->GetUniqueID() == number) return (TObjString*)obj; 00130 lnk = lnk->Next(); 00131 } 00132 return 0; 00133 } 00134 00135 //______________________________________________________________________________ 00136 void TProcessUUID::RemoveUUID(UInt_t number) 00137 { 00138 //Remove entry number in the list of uuids 00139 00140 if (number > (UInt_t)fObjects->GetSize()) return; 00141 TObjLink *lnk = fUUIDs->FirstLink(); 00142 while (lnk) { 00143 TObject *obj = lnk->GetObject(); 00144 if (obj->GetUniqueID() == number) { 00145 fUUIDs->Remove(lnk); 00146 delete obj; 00147 fActive->ResetBit(number); 00148 fObjects->AddAt(0,number); 00149 return; 00150 } 00151 lnk = lnk->Next(); 00152 } 00153 }