Logo ROOT   6.08/02
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
TStreamerInfo.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 /**
13 \class TStreamerInfo TStreamerInfo.cxx
14 \ingroup IO
15 
16 Describes a persistent version of a class.
17 
18 A ROOT file contains the list of TStreamerInfo objects for all the
19 class versions written to this file.
20 When reading a file, all the TStreamerInfo objects are read back in
21 memory and registered to the TClass list of TStreamerInfo.
22 One can see the list and contents of the TStreamerInfo on a file
23 with, e.g.,
24 ~~~{.cpp}
25  TFile f("myfile.root");
26  f.ShowStreamerInfo();
27 ~~~
28 A TStreamerInfo is a list of TStreamerElement objects (one per data
29 member or base class).
30 When streaming an object, the system (TClass) loops on all the
31 TStreamerElement objects and calls the appropriate function for each
32 element type.
33 */
34 
35 #include "TStreamerInfo.h"
36 #include "TFile.h"
37 #include "TROOT.h"
38 #include "TClonesArray.h"
39 #include "TStreamerElement.h"
40 #include "TClass.h"
41 #include "TClassEdit.h"
42 #include "TDataMember.h"
43 #include "TMethodCall.h"
44 #include "TDataType.h"
45 #include "TRealData.h"
46 #include "TBaseClass.h"
47 #include "TBuffer.h"
48 #include "TArrayC.h"
49 #include "TArrayI.h"
50 #include "TArrayF.h"
51 #include "TArrayD.h"
52 #include "TArrayS.h"
53 #include "TArrayL.h"
54 #include "TError.h"
55 #include "TRef.h"
56 #include "TProcessID.h"
57 #include "TSystem.h"
58 
59 #include "TStreamer.h"
60 #include "TContainerConverters.h"
63 #include "TInterpreter.h"
64 
65 #include "TMemberInspector.h"
66 
67 #include "TMakeProject.h"
68 
69 #include "TSchemaRuleSet.h"
70 #include "TSchemaRule.h"
71 
72 #include "TVirtualMutex.h"
73 
74 #include "TStreamerInfoActions.h"
75 
76 #include <memory>
77 #include <array>
78 
79 std::atomic<Int_t> TStreamerInfo::fgCount{0};
80 
81 const Int_t kMaxLen = 1024;
82 
84 
85 static void R__TObjArray_InsertAt(TObjArray *arr, TObject *obj, Int_t at)
86 {
87  // Slide by one.
88  Int_t last = arr->GetLast();
89  arr->AddAtAndExpand(arr->At(last),last+1);
90  for(Int_t ind = last-1; ind >= at; --ind) {
91  arr->AddAt( arr->At(ind), ind+1);
92  };
93  arr->AddAt( obj, at);
94 }
95 
96 static void R__TObjArray_InsertAt(TObjArray *arr, std::vector<TStreamerArtificial*> &objs, Int_t at)
97 {
98  // Slide by enough.
99  Int_t offset = objs.size();
100  Int_t last = arr->GetLast();
101  arr->AddAtAndExpand(arr->At(last),last+offset);
102  for(Int_t ind = last-1; ind >= at; --ind) {
103  arr->AddAt( arr->At(ind), ind+offset);
104  };
105  for(size_t ins = 0; ins < objs.size(); ++ins) {
106  arr->AddAt(objs[ins], at+ins);
107  }
108 }
109 
110 static void R__TObjArray_InsertAfter(TObjArray *arr, TObject *newobj, TObject *oldobj)
111 {
112  // Slide by one.
113  Int_t last = arr->GetLast();
114  Int_t at = 0;
115  while (at<last && arr->At(at) != oldobj) {
116  ++at;
117  }
118  ++at; // we found the object, insert after it
119  R__TObjArray_InsertAt(arr, newobj, at);
120 }
121 
122 static void R__TObjArray_InsertBefore(TObjArray *arr, TObject *newobj, TObject *oldobj)
123 {
124  // Slide by one.
125  Int_t last = arr->GetLast();
126  Int_t at = 0;
127  while (at<last && arr->At(at) != oldobj) {
128  ++at;
129  }
130  R__TObjArray_InsertAt(arr, newobj, at);
131 }
132 
133 enum class EUniquePtrOffset : char
134  {
135  kNA = 0,
136  kZero = 1,
137  kNonZero = 2
138  };
139 
140 ////////////////////////////////////////////////////////////////////////////////
141 /// Default ctor.
142 
144 {
145  fNumber = fgCount;
146  fClass = 0;
147  fElements = 0;
148  fComp = 0;
149  fCompFull = 0;
150  fCompOpt = 0;
151  fCheckSum = 0;
152  fNdata = 0;
153  fNfulldata= 0;
154  fNslots = 0;
155  fSize = 0;
156  fClassVersion = 0;
158  fOldVersion = Class()->GetClassVersion();
159  fNVirtualInfoLoc = 0;
160  fVirtualInfoLoc = 0;
161  fLiveCount = 0;
162 
163  fReadObjectWise = 0;
164  fReadMemberWise = 0;
166  fWriteObjectWise = 0;
167  fWriteMemberWise = 0;
169 }
170 
171 ////////////////////////////////////////////////////////////////////////////////
172 /// Create a TStreamerInfo object.
173 
176 {
177  fgCount++;
178  fNumber = fgCount;
179  fClass = cl;
180  fElements = new TObjArray();
181  fComp = 0;
182  fCompFull = 0;
183  fCompOpt = 0;
184  fCheckSum = 0;
185  fNdata = 0;
186  fNfulldata= 0;
187  fNslots = 0;
188  fSize = 0;
191  fOldVersion = Class()->GetClassVersion();
192  fNVirtualInfoLoc = 0;
193  fVirtualInfoLoc = 0;
194  fLiveCount = 0;
195 
196  fReadObjectWise = 0;
197  fReadMemberWise = 0;
199  fWriteObjectWise = 0;
200  fWriteMemberWise = 0;
202 }
203 
204 ////////////////////////////////////////////////////////////////////////////////
205 /// TStreamerInfo dtor.
206 
208 {
209  delete [] fComp; fComp = 0;
210  delete [] fCompFull; fCompFull = 0;
211  delete [] fCompOpt; fCompOpt = 0;
212  delete [] fVirtualInfoLoc; fVirtualInfoLoc =0;
213 
214  delete fReadObjectWise;
215  delete fReadMemberWise;
216  delete fReadMemberWiseVecPtr;
217  delete fWriteObjectWise;
218  delete fWriteMemberWise;
219  delete fWriteMemberWiseVecPtr;
220 
221  if (!fElements) return;
222  fElements->Delete();
223  delete fElements; fElements=0;
224 }
225 
226 ////////////////////////////////////////////////////////////////////////////////
227 /// Makes sure kBuildOldUsed set once Build or BuildOld finishes.
228 /// Makes sure kBuildRunning reset once Build finishes.
229 
230 namespace {
231  struct TPreventRecursiveBuildGuard {
232  TPreventRecursiveBuildGuard(TStreamerInfo* info): fInfo(info) {
233  fInfo->SetBit(TStreamerInfo::kBuildRunning);
234  fInfo->SetBit(TStreamerInfo::kBuildOldUsed);
235  }
236  ~TPreventRecursiveBuildGuard() {
237  fInfo->ResetBit(TStreamerInfo::kBuildOldUsed);
238  fInfo->ResetBit(TStreamerInfo::kBuildRunning);
239  }
240  TStreamerInfo* fInfo;
241  };
242 
243 }
244 
245 ////////////////////////////////////////////////////////////////////////////////
246 /// Build the I/O data structure for the current class version.
247 ///
248 /// A list of TStreamerElement derived classes is built by scanning
249 /// one by one the list of data members of the analyzed class.
251 {
252  // Did another thread already do the work?
253  if (fIsCompiled) return;
254 
256 
257  // Did another thread already do the work while we were waiting ..
258  if (fIsCompiled) return;
259 
260  // Has Build already been run?
261  if (fIsBuilt) return;
262 
263  // Are we recursing on ourself?
265 
266  // This is used to avoid unwanted recursive call to Build or BuildOld.
267  TPreventRecursiveBuildGuard buildGuard(this);
268 
269  if (fClass->GetCollectionProxy()) {
271  TString title;
272  if (proxy->GetValueClass()) {
273  title.Form("<%s%s> Used to call the proper TStreamerInfo case",proxy->GetValueClass()->GetName(),proxy->HasPointers() ? "*" : "");
274  } else {
275  title .Form("<%s%s> Used to call the proper TStreamerInfo case",TDataType::GetTypeName(proxy->GetType()),proxy->HasPointers() ? "*" : "");
276  }
277  TStreamerElement* element = new TStreamerSTL("This", title.Data(), 0, fClass->GetName(), *proxy, 0);
278  fElements->Add(element);
279  Compile();
281  fIsBuilt = kTRUE;
282  return;
283  }
284 
285  TStreamerElement::Class()->IgnoreTObjectStreamer();
286 
288 
290 
291  Bool_t needAllocClass = kFALSE;
292  Bool_t wasCompiled = fComp != 0;
293  ROOT::TSchemaRuleSet::TMatches rules;
294  if (fClass->GetSchemaRules()) {
296  }
297 
298  //
299  // Iterate over base classes.
300  //
301 
302  bool isCollection = fClass->GetCollectionProxy();
303  bool isString = !strcmp(fClass->GetName(), "string");
304 
305  TBaseClass* base = 0;
306  TIter nextb(fClass->GetListOfBases());
307  while ((base = (TBaseClass*)nextb())) {
308  TStreamerElement* element = 0;
309  Int_t offset = base->GetDelta();
310  if (offset == kMissing) {
311  continue;
312  }
313  if (offset == kNeedObjectForVirtualBaseClass) {
314  Error("Build()", "Cannot stream virtual base %s of class %s",
315  base->GetName(), fClass->GetName());
316  continue;
317  }
318  const char* bname = base->GetName();
319  const char* btitle = base->GetTitle();
320  // this case appears with STL collections as base class.
321  if (!strcmp(bname, "string")) {
322  element = new TStreamerSTLstring(bname, btitle, offset, bname, kFALSE);
323  } else if (base->IsSTLContainer()) {
324  TVirtualCollectionProxy *proxy = base->GetClassPointer()->GetCollectionProxy();
325  if (proxy) element = new TStreamerSTL(bname, btitle, offset, bname, *proxy, kFALSE);
326  else element = new TStreamerSTL(bname, btitle, offset, bname, 0, kFALSE);
327  if (fClass->IsLoaded() && ((TStreamerSTL*)element)->GetSTLtype() != ROOT::kSTLvector) {
328  if (!element->GetClassPointer()->IsLoaded()) {
329  Error("Build","The class \"%s\" is compiled and its base class \"%s\" is a collection and we do not have a dictionary for it, we will not be able to read or write this base class.",GetName(),bname);
330  delete element;
331  continue;
332  }
333  }
334  } else {
335  element = new TStreamerBase(bname, btitle, offset);
336  TClass* clm = element->GetClassPointer();
337  if (!clm) {
338  // We have no information about the class yet, except that since it
339  // is a base class, we know it is a class. So let's create it (in v5
340  // it would have been created as a side effect of the dictionary of
341  // for the derived class having a forward declaration of the base class).
342  clm = new TClass(bname,1,TClass::kForwardDeclared, true /*silent*/);
343  Warning("Build", "%s: base class %s has no streamer or dictionary it will not be saved", GetName(), clm->GetName());
344  element->Init(0);
345  } else {
346  // Now part of the TStreamerBase constructor.
347  // clm->GetStreamerInfo();
348  if ((clm == TObject::Class()) && fClass->CanIgnoreTObjectStreamer()) {
349  // -- An ignored TObject base class.
350  // Note: The TClass kIgnoreTObjectStreamer == BIT(15), but
351  // the TStreamerInfo kIgnoreTobjectStreamer == BIT(13) which
352  // is confusing.
354  // Flag the element to be ignored by setting its type to -1.
355  // This flag will be used later by Compile() to prevent this
356  // element from being inserted into the compiled info.
357  element->SetType(-1);
358  }
359  if (!clm->IsLoaded() && !(isCollection || isString)) {
360  // Don't complain about the base classes of collections nor of
361  // std::string.
362  Warning("Build", "%s: base class %s has no streamer or dictionary it will not be saved", GetName(), clm->GetName());
363  }
364  }
365  }
366  if (element) {
367  fElements->Add(element);
368  }
369  } // end of base class loop
370 
371  //
372  // Iterate over data members.
373  //
374 
375  Int_t dsize;
376  TDataMember* dm = 0;
377  std::string typeNameBuf;
378  std::string trueTypeNameBuf;
380  while ((dm = (TDataMember*) nextd())) {
381  if (fClass->GetClassVersion() == 0) {
382  continue;
383  }
384  if (!dm->IsPersistent()) {
385  continue;
386  }
387  TMemberStreamer* streamer = 0;
388  Int_t offset = GetDataMemberOffset(dm, streamer);
389  if (offset == kMissing) {
390  continue;
391  }
392  TStreamerElement* element = 0;
393  dsize = 0;
394 
395  // Save some useful variables
396  const char* dmName = dm->GetName();
397  const char* dmTitle = dm->GetTitle();
398  const char* dmType = dm->GetTypeName();
399  const char* dmFull = dm->GetTrueTypeName(); // Used to be GetFullTypeName ...
400  Bool_t dmIsPtr = dm->IsaPointer();
401  TDataType* dt(nullptr);
402  Int_t ndim = dm->GetArrayDim();
403  std::array<Int_t, 5> maxIndices; // 5 is the maximum supported in TStreamerElement::SetMaxIndex
404  Bool_t isStdArray(kFALSE);
405 
406  // Let's treat the unique_ptr case
407  bool nameChanged;
408  trueTypeNameBuf = typeNameBuf = TClassEdit::GetNameForIO(dmFull, TClassEdit::EModType::kNone, &nameChanged);
409  if (nameChanged) {
410  if (TClassEdit::IsUniquePtr(dmFull)) {
411  dmIsPtr = true;
412  }
413  while(typeNameBuf.back() == '*') typeNameBuf.pop_back();
414  dmFull = trueTypeNameBuf.c_str();
415  dmType = typeNameBuf.c_str();
416  }
417  if ((isStdArray = TClassEdit::IsStdArray(dmType))){ // We tackle the std array case
419  typeNameBuf,
420  maxIndices,
421  ndim);
422  trueTypeNameBuf = typeNameBuf;
423  while(typeNameBuf.back() == '*') typeNameBuf.pop_back();
424  dmFull = dmType = typeNameBuf.c_str();
425  dt = gROOT->GetType(dmType);
426  }
427 
428  TDataMember* dmCounter = 0;
429  if (dmIsPtr) {
430  //
431  // look for a pointer data member with a counter
432  // in the comment string, like so:
433  //
434  // int n;
435  // double* MyArray; //[n]
436  //
437  const char* lbracket = TVirtualStreamerInfo::GetElementCounterStart(dmTitle);
438  const char* rbracket = ::strchr(dmTitle, ']');
439  if (lbracket && rbracket) {
440  const char* counterName = dm->GetArrayIndex();
441  TRealData* rdCounter = (TRealData*) fClass->GetListOfRealData()->FindObject(counterName);
442  if (!rdCounter || rdCounter->TestBit(TRealData::kTransient)) {
443  Error("Build", "%s, discarding: %s %s, illegal %s\n", GetName(), dmFull, dmName, dmTitle);
444  continue;
445  }
446  dmCounter = rdCounter->GetDataMember();
447  TDataType* dtCounter = dmCounter->GetDataType();
448  Bool_t isInteger = dtCounter && ((dtCounter->GetType() == 3) || (dtCounter->GetType() == 13));
449  if (!dtCounter || !isInteger) {
450  Error("Build", "%s, discarding: %s %s, illegal [%s] (must be Int_t)\n", GetName(), dmFull, dmName, counterName);
451  continue;
452  }
453  TStreamerBasicType* bt = TStreamerInfo::GetElementCounter(counterName, dmCounter->GetClass());
454  if (!bt) {
455  if (dmCounter->GetClass()->Property() & kIsAbstract) {
456  continue;
457  }
458  Error("Build", "%s, discarding: %s %s, illegal [%s] must be placed before \n", GetName(), dmFull, dmName, counterName);
459  continue;
460  }
461  }
462  }
463  if (!dt && !isStdArray) dt = dm->GetDataType();
464  if (dt) {
465  // found a basic type
466  Int_t dtype = dt->GetType();
467  dsize = dt->Size();
468  if (!dmCounter && (strstr(dmFull, "char*") || strstr(dmFull, "Char_t*"))) {
469  dtype = kCharStar;
470  dsize = sizeof(char*);
471  }
472  if (dtype == kOther_t || dtype == kNoType_t) {
473  Error("Build", "%s, unknown type: %s %s", GetName(), dmFull, dmName);
474  continue;
475  } else if (dmIsPtr && (dtype != kCharStar)) {
476  if (dmCounter) {
477  // data member is pointer to an array of basic types
478  element = new TStreamerBasicPointer(dmName, dmTitle, offset, dtype, dm->GetArrayIndex(), dmCounter->GetClass()->GetName(), dmCounter->GetClass()->GetClassVersion(), dmFull);
479  } else {
480  if ((fName == "TString") || (fName == "TClass")) {
481  continue;
482  }
483  Error("Build", "%s, discarding: %s %s, no [dimension]\n", GetName(), dmFull, dmName);
484  continue;
485  }
486  } else {
487  // data member is a basic type
488  if ((fClass == TObject::Class()) && !strcmp(dmName, "fBits")) {
489  //printf("found fBits, changing dtype from %d to 15\n", dtype);
490  dtype = kBits;
491  }
492  // Here we treat data members such as int, float, double[4]
493  element = new TStreamerBasicType(dmName, dmTitle, offset, dtype, dmFull);
494  }
495  } else {
496  // try STL container or string
497  static const char* full_string_name = "basic_string<char,char_traits<char>,allocator<char> >";
498  if (!strcmp(dmType, "string") || !strcmp(dmType, "std::string") || !strcmp(dmType, full_string_name)) {
499  element = new TStreamerSTLstring(dmName, dmTitle, offset, dmFull, dmIsPtr);
500  } else if (dm->IsSTLContainer()) {
501  TVirtualCollectionProxy *proxy = TClass::GetClass(dmType /* the underlying type */)->GetCollectionProxy();
502  if (proxy) element = new TStreamerSTL(dmName, dmTitle, offset, dmFull, *proxy, dmIsPtr);
503  else element = new TStreamerSTL(dmName, dmTitle, offset, dmFull, dmFull, dmIsPtr);
504  if (((TStreamerSTL*)element)->GetSTLtype() != ROOT::kSTLvector) {
505  auto printErrorMsg = [&](const char* category)
506  {
507  Error("Build","The class \"%s\" is %s and for its data member \"%s\" we do not have a dictionary for the collection \"%s\". Because of this, we will not be able to read or write this data member.",GetName(), category, dmName, dmType);
508  };
509  if (fClass->IsLoaded()) {
510  if (!element->GetClassPointer()->IsLoaded()) {
511  printErrorMsg("compiled");
512  delete element;
513  continue;
514  }
515  } else if (fClass->GetState() == TClass::kInterpreted) {
517  printErrorMsg("interpreted");
518  delete element;
519  continue;
520  }
521  }
522  }
523  } else {
524  TClass* clm = TClass::GetClass(dmType);
525  if (!clm) {
526  Error("Build", "%s, unknown type: %s %s\n", GetName(), dmFull, dmName);
527  continue;
528  }
529  if (isStdArray) {
530  // We do not want to rebuild the streamerinfo of an std::array<T,N> asking the dm->GetUnitSize(), but rather of T only.
531 
532  dsize = clm->Size();
533  }
534  if (dmIsPtr) {
535  // a pointer to a class
536  if (dmCounter) {
537  element = new TStreamerLoop(dmName, dmTitle, offset, dm->GetArrayIndex(), dmCounter->GetClass()->GetName(), dmCounter->GetClass()->GetClassVersion(), dmFull);
538  } else {
539  if (clm->IsTObject()) {
540  element = new TStreamerObjectPointer(dmName, dmTitle, offset, dmFull);
541  } else {
542  element = new TStreamerObjectAnyPointer(dmName, dmTitle, offset, dmFull);
543  if (!streamer && !clm->GetStreamer() && !clm->IsLoaded()) {
544  Error("Build", "%s: %s has no streamer or dictionary, data member %s will not be saved", GetName(), dmFull, dmName);
545  }
546  }
547  }
548  } else if (clm->IsTObject()) {
549  element = new TStreamerObject(dmName, dmTitle, offset, dmFull);
550  } else if ((clm == TString::Class()) && !dmIsPtr) {
551  element = new TStreamerString(dmName, dmTitle, offset);
552  } else {
553  element = new TStreamerObjectAny(dmName, dmTitle, offset, dmFull);
554  if (!streamer && !clm->GetStreamer() && !clm->IsLoaded()) {
555  Warning("Build", "%s: %s has no streamer or dictionary, data member \"%s\" will not be saved", GetName(), dmFull, dmName);
556  }
557  }
558  }
559  }
560  if (!element) {
561  // If we didn't make an element, there is nothing to do.
562  continue;
563  }
564  if (!dsize) {
565  dsize = dm->GetUnitSize();
566  }
567  for (Int_t i = 0; i < ndim; ++i) {
568  auto maxIndex = 0;
569  if (isStdArray) maxIndex = maxIndices[i];
570  else maxIndex = dm->GetMaxIndex(i);
571  element->SetMaxIndex(i, maxIndex);
572  }
573  element->SetArrayDim(ndim);
574  // If the datamember was a int[4] this is 4, if double[3][2] 3*2=6
575  Int_t narr = element->GetArrayLength();
576  if (!narr) {
577  narr = 1;
578  }
579  element->SetSize(dsize*narr);
580  element->SetStreamer(streamer);
581  if (!streamer) {
582  Int_t k = element->GetType();
583  if (k == kStreamer) {
584  //if ((k == kSTL) || (k == kSTL + kOffsetL) || (k == kStreamer) || (k == kStreamLoop))
585  element->SetType(-1);
586  }
587  }
588 
589  if ( !wasCompiled && (rules && rules.HasRuleWithSource( element->GetName(), kTRUE )) ) {
590  needAllocClass = kTRUE;
591 
592  // If this is optimized to re-use TStreamerElement(s) in case of variable renaming,
593  // then we must revisit the code in TBranchElement::InitInfo that recalculate the
594  // fID (i.e. the index of the TStreamerElement to be used for streaming).
595 
596  TStreamerElement *cached = element;
597  // Now that we are caching the unconverted element, we do not assign it to the real type even if we could have!
598  if (element->GetNewType()>0 /* intentionally not including base class for now */
599  && rules && !rules.HasRuleWithTarget( element->GetName(), kTRUE ) )
600  {
601  TStreamerElement *copy = (TStreamerElement*)element->Clone();
602  fElements->Add(copy);
604  cached = copy;
605 
606  // Warning("BuildOld","%s::%s is not set from the version %d of %s (You must add a rule for it)\n",GetName(), element->GetName(), GetClassVersion(), GetName() );
607  } else {
608  // If the element is just cached and not repeat, we need to inject an element
609  // to insure the writing.
610  TStreamerElement *writecopy = (TStreamerElement*)element->Clone();
611  fElements->Add(element);
612  writecopy->SetBit(TStreamerElement::kWrite);
613  writecopy->SetNewType( writecopy->GetType() );
614  // Put the write element after the read element (that does caching).
615  element = writecopy;
616  }
618  cached->SetNewType( cached->GetType() );
619  }
620 
621  fElements->Add(element);
622  } // end of member loop
623 
624  // Now add artificial TStreamerElement (i.e. rules that creates new members or set transient members).
626 
627  if (needAllocClass) {
629  if (!infoalloc) {
630  Error("Build","Could you create a TStreamerInfo for %s\n",TString::Format("%s@@%d",GetName(),GetClassVersion()).Data());
631  } else {
632  // Tell clone we should rerun BuildOld
633  infoalloc->SetBit(kBuildOldUsed,false);
634  infoalloc->BuildCheck();
635  infoalloc->BuildOld();
636  TClass *allocClass = infoalloc->GetClass();
637 
638  {
639  TIter next(fElements);
640  TStreamerElement* element;
641  while ((element = (TStreamerElement*) next())) {
642  if (element->TestBit(TStreamerElement::kRepeat) && element->IsaPointer()) {
643  TStreamerElement *other = (TStreamerElement*) infoalloc->GetElements()->FindObject(element->GetName());
644  if (other) {
646  }
647  }
648  }
649  infoalloc->GetElements()->Compress();
650  }
651  {
652  TIter next(fElements);
653  TStreamerElement* element;
654  while ((element = (TStreamerElement*) next())) {
655  if (element->TestBit(TStreamerElement::kCache)) {
656  element->SetOffset(infoalloc->GetOffset(element->GetName()));
657  }
658  }
659  }
660 
661  TStreamerElement *el = new TStreamerArtificial("@@alloc","", 0, TStreamerInfo::kCacheNew, allocClass->GetName());
663 
664  el = new TStreamerArtificial("@@dealloc","", 0, TStreamerInfo::kCacheDelete, allocClass->GetName());
665  fElements->Add( el );
666  }
667  }
668 
669  //
670  // Make a more compact version.
671  //
672  Compile();
673  fIsBuilt = kTRUE;
674 }
675 
676 ////////////////////////////////////////////////////////////////////////////////
677 /// Check if built and consistent with the class dictionary.
678 /// This method is called by TFile::ReadStreamerInfo.
679 
680 void TStreamerInfo::BuildCheck(TFile *file /* = 0 */)
681 {
683 
685  if (!fClass) {
686  // fClassVersion should have been a Version_t and/or Version_t
687  // should have been an Int_t. Changing the on-file format
688  // of the StreamerInfo is 'hard' (for forward compatibility), so
689  // leave it as is for now.
692 
693  // Case of a custom collection (the user provided a CollectionProxy
694  // for a class that is not an STL collection).
695  if (GetElements()->GetEntries() == 1) {
696  TObject *element = GetElements()->UncheckedAt(0);
697  Bool_t isstl = element && strcmp("This",element->GetName())==0;
698  if (isstl) {
699  if (element->GetTitle()[0] == '<') {
700  // We know the content.
701  TString content = element->GetTitle();
702  Int_t level = 1;
703  for(Int_t c = 1; c < content.Length(); ++c) {
704  if (content[c] == '<') ++level;
705  else if (content[c] == '>') --level;
706  if (level == 0) {
707  content.Remove(c+1);
708  break;
709  }
710  }
711  content.Prepend("vector");
712  TClass *clequiv = TClass::GetClass(content);
713  TVirtualCollectionProxy *proxy = clequiv->GetCollectionProxy();
714  if (gDebug > 1)
715  Info("BuildCheck",
716  "Update the collection proxy of the class \"%s\" \n"
717  "\tto be similar to \"%s\".",
718  GetName(),content.Data());
719  fClass->CopyCollectionProxy( *proxy );
720  } else {
721  Warning("BuildCheck", "\n\
722  The class %s had a collection proxy when written but it is not an STL\n \
723  collection and we did not record the type of the content of the collection.\n \
724  We will claim the content is a bool (i.e. no data will be read).",
725  GetName());
726  }
727  }
728  }
729 
730  } else {
733  // We have a collection that is indeed an STL collection,
734  // we know we don't need its streamerInfo.
736  return;
737  }
738  }
739  const TObjArray *array = fClass->GetStreamerInfos();
740  TStreamerInfo* info = 0;
741 
742  if (fClass->TestBit(TClass::kIsEmulation) && array->GetEntries()==0) {
743  // We have an emulated class that has no TStreamerInfo, this
744  // means it was created to insert a (default) rule. Consequently
745  // the error message about the missing dictionary was not printed.
746  // For consistency, let's print it now!
747 
748  ::Warning("TClass::TClass", "no dictionary for class %s is available", GetName());
749  }
750 
751  // Case of a custom collection (the user provided a CollectionProxy
752  // for a class that is not an STL collection).
753  if (GetElements()->GetEntries() == 1) {
754  TObject *element = GetElements()->UncheckedAt(0);
755  Bool_t isstl = element && strcmp("This",element->GetName())==0;
756  if (isstl && !fClass->GetCollectionProxy()) {
757  if (element->GetTitle()[0] == '<') {
758  // We know the content.
759  TString content = element->GetTitle();
760  Int_t level = 1;
761  for(Int_t c = 1; c < content.Length(); ++c) {
762  if (content[c] == '<') ++level;
763  else if (content[c] == '>') --level;
764  if (level == 0) {
765  content.Remove(c+1);
766  break;
767  }
768  }
769  content.Prepend("vector");
770  TClass *clequiv = TClass::GetClass(content);
771  TVirtualCollectionProxy *proxy = clequiv->GetCollectionProxy();
772  if (gDebug > 1)
773  Info("BuildCheck",
774  "Update the collection proxy of the class \"%s\" \n"
775  "\tto be similar to \"%s\".",
776  GetName(),content.Data());
777  fClass->CopyCollectionProxy( *proxy );
778  } else {
779  Warning("BuildCheck", "\n\
780  The class %s had a collection proxy when written but it is not an STL\n \
781  collection and we did not record the type of the content of the collection.\n \
782  We will claim the content is a bool (i.e. no data will be read).",
783  GetName());
784  }
786  return;
787  }
788  }
789 
790  // If the user has not specified a class version (this _used to_
791  // always be the case when the class is Foreign) or if the user
792  // has specified a version to be explicitly 1. [We can not
793  // distinguish the two cases using the information in the "on
794  // file" StreamerInfo.]
795 
796  Bool_t searchOnChecksum = kFALSE;
797  if (fClass->IsLoaded() && fClass->GetClassVersion() >= 2) {
798  // We know for sure that the user specified the version.
799 
800  if (fOnFileClassVersion >= 2) {
801  // The class version was specified when the object was
802  // written
803 
804  searchOnChecksum = kFALSE;
805 
806  } else {
807  // The class version was not specified when the object was
808  // written OR it was specified to be 1.
809 
810  searchOnChecksum = kTRUE;
811  }
812  } else if (fClass->IsLoaded() && !fClass->IsForeign()) {
813  // We are in the case where the class has a Streamer function.
814  // and fClass->GetClassVersion is 1, we still assume that the
815  // Class Version is specified (to be one).
816 
817  searchOnChecksum = kFALSE;
818 
819  } else if (fClass->IsLoaded() /* implied: && fClass->IsForeign() */ ) {
820  // We are in the case of a Foreign class with no specified
821  // class version.
822 
823  searchOnChecksum = kTRUE;
824 
825  }
826  else {
827  // We are in the case of an 'emulated' class.
828 
829  if (fOnFileClassVersion >= 2) {
830  // The class version was specified when the object was
831  // written
832 
833  searchOnChecksum = kFALSE;
834 
835  } else {
836  // The class version was not specified when the object was
837  // written OR it was specified to be 1.
838 
839  searchOnChecksum = kTRUE;
840 
841  TStreamerInfo* v1 = (TStreamerInfo*) array->At(1);
842  if (v1) {
843  if (fCheckSum != v1->GetCheckSum()) {
844  fClassVersion = array->GetLast() + 1;
845  }
846  }
847  }
848  }
849 
850  if (!searchOnChecksum) {
851  if (fClassVersion < (array->GetEntriesFast() - 1)) {
852  info = (TStreamerInfo*) array->At(fClassVersion);
853  }
854  } else {
855  Int_t ninfos = array->GetEntriesFast() - 1;
856  for (Int_t i = -1; i < ninfos; ++i) {
857  info = (TStreamerInfo*) array->UncheckedAt(i);
858  if (!info) {
859  continue;
860  }
861  if (fCheckSum == info->GetCheckSum() && (info->GetOnFileClassVersion()==1 || info->GetOnFileClassVersion()==0)) {
862  // We must match on the same checksum, an existing TStreamerInfo
863  // for one of the 'unversioned' class layout (i.e. version was 1).
864  fClassVersion = i;
865  break;
866  }
867  info = 0;
868  }
869  if (info==0) {
870  // Find an empty slot.
871  ninfos = array->GetEntriesFast() - 1;
872  Int_t slot = 1; // Start of Class version 1.
873  while ((slot < ninfos) && (array->UncheckedAt(slot) != 0)) {
874  ++slot;
875  }
876  fClassVersion = slot;
877  }
878  }
879 
880  // NOTE: Should we check if the already existing info is the same as
881  // the current one? Yes
882  // In case a class (eg Event.h) has a TClonesArray of Tracks, it could be
883  // that the old info does not have the class name (Track) in the data
884  // member title. Set old title to new title
885  if (info) {
886  // We found an existing TStreamerInfo for our ClassVersion
887  Bool_t match = kTRUE;
888  Bool_t done = kFALSE;
889  Bool_t oldIsNonVersioned = kFALSE;
890  if (fClassVersion!=0 && !fClass->TestBit(TClass::kWarned) && (fClassVersion == info->GetClassVersion()) && (fCheckSum != info->GetCheckSum())) {
891  // The TStreamerInfo's checksum is different from the checksum for the compile class.
892 
893  match = kFALSE;
894  oldIsNonVersioned = info->fOnFileClassVersion==1 && info->fClassVersion != 1;
895 
897  // In the case where the read-in TStreamerInfo does not
898  // match in the 'current' in memory TStreamerInfo for
899  // a non foreign class (we can not get here if this is
900  // a foreign class so we do not need to test it),
901  // we need to add this one more test since the CINT behaviour
902  // with enums changed over time, so verify the checksum ignoring
903  // members of type enum. We also used to not count the //[xyz] comment
904  // in the checksum, so test for that too.
906  &&(info->GetCheckSum() == fClass->GetCheckSum() || fClass->MatchLegacyCheckSum(info->GetCheckSum()))
907  )
908  {
909  match = kTRUE;
910  }
911  if (fOldVersion <= 2) {
912  // Names of STL base classes was modified in vers==3. Allocators removed
913  // (We could be more specific (see test for the same case below)
914  match = kTRUE;
915  }
916  if (!match && CompareContent(0,info,kFALSE,kFALSE,file)) {
917  match = kTRUE;
918  }
919 #ifdef TEST_FOR_BACKWARD_COMPATIBILITY_ABSTRACT_CLASSES
920  if (!match && file->GetVersion() < 51800 && fClass && (fClass->Property() & kIsAbstract)
921  && fClass->GetListOfDataMembers()->GetEntries() != 0)
922  {
923  // In some instances of old files (v5.17 and less), some StreamerInfo for
924  // an abstract class where not written correctly, and add no
925  // data member listed. If in addition one of the data member
926  // was declared using a typedef _and_ the current class definition
927  // uses a different typedef, we are unable to recalculate the
928  // checksum as it was, because the information is missing from
929  // the StreamerInfo, and for the same reason CompareContent can
930  // not know whether this is okay or not ...
931  //
932  // Since this is such an unlikely scenario, let's complain
933  // about it anyway (The class layout *may* have changed, we
934  // don't know).
935 
936  // if (this has only base classes) {
937  // match = kTRUE;
938  // }
939  }
940 #endif
941  } else {
942  // The on-file TStreamerInfo's checksum differs from the checksum of a TStreamerInfo on another file.
943 
944  match = kFALSE;
945  oldIsNonVersioned = info->fOnFileClassVersion==1 && info->fClassVersion != 1;
946 
947  // In the case where the read-in TStreamerInfo does not
948  // match in the 'current' in memory TStreamerInfo for
949  // a non foreign class (we can not get here if this is
950  // a foreign class so we do not need to test it),
951  // we need to add this one more test since the CINT behaviour
952  // with enums changed over time, so verify the checksum ignoring
953  // members of type enum. We also used to not count the //[xyz] comment
954  // in the checksum, so test for that too.
958  || MatchLegacyCheckSum(info->GetCheckSum())
960  {
961  match = kTRUE;
962  }
963  if (fOldVersion <= 2) {
964  // Names of STL base classes was modified in vers==3. Allocators removed
965  // (We could be more specific (see test for the same case below)
966  match = kTRUE;
967  }
968  if (!match && CompareContent(0,info,kFALSE,kFALSE,file)) {
969  match = kTRUE;
970  }
971  }
972  }
973  if (info->IsBuilt()) {
975  fNumber = info->GetNumber();
976  Int_t nel = fElements->GetEntriesFast();
977  TObjArray* elems = info->GetElements();
978  TStreamerElement* e1 = 0;
979  TStreamerElement* e2 = 0;
980  for (Int_t i = 0; i < nel; ++i) {
982  e2 = (TStreamerElement*) elems->At(i);
983  if (!e1 || !e2) {
984  continue;
985  }
986  if (strlen(e1->GetTitle()) != strlen(e2->GetTitle())) {
987  e2->SetTitle(e1->GetTitle());
988  }
989  }
990 
991  done = kTRUE;
992  } else {
994  info = 0;
995  }
996  TString origin;
997  if (!match && !fClass->TestBit(TClass::kWarned)) {
998  if (oldIsNonVersioned) {
999  if (file) {
1000  Warning("BuildCheck", "\n\
1001  The class %s transitioned from not having a specified class version\n\
1002  to having a specified class version (the current class version is %d).\n\
1003  However too many different non-versioned layouts of the class have been\n\
1004  loaded so far. This prevent the proper reading of objects written with\n\
1005  the class layout version %d, in particular from the file:\n\
1006  %s.\n\
1007  To work around this issue, load fewer 'old' files in the same ROOT session.",
1009  } else {
1010  Warning("BuildCheck", "\n\
1011  The class %s transitioned from not having a specified class version\n\
1012  to having a specified class version (the current class version is %d).\n\
1013  However too many different non-versioned layouts of the class have been\n\
1014  loaded so far. This prevent the proper reading of objects written with\n\
1015  the class layout version %d.\n\
1016  To work around this issue, load fewer 'old' files in the same ROOT session.",
1018  }
1019  } else {
1020  if (file) {
1021  if (done) {
1022  Warning("BuildCheck", "\n\
1023  The StreamerInfo for version %d of class %s read from the file %s\n\
1024  has a different checksum than the previously loaded StreamerInfo.\n\
1025  Reading objects of type %s from the file %s \n\
1026  (and potentially other files) might not work correctly.\n\
1027  Most likely the version number of the class was not properly\n\
1028  updated [See ClassDef(%s,%d)].",
1029  fClassVersion, GetName(), file->GetName(), GetName(), file->GetName(), GetName(), fClassVersion);
1030  } else {
1031  Warning("BuildCheck", "\n\
1032  The StreamerInfo from %s does not match existing one (%s:%d)\n\
1033  The existing one has not been used yet and will be discarded.\n\
1034  Reading the file %s will work properly, however writing object of\n\
1035  type %s will not work properly. Most likely the version number\n\
1036  of the class was not properly updated [See ClassDef(%s,%d)].",
1037  file->GetName(), GetName(), fClassVersion,file->GetName(),GetName(), GetName(), fClassVersion);
1038  }
1039  } else {
1040  if (done) {
1041  Warning("BuildCheck", "\n\
1042  The StreamerInfo for version %d of class %s\n\
1043  has a different checksum than the previously loaded StreamerInfo.\n\
1044  Reading objects of type %s\n\
1045  (and potentially other files) might not work correctly.\n\
1046  Most likely the version number of the class was not properly\n\
1047  updated [See ClassDef(%s,%d)].",
1049  } else {
1050  Warning("BuildCheck", "\n\
1051  The StreamerInfo from %s does not match existing one (%s:%d)\n\
1052  The existing one has not been used yet and will be discarded.\n\
1053  Reading should work properly, however writing object of\n\
1054  type %s will not work properly. Most likely the version number\n\
1055  of the class was not properly updated [See ClassDef(%s,%d)].",
1057  }
1058  }
1059  }
1060  CompareContent(0,info,kTRUE,kTRUE,file);
1062  }
1063  if (done) {
1064  return;
1065  }
1066  }
1067  // The slot was free, however it might still be reserved for the current
1068  // loaded version of the class
1069  if (fClass->IsLoaded()
1071  && (fClassVersion != 0) // We don't care about transient classes
1073  && (fCheckSum != fClass->GetCheckSum())) {
1074 
1075  // If the old TStreamerInfo matches the in-memory one when we either
1076  // - ignore the members of type enum
1077  // or
1078  // - ignore the comments annotation (//[xyz])
1079  // we can accept the old TStreamerInfo.
1080 
1082 
1084  if (warn) {
1085  warn = !CompareContent(fClass,0,kFALSE,kFALSE,file);
1086  }
1087 #ifdef TEST_FOR_BACKWARD_COMPATIBILITY_ABSTRACT_CLASSES
1088  if (warn && file->GetVersion() < 51800 && fClass && (fClass->Property() & kIsAbstract)
1089  && fClass->GetListOfDataMembers()->GetEntries() != 0)
1090  {
1091  // In some instances of old files (v5.17 and less), some StreamerInfo for
1092  // an abstract class where not written correctly, and add no
1093  // data member listed. If in addition one of the data member
1094  // was declared using a typedef _and_ the current class definition
1095  // uses a different typedef, we are unable to recalculate the
1096  // checksum as it was, because the information is missing from
1097  // the StreamerInfo, and for the same reason CompareContent can
1098  // not know whether this is okay or not ...
1099  //
1100  // Since this is such an unlikely scenario, let's complain
1101  // about it anyway (The class layout *may* have changed, we
1102  // don't know).
1103 
1104  // if (this has only base classes) {
1105  // warn = kFALSE;
1106  // }
1107  }
1108 #endif // TEST_FOR_BACKWARD_COMPATIBILITY
1109  if (warn && (fOldVersion <= 2)) {
1110  // Names of STL base classes was modified in vers==3. Allocators removed
1111  //
1112  TIter nextBC(fClass->GetListOfBases());
1113  TBaseClass* bc = 0;
1114  while ((bc = (TBaseClass*) nextBC())) {
1115  if (bc->GetClassPointer()->GetCollectionType()) {
1116  warn = kFALSE;
1117  }
1118  }
1119  }
1120  if (warn) {
1121  if (file) {
1122  Warning("BuildCheck", "\n\
1123  The StreamerInfo of class %s read from file %s\n\
1124  has the same version (=%d) as the active class but a different checksum.\n\
1125  You should update the version to ClassDef(%s,%d).\n\
1126  Do not try to write objects with the current class definition,\n\
1127  the files will not be readable.\n", GetName(), file->GetName(), fClassVersion, GetName(), fClassVersion + 1);
1128  } else {
1129  Warning("BuildCheck", "\n\
1130  The StreamerInfo of class %s \n\
1131  has the same version (=%d) as the active class but a different checksum.\n\
1132  You should update the version to ClassDef(%s,%d).\n\
1133  Do not try to write objects with the current class definition,\n\
1134  the files will not be readable.\n", GetName(), fClassVersion, GetName(), fClassVersion + 1);
1135  }
1136  CompareContent(fClass,0,kTRUE,kTRUE,file);
1138  }
1139  } else {
1140  if (!fClass->IsVersioned()) {
1141  Fatal("BuildCheck", "\n\
1142  The StreamerInfo of unversioned class %s \n\
1143  has the same version (=%d) as the active class but an old checksum.\n\
1144  This should not happen. An assert will follow.\n", GetName(), fClassVersion);
1145  }
1146  }
1147  }
1148  if (!fClass->IsLoaded() && this->fOnFileClassVersion>1)
1149  {
1150  ROOT::ResetClassVersion(fClass,(const char*)-1, this->fClassVersion);
1151  }
1152  }
1153  // FIXME: This code can never execute because Build() calls
1154  // TStreamerElement::Class()->IgnoreTObjectStreamer()
1155  // so our bits are never saved to the file.
1158  }
1159  if ((fClassVersion < -1) || (fClassVersion > 65000)) {
1160  printf("ERROR reading TStreamerInfo: %s fClassVersion=%d\n", GetName(), fClassVersion);
1161  SetBit(kCanDelete);
1162  fNumber = -1;
1163  return;
1164  }
1165 
1168  && GetCheckSum() != fClass->GetCheckSum()
1170  // We got here, thus we are a perfect alias for the current streamerInfo,
1171  // but we might had odd v5 style name spelling, so let's prefer the
1172  // current one.
1173  SetBit(kCanDelete);
1174  return;
1175  }
1176 
1178  ++fgCount;
1179  fNumber = fgCount;
1180 
1181  // Since we just read this streamerInfo from file, it has already been built.
1182  fIsBuilt = kTRUE;
1183 
1184  //add to the global list of StreamerInfo
1185  TObjArray* infos = (TObjArray*) gROOT->GetListOfStreamerInfo();
1186  infos->AddAtAndExpand(this, fNumber);
1187 }
1188 
1189 ////////////////////////////////////////////////////////////////////////////////
1190 /// Create an Emulation TStreamerInfo object.
1191 
1193 {
1195 
1196  TString duName;
1197  R__ASSERT(file);
1198  Int_t fv = file->GetVersion()%100000;
1199  R__ASSERT(fv < 30000);
1200  fClassVersion = -1;
1201  fCheckSum = 2001;
1202  TObjArray *elements = GetElements();
1203  Int_t ndata = elements ? elements->GetEntries() : 0;
1204  for (Int_t i=0;i < ndata;i++) {
1205  TStreamerElement *element = (TStreamerElement*)elements->UncheckedAt(i);
1206  if (!element) break;
1207  int ty = element->GetType();
1208  if (ty < kChar || ty >kULong+kOffsetL) continue;
1209  if (ty == kLong) element->SetType(kInt);
1210  if (ty == kULong) element->SetType(kUInt);
1211  if (ty == kLong + kOffsetL) element->SetType(kInt + kOffsetL);
1212  if (ty == kULong + kOffsetL) element->SetType(kUInt + kOffsetL);
1213  if (ty <= kULong) continue;
1214  duName = element->GetName();
1215  duName.Append("QWERTY");
1216  TStreamerBasicType *bt = new TStreamerBasicType(duName, "", 0, kInt,"Int_t");
1217  {for (int j=ndata-1;j>=i;j--) {elements->AddAtAndExpand(elements->At(j),j+1);}}
1218  elements->AddAt(bt,i);
1219  ndata++;
1220  i++;
1221  }
1222  BuildOld();
1223 }
1224 
1225 ////////////////////////////////////////////////////////////////////////////////
1226 /// Check if we can build this for foreign class - do we have some rules
1227 /// to do that.
1228 
1229 Bool_t TStreamerInfo::BuildFor( const TClass *in_memory_cl )
1230 {
1232 
1233  if( !in_memory_cl || !in_memory_cl->GetSchemaRules() ) {
1234  return kFALSE;
1235  }
1236 
1237  auto rules = in_memory_cl->GetSchemaRules()->FindRules( GetName(), fOnFileClassVersion, fCheckSum );
1238 
1239  if( rules.empty() && !in_memory_cl->GetCollectionType() ) {
1240  Warning( "BuildFor", "The build of %s streamer info for %s has been requested, but no matching conversion rules were specified", GetName(), in_memory_cl->GetName() );
1241  return kFALSE;
1242  }
1243 
1244  fClass = const_cast<TClass*>(in_memory_cl);
1245 
1246  return kTRUE;
1247 }
1248 
1249 
1250 namespace {
1251 ////////////////////////////////////////////////////////////////////////////////
1252 /// Helper function for BuildOld
1253  Bool_t ClassWasMovedToNamespace(TClass *oldClass, TClass *newClass)
1254  {
1255  // Returns true if oldClass is the same as newClass but newClass is in a
1256  // namespace (and oldClass was not in a namespace).
1257 
1258  if (oldClass == 0 || newClass == 0) return kFALSE;
1259 
1260  UInt_t newlen = strlen(newClass->GetName());
1261  UInt_t oldlen = strlen(oldClass->GetName());
1262 
1263  const char *oldname = oldClass->GetName();
1264  for (UInt_t i = oldlen, done = false, nest = 0; (i>0) && !done ; --i) {
1265  switch (oldClass->GetName()[i-1]) {
1266  case '>' : ++nest; break;
1267  case '<' : if (nest==0) return kFALSE; // the name is not well formed, give up.
1268  --nest; break;
1269  case ':' : if (nest == 0) oldname= &(oldClass->GetName()[i]); done = kTRUE; break;
1270  }
1271  }
1272  oldlen = strlen(oldname);
1273  if (!(strlen(newClass->GetName()) > strlen(oldClass->GetName()))) {
1274  return kFALSE;
1275  }
1276 
1277  const char* newEnd = & (newClass->GetName()[newlen-oldlen]);
1278 
1279  if (0 != strcmp(newEnd, oldname)) {
1280  return kFALSE;
1281  }
1282 
1283  Int_t oldv = oldClass->GetStreamerInfo()->GetClassVersion();
1284 
1285  if (newClass->GetStreamerInfos() && oldv < newClass->GetStreamerInfos()->GetSize() && newClass->GetStreamerInfos()->At(oldv) && strcmp(newClass->GetStreamerInfos()->At(oldv)->GetName(), oldClass->GetName()) != 0) {
1286  // The new class has already a TStreamerInfo for the the same version as
1287  // the old class and this was not the result of an import. So we do not
1288  // have a match
1289  return kFALSE;
1290  }
1291  return kTRUE;
1292  }
1293 
1294 ////////////////////////////////////////////////////////////////////////////////
1295 /// Import the streamerInfo from oldClass to newClass.
1296 ///
1297 /// In case of conflict, returns the version number of the StreamerInfo
1298 /// with the conflict.
1299 /// Return 0 in case of success
1300  Int_t ImportStreamerInfo(TClass *oldClass, TClass *newClass) {
1301 
1302  TIter next(oldClass->GetStreamerInfos());
1303  TStreamerInfo *info;
1304  while ((info = (TStreamerInfo*)next())) {
1305  info = (TStreamerInfo*)info->Clone();
1306  if (!info) {
1307  Error("ImportStreamerInfo","Unable to clone the StreamerInfo for %s.",(*next)->GetName());
1308  } else {
1309  info->SetClass(newClass);
1310  Int_t oldv = info->GetClassVersion();
1311  if (oldv > newClass->GetStreamerInfos()->GetSize() || newClass->GetStreamerInfos()->At(oldv) == 0) {
1312  // All is good.
1313  newClass->RegisterStreamerInfo(info);
1314  } else {
1315  // We verify that we are consistent and that
1316  // newcl->GetStreamerInfos()->UncheckedAt(info->GetClassVersion)
1317  // is already the same as info.
1318  if (strcmp(newClass->GetStreamerInfos()->At(oldv)->GetName(),
1319  oldClass->GetName()) != 0) {
1320  // The existing StreamerInfo does not already come from OldClass.
1321  // This is a real problem!
1322  return oldv;
1323  }
1324  }
1325  }
1326  }
1327  return 0;
1328  }
1329 
1330  Bool_t ContainerMatchTClonesArray(TClass *newClass)
1331  {
1332  // Return true if newClass is a likely valid conversion from
1333  // a TClonesArray
1334 
1335  return newClass->GetCollectionProxy()
1336  && newClass->GetCollectionProxy()->GetValueClass()
1337  && !newClass->GetCollectionProxy()->HasPointers();
1338  }
1339 
1340  Bool_t CollectionMatch(const TClass *oldClass, const TClass* newClass)
1341  {
1342  // Return true if oldClass and newClass points to 2 compatible collection.
1343  // i.e. they contains the exact same type.
1344 
1345  TVirtualCollectionProxy *oldProxy = oldClass->GetCollectionProxy();
1346  TVirtualCollectionProxy *newProxy = newClass->GetCollectionProxy();
1347 
1348  TClass *oldContent = oldProxy->GetValueClass();
1349  TClass *newContent = newProxy->GetValueClass();
1350 
1351  Bool_t contentMatch = kFALSE;
1352  if (oldContent) {
1353  if (oldContent == newContent) {
1354  contentMatch = kTRUE;
1355  } else if (newContent) {
1356  TString oldFlatContent( TMakeProject::UpdateAssociativeToVector(oldContent->GetName()) );
1357  TString newFlatContent( TMakeProject::UpdateAssociativeToVector(newContent->GetName()) );
1358  if (oldFlatContent == newFlatContent) {
1359  contentMatch = kTRUE;
1360  }
1361  } else {
1362  contentMatch = kFALSE;
1363  }
1364  } else {
1365  contentMatch = (newContent==0);
1366  }
1367 
1368  if (contentMatch) {
1369  if ((oldContent==0 && oldProxy->GetType() == newProxy->GetType())
1370  ||(oldContent && oldProxy->HasPointers() == newProxy->HasPointers())) {
1371  // We have compatibles collections (they have the same content)!
1372  return kTRUE;
1373  }
1374  }
1375  return kFALSE;
1376  }
1377 
1378  Bool_t CollectionMatchFloat16(const TClass *oldClass, const TClass* newClass)
1379  {
1380  // Return true if oldClass and newClass points to 2 compatible collection.
1381  // i.e. they contains the exact same type.
1382 
1383  TVirtualCollectionProxy *oldProxy = oldClass->GetCollectionProxy();
1384  TVirtualCollectionProxy *newProxy = newClass->GetCollectionProxy();
1385 
1386  if (oldProxy->GetValueClass() == 0 && newProxy->GetValueClass() == 0
1387  && (oldProxy->GetType() == kFloat_t || oldProxy->GetType() == kFloat16_t)
1388  && (newProxy->GetType() == kFloat_t || newProxy->GetType() == kFloat16_t )) {
1389  // We have compatibles collections (they have the same content)!
1390  return (oldClass->GetCollectionType() == newClass->GetCollectionType());
1391  }
1392  return kFALSE;
1393  }
1394 
1395  Bool_t CollectionMatchDouble32(const TClass *oldClass, const TClass* newClass)
1396  {
1397  // Return true if oldClass and newClass points to 2 compatible collection.
1398  // i.e. they contains the exact same type.
1399 
1400  TVirtualCollectionProxy *oldProxy = oldClass->GetCollectionProxy();
1401  TVirtualCollectionProxy *newProxy = newClass->GetCollectionProxy();
1402 
1403  if (oldProxy->GetValueClass() == 0 && newProxy->GetValueClass() == 0
1404  && (oldProxy->GetType() == kDouble_t || oldProxy->GetType() == kDouble32_t)
1405  && (newProxy->GetType() == kDouble_t || newProxy->GetType() == kDouble32_t )) {
1406  // We have compatibles collections (they have the same content)!
1407  return (oldClass->GetCollectionType() == newClass->GetCollectionType());
1408  }
1409  return kFALSE;
1410  }
1411 
1412  Bool_t CollectionMatchLong64(const TClass *oldClass, const TClass* newClass)
1413  {
1414  // Return true if oldClass and newClass points to 2 compatible collection.
1415  // i.e. they contains the exact same type.
1416 
1417  TVirtualCollectionProxy *oldProxy = oldClass->GetCollectionProxy();
1418  TVirtualCollectionProxy *newProxy = newClass->GetCollectionProxy();
1419 
1420  if (oldProxy->GetValueClass() == 0 && newProxy->GetValueClass() == 0
1421  && (oldProxy->GetType() == kLong_t || oldProxy->GetType() == kLong64_t)
1422  && (newProxy->GetType() == kLong_t || newProxy->GetType() == kLong64_t )) {
1423  // We have compatibles collections (they have the same content)!
1424  return (oldClass->GetCollectionType() == newClass->GetCollectionType());
1425  }
1426  return kFALSE;
1427  }
1428 
1429  Bool_t CollectionMatchULong64(const TClass *oldClass, const TClass* newClass)
1430  {
1431  // Return true if oldClass and newClass points to 2 compatible collection.
1432  // i.e. they contains the exact same type.
1433 
1434  TVirtualCollectionProxy *oldProxy = oldClass->GetCollectionProxy();
1435  TVirtualCollectionProxy *newProxy = newClass->GetCollectionProxy();
1436 
1437  if (oldProxy->GetValueClass() == 0 && newProxy->GetValueClass() == 0
1438  && (oldProxy->GetType() == kULong_t || oldProxy->GetType() == kULong64_t)
1439  && (newProxy->GetType() == kULong_t || newProxy->GetType() == kULong64_t )) {
1440  // We have compatibles collections (they have the same content)!
1441  return (oldClass->GetCollectionType() == newClass->GetCollectionType());
1442  }
1443  return kFALSE;
1444  }
1445 
1446  TClass *FindAlternate(TClass *context, const std::string &i_name, std::string& newName)
1447  {
1448  // Return a class whose has the name as oldClass and can be found
1449  // within the scope of the class 'context'.
1450 
1451  // First strip any 'const ' prefix or trailing '*'.
1452  std::string name(i_name);
1453  newName.clear();
1454  if (name.compare(0,6,"const ")==0) {
1455  newName = "const ";
1456  name.erase(0,6);
1457  }
1458  std::string suffix;
1459  UInt_t nstars = 0;
1460  while(name[name.length()-nstars-1]=='*') {
1461  ++nstars;
1462  suffix.append("*");
1463  }
1464  if (nstars) {
1465  name.erase(name.length()-nstars,nstars);
1466  }
1467 
1468  std::string alternate(context->GetName());
1469  alternate.append("::");
1470  alternate.append(name);
1471 
1472  TClass *altcl = TClass::GetClass(alternate.c_str(),/*load=*/ false,true);
1473  if (altcl) {
1474  newName.append(altcl->GetName());
1475  newName.append(suffix);
1476  return altcl;
1477  }
1478 
1479  size_t ctxt_cursor = strlen(context->GetName());
1480  for (size_t level = 0; ctxt_cursor != 0; --ctxt_cursor) {
1481  switch (context->GetName()[ctxt_cursor]) {
1482  case '<': --level; break;
1483  case '>': ++level; break;
1484  case ':': if (level == 0) {
1485  // we encountered a scope not within a template
1486  // parameter.
1487  alternate.clear();
1488  alternate.append(context->GetName(),ctxt_cursor+1);
1489  alternate.append(name);
1490  altcl = TClass::GetClass(alternate.c_str(),/*load=*/ false,true);
1491  if (altcl) {
1492  newName.append(altcl->GetName());
1493  newName.append(suffix);
1494  return altcl;
1495  }
1496  }
1497  }
1498  }
1499  newName.clear();
1500  return 0;
1501  }
1502 
1503  bool HasScope(const std::string &name)
1504  {
1505  // return true if the type name has a scope in it.
1506 
1507  for(size_t i = 0, level = 0; i<name.length(); ++i) {
1508  switch (name[i]) {
1509  case '<': ++level; break;
1510  case '>': --level; break;
1511  case ':': if (level == 0) {
1512  // we encountered a scope not within a template
1513  // parameter.
1514  return true;
1515  }
1516  }
1517  } // for each in name
1518  return false;
1519  }
1520 
1521  TClass *FixCollectionV5(TClass *context, TClass *oldClass, TClass *newClass)
1522  {
1523  assert(oldClass->GetCollectionProxy() && newClass->GetCollectionProxy());
1524 
1525  TVirtualCollectionProxy *old = oldClass->GetCollectionProxy();
1526  TVirtualCollectionProxy *current = newClass->GetCollectionProxy();
1527  Int_t stlkind = old->GetCollectionType();
1528 
1529  if (stlkind == ROOT::kSTLmap || stlkind == ROOT::kSTLmultimap) {
1530 
1531  TVirtualStreamerInfo *info = current->GetValueClass()->GetStreamerInfo();
1532  if (info->GetElements()->GetEntries() != 2) {
1533  return oldClass;
1534  }
1535  TStreamerElement *f = (TStreamerElement*) info->GetElements()->At(0);
1536  TStreamerElement *s = (TStreamerElement*) info->GetElements()->At(1);
1537 
1538  info = old->GetValueClass()->GetStreamerInfo();
1539  assert(info->GetElements()->GetEntries() == 2);
1540  TStreamerElement *of = (TStreamerElement*) info->GetElements()->At(0);
1541  TStreamerElement *os = (TStreamerElement*) info->GetElements()->At(1);
1542 
1543  TClass *firstNewCl = f ? f->GetClass() : 0;
1544  TClass *secondNewCl = s ? s->GetClass() : 0;
1545 
1546  TClass *firstOldCl = of ? of->GetClass() : 0;
1547  TClass *secondOldCl = os ? os->GetClass() : 0;
1548 
1549  if ((firstNewCl && !firstOldCl) || (secondNewCl && !secondOldCl))
1550  {
1551  std::vector<std::string> inside;
1552  int nestedLoc;
1553  TClassEdit::GetSplit( oldClass->GetName(), inside, nestedLoc, TClassEdit::kLong64 );
1554 
1555  TClass *firstAltCl = firstOldCl;
1556  TClass *secondAltCl = secondOldCl;
1557  std::string firstNewName;
1558  std::string secondNewName;
1559  if (firstNewCl && !HasScope(inside[1])) {
1560  firstAltCl = FindAlternate(context, inside[1], firstNewName);
1561  }
1562  if (secondNewCl && !HasScope(inside[2])) {
1563  secondAltCl = FindAlternate(context, inside[2], secondNewName);
1564  }
1565  if ((firstNewCl && firstAltCl != firstOldCl) ||
1566  (secondNewCl && secondAltCl != secondOldCl) ) {
1567 
1568  // Need to produce new name.
1569  std::string alternate = inside[0];
1570  alternate.append("<");
1571  alternate.append(firstAltCl ? firstNewName : inside[1]);
1572  alternate.append(",");
1573  alternate.append(secondAltCl? secondNewName : inside[2]);
1574  // We are intentionally dropping any further arguments,
1575  // they would be using the wrong typename and would also be
1576  // somewhat superflous since this is for the old layout.
1577  if (alternate[alternate.length()-1]=='>') {
1578  alternate.append(" ");
1579  }
1580  alternate.append(">");
1581  return TClass::GetClass(alternate.c_str(),true,true);
1582  }
1583  }
1584 
1585  } else if (current->GetValueClass() && !old->GetValueClass()
1586  && old->GetType() == kInt_t) {
1587 
1588  // The old CollectionProxy claims it contains int (or enums) while
1589  // the new one claims to contain a class. It is likely that we have
1590  // in the collection name a class (typedef) name that is missing its
1591  // scope. Let's try to check.
1592 
1593  std::vector<std::string> inside;
1594  int nestedLoc;
1595  TClassEdit::GetSplit( oldClass->GetName(), inside, nestedLoc, TClassEdit::kLong64 );
1596 
1597  // Does the type already have a scope, in which case,
1598  // (at least for now), let's assume it is already fine.
1599  if (HasScope(inside[1])) {
1600  return oldClass;
1601  }
1602 
1603  // Now let's if we can find this missing type.
1604  std::string newName;
1605  TClass *altcl = FindAlternate(context, inside[1], newName);
1606 
1607  if (altcl) {
1608  std::string alternate = inside[0];
1609  alternate.append("<");
1610  alternate.append(newName);
1611  // We are intentionally dropping any further arguments,
1612  // they would be using the wrong typename and would also be
1613  // somewhat superflous since this is for the old layout.
1614  if (alternate[alternate.length()-1]=='>') {
1615  alternate.append(" ");
1616  }
1617  alternate.append(">");
1618  return TClass::GetClass(alternate.c_str(),true,true);
1619  }
1620  }
1621  return 0;
1622  }
1623 
1624  // Makes sure kBuildOldUsed set once BuildOld finishes
1625  struct TBuildOldGuard {
1626  TBuildOldGuard(TStreamerInfo* info): fInfo(info) {
1627  fInfo->SetBit(TStreamerInfo::kBuildRunning);
1628  }
1629  ~TBuildOldGuard() {
1630  fInfo->ResetBit(TStreamerInfo::kBuildRunning);
1631  fInfo->SetBit(TStreamerInfo::kBuildOldUsed);
1632  }
1633  TStreamerInfo* fInfo;
1634  };
1635 }
1636 
1637 ////////////////////////////////////////////////////////////////////////////////
1638 /// rebuild the TStreamerInfo structure
1639 
1641 {
1643 
1644  if ( TestBit(kBuildOldUsed) ) return;
1645 
1646  // Are we recursing on ourself?
1648 
1649  // This is used to avoid unwanted recursive call to Build and make sure
1650  // that we record the execution of BuildOld.
1651  TBuildOldGuard buildOldGuard(this);
1652 
1653  if (gDebug > 0) {
1654  printf("\n====>Rebuilding TStreamerInfo for class: %s, version: %d\n", GetName(), fClassVersion);
1655  }
1656 
1657  Bool_t wasCompiled = IsCompiled();
1658 
1659  if (fClass->GetClassVersion() == fClassVersion) {
1661  {
1662  // Handle emulated classes and STL containers specially.
1663  // in this case BuildRealData would call BuildOld for this same
1664  // TStreamerInfo to be able to build the real data on it.
1665  } else {
1666  fClass->BuildRealData();
1667  }
1668  }
1669  else {
1670  // This is to support the following case
1671  // Shared library: Event v2
1672  // calling cl->GetStreamerInfo(1)->BuildOld(); (or equivalent)
1673  // which calls cl->BuildReadData()
1674  // which set fRealData to some value
1675  // then call Event()
1676  // which call cl->GetStreamerInfo()
1677  // which call cl->BuildRealData();
1678  // which returns immediately (upon seeing fRealData!=0)
1679  // then the main StreamerInfo build using the partial content of fRealData
1680  // then BuildRealData returns
1681  // then GetStreamerInfo() returns
1682  // then Event() returns
1683  // then fRealData is finished being populated
1684  // then this function continue,
1685  // then it uses the main streamerInfo
1686  // .... which is incomplete.
1687  //
1688  // Instead we force the creation of the main streamerInfo object
1689  // before the creation of fRealData.
1691  }
1692 
1693  TIter next(fElements);
1694  TStreamerElement* element;
1695  Int_t offset = 0;
1696  TMemberStreamer* streamer = 0;
1697 
1698  constexpr size_t kSizeOfPtr = sizeof(void*);
1699 
1700  int nBaze = 0;
1701 
1702  if ((fElements->GetEntries() == 1) && !strcmp(fElements->At(0)->GetName(), "This")) {
1703  if (fClass->GetCollectionProxy()) {
1704  element = (TStreamerElement*)next();
1705  element->SetNewType( element->GetType() );
1706  element->SetNewClass( fClass );
1707  } else if (((TStreamerElement*)fElements->At(0))->GetType() == TStreamerInfo::kSTL &&
1708  strcmp( ((TStreamerElement*)fElements->At(0))->GetTypeName(),GetName()) != 0) {
1709  // We have a collection that was proxied but does not have a collection proxy,
1710  // let's put one in place just for fun ... humm however we have no clue what is the value
1711  // type ....
1712 
1713  // For now wild guess ....
1714 
1715  }
1716  }
1717 
1718  TClass *allocClass = 0;
1719  TStreamerInfo *infoalloc = 0;
1720 
1721  //---------------------------------------------------------------------------
1722  // Get schema rules for this class
1723  /////////////////////////////////////////////////////////////////////////////
1724 
1725  ROOT::TSchemaRuleSet::TMatches rules;
1726  const ROOT::TSchemaRuleSet* ruleSet = fClass->GetSchemaRules();
1727 
1728  if (ruleSet) rules = ruleSet->FindRules( GetName(), fOnFileClassVersion, fCheckSum );
1729 
1731  Int_t virtualInfoLocAlloc = 0;
1732  fNVirtualInfoLoc = 0;
1733  delete [] fVirtualInfoLoc;
1734  fVirtualInfoLoc = 0;
1735 
1736  while ((element = (TStreamerElement*) next())) {
1737  if (element->IsA()==TStreamerArtificial::Class()
1738  || element->TestBit(TStreamerElement::kCache) )
1739  {
1740  // Prevent BuildOld from modifying existing ArtificialElement (We need to review when and why BuildOld
1741  // needs to be re-run; it might be needed if the 'current' class change (for example from being an onfile
1742  // version to being a version loaded from a shared library) and we thus may have to remove the artifical
1743  // element at the beginning of BuildOld)
1744 
1745  continue;
1746  };
1747 
1748  element->SetNewType(element->GetType());
1749  if (element->IsBase()) {
1750  //---------------------------------------------------------------------
1751  // Dealing with nonSTL bases
1752  ///////////////////////////////////////////////////////////////////////
1753 
1754  if (element->IsA() == TStreamerBase::Class()) {
1755  TStreamerBase* base = (TStreamerBase*) element;
1756 #if defined(PROPER_IMPLEMEMANTION_OF_BASE_CLASS_RENAMING)
1757  TClass* baseclass = fClass->GetBaseClass( base->GetName() );
1758 #else
1759  // Currently the base class renaming does not work, so we use the old
1760  // version of the code which essentially disable the next if(!baseclass ..
1761  // statement.
1762  TClass* baseclass = base->GetClassPointer();
1763 #endif
1764 
1765  //------------------------------------------------------------------
1766  // We do not have this base class - check if we're renaming
1767  ////////////////////////////////////////////////////////////////////
1768 
1769  if( !baseclass && !fClass->TestBit( TClass::kIsEmulation ) ) {
1770  const ROOT::TSchemaRule* rule = (rules ? rules.GetRuleWithSource( base->GetName() ) : 0);
1771 
1772  //---------------------------------------------------------------
1773  // No renaming, sorry
1774  /////////////////////////////////////////////////////////////////
1775 
1776  if( !rule ) {
1777  Error("BuildOld", "Could not find base class: %s for %s and could not find any matching rename rule\n", base->GetName(), GetName());
1778  continue;
1779  }
1780 
1781  //----------------------------------------------------------------
1782  // Find a new target class
1783  /////////////////////////////////////////////////////////////////
1784 
1785  const TObjArray* targets = rule->GetTarget();
1786  if( !targets ) {
1787  Error("BuildOld", "Could not find base class: %s for %s, renaming rule was found but is malformed\n", base->GetName(), GetName());
1788  }
1789  TString newBaseClass = ((TObjString*)targets->At(0))->GetString();
1790  baseclass = TClass::GetClass( newBaseClass );
1791  base->SetNewBaseClass( baseclass );
1792  }
1793  //-------------------------------------------------------------------
1794  // No base class in emulated mode
1795  ////////////////////////////////////////////////////////////////////
1796 
1797  else if( !baseclass ) {
1798  baseclass = base->GetClassPointer();
1799  if (!baseclass) {
1800  Warning("BuildOld", "Missing base class: %s skipped", base->GetName());
1801  // FIXME: Why is the version number 1 here? Answer: because we don't know any better at this point
1802  baseclass = new TClass(element->GetName(), 1, 0, 0, -1, -1);
1803  element->Update(0, baseclass);
1804  }
1805  }
1806  baseclass->BuildRealData();
1807 
1808  // Calculate the offset using the 'real' base class name (as opposed to the
1809  // '@@emulated' in the case of the emulation of an abstract base class.
1810  Int_t baseOffset = fClass->GetBaseClassOffset(baseclass);
1811 
1812  // Deal with potential schema evolution (renaming) of the base class.
1813  if (baseOffset < 0) {
1814 
1815  // See if this base element can be converted into one of
1816  // the existing base class.
1817  TList* listOfBases = fClass->GetListOfBases();
1818  if (listOfBases) {
1819  TBaseClass* bc = 0;
1820  TIter nextBC(fClass->GetListOfBases());
1821  while ((bc = (TBaseClass*) nextBC())) {
1822  TClass *in_memory_bcl = bc->GetClassPointer();
1823  if (in_memory_bcl && in_memory_bcl->GetSchemaRules()) {
1824  auto baserule = in_memory_bcl->GetSchemaRules()->FindRules( base->GetName(), base->GetBaseVersion(), base->GetBaseCheckSum() );
1825  if (!baserule.empty()) {
1826  base->SetNewBaseClass(in_memory_bcl);
1827  baseOffset = bc->GetDelta();
1828 
1829  }
1830  }
1831  }
1832  }
1833  }
1834  // We need to initialize the element now, as we need the
1835  // correct StreamerInfo next.
1836  element->Init(this);
1837 
1838  // Force the StreamerInfo "Compilation" of the base classes first. This is necessary in
1839  // case the base class contains a member used as an array dimension in the derived classes.
1840  TStreamerInfo* infobase;
1841  if (fClass->TestBit(TClass::kIsEmulation) && (baseclass->Property() & kIsAbstract)) {
1842  Int_t version = base->GetBaseVersion();
1843  if (version >= 0 || base->GetBaseCheckSum() == 0) {
1844  infobase = (TStreamerInfo*)baseclass->GetStreamerInfoAbstractEmulated(version);
1845  } else {
1846  infobase = (TStreamerInfo*)baseclass->FindStreamerInfoAbstractEmulated(base->GetBaseCheckSum());
1847  }
1848  if (infobase) baseclass = infobase->GetClass();
1849  }
1850  else {
1851  infobase = (TStreamerInfo*)base->GetBaseStreamerInfo();
1852  }
1853 
1854  if (infobase && infobase->fComp == 0) {
1855  infobase->BuildOld();
1856  }
1857 
1858  if (infobase && shouldHaveInfoLoc && baseclass->TestBit(TClass::kIsEmulation) ) {
1859  if ( (fNVirtualInfoLoc + infobase->fNVirtualInfoLoc) > virtualInfoLocAlloc ) {
1860  ULong_t *store = fVirtualInfoLoc;
1861  virtualInfoLocAlloc = 16 * ( (fNVirtualInfoLoc + infobase->fNVirtualInfoLoc) / 16 + 1);
1862  fVirtualInfoLoc = new ULong_t[virtualInfoLocAlloc];
1863  if (store) {
1864  memcpy(fVirtualInfoLoc, store, sizeof(ULong_t)*fNVirtualInfoLoc);
1865  delete [] store;
1866  }
1867  }
1868  for (int nloc = 0; nloc < infobase->fNVirtualInfoLoc; ++nloc) {
1869  fVirtualInfoLoc[ fNVirtualInfoLoc + nloc ] = baseOffset + infobase->fVirtualInfoLoc[nloc];
1870  }
1871  fNVirtualInfoLoc += infobase->fNVirtualInfoLoc;
1872  }
1873 
1874 
1875  {
1876  if (baseOffset < 0) {
1877  element->SetNewType(-1);
1878  }
1879  }
1880  element->SetOffset(baseOffset);
1881  offset += baseclass->Size();
1882 
1883  continue;
1884  } else {
1885  // Not a base elem but still base, string or STL as a base
1886  nBaze++;
1887  TList* listOfBases = fClass->GetListOfBases();
1888  Int_t baseOffset = -1;
1889  Int_t asize = 0;
1890  if (listOfBases) {
1891  // Do a search for the classname and some of its alternatives spelling.
1892 
1893  TBaseClass* bc = 0;
1894  TIter nextBC(fClass->GetListOfBases());
1895  while ((bc = (TBaseClass*) nextBC())) {
1896  if (strchr(bc->GetName(), '<') || !strcmp(bc->GetName(),"string")) {
1899  if (bcName == elName) {
1900  break;
1901  }
1902  }
1903  }
1904 
1905  if (!bc) {
1906  // Error("BuildOld", "Could not find STL base class: %s for %s\n", element->GetName(), GetName());
1907  offset = kMissing;
1908  element->SetOffset(kMissing);
1909  element->SetNewType(-1);
1910  continue;
1911  } else if (bc->GetClassPointer()->GetCollectionProxy()
1912  && !bc->GetClassPointer()->IsLoaded()
1914  Error("BuildOld","The class \"%s\" is compiled and its base class \"%s\" is a collection and we do not have a dictionary for it, we will not be able to read or write this base class.",GetName(),bc->GetName());
1915  offset = kMissing;
1916  element->SetOffset(kMissing);
1917  element->SetNewType(-1);
1918  continue;
1919  }
1920  baseOffset = bc->GetDelta();
1921  asize = bc->GetClassPointer()->Size();
1922 
1923  } else if (fClass->TestBit( TClass::kIsEmulation )) {
1924  // Do a search for the classname and some of its alternatives spelling.
1925 
1927  if (newInfo == this) {
1928  baseOffset = offset;
1929  asize = element->GetSize();
1930  } else if (newInfo) {
1931  TIter newElems( newInfo->GetElements() );
1932  TStreamerElement *newElement;
1933  while( (newElement = (TStreamerElement*)newElems()) ) {
1934  const char *newElName = newElement->GetName();
1935  if (newElement->IsBase() && (strchr(newElName,'<') || !strcmp(newElName,"string")) ) {
1936  TString bcName(TClassEdit::ShortType(newElName, TClassEdit::kDropStlDefault).c_str());
1938  if (bcName == elName) {
1939  break;
1940  }
1941  }
1942  }
1943  if (!newElement) {
1944  Error("BuildOld", "Could not find STL base class: %s for %s\n", element->GetName(), GetName());
1945  continue;
1946  }
1947  baseOffset = newElement->GetOffset();
1948  asize = newElement->GetSize();
1949  }
1950  }
1951  if (baseOffset == -1) {
1952  TClass* cb = element->GetClassPointer();
1953  if (!cb) {
1954  element->SetNewType(-1);
1955  continue;
1956  }
1957  asize = cb->Size();
1958  baseOffset = fClass->GetBaseClassOffset(cb);
1959  }
1960 
1961  // we know how to read but do we know where to read?
1962  if (baseOffset < 0) {
1963  element->SetNewType(-1);
1964  continue;
1965  }
1966  element->SetOffset(baseOffset);
1967  offset += asize;
1968  element->Init(this);
1969  continue;
1970  } // if element is of type TStreamerBase or not.
1971  } // if (element->IsBase())
1972 
1973  // If we get here, this means that we looked at all the base classes.
1974  if (shouldHaveInfoLoc && fNVirtualInfoLoc==0) {
1975  fNVirtualInfoLoc = 1;
1976  fVirtualInfoLoc = new ULong_t[1]; // To allow for a single delete statement.
1977  fVirtualInfoLoc[0] = offset;
1978  offset += sizeof(TStreamerInfo*);
1979  }
1980 
1981  TDataMember* dm = 0;
1982 
1983  std::string typeNameBuf;
1984  const char* dmType = nullptr;
1985  Bool_t dmIsPtr = false;
1986  Bool_t isUniquePtr = false;
1987  TDataType* dt(nullptr);
1988  Int_t ndim = 0 ; //dm->GetArrayDim();
1989  std::array<Int_t, 5> maxIndices; // 5 is the maximum supported in TStreamerElement::SetMaxIndex
1990  Bool_t isStdArray(kFALSE);
1991 
1992  // First set the offset and sizes.
1993  if (fClass->GetState() <= TClass::kEmulated) {
1994  // Note the initilization in this case are
1995  // delayed until __after__ the schema evolution
1996  // section, just in case the info has changed.
1997 
1998  // We are in the emulated case
1999  streamer = 0;
2000  element->Init(this);
2001  } else {
2002  // The class is known to Cling (and thus is not emulated)
2003  // and we need to use the real offsets.
2004  // However we may not have a 'proper' TClass for it
2005  // (in which case IsLoaded will be false and GetImplFileLine will be -1)
2006 
2007  // First look for the data member in the current class
2008  dm = (TDataMember*) fClass->GetListOfDataMembers()->FindObject(element->GetName());
2009  if (dm && dm->IsPersistent()) {
2010  fClass->BuildRealData();
2011  streamer = 0;
2012  offset = GetDataMemberOffset(dm, streamer);
2013  element->SetOffset(offset);
2014  element->Init(this);
2015 
2016  // Treat unique pointers and std arrays
2017  dmType = dm->GetTypeName();
2018  dmIsPtr = dm->IsaPointer();
2019  Bool_t nameChanged;
2020  typeNameBuf = TClassEdit::GetNameForIO(dmType, TClassEdit::EModType::kNone, &nameChanged);
2021  if (nameChanged) {
2022  isUniquePtr = dmIsPtr = TClassEdit::IsUniquePtr(dmType);
2023  dmType = typeNameBuf.c_str();
2024  }
2025  if ((isStdArray = TClassEdit::IsStdArray(dmType))){ // We tackle the std array case
2027  typeNameBuf,
2028  maxIndices,
2029  ndim);
2030  dmType = typeNameBuf.c_str();
2031  dt = gROOT->GetType(dmType);
2032  }
2033 
2034  // We have a loaded class, let's make sure that if we have a collection
2035  // it is also loaded.
2036  TString dmClassName = TClassEdit::ShortType(dmType,TClassEdit::kDropStlDefault).c_str();
2037  dmClassName = dmClassName.Strip(TString::kTrailing, '*');
2038  if (dmClassName.Index("const ")==0) dmClassName.Remove(0,6);
2039  TClass *elemDm = ! (dt || dm->IsBasic()) ? TClass::GetClass(dmClassName.Data()) : 0;
2040  if (elemDm && elemDm->GetCollectionProxy()
2041  && !elemDm->IsLoaded()
2043  Error("BuildOld","The class \"%s\" is compiled and for its data member \"%s\", we do not have a dictionary for the collection \"%s\", we will not be able to read or write this data member.",GetName(),dm->GetName(),elemDm->GetName());
2044  offset = kMissing;
2045  element->SetOffset(kMissing);
2046  element->SetNewType(-1);
2047  }
2048  element->SetStreamer(streamer);
2049  int narr = element->GetArrayLength();
2050  if (!narr) {
2051  narr = 1;
2052  }
2053  int dsize = dm->GetUnitSize();
2054  element->SetSize(dsize*narr);
2055  } else {
2056  // We did not find it, let's look for it in the base classes via TRealData
2057  TRealData* rd = fClass->GetRealData(element->GetName());
2058  if (rd && rd->GetDataMember()) {
2059  element->SetOffset(rd->GetThisOffset());
2060  element->Init(this);
2061  dm = rd->GetDataMember();
2062  dmType = dm->GetTypeName();
2063  dmIsPtr = dm->IsaPointer();
2064  int narr = element->GetArrayLength();
2065  if (!narr) {
2066  narr = 1;
2067  }
2068  int dsize = dm->GetUnitSize();
2069  element->SetSize(dsize*narr);
2070  }
2071  }
2072  } // Class corresponding to StreamerInfo is emulated or not.
2073 
2074  // Now let's deal with Schema evolution
2075  Int_t newType = -1;
2076  TClassRef newClass;
2077 
2078  if (dm && dm->IsPersistent()) {
2079  if (dm->GetDataType()) {
2080  Bool_t isArray = element->GetArrayLength() >= 1;
2081  Bool_t hasCount = element->HasCounter();
2082  // data member is a basic type
2083  if ((fClass == TObject::Class()) && !strcmp(dm->GetName(), "fBits")) {
2084  //printf("found fBits, changing dtype from %d to 15\n", dtype);
2085  newType = kBits;
2086  } else {
2087  // All the values of EDataType have the same semantic in EReadWrite
2088  newType = (EReadWrite)dm->GetDataType()->GetType();
2089  }
2090  if ((newType == ::kChar_t) && dmIsPtr && !isArray && !hasCount) {
2091  newType = ::kCharStar;
2092  } else if (dmIsPtr) {
2093  newType += kOffsetP;
2094  } else if (isArray) {
2095  newType += kOffsetL;
2096  }
2097  }
2098  if (newType == -1) {
2099  newClass = TClass::GetClass(dmType);
2100  }
2101  } else {
2102  // Either the class is not loaded or the data member is gone
2103  if (!fClass->IsLoaded()) {
2105  if (newInfo && (newInfo != this)) {
2106  TStreamerElement* newElems = (TStreamerElement*) newInfo->GetElements()->FindObject(element->GetName());
2107  newClass = newElems ? newElems->GetClassPointer() : 0;
2108  if (newClass == 0) {
2109  newType = newElems ? newElems->GetType() : -1;
2110  if (!(newType < kObject)) {
2111  // sanity check.
2112  newType = -1;
2113  }
2114  }
2115  } else {
2116  newClass = element->GetClassPointer();
2117  if (newClass.GetClass() == 0) {
2118  newType = element->GetType();
2119  if (!(newType < kObject)) {
2120  // sanity check.
2121  newType = -1;
2122  }
2123  }
2124  }
2125  }
2126  }
2127 
2128  if (newType > 0) {
2129  // Case of a numerical type
2130  if (element->GetType() >= TStreamerInfo::kObject) {
2131  // Old type was not a numerical type.
2132  element->SetNewType(-2);
2133  } else if (element->GetType() != newType) {
2134  element->SetNewType(newType);
2135  if (gDebug > 0) {
2136  // coverity[mixed_enums] - All the values of EDataType have the same semantic in EReadWrite
2137  Info("BuildOld", "element: %s %s::%s has new type: %s/%d", element->GetTypeName(), GetName(), element->GetName(), dm ? dm->GetFullTypeName() : TDataType::GetTypeName((EDataType)newType), newType);
2138  }
2139  }
2140  } else if (newClass.GetClass()) {
2141  // Sometime BuildOld is called again.
2142  // In that case we might already have fix up the streamer element.
2143  // So we need to go back to the original information!
2144  newClass.Reset();
2146  if (oldClass == newClass.GetClass()) {
2147  // Nothing to do, also in the unique_ptr case :)
2148  } else if (ClassWasMovedToNamespace(oldClass, newClass.GetClass())) {
2149  Int_t oldv;
2150  if (0 != (oldv = ImportStreamerInfo(oldClass, newClass.GetClass()))) {
2151  Warning("BuildOld", "Can not properly load the TStreamerInfo from %s into %s due to a conflict for the class version %d", oldClass->GetName(), newClass->GetName(), oldv);
2152  } else {
2153  element->SetTypeName(newClass->GetName());
2154  if (gDebug > 0) {
2155  Warning("BuildOld", "element: %s::%s %s has new type %s", GetName(), element->GetTypeName(), element->GetName(), newClass->GetName());
2156  }
2157  }
2158  } else if (oldClass == TClonesArray::Class()) {
2159  if (ContainerMatchTClonesArray(newClass.GetClass())) {
2160  Int_t elemType = element->GetType();
2161  Bool_t isPrealloc = (elemType == kObjectp) || (elemType == kAnyp) || (elemType == (kObjectp + kOffsetL)) || (elemType == (kAnyp + kOffsetL));
2162  element->Update(oldClass, newClass.GetClass());
2163  TVirtualCollectionProxy *cp = newClass->GetCollectionProxy();
2164  TConvertClonesArrayToProxy *ms = new TConvertClonesArrayToProxy(cp, element->IsaPointer(), isPrealloc);
2165  element->SetStreamer(ms);
2166 
2167  // When the type is kObject, the TObject::Streamer is used instead
2168  // of the TStreamerElement's streamer. So let force the usage
2169  // of our streamer
2170  if (element->GetType() == kObject) {
2171  element->SetNewType(kAny);
2172  element->SetType(kAny);
2173  }
2174  if (gDebug > 0) {
2175  Warning("BuildOld","element: %s::%s %s has new type %s", GetName(), element->GetTypeName(), element->GetName(), newClass->GetName());
2176  }
2177  } else {
2178  element->SetNewType(-2);
2179  }
2180  } else if (oldClass && oldClass->GetCollectionProxy() && newClass->GetCollectionProxy()) {
2181  {
2182  TClass *oldFixedClass = FixCollectionV5(GetClass(),oldClass,newClass);
2183  if (oldFixedClass && oldFixedClass != oldClass) {
2184  element->Update(oldClass,oldFixedClass);
2185  oldClass = oldFixedClass;
2186  }
2187  }
2188  if (CollectionMatch(oldClass, newClass)) {
2189  Int_t oldkind = oldClass->GetCollectionType();
2190  Int_t newkind = newClass->GetCollectionType();
2191 
2192  if ( (oldkind==ROOT::kSTLmap || oldkind==ROOT::kSTLmultimap) &&
2193  (newkind!=ROOT::kSTLmap && newkind!=ROOT::kSTLmultimap) ) {
2194 
2195  Int_t elemType = element->GetType();
2196  Bool_t isPrealloc = (elemType == kObjectp) || (elemType == kAnyp) || (elemType == (kObjectp + kOffsetL)) || (elemType == (kAnyp + kOffsetL));
2197 
2198  TClassStreamer *streamer2 = newClass->GetStreamer();
2199  if (streamer2) {
2200  TConvertMapToProxy *ms = new TConvertMapToProxy(streamer2, element->IsaPointer(), isPrealloc);
2201  if (ms && ms->IsValid()) {
2202  element->SetStreamer(ms);
2203  switch( element->GetType() ) {
2204  //case TStreamerInfo::kSTLvarp: // Variable size array of STL containers.
2205  case TStreamerInfo::kSTLp: // Pointer to container with no virtual table (stl) and no comment
2206  case TStreamerInfo::kSTLp + TStreamerInfo::kOffsetL: // array of pointers to container with no virtual table (stl) and no comment
2207  element->SetNewType(-2);
2208  break;
2209  case TStreamerInfo::kSTL: // container with no virtual table (stl) and no comment
2210  case TStreamerInfo::kSTL + TStreamerInfo::kOffsetL: // array of containers with no virtual table (stl) and no comment
2211  break;
2212  }
2213  } else {
2214  delete ms;
2215  }
2216  }
2217  element->Update(oldClass, newClass.GetClass());
2218 
2219  } else if ( (newkind==ROOT::kSTLmap || newkind==ROOT::kSTLmultimap) &&
2220  (oldkind!=ROOT::kSTLmap && oldkind!=ROOT::kSTLmultimap) ) {
2221  element->SetNewType(-2);
2222  } else {
2223  element->Update(oldClass, newClass.GetClass());
2224  }
2225  // Is this needed ? : element->SetSTLtype(newelement->GetSTLtype());
2226  if (gDebug > 0) {
2227  Warning("BuildOld","element: %s::%s %s has new type %s", GetName(), element->GetTypeName(), element->GetName(), newClass->GetName());
2228  }
2229  } else if (CollectionMatchFloat16(oldClass,newClass)) {
2230  // Actually nothing to do, since both are the same collection of double in memory.
2231  } else if (CollectionMatchDouble32(oldClass,newClass)) {
2232  // Actually nothing to do, since both are the same collection of double in memory.
2233  } else if (CollectionMatchLong64(oldClass,newClass)) {
2234  // Not much to do since both are the same collection of 8 bits entities on file.
2235  element->Update(oldClass, newClass.GetClass());
2236  } else if (CollectionMatchULong64(oldClass,newClass)) {
2237  // Not much to do since both are the same collection of 8 bits unsigned entities on file
2238  element->Update(oldClass, newClass.GetClass());
2239  } else if (newClass->GetSchemaRules()->HasRuleWithSourceClass( oldClass->GetName() )) {
2240  //------------------------------------------------------------------------
2241  // We can convert one type to another (at least for some of the versions).
2242  /////////////////////////////////////////////////////////////////
2243 
2244  element->SetNewClass( newClass );
2245  } else {
2246  element->SetNewType(-2);
2247  }
2248 
2249  } else if(oldClass &&
2250  newClass.GetClass() &&
2251  newClass->GetSchemaRules() &&
2252  newClass->GetSchemaRules()->HasRuleWithSourceClass( oldClass->GetName() ) ) {
2253  //------------------------------------------------------------------------
2254  // We can convert one type to another (at least for some of the versions).
2255  ////////////////////////////////////////////////////////////////////
2256 
2257  element->SetNewClass( newClass );
2258  } else {
2259  element->SetNewType(-2);
2260  }
2261  // Humm we still need to make sure we have the same 'type' (pointer, embedded object, array, etc..)
2262  Bool_t cannotConvert = kFALSE;
2263  if (element->GetNewType() != -2) {
2264  if (dm) {
2265  if (dmIsPtr) {
2266  if (isUniquePtr || strncmp(dm->GetTitle(),"->",2)==0) {
2267  // We are fine, nothing to do.
2268  if (newClass->IsTObject()) {
2269  newType = kObjectp;
2270  } else if (newClass->GetCollectionProxy()) {
2271  newType = kSTLp;
2272  } else {
2273  newType = kAnyp;
2274  }
2275  } else {
2276  if (TClass::GetClass(dm->GetTypeName())->IsTObject()) {
2277  newType = kObjectP;
2278  } else if (newClass->GetCollectionProxy()) {
2279  newType = kSTLp;
2280  } else {
2281  newType = kAnyP;
2282  }
2283  }
2284  } else {
2285  if (newClass->GetCollectionProxy()) {
2286  newType = kSTL;
2287  } else if (newClass == TString::Class()) {
2288  newType = kTString;
2289  } else if (newClass == TObject::Class()) {
2290  newType = kTObject;
2291  } else if (newClass == TNamed::Class()) {
2292  newType = kTNamed;
2293  } else if (newClass->IsTObject()) {
2294  newType = kObject;
2295  } else {
2296  newType = kAny;
2297  }
2298  }
2299  if ((!dmIsPtr || newType==kSTLp) && (isStdArray ? ndim : dm->GetArrayDim()) > 0) {
2300  newType += kOffsetL;
2301  }
2302  } else if (!fClass->IsLoaded()) {
2304  if (newInfo && (newInfo != this)) {
2305  TStreamerElement* newElems = (TStreamerElement*) newInfo->GetElements()->FindObject(element->GetName());
2306  if (newElems) {
2307  newType = newElems->GetType();
2308  }
2309  } else {
2310  newType = element->GetType();
2311  }
2312  }
2313  if (element->GetType() == kSTL
2314  || ((element->GetType() == kObject || element->GetType() == kAny || element->GetType() == kObjectp || element->GetType() == kAnyp)
2315  && oldClass == TClonesArray::Class()))
2316  {
2317  cannotConvert = (newType != kSTL && newType != kObject && newType != kAny && newType != kSTLp && newType != kObjectp && newType != kAnyp);
2318 
2319  } else if (element->GetType() == kSTLp || ((element->GetType() == kObjectP || element->GetType() == kAnyP) && oldClass == TClonesArray::Class()) )
2320  {
2321  cannotConvert = (newType != kSTL && newType != kObject && newType != kAny && newType != kSTLp && newType != kObjectP && newType != kAnyP);
2322 
2323  } else if (element->GetType() == kSTL + kOffsetL
2324  || ((element->GetType() == kObject + kOffsetL|| element->GetType() == kAny + kOffsetL|| element->GetType() == kObjectp+ kOffsetL || element->GetType() == kAnyp+ kOffsetL)
2325  && oldClass == TClonesArray::Class()))
2326  {
2327  cannotConvert = (newType != kSTL + kOffsetL && newType != kObject+ kOffsetL && newType != kAny+ kOffsetL && newType != kSTLp+ kOffsetL && newType != kObjectp+ kOffsetL && newType != kAnyp+ kOffsetL);
2328 
2329  } else if (element->GetType() == kSTLp + kOffsetL || ((element->GetType() == kObjectP+ kOffsetL || element->GetType() == kAnyP+ kOffsetL) && oldClass == TClonesArray::Class()) )
2330  {
2331  cannotConvert = (newType != kSTL+ kOffsetL && newType != kObject+ kOffsetL && newType != kAny+ kOffsetL && newType != kSTLp + kOffsetL&& newType != kObjectP+ kOffsetL && newType != kAnyP+ kOffsetL);
2332 
2333  } else if ((element->GetType() == kObjectp || element->GetType() == kAnyp
2334  || element->GetType() == kObject || element->GetType() == kAny
2335  || element->GetType() == kTObject || element->GetType() == kTNamed || element->GetType() == kTString )) {
2336  // We had Type* ... ; //-> or Type ...;
2337  // this is completely compatible with the same and with a embedded object.
2338  if (newType != -1) {
2339  if (newType == kObjectp || newType == kAnyp
2340  || newType == kObject || newType == kAny
2341  || newType == kTObject || newType == kTNamed || newType == kTString) {
2342  // We are fine, no transformation to make
2343  element->SetNewType(newType);
2344  } else {
2345  // We do not support this yet.
2346  cannotConvert = kTRUE;
2347  }
2348  } else {
2349  // We have no clue
2350  printf("%s We have no clue\n", dm->GetName());
2351  cannotConvert = kTRUE;
2352  }
2353  } else if (element->GetType() == kObjectP || element->GetType() == kAnyP) {
2354  if (newType != -1) {
2355  if (newType == kObjectP || newType == kAnyP ) {
2356  // nothing to do}
2357  } else {
2358  cannotConvert = kTRUE;
2359  }
2360  } else {
2361  // We have no clue
2362  cannotConvert = kTRUE;
2363  }
2364  }
2365  }
2366  if (cannotConvert) {
2367  element->SetNewType(-2);
2368  if (gDebug > 0) {
2369  // coverity[mixed_enums] - All the values of EDataType have the same semantic in EReadWrite
2370  Info("BuildOld", "element: %s %s::%s has new type: %s/%d", element->GetTypeName(), GetName(), element->GetName(), dm ? dm->GetFullTypeName() : TDataType::GetTypeName((EDataType)newType), newType);
2371  }
2372  }
2373  } else {
2374  element->SetNewType(-1);
2375  offset = kMissing;
2376  element->SetOffset(kMissing);
2377  }
2378 
2379  if (offset != kMissing && fClass->GetState() <= TClass::kEmulated) {
2380  // Note the initialization in this case are
2381  // delayed until __after__ the schema evolution
2382  // section, just in case the info has changed.
2383 
2384  // The class is NOT known to Cling, i.e. is emulated,
2385  // and we need to use the calculated offset.
2386 
2387  Int_t asize;
2388  if (element->GetType() == TStreamerInfo::kSTL &&
2389  strcmp(element->GetName(),"This") == 0 &&
2390  strcmp(element->GetTypeName(),GetName()) == 0 &&
2391  !fClass->GetCollectionProxy()) {
2392  // Humm .. we are missing the collection Proxy
2393  // for a proxied (custom) collection ... avoid
2394  // an infinite recursion and take a wild guess
2395  asize = sizeof(std::vector<int>);
2396  } else {
2397  // Regular case
2398  asize = element->GetSize();
2399  }
2400  // align the non-basic data types (required on alpha and IRIX!!)
2401  if ((offset % kSizeOfPtr) != 0) {
2402  offset = offset - (offset % kSizeOfPtr) + kSizeOfPtr;
2403  }
2404  element->SetOffset(offset);
2405  offset += asize;
2406  }
2407 
2408  if (!wasCompiled && rules) {
2409  if (rules.HasRuleWithSource( element->GetName(), kTRUE ) ) {
2410 
2411  if (allocClass == 0) {
2412  infoalloc = (TStreamerInfo *)Clone(TString::Format("%s@@%d",GetName(),GetOnFileClassVersion()));
2413  if (!infoalloc) {
2414  Error("BuildOld","Unable to create the StreamerInfo for %s.",TString::Format("%s@@%d",GetName(),GetOnFileClassVersion()).Data());
2415  } else {
2416  infoalloc->SetBit(kBuildOldUsed,false);
2417  infoalloc->BuildCheck();
2418  infoalloc->BuildOld();
2419  allocClass = infoalloc->GetClass();
2420  }
2421  }
2422 
2423  // Now that we are caching the unconverted element, we do not assign it to the real type even if we could have!
2424  if (element->GetNewType()>0 /* intentionally not including base class for now */
2425  && !rules.HasRuleWithTarget( element->GetName(), kTRUE ) ) {
2426 
2427  TStreamerElement *copy = (TStreamerElement*)element->Clone();
2428  R__TObjArray_InsertBefore( fElements, copy, element );
2429  next(); // move the cursor passed the insert object.
2431  element = copy;
2432 
2433  // Warning("BuildOld","%s::%s is not set from the version %d of %s (You must add a rule for it)\n",GetName(), element->GetName(), GetClassVersion(), GetName() );
2434  } else {
2435  // If the element is just cached and not repeat, we need to inject an element
2436  // to insure the writing.
2437  TStreamerElement *writecopy = (TStreamerElement*)element->Clone();
2438  R__TObjArray_InsertAfter( fElements, writecopy, element );
2439  next(); // move the cursor passed the insert object.
2440  writecopy->SetBit(TStreamerElement::kWrite);
2441  writecopy->SetNewType( writecopy->GetType() );
2442  writecopy->SetBit(TStreamerElement::kCache);
2443  writecopy->SetOffset(infoalloc ? infoalloc->GetOffset(element->GetName()) : 0);
2444  }
2445  element->SetBit(TStreamerElement::kCache);
2446  element->SetNewType( element->GetType() );
2447  element->SetOffset(infoalloc ? infoalloc->GetOffset(element->GetName()) : 0);
2448  } else if (rules.HasRuleWithTarget( element->GetName(), kTRUE ) ) {
2449  // The data member exist in the onfile StreamerInfo and there is a rule
2450  // that has the same member 'only' has a target ... so this means we are
2451  // asked to ignore the input data ...
2452  if (element->GetType() == kCounter) {
2453  // If the element is a counter, we will need its value to read
2454  // other data member, so let's do so (by not disabling it) even
2455  // if the value will be over-written by a rule.
2456  } else {
2457  element->SetOffset(kMissing);
2458  }
2459  }
2460  } else if (rules && rules.HasRuleWithTarget( element->GetName(), kTRUE ) ) {
2461  // The data member exist in the onfile StreamerInfo and there is a rule
2462  // that has the same member 'only' has a target ... so this means we are
2463  // asked to ignore the input data ...
2464  if (element->GetType() == kCounter) {
2465  // If the element is a counter, we will need its value to read
2466  // other data member, so let's do so (by not disabling it) even
2467  // if the value will be over-written by a rule.
2468  } else {
2469  element->SetOffset(kMissing);
2470  }
2471  }
2472 
2473  if (element->GetNewType() == -2) {
2474  Warning("BuildOld", "Cannot convert %s::%s from type: %s to type: %s, skip element", GetName(), element->GetName(), element->GetTypeName(), newClass ? newClass->GetName() : (dm ? dm->GetFullTypeName() : "unknown") );
2475  }
2476  }
2477 
2478  // If we get here, this means that there no data member after the last base class
2479  // (or no base class at all).
2480  if (shouldHaveInfoLoc && fNVirtualInfoLoc==0) {
2481  fNVirtualInfoLoc = 1;
2482  fVirtualInfoLoc = new ULong_t[1]; // To allow for a single delete statement.
2483  fVirtualInfoLoc[0] = offset;
2484  offset += sizeof(TStreamerInfo*);
2485  }
2486 
2487  // change order , move "bazes" to the end. Workaround old bug
2488  if ((fOldVersion <= 2) && nBaze) {
2489  SetBit(kRecovered);
2490  TObjArray& arr = *fElements;
2491  TObjArray tai(nBaze);
2492  int narr = arr.GetLast() + 1;
2493  int iel;
2494  int jel = 0;
2495  int kel = 0;
2496  for (iel = 0; iel < narr; ++iel) {
2497  element = (TStreamerElement*) arr[iel];
2498  if (element->IsBase() && (element->IsA() != TStreamerBase::Class())) {
2499  tai[kel++] = element;
2500  } else {
2501  arr[jel++] = element;
2502  }
2503  }
2504  for (kel = 0; jel < narr;) {
2505  arr[jel++] = tai[kel++];
2506  }
2507  }
2508 
2509  // Now add artificial TStreamerElement (i.e. rules that creates new members or set transient members).
2510  if (!wasCompiled) InsertArtificialElements(rules);
2511 
2512  if (!wasCompiled && allocClass) {
2513 
2514  TStreamerElement *el = new TStreamerArtificial("@@alloc","", 0, TStreamerInfo::kCacheNew, allocClass->GetName());
2515  R__TObjArray_InsertAt( fElements, el, 0 );
2516 
2517  el = new TStreamerArtificial("@@dealloc","", 0, TStreamerInfo::kCacheDelete, allocClass->GetName());
2518  fElements->Add( el );
2519  }
2520 
2521  Compile();
2522 }
2523 
2524 ////////////////////////////////////////////////////////////////////////////////
2525 /// If opt contains 'built', reset this StreamerInfo as if Build or BuildOld
2526 /// was never called on it (useful to force their re-running).
2527 
2529 {
2530  TString opt = option;
2531  opt.ToLower();
2532 
2533  if (opt.Contains("build")) {
2535 
2536  delete [] fComp; fComp = 0;
2537  delete [] fCompFull; fCompFull= 0;
2538  delete [] fCompOpt; fCompOpt = 0;
2539  fNdata = 0;
2540  fNfulldata = 0;
2541  fNslots= 0;
2542  fSize = 0;
2543  ResetIsCompiled();
2545 
2552  }
2553 }
2554 
2555 namespace {
2556  // TMemberInfo
2557  // Local helper class to be able to compare data member represented by
2558  // 2 distinct TStreamerInfos
2559  class TMemberInfo {
2560  public:
2561  TClass *fParent;
2562  TString fName;
2563  TString fClassName;
2564  TString fComment;
2565  Int_t fDataType;
2566 
2567  TMemberInfo(TClass *parent) : fParent(parent) {};
2568 
2569  void SetDataType(Int_t datatype) {
2570  fDataType = datatype;
2571  }
2572 
2573  void SetName(const char *name) {
2574  fName = name;
2575  }
2576  void SetClassName(const char *name) {
2578  }
2579  void SetComment(const char *title) {
2580  const char *left = strstr(title,"[");
2581  if (left) {
2582  const char *right = strstr(left,"]");
2583  if (right) {
2584  ++left;
2585  fComment.Append(left,right-left);
2586  }
2587  }
2588  }
2589  void Clear() {
2590  fName.Clear();
2591  fClassName.Clear();
2592  fComment.Clear();
2593  }
2594  /* Hide this not yet used implementation to suppress warnings message
2595  from icc 11
2596  Bool_t operator==(const TMemberInfo &other) {
2597  return fName==other.fName
2598  && fClassName == other.fClassName
2599  && fComment == other.fComment;
2600  }
2601  */
2602  Bool_t operator!=(const TMemberInfo &other) {
2603  if (fName != other.fName) return kTRUE;
2604  if (fDataType < TStreamerInfo::kObject) {
2605  // For simple type, let compare the data type
2606  if (fDataType != other.fDataType) {
2607  if ( (fDataType == 4 && other.fDataType == 16)
2608  || (fDataType == 16 && other.fDataType == 4) ) {
2609  // long and 'long long' have the same file format
2610  } else if ( (fDataType == 14 && other.fDataType == 17)
2611  || (fDataType == 17 && other.fDataType == 14) ) {
2612  // unsigned long and 'unsigned long long' have the same file format
2613  } else if ( (fDataType == 3 && other.fDataType == 6)
2614  ||(fDataType == 6 && other.fDataType == 3) ){
2615  // Int_t and kCounter. As the switch from Int_t (3) to
2616  // kCounter (6) might be triggered by a derived class using
2617  // the field as an array size, the class itself has no
2618  // control on what the field type really use.
2619  } else {
2620  return kTRUE;
2621  }
2622  }
2623  } else if (fClassName != other.fClassName) {
2624  if ( (fClassName == "long" && (other.fClassName == "long long" || other.fClassName == "Long64_t"))
2625  || ( (fClassName == "long long" || fClassName == "Long64_t") && other.fClassName == "long") ) {
2626  // This is okay both have the same on file format.
2627  } else if ( (fClassName == "unsigned long" && (other.fClassName == "unsigned long long" || other.fClassName == "ULong64_t"))
2628  || ( (fClassName == "unsigned long long" || fClassName == "ULong64_t") && other.fClassName == "unsigned long") ) {
2629  // This is okay both have the same on file format.
2630  } else if (TClassEdit::IsSTLCont(fClassName)) {
2632  TString othername = TClassEdit::ShortType( other.fClassName, TClassEdit::kDropStlDefault );
2633  if (name != othername) {
2634  TClass *cl = TClass::GetClass(name);
2635  TClass *otherCl = TClass::GetClass(othername);
2636  if (!CollectionMatch(cl,otherCl)) {
2637  TClass *oldFixedClass = FixCollectionV5(fParent,cl,otherCl);
2638  if (!oldFixedClass || !CollectionMatch(oldFixedClass,otherCl)) {
2639  return kTRUE;
2640  }
2641  }
2642  }
2643  } else {
2644  return kTRUE;
2645  }
2646  }
2647  return fComment != other.fComment;
2648  }
2649  };
2650 }
2651 
2652 ////////////////////////////////////////////////////////////////////////////////
2653 /// Emulated a call ShowMembers() on the obj of this class type, passing insp and parent.
2654 
2655 void TStreamerInfo::CallShowMembers(const void* obj, TMemberInspector &insp, Bool_t isTransient) const
2656 {
2657  TIter next(fElements);
2658  TStreamerElement* element = (TStreamerElement*) next();
2659 
2660  TString elementName;
2661 
2662  for (; element; element = (TStreamerElement*) next()) {
2663 
2664  // Skip elements which have not been allocated memory.
2665  if (element->GetOffset() == kMissing) {
2666  continue;
2667  }
2668 
2669  char* eaddr = ((char*)obj) + element->GetOffset();
2670 
2671  if (element->IsBase()) {
2672  // Nothing to do this round.
2673  } else if (element->IsaPointer()) {
2674  elementName.Form("*%s",element->GetFullName());
2675  insp.Inspect(fClass, insp.GetParent(), elementName.Data(), eaddr, isTransient);
2676  } else {
2677  insp.Inspect(fClass, insp.GetParent(), element->GetFullName(), eaddr, isTransient);
2678  Int_t etype = element->GetType();
2679  switch(etype) {
2680  case kObject:
2681  case kAny:
2682  case kTObject:
2683  case kTString:
2684  case kTNamed:
2685  case kSTL:
2686  {
2687  TClass *ecl = element->GetClassPointer();
2688  if (ecl && (fClass!=ecl /* This happens 'artificially for stl container see the use of "This" */)) {
2689  insp.InspectMember(ecl, eaddr, TString(element->GetName()) + ".", isTransient);
2690  }
2691  break;
2692  }
2693  } // switch(etype)
2694  } // if IsaPointer()
2695  } // Loop over elements
2696 
2697  // And now do the base classes
2698  next.Reset();
2699  element = (TStreamerElement*) next();
2700  for (; element; element = (TStreamerElement*) next()) {
2701  if (element->IsBase()) {
2702  // Skip elements which have not been allocated memory.
2703  if (element->GetOffset() == kMissing) {
2704  continue;
2705  }
2706 
2707  char* eaddr = ((char*)obj) + element->GetOffset();
2708 
2709  TClass *ecl = element->GetClassPointer();
2710  if (ecl) {
2711  ecl->CallShowMembers(eaddr, insp, isTransient);
2712  }
2713  } // If is a abse
2714  } // Loop over elements
2715 }
2716 
2717 ////////////////////////////////////////////////////////////////////////////////
2718 /// Make a clone of an object using the Streamer facility.
2719 /// If newname is specified, this will be the name of the new object.
2720 
2721 TObject *TStreamerInfo::Clone(const char *newname) const
2722 {
2723  TStreamerInfo *newinfo = (TStreamerInfo*)TNamed::Clone(newname);
2724  if (newname && newname[0] && fName != newname) {
2725  TObjArray *newelems = newinfo->GetElements();
2726  Int_t ndata = newelems->GetEntries();
2727  for(Int_t i = 0; i < ndata; ++i) {
2728  TObject *element = newelems->UncheckedAt(i);
2729  if (element->IsA() == TStreamerLoop::Class()) {
2730  TStreamerLoop *eloop = (TStreamerLoop*)element;
2731  if (fName == eloop->GetCountClass()) {
2732  eloop->SetCountClass(newname);
2733  eloop->Init();
2734  }
2735  } else if (element->IsA() == TStreamerBasicPointer::Class()) {
2736  TStreamerBasicPointer *eptr = (TStreamerBasicPointer*)element;
2737  if (fName == eptr->GetCountClass()) {
2738  eptr->SetCountClass(newname);
2739  eptr->Init();
2740  }
2741  }
2742  }
2743  }
2744  return newinfo;
2745 }
2746 
2747 ////////////////////////////////////////////////////////////////////////////////
2748 /// Return True if the current StreamerInfo in cl or info is equivalent to this TStreamerInfo.
2749 ///
2750 /// In this context 'Equivalent' means the same number of persistent data member which the same actual C++ type and
2751 /// the same name.
2752 /// If 'warn' is true, Warning message are printed to explicit the differences.
2753 /// If 'complete' is false, stop at the first error, otherwise continue until all members have been checked.
2754 
2756 {
2757  Bool_t result = kTRUE;
2758  R__ASSERT( (cl==0 || info==0) && (cl!=0 || info!=0) /* must compare to only one thing! */);
2759 
2760  TString name;
2761  TString type;
2762  TStreamerElement *el;
2763  TStreamerElement *infoel = 0;
2764 
2765  TIter next(GetElements());
2766  TIter infonext((TList*)0);
2767  TIter basenext((TList*)0);
2768  TIter membernext((TList*)0);
2769  if (info) {
2770  infonext = info->GetElements();
2771  }
2772  if (cl) {
2773  TList *tlb = cl->GetListOfBases();
2774  if (tlb) { // Loop over bases
2775  basenext = tlb;
2776  }
2777  tlb = cl->GetListOfDataMembers();
2778  if (tlb) {
2779  membernext = tlb;
2780  }
2781  }
2782 
2783  // First let's compare base classes
2784  Bool_t done = kFALSE;
2785  TString localClass;
2786  TString otherClass;
2787  while(!done) {
2788  localClass.Clear();
2789  otherClass.Clear();
2790  el = (TStreamerElement*)next();
2791  if (el && el->IsBase()) {
2792  localClass = el->GetName();
2793  } else {
2794  el = 0;
2795  }
2796  if (cl) {
2797  TBaseClass *tbc = (TBaseClass*)basenext();
2798  if (tbc) {
2799  otherClass = tbc->GetName();
2800  } else if (el==0) {
2801  done = kTRUE;
2802  break;
2803  }
2804  } else {
2805  infoel = (TStreamerElement*)infonext();
2806  if (infoel && infoel->IsBase()) {
2807  otherClass = infoel->GetName();
2808  } else if (el==0) {
2809  done = kTRUE;
2810  break;
2811  }
2812  }
2813  if (TClassEdit::IsSTLCont(localClass)) {
2814  localClass = TClassEdit::ShortType( localClass, TClassEdit::kDropStlDefault );
2815  otherClass = TClassEdit::ShortType( otherClass, TClassEdit::kDropStlDefault );
2816  }
2817  // Need to normalize the name
2818  if (localClass != otherClass) {
2819  if (warn) {
2820  if (el==0) {
2821  Warning("CompareContent",
2822  "The in-memory layout version %d for class '%s' has a base class (%s) that the on-file layout version %d does not have.",
2823  GetClassVersion(), GetName(), otherClass.Data(), GetClassVersion());
2824  } else if (otherClass.Length()==0) {
2825  Warning("CompareContent",
2826  "The on-file layout version %d for class '%s' has a base class (%s) that the in-memory layout version %d does not have",
2827  GetClassVersion(), GetName(), localClass.Data(), GetClassVersion());
2828  } else {
2829  Warning("CompareContent",
2830  "One base class of the on-file layout version %d and of the in memory layout version %d for '%s' is different: '%s' vs '%s'",
2831  GetClassVersion(), GetClassVersion(), GetName(), localClass.Data(), otherClass.Data());
2832  }
2833  }
2834  if (!complete) return kFALSE;
2835  result = result && kFALSE;
2836  }
2837  if (cl) {
2838  TStreamerBase *localBase = dynamic_cast<TStreamerBase*>(el);
2839  if (!localBase) continue;
2840  // We already have localBaseClass == otherBaseClass
2841  TClass *otherBaseClass = localBase->GetClassPointer();
2842  if (!otherBaseClass) continue;
2843  if (otherBaseClass->IsVersioned() && localBase->GetBaseVersion() != otherBaseClass->GetClassVersion()) {
2844  TString msg;
2845  msg.Form(" The StreamerInfo of class %s read from %s%s\n"
2846  " has the same version (=%d) as the active class but a different checksum.\n"
2847  " You should update the version to ClassDef(%s,%d).\n"
2848  " The objects on this file might not be readable because:\n"
2849  " The in-memory layout version %d for class '%s' has a base class (%s) with version %d but the on-file layout version %d recorded the version number %d for this base class (%s).",
2850  GetName(), file ? "file " : "", file ? file->GetName() : "", fClassVersion, GetName(), fClassVersion + 1,
2851  GetClassVersion(), GetName(), otherClass.Data(), otherBaseClass->GetClassVersion(),
2852  GetClassVersion(), localBase->GetBaseVersion(), localClass.Data());
2853  TStreamerBase *otherBase = (TStreamerBase*)cl->GetStreamerInfo()->GetElements()->FindObject(otherClass);
2854  otherBase->SetErrorMessage(msg);
2855 
2856  } else if (!otherBaseClass->IsVersioned() && localBase->GetBaseCheckSum() != otherBaseClass->GetCheckSum()) {
2857  TVirtualStreamerInfo *localBaseInfo = otherBaseClass->FindStreamerInfo(localBase->GetBaseCheckSum());
2858  if (!localBaseInfo) {
2859  // We are likely in the situation where the base class comes after the derived
2860  // class in the TFile's list of StreamerInfo, so it has not yet been loaded,
2861  // let's see if it is there.
2862  const TList *list = file->GetStreamerInfoCache();
2863  localBaseInfo = list ? (TStreamerInfo*)list->FindObject(localBase->GetName()) : 0;
2864  }
2865  if (!localBaseInfo) {
2866  TString msg;
2867  msg.Form(" The StreamerInfo of the base class %s (of class %s) read from %s%s\n"
2868  " refers to a checksum (%x) that can not be found neither in memory nor in the file.\n",
2869  otherBaseClass->GetName(), localClass.Data(),
2870  file ? "file " : "", file ? file->GetName() : "",
2871  localBase->GetBaseCheckSum()
2872  );
2873  TStreamerBase *otherBase = (TStreamerBase*)cl->GetStreamerInfo()->GetElements()->FindObject(otherClass);
2874  otherBase->SetErrorMessage(msg);
2875  continue;
2876  }
2877  if (localBaseInfo->CompareContent(otherBaseClass,0,kFALSE,kFALSE,file) ) {
2878  // They are equivalent, no problem.
2879  continue;
2880  }
2881  TString msg;
2882  msg.Form(" The StreamerInfo of class %s read from %s%s\n"
2883  " has the same version (=%d) as the active class but a different checksum.\n"
2884  " You should update the version to ClassDef(%s,%d).\n"
2885  " The objects on this file might not be readable because:\n"
2886  " The in-memory layout version %d for class '%s' has a base class (%s) with checksum %x but the on-file layout version %d recorded the checksum value %x for this base class (%s).",
2887  GetName(), file ? "file " : "", file ? file->GetName() : "", fClassVersion, GetName(), fClassVersion + 1,
2888  GetClassVersion(), GetName(), otherClass.Data(), otherBaseClass->GetCheckSum(),
2889  GetClassVersion(), localBase->GetBaseCheckSum(), localClass.Data());
2890  TStreamerBase *otherBase = (TStreamerBase*)cl->GetStreamerInfo()->GetElements()->FindObject(otherClass);
2891  otherBase->SetErrorMessage(msg);
2892  }
2893  } else {
2894  TStreamerBase *localBase = dynamic_cast<TStreamerBase*>(el);
2895  TStreamerBase *otherBase = dynamic_cast<TStreamerBase*>(infoel);
2896  if (!localBase || !otherBase) continue;
2897 
2898  // We already have localBaseClass == otherBaseClass
2899  TClass *otherBaseClass = localBase->GetClassPointer();
2900  if (otherBaseClass->IsVersioned() && localBase->GetBaseVersion() != otherBase->GetBaseVersion()) {
2901  TString msg;
2902  msg.Form(" The StreamerInfo of class %s read from %s%s\n"
2903  " has the same version (=%d) as the active class but a different checksum.\n"
2904  " You should update the version to ClassDef(%s,%d).\n"
2905  " The objects on this file might not be readable because:\n"
2906  " The in-memory layout version %d for class '%s' has a base class (%s) with version %d but the on-file layout version %d recorded the version number %d for this base class (%s).",
2907  GetName(), file ? "file " : "", file ? file->GetName() : "", fClassVersion, GetName(), fClassVersion + 1,
2908  GetClassVersion(), GetName(), otherClass.Data(), otherBase->GetBaseVersion(),
2909  GetClassVersion(), localBase->GetBaseVersion(), localClass.Data());
2910  otherBase->SetErrorMessage(msg);
2911 
2912  } else if (!otherBaseClass->IsVersioned() && localBase->GetBaseCheckSum() != otherBase->GetBaseCheckSum())
2913  {
2914  TVirtualStreamerInfo *localBaseInfo = otherBaseClass->FindStreamerInfo(localBase->GetBaseCheckSum());
2915  TVirtualStreamerInfo *otherBaseInfo = otherBaseClass->FindStreamerInfo(otherBase->GetBaseCheckSum());
2916  if (localBaseInfo == otherBaseInfo ||
2917  localBaseInfo->CompareContent(0,otherBaseInfo,kFALSE,kFALSE,file) ) {
2918  // They are equivalent, no problem.
2919  continue;
2920  }
2921  TString msg;
2922  msg.Form(" The StreamerInfo of class %s read from %s%s\n"
2923  " has the same version (=%d) as the active class but a different checksum.\n"
2924  " You should update the version to ClassDef(%s,%d).\n"
2925  " The objects on this file might not be readable because:\n"
2926  " The in-memory layout version %d for class '%s' has a base class (%s) with checksum %x but the on-file layout version %d recorded the checksum value %x for this base class (%s).",
2927  GetName(), file ? "file " : "", file ? file->GetName() : "", fClassVersion, GetName(), fClassVersion + 1,
2928  GetClassVersion(), GetName(), otherClass.Data(), otherBase->GetBaseCheckSum(),
2929  GetClassVersion(), localBase->GetBaseCheckSum(), localClass.Data());
2930  otherBase->SetErrorMessage(msg);
2931  }
2932  }
2933  }
2934  if (!result && !complete) {
2935  return result;
2936  }
2937  // Next the datamembers
2938  done = kFALSE;
2939  next.Reset();
2940  infonext.Reset();
2941 
2942  TMemberInfo local(GetClass());
2943  TMemberInfo other(cl ? cl : info->GetClass());
2944  UInt_t idx = 0;
2945  while(!done) {
2946  local.Clear();
2947  other.Clear();
2948  el = (TStreamerElement*)next();
2949  while (el && (el->IsBase() || el->IsA() == TStreamerArtificial::Class())) {
2950  el = (TStreamerElement*)next();
2951  ++idx;
2952  }
2953  if (el) {
2954  local.SetName( el->GetName() );
2955  local.SetClassName( el->GetTypeName() );
2956  local.SetComment( el->GetTitle() );
2957  local.SetDataType( el->GetType() );
2958  }
2959  if (cl) {
2960  TDataMember *tdm = (TDataMember*)membernext();
2961  while(tdm && ( (!tdm->IsPersistent()) || (tdm->Property()&kIsStatic) || (el && local.fName != tdm->GetName()) )) {
2962  tdm = (TDataMember*)membernext();
2963  }
2964  if (tdm) {
2965  other.SetName( tdm->GetName() );
2966  other.SetClassName( tdm->GetTrueTypeName() );
2967  other.SetComment( tdm->GetTitle() );
2968  if (tdm->GetDataType()) {
2969  // Need to update the type for arrays.
2970  if (tdm->IsaPointer()) {
2971  if (tdm->GetDataType()->GetType() == TVirtualStreamerInfo::kChar && !tdm->GetArrayDim() && tdm->GetArrayIndex()[0]==0) {
2972  other.SetDataType( TVirtualStreamerInfo::kCharStar );
2973  } else {
2974  other.SetDataType( tdm->GetDataType()->GetType() + TVirtualStreamerInfo::kOffsetP);
2975  }
2976  } else {
2977  if (tdm->GetArrayDim()) {
2978  other.SetDataType( tdm->GetDataType()->GetType() + TVirtualStreamerInfo::kOffsetL);
2979  } else {
2980  other.SetDataType( tdm->GetDataType()->GetType() );
2981  }
2982  }
2983  }
2984  } else if (el==0) {
2985  done = kTRUE;
2986  break;
2987  }
2988  } else {
2989  infoel = (TStreamerElement*)infonext();
2990  while (infoel && (infoel->IsBase() || infoel->IsA() == TStreamerArtificial::Class())) {
2991  infoel = (TStreamerElement*)infonext();
2992  }
2993  if (infoel) {
2994  other.SetName( infoel->GetName() );
2995  other.SetClassName( infoel->GetTypeName() );
2996  other.SetComment( infoel->GetTitle() );
2997  other.SetDataType( infoel->GetType() );
2998  } else if (el==0) {
2999  done = kTRUE;
3000  break;
3001  }
3002  }
3003  if (local!=other) {
3004  if (warn) {
3005  if (!el) {
3006  Warning("CompareContent","The following data member of\nthe in-memory layout version %d of class '%s' is missing from \nthe on-file layout version %d:\n"
3007  " %s %s; //%s"
3009  ,other.fClassName.Data(),other.fName.Data(),other.fComment.Data());
3010 
3011  } else if (other.fName.Length()==0) {
3012  Warning("CompareContent","The following data member of\nthe in-memory layout version %d of class '%s' is missing from \nthe on-file layout version %d:\n"
3013  " %s %s; //%s"
3015  ,local.fClassName.Data(),local.fName.Data(),local.fComment.Data());
3016  } else {
3017  Warning("CompareContent","The following data member of\nthe on-file layout version %d of class '%s' differs from \nthe in-memory layout version %d:\n"
3018  " %s %s; //%s\n"
3019  "vs\n"
3020  " %s %s; //%s"
3022  ,local.fClassName.Data(),local.fName.Data(),local.fComment.Data()
3023  ,other.fClassName.Data(),other.fName.Data(),other.fComment.Data());
3024  }
3025  }
3026  result = result && kFALSE;
3027  if (!complete) return result;
3028  }
3029  ++idx;
3030  }
3031  return result;
3032 }
3033 
3034 
3035 ////////////////////////////////////////////////////////////////////////////////
3036 /// Compute total size of all persistent elements of the class
3037 
3039 {
3041  //faster and more precise to use last element offset +size
3042  //on 64 bit machines, offset may be forced to be a multiple of 8 bytes
3043  fSize = element ? element->GetOffset() + element->GetSize() : 0;
3044  if (fNVirtualInfoLoc > 0 && (fVirtualInfoLoc[0]+sizeof(TStreamerInfo*)) >= (ULong_t)fSize) {
3045  fSize = fVirtualInfoLoc[0] + sizeof(TStreamerInfo*);
3046  }
3047 
3048  // On some platform and in some case of layout non-basic data types needs
3049  // to be aligned. So let's be on the safe side and align on the size of
3050  // the pointers. (Question: is that the right thing on x32 ABI ?)
3051  constexpr size_t kSizeOfPtr = sizeof(void*);
3052  if ((fSize % kSizeOfPtr) != 0) {
3053  fSize = fSize - (fSize % kSizeOfPtr) + kSizeOfPtr;
3054  }
3055 }
3056 
3057 ////////////////////////////////////////////////////////////////////////////////
3058 /// Recursively mark streamer infos for writing to a file.
3059 ///
3060 /// Will force this TStreamerInfo to the file and also
3061 /// all the dependencies.
3062 /// If argument force > 0 the loop on class dependencies is forced.
3063 /// This function is called when streaming a class that contains
3064 /// a null pointer. In this case, the TStreamerInfo for the class
3065 /// with the null pointer must be written to the file and also all
3066 /// the TStreamerInfo of all the classes referenced by the class.
3067 /// We must be given a file to write to.
3068 
3070 {
3071  if (!file) {
3072  return;
3073  }
3074  // Get the given file's list of streamer infos marked for writing.
3075  TArrayC* cindex = file->GetClassIndex();
3076  //the test below testing fArray[fNumber]>1 is to avoid a recursivity
3077  //problem in some cases like:
3078  // class aProblemChild: public TNamed {
3079  // aProblemChild *canBeNull;
3080  // };
3081  if ( // -- Done if already marked, and we are not forcing, or forcing is blocked.
3082  (cindex->fArray[fNumber] && !force) || // Streamer info is already marked, and not forcing, or
3083  (cindex->fArray[fNumber] > 1) // == 2 means ignore forcing to prevent infinite recursion.
3084  ) {
3085  return;
3086  }
3087  // We do not want to write streamer info to the file
3088  // for std::string.
3089  static TClassRef string_classref("string");
3090  if (fClass == string_classref) { // We are std::string.
3091  return;
3092  }
3093  // We do not want to write streamer info to the file
3094  // for STL containers.
3095  if (fClass==0) {
3096  // Build or BuildCheck has not been called yet.
3097  // Let's use another means of checking.
3098  if (fElements && fElements->GetEntries()==1 && strcmp("This",fElements->UncheckedAt(0)->GetName())==0) {
3099  // We are an STL collection.
3100  return;
3101  }
3102  } else if (fClass->GetCollectionProxy()) { // We are an STL collection.
3103  return;
3104  }
3105  // Mark ourselves for output, and block
3106  // forcing to prevent infinite recursion.
3107  cindex->fArray[fNumber] = 2;
3108  // Signal the file that the marked streamer info list has changed.
3109  cindex->fArray[0] = 1;
3110  // Recursively mark the streamer infos for
3111  // all of our elements.
3112  TIter next(fElements);
3113  TStreamerElement* element = (TStreamerElement*) next();
3114  for (; element; element = (TStreamerElement*) next()) {
3115  if (element->IsTransient()) continue;
3116  TClass* cl = element->GetClassPointer();
3117  if (cl) {
3118  TVirtualStreamerInfo* si = 0;
3119  if (cl->Property() & kIsAbstract) {
3120  // If the class of the element is abstract, register the
3121  // TStreamerInfo only if it has already been built.
3122  // Otherwise call cl->GetStreamerInfo() would generate an
3123  // incorrect StreamerInfo.
3124  si = cl->GetCurrentStreamerInfo();
3125  } else {
3126  si = cl->GetStreamerInfo();
3127  }
3128  if (si) {
3129  si->ForceWriteInfo(file, force);
3130  }
3131  }
3132  }
3133 }
3134 
3135 ////////////////////////////////////////////////////////////////////////////////
3136 /// Assuming that obj points to (the part of) an object that is of the
3137 /// type described by this streamerInfo, return the actual type of the
3138 /// object (i.e. the type described by this streamerInfo is a base class
3139 /// of the actual type of the object.
3140 /// This routine should only be called if the class described by this
3141 /// StreamerInfo is 'emulated'.
3142 
3143 TClass *TStreamerInfo::GetActualClass(const void *obj) const
3144 {
3145  R__ASSERT(!fClass->IsLoaded());
3146 
3147  if (fNVirtualInfoLoc != 0) {
3148  TStreamerInfo *allocator = *(TStreamerInfo**)( (const char*)obj + fVirtualInfoLoc[0] );
3149  if (allocator) return allocator->GetClass();
3150  }
3151  return (TClass*)fClass;
3152 }
3153 
3154 ////////////////////////////////////////////////////////////////////////////////
3155 /// Return true if the checksum passed as argument is one of the checksum
3156 /// value produced by the older checksum calculation algorithm.
3157 
3159 {
3160  for(UInt_t i = 1; i < TClass::kLatestCheckSum; ++i) {
3161  if ( checksum == GetCheckSum( (TClass::ECheckSum) i) ) return kTRUE;
3162  }
3163  return kFALSE;
3164 }
3165 
3166 ////////////////////////////////////////////////////////////////////////////////
3167 /// Recalculate the checksum of this TStreamerInfo based on its code.
3168 ///
3169 /// The class ckecksum is used by the automatic schema evolution algorithm
3170 /// to uniquely identify a class version.
3171 /// The check sum is built from the names/types of base classes and
3172 /// data members.
3173 /// The valid range of code is determined by ECheckSum.
3174 /// - kNoEnum: data members of type enum are not counted in the checksum
3175 /// - kNoRange: return the checksum of data members and base classes, not including the ranges and array size found in comments.
3176 /// - kWithTypeDef: use the sugared type name in the calculation.
3177 ///
3178 /// This is needed for backward compatibility.
3179 /// ### WARNING
3180 /// This function must be kept in sync with TClass::GetCheckSum.
3181 /// They are both used to handle backward compatibility and should both return the same values.
3182 /// TStreamerInfo uses the information in TStreamerElement while TClass uses the information
3183 /// from TClass::GetListOfBases and TClass::GetListOfDataMembers.
3184 /// Original algorithm from Victor Perevovchikov (perev@bnl.gov).
3185 
3187 {
3188  // kCurrentCheckSum (0) should be kept for backward compatibility, to be
3189  // able to use the inequality checks, we need to set the code to the largest
3190  // value.
3192 
3193  UInt_t id = 0;
3194 
3195  int il;
3196  TString name = GetName();
3197  TString type;
3198  il = name.Length();
3199  for (int i=0; i<il; i++) id = id*3+name[i];
3200 
3201  TIter next(GetElements());
3202  TStreamerElement *el;
3203  while ( (el=(TStreamerElement*)next()) && !fClass->GetCollectionProxy()) { // loop over bases if not a proxied collection
3204  if (el->IsBase()) {
3205  name = el->GetName();
3206  il = name.Length();
3207  for (int i=0; i<il; i++) id = id*3+name[i];
3208  if (code > TClass::kNoBaseCheckSum && el->IsA() == TStreamerBase::Class()) {
3209  TStreamerBase *base = (TStreamerBase*)el;
3210  id = id*3 + base->GetBaseCheckSum();
3211  }
3212  }
3213  } /* End of Base Loop */
3214 
3215  next.Reset();
3216  while ( (el=(TStreamerElement*)next()) ) {
3217  if (el->IsBase()) continue;
3218 
3219  // humm can we tell if a TStreamerElement is an enum?
3220  // Maybe something like:
3221  Bool_t isenum = kFALSE;
3222  if ( el->GetType()==3 && gROOT->GetType(el->GetTypeName())==0) {
3223  // If the type is not an enum but a typedef to int then
3224  // el->GetTypeName() should be return 'int'
3225  isenum = kTRUE;
3226  }
3227  if ( (code > TClass::kNoEnum) && isenum) id = id*3 + 1;
3228 
3229  name = el->GetName(); il = name.Length();
3230 
3231  int i;
3232  for (i=0; i<il; i++) id = id*3+name[i];
3233 
3234  if (code == TClass::kReflex || code == TClass::kReflexNoComment) {
3235  // With TClass::kReflexV5 we do not want the Long64 in the name
3236  // nor any typedef.
3238 
3239  } else if (code <= TClass::kWithTypeDef) {
3240  // humm ... In the streamerInfo we only have the desugared/normalized
3241  // names, so we are unable to calculate the name with typedefs ...
3242  // except for the case of the ROOT typedef (Int_t, etc.) which are
3243  // kept by TClassEdit::ResolveTypedef(typeName) but not by TCling's
3244  // normalization ...
3245  //
3246  type = el->GetTypeName();
3247  } else {
3249  }
3250  if (TClassEdit::IsSTLCont(type)) {
3252  }
3253  if (code == TClass::kReflex || code == TClass::kReflexNoComment) {
3254  type.ReplaceAll("ULong64_t","unsigned long long");
3255  type.ReplaceAll("Long64_t","long long");
3256  type.ReplaceAll("signed char","char");
3257  type.ReplaceAll("<signed char","<char");
3258  type.ReplaceAll(",signed char",",char");
3259  if (type=="signed char") type = "char";
3260  }
3261 
3262  il = type.Length();
3263  for (i=0; i<il; i++) id = id*3+type[i];
3264 
3265  int dim = el->GetArrayDim();
3266  if (dim) {
3267  for (i=0;i<dim;i++) id = id*3+el->GetMaxIndex(i);
3268  }
3269 
3270 
3271  if (code > TClass::kNoRange) {
3272  const char *left;
3273  if (code > TClass::kNoRangeCheck)
3275  else
3276  left = strstr(el->GetTitle(),"[");
3277  if (left) {
3278  const char *right = strstr(left,"]");
3279  if (right) {
3280  ++left;
3281  while (left != right) {
3282  id = id*3 + *left;
3283  ++left;
3284  }
3285  }
3286  }
3287  }
3288  }
3289  return id;
3290 }
3291 
3292 ////////////////////////////////////////////////////////////////////////////////
3293 
3294 static void R__WriteConstructorBody(FILE *file, TIter &next)
3295 {
3296  TStreamerElement *element = 0;
3297  next.Reset();
3298  while ((element = (TStreamerElement*)next())) {
3303  if(element->GetArrayLength() <= 1) {
3304  fprintf(file," %s = 0;\n",element->GetName());
3305  } else {
3306  fprintf(file," memset(%s,0,%d);\n",element->GetName(),element->GetSize());
3307  }
3308  }
3309  if (TVirtualStreamerInfo::kOffsetP <= element->GetType() && element->GetType() < TVirtualStreamerInfo::kObject ) {
3310  fprintf(file," %s = 0;\n",element->GetName());
3311  }
3312  }
3313 }
3314 
3315 ////////////////////////////////////////////////////////////////////////////////
3316 /// Write down the body of the 'move' constructor.
3317 
3318 static void R__WriteMoveConstructorBody(FILE *file, const TString &protoname, TIter &next)
3319 {
3320  TStreamerElement *element = 0;
3321  next.Reset();
3322  Bool_t atstart = kTRUE;
3323  while ((element = (TStreamerElement*)next())) {
3324  if (element->IsBase()) {
3325  if (atstart) { fprintf(file," : "); atstart = kFALSE; }
3326  else fprintf(file," , ");
3327  fprintf(file, "%s(const_cast<%s &>( rhs ))\n", element->GetName(),protoname.Data());
3328  } else {
3329  if (element->GetArrayLength() <= 1) {
3330  if (atstart) { fprintf(file," : "); atstart = kFALSE; }
3331  else fprintf(file," , ");
3332  fprintf(file, "%s(const_cast<%s &>( rhs ).%s)\n",element->GetName(),protoname.Data(),element->GetName());
3333  }
3334  }
3335  }
3336  fprintf(file,"{\n");
3337  fprintf(file," // This is NOT a copy constructor. This is actually a move constructor (for stl container's sake).\n");
3338  fprintf(file," // Use at your own risk!\n");
3339  fprintf(file," (void)rhs; // avoid warning about unused parameter\n");
3340  next.Reset();
3341  Bool_t defMod = kFALSE;
3342  while ((element = (TStreamerElement*)next())) {
3345  || element->GetType() == TVirtualStreamerInfo::kAnyPnoVT)
3346  {
3347  if (!defMod) { fprintf(file," %s &modrhs = const_cast<%s &>( rhs );\n",protoname.Data(),protoname.Data()); defMod = kTRUE; };
3348  const char *ename = element->GetName();
3349  const char *colon2 = strstr(ename,"::");
3350  if (colon2) ename = colon2+2;
3351  if(element->GetArrayLength() <= 1) {
3352  fprintf(file," modrhs.%s = 0;\n",ename);
3353  } else {
3354  fprintf(file," memset(modrhs.%s,0,%d);\n",ename,element->GetSize());
3355  }
3356  } else {
3357  const char *ename = element->GetName();
3358  if (element->GetType() == kCharStar) {
3359  if (!defMod) {
3360  fprintf(file," %s &modrhs = const_cast<%s &>( rhs );\n",protoname.Data(),protoname.Data()); defMod = kTRUE;
3361  };
3362  fprintf(file," modrhs.%s = 0;\n",ename);
3363  } else if (TVirtualStreamerInfo::kOffsetP <= element->GetType() && element->GetType() < TVirtualStreamerInfo::kObject ) {
3364  if (!defMod) {
3365  fprintf(file," %s &modrhs = const_cast<%s &>( rhs );\n",protoname.Data(),protoname.Data()); defMod = kTRUE;
3366  };
3367  fprintf(file," modrhs.%s = 0;\n",ename);
3368  } else if (element->GetArrayLength() > 1) {
3369  // FIXME: Need to add support for variable length array.
3370  if (element->GetArrayDim() == 1) {
3371  fprintf(file," for (Int_t i=0;i<%d;i++) %s[i] = rhs.%s[i];\n",element->GetArrayLength(),ename,ename);
3372  } else if (element->GetArrayDim() >= 2) {
3373  fprintf(file," for (Int_t i=0;i<%d;i++) (&(%s",element->GetArrayLength(),ename);
3374  for (Int_t d = 0; d < element->GetArrayDim(); ++d) {
3375  fprintf(file,"[0]");
3376  }
3377  fprintf(file,"))[i] = (&(rhs.%s",ename);
3378  for (Int_t d = 0; d < element->GetArrayDim(); ++d) {
3379  fprintf(file,"[0]");
3380  }
3381  fprintf(file,"))[i];\n");
3382  }
3383  } else if (element->GetType() == TVirtualStreamerInfo::kSTLp) {
3384  if (!defMod) { fprintf(file," %s &modrhs = const_cast<%s &>( rhs );\n",protoname.Data(),protoname.Data()); defMod = kTRUE; };
3385  fprintf(file," modrhs.%s = 0;\n",ename);
3386  } else if (element->GetType() == TVirtualStreamerInfo::kSTL) {
3387  if (!defMod) {
3388  fprintf(file," %s &modrhs = const_cast<%s &>( rhs );\n",protoname.Data(),protoname.Data()); defMod = kTRUE;
3389  }
3390  TClass *cle = element->GetClassPointer();
3391  TVirtualCollectionProxy *proxy = cle ? element->GetClassPointer()->GetCollectionProxy() : 0;
3392  std::string method_name = "clear";
3393  if (!element->TestBit(TStreamerElement::kDoNotDelete) && proxy && (((TStreamerSTL*)element)->GetSTLtype() == ROOT::kSTLbitset)) {
3394  method_name = "reset";
3395  }
3396  if (element->IsBase()) {
3397  fprintf(file," modrhs.%s();\n", method_name.c_str());
3398  } else {
3399  fprintf(file," modrhs.%s.%s();\n",ename, method_name.c_str());
3400  }
3401  }
3402  }
3403  }
3404 }
3405 
3406 ////////////////////////////////////////////////////////////////////////////////
3407 
3408 static void R__WriteDestructorBody(FILE *file, TIter &next)
3409 {
3410  TStreamerElement *element = 0;
3411  next.Reset();
3412  while ((element = (TStreamerElement*)next())) {
3415  || element->GetType() == TVirtualStreamerInfo::kAnyPnoVT)
3416  {
3417  const char *ename = element->GetName();
3418  const char *colon2 = strstr(ename,"::");
3419  if (colon2) ename = colon2+2;
3420  if (element->TestBit(TStreamerElement::kDoNotDelete)) {
3421  if(element->GetArrayLength() <= 1) {
3422  fprintf(file," %s = 0;\n",ename);
3423  } else {
3424  fprintf(file," memset(%s,0,%d);\n",ename,element->GetSize());
3425  }
3426  } else {
3427  if(element->GetArrayLength() <= 1) {
3428  fprintf(file," delete %s; %s = 0;\n",ename,ename);
3429  } else {
3430  fprintf(file," for (Int_t i=0;i<%d;i++) delete %s[i]; memset(%s,0,%d);\n",element->GetArrayLength(),ename,ename,element->GetSize());
3431  }
3432  }
3433  }
3434  if (element->GetType() == TVirtualStreamerInfo::kCharStar) {
3435  const char *ename = element->GetName();
3436  if (element->TestBit(TStreamerElement::kDoNotDelete)) {
3437  fprintf(file," %s = 0;\n",ename);
3438  } else {
3439  fprintf(file," delete [] %s; %s = 0;\n",ename,ename);
3440  }
3441  }
3442  if (TVirtualStreamerInfo::kOffsetP <= element->GetType() && element->GetType() < TVirtualStreamerInfo::kObject ) {
3443  const char *ename = element->GetName();
3444  if (element->TestBit(TStreamerElement::kDoNotDelete)) {
3445  fprintf(file," %s = 0;\n",ename);
3446  } else if (element->HasCounter()) {
3447  fprintf(file," delete %s; %s = 0;\n",ename,ename);
3448  } else {
3449  fprintf(file," delete [] %s; %s = 0;\n",ename,ename);
3450  }
3451  }
3452  if (element->GetType() == TVirtualStreamerInfo::kSTL || element->GetType() == TVirtualStreamerInfo::kSTLp) {
3453  const char *ename = element->GetName();
3454  const char *prefix = "";
3455  if ( element->GetType() == TVirtualStreamerInfo::kSTLp ) {
3456  prefix = "*";
3457  } else if ( element->IsBase() ) {
3458  ename = "this";
3459  }
3460  TClass *cle = element->GetClassPointer();
3461  TVirtualCollectionProxy *proxy = cle ? element->GetClassPointer()->GetCollectionProxy() : 0;
3462  if (!element->TestBit(TStreamerElement::kDoNotDelete) && proxy) {
3463  Int_t stltype = ((TStreamerSTL*)element)->GetSTLtype();
3464 
3465  if (proxy->HasPointers()) {
3466  fprintf(file," std::for_each( (%s %s).rbegin(), (%s %s).rend(), DeleteObjectFunctor() );\n",prefix,ename,prefix,ename);
3467  //fprintf(file," %s::iterator iter;\n");
3468  //fprintf(file," %s::iterator begin = (%s %s).begin();\n");
3469  //fprintf(file," %s::iterator end (%s %s).end();\n");
3470  //fprintf(file," for( iter = begin; iter != end; ++iter) { delete *iter; }\n");
3471  } else {
3472  if (stltype == ROOT::kSTLmap || stltype == ROOT::kSTLmultimap) {
3474  std::vector<std::string> inside;
3475  int nestedLoc;
3476  TClassEdit::GetSplit(enamebasic, inside, nestedLoc, TClassEdit::kLong64);
3477  if (inside[1][inside[1].size()-1]=='*' || inside[2][inside[2].size()-1]=='*') {
3478  fprintf(file," std::for_each( (%s %s).rbegin(), (%s %s).rend(), DeleteObjectFunctor() );\n",prefix,ename,prefix,ename);
3479  }
3480  }
3481  }
3482  }
3483  if ( prefix[0] ) {
3484  fprintf(file," delete %s; %s = 0;\n",ename,ename);
3485  }
3486  }
3487  }
3488 }
3489 
3490 ////////////////////////////////////////////////////////////////////////////////
3491 /// Write the Declaration of class.
3492 
3493 void TStreamerInfo::GenerateDeclaration(FILE *fp, FILE *sfp, const TList *subClasses, Bool_t top)
3494 {
3495  if (fClassVersion == -3) {
3496  return;
3497  }
3498 
3499  Bool_t needGenericTemplate = fElements==0 || fElements->GetEntries() == 0;
3500  Bool_t isTemplate = kFALSE;
3501  const char *clname = GetName();
3502  TString template_protoname;
3503  if (strchr(clname, ':')) {
3504  // We might have a namespace in front of the classname.
3505  Int_t len = strlen(clname);
3506  const char *name = clname;
3507  UInt_t nest = 0;
3508  UInt_t pr_pos = 0;
3509  for (Int_t cur = 0; cur < len; ++cur) {
3510  switch (clname[cur]) {
3511  case '<':
3512  ++nest;
3513  pr_pos = cur;
3514  isTemplate = kTRUE;
3515  break;
3516  case '>':
3517  if (nest == 0) { cur = len; continue; } // the name is not well formed, give up.
3518  --nest;
3519  break;
3520  case ':': {
3521  if (nest == 0 && clname[cur+1] == ':') {
3522  // We have a scope
3523  isTemplate = kFALSE;
3524  name = clname + cur + 2;
3525  }
3526  break;
3527  }
3528  }
3529  }
3530  if (isTemplate) {
3531  template_protoname.Append(clname,pr_pos);
3532  }
3533  clname = name;
3534  } else {
3535  const char *where = strstr(clname, "<");
3536  isTemplate = where != 0;
3537  if (isTemplate) {
3538  template_protoname.Append(clname,where-clname);
3539  }
3540  }
3541 
3542  if (needGenericTemplate && isTemplate) {
3543  TString templateName(TMakeProject::GetHeaderName("template "+template_protoname,0));
3544  fprintf(fp, "#ifndef %s_h\n", templateName.Data());
3545  fprintf(fp, "#define %s_h\n", templateName.Data());
3546  }
3547 
3548  TString protoname;
3549  UInt_t numberOfNamespaces = TMakeProject::GenerateClassPrefix(fp, GetName(), top, protoname, 0, kFALSE, needGenericTemplate);
3550 
3551  // Generate class statement with base classes.
3552  TStreamerElement *element;
3553  TIter next(fElements);
3554  Int_t nbase = 0;
3555  while ((element = (TStreamerElement*)next())) {
3556  if (!element->IsBase()) continue;
3557  nbase++;
3558  const char *ename = element->GetName();
3559  if (nbase == 1) fprintf(fp," : public %s",ename);
3560  else fprintf(fp," , public %s",ename);
3561  }
3562  fprintf(fp," {\n");
3563 
3564  // Generate forward declaration nested classes.
3565  if (subClasses && subClasses->GetEntries()) {
3566  Bool_t needheader = true;
3567 
3568  TIter subnext(subClasses);
3569  TStreamerInfo *subinfo;
3570  Int_t len = strlen(GetName());
3571  while ((subinfo = (TStreamerInfo*)subnext())) {
3572  if (strncmp(GetName(),subinfo->GetName(),len)==0 && (subinfo->GetName()[len]==':') ) {
3573  if (subinfo->GetName()[len+1]==':' && strstr(subinfo->GetName()+len+2,":")==0) {
3574  if (needheader) {
3575  fprintf(fp,"\npublic:\n");
3576  fprintf(fp,"// Nested classes forward declaration.\n");
3577  needheader = false;
3578  }
3579  TString sub_protoname;
3580  UInt_t sub_numberOfClasses = 0;
3581  UInt_t sub_numberOfNamespaces;
3582  if (subinfo->GetClassVersion() == -3) {
3583  sub_numberOfNamespaces = TMakeProject::GenerateClassPrefix(fp, subinfo->GetName() + len+2, kFALSE, sub_protoname, &sub_numberOfClasses, 3);
3584  } else {
3585  sub_numberOfNamespaces = TMakeProject::GenerateClassPrefix(fp, subinfo->GetName() + len+2, kFALSE, sub_protoname, &sub_numberOfClasses, kFALSE);
3586  fprintf(fp, ";\n");
3587  }
3588 
3589  for (UInt_t i = 0;i < sub_numberOfClasses;++i) {
3590  fprintf(fp, "}; // end of class.\n");
3591  }
3592  if (sub_numberOfNamespaces > 0) {
3593  Error("GenerateDeclaration","Nested classes %s thought to be inside a namespace inside the class %s",subinfo->GetName(),GetName());
3594  }
3595  }
3596  }
3597  }
3598  }
3599 
3600  fprintf(fp,"\npublic:\n");
3601  fprintf(fp,"// Nested classes declaration.\n");
3602 
3603  // Generate nested classes.
3604  if (subClasses && subClasses->GetEntries()) {
3605  TIter subnext(subClasses,kIterBackward);
3606  TStreamerInfo *subinfo;
3607  Int_t len = strlen(GetName());
3608  while ((subinfo = (TStreamerInfo*)subnext())) {
3609  if (strncmp(GetName(),subinfo->GetName(),len)==0 && (subinfo->GetName()[len]==':')) {
3610  if (subinfo->GetName()[len+1]==':' && strstr(subinfo->GetName()+len+2,":")==0) {
3611  subinfo->GenerateDeclaration(fp, sfp, subClasses, kFALSE);
3612  }
3613  }
3614  }
3615  }
3616 
3617  fprintf(fp,"\npublic:\n");
3618  fprintf(fp,"// Data Members.\n");
3619 
3620  {
3621  // Generate data members.
3622  TString name(128);
3623  Int_t ltype = 12;
3624  Int_t ldata = 10;
3625  Int_t lt,ld,is;
3626  TString line;
3627  line.Resize(kMaxLen);
3628  next.Reset();
3629  while ((element = (TStreamerElement*)next())) {
3630 
3631  if (element->IsBase()) continue;
3632  const char *ename = element->GetName();
3633 
3634  name = ename;
3635  for (Int_t i=0;i < element->GetArrayDim();i++) {
3636  name += TString::Format("[%d]",element->GetMaxIndex(i));
3637  }
3638  name += ";";
3639  ld = name.Length();
3640 
3641  TString enamebasic = element->GetTypeNameBasic();
3642  if (element->IsA() == TStreamerSTL::Class()) {
3643  // If we have a map, multimap, set or multiset,
3644  // and the key is a class, we need to replace the
3645  // container by a vector since we don't have the
3646  // comparator function.
3647  Int_t stltype = ((TStreamerSTL*)element)->GetSTLtype();
3648  switch (stltype) {
3649  case ROOT::kSTLmap:
3650  case ROOT::kSTLmultimap:
3651  case ROOT::kSTLset:
3652  case ROOT::kSTLmultiset:
3655  {
3656  enamebasic = TMakeProject::UpdateAssociativeToVector(enamebasic);
3657  }
3658  default:
3659  // nothing to do.
3660  break;
3661  }
3662  }
3663 
3664  lt = enamebasic.Length();
3665 
3666  line = " ";
3667  line += enamebasic;
3668  if (lt>=ltype) ltype = lt+1;
3669 
3670  for (is = 3+lt; is < (3+ltype); ++is) line += ' ';
3671 
3672  line += name;
3673  if (element->IsaPointer() && !strchr(line,'*')) line[2+ltype] = '*';
3674 
3675  if (ld>=ldata) ldata = ld+1;
3676  for (is = 3+ltype+ld; is < (3+ltype+ldata); ++is) line += ' ';
3677 
3678  line += " //";
3679  line += element->GetTitle();
3680  fprintf(fp,"%s\n",line.Data());
3681  }
3682  }
3683  if (needGenericTemplate && isTemplate) {
3684  // Generate default functions, ClassDef and trailer.
3685  fprintf(fp,"\n %s() {\n",protoname.Data());
3686  R__WriteConstructorBody(fp,next);
3687  fprintf(fp," }\n");
3688  fprintf(fp," %s(const %s & rhs )\n",protoname.Data(),protoname.Data());
3689  R__WriteMoveConstructorBody(fp,protoname,next);
3690  fprintf(fp," }\n");
3691  fprintf(fp," virtual ~%s() {\n",protoname.Data());
3692  R__WriteDestructorBody(fp,next);
3693  fprintf(fp," }\n\n");
3694 
3695  } else {
3696  // Generate default functions, ClassDef and trailer.
3697  fprintf(fp,"\n %s();\n",protoname.Data());
3698  fprintf(fp," %s(const %s & );\n",protoname.Data(),protoname.Data());
3699  fprintf(fp," virtual ~%s();\n\n",protoname.Data());
3700 
3701  // Add the implementations to the source.cxx file.
3703  fprintf(sfp,"#ifndef %s_cxx\n",guard.Data());
3704  fprintf(sfp,"#define %s_cxx\n",guard.Data());
3705  fprintf(sfp,"%s::%s() {\n",GetName(),protoname.Data());
3706  R__WriteConstructorBody(sfp,next);
3707  fprintf(sfp,"}\n");
3708 
3709  fprintf(sfp,"%s::%s(const %s & rhs)\n",GetName(),protoname.Data(),protoname.Data());
3710  R__WriteMoveConstructorBody(sfp,protoname,next);
3711  fprintf(sfp,"}\n");
3712 
3713  fprintf(sfp,"%s::~%s() {\n",GetName(),protoname.Data());
3714  R__WriteDestructorBody(sfp,next);
3715  fprintf(sfp,"}\n");
3716  fprintf(sfp,"#endif // %s_cxx\n\n",guard.Data());
3717  }
3718 
3719  TClass *cl = gROOT->GetClass(GetName());
3720  if (fClassVersion > 1 || (cl && cl->IsTObject()) ) {
3721  // add 1 to class version in case we didn't manage reproduce the class layout to 100%.
3722  if (fClassVersion == 0) {
3723  // If the class was declared 'transient', keep it that way.
3724  fprintf(fp," ClassDef(%s,%d); // Generated by MakeProject.\n",protoname.Data(),0);
3725  } else {
3726  fprintf(fp," ClassDef(%s,%d); // Generated by MakeProject.\n",protoname.Data(),fClassVersion + 1);
3727  }
3728  }
3729  fprintf(fp,"};\n");
3730 
3731  for(UInt_t i=0;i<numberOfNamespaces;++i) {
3732  fprintf(fp,"} // namespace\n");
3733  }
3734 
3735  if (needGenericTemplate && isTemplate) {
3736  fprintf(fp,"#endif // generic template declaration\n");
3737  }
3738 }
3739 
3740 ////////////////////////////////////////////////////////////////////////////////
3741 /// Add to the header file, the \#include need for this class.
3742 
3743 UInt_t TStreamerInfo::GenerateIncludes(FILE *fp, char *inclist, const TList *extrainfos)
3744 {
3745  if (inclist[0]==0) {
3746  // Always have this include for ClassDef.
3747  TMakeProject::AddInclude( fp, "Rtypes.h", kFALSE, inclist);
3748  }
3749  UInt_t ninc = 0;
3750 
3751  const char *clname = GetName();
3752  if (strchr(clname,'<')) {
3753  // This is a template, we need to check the template parameter.
3754  ninc += TMakeProject::GenerateIncludeForTemplate(fp, clname, inclist, kFALSE, extrainfos);
3755  }
3756 
3757  TString name(1024);
3758  Int_t ltype = 10;
3759  Int_t ldata = 10;
3760  Int_t lt;
3761  Int_t ld;
3762  TIter next(fElements);
3763  TStreamerElement *element;
3764  Bool_t incRiostream = kFALSE;
3765  while ((element = (TStreamerElement*)next())) {
3766  //if (element->IsA() == TStreamerBase::Class()) continue;
3767  const char *ename = element->GetName();
3768  const char *colon2 = strstr(ename,"::");
3769  if (colon2) ename = colon2+2;
3770  name = ename;
3771  for (Int_t i=0;i < element->GetArrayDim();i++) {
3772  name += TString::Format("[%d]",element->GetMaxIndex(i));
3773  }
3774  ld = name.Length();
3775  lt = strlen(element->GetTypeName());
3776  if (ltype < lt) ltype = lt;
3777  if (ldata < ld) ldata = ld;
3778 
3779  //must include Riostream.h in case of an STL container
3780  if (!incRiostream && element->InheritsFrom(TStreamerSTL::Class())) {
3781  incRiostream = kTRUE;
3782  TMakeProject::AddInclude( fp, "Riostream.h", kFALSE, inclist);
3783  }
3784 
3785  //get include file name if any
3786  const char *include = element->GetInclude();
3787  if (!include[0]) continue;
3788 
3789  Bool_t greater = (include[0]=='<');
3790  include++;
3791 
3792  if (strncmp(include,"include/",8)==0) {
3793  include += 8;
3794  }
3795  if (strncmp(include,"include\\",9)==0) {
3796  include += 9;
3797  }
3798  if (strncmp(element->GetTypeName(),"pair<",strlen("pair<"))==0) {
3799  TMakeProject::AddInclude( fp, "utility", kTRUE, inclist);
3800  } else if (strncmp(element->GetTypeName(),"auto_ptr<",strlen("auto_ptr<"))==0) {
3801  TMakeProject::AddInclude( fp, "memory", kTRUE, inclist);
3802  } else {
3803  TString incName( include, strlen(include)-1 );
3804  incName = TMakeProject::GetHeaderName(incName,extrainfos);
3805  TMakeProject::AddInclude( fp, incName.Data(), greater, inclist);
3806  }
3807 
3808  if (strchr(element->GetTypeName(),'<')) {
3809  // This is a template, we need to check the template parameter.
3810  ninc += TMakeProject::GenerateIncludeForTemplate(fp, element->GetTypeName(), inclist, kFALSE, extrainfos);
3811  }
3812  }
3813  return ninc;
3814 }
3815 
3816 ////////////////////////////////////////////////////////////////////////////////
3817 /// Generate header file for the class described by this TStreamerInfo
3818 /// the function is called by TFile::MakeProject for each class in the file
3819 
3820 Int_t TStreamerInfo::GenerateHeaderFile(const char *dirname, const TList *subClasses, const TList *extrainfos)
3821 {
3822  // if (fClassVersion == -4) return 0;
3823  if ((fClass && fClass->GetCollectionType()) || TClassEdit::IsSTLCont(GetName())) return 0;
3824  if (strncmp(GetName(),"pair<",strlen("pair<"))==0) return 0;
3825  if (strncmp(GetName(),"auto_ptr<",strlen("auto_ptr<"))==0) return 0;
3826 
3827  TClass *cl = TClass::GetClass(GetName());
3828  if (cl) {
3829  if (cl->HasInterpreterInfo()) return 0; // skip known classes
3830  }
3831  Bool_t isTemplate = kFALSE;
3832  if (strchr(GetName(),':')) {
3833  UInt_t len = strlen(GetName());
3834  UInt_t nest = 0;
3835  UInt_t scope = 0;
3836  for(UInt_t i=len; i>0; --i) {
3837  switch(GetName()[i]) {
3838  case '>': ++nest; if (scope==0) { isTemplate = kTRUE; } break;
3839  case '<': --nest; break;
3840  case ':':
3841  if (nest==0 && GetName()[i-1]==':') {
3842  // We have a scope
3843  TString nsname(GetName(), i-1);
3844  cl = gROOT->GetClass(nsname);
3845  if (cl && (cl->Size()!=0 || (cl->Size()==0 && !cl->HasInterpreterInfo() /*empty 'base' class on file*/))) {
3846  // This class is actually nested.
3847  return 0;
3848  } else if (cl == 0 && extrainfos != 0) {
3849  TStreamerInfo *clinfo = (TStreamerInfo*)extrainfos->FindObject(nsname);
3850  if (clinfo && clinfo->GetClassVersion() == -5) {
3851  // This class is actually nested.
3852  return 0;
3853  }
3854  }
3855  ++scope;
3856  }
3857  break;
3858  }
3859  }
3860  }
3861  Bool_t needGenericTemplate = isTemplate && (fElements==0 || fElements->GetEntries()==0);
3862 
3863  if (gDebug) printf("generating code for class %s\n",GetName());
3864 
3865  // Open the file
3866 
3867  TString headername( TMakeProject::GetHeaderName( GetName(), extrainfos ) );
3868  TString filename;
3869  filename.Form("%s/%s.h",dirname,headername.Data());
3870 
3871  FILE *fp = fopen(filename.Data(),"w");
3872  if (!fp) {
3873  Error("MakeProject","Cannot open output file:%s\n",filename.Data());
3874  return 0;
3875  }
3876 
3877  filename.Form("%s/%sProjectHeaders.h",dirname,gSystem->BaseName(dirname));
3878  FILE *allfp = fopen(filename.Data(),"a");
3879  if (!allfp) {
3880  Error("MakeProject","Cannot open output file:%s\n",filename.Data());
3881  fclose(fp);
3882  return 0;
3883  }
3884  fprintf(allfp,"#include \"%s.h\"\n", headername.Data());
3885  fclose(allfp);
3886 
3887  char *inclist = new char[50000];
3888  inclist[0] = 0;
3889 
3890  // Generate class header.
3891  TDatime td;
3892  fprintf(fp,"//////////////////////////////////////////////////////////\n");
3893  fprintf(fp,"// This class has been generated by TFile::MakeProject\n");
3894  fprintf(fp,"// (%s by ROOT version %s)\n",td.AsString(),gROOT->GetVersion());
3895  fprintf(fp,"// from the StreamerInfo in file %s\n",gDirectory->GetFile()->GetName());
3896  fprintf(fp,"//////////////////////////////////////////////////////////\n");
3897  fprintf(fp,"\n");
3898  fprintf(fp,"\n");
3899  fprintf(fp,"#ifndef %s_h\n",headername.Data());
3900  fprintf(fp,"#define %s_h\n",headername.Data());
3901  TMakeProject::GenerateForwardDeclaration(fp, GetName(), inclist, kFALSE, needGenericTemplate, extrainfos);
3902  fprintf(fp,"\n");
3903 
3904  UInt_t ninc = 0;
3905  ninc += GenerateIncludes(fp, inclist, extrainfos);
3906  if (subClasses) {
3907  TIter subnext(subClasses);
3908  TStreamerInfo *subinfo;
3909  while ((subinfo = (TStreamerInfo*)subnext())) {
3910  ninc = subinfo->GenerateIncludes(fp, inclist, extrainfos);
3911  }
3912  }
3913  fprintf(fp,"\n");
3914 
3915  TString sourcename; sourcename.Form( "%s/%sProjectSource.cxx", dirname, gSystem->BaseName(dirname) );
3916  FILE *sfp = fopen( sourcename.Data(), "a" );
3917  if (sfp) {
3918  GenerateDeclaration(fp, sfp, subClasses);
3919  } else {
3920  Error("GenerateHeaderFile","Could not open %s for appending",sourcename.Data());
3921  }
3922  TMakeProject::GeneratePostDeclaration(fp, this, inclist);
3923 
3924  fprintf(fp,"#endif\n");
3925 
3926  delete [] inclist;
3927  fclose(fp);
3928  if (sfp) fclose(sfp);
3929  return 1;
3930 }
3931 
3932 ////////////////////////////////////////////////////////////////////////////////
3933 /// Compute data member offset.
3934 /// Return pointer to the Streamer function if one exists
3935 
3937 {
3938  TIter nextr(fClass->GetListOfRealData());
3939  char dmbracket[256];
3940  snprintf(dmbracket,255,"%s[",dm->GetName());
3941  Int_t offset = kMissing;
3942  if (!fClass->IsLoaded()) {
3943  // If the 'class' is not loaded, we do not have a TClass bootstrap and thus
3944  // the 'RealData' might not have enough information because of the lack
3945  // of proper ShowMember implementation.
3946  if (! (dm->Property() & kIsStatic) ) {
3947  // Give an offset only to non-static members.
3948  offset = dm->GetOffset();
3949  }
3950  }
3951  TRealData *rdm;
3952  while ((rdm = (TRealData*)nextr())) {
3953  char *rdmc = (char*)rdm->GetName();
3954  //next statement required in case a class and one of its parent class
3955  //have data members with the same name
3956  if (dm->IsaPointer() && rdmc[0] == '*') rdmc++;
3957 
3958  if (rdm->GetDataMember() != dm) continue;
3959  if (strcmp(rdmc,dm->GetName()) == 0) {
3960  offset = rdm->GetThisOffset();
3961  streamer = rdm->GetStreamer();
3962  break;
3963  }
3964  if (strcmp(rdm->GetName(),dm->GetName()) == 0) {
3965  if (rdm->IsObject()) {
3966  offset = rdm->GetThisOffset();
3967  streamer = rdm->GetStreamer();
3968  break;
3969  }
3970  }
3971  if (strstr(rdm->GetName(),dmbracket)) {
3972  offset = rdm->GetThisOffset();
3973  streamer = rdm->GetStreamer();
3974  break;
3975  }
3976  }
3977  return offset;
3978 }
3979 
3980 ////////////////////////////////////////////////////////////////////////////////
3981 /// Return the offset of the data member as indicated by this StreamerInfo.
3982 
3983 Int_t TStreamerInfo::GetOffset(const char *elementName) const
3984 {
3985  if (elementName == 0) return 0;
3986 
3987  Int_t offset = 0;
3988  TStreamerElement *elem = (TStreamerElement*)fElements->FindObject(elementName);
3989  if (elem) offset = elem->GetOffset();
3990 
3991  return offset;
3992 }
3993 
3994 ////////////////////////////////////////////////////////////////////////////////
3995 /// Return total size of all persistent elements of the class (with offsets).
3996 
3998 {
3999  return fSize;
4000 }
4001 
4002 ////////////////////////////////////////////////////////////////////////////////
4003 /// Return total size of all persistent elements of the class
4004 /// use GetSize if you want to get the real size in memory.
4005 
4007 {
4008  TIter next(fElements);
4009  TStreamerElement *element;
4010  Int_t asize = 0;
4011  while ((element = (TStreamerElement*)next())) {
4012  asize += element->GetSize();
4013  }
4014  return asize;
4015 }
4016 
4017 ////////////////////////////////////////////////////////////////////////////////
4018 /// Return the StreamerElement of "datamember" inside our
4019 /// class or any of its base classes.
4020 ///
4021 /// The offset information
4022 /// contained in the StreamerElement is related to its immediately
4023 /// containing class, so we return in 'offset' the offset inside
4024 /// our class.
4025 
4026 TStreamerElement* TStreamerInfo::GetStreamerElement(const char* datamember, Int_t& offset) const
4027 {
4028  if (!fElements) {
4029  return 0;
4030  }
4031 
4032  // Look first at the data members and base classes
4033  // of our class.
4034  TStreamerElement* element = (TStreamerElement*) fElements->FindObject(datamember);
4035  if (element) {
4036  offset = element->GetOffset();
4037  return element;
4038  }
4039 
4040  // Not found, so now try the data members and base classes
4041  // of the base classes of our class.
4042  if (fClass->HasDataMemberInfo()) {
4043  // Our class has a dictionary loaded, use it to search the base classes.
4044  TStreamerElement* base_element = 0;
4045  TBaseClass* base = 0;
4046  TClass* base_cl = 0;
4047  Int_t base_offset = 0;
4048  Int_t local_offset = 0;
4049  TIter nextb(fClass->GetListOfBases());
4050  // Iterate on list of base classes.
4051  while ((base = (TBaseClass*) nextb())) {
4052  base_cl = TClass::GetClass(base->GetName());
4053  base_element = (TStreamerElement*) fElements->FindObject(base->GetName());
4054  if (!base_cl || !base_element) {
4055  continue;
4056  }
4057  base_offset = base_element->GetOffset();
4058  element = ((TStreamerInfo*)base_cl->GetStreamerInfo())->GetStreamerElement(datamember, local_offset);
4059  if (element) {
4060  offset = base_offset + local_offset;
4061  return element;
4062  }
4063  }
4064  } else {
4065  // Our class's dictionary is not loaded. Search through the base class streamer elements.
4066  TIter next(fElements);
4067  TStreamerElement* curelem = 0;
4068  while ((curelem = (TStreamerElement*) next())) {
4069  if (curelem->InheritsFrom(TStreamerBase::Class())) {
4070  TClass* baseClass = curelem->GetClassPointer();
4071  if (!baseClass) {
4072  continue;
4073  }
4074  Int_t base_offset = curelem->GetOffset();
4075  Int_t local_offset = 0;
4076  TStreamerInfo *baseInfo;
4077  if (baseClass->Property() & kIsAbstract) {
4078  baseInfo = (TStreamerInfo*)baseClass->GetStreamerInfoAbstractEmulated();
4079  } else {
4080  baseInfo = (TStreamerInfo*)baseClass->GetStreamerInfo();
4081  }
4082  if (baseInfo) element = baseInfo->GetStreamerElement(datamember, local_offset);
4083  if (element) {
4084  offset = base_offset + local_offset;
4085  return element;
4086  }
4087  }
4088  }
4089  }
4090  return 0;
4091 }
4092 
4093 ////////////////////////////////////////////////////////////////////////////////
4094 /// <b>Obsolete</b>: this routine is obsolete and should not longer be used.
4095 ///
4096 /// TStreamerInfo holds two types of data structures
4097 /// - TObjArray* fElements; containing the list of all TStreamerElement
4098 /// objects for this class version.
4099 /// - ULong_t* fElem; containing the preprocessed information
4100 /// by TStreamerInfo::Compile In case consecutive data members
4101 /// are of the same type, the Compile function declares the consecutive
4102 /// elements as one single element in fElems.
4103 ///
4104 /// Example with the class TAttLine:
4105 /// ~~~{.cpp}
4106 /// TClass::GetClass("TAttLine")->GetStreamerInfo()->ls(); produces;
4107 /// StreamerInfo for class: TAttLine, version=1
4108 /// short fLineColor offset= 4 type= 2 line color
4109 /// short fLineStyle offset= 6 type= 2 line style
4110 /// short fLineWidth offset= 8 type= 2 line width
4111 /// i= 0, fLineColor type= 22, offset= 4, len=3, method=0
4112 /// ~~~
4113 /// For I/O implementations (eg. XML) , one has to know the original name
4114 /// of the data member. This function can be used to return a pointer
4115 /// to the original TStreamerElement object corresponding to the j-th
4116 /// element of a compressed array in fElems.
4117 /// Parameters description:
4118 /// - i: the serial number in array fElem
4119 /// - j: the element number in the array of consecutive types
4120 /// In the above example the class TAttLine has 3 consecutive data members
4121 /// of the same type "short". Compile makes one single array of 3 elements.
4122 /// To access the TStreamerElement for the second element
4123 /// of this array, one can call:
4124 /// ~~~{.cpp}
4125 /// auto el = GetStreamerElementReal(0,1);
4126 /// auto membername = el->GetName();
4127 /// ~~~
4128 /// This function is typically called from TBuffer, TXmlBuffer.
4129 
4131 {
4132  ::Obsolete("TStreamerInfo::GetStreamerElementReal", "v5-34-20", "v6-00-02");
4133 
4134  if (i < 0 || i >= fNdata) return 0;
4135  if (j < 0) return 0;
4136  if (!fElements) return 0;
4137  TStreamerElement *se = (TStreamerElement*)fCompOpt[i]->fElem;
4138  if (!se) return 0;
4139  Int_t nelems = fElements->GetEntriesFast();
4140  for (Int_t ise=0;ise < nelems;ise++) {
4141  if (se != (TStreamerElement*)fElements->UncheckedAt(ise)) continue;
4142  if (ise+j >= nelems) return 0;
4143  return (TStreamerElement*)fElements->UncheckedAt(ise+j);
4144  }
4145  return 0;
4146 }
4147 
4148 ////////////////////////////////////////////////////////////////////////////////
4149 /// Get the value from inside a collection.
4150 
4151 template <typename T>
4153 {
4154  if (type>=kConv && type<kSTL) {
4155  type -= kConv;
4156  }
4157  switch (type) {
4158  // basic types
4159  case kBool: {Bool_t *val = (Bool_t*)ladd; return T(*val);}
4160  case kChar: {Char_t *val = (Char_t*)ladd; return T(*val);}
4161  case kShort: {Short_t *val = (Short_t*)ladd; return T(*val);}
4162  case kInt: {Int_t *val = (Int_t*)ladd; return T(*val);}
4163  case kLong: {Long_t *val = (Long_t*)ladd; return T(*val);}
4164  case kLong64: {Long64_t *val = (Long64_t*)ladd; return T(*val);}
4165  case kFloat: {Float_t *val = (Float_t*)ladd; return T(*val);}
4166  case kFloat16: {Float_t *val = (Float_t*)ladd; return T(*val);}
4167  case kDouble: {Double_t *val = (Double_t*)ladd; return T(*val);}
4168  case kDouble32: {Double_t *val = (Double_t*)ladd; return T(*val);}
4169  case kUChar: {UChar_t *val = (UChar_t*)ladd; return T(*val);}
4170  case kUShort: {UShort_t *val = (UShort_t*)ladd; return T(*val);}
4171  case kUInt: {UInt_t *val = (UInt_t*)ladd; return T(*val);}
4172  case kULong: {ULong_t *val = (ULong_t*)ladd; return T(*val);}
4173 #if defined(_MSC_VER) && (_MSC_VER <= 1200)
4174  case kULong64: {Long64_t *val = (Long64_t*)ladd; return T(*val);}
4175 #else
4176  case kULong64: {ULong64_t *val= (ULong64_t*)ladd; return T(*val);}
4177 #endif
4178  case kBits: {UInt_t *val = (UInt_t*)ladd; return T(*val);}
4179 
4180  // array of basic types array[8]
4181  case kOffsetL + kBool: {Bool_t *val = (Bool_t*)ladd; return T(val[k]);}
4182  case kOffsetL + kChar: {Char_t *val = (Char_t*)ladd; return T(val[k]);}
4183  case kOffsetL + kShort: {Short_t *val = (Short_t*)ladd; return T(val[k]);}
4184  case kOffsetL + kInt: {Int_t *val = (Int_t*)ladd; return T(val[k]);}
4185  case kOffsetL + kLong: {Long_t *val = (Long_t*)ladd; return T(val[k]);}
4186  case kOffsetL + kLong64: {Long64_t *val = (Long64_t*)ladd; return T(val[k]);}
4187  case kOffsetL + kFloat: {Float_t *val = (Float_t*)ladd; return T(val[k]);}
4188  case kOffsetL + kFloat16: {Float_t *val = (Float_t*)ladd; return T(val[k]);}
4189  case kOffsetL + kDouble: {Double_t *val = (Double_t*)ladd; return T(val[k]);}
4190  case kOffsetL + kDouble32:{Double_t *val = (Double_t*)ladd; return T(val[k]);}
4191  case kOffsetL + kUChar: {UChar_t *val = (UChar_t*)ladd; return T(val[k]);}
4192  case kOffsetL + kUShort: {UShort_t *val = (UShort_t*)ladd; return T(val[k]);}
4193  case kOffsetL + kUInt: {UInt_t *val = (UInt_t*)ladd; return T(val[k]);}
4194  case kOffsetL + kULong: {ULong_t *val = (ULong_t*)ladd; return T(val[k]);}
4195 #if defined(_MSC_VER) && (_MSC_VER <= 1200)
4196  case kOffsetL + kULong64: {Long64_t *val = (Long64_t*)ladd; return T(val[k]);}
4197 #else
4198  case kOffsetL + kULong64:{ULong64_t *val= (ULong64_t*)ladd; return T(val[k]);}
4199 #endif
4200 
4201 #define READ_ARRAY(TYPE_t) \
4202  { \
4203  Int_t sub_instance, index; \
4204  Int_t instance = k; \
4205  if (len) { \
4206  index = instance / len; \
4207  sub_instance = instance % len; \
4208  } else { \
4209  index = instance; \
4210  sub_instance = 0; \
4211  } \
4212  TYPE_t **val =(TYPE_t**)(ladd); \
4213  return T((val[sub_instance])[index]); \
4214  }
4215 
4216  // pointer to an array of basic types array[n]
4220  case kOffsetP + kInt_t: READ_ARRAY(Int_t)
4223  case kOffsetP + kFloat16_t:
4225  case kOffsetP + kDouble32_t:
4231 #if defined(_MSC_VER) && (_MSC_VER <= 1200)
4233 #else
4235 #endif
4236 
4237  // array counter //[n]
4238  case kCounter: {Int_t *val = (Int_t*)ladd; return T(*val);}
4239  }
4240  return 0;
4241 }
4242 
4243 
4244 
4245 template Double_t TStreamerInfo::GetTypedValue(char *pointer, Int_t i, Int_t j, Int_t len) const;
4246 template Long64_t TStreamerInfo::GetTypedValue(char *pointer, Int_t i, Int_t j, Int_t len) const;
4247 template LongDouble_t TStreamerInfo::GetTypedValue(char *pointer, Int_t i, Int_t j, Int_t len) const;
4248 
4249 ////////////////////////////////////////////////////////////////////////////////
4250 /// Return value of element i in object at pointer.
4251 /// The function may be called in two ways:
4252 /// - method1 len < 0: i is assumed to be the TStreamerElement number i in StreamerInfo
4253 /// - method2 len >= 0: i is the type, address of variable is directly pointer.
4254 
4255 template <typename T>
4256 T TStreamerInfo::GetTypedValue(char *pointer, Int_t i, Int_t j, Int_t len) const
4257 {
4258  char *ladd;
4259  Int_t atype;
4260  if (len >= 0) {
4261  ladd = pointer;
4262  atype = i;
4263  } else {
4264  if (i < 0) return 0;
4265  ladd = pointer + fCompFull[i]->fOffset;
4266  atype = fCompFull[i]->fNewType;
4267  len = fCompFull[i]->fElem->GetArrayLength();
4268  if (atype == kSTL) {
4269  TClass *newClass = fCompFull[i]->fElem->GetNewClass();
4270  if (newClass == 0) {
4271  newClass = fCompFull[i]->fElem->GetClassPointer();
4272  }
4273  TClass *innerClass = newClass->GetCollectionProxy()->GetValueClass();
4274  if (innerClass) {
4275  return 0; // We don't know which member of the class we would want.
4276  } else {
4277  TVirtualCollectionProxy *proxy = newClass->GetCollectionProxy();
4278  // EDataType is a subset of TStreamerInfo::EReadWrite
4279  atype = (TStreamerInfo::EReadWrite)proxy->GetType();
4280  TVirtualCollectionProxy::TPushPop pop(proxy,ladd);
4281  Int_t nc = proxy->Size();
4282  if (j >= nc) return 0;
4283  char *element_ptr = (char*)proxy->At(j);
4284  return GetTypedValueAux<T>(atype,element_ptr,0,1);
4285  }
4286  }
4287  }
4288  return GetTypedValueAux<T>(atype,ladd,j,len);
4289 }
4290 
4291 ////////////////////////////////////////////////////////////////////////////////
4292 
4293 template Double_t TStreamerInfo::GetTypedValueClones<Double_t>(TClonesArray *clones, Int_t i, Int_t j, int k, Int_t eoffset) const;
4294 template Long64_t TStreamerInfo::GetTypedValueClones(TClonesArray *clones, Int_t i, Int_t j, int k, Int_t eoffset) const;
4295 template LongDouble_t TStreamerInfo::GetTypedValueClones(TClonesArray *clones, Int_t i, Int_t j, int k, Int_t eoffset) const;
4296 
4297 template <typename T>
4299 {
4300  // return value of element i in object number j in a TClonesArray and eventually
4301  // element k in a sub-array.
4302 
4303  Int_t nc = clones->GetEntriesFast();
4304  if (j >= nc) return 0;
4305 
4306  char *pointer = (char*)clones->UncheckedAt(j);
4307  char *ladd = pointer + eoffset + fCompFull[i]->fOffset;
4308  return GetTypedValueAux<T>(fCompFull[i]->fType,ladd,k,((TStreamerElement*)fCompFull[i]->fElem)->GetArrayLength());
4309 }
4310 
4311 template Double_t TStreamerInfo::GetTypedValueSTL(TVirtualCollectionProxy *cont, Int_t i, Int_t j, int k, Int_t eoffset) const;
4312 template Long64_t TStreamerInfo::GetTypedValueSTL(TVirtualCollectionProxy *cont, Int_t i, Int_t j, int k, Int_t eoffset) const;
4313 template LongDouble_t TStreamerInfo::GetTypedValueSTL(TVirtualCollectionProxy *cont, Int_t i, Int_t j, int k, Int_t eoffset) const;
4314 
4315 ////////////////////////////////////////////////////////////////////////////////
4316 /// Return value of element i in object number j in a TClonesArray and eventually
4317 /// element k in a sub-array.
4318 
4319 template <typename T>
4321 {
4322  Int_t nc = cont->Size();
4323  if (j >= nc) return 0;
4324 
4325  char *pointer = (char*)cont->At(j);
4326  char *ladd = pointer + eoffset + fCompFull[i]->fOffset;
4327  return GetTypedValueAux<T>(fCompFull[i]->fType,ladd,k,((TStreamerElement*)fCompFull[i]->fElem)->GetArrayLength());
4328 }
4329 
4330 template Double_t TStreamerInfo::GetTypedValueSTLP(TVirtualCollectionProxy *cont, Int_t i, Int_t j, int k, Int_t eoffset) const;
4331 template Long64_t TStreamerInfo::GetTypedValueSTLP(TVirtualCollectionProxy *cont, Int_t i, Int_t j, int k, Int_t eoffset) const;
4332 template LongDouble_t TStreamerInfo::GetTypedValueSTLP(TVirtualCollectionProxy *cont, Int_t i, Int_t j, int k, Int_t eoffset) const;
4333 
4334 ////////////////////////////////////////////////////////////////////////////////
4335 /// Return value of element i in object number j in a TClonesArray and eventually
4336 /// element k in a sub-array.
4337 
4338 template <typename T>
4340 {
4341  Int_t nc = cont->Size();
4342 
4343  if (j >= nc) return 0;
4344 
4345  char **ptr = (char**)cont->At(j);
4346  char *pointer = *ptr;
4347 
4348  char *ladd = pointer + eoffset + fCompFull[i]->fOffset;
4349  return GetTypedValueAux<T>(fCompFull[i]->fType,ladd,k,((TStreamerElement*)fCompFull[i]->fElem)->GetArrayLength());
4350 }
4351 
4352 ////////////////////////////////////////////////////////////////////////////////
4353 /// Insert new members as expressed in the array of TSchemaRule(s).
4354 
4355 void TStreamerInfo::InsertArtificialElements(std::vector<const ROOT::TSchemaRule*> &rules)
4356 {
4357  if (rules.empty()) return;
4358 
4359  TIter next(fElements);
4360  UInt_t count = 0;
4361 
4362  for(auto rule : rules) {
4363  if( rule->IsRenameRule() || rule->IsAliasRule() )
4364  continue;
4365  next.Reset();
4366  TStreamerElement *element;
4367  while ((element = (TStreamerElement*) next())) {
4368  if ( rule->HasTarget( element->GetName() ) ) {
4369 
4370  // Check whether this is an 'attribute' rule.
4371  if ( rule->GetAttributes()[0] != 0 ) {
4372  TString attr( rule->GetAttributes() );
4373  attr.ToLower();
4374  if (attr.Contains("owner")) {
4375  if (attr.Contains("notowner")) {
4377  } else {
4379  }
4380  }
4381 
4382  }
4383  break;
4384  }
4385  }
4386 
4387  // NOTE: Before adding the rule we should check that the source do
4388  // existing in this StreamerInfo.
4389  const TObjArray *sources = rule->GetSource();
4390  TIter input(sources);
4391  TObject *src;
4392  while((src = input())) {
4393  if ( !GetElements()->FindObject(src->GetName()) ) {
4394  // Missing source.
4395 #if 0 // Don't warn about not activating the rule. If don't warn the user can
4396  // have more flexibility in specifying when the rule applies and relying
4397  // on both the version number *and* the presence of the source members.
4398  // Activating this warning would for example mean that we need to carefully
4399  // tweak $ROOTSYS/etc/class.rules.
4400  TString ruleStr;
4401  rule->AsString(ruleStr);
4402  Warning("InsertArtificialElements","For class %s in StreamerInfo %d is missing the source data member %s when trying to apply the rule:\n %s",
4403  GetName(),GetClassVersion(),src->GetName(),ruleStr.Data());
4404  rule = 0;
4405 #endif
4406  break;
4407  }
4408  }
4409 
4410  if (!rule) continue;
4411 
4412  TStreamerArtificial *newel;
4413  typedef std::vector<TStreamerArtificial*> vec_t;
4414  vec_t toAdd;
4415 
4416  if (rule->GetTarget()==0) {
4417  TString newName;
4418  newName.Form("%s_rule%d",fClass->GetName(),count);
4419  newel = new TStreamerArtificial(newName,"",
4420  fClass->GetDataMemberOffset(newName),
4422  "void");
4424  newel->SetReadFunc( rule->GetReadFunctionPointer() );
4425  newel->SetReadRawFunc( rule->GetReadRawFunctionPointer() );
4426  toAdd.push_back(newel);
4427  } else {
4428  toAdd.reserve(rule->GetTarget()->GetEntries());
4429  TObjString * objstr = (TObjString*)(rule->GetTarget()->At(0));
4430  if (objstr) {
4431  TString newName = objstr->String();
4432  TString realDataName;
4433  if ( TDataMember* dm = fClass->GetDataMember( newName ) ) {
4434  TRealData::GetName(realDataName,dm);
4435  newel = new TStreamerArtificial(realDataName,"",
4436  fClass->GetDataMemberOffset(newName),
4438  fClass->GetDataMember( newName )->GetTypeName());
4439  newel->SetReadFunc( rule->GetReadFunctionPointer() );
4440  newel->SetReadRawFunc( rule->GetReadRawFunctionPointer() );
4441  toAdd.push_back(newel);
4442  } else {
4443  // This would be a completely new member (so it would need to be cached)
4444  // TOBEDONE
4445  }
4446  for(Int_t other = 1; other < rule->GetTarget()->GetEntries(); ++other) {
4447  objstr = (TObjString*)(rule->GetTarget()->At(other));
4448  if (objstr) {
4449  newName = objstr->String();
4450  if ( TDataMember* dm = fClass->GetDataMember( newName ) ) {
4451  TRealData::GetName(realDataName,dm);
4452  newel = new TStreamerArtificial(realDataName,"",
4453  fClass->GetDataMemberOffset(newName),
4455  fClass->GetDataMember( newName )->GetTypeName());
4456  toAdd.push_back(newel);
4457  }
4458  }
4459  }
4460  } // For each target of the rule
4461  }
4462  // Now find we with need to add them
4463  TIter s_iter(rule->GetSource());
4464  Int_t loc = -1;
4465  while( TObjString *s = (TObjString*)s_iter() ) {
4466  for(Int_t i = fElements->GetLast(); i >= 0 && (i+1) >= loc; --i) {
4467  if (s->String() == fElements->UncheckedAt(i)->GetName()) {
4468  if (loc == -1 || (i+1)>loc) {
4469  loc = i+1;
4470  }
4471  }
4472  }
4473  }
4474  if (loc == -1) {
4475  // Verify if the last one is not 'skipped'.
4476  for(Int_t i = fElements->GetLast(); i >= 0 && (i+1) >= loc; --i) {
4477  if ( ((TStreamerElement*)fElements->UncheckedAt(i))->GetNewType() != -2 ) {
4478  break;
4479  }
4480  loc = i;
4481  }
4482  }
4483  if (loc == -1) {
4484  for(vec_t::iterator iter = toAdd.begin(); iter != toAdd.end(); ++iter) {
4485  fElements->Add(*iter);
4486  }
4487  } else {
4488  R__TObjArray_InsertAt(fElements, toAdd, loc);
4489  }
4490  } // None of the target of the rule are on file.
4491 }
4492 
4493 ////////////////////////////////////////////////////////////////////////////////
4494 /// List the TStreamerElement list and also the precomputed tables
4495 /// if option contains the string "incOrig", also prints the original
4496 /// (non-optimized elements in the list of compiled elements.
4497 
4498 void TStreamerInfo::ls(Option_t *option) const
4499 {
4500  if (fClass && (fName != fClass->GetName())) {
4501  if (fClass->IsVersioned()) {
4502  Printf("\nStreamerInfo for conversion to %s from: %s, version=%d, checksum=0x%x",fClass->GetName(),GetName(),fClassVersion,GetCheckSum());
4503  } else {
4504  Printf("\nStreamerInfo for conversion to %s from: %s, checksum=0x%x",fClass->GetName(),GetName(),GetCheckSum());
4505  }
4506  } else {
4507  if (!fClass || fClass->IsVersioned()) {
4508  Printf("\nStreamerInfo for class: %s, version=%d, checksum=0x%x",GetName(),fClassVersion,GetCheckSum());
4509  } else {
4510  Printf("\nStreamerInfo for class: %s, checksum=0x%x",GetName(),GetCheckSum());
4511  }
4512  }
4513 
4514  if (fElements) {
4515  TIter next(fElements);
4516  TObject *obj;
4517  while ((obj = next()))
4518  obj->ls(option);
4519  }
4520  if (strstr(option,"full") != 0) {
4521  for (Int_t i=0; i < fNfulldata; ++i) {
4522  TStreamerElement *element = (TStreamerElement*)fCompFull[i]->fElem;
4523  TString sequenceType;
4524  element->GetSequenceType(sequenceType);
4525  // by definition of the loop (i+1) <= fNdata
4526  if (sequenceType.Length()) {
4527  sequenceType.Prepend(" [");
4528  sequenceType += "]";
4529  }
4530  Printf(" i=%2d, %-15s type=%3d, offset=%3d, len=%d, method=%ld%s",
4531  i,element->GetName(),fCompFull[i]->fType,fCompFull[i]->fOffset,fCompFull[i]->fLength,fCompFull[i]->fMethod,
4532  sequenceType.Data());
4533  }
4534 
4535  } else {
4536  Bool_t wantOrig = strstr(option,"incOrig") != 0;
4537  Bool_t optimized = kFALSE;
4538  for (Int_t i=0,j=0;i < fNdata;++i,++j) {
4539  TStreamerElement *element = (TStreamerElement*)fCompOpt[i]->fElem;
4540  TString sequenceType;
4541  element->GetSequenceType(sequenceType);
4542  // by definition of the loop (i+1) <= fNdata
4544  if (optimized) {
4545  // This was optimized.
4546  if (sequenceType.Length() != 0) {
4547  sequenceType += ',';
4548  }
4549  sequenceType += "optimized";
4550  }
4551  if (sequenceType.Length()) {
4552  sequenceType.Prepend(" [");
4553  sequenceType += "]";
4554  }
4555  Printf(" i=%2d, %-15s type=%3d, offset=%3d, len=%d, method=%ld%s",
4556  i,element->GetName(),fCompOpt[i]->fType,fCompOpt[i]->fOffset,fCompOpt[i]->fLength,fCompOpt[i]->fMethod,
4557  sequenceType.Data());
4558  if (optimized && wantOrig) {
4559  Bool_t done;
4560  do {
4561  element = (TStreamerElement*)fCompFull[j]->fElem;
4562  element->GetSequenceType(sequenceType);
4563  if (sequenceType.Length()) {
4564  sequenceType.Prepend(" [");
4565  sequenceType += "]";
4566  }
4567  Printf(" j=%2d, %-15s type=%3d, offset=%3d, len=%d, method=%ld%s",
4568  j,element->GetName(),fCompFull[j]->fType,fCompFull[j]->fOffset,fCompFull[j]->fLength,fCompFull[j]->fMethod,
4569  sequenceType.Data());
4570  ++j;
4571  done = j >= fNfulldata || ( (i+1 < fNdata) && fCompOpt[i+1]->fElem == fCompFull[j+1]->fElem );
4572  } while (!done);
4573 
4574  }
4575  }
4576  }
4577 }
4578 
4579 ////////////////////////////////////////////////////////////////////////////////
4580 /// An emulated object is created at address obj, if obj is null we
4581 /// allocate memory for the object.
4582 
4583 void* TStreamerInfo::New(void *obj)
4584 {
4585  //???FIX ME: What about varying length array elements?
4586 
4587  char* p = (char*) obj;
4588 
4589  TIter next(fElements);
4590 
4591  if (!p) {
4592  // Allocate and initialize the memory block.
4593  p = new char[fSize];
4594  memset(p, 0, fSize);
4595  }
4596 
4597  next.Reset();
4598  TStreamerElement* element = (TStreamerElement*) next();
4599 
4600  for (; element; element = (TStreamerElement*) next()) {
4601 
4602  // Skip elements which have not been allocated memory.
4603  if (element->GetOffset() == kMissing) {
4604  continue;
4605  }
4606 
4607  // Skip elements for which we do not have any class
4608  // information. FIXME: Document how this could happen.
4609  TClass* cle = element->GetClassPointer();
4610  if (!cle) {
4611  continue;
4612  }
4613 
4614  char* eaddr = p + element->GetOffset();
4615  Int_t etype = element->GetType();
4616 
4617  //cle->GetStreamerInfo(); //necessary in case "->" is not specified
4618 
4619  switch (etype) {
4620 
4621  case kAnyP:
4622  case kObjectP:
4623  case kSTLp:
4624  {
4625  // Initialize array of pointers with null pointers.
4626  char** r = (char**) eaddr;
4627  Int_t len = element->GetArrayLength();
4628  for (Int_t i = 0; i < len; ++i) {
4629  r[i] = 0;
4630  }
4631  }
4632  break;
4633 
4634  case kObjectp:
4635  case kAnyp:
4636  {
4637  // If the option "->" is given in the data member comment field
4638  // it is assumed that the object exists before reading data in,
4639  // so we create an object.
4640  if (cle != TClonesArray::Class()) {
4641  void** r = (void**) eaddr;
4642  *r = cle->New();
4643  } else {
4644  // In the case of a TClonesArray, the class name of
4645  // the contained objects must be specified in the
4646  // data member comment in this format:
4647  // TClonesArray* myVar; //->(className)
4648  const char* title = element->GetTitle();
4649  const char* bracket1 = strrchr(title, '(');
4650  const char* bracket2 = strrchr(title, ')');
4651  if (bracket1 && bracket2 && (bracket2 != (bracket1 + 1))) {
4652  Int_t len = bracket2 - (bracket1 + 1);
4653  char* clonesClass = new char[len+1];
4654  clonesClass[0] = '\0';
4655  strncat(clonesClass, bracket1 + 1, len);
4656  void** r = (void**) eaddr;
4657  *r = (void*) new TClonesArray(clonesClass);
4658  delete[] clonesClass;
4659  } else {
4660  //Warning("New", "No class name found for TClonesArray initializer in data member comment (expected \"//->(className)\"");
4661  void** r = (void**) eaddr;
4662  *r = (void*) new TClonesArray();
4663  }
4664  }
4665  }
4666  break;
4667 
4668  case kBase:
4669  {
4670  if (cle->Property() & kIsAbstract) {
4672  if (einfo) einfo->New(eaddr);
4673  } else {
4674  cle->New(eaddr);
4675  }
4676  break;
4677  }
4678  case kObject:
4679  case kAny:
4680  case kTObject:
4681  case kTString:
4682  case kTNamed:
4683  {
4684  cle->New(eaddr);
4685  }
4686  break;
4687 
4688  case kSTL:
4689  {
4690  if (strcmp(element->GetName(),"This")==0 &&
4691  !cle->GetCollectionProxy()) {
4692  // missing information, avoid infinite loop
4693  // by doing nothing ....
4694  } else {
4695  cle->New(eaddr);
4696  }
4697  }
4698  break;
4699 
4700  case kObject + kOffsetL:
4701  case kAny + kOffsetL:
4702  case kTObject + kOffsetL:
4703  case kTString + kOffsetL:
4704  case kTNamed + kOffsetL:
4705  case kSTL + kOffsetL:
4706  {
4707  Int_t size = cle->Size();
4708  char* r = eaddr;
4709  Int_t len = element->GetArrayLength();
4710  for (Int_t i = 0; i < len; ++i, r += size) {
4711  cle->New(r);
4712  }
4713  }
4714  break;
4715 
4716  } // switch etype
4717  } // for TIter next(fElements)
4718 
4719  for(int nbase = 0; nbase < fNVirtualInfoLoc; ++nbase) {
4720  *(TStreamerInfo**)(p + fVirtualInfoLoc[nbase]) = this;
4721  }
4722  ++fLiveCount;
4723  return p;
4724 }
4725 
4726 ////////////////////////////////////////////////////////////////////////////////
4727 /// An array of emulated objects is created at address ary, if ary is null,
4728 /// we allocate memory for the array.
4729 
4730 void* TStreamerInfo::NewArray(Long_t nElements, void *ary)
4731 {
4732  if (fClass == 0) {
4733  Error("NewArray", "TClass pointer is null!");
4734  return 0;
4735  }
4736 
4737  Int_t size = fClass->Size();
4738 
4739  char* p = (char*) ary;
4740 
4741  if (!p) {
4742  Long_t len = nElements * size + sizeof(Long_t)*2;
4743  p = new char[len];
4744  memset(p, 0, len);
4745  }
4746 
4747  // Store the array cookie
4748  Long_t* r = (Long_t*) p;
4749  r[0] = size;
4750  r[1] = nElements;
4751  char* dataBegin = (char*) &r[2];
4752 
4753  // Do a placement new for each element.
4754  p = dataBegin;
4755  for (Long_t cnt = 0; cnt < nElements; ++cnt) {
4756  New(p);
4757  p += size;
4758  } // for nElements
4759 
4760  return dataBegin;
4761 }
4762 
4763 
4764 #define DeleteBasicPointer(addr,element,name) \
4765  { \
4766  name **f = (name**)(addr); \
4767  int n = element->GetArrayLength() ? element->GetArrayLength() : 1;\
4768  for(int j=0;j<n;j++) { \
4769  delete [] f[j]; \
4770  f[j] = 0; \
4771  } \
4772  }
4773 
4774 ////////////////////////////////////////////////////////////////////////////////
4775 /// Internal part of the destructor.
4776 /// Destruct each of the datamembers in the same order
4777 /// as the implicit destructor would.
4778 
4779 void TStreamerInfo::DestructorImpl(void* obj, Bool_t dtorOnly)
4780 {
4781  R__ASSERT(obj != 0);
4782 
4783  char *p = (char*)obj;
4784 
4785  Int_t nelements = fElements->GetEntriesFast();
4786  //for (; ele; ele = (TStreamerElement*) next())
4787  for (Int_t elenum = nelements - 1; elenum >= 0; --elenum) {
4789  if (ele->GetOffset() == kMissing) continue;
4790  char* eaddr = p + ele->GetOffset();
4791 
4792 
4793  Int_t etype = ele->GetType();
4794 
4795  switch(etype) {
4811  case TStreamerInfo::kCharStar: DeleteBasicPointer(eaddr,ele,Char_t); continue;
4812  }
4813 
4814 
4815 
4816  TClass* cle = ele->GetClassPointer();
4817  if (!cle) continue;
4818 
4819 
4820  if (etype == kObjectp || etype == kAnyp) {
4821  // Destroy an array of pre-allocated objects.
4822  Int_t len = ele->GetArrayLength();
4823  if (!len) {
4824  len = 1;
4825  }
4826  void** r = (void**) eaddr;
4827  for (Int_t j = len - 1; j >= 0; --j) {
4828  if (r[j]) {
4829  cle->Destructor(r[j]);
4830  r[j] = 0;
4831  }
4832  }
4833  }
4834 
4835  if ((etype == kObjectP || etype == kAnyP || etype == kSTLp) && !ele->TestBit(TStreamerElement::kDoNotDelete)) {
4836  // Destroy an array of pointers to not-pre-allocated objects.
4837  Int_t len = ele->GetArrayLength();
4838  if (!len) {
4839  len = 1;
4840  }
4841  void** r = (void**) eaddr;
4842  for (Int_t j = len - 1; j >= 0; --j) {
4843  if (r[j]) {
4844  cle->Destructor(r[j]);
4845  r[j] = 0;
4846  }
4847  }
4848  }
4849 
4850  if (etype == kBase) {
4851  if (cle->Property() & kIsAbstract) {
4853  if (einfo) einfo->Destructor(eaddr, kTRUE);
4854  } else {
4855  cle->Destructor(eaddr, kTRUE);
4856  }
4857  }
4858 
4859  if (etype == kObject || etype == kAny ||
4860  etype == kTObject || etype == kTString || etype == kTNamed) {
4861  // A data member is destroyed, but not deleted.
4862  cle->Destructor(eaddr, kTRUE);
4863  }
4864 
4865  if (etype == kSTL) {
4866  // A data member is destroyed, but not deleted.
4868  if (!pr) {
4869  if (strcmp(ele->GetName(),"This")==0) {
4870  // missing information, avoid infinite loop
4871  // by doing nothing ....
4872  } else {
4873  cle->Destructor(eaddr, kTRUE);
4874  }
4875  } else {
4877  TVirtualCollectionProxy::TPushPop env(cle->GetCollectionProxy(), eaddr); // used for both this 'clear' and the 'clear' inside destructor.
4878  cle->GetCollectionProxy()->Clear(); // empty the collection without deleting the pointer
4879  pr->Destructor(eaddr, kTRUE);
4880  } else {
4881  pr->Destructor(eaddr, kTRUE);
4882  }
4883  }
4884  }
4885 
4886  if (etype == kObject + kOffsetL || etype == kAny + kOffsetL ||
4887  etype == kTObject + kOffsetL || etype == kTString + kOffsetL ||
4888  etype == kTNamed + kOffsetL || etype == kSTL + kOffsetL) {
4889  // For a data member which is an array of objects, we
4890  // destroy the objects, but do not delete them.
4891  Int_t len = ele->GetArrayLength();
4892  Int_t size = cle->Size();
4893  char* r = eaddr + (size * (len - 1));
4894  for (Int_t j = len - 1; j >= 0; --j, r -= size) {
4895  cle->Destructor(r, kTRUE);
4896  }
4897  }
4898  } // iter over elements
4899 
4900  if (!dtorOnly) {
4901  delete[] p;
4902  }
4903  --fLiveCount;
4904 }
4905 
4906 ////////////////////////////////////////////////////////////////////////////////
4907 /// Emulated destructor for this class.
4908 ///
4909 /// An emulated object is destroyed at address p.
4910 /// Destruct each of the datamembers in the same order
4911 /// as the implicit destructor would.
4912 
4913 void TStreamerInfo::Destructor(void* obj, Bool_t dtorOnly)
4914 {
4915  // Do nothing if passed a null pointer.
4916  if (obj == 0) return;
4917 
4918  char* p = (char*) obj;
4919 
4920  if (!dtorOnly && fNVirtualInfoLoc) {
4921  // !dtorOnly is used to filter out the case where this is called for
4922  // a base class or embedded object of the outer most class.
4923  TStreamerInfo *allocator = *(TStreamerInfo**)(p + fVirtualInfoLoc[0]);
4924  if (allocator != this) {
4925 
4926  Int_t baseoffset = allocator->GetClass()->GetBaseClassOffset(GetClass());
4927 
4928  p -= baseoffset;
4929  allocator->DestructorImpl(p, kFALSE);
4930  return;
4931  }
4932  }
4933  DestructorImpl(p, dtorOnly);
4934 }
4935 
4936 ////////////////////////////////////////////////////////////////////////////////
4937 /// Destroy an array of emulated objects, with optional delete.
4938 
4939 void TStreamerInfo::DeleteArray(void* ary, Bool_t dtorOnly)
4940 {
4941  // Do nothing if passed a null pointer.
4942  if (ary == 0) return;
4943 
4944  //???FIX ME: What about varying length arrays?
4945 
4946  Long_t* r = (Long_t*) ary;
4947  Long_t arrayLen = r[-1];
4948  Long_t size = r[-2];
4949  char* memBegin = (char*) &r[-2];
4950 
4951  char* p = ((char*) ary) + ((arrayLen - 1) * size);
4952  for (Long_t cnt = 0; cnt < arrayLen; ++cnt, p -= size) {
4953  // Destroy each element, but do not delete it.
4954  Destructor(p, kTRUE);
4955  } // for arrayItemSize
4956 
4957  if (!dtorOnly) {
4958  delete[] memBegin;
4959  }
4960 }
4961 
4962 ////////////////////////////////////////////////////////////////////////////////
4963 /// print value of element i in object at pointer
4964 /// The function may be called in two ways:
4965 /// -method1 len < 0
4966 /// i is assumed to be the TStreamerElement number i in StreamerInfo
4967 /// -method2 len >= 0
4968 /// i is the type
4969 /// address of variable is directly pointer.
4970 /// len is the number of elements to be printed starting at pointer.
4971 
4972 void TStreamerInfo::PrintValue(const char *name, char *pointer, Int_t i, Int_t len, Int_t lenmax) const
4973 {
4974  char *ladd;
4975  Int_t atype,aleng;
4976  printf(" %-15s = ",name);
4977 
4978  TStreamerElement * aElement = 0;
4979  Int_t *count = 0;
4980  if (len >= 0) {
4981  ladd = pointer;
4982  atype = i;
4983  aleng = len;
4984  } else {
4985  if (i < 0) {
4986  if (pointer==0) {
4987  printf("NULL\n");
4988  } else {
4989  const static TClassRef stringClass("string");
4990  if (fClass == stringClass) {
4991  std::string *st = (std::string*)(pointer);
4992  printf("%s\n",st->c_str());
4993  } else if (fClass == TString::Class()) {
4994  TString *st = (TString*)(pointer);
4995  printf("%s\n",st->Data());
4996  } else {
4997  printf("(%s*)0x%lx\n",GetName(),(ULong_t)pointer);
4998  }
4999  }
5000  return;
5001  }
5002  ladd = pointer + fCompFull[i]->fOffset;
5003  atype = fCompFull[i]->fNewType;
5004  aleng = fCompFull[i]->fLength;
5005  aElement = (TStreamerElement*)fCompFull[i]->fElem;
5006  count = (Int_t*)(pointer+fCompFull[i]->fMethod);
5007  }
5008  if (aleng > lenmax) aleng = lenmax;
5009 
5010  PrintValueAux(ladd,atype,aElement,aleng,count);
5011  printf("\n");
5012 }
5013 
5014 ////////////////////////////////////////////////////////////////////////////////
5015 /// Print value of element i in a TClonesArray.
5016 
5017 void TStreamerInfo::PrintValueClones(const char *name, TClonesArray *clones, Int_t i, Int_t eoffset, Int_t lenmax) const
5018 {
5019  if (!clones) {printf(" %-15s = \n",name); return;}
5020  printf(" %-15s = ",name);
5021  Int_t nc = clones->GetEntriesFast();
5022  if (nc > lenmax) nc = lenmax;
5023 
5024  Int_t offset = eoffset + fCompFull[i]->fOffset;
5025  TStreamerElement *aElement = (TStreamerElement*)fCompFull[i]->fElem;
5026  int aleng = fCompFull[i]->fLength;
5027  if (aleng > lenmax) aleng = lenmax;
5028 
5029  for (Int_t k=0;k < nc;k++) {
5030  char *pointer = (char*)clones->UncheckedAt(k);
5031  char *ladd = pointer+offset;
5032  Int_t *count = (Int_t*)(pointer+fCompFull[i]->fMethod);
5033  PrintValueAux(ladd,fCompFull[i]->fNewType,aElement, aleng, count);
5034  if (k < nc-1) printf(", ");
5035  }
5036  printf("\n");
5037 }
5038 
5039 ////////////////////////////////////////////////////////////////////////////////
5040 /// Print value of element i in a TClonesArray.
5041 
5042 void TStreamerInfo::PrintValueSTL(const char *name, TVirtualCollectionProxy *cont, Int_t i, Int_t eoffset, Int_t lenmax) const
5043 {
5044  if (!cont) {printf(" %-15s = \n",name); return;}
5045  printf(" %-15s = ",name);
5046  Int_t nc = cont->Size();
5047  if (nc > lenmax) nc = lenmax;
5048 
5049  Int_t offset = eoffset + fCompFull[i]->fOffset;
5050  TStreamerElement *aElement = (TStreamerElement*)fCompFull[i]->fElem;
5051  int aleng = fCompFull[i]->fLength;
5052  if (aleng > lenmax) aleng = lenmax;
5053 
5054  for (Int_t k=0;k < nc;k++) {
5055  char *pointer = (char*)cont->At(k);
5056  char *ladd = pointer+offset;
5057  Int_t *count = (Int_t*)(pointer+fCompFull[i]->fMethod);
5058  PrintValueAux(ladd,fCompFull[i]->fNewType,aElement, aleng, count);
5059  if (k < nc-1) printf(", ");
5060  }
5061  printf("\n");
5062 }
5063 
5064 ////////////////////////////////////////////////////////////////////////////////
5065 /// Stream an object of class TStreamerInfo.
5066 
5067 void TStreamerInfo::Streamer(TBuffer &R__b)
5068 {
5069  UInt_t R__s, R__c;
5070  if (R__b.IsReading()) {
5071  Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
5072  fOldVersion = R__v;
5073  if (R__v > 1) {
5074  //R__b.ReadClassBuffer(TStreamerInfo::Class(), this, R__v, R__s, R__c);
5075  R__b.ClassBegin(TStreamerInfo::Class(), R__v);
5076  R__b.ClassMember("TNamed");
5077  TNamed::Streamer(R__b);
5078  fName = TClassEdit::GetLong64_Name( fName.Data() ).c_str();
5079  R__b.ClassMember("fCheckSum","UInt_t");
5080  R__b >> fCheckSum;
5081  R__b.ClassMember("fClassVersion","Int_t");
5082  R__b >> fClassVersion;
5084  R__b.ClassMember("fElements","TObjArray*");
5085  R__b >> fElements;
5087  R__b.SetBufferOffset(R__s+R__c+sizeof(UInt_t));
5091 
5092  if (R__b.GetParent() && R__b.GetVersionOwner() < 50000)
5093  {
5094  // In some older files, the type of the TStreamerElement was not
5095  // as we (now) expect.
5096  Int_t nobjects = fElements->GetEntriesFast();
5097  TClass *basic = TStreamerBasicType::Class();
5098  for (Int_t i = 0; i < nobjects; i++) {
5099  TStreamerElement *el = (TStreamerElement*)fElements->UncheckedAt(i);
5100  TStreamerElement *rel = 0;
5101  if ( el->IsA() == basic ) {
5102  switch (el->GetType()) {
5103  default: break; /* nothing */
5104  case TStreamerInfo::kObject: /*61*/
5105  rel = new TStreamerObject(el->GetName(),el->GetTitle(),el->GetOffset(),el->GetTypeName());
5106  break;
5107  case TStreamerInfo::kAny: /*62*/
5108  rel = new TStreamerObjectAny(el->GetName(),el->GetTitle(),el->GetOffset(),el->GetTypeName());
5109  break;
5110  case TStreamerInfo::kObjectp: /* 63 */
5111  rel = new TStreamerObjectPointer(el->GetName(),el->GetTitle(),el->GetOffset(),el->GetTypeName());
5112  break;
5113  case TStreamerInfo::kObjectP: /* 64 */
5114  rel = new TStreamerObjectPointer(el->GetName(),el->GetTitle(),el->GetOffset(),el->GetTypeName());
5115  break;
5116  case TStreamerInfo::kTString: /* 65 */
5117  rel = new TStreamerObject(el->GetName(),el->GetTitle(),el->GetOffset(),el->GetTypeName());
5118  break;
5119  }
5120  if (rel) {
5121  (*fElements)[i] = rel;
5122  delete el;
5123  }
5124  }
5125  }
5126  }
5127  return;
5128  }
5129  //====process old versions before automatic schema evolution
5130  TNamed::Streamer(R__b);
5131  fName = TClassEdit::GetLong64_Name( fName.Data() ).c_str();
5132  R__b >> fCheckSum;
5133  R__b >> fClassVersion;
5135  R__b >> fElements;
5136  R__b.CheckByteCount(R__s, R__c, TStreamerInfo::IsA());
5137  } else {
5138  R__c = R__b.WriteVersion(TStreamerInfo::IsA(), kTRUE);
5140  R__b.ClassMember("TNamed");
5141  TNamed::Streamer(R__b);
5142  R__b.ClassMember("fCheckSum","UInt_t");
5143  R__b << fCheckSum;
5144  R__b.ClassMember("fClassVersion","Int_t");
5145  R__b << ((fClassVersion > 0) ? fClassVersion : -fClassVersion);
5146 
5147  //------------------------------------------------------------------------
5148  // Stream only non-artificial streamer elements
5149  //////////////////////////////////////////////////////////////////////////
5150 
5151  R__b.ClassMember("fElements","TObjArray*");
5152 #if NOTYET
5153  if (has_no_artificial_member) {
5154  R__b << fElements;
5155  } else
5156 #endif
5157  {
5159  Int_t nobjects = fElements->GetEntriesFast();
5160  TObjArray store( *fElements );
5161  TStreamerElement *el;
5162  for (Int_t i = 0; i < nobjects; i++) {
5163  el = (TStreamerElement*)fElements->UncheckedAt(i);
5164  if( el != 0 && (el->IsA() == TStreamerArtificial::Class() || el->TestBit(TStreamerElement::kRepeat))) {
5165  fElements->RemoveAt( i );
5166  } else if( el !=0 && (el->TestBit(TStreamerElement::kCache) && !el->TestBit(TStreamerElement::kWrite)) ) {
5167  fElements->RemoveAt( i );
5168  }
5169  }
5170  fElements->Compress();
5171  R__b << fElements;
5172  R__ASSERT(!fElements->IsOwner());
5173  *fElements = store;
5174  }
5176  R__b.SetByteCount(R__c, kTRUE);
5177  }
5178 }
5179 
5180 ////////////////////////////////////////////////////////////////////////////////
5181 /// Mark the classindex of the current file as using this TStreamerInfo.
5182 /// This function is deprecated and its functionality is now done by
5183 /// the overloads of TBuffer::TagStreamerInfo.
5184 
5186 {
5187  if (file) {
5188  // If the value of the atomic is kFALSE (equal to expected), change its value
5189  // to kTRUE and return true. Leave it as it is otherwise and return false.
5190  static std::atomic<Bool_t> onlyonce(kFALSE);
5191  Bool_t expected = kFALSE;
5192  if (onlyonce.compare_exchange_strong(expected,kTRUE)) {
5193  Warning("TagFile","This function is deprecated, use TBuffer::TagStreamerInfo instead");
5194  }
5195  TArrayC *cindex = file->GetClassIndex();
5196  Int_t nindex = cindex->GetSize();
5197  if (fNumber < 0 || fNumber >= nindex) {
5198  Error("TagFile","StreamerInfo: %s number: %d out of range[0,%d] in file: %s",
5199  GetName(),fNumber,nindex,file->GetName());
5200  return;
5201  }
5202  if (cindex->fArray[fNumber] == 0) {
5203  cindex->fArray[0] = 1;
5204  cindex->fArray[fNumber] = 1;
5205  }
5206  }
5207 }
5208 
5209 ////////////////////////////////////////////////////////////////////////////////
5210 
5211 #ifdef DOLOOP
5212 #undef DOLOOP
5213 #endif
5214 #define DOLOOP for (k = 0, pointer = arr[0]; k < narr; pointer = arr[++k])
5215 
5216 namespace {
5217  static void PrintCR(int j,Int_t aleng, UInt_t ltype)
5218  {
5219  if (j == aleng-1) printf("\n");
5220  else {
5221  printf(", ");
5222  if (j%ltype == ltype-1) printf("\n ");
5223  }
5224  }
5225 }
5226 
5227 ////////////////////////////////////////////////////////////////////////////////
5228 /// print value of element in object at pointer, type atype, leng aleng or *count
5229 /// The function may be called in two ways:
5230 /// -method1 len < 0
5231 /// i is assumed to be the TStreamerElement number i in StreamerInfo
5232 /// -method2 len >= 0
5233 /// i is the type
5234 /// address of variable is directly pointer.
5235 /// len is the number of elements to be printed starting at pointer.
5236 
5237 void TStreamerInfo::PrintValueAux(char *ladd, Int_t atype, TStreamerElement *aElement, Int_t aleng, Int_t *count)
5238 {
5239  int j;
5240 
5241  //assert(!((kOffsetP + kChar) <= atype && atype <= (kOffsetP + kBool) && count == 0));
5242  switch (atype) {
5243  // basic types
5244  case kBool: {Bool_t *val = (Bool_t* )ladd; printf("%d" ,*val); break;}
5245  case kChar: {Char_t *val = (Char_t* )ladd; printf("%d" ,*val); break;}
5246  case kShort: {Short_t *val = (Short_t* )ladd; printf("%d" ,*val); break;}
5247  case kInt: {Int_t *val = (Int_t* )ladd; printf("%d" ,*val); break;}
5248  case kLong: {Long_t *val = (Long_t* )ladd; printf("%ld",*val); break;}
5249  case kLong64: {Long64_t *val = (Long64_t* )ladd; printf("%lld",*val); break;}
5250  case kFloat: {Float_t *val = (Float_t* )ladd; printf("%f" ,*val); break;}
5251  case kFloat16: {Float_t *val = (Float_t* )ladd; printf("%f" ,*val); break;}
5252  case kDouble: {Double_t *val = (Double_t* )ladd; printf("%g" ,*val); break;}
5253  case kDouble32: {Double_t *val = (Double_t* )ladd; printf("%g" ,*val); break;}
5254  case kUChar: {UChar_t *val = (UChar_t* )ladd; printf("%u" ,*val); break;}
5255  case kUShort: {UShort_t *val = (UShort_t* )ladd; printf("%u" ,*val); break;}
5256  case kUInt: {UInt_t *val = (UInt_t* )ladd; printf("%u" ,*val); break;}
5257  case kULong: {ULong_t *val = (ULong_t* )ladd; printf("%lu",*val); break;}
5258  case kULong64: {ULong64_t *val = (ULong64_t*)ladd; printf("%llu",*val); break;}
5259  case kBits: {UInt_t *val = (UInt_t* )ladd; printf("%d" ,*val); break;}
5260 
5261  // array of basic types array[8]
5262  case kOffsetL + kBool: {Bool_t *val = (Bool_t* )ladd; for(j=0;j<aleng;j++) { printf("%c " ,val[j]); PrintCR(j,aleng,20); } break;}
5263  case kOffsetL + kChar: {Char_t *val = (Char_t* )ladd; for(j=0;j<aleng;j++) { printf("%c " ,val[j]); PrintCR(j,aleng,20); } break;}
5264  case kOffsetL + kShort: {Short_t *val = (Short_t* )ladd; for(j=0;j<aleng;j++) { printf("%d " ,val[j]); PrintCR(j,aleng,10); } break;}
5265  case kOffsetL + kInt: {Int_t *val = (Int_t* )ladd; for(j=0;j<aleng;j++) { printf("%d " ,val[j]); PrintCR(j,aleng,10); } break;}
5266  case kOffsetL + kLong: {Long_t *val = (Long_t* )ladd; for(j=0;j<aleng;j++) { printf("%ld ",val[j]); PrintCR(j,aleng, 5); } break;}
5267  case kOffsetL + kLong64: {Long64_t *val = (Long64_t* )ladd; for(j=0;j<aleng;j++) { printf("%lld ",val[j]);PrintCR(j,aleng, 5); } break;}
5268  case kOffsetL + kFloat: {Float_t *val = (Float_t* )ladd; for(j=0;j<aleng;j++) { printf("%f " ,val[j]); PrintCR(j,aleng, 5); } break;}
5269  case kOffsetL + kFloat16: {Float_t *val = (Float_t* )ladd; for(j=0;j<aleng;j++) { printf("%f " ,val[j]); PrintCR(j,aleng, 5); } break;}
5270  case kOffsetL + kDouble: {Double_t *val = (Double_t* )ladd; for(j=0;j<aleng;j++) { printf("%g " ,val[j]); PrintCR(j,aleng, 5); } break;}
5271  case kOffsetL + kDouble32:{Double_t *val = (Double_t* )ladd; for(j=0;j<aleng;j++) { printf("%g " ,val[j]); PrintCR(j,aleng, 5); } break;}
5272  case kOffsetL + kUChar: {UChar_t *val = (UChar_t* )ladd; for(j=0;j<aleng;j++) { printf("%u " ,val[j]); PrintCR(j,aleng,20); } break;}
5273  case kOffsetL + kUShort: {UShort_t *val = (UShort_t* )ladd; for(j=0;j<aleng;j++) { printf("%u " ,val[j]); PrintCR(j,aleng,10); } break;}
5274  case kOffsetL + kUInt: {UInt_t *val = (UInt_t* )ladd; for(j=0;j<aleng;j++) { printf("%u " ,val[j]); PrintCR(j,aleng, 5); } break;}
5275  case kOffsetL + kULong: {ULong_t *val = (ULong_t* )ladd; for(j=0;j<aleng;j++) { printf("%lu ",val[j]); PrintCR(j,aleng, 5); } break;}
5276  case kOffsetL + kULong64: {ULong64_t *val = (ULong64_t*)ladd; for(j=0;j<aleng;j++) { printf("%llu ",val[j]);PrintCR(j,aleng, 5); } break;}
5277  case kOffsetL + kBits: {UInt_t *val = (UInt_t* )ladd; for(j=0;j<aleng;j++) { printf("%d " ,val[j]); PrintCR(j,aleng, 5); } break;}
5278 
5279  // pointer to an array of basic types array[n]
5280  case kOffsetP + kBool: {Bool_t **val = (Bool_t** )ladd; for(j=0;j<*count;j++) { printf("%d " ,(*val)[j]); PrintCR(j,aleng,20); } break;}
5281  case kOffsetP + kChar: {Char_t **val = (Char_t** )ladd; for(j=0;j<*count;j++) { printf("%d " ,(*val)[j]); PrintCR(j,aleng,20); } break;}
5282  case kOffsetP + kShort: {Short_t **val = (Short_t** )ladd; for(j=0;j<*count;j++) { printf("%d " ,(*val)[j]); PrintCR(j,aleng,10); } break;}
5283  case kOffsetP + kInt: {Int_t **val = (Int_t** )ladd; for(j=0;j<*count;j++) { printf("%d " ,(*val)[j]); PrintCR(j,aleng,10); } break;}
5284  case kOffsetP + kLong: {Long_t **val = (Long_t** )ladd; for(j=0;j<*count;j++) { printf("%ld ",(*val)[j]); PrintCR(j,aleng, 5); } break;}
5285  case kOffsetP + kLong64: {Long64_t **val = (Long64_t**)ladd; for(j=0;j<*count;j++) { printf("%lld ",(*val)[j]); PrintCR(j,aleng, 5); } break;}
5286  case kOffsetP + kFloat: {Float_t **val = (Float_t** )ladd; for(j=0;j<*count;j++) { printf("%f " ,(*val)[j]); PrintCR(j,aleng, 5); } break;}
5287  case kOffsetP + kFloat16: {Float_t **val = (Float_t** )ladd; for(j=0;j<*count;j++) { printf("%f " ,(*val)[j]); PrintCR(j,aleng, 5); } break;}
5288  case kOffsetP + kDouble: {Double_t **val = (Double_t**)ladd; for(j=0;j<*count;j++) { printf("%g " ,(*val)[j]); PrintCR(j,aleng, 5); } break;}
5289  case kOffsetP + kDouble32:{Double_t **val = (Double_t**)ladd; for(j=0;j<*count;j++) { printf("%g " ,(*val)[j]); PrintCR(j,aleng, 5); } break;}
5290  case kOffsetP + kUChar: {UChar_t **val = (UChar_t** )ladd; for(j=0;j<*count;j++) { printf("%u " ,(*val)[j]); PrintCR(j,aleng,20); } break;}
5291  case kOffsetP + kUShort: {UShort_t **val = (UShort_t**)ladd; for(j=0;j<*count;j++) { printf("%u " ,(*val)[j]); PrintCR(j,aleng,10); } break;}
5292  case kOffsetP + kUInt: {UInt_t **val = (UInt_t** )ladd; for(j=0;j<*count;j++) { printf("%u " ,(*val)[j]); PrintCR(j,aleng, 5); } break;}
5293  case kOffsetP + kULong: {ULong_t **val = (ULong_t** )ladd; for(j=0;j<*count;j++) { printf("%lu ",(*val)[j]); PrintCR(j,aleng, 5); } break;}
5294  case kOffsetP + kULong64: {ULong64_t**val = (ULong64_t**)ladd; for(j=0;j<*count;j++){ printf("%llu ",(*val)[j]); PrintCR(j,aleng, 5); } break;}
5295 
5296  // array counter //[n]
5297  case kCounter: {Int_t *val = (Int_t*)ladd; printf("%d",*val); break;}
5298  // char *
5299  case kCharStar:{
5300  char **val = (char**)ladd;
5301  if (*val) printf("%s",*val);
5302  break;
5303  }
5304  // Class * derived from TObject with comment field //->
5305  case kObjectp: {
5306  TObject **obj = (TObject**)(ladd);
5308  printf("(%s*)%lx",el ? el->GetClass()->GetName() : "unknown_type",(Long_t)(*obj));
5309  break;
5310  }
5311 
5312  // Class* derived from TObject
5313  case kObjectP: {
5314  TObject **obj = (TObject**)(ladd);
5316  printf("(%s*)%lx",el ? el->GetClass()->GetName() : "unknown_type",(Long_t)(*obj));
5317  break;
5318  }
5319 
5320  // Class derived from TObject
5321  case kObject: {
5322  TObject *obj = (TObject*)(ladd);
5323  printf("%s",obj->GetName());
5324  break;
5325  }
5326 
5327  // Special case for TString, TObject, TNamed
5328  case kTString: {
5329  TString *st = (TString*)(ladd);
5330  printf("%s",st->Data());
5331  break;
5332  }
5333  case kTObject: {
5334  TObject *obj = (TObject*)(ladd);
5335  printf("%s",obj->GetName());
5336  break;
5337  }
5338  case kTNamed: {
5339  TNamed *named = (TNamed*) (ladd);
5340  printf("%s/%s",named->GetName(),named->GetTitle());
5341  break;
5342  }
5343 
5344  // Class * not derived from TObject with comment field //->
5345  case kAnyp: {
5346  TObject **obj = (TObject**)(ladd);
5348  printf("(%s*)0x%lx",el ? el->GetClass()->GetName() : "unknown_type",(Long_t)(*obj));
5349  break;
5350  }
5351 
5352  // Class* not derived from TObject
5353  case kAnyP: {
5354  TObject **obj = (TObject**)(ladd);
5356  printf("(%s*)0x%lx",el ? el->GetClass()->GetName() : "unknown_type",(Long_t)(*obj));
5357  break;
5358  }
5359  // Any Class not derived from TObject
5360  case kOffsetL + kObjectp:
5361  case kOffsetL + kObjectP:
5362  case kAny: {
5363  printf("printing kAny case (%d)",atype);
5364 // if (aElement) {
5365 // TMemberStreamer *pstreamer = aElement->GetStreamer();
5366 // if (pstreamer == 0) {
5367 // //printf("ERROR, Streamer is null\n");
5368 // //aElement->ls();
5369 // break;
5370 // }
5371 // //(*pstreamer)(b,ladd,0);
5372 // }
5373  break;
5374  }
5375  // Base Class
5376  case kBase: {
5377  printf("printing kBase case (%d)",atype);
5378  //aElement->ReadBuffer(b,pointer);
5379  break;
5380  }
5381 
5382  case kOffsetL + kObject:
5383  case kOffsetL + kTString:
5384  case kOffsetL + kTObject:
5385  case kOffsetL + kTNamed:
5386  case kStreamer: {
5387  printf("printing kStreamer case (%d)",atype);
5388 // TMemberStreamer *pstreamer = aElement->GetStreamer();
5389 // if (pstreamer == 0) {
5390 // //printf("ERROR, Streamer is null\n");
5391 // //aElement->ls();
5392 // break;
5393 // }
5394 // //UInt_t start,count;
5395 // //b.ReadVersion(&start, &count);
5396 // //(*pstreamer)(b,ladd,0);
5397 // //b.CheckByteCount(start,count,IsA());
5398  break;
5399  }
5400 
5401  case kStreamLoop: {
5402  printf("printing kStreamLoop case (%d)",atype);
5403 // TMemberStreamer *pstreamer = aElement->GetStreamer();
5404 // if (pstreamer == 0) {
5405 // //printf("ERROR, Streamer is null\n");
5406 // //aElement->ls();
5407 // break;
5408 // }
5409  //Int_t *counter = (Int_t*)(count);
5410  //UInt_t start,count;
5411  ///b.ReadVersion(&start, &count);
5412  //(*pstreamer)(b,ladd,*counter);
5413  //b.CheckByteCount(start,count,IsA());
5414  break;
5415  }
5416  case kSTL: {
5417  if (aElement) {
5418  static TClassRef stringClass("string");
5419  if (ladd && aElement->GetClass() == stringClass) {
5420  std::string *st = (std::string*)(ladd);
5421  printf("%s",st->c_str());
5422  } else {
5423  printf("(%s*)0x%lx",aElement->GetClass()->GetName(),(Long_t)(ladd));
5424  }
5425  } else {
5426  printf("(unknown_type*)0x%lx",(Long_t)(ladd));
5427  }
5428  break;
5429  }
5430  }
5431 }
5432 
5433 ////////////////////////////////////////////////////////////////////////////////
5434 ///function called by the TClass constructor when replacing an emulated class
5435 ///by the real class
5436 
5437 void TStreamerInfo::Update(const TClass *oldcl, TClass *newcl)
5438 {
5439  TStreamerElement *element;
5440  TIter nextElement(GetElements());
5441  while ((element = (TStreamerElement*)nextElement())) {
5442  element->Update(oldcl,newcl);
5443  }
5444  for (Int_t i=0;i < fNslots;i++) {
5445  fComp[i].Update(oldcl,newcl);
5446  }
5447 }
5448 
5449 ////////////////////////////////////////////////////////////////////////////////
5450 /// Update the TClass pointer cached in this object.
5451 
5453 {
5454  if (fType != -1) {
5455  if (fClass == oldcl)
5456  fClass = newcl;
5457  else if (fClass == 0)
5459  }
5460 }
5461 
5462 ////////////////////////////////////////////////////////////////////////////////
5463 /// Generate emulated collection proxy for a given class.
5464 
5466 TStreamerInfo::GenEmulatedProxy(const char* class_name, Bool_t silent)
5467 {
5468  return TCollectionProxyFactory::GenEmulatedProxy(class_name, silent);
5469 }
5470 
5471 ////////////////////////////////////////////////////////////////////////////////
5472 /// Generate emulated class streamer for a given collection class.
5473 
5475 TStreamerInfo::GenEmulatedClassStreamer(const char* class_name, Bool_t silent)
5476 {
5477  return TCollectionProxyFactory::GenEmulatedClassStreamer(class_name, silent);
5478 }
5479 
5480 ////////////////////////////////////////////////////////////////////////////////
5481 /// Generate proxy from static functions.
5482 
5484 TStreamerInfo::GenExplicitProxy( const ::ROOT::TCollectionProxyInfo &info, TClass *cl )
5485 {
5487 }
5488 
5489 ////////////////////////////////////////////////////////////////////////////////
5490 /// Generate class streamer from static functions.
5491 
5493 TStreamerInfo::GenExplicitClassStreamer( const ::ROOT::TCollectionProxyInfo &info, TClass *cl )
5494 {
5496 }
EState GetState() const
Definition: TClass.h:443
const int ndata
TObject * GetParent() const
Return pointer to parent of this buffer.
Definition: TBuffer.cxx:231
Describe Streamer information for one class version.
Definition: TStreamerInfo.h:47
Small helper to read a TBuffer containing a TClonesArray into any valid collection.
virtual const char * BaseName(const char *pathname)
Base name of a file name. Base name of /user/root is root.
Definition: TSystem.cxx:929
virtual Int_t GetEntries() const
Definition: TCollection.h:92
virtual const char * GetTitle() const
Returns title of object.
Definition: TNamed.h:52
virtual void * New(void *obj=0)=0
void SetBufferOffset(Int_t offset=0)
Definition: TBuffer.h:90
virtual Int_t GetCollectionType() const =0
Int_t fClassVersion
Class version identifier.
Definition: TStreamerInfo.h:97
TList * GetListOfBases()
Return list containing the TBaseClass(es) of a class.
Definition: TClass.cxx:3439
static std::atomic< Int_t > fgCount
Number of TStreamerInfo instances.
An array of TObjects.
Definition: TObjArray.h:39
static void R__TObjArray_InsertBefore(TObjArray *arr, TObject *newobj, TObject *oldobj)
virtual Int_t GetProperties() const
virtual void ClassBegin(const TClass *, Version_t=-1)=0
virtual void SetOffset(Int_t offset)
TString GetTypeName()
Get basic type of typedef, e,g.
Definition: TDataType.cxx:149
Version_t fOldVersion
! Version of the TStreamerInfo object read from the file
void PrintValueClones(const char *name, TClonesArray *clones, Int_t i, Int_t eoffset, Int_t lenmax=1000) const
Print value of element i in a TClonesArray.
ROOT::ESTLType IsSTLCont(std::string_view type)
type : type name: vector&lt;list&lt;classA,allocator&gt;,allocator&gt; result: 0 : not stl container code of cont...
T GetTypedValue(char *pointer, Int_t i, Int_t j, Int_t len) const
Return value of element i in object at pointer.
Int_t GetOffset() const
long long Long64_t
Definition: RtypesCore.h:69
static void PrintValueAux(char *ladd, Int_t atype, TStreamerElement *aElement, Int_t aleng, Int_t *count)
print value of element in object at pointer, type atype, leng aleng or *count The function may be cal...
const char * GetTypeName() const
void BuildEmulated(TFile *file)
Create an Emulation TStreamerInfo object.
TStreamerInfoActions::TActionSequence * fWriteMemberWiseVecPtr
! List of write action resulting from the compilation for use in member wise streaming.
Bool_t IsReading() const
Definition: TBuffer.h:83
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class &quot;classname&quot;.
Definition: TObject.cxx:488
short Version_t
Definition: RtypesCore.h:61
virtual Bool_t CompareContent(TClass *cl, TVirtualStreamerInfo *info, Bool_t warn, Bool_t complete, TFile *file)=0
Int_t GetType() const
Definition: TDataType.h:70
Ssiz_t Length() const
Definition: TString.h:390
TLine * line
Int_t GetUnitSize() const
Get the sizeof the underlying type of the data member (i.e.
virtual TClass * GetClass() const =0
Collectable string class.
Definition: TObjString.h:32
float Float_t
Definition: RtypesCore.h:53
Equal to TDataType&#39;s kchar.
virtual void SetSize(Int_t dsize)
Int_t GetLast() const
Return index of last object in array.
Definition: TObjArray.cxx:528
return c
const char Option_t
Definition: RtypesCore.h:62
virtual TClass * GetValueClass() const =0
virtual void Delete(Option_t *option="")
Remove all objects from the array AND delete all heap based objects.
Definition: TObjArray.cxx:329
All ROOT classes may have RTTI (run time type identification) support added.
Definition: TDataMember.h:33
int GetSplit(const char *type, std::vector< std::string > &output, int &nestedLoc, EModType mode=TClassEdit::kNone)
Stores in output (after emptying it) the split type.
Definition: TClassEdit.cxx:938
static TString GetHeaderName(const char *name, const TList *extrainfos, Bool_t includeNested=kFALSE)
Return the header name containing the description of name.
double T(double x)
Definition: ChebyshevPol.h:34
R__EXTERN TVirtualMutex * gInterpreterMutex
Definition: TInterpreter.h:46
T GetTypedValueSTLP(TVirtualCollectionProxy *cont, Int_t i, Int_t j, Int_t k, Int_t eoffset) const
Return value of element i in object number j in a TClonesArray and eventually element k in a sub-arra...
TString & ReplaceAll(const TString &s1, const TString &s2)
Definition: TString.h:635
TClass * GetClassPointer(Bool_t load=kTRUE)
Get pointer to the base class TClass.
Definition: TBaseClass.cxx:63
unsigned short UShort_t
Definition: RtypesCore.h:36
Bool_t IsTObject() const
Return kTRUE is the class inherits from TObject.
Definition: TClass.cxx:5561
UInt_t GetBaseCheckSum()
void Update(const TClass *oldcl, TClass *newcl)
Update the TClass pointer cached in this object.
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
Definition: TObject.cxx:899
void InsertArtificialElements(std::vector< const ROOT::TSchemaRule * > &rules)
Insert new members as expressed in the array of TSchemaRule(s).
static TClassStreamer * GenEmulatedClassStreamer(const char *class_name, Bool_t silent)
Generate emulated class streamer for a given collection class.
const char * GetCountClass() const
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format...
Definition: TFile.h:50
Long_t Property() const
Set TObject::fBits and fStreamerType to cache information about the class.
Definition: TClass.cxx:5661
Buffer base class used for serializing objects.
Definition: TBuffer.h:42
virtual void SetTypeName(const char *name)
Bool_t IsPersistent() const
Definition: TDataMember.h:89
#define R__ASSERT(e)
Definition: TError.h:98
TClass * GetNewClass() const
virtual Int_t CheckByteCount(UInt_t startpos, UInt_t bcnt, const TClass *clss)=0
#define gROOT
Definition: TROOT.h:379
TList * GetListOfDataMembers(Bool_t load=kTRUE)
Return list containing the TDataMembers of a class.
Definition: TClass.cxx:3549
void SetReadFunc(ROOT::TSchemaRule::ReadFuncPtr_t val)
void ForceWriteInfo(TFile *file, Bool_t force=kFALSE)
Recursively mark streamer infos for writing to a file.
virtual Bool_t IsTransient() const
Return kTRUE if the element represent an entity that is not written to the disk (transient members...
void * New(void *obj=0)
An emulated object is created at address obj, if obj is null we allocate memory for the object...
virtual Int_t GetSize() const
Returns size of this element in bytes.
EUniquePtrOffset
Basic string class.
Definition: TString.h:137
Bool_t IsForeign() const
Return kTRUE is the class is Foreign (the class does not have a Streamer method). ...
Definition: TClass.cxx:5570
TVirtualStreamerInfo * GetCurrentStreamerInfo()
Definition: TClass.h:393
void ToLower()
Change string to lower-case.
Definition: TString.cxx:1089
void DestructorImpl(void *p, Bool_t dtorOnly)
Internal part of the destructor.
int Int_t
Definition: RtypesCore.h:41
static void GeneratePostDeclaration(FILE *fp, const TVirtualStreamerInfo *info, char *inclist)
Add to the header file anything that need to appear after the class declaration (this includes some #...
bool Bool_t
Definition: RtypesCore.h:59
TDataType * GetDataType() const
Definition: TDataMember.h:74
void Reset()
Definition: TClassRef.h:76
virtual void Clear(const char *opt="")=0
Bool_t IsaPointer() const
Return true if data member is a pointer.
const Bool_t kFALSE
Definition: Rtypes.h:92
virtual TObject * FindObject(const char *name) const
Find an object in this list using its name.
Definition: TList.cxx:497
Int_t GenerateHeaderFile(const char *dirname, const TList *subClasses=0, const TList *extrainfos=0)
Generate header file for the class described by this TStreamerInfo the function is called by TFile::M...
Cache the value in memory than is not part of the object but is accessible via a SchemaRule.
Type GetType(const std::string &Name)
Definition: Systematics.cxx:34
static const char * GetElementCounterStart(const char *dmTitle)
Given a comment/title declaring an array counter, for example: ~~~ {.cpp}.
Int_t fNdata
!number of optimized elements
TVirtualStreamerInfo * FindStreamerInfoAbstractEmulated(UInt_t checksum) const
For the case where the requestor class is emulated and this class is abstract, returns a pointer to t...
Definition: TClass.cxx:4489
virtual Bool_t IsBase() const
Return kTRUE if the element represent a base class.
bool IsSTLBitset(const char *type)
Return true is the name is std::bitset&lt;number&gt; or bitset&lt;number&gt;
virtual void SetArrayDim(Int_t dim)
Set number of array dimensions.
ULong_t * fVirtualInfoLoc
![fNVirtualInfoLoc] Location of the pointer to the TStreamerInfo inside the object (when emulated) ...
Int_t GetEntriesFast() const
Definition: TObjArray.h:66
TString & Prepend(const char *cs)
Definition: TString.h:604
Abstract base class for accessing the data-members of a class.
virtual UInt_t WriteVersion(const TClass *cl, Bool_t useBcnt=kFALSE)=0
Int_t GetBaseVersion()
const char * Class
Definition: TXMLSetup.cxx:64
Int_t GetType(Int_t id) const
virtual EDataType GetType() const =0
Int_t GetMaxIndex(Int_t dim) const
Return maximum index for array dimension &quot;dim&quot;.
virtual void SetMaxIndex(Int_t dim, Int_t max)
set maximum index for array with dimension dim
virtual void ForceWriteInfo(TFile *file, Bool_t force=kFALSE)=0
void Destructor(void *p, Bool_t dtorOnly=kFALSE)
Emulated destructor for this class.
static Proxy_t * GenExplicitProxy(const ::ROOT::TCollectionProxyInfo &info, TClass *cl)
Generate proxy from static functions.
void DeleteArray(void *p, Bool_t dtorOnly=kFALSE)
Destroy an array of emulated objects, with optional delete.
const char * GetFullTypeName() const
Get full type description of data member, e,g.: &quot;class TDirectory*&quot;.
void Reset()
Definition: TCollection.h:161
TCompInfo ** fCompFull
![fElements-&gt;GetEntries()]
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition: TObject.cxx:739
const char * GetArrayIndex() const
If the data member is pointer and has a valid array size in its comments GetArrayIndex returns a stri...
Bool_t IsVersioned() const
Definition: TClass.h:463
TClass * GetActualClass(const void *obj) const
Assuming that obj points to (the part of) an object that is of the type described by this streamerInf...
if object in a list can be deleted
Definition: TObject.h:56
void ComputeSize()
Compute total size of all persistent elements of the class.
TList * GetListOfRealData() const
Definition: TClass.h:405
TStreamerInfoActions::TActionSequence * fReadMemberWise
! List of read action resulting from the compilation for use in member wise streaming.
const char * Data() const
Definition: TString.h:349
virtual TObject * FindObject(const char *name) const
Find an object in this collection using its name.
Definition: TObjArray.cxx:396
Int_t fSize
!size of the persistent class
Int_t GetBaseClassOffset(const TClass *toBase, void *address=0, bool isDerivedObject=true)
Definition: TClass.cxx:2696
virtual void Fatal(const char *method, const char *msgfmt,...) const
Issue fatal error message.
Definition: TObject.cxx:953
virtual void ClassMember(const char *, const char *=0, Int_t=-1, Int_t=-1)=0
virtual void ls(Option_t *option="") const
The ls function lists the contents of a class on stdout.
Definition: TObject.cxx:537
Bool_t MatchLegacyCheckSum(UInt_t checksum) const
Return true if the checksum passed as argument is one of the checksum value produced by the older che...
Definition: TClass.cxx:6040
virtual Int_t GetClassVersion() const =0
const char * GetTrueTypeName() const
Get full type description of data member, e,g.: &quot;class TDirectory*&quot;.
virtual TVirtualCollectionProxy * GenEmulatedProxy(const char *class_name, Bool_t silent)
Generate emulated collection proxy for a given class.
friend class TClonesArray
Definition: TObject.h:198
#define READ_ARRAY(TYPE_t)
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString...
Definition: TString.cxx:2335
virtual void Init(TObject *obj=0)
Initliaze the element.
virtual TClassStreamer * GenEmulatedClassStreamer(const char *class_name, Bool_t silent)
Generate emulated class streamer for a given collection class.
const char * GetCountClass() const
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:33
virtual TVirtualCollectionProxy * GenExplicitProxy(const ::ROOT::Detail::TCollectionProxyInfo &info, TClass *cl)
Generate proxy from static functions.
virtual Int_t GetVersionOwner() const =0
ECheckSum
Definition: TClass.h:102
std::string GetNameForIO(const std::string &templateInstanceName, TClassEdit::EModType mode=TClassEdit::kNone, bool *hasChanged=nullptr)
void * New(ENewType defConstructor=kClassNew, Bool_t quiet=kFALSE) const
Return a pointer to a newly allocated object of this class.
Definition: TClass.cxx:4692
Int_t GetOnFileClassVersion() const
Int_t GetDelta()
Get offset from &quot;this&quot; to part of base class.
Definition: TBaseClass.cxx:75
#define DeleteBasicPointer(addr, element, name)
void Clear()
Clear string without changing its capacity.
Definition: TString.cxx:1140
std::string ResolveTypedef(const char *tname, bool resolveAll=false)
Bool_t MatchLegacyCheckSum(UInt_t checksum) const
Return true if the checksum passed as argument is one of the checksum value produced by the older che...
virtual void SetNewClass(TClass *cl)
virtual Bool_t IsaPointer() const
Int_t fNfulldata
!number of elements
T GetTypedValueSTL(TVirtualCollectionProxy *cont, Int_t i, Int_t j, Int_t k, Int_t eoffset) const
Return value of element i in object number j in a TClonesArray and eventually element k in a sub-arra...
TString & Append(const char *cs)
Definition: TString.h:492
std::vector< std::vector< double > > Data
TStreamerInfoActions::TActionSequence * fReadObjectWise
! List of read action resulting from the compilation.
virtual TClassStreamer * GenExplicitClassStreamer(const ::ROOT::Detail::TCollectionProxyInfo &info, TClass *cl)
Generate class streamer from static functions.
virtual TObject * Clone(const char *newname="") const
Make a clone of an object using the Streamer facility.
Definition: TNamed.cxx:65
TClass * GetClass() const
bool IsStdArray(std::string_view name)
Definition: TClassEdit.h:180
static UInt_t GenerateForwardDeclaration(FILE *fp, const char *clname, char *inclist, Bool_t implementEmptyClass, Bool_t needGenericTemplate, const TList *extrainfos)
Insert a (complete) forward declaration for the class &#39;clname&#39;.
static void R__WriteMoveConstructorBody(FILE *file, const TString &protoname, TIter &next)
Write down the body of the &#39;move&#39; constructor.
XFontStruct * id
Definition: TGX11.cxx:108
void SetCountClass(const char *clname)
void RegisterStreamerInfo(TVirtualStreamerInfo *info)
Register the StreamerInfo in the given slot, change the State of the TClass as appropriate.
Definition: TClass.cxx:6816
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:925
Bool_t IsObject() const
Definition: TRealData.h:60
Bool_t operator!=(const TDatime &d1, const TDatime &d2)
Definition: TDatime.h:103
UInt_t fCheckSum
Checksum of original class.
Definition: TStreamerInfo.h:96
virtual const char * GetInclude() const
void GenerateDeclaration(FILE *fp, FILE *sfp, const TList *subClasses, Bool_t top=kTRUE)
Write the Declaration of class.
std::string GetLong64_Name(const char *original)
Replace &#39;long long&#39; and &#39;unsigned long long&#39; by &#39;Long64_t&#39; and &#39;ULong64_t&#39;.
Definition: TClassEdit.cxx:817
void Error(const char *location, const char *msgfmt,...)
Int_t GetClassVersion() const
Int_t GetArrayDim() const
static void AddInclude(FILE *fp, const char *header, Bool_t system, char *inclist)
Add an include statement, if it has not already been added.
TVirtualStreamerInfo * FindStreamerInfo(TObjArray *arr, UInt_t checksum) const
Find the TVirtualStreamerInfo in the StreamerInfos corresponding to checksum.
Definition: TClass.cxx:6603
virtual void Update(const TClass *oldClass, TClass *newClass)
function called by the TClass constructor when replacing an emulated class by the real class ...
UInt_t GetCheckSum(ECheckSum code=kCurrentCheckSum) const
Call GetCheckSum with validity check.
Definition: TClass.cxx:6051
const Int_t kMaxLen
Definition: TDirectory.cxx:31
static T GetTypedValueAux(Int_t type, void *ladd, int k, Int_t len)
Get the value from inside a collection.
virtual void SetStreamer(TMemberStreamer *streamer)
set pointer to Streamer function for this element
A doubly linked list.
Definition: TList.h:47
virtual void Destructor(void *p, Bool_t dtorOnly=kFALSE) const
static void R__WriteDestructorBody(FILE *file, TIter &next)
void PrintValue(const char *name, char *pointer, Int_t i, Int_t len, Int_t lenmax=1000) const
print value of element i in object at pointer The function may be called in two ways: -method1 len &lt; ...
TClass * GetBaseClass(const char *classname)
Return pointer to the base class &quot;classname&quot;.
Definition: TClass.cxx:2562
TObject * UncheckedAt(Int_t i) const
Definition: TObjArray.h:91
virtual void Update(const TClass *oldClass, TClass *newClass)
function called by the TClass constructor when replacing an emulated class by the real class ...
TRealData * GetRealData(const char *name) const
Return pointer to TRealData element with name &quot;name&quot;.
Definition: TClass.cxx:3266
void BuildRealData(void *pointer=0, Bool_t isTransient=kFALSE)
Build a full list of persistent data members.
Definition: TClass.cxx:1930
TClass * fClass
!pointer to class
void SetErrorMessage(const char *msg)
static void R__TObjArray_InsertAt(TObjArray *arr, TObject *obj, Int_t at)
Bool_t HasRuleWithSourceClass(const TString &source) const
Return True if we have any rule whose source class is &#39;source&#39;.
void ResetClassVersion(TClass *, const char *, Short_t)
Global function to update the version number.
Int_t GetOffset(const char *) const
Return the offset of the data member as indicated by this StreamerInfo.
const char * GetTypeName() const
Get type of data member, e,g.: &quot;class TDirectory*&quot; -&gt; &quot;TDirectory&quot;.
TObjArray * fElements
Array of TStreamerElements.
UInt_t GenerateIncludes(FILE *fp, char *inclist, const TList *extrainfos)
Add to the header file, the #include need for this class.
void ls(Option_t *option="") const
List the TStreamerElement list and also the precomputed tables if option contains the string &quot;incOrig...
virtual void AddAtAndExpand(TObject *obj, Int_t idx)
Add object at position idx.
Definition: TObjArray.cxx:222
TRandom2 r(17)
TObjArray * GetElements() const
Long_t GetOffset() const
Get offset from &quot;this&quot;.
R__EXTERN TSystem * gSystem
Definition: TSystem.h:549
void BuildOld()
rebuild the TStreamerInfo structure
void Clear(Option_t *)
If opt contains &#39;built&#39;, reset this StreamerInfo as if Build or BuildOld was never called on it (usef...
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:4346
TClass * GetClass() const
Definition: TDataMember.h:73
Basic data type descriptor (datatype information is obtained from CINT).
Definition: TDataType.h:46
const char * GetTypeNameBasic() const
Return type name of this element in case the type name is not a standard basic type, return the basic type name known to CINT.
void SetCountClass(const char *clname)
Int_t GetMaxIndex(Int_t i) const
Int_t fOnFileClassVersion
!Class version identifier as stored on file.
Definition: TStreamerInfo.h:98
virtual Bool_t HasPointers() const =0
void Destructor(void *obj, Bool_t dtorOnly=kFALSE)
Explicitly call destructor for object.
Definition: TClass.cxx:5049
void IgnoreTObjectStreamer(Bool_t ignore=kTRUE)
When the class kIgnoreTObjectStreamer bit is set, the automatically generated Streamer will not call ...
Definition: TClass.cxx:4555
UInt_t GetCheckSum() const
Bool_t HasInterpreterInfo() const
Definition: TClass.h:374
void Form(const char *fmt,...)
Formats a string using a printf style format descriptor.
Definition: TString.cxx:2322
virtual Bool_t BuildFor(const TClass *cl)
Check if we can build this for foreign class - do we have some rules to do that.
unsigned int UInt_t
Definition: RtypesCore.h:42
Bool_t TestBit(UInt_t f) const
Definition: TObject.h:157
Int_t GetDataMemberOffset(TDataMember *dm, TMemberStreamer *&streamer) const
Compute data member offset.
short Short_t
Definition: RtypesCore.h:35
The TRealData class manages the effective list of all data members for a given class.
Definition: TRealData.h:34
Bool_t CanIgnoreTObjectStreamer()
Definition: TClass.h:358
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:51
static void R__WriteConstructorBody(FILE *file, TIter &next)
TSubString Strip(EStripType s=kTrailing, char c= ' ') const
Return a substring of self stripped at beginning and/or end.
Definition: TString.cxx:1070
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
long double LongDouble_t
Definition: RtypesCore.h:57
Eventhough BIT(13) is taken up by TObject (to preserverse forward compatibility)
Version_t GetClassVersion() const
Definition: TClass.h:382
static TVirtualCollectionProxy * GenEmulatedProxy(const char *class_name, Bool_t silent)
Generate emulated collection proxy for a given class.
TClass * fClass
Not Owned.
Definition: TStreamerInfo.h:61
TString fName
Definition: TNamed.h:36
bool IsStdClass(const char *type)
return true if the class belongs to the std namespace
TString & String()
Definition: TObjString.h:52
virtual void AddAt(TObject *obj, Int_t idx)
Add object at position ids.
Definition: TObjArray.cxx:239
Each class (see TClass) has a linked list of its base class(es).
Definition: TBaseClass.h:35
#define Printf
Definition: TGeoToOCC.h:18
Int_t GetNumber() const
TCompInfo * fComp
![fNslots with less than fElements-&gt;GetEntries()*1.5 used] Compiled info
TStreamerInfoActions::TActionSequence * fWriteMemberWise
! List of write action resulting from the compilation for use in member wise streaming.
Bool_t fIsBuilt
true if the StreamerInfo has been optimized
#define R__LOCKGUARD2(mutex)
Int_t GetSize() const
Definition: TArray.h:49
Bool_t CallShowMembers(const void *obj, TMemberInspector &insp, Bool_t isTransient=kFALSE) const
Call ShowMembers() on the obj of this class type, passing insp and parent.
Definition: TClass.cxx:2104
TStreamerElement * fElem
Not Owned.
Definition: TStreamerInfo.h:59
virtual void Destructor(void *p, Bool_t dtorOnly=kFALSE)=0
static UInt_t GenerateIncludeForTemplate(FILE *fp, const char *clname, char *inclist, Bool_t forward, const TList *extrainfos)
Add to the header file, the #include needed for the argument of this template.
TString & Remove(Ssiz_t pos)
Definition: TString.h:616
std::atomic< Bool_t > fIsCompiled
true if the StreamerInfo has been &#39;built&#39; (i.e. has all the StreamerElements it should have) ...
long Long_t
Definition: RtypesCore.h:50
Bool_t IsLoaded() const
Return true if the shared library of this class is currently in the a process&#39;s memory.
Definition: TClass.cxx:5535
void CallShowMembers(const void *obj, TMemberInspector &insp, Bool_t isTransient) const
Emulated a call ShowMembers() on the obj of this class type, passing insp and parent.
void Obsolete(const char *method, const char *asOfVers, const char *removedFromVers) const
Use this method to declare a method obsolete.
Definition: TObject.cxx:987
TStreamerElement * GetStreamerElementReal(Int_t i, Int_t j) const
Obsolete: this routine is obsolete and should not longer be used.
void Build()
Build the I/O data structure for the current class version.
virtual Int_t GetSize() const
Definition: TCollection.h:95
TStreamerElement * GetStreamerElement(const char *datamember, Int_t &offset) const
Return the StreamerElement of &quot;datamember&quot; inside our class or any of its base classes.
T GetTypedValueClones(TClonesArray *clones, Int_t i, Int_t j, Int_t k, Int_t eoffset) const
#define ClassImp(name)
Definition: Rtypes.h:279
double f(double x)
Int_t GetSizeElements() const
Return total size of all persistent elements of the class use GetSize if you want to get the real siz...
const char * GetParent() const
virtual const char * GetName() const
Returns name of object.
Definition: TObject.cxx:416
double Double_t
Definition: RtypesCore.h:55
virtual TObjArray * GetElements() const =0
virtual TClass * GetClassPointer() const
Returns a pointer to the TClass of this element.
virtual TClass * GetClassPointer() const
Returns a pointer to the TClass of this element.
Int_t fNslots
!total numbrer of slots in fComp.
TStreamerInfoActions::TActionSequence * fReadMemberWiseVecPtr
! List of read action resulting from the compilation for use in member wise streaming.
TStreamerInfoActions::TActionSequence * fWriteObjectWise
! List of write action resulting from the compilation.
void RemoveStreamerInfo(Int_t slot)
Remove and delete the StreamerInfo in the given slot.
Definition: TClass.cxx:6840
int type
Definition: TGX11.cxx:120
Int_t GetNewType(Int_t id) const
unsigned long long ULong64_t
Definition: RtypesCore.h:70
void SetNewBaseClass(TClass *cl)
unsigned long ULong_t
Definition: RtypesCore.h:51
const TObjArray * GetTarget() const
Get the target data members of this rule (i.e. the in memory data member).
EDataType
Definition: TDataType.h:30
virtual void SetType(Int_t dtype)
Int_t fNVirtualInfoLoc
! Number of virtual info location to update.
Int_t GetNewType() const
virtual void * At(UInt_t idx)=0
TClassStreamer * GetStreamer() const
Return the Streamer Class allowing streaming (if any).
Definition: TClass.cxx:2818
#define R__LOCKGUARD(mutex)
void InspectMember(const T &obj, const char *name, Bool_t isTransient)
Long_t GetDataMemberOffset(const char *membername) const
return offset for member name.
Definition: TClass.cxx:3240
Int_t GetEntries() const
Return the number of objects in array (i.e.
Definition: TObjArray.cxx:494
static TClass * GetClass(const char *name, Bool_t load=kTRUE, Bool_t silent=kFALSE)
Static method returning pointer to TClass of the specified class name.
Definition: TClass.cxx:2872
const TMatches FindRules(const TString &source) const
Return all the rules that are about the given &#39;source&#39; class.
void Compile()
loop on the TStreamerElement list regroup members with same type Store predigested information into l...
TVirtualCollectionProxy * GetCollectionProxy() const
Return the proxy describing the collection (if any).
Definition: TClass.cxx:2801
void TagFile(TFile *fFile)
Mark the classindex of the current file as using this TStreamerInfo.
TDataMember * GetDataMember(const char *datamember) const
Return pointer to datamember object with name &quot;datamember&quot;.
Definition: TClass.cxx:3212
const TList * GetStreamerInfoCache()
Returns the cached list of StreamerInfos used in this file.
Definition: TFile.cxx:1304
TClass * GetClass() const
Mother of all ROOT objects.
Definition: TObject.h:37
Int_t Size() const
Get size of basic typedef&#39;ed type.
Definition: TDataType.cxx:366
virtual void Init(TObject *obj=0)
Setup the element.
Int_t GetArrayDim() const
Return number of array dimensions.
virtual void Inspect(TClass *cl, const char *parent, const char *name, const void *addr)
Int_t GetSize() const
Return total size of all persistent elements of the class (with offsets).
Int_t IsSTLContainer()
The return type is defined in TDictionary (kVector, kList, etc.)
TMemberStreamer * GetStreamer() const
Return the associate streamer object.
Definition: TRealData.cxx:98
TClass * GetClass() const
Definition: TClassRef.h:75
virtual UInt_t Size() const =0
TClassRef is used to implement a permanent reference to a TClass object.
Definition: TClassRef.h:33
char Char_t
Definition: RtypesCore.h:29
static TString UpdateAssociativeToVector(const char *name)
If we have a map, multimap, set or multiset, plus unordered partners, and the key is a class...
TObject * Last() const
Return the object in the last filled slot. Returns 0 if no entries.
Definition: TObjArray.cxx:479
An array of clone (identical) objects.
Definition: TClonesArray.h:32
Int_t fNumber
!Unique identifier
Definition: TStreamerInfo.h:99
void BuildCheck(TFile *file=0)
Check if built and consistent with the class dictionary.
void GetSequenceType(TString &type) const
Fill type with the string representation of sequence information including &#39;cached&#39;,&#39;repeat&#39;,&#39;write&#39; or &#39;nodelete&#39;.
virtual ~TStreamerInfo()
TStreamerInfo dtor.
virtual void ClassEnd(const TClass *)=0
Int_t GetVersion() const
Definition: TFile.h:214
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition: TString.h:567
Char_t * fArray
Definition: TArrayC.h:32
std::string ShortType(const char *typeDesc, int mode)
Return the absolute type of typeDesc.
virtual void SetNewType(Int_t dtype)
static TStreamerBasicType * GetElementCounter(const char *countName, TClass *cl)
Get pointer to a TStreamerBasicType in TClass *cl static function.
virtual Bool_t HasCounter() const
const ROOT::Detail::TSchemaRuleSet * GetSchemaRules() const
Return the set of the schema rules if any.
Definition: TClass.cxx:1831
#define snprintf
Definition: civetweb.c:822
bool IsUniquePtr(std::string_view name)
Definition: TClassEdit.h:179
Int_t GetType() const
TVirtualStreamerInfo * GetBaseStreamerInfo() const
R__EXTERN Int_t gDebug
Definition: Rtypes.h:128
ROOT::ESTLType GetCollectionType() const
Return the &#39;type&#39; of the STL the TClass is representing.
Definition: TClass.cxx:2790
Bool_t IsBasic() const
Return true if data member is a basic type, e.g. char, int, long...
const TObjArray * GetStreamerInfos() const
Definition: TClass.h:447
Long_t Property() const
Get property description word. For meaning of bits see EProperty.
void * NewArray(Long_t nElements, void *ary=0)
An array of emulated objects is created at address ary, if ary is null, we allocate memory for the ar...
void Add(TObject *obj)
Definition: TObjArray.h:75
TCompInfo ** fCompOpt
![fNdata]
#define gDirectory
Definition: TDirectory.h:221
double result[121]
TDataMember * GetDataMember() const
Definition: TRealData.h:57
void ResetBit(UInt_t f)
Definition: TObject.h:156
unsigned char UChar_t
Definition: RtypesCore.h:34
Bool_t HasDataMemberInfo() const
Definition: TClass.h:371
TObject * At(Int_t idx) const
Definition: TObjArray.h:167
virtual const char * GetFullName() const
Return element name including dimensions, if any Note that this function stores the name into a stati...
virtual void Init(TObject *obj=0)
Setup the element.
const Bool_t kIterBackward
Definition: TCollection.h:44
TObject * Clone(const char *newname="") const
Make a clone of an object using the Streamer facility.
virtual void Compress()
Remove empty slots from array.
Definition: TObjArray.cxx:309
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
Definition: TString.h:582
Abstract Interface class describing Streamer information for one class.
const char * AsString() const
Return the date &amp; time as a string (ctime() format).
Definition: TDatime.cxx:101
const Bool_t kTRUE
Definition: Rtypes.h:91
virtual const char * GetName() const
Returns name of object.
Definition: TRealData.h:56
Long_t GetThisOffset() const
Definition: TRealData.h:59
virtual const char * GetTitle() const
Returns title of object.
Definition: TObject.cxx:460
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
Definition: TNamed.cxx:155
virtual TObject * FindObject(const char *name) const
Must be redefined in derived classes.
Definition: TObject.cxx:380
void PrintValueSTL(const char *name, TVirtualCollectionProxy *cont, Int_t i, Int_t eoffset, Int_t lenmax=1000) const
Print value of element i in a TClonesArray.
bool GetStdArrayProperties(const char *typeName, std::string &typeNameBuf, std::array< int, 5 > &maxIndices, int &ndim)
static UInt_t GenerateClassPrefix(FILE *fp, const char *clname, Bool_t top, TString &protoname, UInt_t *numberOfClasses, Int_t implementEmptyClass=kFALSE, Bool_t needGenericTemplate=kFALSE)
Write the start of the class (forward) declaration.
void CopyCollectionProxy(const TVirtualCollectionProxy &)
Copy the argument.
Definition: TClass.cxx:2377
void SetReadRawFunc(ROOT::TSchemaRule::ReadRawFuncPtr_t val)
gr SetName("gr")
char name[80]
Definition: TGX11.cxx:109
Int_t Size() const
Return size of object of this class.
Definition: TClass.cxx:5334
const char * cnt
Definition: TXMLSetup.cxx:75
Bool_t CompareContent(TClass *cl, TVirtualStreamerInfo *info, Bool_t warn, Bool_t complete, TFile *file)
Return True if the current StreamerInfo in cl or info is equivalent to this TStreamerInfo.
std::atomic< ULong_t > fLiveCount
! Number of outstanding pointer to this StreamerInfo.
TArrayC * GetClassIndex() const
Definition: TFile.h:195
virtual Version_t ReadVersion(UInt_t *start=0, UInt_t *bcnt=0, const TClass *cl=0)=0
void Resize(Ssiz_t n)
Resize the string. Truncate or add blanks as necessary.
Definition: TString.cxx:1059
static TClassStreamer * GenExplicitClassStreamer(const ::ROOT::TCollectionProxyInfo &info, TClass *cl)
Generate class streamer from static functions.
TStreamerInfo()
Default ctor.
This class stores the date and time with a precision of one second in an unsigned 32 bit word (950130...
Definition: TDatime.h:39
TVirtualStreamerInfo * GetStreamerInfoAbstractEmulated(Int_t version=0) const
For the case where the requestor class is emulated and this class is abstract, returns a pointer to t...
Definition: TClass.cxx:4429
Int_t GetArrayLength() const
static void R__TObjArray_InsertAfter(TObjArray *arr, TObject *newobj, TObject *oldobj)
Array of chars or bytes (8 bits per element).
Definition: TArrayC.h:29
EReadWrite
EReadWrite Enumerator Enum Constant Description kBase Base class element kOffsetL Fixed size array k...
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition: TObject.cxx:911