StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StObject.cxx
1 // $Id: StObject.cxx,v 1.28 2015/08/28 19:54:18 perev Exp $
2 // $Log: StObject.cxx,v $
3 // Revision 1.28 2015/08/28 19:54:18 perev
4 // Add specific copy constructor to StObject.
5 // This ctr set zero to bit 1<<22. This boit means that object belongs
6 // to structured container. But copy obviously not.
7 //
8 // Revision 1.27 2012/06/11 15:08:41 fisyak
9 // std namespace, warn off for x64
10 //
11 // Revision 1.26 2012/02/21 18:50:46 perev
12 // bug #2281 fix
13 //
14 // Revision 1.22 2009/08/26 20:44:08 fine
15 // fix the compilation issues under SL5_64_bits gcc 4.3.2
16 //
17 // Revision 1.21 2006/08/10 03:34:38 perev
18 // Assert==>assert
19 //
20 // Revision 1.20 2005/10/21 21:13:52 perev
21 // test added to avoid copy to itself. Make walgrin happy
22 //
23 // Revision 1.19 2004/05/03 23:31:46 perev
24 // Possible non init WarnOff
25 //
26 // Revision 1.18 2003/09/02 17:59:24 perev
27 // gcc 3.2 updates + WarnOff
28 //
29 // Revision 1.17 2002/11/26 02:23:38 perev
30 // new ROOT adoptation
31 //
32 // Revision 1.16 2002/01/27 23:46:49 perev
33 // Zombie test added
34 //
35 // Revision 1.15 2001/05/30 17:46:41 perev
36 // StEvent branching
37 //
38 // Revision 1.14 2000/09/30 17:48:27 perev
39 // Zombies cons and loop for stru vector
40 //
41 // Revision 1.13 2000/09/15 15:11:58 perev
42 // Zombie for StEvent
43 //
44 // Revision 1.12 2000/07/30 01:49:03 perev
45 // StObject vers restored
46 //
47 // Revision 1.10 2000/06/19 01:28:26 perev
48 // STL StEvent
49 //
50 // Revision 1.9 2000/04/23 01:00:45 perev
51 // StEvent monolitic I/O
52 //
53 // Revision 1.8 2000/04/20 14:24:09 perev
54 // StArray fixes
55 //
56 // Revision 1.7 2000/04/18 02:57:25 perev
57 // StEvent browse
58 //
59 // Revision 1.6 1999/12/21 15:42:58 fine
60 // remove compilation warning
61 //
62 // Revision 1.5 1999/12/13 21:40:41 perev
63 // Remove warnings
64 //
65 // Revision 1.4 1999/11/17 14:22:10 perev
66 // bug in dtor fix
67 //
68 // Revision 1.3 1999/11/15 23:09:10 perev
69 // Streamer for StrArray and auto remove
70 //
71 // Revision 1.2 1999/06/23 20:31:04 perev
72 // StArray I/O + browser
73 //
74 // Revision 1.1 1999/04/30 13:15:55 fisyak
75 // Ad StObject, modification StArray for StRootEvent
76 //
77 #include "StObject.h"
78 #include "TDataSetIter.h"
79 #include "TROOT.h"
80 #include "TError.h"
81 #include "TMath.h"
82 #include "TBrowser.h"
83 #include "TClass.h"
84 #include "StArray.h"
85 #include "TSystem.h"
86 
87 StXRefManager *StXRefManager::fgManager=0;
88 UInt_t StObject::fgTally=0;
89 StXRefManagerList StXRefManager::fgManagerList;
90 int StXRefManager::fgRWmode=-1;
91 enum {kBelongs = (1<<22)};
92 
93 
94 ClassImp(StObject)
95 //_____________________________________________________________________________
96 StObject::StObject(const StObject &sto):TObject(sto)
97 {
98  SetBit(kBelongs,0);
99 }
100 //_____________________________________________________________________________
101 StObject &StObject::operator=(const StObject &sto)
102 {
103  TObject::operator=(sto);
104  SetBit(kBelongs,0); return *this;
105 }
106 //_____________________________________________________________________________
107 StObject::~StObject()
108 {
109 }
110 //______________________________________________________________________________
111 void StObject::Streamer(TBuffer &R__b)
112 {
113 // Stream an object of class StObject.
114  unsigned char uc=0;
115 
116  if (R__b.IsReading()) {
117  Version_t R__v = R__b.ReadVersion();
118 
119  switch (R__v){
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;
123  }
124 
125  } else {
126  R__b.WriteVersion(StObject::Class());
127  if (fgTally) {
128  UInt_t udx = GetUniqueID();
129  if (!udx) { udx = ++fgTally; SetUniqueID(udx);}
130  }
131  TObject::Streamer(R__b);
132  }
133 }
134 //______________________________________________________________________________
135 UInt_t StObject::Ztreamer(TBuffer &R__b)
136 {
137  UInt_t udx = GetUniqueID();
138  if (!udx) { udx = ++fgTally; SetUniqueID(udx);}
139  R__b << udx;
140  return udx;
141 }
142 
143 ClassImp(StUUId)
144 //_____________________________________________________________________________
145 StUUId::StUUId()
146 {
147  memset(fID,0,16);
148 }
149 //_____________________________________________________________________________
150 void StUUId::Generate()
151 {
152  static UInt_t uu[4] = {0,0,0,0};
153  if (!uu[0]) {
154  uu[3] = TMath::Hash(gSystem->HostName());
155  uu[3] ^= TMath::Hash(gSystem->WorkingDirectory());
156  uu[2] = (gSystem->GetPid())<<16;
157  }
158  if (fID[0]) return;
159  fID[3] = uu[3];
160  fID[2] = uu[2]++;
161  fID[1] = (UInt_t)((ULong_t)this);
162 #if ROOT_VERSION_CODE < 335105 /* ROOT_VERSION(5,29,1) */
163  fID[0] = (UInt_t)((ULong_t)gSystem->Now());
164 #else
165  fID[0] = (UInt_t)((ULong64_t)gSystem->Now());
166 #endif
167 }
168 
169 //_____________________________________________________________________________
170 void StUUId::Streamer(TBuffer &R__b)
171 {
172  if (R__b.IsReading()) {
173  R__b.ReadFastArray (fID,4);
174  } else {
175  R__b.WriteFastArray(fID,4);
176  }
177 }
178 //_____________________________________________________________________________
179 StUUId &StUUId::operator=(const StUUId &from)
180 {
181  if (this != &from) memcpy(fID,from.fID,sizeof(fID));
182  return *this;
183 }
184 //_____________________________________________________________________________
185 StUUId &StUUId::operator=(const char *from )
186 {
187  memcpy(fID,from ,16); return *this;
188 }
189 //_____________________________________________________________________________
190 int StUUId::Compare(const StUUId &u2) const
191 {
192  return memcmp(fID,u2.fID,16);
193 }
194 
195 
196 //_____________________________________________________________________________
197 ClassImp(StXRef)
198 //_____________________________________________________________________________
199 StXRef::StXRef(const char *brName, StXRefMain *evt,UInt_t tally)
200  : TDataSet(brName,evt)
201 {
202  SetMain(evt);
203  if (evt) SetUUId(evt->GetUUId());
204  SetTally(tally);
205 
206 }
207 //_____________________________________________________________________________
208 StXRef::~StXRef()
209 {
210 }
211 
212 //_____________________________________________________________________________
213 void StXRef::Streamer(TBuffer &R__b)
214 {
215  UInt_t R__s,R__c;
216 
217  if (R__b.IsReading() ) { //READ
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);
223  R__b >> fTally;
224  StXRefManager::Close(this);
225  Synchro(1);
226  R__b.CheckByteCount(R__s,R__c,Class());
227 
228  } else {
229  StXRefManager::fgRWmode = 1;
230  assert(!fUUId.IsNull());
231  Synchro(0);
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);
237  R__b << fTally;
238  R__b.SetByteCount(R__c,kTRUE);
239  }
240 }
241 //_____________________________________________________________________________
242 StXRefMain *StXRef::GetMain()
243 {
244  if (!fMain) {
245  fMain = MakeMain();
246  fMain->SetUUId(fUUId);
247  }
248  return fMain;
249 }
250 //_____________________________________________________________________________
251 void StXRef::Add(TDataSet *ds)
252 {
253  if (ds == this) return;
254  if (ds->GetParent() == this) return;
255  TDataSet *os = FindByName(ds->GetName());
256  if (os == ds) return;
257  if (os){
258  assert(os->IsA()==ds->IsA());
259  TDataSetIter Next(this);
260  StXRef *xr;
261  while((xr = (StXRef*)Next())) {
262  if (!xr->InheritsFrom(Class())) continue;
263  if (fUUId.Compare(xr->GetUUId()))continue;
264  Remove(xr);
265  }
266  }
267  if (ds->InheritsFrom(Class()))
268  assert(!fUUId.Compare(((StXRef*)ds)->GetUUId()));
269  ds->Shunt(0); TDataSet::Add(ds);
270 }
271 
272 //_____________________________________________________________________________
273 ClassImp(StXRefMain)
274 
276 {
277 }
278 //______________________________________________________________________________
279 void StXRefMain::Streamer(TBuffer &R__b)
280 {
281  StXRef::Streamer(R__b);
282 }
283 //_____________________________________________________________________________
284 StXRefManager::StXRefManager(const StUUId &id)
285 {
286  fTally = 0;
287  fUpd = 0;
288  fUUId = id;
289  fMain=0;
290  fgManagerList.push_front(this);
291  fColList.push_front(0);
292 }
293 //_____________________________________________________________________________
294 StXRefManager::~StXRefManager()
295 {
296 
297  UInt_t umin,umax,u;
298  fObjTab.GetMiMax(umin,umax);
299  for (u=umin;u<=umax;u++) {
300  TObject **to = (TObject**)fObjTab.Get(u);
301  if (!to ) continue;
302  if (!*to) continue;
303  (*to)->SetUniqueID(0);
304  }
305 
306  fgManagerList.remove(this);
307  if (fgManager==this) { fgManager=0; StObject::fgTally=0;}
308  fMain=0; fTally=0;
309  for (StCollListIter it = fColList.begin(); *it ;it++) {delete *it;}
310 }
311 
312 
313 //_____________________________________________________________________________
314 void StXRefManager::Cd(StXRef *xref)
315 {
316  StXRefManager *man = fgManager;
317  if (man) {
318  if (man->fTally!=StObject::fgTally) {//Was modified
319  man->fTally = StObject::fgTally;
320  } }
321 
322  if (!man || man->fUUId.Compare(xref->GetUUId())!=0) {
323  StXRefManagerListIter it;
324  man = 0;
325  for (it=fgManagerList.begin();it!=fgManagerList.end();it++){
326  StXRefManager *m=*it;
327  if (m->fUUId.Compare(xref->GetUUId())!=0) continue;
328  man = m; break;
329  } }
330  fgManager = man;
331 }
332 //_____________________________________________________________________________
333 void StXRefManager::Open(StXRef *xref)
334 {
335  if (fgRWmode==1) { //Writing
336  if (xref->IsMain()) StObject::fgTally=1;
337  return;
338  }
339 
340  Cd(xref);
341  StXRefManager *man = fgManager;
342  if (!man) {
343  assert(xref->IsMain());
344  man = new StXRefManager(xref->GetUUId());
345  fgManagerList.push_front(man);
346  fgManager = man;
347  StObject::fgTally=1;
348  }
349  if (man->fMain==0) {
350  man->fMain = xref->GetMain();
351  } else {
352  xref->SetMain(man->fMain);
353  }
354 }
355 //_____________________________________________________________________________
356 void StXRefManager::Close(StXRef *xref)
357 {
358  if (fgRWmode==1) { //Writing
359  if (!xref->IsMain()) return;
360  StObject::fgTally=0;fgRWmode=-1;
361  return;
362  }
363  Cd(xref);
364  StXRefManager *man = fgManager;
365  assert(man);
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;
370 }
371 
372 
373 //_____________________________________________________________________________
374 void StXRefManager::AddColl (StProxyUrr *rarr)
375 {
376  fUpd=1; fColList.push_front(rarr);
377 }
378 //_____________________________________________________________________________
379 void StXRefManager::AddColl (const StStrArray *sarr)
380 {
381  int size = sarr->size();
382  if (!size) return;
383  fUpd=1;
384  UInt_t u;
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);
391  if (*p) {// Used already
392  if (*p == to) continue;
393  assert(to->IsA() == (*p)->IsA());
394  }
395  *p = to;
396  }
397 }
398 //_____________________________________________________________________________
399 void StXRefManager::Update ()
400 {
401  if(!fUpd) return;
402  fUpd = 0;
403  StObjArray *arr;
404  StProxyUrr *urr;
405  StCollListIter it;
406  UInt_t idx,udx,sizeUrr,lst=999999;
407  TObject **p;
408  for (it = fColList.begin(); (urr = *it);) {//List
409  sizeUrr = urr->size();
410  switch (urr->GetType()) {
411 
412  case 1: //Link case
413  assert(sizeUrr==1);
414  lst = 2;
415  udx = (*urr)[0];
416  p = (TObject**)fObjTab.Get(udx);
417  if (!p || !(*p)) break;
418  urr->GetAdr()[0] = *p;
419  lst = 0; break;
420 
421  case 0: //refArray case
422  lst=0;
423  arr = (StObjArray*)urr->GetArr(); assert(arr);
424  for (idx=0;idx<sizeUrr;idx++) { //RefArray loop
425  udx = (*urr)[idx];
426  p = (TObject**)fObjTab.Get(udx);
427  if (!p || !(*p)) {(*urr)[lst++] = udx; continue;}
428  arr->push_back(*p);
429  }//end RefArray loop
430  }
431  if (lst) { urr->resize(lst-1); it++; }
432  else {it = fColList.erase(it); delete urr;}
433  }//end List
434 
435 }
436 //_____________________________________________________________________________
437 void StXRefManager::Clear (Option_t*)
438 {}
439 
440 //_____________________________________________________________________________
441 TDataSet *StXRefManager::GetMain()
442 {
443  if (!fgManager) return 0;
444  return fgManager->fMain;
445 }
446 //_____________________________________________________________________________
447 TPageMap::TPageMap()
448 {
449 
450  fList = 0;
451  fTopPage = NewPage();
452  fLstPage = 0;
453  fLstUdx = 0;
454  fMinUdx = 1000000000;
455  fMaxUdx = 0;
456 }
457 //_____________________________________________________________________________
458 
459 
460 TPageMap::~TPageMap()
461 {
462  ULong_t *p,*n=0;
463  for (p = fList; p ; p = n)
464  { n = (ULong_t*)p[0]; free(p);}
465 }
466 //_____________________________________________________________________________
467 ULong_t *TPageMap::NewPage()
468 {
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;
472  return p+1;
473 }
474 
475 //_____________________________________________________________________________
476 ULong_t *TPageMap::Get(UInt_t udx)
477 {
478  if ((udx&kLAST) == fLstUdx) {
479  if (!fLstPage) return 0;
480 
481  } else {
482 
483  fLstPage = 0;
484  fLstUdx = (udx&kLAST);
485  ULong_t *b = fTopPage;
486  UInt_t u,s=kBITZ;
487  while(2001) {
488  u = (udx>>s)&kMASK;
489  b = (ULong_t*)b[u];
490  if (!b) return 0;
491  if (!(s -=kBITS)) break;;
492  }
493  fLstPage = b;
494  }
495  return fLstPage + (udx&kMASK);
496 }
497 //_____________________________________________________________________________
498 ULong_t *TPageMap::GET(UInt_t udx)
499 {
500  if (fMinUdx>udx) fMinUdx=udx;
501  if (fMaxUdx<udx) fMaxUdx=udx;
502 
503  if ((udx&kLAST) != fLstUdx || fLstPage==0) {
504  fLstUdx = (udx&kLAST);
505  ULong_t *b = fTopPage,*a;
506  UInt_t u,s=kBITZ;
507  while(2001) {
508  u = (udx>>s)&kMASK;
509  if (!(a = (ULong_t*)b[u])) {((ULong_t**)b)[u] = a = NewPage();}
510  b = a;
511  if (!(s -=kBITS)) break;;
512  }
513  fLstPage = b;
514  }
515  return fLstPage + (udx&kMASK);
516 }
517 //_____________________________________________________________________________
518 void TPageMap::Test()
519 {
520  TPageMap map;
521 
522  UInt_t range = 10000000;
523  UInt_t step = range/1000;
524  UInt_t u;
525  for (u=1; u < range; u+=step)
526  {
527  ULong_t *p = map.GET(u);
528  assert(p);
529  assert(!*p);
530  *p = u;
531  }
532  for (u=1; u < range; u+=step)
533  {
534  ULong_t *p = map.Get(u);
535  assert(p);
536  assert(*p);
537  assert(*p==u);
538  }
539  printf(" TPageMap::Test() OK\n");
540 }
541 
542 
543 
544 
545 
546 
547 
548 
549 
virtual void Remove(TDataSet *set)
Remiove the &quot;set&quot; from this TDataSet.
Definition: TDataSet.cxx:641
virtual TDataSet * Next() const
Definition: TDataSet.cxx:447
virtual void Shunt(TDataSet *newParent=0)
Definition: TDataSet.cxx:810
virtual TDataSet * FindByName(const char *name, const char *path="", Option_t *opt="") const
Definition: TDataSet.cxx:378