78 #include "TDataSetIter.h"
88 UInt_t StObject::fgTally=0;
89 StXRefManagerList StXRefManager::fgManagerList;
90 int StXRefManager::fgRWmode=-1;
91 enum {kBelongs = (1<<22)};
103 TObject::operator=(sto);
104 SetBit(kBelongs,0);
return *
this;
107 StObject::~StObject()
111 void StObject::Streamer(TBuffer &R__b)
116 if (R__b.IsReading()) {
117 Version_t R__v = R__b.ReadVersion();
120 case 1: TObject::Streamer(R__b);
return;
121 case 2: R__b >> uc;
if (uc) TObject::Streamer(R__b);
return;
122 default: TObject::Streamer(R__b);
return;
126 R__b.WriteVersion(StObject::Class());
128 UInt_t udx = GetUniqueID();
129 if (!udx) { udx = ++fgTally; SetUniqueID(udx);}
131 TObject::Streamer(R__b);
135 UInt_t StObject::Ztreamer(TBuffer &R__b)
137 UInt_t udx = GetUniqueID();
138 if (!udx) { udx = ++fgTally; SetUniqueID(udx);}
150 void StUUId::Generate()
152 static UInt_t uu[4] = {0,0,0,0};
154 uu[3] = TMath::Hash(gSystem->HostName());
155 uu[3] ^= TMath::Hash(gSystem->WorkingDirectory());
156 uu[2] = (gSystem->GetPid())<<16;
161 fID[1] = (UInt_t)((ULong_t)
this);
162 #if ROOT_VERSION_CODE < 335105
163 fID[0] = (UInt_t)((ULong_t)gSystem->Now());
165 fID[0] = (UInt_t)((ULong64_t)gSystem->Now());
170 void StUUId::Streamer(TBuffer &R__b)
172 if (R__b.IsReading()) {
173 R__b.ReadFastArray (fID,4);
175 R__b.WriteFastArray(fID,4);
181 if (
this != &from) memcpy(fID,from.fID,
sizeof(fID));
185 StUUId &StUUId::operator=(
const char *from )
187 memcpy(fID,from ,16);
return *
this;
190 int StUUId::Compare(
const StUUId &u2)
const
192 return memcmp(fID,u2.fID,16);
203 if (evt) SetUUId(evt->GetUUId());
213 void StXRef::Streamer(TBuffer &R__b)
217 if (R__b.IsReading() ) {
218 StXRefManager::fgRWmode = 0;
219 Version_t R__v = R__b.ReadVersion(&R__s,&R__c);
if (R__v){};
220 fUUId.Streamer(R__b);
221 StXRefManager::Open(
this);
222 TDataSet::Streamer(R__b);
224 StXRefManager::Close(
this);
226 R__b.CheckByteCount(R__s,R__c,Class());
229 StXRefManager::fgRWmode = 1;
230 assert(!fUUId.IsNull());
232 R__c = R__b.WriteVersion(Class(),kTRUE);
233 fUUId.Streamer(R__b);
234 StXRefManager::Open(
this);
235 TDataSet::Streamer(R__b);
236 StXRefManager::Close(
this);
238 R__b.SetByteCount(R__c,kTRUE);
246 fMain->SetUUId(fUUId);
253 if (ds ==
this)
return;
254 if (ds->GetParent() ==
this)
return;
256 if (os == ds)
return;
258 assert(os->IsA()==ds->IsA());
262 if (!xr->InheritsFrom(Class()))
continue;
263 if (fUUId.Compare(xr->GetUUId()))
continue;
267 if (ds->InheritsFrom(Class()))
268 assert(!fUUId.Compare(((
StXRef*)ds)->GetUUId()));
269 ds->
Shunt(0); TDataSet::Add(ds);
279 void StXRefMain::Streamer(TBuffer &R__b)
281 StXRef::Streamer(R__b);
284 StXRefManager::StXRefManager(
const StUUId &
id)
290 fgManagerList.push_front(
this);
291 fColList.push_front(0);
294 StXRefManager::~StXRefManager()
298 fObjTab.GetMiMax(umin,umax);
299 for (u=umin;u<=umax;u++) {
300 TObject **to = (TObject**)fObjTab.Get(u);
303 (*to)->SetUniqueID(0);
306 fgManagerList.remove(
this);
307 if (fgManager==
this) { fgManager=0; StObject::fgTally=0;}
309 for (StCollListIter it = fColList.begin(); *it ;it++) {
delete *it;}
314 void StXRefManager::Cd(
StXRef *xref)
318 if (man->fTally!=StObject::fgTally) {
319 man->fTally = StObject::fgTally;
322 if (!man || man->fUUId.Compare(xref->GetUUId())!=0) {
323 StXRefManagerListIter it;
325 for (it=fgManagerList.begin();it!=fgManagerList.end();it++){
327 if (m->fUUId.Compare(xref->GetUUId())!=0)
continue;
333 void StXRefManager::Open(
StXRef *xref)
336 if (xref->IsMain()) StObject::fgTally=1;
343 assert(xref->IsMain());
345 fgManagerList.push_front(man);
350 man->fMain = xref->GetMain();
352 xref->SetMain(man->fMain);
356 void StXRefManager::Close(
StXRef *xref)
359 if (!xref->IsMain())
return;
360 StObject::fgTally=0;fgRWmode=-1;
366 if (xref->IsMain()) man->Update();
367 if (man->fMain && man->fMain!= xref) man->fMain->Add(xref);
368 if (!xref->IsMain())
return;
369 delete man; fgRWmode=-1; StObject::fgTally=0;
374 void StXRefManager::AddColl (
StProxyUrr *rarr)
376 fUpd=1; fColList.push_front(rarr);
379 void StXRefManager::AddColl (
const StStrArray *sarr)
381 int size = sarr->size();
385 const TObject *to, **p;
386 const_VecTObjIter it= sarr->begin();
387 for(
int i=0;i<size;i++) {
388 if (!(to = it[i]))
continue;
389 if (!(u = to->GetUniqueID()))
continue;
390 p = (
const TObject**)fObjTab.GET(u);
392 if (*p == to)
continue;
393 assert(to->IsA() == (*p)->IsA());
399 void StXRefManager::Update ()
406 UInt_t idx,udx,sizeUrr,lst=999999;
408 for (it = fColList.begin(); (urr = *it);) {
409 sizeUrr = urr->size();
410 switch (urr->GetType()) {
416 p = (TObject**)fObjTab.Get(udx);
417 if (!p || !(*p))
break;
418 urr->GetAdr()[0] = *p;
423 arr = (
StObjArray*)urr->GetArr(); assert(arr);
424 for (idx=0;idx<sizeUrr;idx++) {
426 p = (TObject**)fObjTab.Get(udx);
427 if (!p || !(*p)) {(*urr)[lst++] = udx;
continue;}
431 if (lst) { urr->resize(lst-1); it++; }
432 else {it = fColList.erase(it);
delete urr;}
437 void StXRefManager::Clear (Option_t*)
443 if (!fgManager)
return 0;
444 return fgManager->fMain;
451 fTopPage = NewPage();
454 fMinUdx = 1000000000;
460 TPageMap::~TPageMap()
463 for (p = fList; p ; p = n)
464 { n = (ULong_t*)p[0]; free(p);}
467 ULong_t *TPageMap::NewPage()
469 int n =
sizeof(ULong_t)*(kPAGE+1);
470 ULong_t *p = (ULong_t*)malloc(n); memset(p,0,n);
471 p[0] = (ULong_t)fList; fList = p;
476 ULong_t *TPageMap::Get(UInt_t udx)
478 if ((udx&kLAST) == fLstUdx) {
479 if (!fLstPage)
return 0;
484 fLstUdx = (udx&kLAST);
485 ULong_t *b = fTopPage;
491 if (!(s -=kBITS))
break;;
495 return fLstPage + (udx&kMASK);
498 ULong_t *TPageMap::GET(UInt_t udx)
500 if (fMinUdx>udx) fMinUdx=udx;
501 if (fMaxUdx<udx) fMaxUdx=udx;
503 if ((udx&kLAST) != fLstUdx || fLstPage==0) {
504 fLstUdx = (udx&kLAST);
505 ULong_t *b = fTopPage,*a;
509 if (!(a = (ULong_t*)b[u])) {((ULong_t**)b)[u] = a = NewPage();}
511 if (!(s -=kBITS))
break;;
515 return fLstPage + (udx&kMASK);
518 void TPageMap::Test()
522 UInt_t range = 10000000;
523 UInt_t step = range/1000;
525 for (u=1; u < range; u+=step)
527 ULong_t *p = map.GET(u);
532 for (u=1; u < range; u+=step)
534 ULong_t *p = map.Get(u);
539 printf(
" TPageMap::Test() OK\n");
virtual void Remove(TDataSet *set)
Remiove the "set" from this TDataSet.
virtual TDataSet * Next() const
virtual void Shunt(TDataSet *newParent=0)
virtual TDataSet * FindByName(const char *name, const char *path="", Option_t *opt="") const