ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
TStreamerInfoWriteBuffer.cxx
Go to the documentation of this file.
1 // @(#)root/io:$Id$
2 // Author: Rene Brun 12/10/2000
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2000, 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 #include "TBuffer.h"
13 #include "TClass.h"
14 #include "TClonesArray.h"
15 #include "TError.h"
16 #include "TProcessID.h"
17 #include "TStreamer.h"
18 #include "TStreamerElement.h"
19 #include "TStreamerInfo.h"
21 #include "TRefTable.h"
22 #include "TFile.h"
23 
24 #include "TVirtualArray.h"
25 #include "TBufferFile.h"
26 #include "TInterpreter.h"
27 
28 //==========CPP macros
29 
30 #define DOLOOP for(int k=0; k<narr; ++k)
31 
32 #define WriteBasicTypeElem(name,index) \
33  { \
34  name *x=(name*)(arr[index]+ioffset); \
35  b << *x; \
36  }
37 
38 #define WriteBasicType(name) \
39  { \
40  WriteBasicTypeElem(name,0); \
41  }
42 
43 #define WriteBasicTypeLoop(name) \
44  { \
45  for(int k=0; k<narr; ++k) WriteBasicTypeElem(name,k); \
46  }
47 
48 #define WriteBasicArrayElem(name,index) \
49  { \
50  name *x=(name*)(arr[index]+ioffset); \
51  b.WriteFastArray(x,compinfo[i]->fLength); \
52  }
53 
54 #define WriteBasicArray(name) \
55  { \
56  WriteBasicArrayElem(name,0); \
57  }
58 
59 #define WriteBasicArrayLoop(name) \
60  { \
61  for(int k=0; k<narr; ++k) WriteBasicArrayElem(name,k); \
62  }
63 
64 #define WriteBasicPointerElem(name,index) \
65  { \
66  Int_t *l = (Int_t*)(arr[index]+imethod); \
67  name **f = (name**)(arr[index]+ioffset); \
68  name *af = *f; \
69  if (af && *l) b << Char_t(1); \
70  else {b << Char_t(0); continue;} \
71  int j; \
72  for(j=0;j<compinfo[i]->fLength;j++) { \
73  b.WriteFastArray(f[j],*l); \
74  } \
75  }
76 
77 #define WriteBasicPointer(name) \
78  { \
79  int imethod = compinfo[i]->fMethod+eoffset; \
80  WriteBasicPointerElem(name,0); \
81  }
82 
83 #define WriteBasicPointerLoop(name) \
84  { \
85  int imethod = compinfo[i]->fMethod+eoffset; \
86  for(int k=0; k<narr; ++k) { \
87  WriteBasicPointerElem(name,k); \
88  } \
89  }
90 
91 // Helper function for TStreamerInfo::WriteBuffer
92 namespace {
93  template <class T> Bool_t R__TestUseCache(TStreamerElement *element)
94  {
95  return element->TestBit(TStreamerElement::kCache);
96  }
97 
98  template <> Bool_t R__TestUseCache<TVirtualArray>(TStreamerElement*)
99  {
100  // We are already using the cache, no need to recurse one more time.
101  return kFALSE;
102  }
103 }
104 
105 ////////////////////////////////////////////////////////////////////////////////
106 /// The object at pointer is serialized to the buffer b
107 /// if (arrayMode & 1) ptr is a pointer to array of pointers to the objects
108 /// otherwise it is a pointer to a pointer to a single object.
109 /// This also means that T is of a type such that arr[i] is a pointer to an
110 /// object. Currently the only anticipated instantiation are for T==char**
111 /// and T==TVirtualCollectionProxy
112 
113 template <class T>
115  TCompInfo *const*const compinfo, Int_t first, Int_t last,
116  Int_t narr, Int_t eoffset, Int_t arrayMode)
117 {
118  Bool_t needIncrement = !( arrayMode & 2 );
119  arrayMode = arrayMode & (~2);
120 
121  if (needIncrement) b.IncrementLevel(this);
122 
123  //mark this class as being used in the current file
124  b.TagStreamerInfo(this);
125 
126  //============
127 
128  //loop on all active members
129 // Int_t last;
130 // if (first < 0) {first = 0; last = ninfo;}
131 // else last = first+1;
132 
133  // In order to speed up the case where the object being written is
134  // not in a collection (i.e. arrayMode is false), we actually
135  // duplicate the elementary types using this typeOffset.
136  static const int kHaveLoop = 1024;
137  const Int_t typeOffset = arrayMode ? kHaveLoop : 0;
138 
139  for (Int_t i=first;i<last;i++) {
140 
141  TStreamerElement *aElement = (TStreamerElement*)compinfo[i]->fElem;
142 
143  if (needIncrement) b.SetStreamerElementNumber(aElement,compinfo[i]->fType);
144 
145  Int_t ioffset = eoffset+compinfo[i]->fOffset;
146 
147  if (R__TestUseCache<T>(aElement)) {
148  if (aElement->TestBit(TStreamerElement::kWrite)) {
149  if (((TBufferFile&)b).PeekDataCache()==0) {
150  Warning("WriteBuffer","Skipping %s::%s because the cache is missing.",GetName(),aElement->GetName());
151  } else {
152  if (gDebug > 1) {
153  printf("WriteBuffer, class:%s, name=%s, fType[%d]=%d,"
154  " %s, bufpos=%d, arr=%p, eoffset=%d, Redirect=%p\n",
155  fClass->GetName(),aElement->GetName(),i,compinfo[i]->fType,
156  aElement->ClassName(),b.Length(),arr[0], eoffset,((TBufferFile&)b).PeekDataCache()->GetObjectAt(0));
157  }
158  WriteBufferAux(b,*((TBufferFile&)b).PeekDataCache(),compinfo,i,i+1,narr,eoffset, arrayMode);
159  }
160  continue;
161  } else {
162  if (gDebug > 1) {
163  printf("WriteBuffer, class:%s, name=%s, fType[%d]=%d,"
164  " %s, bufpos=%d, arr=%p, eoffset=%d, not a write rule, skipping.\n",
165  fClass->GetName(),aElement->GetName(),i,compinfo[i]->fType,
166  aElement->ClassName(),b.Length(),arr[0], eoffset);
167  }
168  // The rule was a cached element for a read, rule, the real offset is in the
169  // next element (the one for the rule itself).
170  if (aElement->TestBit(TStreamerElement::kRepeat)) continue;
171  ioffset = eoffset+compinfo[i]->fOffset;
172  }
173  }
174 
175 
176  if (gDebug > 1) {
177  printf("WriteBuffer, class:%s, name=%s, fType[%d]=%d, %s, "
178  "bufpos=%d, arr=%p, offset=%d\n",
179  fClass->GetName(),aElement->GetName(),i,compinfo[i]->fType,aElement->ClassName(),
180  b.Length(),arr[0],ioffset);
181  }
182 
183  switch (compinfo[i]->fType+typeOffset) {
184  // In this switch we intentionally use 'continue' instead of
185  // 'break' to avoid running the 2nd switch (see later in this
186  // function).
187 
188  case TStreamerInfo::kBool: WriteBasicType(Bool_t); continue;
189  case TStreamerInfo::kChar: WriteBasicType(Char_t); continue;
191  case TStreamerInfo::kInt: WriteBasicType(Int_t); continue;
192  case TStreamerInfo::kLong: WriteBasicType(Long_t); continue;
198  case TStreamerInfo::kUInt: WriteBasicType(UInt_t); continue;
202  Float_t *x=(Float_t*)(arr[0]+ioffset);
203  b.WriteFloat16(x,aElement);
204  continue;
205  }
207  Double_t *x=(Double_t*)(arr[0]+ioffset);
208  b.WriteDouble32(x,aElement);
209  continue;
210  }
211 
212  case TStreamerInfo::kBool + kHaveLoop: WriteBasicTypeLoop(Bool_t); continue;
213  case TStreamerInfo::kChar + kHaveLoop: WriteBasicTypeLoop(Char_t); continue;
214  case TStreamerInfo::kShort + kHaveLoop: WriteBasicTypeLoop(Short_t); continue;
215  case TStreamerInfo::kInt + kHaveLoop: WriteBasicTypeLoop(Int_t); continue;
216  case TStreamerInfo::kLong + kHaveLoop: WriteBasicTypeLoop(Long_t); continue;
217  case TStreamerInfo::kLong64 + kHaveLoop: WriteBasicTypeLoop(Long64_t); continue;
218  case TStreamerInfo::kFloat + kHaveLoop: WriteBasicTypeLoop(Float_t); continue;
219  case TStreamerInfo::kDouble + kHaveLoop: WriteBasicTypeLoop(Double_t); continue;
220  case TStreamerInfo::kUChar + kHaveLoop: WriteBasicTypeLoop(UChar_t); continue;
221  case TStreamerInfo::kUShort + kHaveLoop: WriteBasicTypeLoop(UShort_t); continue;
222  case TStreamerInfo::kUInt + kHaveLoop: WriteBasicTypeLoop(UInt_t); continue;
223  case TStreamerInfo::kULong + kHaveLoop: WriteBasicTypeLoop(ULong_t); continue;
224  case TStreamerInfo::kULong64 + kHaveLoop: WriteBasicTypeLoop(ULong64_t); continue;
225  case TStreamerInfo::kFloat16+ kHaveLoop: {
226  for(int k=0; k<narr; ++k) {
227  Float_t *x=(Float_t*)(arr[k]+ioffset);
228  b.WriteFloat16(x,aElement);
229  }
230  continue;
231  }
232  case TStreamerInfo::kDouble32+ kHaveLoop: {
233  for(int k=0; k<narr; ++k) {
234  Double_t *x=(Double_t*)(arr[k]+ioffset);
235  b.WriteDouble32(x,aElement);
236  }
237  continue;
238  }
239 
240  // write array of basic types array[8]
255  b.WriteFastArrayFloat16((Float_t*)(arr[0]+ioffset),compinfo[i]->fLength,aElement);
256  continue;
257  }
259  b.WriteFastArrayDouble32((Double_t*)(arr[0]+ioffset),compinfo[i]->fLength,aElement);
260  continue;
261  }
262 
277  for(int k=0; k<narr; ++k) {
278  b.WriteFastArrayFloat16((Float_t*)(arr[k]+ioffset),compinfo[i]->fLength,aElement);
279  }
280  continue;
281  }
283  for(int k=0; k<narr; ++k) {
284  b.WriteFastArrayDouble32((Double_t*)(arr[k]+ioffset),compinfo[i]->fLength,aElement);
285  }
286  continue;
287  }
288 
289  // write pointer to an array of basic types array[n]
304  int imethod = compinfo[i]->fMethod+eoffset;
305  Int_t *l = (Int_t*)(arr[0]+imethod);
306  Float_t **f = (Float_t**)(arr[0]+ioffset);
307  Float_t *af = *f;
308  if (af && *l) b << Char_t(1);
309  else {b << Char_t(0); continue;}
310  int j;
311  for(j=0;j<compinfo[i]->fLength;j++) {
312  b.WriteFastArrayFloat16(f[j],*l,aElement);
313  }
314  continue;
315  }
317  int imethod = compinfo[i]->fMethod+eoffset;
318  Int_t *l = (Int_t*)(arr[0]+imethod);
319  Double_t **f = (Double_t**)(arr[0]+ioffset);
320  Double_t *af = *f;
321  if (af && *l) b << Char_t(1);
322  else {b << Char_t(0); continue;}
323  int j;
324  for(j=0;j<compinfo[i]->fLength;j++) {
325  b.WriteFastArrayDouble32(f[j],*l,aElement);
326  }
327  continue;
328  }
329 
344  int imethod = compinfo[i]->fMethod+eoffset;
345  for(int k=0; k<narr; ++k) {
346  Int_t *l = (Int_t*)(arr[k]+imethod);
347  Float_t **f = (Float_t**)(arr[k]+ioffset);
348  Float_t *af = *f;
349  if (af && *l) b << Char_t(1);
350  else {b << Char_t(0); continue;}
351  int j;
352  for(j=0;j<compinfo[i]->fLength;j++) {
353  b.WriteFastArrayFloat16(f[j],*l,aElement);
354  }
355  }
356  continue;
357  }
359  int imethod = compinfo[i]->fMethod+eoffset;
360  for(int k=0; k<narr; ++k) {
361  Int_t *l = (Int_t*)(arr[k]+imethod);
362  Double_t **f = (Double_t**)(arr[k]+ioffset);
363  Double_t *af = *f;
364  if (af && *l) b << Char_t(1);
365  else {b << Char_t(0); continue;}
366  int j;
367  for(j=0;j<compinfo[i]->fLength;j++) {
368  b.WriteFastArrayDouble32(f[j],*l,aElement);
369  }
370  }
371  continue;
372  }
373 
375  Int_t *x=(Int_t*)(arr[0]+ioffset);
376  b << *x;
377  if (i == last-1) {
378  if (needIncrement) b.DecrementLevel(this);
379  return x[0]; // info used by TBranchElement::FillLeaves
380  }
381  continue;
382  }
383 
384  case TStreamerInfo::kCounter + kHaveLoop : {
385  DOLOOP {
386  Int_t *x=(Int_t*)(arr[k]+ioffset);
387  b << x[0];
388  }
389  continue;
390  }
391 
392 
393  };
394  Bool_t isPreAlloc = 0;
395 
396  switch (compinfo[i]->fType) {
397 
398  // char*
400  Int_t nch = 0;
401  char **f = (char**)(arr[k]+ioffset);
402  char *af = *f;
403  if (af) {
404  nch = strlen(af);
405  b << nch;
406  b.WriteFastArray(af,nch);
407  } else {
408  b << nch;
409  }
410  }
411  continue; }
412 
413  // special case for TObject::fBits in case of a referenced object
414  case TStreamerInfo::kBits: { DOLOOP {
415  UInt_t *x=(UInt_t*)(arr[k]+ioffset); b << *x;
416  if ((*x & kIsReferenced) != 0) {
417  TObject *obj = (TObject*)(arr[k]+eoffset);
420  if(table) table->Add(obj->GetUniqueID(),pid);
421  UShort_t pidf = b.WriteProcessID(pid);
422  b << pidf;
423  }
424  }
425  continue; }
426 
427  // Special case for TString, TObject, TNamed
428  case TStreamerInfo::kTString: { DOLOOP{ ((TString*)(arr[k]+ioffset))->Streamer(b); }; continue; }
429  case TStreamerInfo::kTObject: { DOLOOP{ ((TObject*)(arr[k]+ioffset))->TObject::Streamer(b);}; continue; }
430  case TStreamerInfo::kTNamed: { DOLOOP{ ((TNamed *)(arr[k]+ioffset))->TNamed::Streamer(b); }; continue; }
431 
432  case TStreamerInfo::kAnyp: // Class* Class not derived from TObject and with comment field //->
434 
435  case TStreamerInfo::kObjectp: // Class * Class derived from TObject and with comment field //->
437 
438  isPreAlloc = kTRUE;
439 
440  // Intentional fallthrough now that isPreAlloc is set.
441  case TStreamerInfo::kAnyP: // Class* Class not derived from TObject and no comment
443 
444  case TStreamerInfo::kObjectP: // Class* Class derived from TObject
446  TClass *cl = compinfo[i]->fClass;
447  TMemberStreamer *pstreamer = compinfo[i]->fStreamer;
448  DOLOOP {
449  Int_t res = b.WriteFastArray((void**)(arr[k]+ioffset),cl,compinfo[i]->fLength,isPreAlloc,pstreamer);
450  if (res==2) {
451  Warning("WriteBuffer",
452  "The actual class of %s::%s is not available. Only the \"%s\" part will be written\n",
453  GetName(),aElement->GetName(),cl->GetName());
454  }
455  }
456  continue;
457  }
458 
459  case TStreamerInfo::kAnyPnoVT: // Class* Class not derived from TObject and no virtual table and no comment
461  TClass *cl = compinfo[i]->fClass;
462  TMemberStreamer *pstreamer = compinfo[i]->fStreamer;
463  DOLOOP {
464  void **f = (void**)(arr[k]+ioffset);
465  int j;
466  for(j=0;j<compinfo[i]->fLength;j++) {
467  void *af = f[j];
468  if (af) b << Char_t(1);
469  else {b << Char_t(0); continue;}
470  if (pstreamer) (*pstreamer)(b, af, 0);
471  else cl->Streamer( af, b );
472  }
473  }
474  continue;
475  }
476 
477 // case TStreamerInfo::kSTLvarp: // Variable size array of STL containers.
478 // {
479 // TMemberStreamer *pstreamer = compinfo[i]->fStreamer;
480 // TClass *cl = compinfo[i]->fClass;
481 // UInt_t pos = b.WriteVersion(this->IsA(),kTRUE);
482 // if (pstreamer == 0) {
483 // Int_t size = cl->Size();
484 // Int_t imethod = compinfo[i]->fMethod+eoffset;
485 // DOLOOP {
486 // char **contp = (char**)(arr[k]+ioffset);
487 // const Int_t *counter = (Int_t*)(arr[k]+imethod);
488 // const Int_t sublen = (*counter);
489 
490 // for(int j=0;j<compinfo[i]->fLength;++j) {
491 // char *cont = contp[j];
492 // for(int k=0;k<sublen;++k) {
493 // cl->Streamer( cont, b );
494 // cont += size;
495 // }
496 // }
497 // }
498 // } else {
499 // DOLOOP{(*pstreamer)(b,arr[k]+ioffset,compinfo[i]->fLength);}
500 // }
501 // b.SetByteCount(pos,kTRUE);
502 // }
503 // continue;
504 
505 
506  case TStreamerInfo::kSTLp: // Pointer to container with no virtual table (stl) and no comment
507  case TStreamerInfo::kSTLp + TStreamerInfo::kOffsetL: // array of pointers to container with no virtual table (stl) and no comment
508  {
509  TClass *cl = compinfo[i]->fClass;
510  TMemberStreamer *pstreamer = compinfo[i]->fStreamer;
512  TClass* vClass = proxy ? proxy->GetValueClass() : 0;
513 
515  && proxy && vClass
517  && cl->CanSplit()
518  && !(strspn(aElement->GetTitle(),"||") == 2)
519  && !(vClass->TestBit(TClass::kHasCustomStreamerMember)) ) {
520  // Let's save the collection member-wise.
521 
522  UInt_t pos = b.WriteVersionMemberWise(this->IsA(),kTRUE);
523  b.WriteVersion( vClass, kFALSE );
524  TStreamerInfo *subinfo = (TStreamerInfo*)vClass->GetStreamerInfo();
525  DOLOOP {
526  char **contp = (char**)(arr[k]+ioffset);
527  for(int j=0;j<compinfo[i]->fLength;++j) {
528  char *cont = contp[j];
529  TVirtualCollectionProxy::TPushPop helper( proxy, cont );
530  Int_t nobjects = cont ? proxy->Size() : 0;
531  b << nobjects;
532  subinfo->WriteBufferSTL(b,proxy,nobjects);
533  }
534  }
535  b.SetByteCount(pos,kTRUE);
536  continue;
537  }
538  UInt_t pos = b.WriteVersion(this->IsA(),kTRUE);
539  if (pstreamer == 0) {
540  DOLOOP {
541  char **contp = (char**)(arr[k]+ioffset);
542  for(int j=0;j<compinfo[i]->fLength;++j) {
543  char *cont = contp[j];
544  cl->Streamer( cont, b );
545  }
546  }
547  } else {
548  DOLOOP{(*pstreamer)(b,arr[k]+ioffset,compinfo[i]->fLength);}
549  }
550  b.SetByteCount(pos,kTRUE);
551  }
552  continue;
553 
554  case TStreamerInfo::kSTL: // container with no virtual table (stl) and no comment
555  case TStreamerInfo::kSTL + TStreamerInfo::kOffsetL: // array of containers with no virtual table (stl) and no comment
556  {
557  TClass *cl = compinfo[i]->fClass;
558  TMemberStreamer *pstreamer = compinfo[i]->fStreamer;
560  TClass* vClass = proxy ? proxy->GetValueClass() : 0;
562  && proxy && vClass
563  && GetStreamMemberWise() && cl->CanSplit()
564  && !(strspn(aElement->GetTitle(),"||") == 2)
565  && !(vClass->TestBit(TClass::kHasCustomStreamerMember)) ) {
566  // Let's save the collection in member-wise order.
567 
568  UInt_t pos = b.WriteVersionMemberWise(this->IsA(),kTRUE);
569  b.WriteVersion( vClass, kFALSE );
570  TStreamerInfo *subinfo = (TStreamerInfo*)vClass->GetStreamerInfo();
571  DOLOOP {
572  char *obj = (char*)(arr[k]+ioffset);
573  Int_t n = compinfo[i]->fLength;
574  if (!n) n=1;
575  int size = cl->Size();
576 
577  for(Int_t j=0; j<n; j++,obj+=size) {
578  TVirtualCollectionProxy::TPushPop helper( proxy, obj );
579  Int_t nobjects = proxy->Size();
580  b << nobjects;
581  subinfo->WriteBufferSTL(b,proxy,nobjects);
582  }
583  }
584  b.SetByteCount(pos,kTRUE);
585  continue;
586  }
587  UInt_t pos = b.WriteVersion(this->IsA(),kTRUE);
588  if (pstreamer == 0) {
589  DOLOOP {
590  b.WriteFastArray((void*)(arr[k]+ioffset),cl,compinfo[i]->fLength,0);
591  }
592  } else {
593  DOLOOP{(*pstreamer)(b,arr[k]+ioffset,compinfo[i]->fLength);}
594  }
595  b.SetByteCount(pos,kTRUE);
596 
597  continue;
598  }
599 
600  case TStreamerInfo::kObject: // Class derived from TObject
601  case TStreamerInfo::kAny: // Class NOT derived from TObject
604  TClass *cl = compinfo[i]->fClass;
605  TMemberStreamer *pstreamer = compinfo[i]->fStreamer;
606  DOLOOP
607  {b.WriteFastArray((void*)(arr[k]+ioffset),cl,compinfo[i]->fLength,pstreamer);}
608  continue;
609  }
610 
614  {
615  TMemberStreamer *pstreamer = compinfo[i]->fStreamer;
616  TClass *cl = compinfo[i]->fClass;
617 
618  UInt_t pos = b.WriteVersion(this->IsA(),kTRUE);
619  DOLOOP {b.WriteFastArray((void*)(arr[k]+ioffset),cl,compinfo[i]->fLength,pstreamer);}
620  b.SetByteCount(pos,kTRUE);
621  continue;
622  }
623 
624  // Base Class
626  if (!(arrayMode&1)) {
627  TMemberStreamer *pstreamer = compinfo[i]->fStreamer;
628  if(pstreamer) {
629  // See kStreamer case (similar code)
630  UInt_t pos = b.WriteVersion(this->IsA(),kTRUE);
631  DOLOOP{(*pstreamer)(b,arr[k]+ioffset,compinfo[i]->fLength);}
632  b.SetByteCount(pos,kTRUE);
633  } else {
634  DOLOOP { ((TStreamerBase*)aElement)->WriteBuffer(b,arr[k]);}
635  }
636  } else {
637  TClass *cl = compinfo[i]->fClass;
638  TStreamerInfo *binfo = ((TStreamerInfo*)cl->GetStreamerInfo());
639  binfo->WriteBufferAux(b,arr,binfo->fCompFull,0,binfo->fNfulldata,narr,ioffset,arrayMode);
640  }
641  continue;
642 
644  {
645  TMemberStreamer *pstreamer = compinfo[i]->fStreamer;
646 
647  UInt_t pos = b.WriteVersion(this->IsA(),kTRUE);
648  if (pstreamer == 0) {
649  printf("ERROR, Streamer is null\n");
650  aElement->ls();continue;
651  } else {
652  DOLOOP{(*pstreamer)(b,arr[k]+ioffset,compinfo[i]->fLength);}
653  }
654  b.SetByteCount(pos,kTRUE);
655  }
656  continue;
657 
659  // -- A pointer to a varying-length array of objects.
660  // MyClass* ary; //[n]
661  // -- Or a pointer to a varying-length array of pointers to objects.
662  // MyClass** ary; //[n]
664  // -- An array of pointers to a varying-length array of objects.
665  // MyClass* ary[d]; //[n]
666  // -- Or an array of pointers to a varying-length array of pointers to objects.
667  // MyClass** ary[d]; //[n]
668  {
669  // Get the class of the data member.
670  TClass* cl = compinfo[i]->fClass;
671  // Get any private streamer which was set for the data member.
672  TMemberStreamer* pstreamer = compinfo[i]->fStreamer;
673  // Which are we, an array of objects or an array of pointers to objects?
674  Bool_t isPtrPtr = (strstr(aElement->GetTypeName(), "**") != 0);
675  if (pstreamer) {
676  // -- We have a private streamer.
677  UInt_t pos = b.WriteVersion(this->IsA(), kTRUE);
678  // Loop over the entries in the clones array or the STL container.
679  for (int k = 0; k < narr; ++k) {
680  // Get a pointer to the counter for the varying length array.
681  Int_t* counter = (Int_t*) (arr[k] /*entry pointer*/ + eoffset /*entry offset*/ + compinfo[i]->fMethod /*counter offset*/);
682  // And call the private streamer, passing it the buffer, the object, and the counter.
683  (*pstreamer)(b, arr[k] /*entry pointer*/ + ioffset /*object offset*/, *counter);
684  }
685  b.SetByteCount(pos, kTRUE);
686  // We are done, next streamer element.
687  continue;
688  }
689  // At this point we do *not* have a private streamer.
690  // Get the version of the file we are writing to.
691  TFile* file = (TFile*) b.GetParent();
692  // By default assume the file version is the newest.
693  Int_t fileVersion = kMaxInt;
694  if (file) {
695  fileVersion = file->GetVersion();
696  }
697  // Write the class version to the buffer.
698  UInt_t pos = b.WriteVersion(this->IsA(), kTRUE);
699  if (fileVersion > 51508) {
700  // -- Newer versions allow polymorphic pointers to objects.
701  // Loop over the entries in the clones array or the STL container.
702  for (int k = 0; k < narr; ++k) {
703  // Get the counter for the varying length array.
704  Int_t vlen = *((Int_t*) (arr[k] /*entry pointer*/ + eoffset /*entry offset*/ + compinfo[i]->fMethod /*counter offset*/));
705  //b << vlen;
706  if (vlen) {
707  // Get a pointer to the array of pointers.
708  char** pp = (char**) (arr[k] /*entry pointer*/ + ioffset /*object offset*/);
709  // Loop over each element of the array of pointers to varying-length arrays.
710  for (Int_t ndx = 0; ndx < compinfo[i]->fLength; ++ndx) {
711  if (!pp[ndx]) {
712  // -- We do not have a pointer to a varying-length array.
713  Error("WriteBufferAux", "The pointer to element %s::%s type %d (%s) is null\n", GetName(), aElement->GetFullName(), compinfo[i]->fType, aElement->GetTypeName());
714  continue;
715  }
716  if (!isPtrPtr) {
717  // -- We are a varying-length array of objects.
718  // Write the entire array of objects to the buffer.
719  // Note: Polymorphism is not allowed here.
720  b.WriteFastArray(pp[ndx], cl, vlen, 0);
721  }
722  else {
723  // -- We are a varying-length array of pointers to objects.
724  // Write the entire array of object pointers to the buffer.
725  // Note: The object pointers are allowed to be polymorphic.
726  b.WriteFastArray((void**) pp[ndx], cl, vlen, kFALSE, 0);
727  } // isPtrPtr
728  } // ndx
729  } // vlen
730  } // k
731  }
732  else {
733  // -- Older versions do *not* allow polymorphic pointers to objects.
734  // Loop over the entries in the clones array or the STL container.
735  for (int k = 0; k < narr; ++k) {
736  // Get the counter for the varying length array.
737  Int_t vlen = *((Int_t*) (arr[k] /*entry pointer*/ + eoffset /*entry offset*/ + compinfo[i]->fMethod /*counter offset*/));
738  //b << vlen;
739  if (vlen) {
740  // Get a pointer to the array of pointers.
741  char** pp = (char**) (arr[k] /*entry pointer*/ + ioffset /*object offset*/);
742  // -- Older versions do *not* allow polymorphic pointers to objects.
743  // Loop over each element of the array of pointers to varying-length arrays.
744  for (Int_t ndx = 0; ndx < compinfo[i]->fLength; ++ndx) {
745  if (!pp[ndx]) {
746  // -- We do not have a pointer to a varying-length array.
747  Error("WriteBufferAux", "The pointer to element %s::%s type %d (%s) is null\n", GetName(), aElement->GetFullName(), compinfo[i]->fType, aElement->GetTypeName());
748  continue;
749  }
750  if (!isPtrPtr) {
751  // -- We are a varying-length array of objects.
752  // Loop over the elements of the varying length array.
753  for (Int_t v = 0; v < vlen; ++v) {
754  // Write the object to the buffer.
755  cl->Streamer(pp[ndx] + (v * cl->Size()), b);
756  } // v
757  }
758  else {
759  // -- We are a varying-length array of pointers to objects.
760  // Loop over the elements of the varying length array.
761  for (Int_t v = 0; v < vlen; ++v) {
762  // Get a pointer to the object pointer.
763  char** r = (char**) pp[ndx];
764  // Write the object to the buffer.
765  cl->Streamer(r[v], b);
766  } // v
767  } // isPtrPtr
768  } // ndx
769  } // vlen
770  } // k
771  } // fileVersion
772  // Backpatch the byte count into the buffer.
773  b.SetByteCount(pos, kTRUE);
774  continue;
775  }
776 
778  ((TBufferFile&)b).PushDataCache( new TVirtualArray( aElement->GetClassPointer(), narr ) );
779  continue;
781  delete ((TBufferFile&)b).PopDataCache();
782  continue;
784 #if 0
785  ROOT::TSchemaRule::WriteFuncPtr_t writefunc = ((TStreamerArtificial*)aElement)->GetWriteFunc();
786  if (writefunc) {
787  DOLOOP( writefunc(arr[k]+eoffset, b) );
788  }
789 #endif
790  continue;
791  case -1:
792  // -- Skip an ignored TObject base class.
793  continue;
794  default:
795  Error("WriteBuffer","The element %s::%s type %d (%s) is not supported yet\n",GetName(),aElement->GetFullName(),compinfo[i]->fType,aElement->GetTypeName());
796  continue;
797  }
798  }
799 
800  if (needIncrement) b.DecrementLevel(this);
801 
802  return 0;
803 }
804 
805 template Int_t TStreamerInfo::WriteBufferAux<char**>(TBuffer &b, char ** const &arr, TCompInfo *const*const compinfo, Int_t first, Int_t last, Int_t narr,Int_t eoffset,Int_t mode);
806 
807 ////////////////////////////////////////////////////////////////////////////////
808 /// Write for STL container. ('first' is an id between -1 and fNfulldata).
809 
811 {
812  if (!nc) return 0;
813  R__ASSERT((unsigned int)nc==cont->Size());
814 
815 
816  int ret = WriteBufferAux(b,*cont,fCompFull,0,fNfulldata,nc,/* eoffset = */ 0,1);
817  return ret;
818 }
819 
820 ////////////////////////////////////////////////////////////////////////////////
821 /// Write for STL container. ('first' is an id between -1 and fNfulldata).
822 /// Note: This is no longer used.
823 
825 {
826  if (!nc) return 0;
827  R__ASSERT((unsigned int)nc==cont->Size());
828  int ret = WriteBufferAux(b, TPointerCollectionAdapter(cont),fCompFull,first==-1?0:first,first==-1?fNfulldata:first+1,nc,eoffset,1);
829  return ret;
830 }
831 
832 
833 ////////////////////////////////////////////////////////////////////////////////
834 /// General Write. ('first' is an id between -1 and fNdata).
835 /// Note: This is no longer used.
836 
838 {
839  return WriteBufferAux(b,&ipointer,fCompOpt,first==-1?0:first,first==-1?fNdata:first+1,1,0,0);
840 }
841 
842 ////////////////////////////////////////////////////////////////////////////////
843 /// Write for ClonesArray ('first' is an id between -1 and fNfulldata).
844 /// Note: This is no longer used.
845 
847  Int_t nc, Int_t first, Int_t eoffset)
848 {
849  char **arr = reinterpret_cast<char**>(clones->GetObjectRef(0));
850  return WriteBufferAux(b,arr,fCompFull,first==-1?0:first,first==-1?fNfulldata:first+1,nc,eoffset,1);
851 }
852 
853 
TObject * GetParent() const
Return pointer to parent of this buffer.
Definition: TBuffer.cxx:229
Describe Streamer information for one class version.
Definition: TStreamerInfo.h:47
virtual const char * GetTitle() const
Returns title of object.
Definition: TNamed.h:52
virtual void WriteFloat16(Float_t *f, TStreamerElement *ele=0)=0
static Bool_t GetStreamMemberWise()
Return whether the TStreamerInfos will save the collections in "member-wise" order whenever possible...
virtual void WriteFastArrayFloat16(const Float_t *f, Int_t n, TStreamerElement *ele=0)=0
Bool_t CanSplit() const
Return true if the data member of this TClass can be saved separately.
Definition: TClass.cxx:2152
The concrete implementation of TBuffer for writing/reading to/from a ROOT file or socket...
Definition: TBufferFile.h:51
long long Long64_t
Definition: RtypesCore.h:69
const char * GetTypeName() const
float Float_t
Definition: RtypesCore.h:53
Equal to TDataType's kchar.
virtual TClass * GetValueClass() const =0
virtual void WriteDouble32(Double_t *d, TStreamerElement *ele=0)=0
unsigned short UShort_t
Definition: RtypesCore.h:36
#define WriteBasicArray(name)
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format...
Definition: TFile.h:45
Buffer base class used for serializing objects.
Definition: TBuffer.h:42
#define R__ASSERT(e)
Definition: TError.h:98
virtual UInt_t WriteVersionMemberWise(const TClass *cl, Bool_t useBcnt=kFALSE)=0
Basic string class.
Definition: TString.h:137
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kFALSE
Definition: Rtypes.h:92
Cache the value in memory than is not part of the object but is accessible via a SchemaRule.
Int_t fNdata
!number of optimized elements
virtual UInt_t WriteVersion(const TClass *cl, Bool_t useBcnt=kFALSE)=0
#define WriteBasicPointerLoop(name)
TFile * f
TCompInfo ** fCompFull
![fElements->GetEntries()]
TTree * T
Int_t WriteBufferSTLPtrs(TBuffer &b, TVirtualCollectionProxy *cont, Int_t nc, Int_t first, Int_t eoffset)
Write for STL container.
Double_t x[n]
Definition: legend1.C:17
#define WriteBasicTypeLoop(name)
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:33
virtual void SetStreamerElementNumber(TStreamerElement *elem, Int_t comp_type)=0
Int_t WriteBufferAux(TBuffer &b, const T &arr, TCompInfo *const *const compinfo, Int_t first, Int_t last, Int_t narr, Int_t eoffset, Int_t mode)
The object at pointer is serialized to the buffer b if (arrayMode & 1) ptr is a pointer to array of p...
Int_t WriteBufferClones(TBuffer &b, TClonesArray *clones, Int_t nc, Int_t first, Int_t eoffset)
Write for ClonesArray ('first' is an id between -1 and fNfulldata).
TMemberStreamer * fStreamer
Not Owned.
Definition: TStreamerInfo.h:64
Int_t fNfulldata
!number of elements
A TProcessID identifies a ROOT job in a unique way in time and space.
Definition: TProcessID.h:34
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:918
virtual UShort_t WriteProcessID(TProcessID *pid)=0
Always return 0 (current processID).
Definition: TBuffer.cxx:320
TClass * fClass
!pointer to class
virtual void ls(Option_t *option="") const
Print the content of the element.
static TProcessID * GetProcessWithUID(const TObject *obj)
static function returning a pointer to TProcessID with its pid encoded in the highest byte of obj->Ge...
Definition: TProcessID.cxx:252
ROOT::R::TRInterface & r
Definition: Object.C:4
Wrapper around an object and giving indirect access to its content even if the object is not of a cla...
Definition: TVirtualArray.h:26
TVirtualStreamerInfo * GetStreamerInfo(Int_t version=0) const
returns a pointer to the TVirtualStreamerInfo object for version If the object does not exist...
Definition: TClass.cxx:4256
SVector< double, 2 > v
Definition: Dict.h:5
virtual const char * ClassName() const
Returns name of class to which the object belongs.
Definition: TObject.cxx:187
TClass * IsA() const
#define WriteBasicArrayLoop(name)
unsigned int UInt_t
Definition: RtypesCore.h:42
Bool_t TestBit(UInt_t f) const
Definition: TObject.h:173
#define WriteBasicPointer(name)
bool first
Definition: line3Dfit.C:48
short Short_t
Definition: RtypesCore.h:35
TLine * l
Definition: textangle.C:4
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:51
The ROOT global object gROOT contains a list of all defined classes.
Definition: TClass.h:81
virtual void SetByteCount(UInt_t cntpos, Bool_t packInVersion=kFALSE)=0
TClass * fClass
Not Owned.
Definition: TStreamerInfo.h:61
virtual void WriteFastArray(const Bool_t *b, Int_t n)=0
PyObject * fType
long Long_t
Definition: RtypesCore.h:50
#define WriteBasicType(name)
Int_t WriteBuffer(TBuffer &b, char *pointer, Int_t first)
General Write.
virtual void DecrementLevel(TVirtualStreamerInfo *)=0
Int_t WriteBufferSTL(TBuffer &b, TVirtualCollectionProxy *cont, Int_t nc)
Write for STL container. ('first' is an id between -1 and fNfulldata).
tuple file
Definition: fildir.py:20
double Double_t
Definition: RtypesCore.h:55
virtual TClass * GetClassPointer() const
Returns a pointer to the TClass of this element.
static TRefTable * GetRefTable()
Static function returning the current TRefTable.
Definition: TRefTable.cxx:287
unsigned long long ULong64_t
Definition: RtypesCore.h:70
ClassImp(TMCParticle) void TMCParticle printf(": p=(%7.3f,%7.3f,%9.3f) ;", fPx, fPy, fPz)
unsigned long ULong_t
Definition: RtypesCore.h:51
A TRefTable maintains the association between a referenced object and the parent object supporting th...
Definition: TRefTable.h:37
virtual UInt_t GetUniqueID() const
Return the unique object id.
Definition: TObject.cxx:433
TVirtualCollectionProxy * GetCollectionProxy() const
Return the proxy describing the collection (if any).
Definition: TClass.cxx:2730
#define DOLOOP
Mother of all ROOT objects.
Definition: TObject.h:58
const Int_t kMaxInt
Definition: Rtypes.h:103
virtual UInt_t Size() const =0
char Char_t
Definition: RtypesCore.h:29
An array of clone (identical) objects.
Definition: TClonesArray.h:32
virtual void TagStreamerInfo(TVirtualStreamerInfo *info)=0
Int_t Length() const
Definition: TBuffer.h:96
Int_t GetVersion() const
Definition: TFile.h:205
R__EXTERN Int_t gDebug
Definition: Rtypes.h:128
TCompInfo ** fCompOpt
![fNdata]
TObject ** GetObjectRef() const
Definition: TObjArray.h:70
unsigned char UChar_t
Definition: RtypesCore.h:34
virtual void IncrementLevel(TVirtualStreamerInfo *info)=0
virtual const char * GetFullName() const
Return element name including dimensions, if any Note that this function stores the name into a stati...
void Streamer(void *obj, TBuffer &b, const TClass *onfile_class=0) const
Definition: TClass.h:539
const Bool_t kTRUE
Definition: Rtypes.h:91
TObject * obj
const Int_t n
Definition: legend1.C:16
Int_t Size() const
Return size of object of this class.
Definition: TClass.cxx:5243
virtual void WriteFastArrayDouble32(const Double_t *d, Int_t n, TStreamerElement *ele=0)=0
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition: TObject.cxx:904