Logo ROOT  
Reference Guide
TClass.cxx
Go to the documentation of this file.
1// @(#)root/meta:$Id: 7109cb45f1219c2aae6be19906ae5a63e31972ef $
2// Author: Rene Brun 07/01/95
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/** \class TClass
13TClass instances represent classes, structs and namespaces in the ROOT type system.
14
15TClass instances are created starting from different sources of information:
161. TStreamerInfo instances saved in a ROOT file which is opened. This is called in jargon an *emulated TClass*.
172. From TProtoClass instances saved in a ROOT pcm file created by the dictionary generator and the dictionary itself.
183. From a lookup in the AST built by cling.
19
20If a TClass instance is built through the mechanisms 1. and 2., it does not contain information about methods of the
21class/struct/namespace it represents. Conversely, if built through 3. or 1., it does not carry the information which is necessary
22to ROOT to perform I/O of instances of the class/struct it represents.
23The mechanisms 1., 2. and 3. are not mutually exclusive: it can happen that during the execution of the program, all
24the three are triggered, modifying the state of the TClass instance.
25
26In order to retrieve a TClass instance from the type system, a query can be executed as follows through the static
27TClass::GetClass method:
28
29~~~ {.cpp}
30auto myClassTClass_0 = TClass::GetClass("myClass");
31auto myClassTClass_1 = TClass::GetClass<myClass>();
32auto myClassTClass_2 = TClass::GetClass(myClassTypeInfo);
33~~~
34
35The name of classes is crucial for ROOT. A careful procedure of *name normalization* is carried out for
36each and every class. A *normalized name* is a valid C++ class name.
37In order to access the name of a class within the ROOT type system, the method TClass::GetName() can be used.
38*/
39
40//*-*x7.5 macros/layout_class
41
42#include "TClass.h"
43
44#include "Riostream.h"
45#include "TBaseClass.h"
46#include "TBrowser.h"
47#include "TBuffer.h"
48#include "TClassGenerator.h"
49#include "TClassEdit.h"
50#include "TClassMenuItem.h"
51#include "TClassRef.h"
52#include "TClassTable.h"
53#include "TDataMember.h"
54#include "TDataType.h"
55#include "TDatime.h"
56#include "TEnum.h"
57#include "TError.h"
58#include "TExMap.h"
59#include "TFunctionTemplate.h"
60#include "THashList.h"
61#include "TInterpreter.h"
62#include "TMemberInspector.h"
63#include "TMethod.h"
64#include "TMethodArg.h"
65#include "TMethodCall.h"
66#include "TObjArray.h"
67#include "TObjString.h"
68#include "TProtoClass.h"
69#include "TROOT.h"
70#include "TRealData.h"
71#include "TCheckHashRecursiveRemoveConsistency.h" // Private header
72#include "TStreamer.h"
73#include "TStreamerElement.h"
76#include "TVirtualIsAProxy.h"
77#include "TVirtualRefProxy.h"
78#include "TVirtualMutex.h"
79#include "TVirtualPad.h"
80#include "THashTable.h"
81#include "TSchemaRuleSet.h"
82#include "TGenericClassInfo.h"
83#include "TIsAProxy.h"
84#include "TSchemaRule.h"
85#include "TSystem.h"
86#include "TThreadSlots.h"
87#include "ThreadLocalStorage.h"
88
89#include <cstdio>
90#include <cctype>
91#include <set>
92#include <sstream>
93#include <string>
94#include <map>
95#include <typeinfo>
96#include <cmath>
97#include <assert.h>
98#include <vector>
99#include <memory>
100
101#include "TSpinLockGuard.h"
102
103#ifdef WIN32
104#include <io.h>
105#include "Windows4Root.h"
106#include <Psapi.h>
107#define RTLD_DEFAULT ((void *)::GetModuleHandle(NULL))
108#define dlsym(library, function_name) ::GetProcAddress((HMODULE)library, function_name)
109#else
110#include <dlfcn.h>
111#endif
112
113#include "TListOfDataMembers.h"
114#include "TListOfFunctions.h"
116#include "TListOfEnums.h"
117#include "TListOfEnumsWithLock.h"
118#include "TViewPubDataMembers.h"
119#include "TViewPubFunctions.h"
120#include "TArray.h"
121#include "TClonesArray.h"
122#include "TRef.h"
123#include "TRefArray.h"
124
125using namespace std;
126
127// Mutex to protect CINT and META operations
128// (exported to be used for similar cases in related classes)
129
131
132namespace {
133
134 static constexpr const char kUndeterminedClassInfoName[] = "<NOT YET DETERMINED FROM fClassInfo>";
135
136 class TMmallocDescTemp {
137 private:
138 void *fSave;
139 public:
140 TMmallocDescTemp(void *value = 0) :
142 ~TMmallocDescTemp() { ROOT::Internal::gMmallocDesc = fSave; }
143 };
144
145 // When a new class is created, we need to be able to find
146 // if there are any existing classes that have the same name
147 // after any typedefs are expanded. (This only really affects
148 // template arguments.) To avoid having to search through all classes
149 // in that case, we keep a hash table mapping from the fully
150 // typedef-expanded names to the original class names.
151 // An entry is made in the table only if they are actually different.
152 //
153 // In these objects, the TObjString base holds the typedef-expanded
154 // name (the hash key), and fOrigName holds the original class name
155 // (the value to which the key maps).
156 //
157 class TNameMapNode : public TObjString {
158 public:
159 TString fOrigName;
160
161 TNameMapNode(const char *typedf, const char *orig) :
162 TObjString (typedf),
163 fOrigName (orig)
164 {
165 }
166 };
167
168}
169
170std::atomic<Int_t> TClass::fgClassCount;
171
172static bool IsFromRootCling() {
173 // rootcling also uses TCling for generating the dictionary ROOT files.
174 const static bool foundSymbol = dlsym(RTLD_DEFAULT, "usedToIdentifyRootClingByDlSym");
175 return foundSymbol;
176}
177
178// Implementation of the TDeclNameRegistry
179
180////////////////////////////////////////////////////////////////////////////////
181/// TDeclNameRegistry class constructor.
182
184{
185 // MSVC doesn't support fSpinLock=ATOMIC_FLAG_INIT; in the class definition
186 std::atomic_flag_clear( &fSpinLock );
187}
188
189////////////////////////////////////////////////////////////////////////////////
190/// Extract this part of the name
191/// 1. Templates ns::ns2::,,,::THISPART<...
192/// 2. Namespaces,classes ns::ns2::,,,::THISPART
193
195{
196 // Sanity check
197 auto strLen = strlen(name);
198 if (strLen == 0) return;
199 // find <. If none, put end of string
200 const char* endCharPtr = strchr(name, '<');
201 endCharPtr = !endCharPtr ? &name[strLen] : endCharPtr;
202 // find last : before the <. If not found, put begin of string
203 const char* beginCharPtr = endCharPtr;
204 while (beginCharPtr!=name){
205 if (*beginCharPtr==':'){
206 beginCharPtr++;
207 break;
208 }
209 beginCharPtr--;
210 }
211 beginCharPtr = beginCharPtr!=endCharPtr ? beginCharPtr : name;
212 std::string s(beginCharPtr, endCharPtr);
213 if (fVerbLevel>1)
214 printf("TDeclNameRegistry::AddQualifiedName Adding key %s for class/namespace %s\n", s.c_str(), name);
215 ROOT::Internal::TSpinLockGuard slg(fSpinLock);
216 fClassNamesSet.insert(s);
217}
218
219////////////////////////////////////////////////////////////////////////////////
220
222{
223 Bool_t found = false;
224 {
225 ROOT::Internal::TSpinLockGuard slg(fSpinLock);
226 found = fClassNamesSet.find(name) != fClassNamesSet.end();
227 }
228 return found;
229}
230
231////////////////////////////////////////////////////////////////////////////////
232
234{
235 if (fVerbLevel > 1) {
236 printf("TDeclNameRegistry Destructor. List of %lu names:\n",
237 (long unsigned int)fClassNamesSet.size());
238 for (auto const & key: fClassNamesSet) {
239 printf(" - %s\n", key.c_str());
240 }
241 }
242}
243
244////////////////////////////////////////////////////////////////////////////////
245
247 const char *name,
248 TDeclNameRegistry &emuRegistry): fState(state),fName(name), fNoInfoOrEmuOrFwdDeclNameRegistry(emuRegistry) {}
249
250////////////////////////////////////////////////////////////////////////////////
251
253 if (fState == TClass::kNoInfo ||
257 }
258 }
259
260// Initialise the global member of TClass
262
263//Intent of why/how TClass::New() is called
264//[Not a static data member because MacOS does not support static thread local data member ... who knows why]
266 TTHREAD_TLS(TClass::ENewType) fgCallingNew = TClass::kRealNew;
267 return fgCallingNew;
268}
269
270struct TClass__GetCallingNewRAII
271{
272 TClass::ENewType &fCurrentValue;
273 TClass::ENewType fOldValue;
274
275 TClass__GetCallingNewRAII(TClass::ENewType newvalue) :
276 fCurrentValue(TClass__GetCallingNew()),
277 fOldValue(fCurrentValue)
278 {
279 fCurrentValue = newvalue;
280 }
281
282 ~TClass__GetCallingNewRAII()
283 {
284 fCurrentValue = fOldValue;
285 }
286};
287
288void TClass::RegisterAddressInRepository(const char * /*where*/, void *location, const TClass *what) const
289{
290 // Register the object for special handling in the destructor.
291
292 Version_t version = what->GetClassVersion();
293// if (!fObjectVersionRepository.count(location)) {
294// Info(where, "Registering address %p of class '%s' version %d", location, what->GetName(), version);
295// } else {
296// Warning(where, "Registering address %p again of class '%s' version %d", location, what->GetName(), version);
297// }
298 {
300 fObjectVersionRepository.insert(RepoCont_t::value_type(location, version));
301 }
302#if 0
303 // This code could be used to prevent an address to be registered twice.
304 std::pair<RepoCont_t::iterator, Bool_t> tmp = fObjectVersionRepository.insert(RepoCont_t::value_type>(location, version));
305 if (!tmp.second) {
306 Warning(where, "Reregistering an object of class '%s' version %d at address %p", what->GetName(), version, p);
307 fObjectVersionRepository.erase(tmp.first);
308 tmp = fObjectVersionRepository.insert(RepoCont_t::value_type>(location, version));
309 if (!tmp.second) {
310 Warning(where, "Failed to reregister an object of class '%s' version %d at address %p", what->GetName(), version, location);
311 }
312 }
313#endif
314}
315
316void TClass::UnregisterAddressInRepository(const char * /*where*/, void *location, const TClass *what) const
317{
318 // Remove an address from the repository of address/object.
319
321 RepoCont_t::iterator cur = fObjectVersionRepository.find(location);
322 for (; cur != fObjectVersionRepository.end();) {
323 RepoCont_t::iterator tmp = cur++;
324 if ((tmp->first == location) && (tmp->second == what->GetClassVersion())) {
325 // -- We still have an address, version match.
326 // Info(where, "Unregistering address %p of class '%s' version %d", location, what->GetName(), what->GetClassVersion());
327 fObjectVersionRepository.erase(tmp);
328 } else {
329 // -- No address, version match, we've reached the end.
330 break;
331 }
332 }
333}
334
335void TClass::MoveAddressInRepository(const char * /*where*/, void *oldadd, void *newadd, const TClass *what) const
336{
337 // Register in the repository that an object has moved.
338
339 // Move not only the object itself but also any base classes or sub-objects.
340 size_t objsize = what->Size();
341 long delta = (char*)newadd - (char*)oldadd;
343 RepoCont_t::iterator cur = fObjectVersionRepository.find(oldadd);
344 for (; cur != fObjectVersionRepository.end();) {
345 RepoCont_t::iterator tmp = cur++;
346 if (oldadd <= tmp->first && tmp->first < ( ((char*)oldadd) + objsize) ) {
347 // The location is within the object, let's move it.
348
349 fObjectVersionRepository.insert(RepoCont_t::value_type(((char*)tmp->first)+delta, tmp->second));
350 fObjectVersionRepository.erase(tmp);
351
352 } else {
353 // -- No address, version match, we've reached the end.
354 break;
355 }
356 }
357}
358
359//______________________________________________________________________________
360//______________________________________________________________________________
361namespace ROOT {
362#define R__USE_STD_MAP
363 class TMapTypeToTClass {
364#if defined R__USE_STD_MAP
365 // This wrapper class allow to avoid putting #include <map> in the
366 // TROOT.h header file.
367 public:
368 typedef std::map<std::string,TClass*> IdMap_t;
369 typedef IdMap_t::key_type key_type;
370 typedef IdMap_t::const_iterator const_iterator;
371 typedef IdMap_t::size_type size_type;
372#ifdef R__WIN32
373 // Window's std::map does NOT defined mapped_type
374 typedef TClass* mapped_type;
375#else
376 typedef IdMap_t::mapped_type mapped_type;
377#endif
378
379 private:
380 IdMap_t fMap;
381
382 public:
383 void Add(const key_type &key, mapped_type &obj)
384 {
385 // Add the <key,obj> pair to the map.
386 fMap[key] = obj;
387 }
388 mapped_type Find(const key_type &key) const
389 {
390 // Find the type corresponding to the key.
391 IdMap_t::const_iterator iter = fMap.find(key);
392 mapped_type cl = 0;
393 if (iter != fMap.end()) cl = iter->second;
394 return cl;
395 }
396 void Remove(const key_type &key) {
397 // Remove the type corresponding to the key.
398 fMap.erase(key);
399 }
400#else
401 private:
402 TMap fMap;
403
404 public:
405#ifdef R__COMPLETE_MEM_TERMINATION
406 TMapTypeToTClass() {
407 TIter next(&fMap);
408 TObjString *key;
409 while((key = (TObjString*)next())) {
410 delete key;
411 }
412 }
413#endif
414 void Add(const char *key, TClass *&obj) {
415 TObjString *realkey = new TObjString(key);
416 fMap.Add(realkey, obj);
417 }
418 TClass* Find(const char *key) const {
419 const TPair *a = (const TPair *)fMap.FindObject(key);
420 if (a) return (TClass*) a->Value();
421 return 0;
422 }
423 void Remove(const char *key) {
424 TObjString realkey(key);
425 TObject *actual = fMap.Remove(&realkey);
426 delete actual;
427 }
428#endif
429 };
430
431 class TMapDeclIdToTClass {
432 // Wrapper class for the multimap of DeclId_t and TClass.
433 public:
434 typedef multimap<TDictionary::DeclId_t, TClass*> DeclIdMap_t;
435 typedef DeclIdMap_t::key_type key_type;
436 typedef DeclIdMap_t::mapped_type mapped_type;
437 typedef DeclIdMap_t::const_iterator const_iterator;
438 typedef std::pair <const_iterator, const_iterator> equal_range;
439 typedef DeclIdMap_t::size_type size_type;
440
441 private:
442 DeclIdMap_t fMap;
443
444 public:
445 void Add(const key_type &key, mapped_type obj)
446 {
447 // Add the <key,obj> pair to the map.
448 std::pair<const key_type, mapped_type> pair = make_pair(key, obj);
449 fMap.insert(pair);
450 }
451 size_type CountElementsWithKey(const key_type &key)
452 {
453 return fMap.count(key);
454 }
455 equal_range Find(const key_type &key) const
456 {
457 // Find the type corresponding to the key.
458 return fMap.equal_range(key);
459 }
460 void Remove(const key_type &key) {
461 // Remove the type corresponding to the key.
462 fMap.erase(key);
463 }
464 };
465}
466
468
469#ifdef R__COMPLETE_MEM_TERMINATION
470 static IdMap_t gIdMapObject;
471 return &gIdMapObject;
472#else
473 static IdMap_t *gIdMap = new IdMap_t;
474 return gIdMap;
475#endif
476}
477
479
480#ifdef R__COMPLETE_MEM_TERMINATION
481 static DeclIdMap_t gDeclIdMapObject;
482 return &gDeclIdMapObject;
483#else
484 static DeclIdMap_t *gDeclIdMap = new DeclIdMap_t;
485 return gDeclIdMap;
486#endif
487}
488
489////////////////////////////////////////////////////////////////////////////////
490/// static: Add a class to the list and map of classes.
491
493{
494 if (!cl) return;
495
497 gROOT->GetListOfClasses()->Add(cl);
498 if (cl->GetTypeInfo()) {
499 GetIdMap()->Add(cl->GetTypeInfo()->name(),cl);
500 }
501 if (cl->fClassInfo) {
502 GetDeclIdMap()->Add((void*)(cl->fClassInfo), cl);
503 }
504}
505
506////////////////////////////////////////////////////////////////////////////////
507/// static: Add a TClass* to the map of classes.
508
510{
511 if (!cl || !id) return;
512 GetDeclIdMap()->Add(id, cl);
513}
514
515////////////////////////////////////////////////////////////////////////////////
516/// static: Remove a class from the list and map of classes
517
519{
520 if (!oldcl) return;
521
523 gROOT->GetListOfClasses()->Remove(oldcl);
524 if (oldcl->GetTypeInfo()) {
525 GetIdMap()->Remove(oldcl->GetTypeInfo()->name());
526 }
527 if (oldcl->fClassInfo) {
528 //GetDeclIdMap()->Remove((void*)(oldcl->fClassInfo));
529 }
530}
531
532////////////////////////////////////////////////////////////////////////////////
533
535{
536 if (!id) return;
537 GetDeclIdMap()->Remove(id);
538}
539
540////////////////////////////////////////////////////////////////////////////////
541/// Indirect call to the implementation of ShowMember allowing [forward]
542/// declaration with out a full definition of the TClass class.
543
544void ROOT::Class_ShowMembers(TClass *cl, const void *obj, TMemberInspector&insp)
545{
546 gInterpreter->InspectMembers(insp, obj, cl, kFALSE);
547}
548
549//______________________________________________________________________________
550//______________________________________________________________________________
551
552class TDumpMembers : public TMemberInspector {
553 bool fNoAddr;
554public:
555 TDumpMembers(bool noAddr): fNoAddr(noAddr) { }
556
558 void Inspect(TClass *cl, const char *parent, const char *name, const void *addr, Bool_t isTransient);
559};
560
561////////////////////////////////////////////////////////////////////////////////
562/// Print value of member mname.
563///
564/// This method is called by the ShowMembers() method for each
565/// data member when object.Dump() is invoked.
566///
567/// - cl is the pointer to the current class
568/// - pname is the parent name (in case of composed objects)
569/// - mname is the data member name
570/// - add is the data member address
571
572void TDumpMembers::Inspect(TClass *cl, const char *pname, const char *mname, const void *add, Bool_t /* isTransient */)
573{
574 const Int_t kvalue = 30;
575#ifdef R__B64
576 const Int_t ktitle = 50;
577#else
578 const Int_t ktitle = 42;
579#endif
580 const Int_t kline = 1024;
581 Int_t cdate = 0;
582 Int_t ctime = 0;
583 UInt_t *cdatime = 0;
584 char line[kline];
585
586 TDataType *membertype;
587 EDataType memberDataType = kNoType_t;
588 const char *memberName;
589 const char *memberFullTypeName;
590 const char *memberTitle;
591 Bool_t isapointer;
592 Bool_t isbasic;
593
594 if (TDataMember *member = cl->GetDataMember(mname)) {
595 if (member->GetDataType()) {
596 memberDataType = (EDataType)member->GetDataType()->GetType();
597 }
598 memberName = member->GetName();
599 memberFullTypeName = member->GetFullTypeName();
600 memberTitle = member->GetTitle();
601 isapointer = member->IsaPointer();
602 isbasic = member->IsBasic();
603 membertype = member->GetDataType();
604 } else if (!cl->IsLoaded()) {
605 // The class is not loaded, hence it is 'emulated' and the main source of
606 // information is the StreamerInfo.
608 if (!info) return;
609 const char *cursor = mname;
610 while ( (*cursor)=='*' ) ++cursor;
611 TString elname( cursor );
612 Ssiz_t pos = elname.Index("[");
613 if ( pos != kNPOS ) {
614 elname.Remove( pos );
615 }
616 TStreamerElement *element = (TStreamerElement*)info->GetElements()->FindObject(elname.Data());
617 if (!element) return;
618 memberFullTypeName = element->GetTypeName();
619
620 memberDataType = (EDataType)element->GetType();
621
622 memberName = element->GetName();
623 memberTitle = element->GetTitle();
624 isapointer = element->IsaPointer() || element->GetType() == TVirtualStreamerInfo::kCharStar;
625 membertype = gROOT->GetType(memberFullTypeName);
626
627 isbasic = membertype !=0;
628 } else {
629 return;
630 }
631
632
633 Bool_t isdate = kFALSE;
634 if (strcmp(memberName,"fDatime") == 0 && memberDataType == kUInt_t) {
635 isdate = kTRUE;
636 }
637 Bool_t isbits = kFALSE;
638 if (strcmp(memberName,"fBits") == 0 && memberDataType == kUInt_t) {
639 isbits = kTRUE;
640 }
641 TClass * dataClass = TClass::GetClass(memberFullTypeName);
642 Bool_t isTString = (dataClass == TString::Class());
643 static TClassRef stdClass("std::string");
644 Bool_t isStdString = (dataClass == stdClass);
645
646 Int_t i;
647 for (i = 0;i < kline; i++) line[i] = ' ';
648 line[kline-1] = 0;
649 snprintf(line,kline,"%s%s ",pname,mname);
650 i = strlen(line); line[i] = ' ';
651
652 // Encode data value or pointer value
653 char *pointer = (char*)add;
654 char **ppointer = (char**)(pointer);
655
656 if (isapointer) {
657 char **p3pointer = (char**)(*ppointer);
658 if (!p3pointer)
659 snprintf(&line[kvalue],kline-kvalue,"->0");
660 else if (!isbasic) {
661 if (!fNoAddr) {
662 snprintf(&line[kvalue],kline-kvalue,"->%lx ", (Long_t)p3pointer);
663 }
664 } else if (membertype) {
665 if (!strcmp(membertype->GetTypeName(), "char")) {
666 i = strlen(*ppointer);
667 if (kvalue+i > kline) i=kline-1-kvalue;
668 Bool_t isPrintable = kTRUE;
669 for (Int_t j = 0; j < i; j++) {
670 if (!std::isprint((*ppointer)[j])) {
671 isPrintable = kFALSE;
672 break;
673 }
674 }
675 if (isPrintable) {
676 strncpy(line + kvalue, *ppointer, i);
677 line[kvalue+i] = 0;
678 } else {
679 line[kvalue] = 0;
680 }
681 } else {
682 strncpy(&line[kvalue], membertype->AsString(p3pointer), TMath::Min(kline-1-kvalue,(int)strlen(membertype->AsString(p3pointer))));
683 }
684 } else if (!strcmp(memberFullTypeName, "char*") ||
685 !strcmp(memberFullTypeName, "const char*")) {
686 i = strlen(*ppointer);
687 if (kvalue+i >= kline) i=kline-1-kvalue;
688 Bool_t isPrintable = kTRUE;
689 for (Int_t j = 0; j < i; j++) {
690 if (!std::isprint((*ppointer)[j])) {
691 isPrintable = kFALSE;
692 break;
693 }
694 }
695 if (isPrintable) {
696 strncpy(line + kvalue, *ppointer, std::min( i, kline - kvalue));
697 line[kvalue+i] = 0;
698 } else {
699 line[kvalue] = 0;
700 }
701 } else {
702 if (!fNoAddr) {
703 snprintf(&line[kvalue],kline-kvalue,"->%lx ", (Long_t)p3pointer);
704 }
705 }
706 } else if (membertype) {
707 if (isdate) {
708 cdatime = (UInt_t*)pointer;
709 TDatime::GetDateTime(cdatime[0],cdate,ctime);
710 snprintf(&line[kvalue],kline-kvalue,"%d/%d",cdate,ctime);
711 } else if (isbits) {
712 snprintf(&line[kvalue],kline-kvalue,"0x%08x", *(UInt_t*)pointer);
713 } else {
714 strncpy(&line[kvalue], membertype->AsString(pointer), TMath::Min(kline-1-kvalue,(int)strlen(membertype->AsString(pointer))));
715 }
716 } else {
717 if (isStdString) {
718 std::string *str = (std::string*)pointer;
719 snprintf(&line[kvalue],kline-kvalue,"%s",str->c_str());
720 } else if (isTString) {
721 TString *str = (TString*)pointer;
722 snprintf(&line[kvalue],kline-kvalue,"%s",str->Data());
723 } else {
724 if (!fNoAddr) {
725 snprintf(&line[kvalue],kline-kvalue,"->%lx ", (Long_t)pointer);
726 }
727 }
728 }
729 // Encode data member title
730 if (isdate == kFALSE && strcmp(memberFullTypeName, "char*") && strcmp(memberFullTypeName, "const char*")) {
731 i = strlen(&line[0]); line[i] = ' ';
732 assert(250 > ktitle);
733 strlcpy(&line[ktitle],memberTitle,250-ktitle+1); // strlcpy copy 'size-1' characters.
734 }
735 Printf("%s", line);
736}
737
739
740//______________________________________________________________________________
741
742class TBuildRealData : public TMemberInspector {
743
744private:
745 void *fRealDataObject;
746 TClass *fRealDataClass;
747
748public:
749 TBuildRealData(void *obj, TClass *cl) {
750 // Main constructor.
751 fRealDataObject = obj;
752 fRealDataClass = cl;
753 }
755 void Inspect(TClass *cl, const char *parent, const char *name, const void *addr, Bool_t isTransient);
756
757};
758
759////////////////////////////////////////////////////////////////////////////////
760/// This method is called from ShowMembers() via BuildRealdata().
761
762void TBuildRealData::Inspect(TClass* cl, const char* pname, const char* mname, const void* add, Bool_t isTransient)
763{
764 TDataMember* dm = cl->GetDataMember(mname);
765 if (!dm) {
766 return;
767 }
768
769 Bool_t isTransientMember = kFALSE;
770
771 if (!dm->IsPersistent()) {
772 // For the DataModelEvolution we need access to the transient member.
773 // so we now record them in the list of RealData.
774 isTransientMember = kTRUE;
775 isTransient = kTRUE;
776 }
777
778 TString rname( pname );
779 // Take into account cases like TPaveStats->TPaveText->TPave->TBox.
780 // Check that member is in a derived class or an object in the class.
781 if (cl != fRealDataClass) {
782 if (!fRealDataClass->InheritsFrom(cl)) {
783 Ssiz_t dot = rname.Index('.');
784 if (dot == kNPOS) {
785 return;
786 }
787 rname[dot] = '\0';
788 if (!fRealDataClass->GetDataMember(rname)) {
789 //could be a data member in a base class like in this example
790 // class Event : public Data {
791 // class Data : public TObject {
792 // EventHeader fEvtHdr;
793 // class EventHeader {
794 // Int_t fEvtNum;
795 // Int_t fRun;
796 // Int_t fDate;
797 // EventVertex fVertex;
798 // class EventVertex {
799 // EventTime fTime;
800 // class EventTime {
801 // Int_t fSec;
802 // Int_t fNanoSec;
803 if (!fRealDataClass->GetBaseDataMember(rname)) {
804 return;
805 }
806 }
807 rname[dot] = '.';
808 }
809 }
810
811 Long_t offset = Long_t(((Long_t) add) - ((Long_t) fRealDataObject));
812
813 if (TClassEdit::IsStdArray(dm->GetTypeName())){ // We tackle the std array case
814 TString rdName;
815 TRealData::GetName(rdName,dm);
816 rname += rdName;
817 TRealData* rd = new TRealData(rname.Data(), offset, dm);
818 fRealDataClass->GetListOfRealData()->Add(rd);
819 return;
820 }
821
822 rname += mname;
823
824 if (dm->IsaPointer()) {
825 // Data member is a pointer.
826 TRealData* rd = new TRealData(rname, offset, dm);
827 if (isTransientMember) { rd->SetBit(TRealData::kTransient); };
828 fRealDataClass->GetListOfRealData()->Add(rd);
829 } else {
830 // Data Member is a basic data type.
831 TRealData* rd = new TRealData(rname, offset, dm);
832 if (isTransientMember) { rd->SetBit(TRealData::kTransient); };
833 if (!dm->IsBasic()) {
834 rd->SetIsObject(kTRUE);
835
836 // Make sure that BuildReadData is called for any abstract
837 // bases classes involved in this object, i.e for all the
838 // classes composing this object (base classes, type of
839 // embedded object and same for their data members).
840 //
841 TClass* dmclass = TClass::GetClass(dm->GetTypeName(), kTRUE, isTransient);
842 if (!dmclass) {
843 dmclass = TClass::GetClass(dm->GetTrueTypeName(), kTRUE, isTransient);
844 }
845 if (dmclass) {
846 if ((dmclass != cl) && !dm->IsaPointer()) {
847 if (dmclass->GetCollectionProxy()) {
848 TClass* valcl = dmclass->GetCollectionProxy()->GetValueClass();
849 // We create the real data for the content of the collection to help the case
850 // of split branches in a TTree (where the node for the data member itself
851 // might have been elided). However, in some cases, like transient members
852 // and/or classes, the content might not be create-able. An example is the
853 // case of a map<A,B> where either A or B does not have default constructor
854 // and thus the compilation of the default constructor for pair<A,B> will
855 // fail (noisily) [This could also apply to any template instance, where it
856 // might have a default constructor definition that can not be compiled due
857 // to the template parameter]
858 if (valcl) {
859 Bool_t wantBuild = kTRUE;
860 if (valcl->Property() & kIsAbstract) wantBuild = kFALSE;
861 if ( (isTransient)
863 && (!valcl->IsLoaded()) ) {
864 // Case where the collection dictionary was not requested and
865 // the content's dictionary was also not requested.
866 // [This is a super set of what we need, but we can't really detect it :(]
867 wantBuild = kFALSE;
868 }
869
870 if (wantBuild) valcl->BuildRealData(0, isTransient);
871 }
872 } else {
873 void* addrForRecursion = 0;
874 if (GetObjectValidity() == kValidObjectGiven)
875 addrForRecursion = const_cast<void*>(add);
876
877 dmclass->BuildRealData(addrForRecursion, isTransient);
878 }
879 }
880 }
881 }
882 fRealDataClass->GetListOfRealData()->Add(rd);
883 }
884}
885
886//______________________________________________________________________________
887//______________________________________________________________________________
888//______________________________________________________________________________
889
890////////////////////////////////////////////////////////////////////////////////
891
892class TAutoInspector : public TMemberInspector {
893public:
894 Int_t fCount;
895 TBrowser *fBrowser;
896
897 TAutoInspector(TBrowser *b) {
898 // main constructor.
899 fBrowser = b; fCount = 0; }
900 virtual ~TAutoInspector() { }
902 virtual void Inspect(TClass *cl, const char *parent, const char *name, const void *addr, Bool_t isTransient);
903 virtual Bool_t IsTreatingNonAccessibleTypes() {return kFALSE;}
904};
905
906////////////////////////////////////////////////////////////////////////////////
907/// This method is called from ShowMembers() via AutoBrowse().
908
909void TAutoInspector::Inspect(TClass *cl, const char *tit, const char *name,
910 const void *addr, Bool_t /* isTransient */)
911{
912 if(tit && strchr(tit,'.')) return ;
913 if (fCount && !fBrowser) return;
914
915 TString ts;
916
917 if (!cl) return;
918 //if (*(cl->GetName()) == 'T') return;
919 if (*name == '*') name++;
920 int ln = strcspn(name,"[ ");
921 TString iname(name,ln);
922
923 ClassInfo_t *classInfo = cl->GetClassInfo();
924 if (!classInfo) return;
925
926 // Browse data members
928 TString mname;
929
930 int found=0;
931 while (gCling->DataMemberInfo_Next(m)) { // MemberLoop
932 mname = gCling->DataMemberInfo_Name(m);
933 mname.ReplaceAll("*","");
934 if ((found = (iname==mname))) break;
935 }
936 assert(found);
937
938 // we skip: non static members and non objects
939 // - the member G__virtualinfo inserted by the CINT RTTI system
940
941 //Long_t prop = m.Property() | m.Type()->Property();
943 if (prop & kIsStatic) return;
944 if (prop & kIsFundamental) return;
945 if (prop & kIsEnum) return;
946 if (mname == "G__virtualinfo") return;
947
948 int size = sizeof(void*);
949
950 int nmax = 1;
951 if (prop & kIsArray) {
952 for (int dim = 0; dim < gCling->DataMemberInfo_ArrayDim(m); dim++) nmax *= gCling->DataMemberInfo_MaxIndex(m,dim);
953 }
954
957 TClass * clm = TClass::GetClass(clmName.c_str());
958 R__ASSERT(clm);
959 if (!(prop & kIsPointer)) {
960 size = clm->Size();
961 if (size==0) size = gCling->DataMemberInfo_TypeSize(m);
962 }
963
964
967
968 for(int i=0; i<nmax; i++) {
969
970 char *ptr = (char*)addr + i*size;
971
972 void *obj = (prop & kIsPointer) ? *((void**)ptr) : (TObject*)ptr;
973
974 if (!obj) continue;
975
976 fCount++;
977 if (!fBrowser) return;
978
979 TString bwname;
980 TClass *actualClass = clm->GetActualClass(obj);
981 if (clm->IsTObject()) {
982 TObject *tobj = (TObject*)clm->DynamicCast(TObject::Class(),obj);
983 bwname = tobj->GetName();
984 } else {
985 bwname = actualClass->GetName();
986 bwname += "::";
987 bwname += mname;
988 }
989
990 if (!clm->IsTObject() ||
991 bwname.Length()==0 ||
992 strcmp(bwname.Data(),actualClass->GetName())==0) {
993 bwname = name;
994 int l = strcspn(bwname.Data(),"[ ");
995 if (l<bwname.Length() && bwname[l]=='[') {
996 char cbuf[13]; snprintf(cbuf,13,"[%02d]",i);
997 ts.Replace(0,999,bwname,l);
998 ts += cbuf;
999 bwname = (const char*)ts;
1000 }
1001 }
1002
1003 if (proxy==0) {
1004
1005 fBrowser->Add(obj,clm,bwname);
1006
1007 } else {
1008 TClass *valueCl = proxy->GetValueClass();
1009
1010 if (valueCl==0) {
1011
1012 fBrowser->Add( obj, clm, bwname );
1013
1014 } else {
1015 TVirtualCollectionProxy::TPushPop env(proxy, obj);
1016 TClass *actualCl = 0;
1017
1018 int sz = proxy->Size();
1019
1020 char fmt[] = {"#%09d"};
1021 fmt[3] = '0'+(int)log10(double(sz))+1;
1022 char buf[20];
1023 for (int ii=0;ii<sz;ii++) {
1024 void *p = proxy->At(ii);
1025
1026 if (proxy->HasPointers()) {
1027 p = *((void**)p);
1028 if(!p) continue;
1029 actualCl = valueCl->GetActualClass(p);
1030 p = actualCl->DynamicCast(valueCl,p,0);
1031 }
1032 fCount++;
1033 snprintf(buf,20,fmt,ii);
1034 ts = bwname;
1035 ts += buf;
1036 fBrowser->Add( p, actualCl, ts );
1037 }
1038 }
1039 }
1040 }
1041}
1042
1043//______________________________________________________________________________
1044//______________________________________________________________________________
1045//______________________________________________________________________________
1046
1048
1049////////////////////////////////////////////////////////////////////////////////
1050
1052 TDictionary(),
1053 fPersistentRef(0),
1055 fBase(0), fData(0), fUsingData(0), fEnums(0), fFuncTemplate(0), fMethod(0), fAllPubData(0),
1058 fInstanceCount(0), fOnHeap(0),
1060 fTypeInfo(0), fShowMembers(0),
1061 fStreamer(0), fIsA(0), fGlobalIsA(0), fIsAMethod(0),
1066 fState(kNoInfo),
1069
1070{
1071 // Default ctor.
1072
1074 {
1075 TMmallocDescTemp setreset;
1076 fStreamerInfo = new TObjArray(1, -2);
1077 }
1078 fDeclFileLine = -2; // -2 for standalone TClass (checked in dtor)
1079}
1080
1081////////////////////////////////////////////////////////////////////////////////
1082/// Create a TClass object. This object contains the full dictionary
1083/// of a class. It has list to baseclasses, datamembers and methods.
1084/// Use this ctor to create a standalone TClass object. Most useful
1085/// to get a TClass interface to an interpreted class. Used by TTabCom.
1086/// Normally you would use TClass::GetClass("class") to get access to a
1087/// TClass object for a certain class.
1088
1089TClass::TClass(const char *name, Bool_t silent) :
1091 fPersistentRef(0),
1092 fStreamerInfo(0), fConversionStreamerInfo(0), fRealData(0),
1093 fBase(0), fData(0), fUsingData(0), fEnums(0), fFuncTemplate(0), fMethod(0), fAllPubData(0),
1094 fAllPubMethod(0), fClassMenuList(0),
1095 fDeclFileName(""), fImplFileName(""), fDeclFileLine(0), fImplFileLine(0),
1096 fInstanceCount(0), fOnHeap(0),
1097 fCheckSum(0), fCollectionProxy(0), fClassVersion(0), fClassInfo(0),
1098 fTypeInfo(0), fShowMembers(0),
1099 fStreamer(0), fIsA(0), fGlobalIsA(0), fIsAMethod(0),
1100 fMerge(0), fResetAfterMerge(0), fNew(0), fNewArray(0), fDelete(0), fDeleteArray(0),
1101 fDestructor(0), fDirAutoAdd(0), fStreamerFunc(0), fConvStreamerFunc(0), fSizeof(-1),
1102 fCanSplit(-1), fIsSyntheticPair(kFALSE), fProperty(0), fClassProperty(0), fHasRootPcmInfo(kFALSE), fCanLoadClassInfo(kFALSE),
1103 fIsOffsetStreamerSet(kFALSE), fVersionUsed(kFALSE), fRuntimeProperties(0), fOffsetStreamer(0), fStreamerType(TClass::kDefault),
1104 fState(kNoInfo),
1105 fCurrentInfo(0), fLastReadInfo(0), fRefProxy(0),
1106 fSchemaRules(0), fStreamerImpl(&TClass::StreamerDefault)
1107{
1109
1110 if (!gROOT)
1111 ::Fatal("TClass::TClass", "ROOT system not initialized");
1112
1113 {
1114 TMmallocDescTemp setreset;
1115 fStreamerInfo = new TObjArray(1, -2);
1116 }
1117 fDeclFileLine = -2; // -2 for standalone TClass (checked in dtor)
1118
1120 if (!gInterpreter)
1121 ::Fatal("TClass::TClass", "gInterpreter not initialized");
1122
1123 gInterpreter->SetClassInfo(this); // sets fClassInfo pointer
1124 if (!silent && !fClassInfo && !TClassEdit::IsArtificial(name))
1125 ::Warning("TClass::TClass", "no dictionary for class %s is available", name);
1127
1130}
1131
1132////////////////////////////////////////////////////////////////////////////////
1133/// Create a TClass object. This object contains the full dictionary
1134/// of a class. It has list to baseclasses, datamembers and methods.
1135
1136TClass::TClass(const char *name, Version_t cversion, Bool_t silent) :
1138 fPersistentRef(0),
1139 fStreamerInfo(0), fConversionStreamerInfo(0), fRealData(0),
1140 fBase(0), fData(0), fUsingData(0), fEnums(0), fFuncTemplate(0), fMethod(0), fAllPubData(0),
1141 fAllPubMethod(0), fClassMenuList(0),
1142 fDeclFileName(""), fImplFileName(""), fDeclFileLine(0), fImplFileLine(0),
1143 fInstanceCount(0), fOnHeap(0),
1144 fCheckSum(0), fCollectionProxy(0), fClassVersion(0), fClassInfo(0),
1145 fTypeInfo(0), fShowMembers(0),
1146 fStreamer(0), fIsA(0), fGlobalIsA(0), fIsAMethod(0),
1147 fMerge(0), fResetAfterMerge(0), fNew(0), fNewArray(0), fDelete(0), fDeleteArray(0),
1148 fDestructor(0), fDirAutoAdd(0), fStreamerFunc(0), fConvStreamerFunc(0), fSizeof(-1),
1149 fCanSplit(-1), fIsSyntheticPair(kFALSE), fProperty(0), fClassProperty(0), fHasRootPcmInfo(kFALSE), fCanLoadClassInfo(kFALSE),
1150 fIsOffsetStreamerSet(kFALSE), fVersionUsed(kFALSE), fRuntimeProperties(0), fOffsetStreamer(0), fStreamerType(TClass::kDefault),
1151 fState(kNoInfo),
1152 fCurrentInfo(0), fLastReadInfo(0), fRefProxy(0),
1153 fSchemaRules(0), fStreamerImpl(&TClass::StreamerDefault)
1154{
1156 Init(name, cversion, 0, 0, 0, 0, -1, -1, 0, silent);
1157}
1158
1159////////////////////////////////////////////////////////////////////////////////
1160/// Create a TClass object. This object does not contain anything. We mimic
1161/// the case of a class fwd declared in the interpreter.
1162
1163TClass::TClass(const char *name, Version_t cversion, EState theState, Bool_t silent) :
1165 fPersistentRef(0),
1166 fStreamerInfo(0), fConversionStreamerInfo(0), fRealData(0),
1167 fBase(0), fData(0), fUsingData(0), fEnums(0), fFuncTemplate(0), fMethod(0), fAllPubData(0),
1168 fAllPubMethod(0), fClassMenuList(0),
1169 fDeclFileName(""), fImplFileName(""), fDeclFileLine(0), fImplFileLine(0),
1170 fInstanceCount(0), fOnHeap(0),
1171 fCheckSum(0), fCollectionProxy(0), fClassVersion(0), fClassInfo(0),
1172 fTypeInfo(0), fShowMembers(0),
1173 fStreamer(0), fIsA(0), fGlobalIsA(0), fIsAMethod(0),
1174 fMerge(0), fResetAfterMerge(0), fNew(0), fNewArray(0), fDelete(0), fDeleteArray(0),
1175 fDestructor(0), fDirAutoAdd(0), fStreamerFunc(0), fConvStreamerFunc(0), fSizeof(-1),
1176 fCanSplit(-1), fIsSyntheticPair(kFALSE), fProperty(0), fClassProperty(0), fHasRootPcmInfo(kFALSE), fCanLoadClassInfo(kFALSE),
1177 fIsOffsetStreamerSet(kFALSE), fVersionUsed(kFALSE), fRuntimeProperties(0), fOffsetStreamer(0), fStreamerType(TClass::kDefault),
1178 fState(theState),
1179 fCurrentInfo(0), fLastReadInfo(0), fRefProxy(0),
1180 fSchemaRules(0), fStreamerImpl(&TClass::StreamerDefault)
1181{
1183
1184 // Treat the case in which a TClass instance is created for a namespace
1185 if (theState == kNamespaceForMeta){
1187 theState = kForwardDeclared; // it immediately decays in kForwardDeclared
1188 }
1189
1190 if (theState != kForwardDeclared && theState != kEmulated)
1191 ::Fatal("TClass::TClass",
1192 "A TClass entry cannot be initialized in a state different from kForwardDeclared or kEmulated.");
1193 Init(name, cversion, 0, 0, 0, 0, -1, -1, 0, silent);
1194}
1195
1196////////////////////////////////////////////////////////////////////////////////
1197/// Create a TClass object. This object contains the full dictionary
1198/// of a class. It has list to baseclasses, datamembers and methods.
1199/// Use this ctor to create a standalone TClass object. Most useful
1200/// to get a TClass interface to an interpreted class. Used by TTabCom.
1201/// Normally you would use TClass::GetClass("class") to get access to a
1202/// TClass object for a certain class.
1203///
1204/// This copies the ClassInfo (i.e. does *not* take ownership of it).
1205
1206TClass::TClass(ClassInfo_t *classInfo, Version_t cversion,
1207 const char *dfil, const char *ifil, Int_t dl, Int_t il, Bool_t silent) :
1208 TDictionary(""),
1209 fPersistentRef(0),
1210 fStreamerInfo(0), fConversionStreamerInfo(0), fRealData(0),
1211 fBase(0), fData(0), fUsingData(0), fEnums(0), fFuncTemplate(0), fMethod(0), fAllPubData(0),
1212 fAllPubMethod(0), fClassMenuList(0),
1213 fDeclFileName(""), fImplFileName(""), fDeclFileLine(0), fImplFileLine(0),
1214 fInstanceCount(0), fOnHeap(0),
1215 fCheckSum(0), fCollectionProxy(0), fClassVersion(0), fClassInfo(0),
1216 fTypeInfo(0), fShowMembers(0),
1217 fStreamer(0), fIsA(0), fGlobalIsA(0), fIsAMethod(0),
1218 fMerge(0), fResetAfterMerge(0), fNew(0), fNewArray(0), fDelete(0), fDeleteArray(0),
1219 fDestructor(0), fDirAutoAdd(0), fStreamerFunc(0), fConvStreamerFunc(0), fSizeof(-1),
1220 fCanSplit(-1), fIsSyntheticPair(kFALSE), fProperty(0), fClassProperty(0), fHasRootPcmInfo(kFALSE), fCanLoadClassInfo(kFALSE),
1221 fIsOffsetStreamerSet(kFALSE), fVersionUsed(kFALSE), fRuntimeProperties(0), fOffsetStreamer(0), fStreamerType(TClass::kDefault),
1222 fState(kNoInfo),
1223 fCurrentInfo(0), fLastReadInfo(0), fRefProxy(0),
1224 fSchemaRules(0), fStreamerImpl(&TClass::StreamerDefault)
1225{
1227
1228 if (!gROOT)
1229 ::Fatal("TClass::TClass", "ROOT system not initialized");
1230
1231 fDeclFileLine = -2; // -2 for standalone TClass (checked in dtor)
1232
1234 if (!gInterpreter)
1235 ::Fatal("TClass::TClass", "gInterpreter not initialized");
1236
1237 if (!classInfo || !gInterpreter->ClassInfo_IsValid(classInfo)) {
1238 MakeZombie();
1239 fState = kNoInfo;
1240 } else {
1241 fName = gInterpreter->ClassInfo_FullName(classInfo);
1242
1244 Init(fName, cversion, 0, 0, dfil, ifil, dl, il, classInfo, silent);
1245 }
1247
1249}
1250
1251
1252////////////////////////////////////////////////////////////////////////////////
1253/// Create a TClass object. This object contains the full dictionary
1254/// of a class. It has list to baseclasses, datamembers and methods.
1255
1256TClass::TClass(const char *name, Version_t cversion,
1257 const char *dfil, const char *ifil, Int_t dl, Int_t il, Bool_t silent) :
1259 fPersistentRef(0),
1260 fStreamerInfo(0), fConversionStreamerInfo(0), fRealData(0),
1261 fBase(0), fData(0), fUsingData(0), fEnums(0), fFuncTemplate(0), fMethod(0), fAllPubData(0),
1262 fAllPubMethod(0), fClassMenuList(0),
1263 fDeclFileName(""), fImplFileName(""), fDeclFileLine(0), fImplFileLine(0),
1264 fInstanceCount(0), fOnHeap(0),
1265 fCheckSum(0), fCollectionProxy(0), fClassVersion(0), fClassInfo(0),
1266 fTypeInfo(0), fShowMembers(0),
1267 fStreamer(0), fIsA(0), fGlobalIsA(0), fIsAMethod(0),
1268 fMerge(0), fResetAfterMerge(0), fNew(0), fNewArray(0), fDelete(0), fDeleteArray(0),
1269 fDestructor(0), fDirAutoAdd(0), fStreamerFunc(0), fConvStreamerFunc(0), fSizeof(-1),
1270 fCanSplit(-1), fIsSyntheticPair(kFALSE), fProperty(0), fClassProperty(0), fHasRootPcmInfo(kFALSE), fCanLoadClassInfo(kFALSE),
1271 fIsOffsetStreamerSet(kFALSE), fVersionUsed(kFALSE), fRuntimeProperties(0), fOffsetStreamer(0), fStreamerType(TClass::kDefault),
1272 fState(kNoInfo),
1273 fCurrentInfo(0), fLastReadInfo(0), fRefProxy(0),
1274 fSchemaRules(0), fStreamerImpl(&TClass::StreamerDefault)
1275{
1277 Init(name,cversion, 0, 0, dfil, ifil, dl, il, 0, silent);
1278}
1279
1280////////////////////////////////////////////////////////////////////////////////
1281/// Create a TClass object. This object contains the full dictionary
1282/// of a class. It has list to baseclasses, datamembers and methods.
1283
1284TClass::TClass(const char *name, Version_t cversion,
1285 const std::type_info &info, TVirtualIsAProxy *isa,
1286 const char *dfil, const char *ifil, Int_t dl, Int_t il,
1287 Bool_t silent) :
1289 fPersistentRef(0),
1290 fStreamerInfo(0), fConversionStreamerInfo(0), fRealData(0),
1291 fBase(0), fData(0), fUsingData(0), fEnums(0), fFuncTemplate(0), fMethod(0), fAllPubData(0),
1292 fAllPubMethod(0),
1293 fClassMenuList(0),
1294 fDeclFileName(""), fImplFileName(""), fDeclFileLine(0), fImplFileLine(0),
1295 fInstanceCount(0), fOnHeap(0),
1296 fCheckSum(0), fCollectionProxy(0), fClassVersion(0), fClassInfo(0),
1297 fTypeInfo(0), fShowMembers(0),
1298 fStreamer(0), fIsA(0), fGlobalIsA(0), fIsAMethod(0),
1299 fMerge(0), fResetAfterMerge(0), fNew(0), fNewArray(0), fDelete(0), fDeleteArray(0),
1300 fDestructor(0), fDirAutoAdd(0), fStreamerFunc(0), fConvStreamerFunc(0), fSizeof(-1),
1301 fCanSplit(-1), fIsSyntheticPair(kFALSE), fProperty(0), fClassProperty(0), fHasRootPcmInfo(kFALSE), fCanLoadClassInfo(kFALSE),
1302 fIsOffsetStreamerSet(kFALSE), fVersionUsed(kFALSE), fRuntimeProperties(0), fOffsetStreamer(0), fStreamerType(TClass::kDefault),
1303 fState(kHasTClassInit),
1304 fCurrentInfo(0), fLastReadInfo(0), fRefProxy(0),
1305 fSchemaRules(0), fStreamerImpl(&TClass::StreamerDefault)
1306{
1308 // use info
1309 Init(name, cversion, &info, isa, dfil, ifil, dl, il, 0, silent);
1310}
1311
1312////////////////////////////////////////////////////////////////////////////////
1313/// we found at least one equivalent.
1314/// let's force a reload
1315
1317{
1318 TClass::RemoveClass(oldcl);
1319
1320 if (oldcl->CanIgnoreTObjectStreamer()) {
1322 }
1323
1325 TIter next(oldcl->GetStreamerInfos());
1326 while ((info = (TVirtualStreamerInfo*)next())) {
1327 info->Clear("build");
1328 info->SetClass(this);
1329 if (IsSyntheticPair()) {
1330 // Some pair's StreamerInfo were inappropriately marked as versioned
1331 info->SetClassVersion(1);
1332 // There is already a TStreamerInfo put there by the synthetic
1333 // creation.
1334 fStreamerInfo->Add(info);
1335 } else {
1337 }
1338 }
1339 oldcl->fStreamerInfo->Clear();
1340
1341 oldcl->ReplaceWith(this);
1342 delete oldcl;
1343}
1344
1345////////////////////////////////////////////////////////////////////////////////
1346/// Initialize a TClass object. This object contains the full dictionary
1347/// of a class. It has list to baseclasses, datamembers and methods.
1348
1349void TClass::Init(const char *name, Version_t cversion,
1350 const std::type_info *typeinfo, TVirtualIsAProxy *isa,
1351 const char *dfil, const char *ifil, Int_t dl, Int_t il,
1352 ClassInfo_t *givenInfo,
1353 Bool_t silent)
1354{
1355 if (!gROOT)
1356 ::Fatal("TClass::TClass", "ROOT system not initialized");
1357 if (!name || !name[0]) {
1358 ::Error("TClass::Init", "The name parameter is invalid (null or empty)");
1359 MakeZombie();
1360 return;
1361 }
1362 // Always strip the default STL template arguments (from any template argument or the class name)
1364 fName = name; // We can assume that the artificial class name is already normalized.
1365 else
1367
1368 fClassVersion = cversion;
1369 fDeclFileName = dfil ? dfil : "";
1370 fImplFileName = ifil ? ifil : "";
1371 fDeclFileLine = dl;
1372 fImplFileLine = il;
1373 fTypeInfo = typeinfo;
1374 fIsA = isa;
1375 if ( fIsA ) fIsA->SetClass(this);
1376 // See also TCling::GenerateTClass() which will update fClassVersion after creation!
1377 fStreamerInfo = new TObjArray(fClassVersion+2+10,-1); // +10 to read new data by old
1378 fProperty = -1;
1379 fClassProperty = 0;
1380 const bool ispair = TClassEdit::IsStdPair(fName);
1381 if (ispair)
1383
1385
1386 TClass *oldcl = (TClass*)gROOT->GetListOfClasses()->FindObject(fName.Data());
1387
1389
1390 if (oldcl && oldcl->TestBit(kLoading)) {
1391 // Do not recreate a class while it is already being created!
1392
1393 // We can no longer reproduce this case, to check whether we are, we use
1394 // this code:
1395 // Fatal("Init","A bad replacement for %s was requested\n",name);
1396 return;
1397 }
1398
1399 TClass **persistentRef = 0;
1400 if (oldcl) {
1401
1402 persistentRef = oldcl->fPersistentRef.exchange(0);
1403
1404 // The code from here is also in ForceReload.
1405 TClass::RemoveClass(oldcl);
1406 // move the StreamerInfo immediately so that there are
1407 // properly updated!
1408
1409 if (oldcl->CanIgnoreTObjectStreamer()) {
1411 }
1413
1414 TIter next(oldcl->GetStreamerInfos());
1415 while ((info = (TVirtualStreamerInfo*)next())) {
1416 // We need to force a call to BuildOld
1417 info->Clear("build");
1418 info->SetClass(this);
1420 }
1421 oldcl->fStreamerInfo->Clear();
1422 // The code diverges here from ForceReload.
1423
1424 // Move the Schema Rules too.
1425 fSchemaRules = oldcl->fSchemaRules;
1426 oldcl->fSchemaRules = 0;
1427
1428 // Move the TFunctions.
1430 if (fFuncTemplate)
1431 fFuncTemplate->fClass = this;
1432 oldcl->fFuncTemplate = nullptr;
1433 fMethod.store( oldcl->fMethod );
1434 if (fMethod)
1435 (*fMethod).fClass = this;
1436 oldcl->fMethod = nullptr;
1437
1438 }
1439
1441 // Advertise ourself as the loading class for this class name
1442 TClass::AddClass(this);
1443
1445
1446 if (!gInterpreter)
1447 ::Fatal("TClass::Init", "gInterpreter not initialized");
1448
1449 if (givenInfo) {
1450 bool invalid = !gInterpreter->ClassInfo_IsValid(givenInfo);
1451 bool notloaded = !gInterpreter->ClassInfo_IsLoaded(givenInfo);
1452 auto property = gInterpreter->ClassInfo_Property(givenInfo);
1453
1454 if (invalid || (notloaded && (property & kIsNamespace)) ||
1455 !(property & (kIsClass | kIsStruct | kIsNamespace))) {
1457 MakeZombie();
1458 fState = kNoInfo;
1459 TClass::RemoveClass(this);
1460 return;
1461 }
1462 }
1463
1464 if (!invalid) {
1465 fClassInfo = gInterpreter->ClassInfo_Factory(givenInfo);
1466 fCanLoadClassInfo = false; // avoids calls to LoadClassInfo() if info is already loaded
1467 if (fState <= kEmulated)
1469 }
1470 }
1471
1472 // We need to check if the class it is not fwd declared for the cases where we
1473 // created a TClass directly in the kForwardDeclared state. Indeed in those cases
1474 // fClassInfo will always be nullptr.
1476
1477 if (fState == kHasTClassInit) {
1478 // If the TClass is being generated from a ROOT dictionary,
1479 // even though we do not seem to have a CINT dictionary for
1480 // the class, we will will try to load it anyway UNLESS
1481 // the class is an STL container (or string).
1482 // This is because we do not expect the CINT dictionary
1483 // to be present for all STL classes (and we can handle
1484 // the lack of CINT dictionary in that cases).
1485 // However, the cling the dictionary no longer carries
1486 // an instantiation with it, unless we request the loading
1487 // here *or* the user explicitly instantiate the template
1488 // we would not have a ClassInfo for the template
1489 // instantiation.
1491 // Here we check and grab the info from the rootpcm.
1493 if (proto)
1494 proto->FillTClass(this);
1495 }
1496 if (!fHasRootPcmInfo && gInterpreter->CheckClassInfo(fName, /* autoload = */ kTRUE)) {
1497 gInterpreter->SetClassInfo(this); // sets fClassInfo pointer
1498 if (fClassInfo) {
1499 // This should be moved out of GetCheckSum itself however the last time
1500 // we tried this cause problem, in particular in the end-of-process operation.
1501 // fCheckSum = GetCheckSum(kLatestCheckSum);
1502 } else {
1503 if (!fClassInfo) {
1504 if (IsZombie()) {
1505 TClass::RemoveClass(this);
1506 return;
1507 }
1508 }
1509 }
1510 }
1511 }
1512 if (!silent && (!fClassInfo && !fCanLoadClassInfo) && !isStl && !TClassEdit::IsArtificial(fName) &&
1514 if (fState == kHasTClassInit) {
1515 if (fImplFileLine == -1 && fClassVersion == 0) {
1516 // We have a 'transient' class with a ClassDefInline and apparently no interpreter
1517 // information. Since it is transient, it is more than likely that the lack
1518 // will be harmles.
1519 } else {
1520 ::Error("TClass::Init", "no interpreter information for class %s is available even though it has a TClass "
1521 "initialization routine.",
1522 fName.Data());
1523 }
1524 } else {
1525 const bool ispairbase = TClassEdit::IsStdPairBase(fName.Data()) && !IsFromRootCling();
1526 if (!ispairbase)
1527 ::Warning("TClass::Init", "no dictionary for class %s is available", fName.Data());
1528 }
1529 }
1530
1531 fgClassCount++;
1533
1534 // Make the typedef-expanded -> original hash table entries.
1535 // There may be several entries for any given key.
1536 // We only make entries if the typedef-expanded name
1537 // is different from the original name.
1538 TString resolvedThis;
1539 if (!givenInfo && strchr (name, '<')) {
1540 if ( fName != name) {
1541 if (!fgClassTypedefHash) {
1542 fgClassTypedefHash = new THashTable (100, 5);
1544 }
1545
1546 fgClassTypedefHash->Add (new TNameMapNode (name, fName));
1548
1549 }
1550 resolvedThis = TClassEdit::ResolveTypedef (name, kTRUE);
1551 if (resolvedThis != name) {
1552 if (!fgClassTypedefHash) {
1553 fgClassTypedefHash = new THashTable (100, 5);
1555 }
1556
1557 fgClassTypedefHash->Add (new TNameMapNode (resolvedThis, fName));
1559 }
1560
1561 }
1562
1563 //In case a class with the same name had been created by TVirtualStreamerInfo
1564 //we must delete the old class, importing only the StreamerInfo structure
1565 //from the old dummy class.
1566 if (oldcl) {
1567
1568 oldcl->ReplaceWith(this);
1569 delete oldcl;
1570
1571 } else if (!givenInfo && resolvedThis.Length() > 0 && fgClassTypedefHash) {
1572
1573 // Check for existing equivalent.
1574
1575 if (resolvedThis != fName) {
1576 oldcl = (TClass*)gROOT->GetListOfClasses()->FindObject(resolvedThis);
1577 if (oldcl && oldcl != this) {
1578 persistentRef = oldcl->fPersistentRef.exchange(0);
1579 ForceReload (oldcl);
1580 }
1581 }
1582 TIter next( fgClassTypedefHash->GetListForObject(resolvedThis) );
1583 while ( TNameMapNode* htmp = static_cast<TNameMapNode*> (next()) ) {
1584 if (resolvedThis != htmp->String()) continue;
1585 oldcl = (TClass*)gROOT->GetListOfClasses()->FindObject(htmp->fOrigName); // gROOT->GetClass (htmp->fOrigName, kFALSE);
1586 if (oldcl && oldcl != this) {
1587 persistentRef = oldcl->fPersistentRef.exchange(0);
1588 ForceReload (oldcl);
1589 }
1590 }
1591 }
1592 if (fClassInfo) {
1594 if ( fDeclFileName == 0 || fDeclFileName[0] == '\0' ) {
1595 fDeclFileName = kUndeterminedClassInfoName;
1596 // Missing interface:
1597 // fDeclFileLine = gInterpreter->ClassInfo_FileLine( fClassInfo );
1598
1599 // But really do not want to set ImplFileLine as it is currently the
1600 // marker of being 'loaded' or not (reminder loaded == has a TClass bootstrap).
1601 }
1602 }
1603
1604 if (persistentRef) {
1605 fPersistentRef = persistentRef;
1606 } else {
1607 fPersistentRef = new TClass*;
1608 }
1609 *fPersistentRef = this;
1610
1611 if ( isStl || !strncmp(GetName(),"stdext::hash_",13) || !strncmp(GetName(),"__gnu_cxx::hash_",16) ) {
1612 if (fState != kHasTClassInit) {
1613 // If we have a TClass compiled initialization, we can safely assume that
1614 // there will also be a collection proxy.
1616 if (fCollectionProxy) {
1618
1619 // Numeric Collections have implicit conversions:
1621
1622 } else if (!silent) {
1623 Warning("Init","Collection proxy for %s was not properly initialized!",GetName());
1624 }
1625 if (fStreamer==0) {
1627 }
1628 }
1629 } else if (TClassEdit::IsStdPair(GetName())) {
1630 // std::pairs have implicit conversions
1632 }
1633
1635}
1636
1637////////////////////////////////////////////////////////////////////////////////
1638/// TClass dtor. Deletes all list that might have been created.
1639
1641{
1643
1644 // Remove from the typedef hashtables.
1646 TString resolvedThis = TClassEdit::ResolveTypedef (GetName(), kTRUE);
1647 TIter next (fgClassTypedefHash->GetListForObject (resolvedThis));
1648 while ( TNameMapNode* htmp = static_cast<TNameMapNode*> (next()) ) {
1649 if (resolvedThis == htmp->String() && htmp->fOrigName == GetName()) {
1650 fgClassTypedefHash->Remove (htmp);
1651 delete htmp;
1652 break;
1653 }
1654 }
1655 }
1656
1657 // Not owning lists, don't call Delete()
1658 // But this still need to be done first because the TList destructor
1659 // does access the object contained (via GetObject()->TestBit(kCanDelete))
1660 delete fStreamer; fStreamer =0;
1661 delete fAllPubData; fAllPubData =0;
1662 delete fAllPubMethod; fAllPubMethod=0;
1663
1664 delete fPersistentRef.load();
1665
1666 if (fBase.load())
1667 (*fBase).Delete();
1668 delete fBase.load(); fBase = 0;
1669
1670 if (fData.load())
1671 (*fData).Delete();
1672 delete fData.load(); fData = 0;
1673
1674 if (fUsingData.load())
1675 (*fUsingData).Delete();
1676 delete fUsingData.load(); fUsingData = 0;
1677
1678 if (fEnums.load())
1679 (*fEnums).Delete();
1680 delete fEnums.load(); fEnums = 0;
1681
1682 if (fFuncTemplate)
1684 delete fFuncTemplate; fFuncTemplate = 0;
1685
1686 if (fMethod.load())
1687 (*fMethod).Delete();
1688 delete fMethod.load(); fMethod=0;
1689
1690 if (fRealData)
1691 fRealData->Delete();
1692 delete fRealData; fRealData=0;
1693
1694 if (fStreamerInfo)
1696 delete fStreamerInfo; fStreamerInfo = nullptr;
1697
1698 if (fDeclFileLine >= -1)
1699 TClass::RemoveClass(this);
1700
1702 fClassInfo=0;
1703
1704 if (fClassMenuList)
1707
1709
1710 if ( fIsA ) delete fIsA;
1711
1712 if ( fRefProxy ) fRefProxy->Release();
1713 fRefProxy = 0;
1714
1715 delete fStreamer;
1716 delete fCollectionProxy;
1717 delete fIsAMethod.load();
1718 delete fSchemaRules;
1719 if (fConversionStreamerInfo.load()) {
1720 std::map<std::string, TObjArray*>::iterator it;
1721 std::map<std::string, TObjArray*>::iterator end = (*fConversionStreamerInfo).end();
1722 for( it = (*fConversionStreamerInfo).begin(); it != end; ++it ) {
1723 delete it->second;
1724 }
1725 delete fConversionStreamerInfo.load();
1726 }
1727}
1728
1729////////////////////////////////////////////////////////////////////////////////
1730
1731namespace {
1732 Int_t ReadRulesContent(FILE *f)
1733 {
1734 // Read a class.rules file which contains one rule per line with comment
1735 // starting with a #
1736 // Returns the number of rules loaded.
1737 // Returns -1 in case of error.
1738
1739 R__ASSERT(f!=0);
1740 TString rule(1024);
1741 int c, state = 0;
1742 Int_t count = 0;
1743
1744 while ((c = fgetc(f)) != EOF) {
1745 if (c == 13) // ignore CR
1746 continue;
1747 if (c == '\n') {
1748 if (state != 3) {
1749 state = 0;
1750 if (rule.Length() > 0) {
1751 if (TClass::AddRule(rule)) {
1752 ++count;
1753 }
1754 rule.Clear();
1755 }
1756 }
1757 continue;
1758 }
1759 switch (state) {
1760 case 0: // start of line
1761 switch (c) {
1762 case ' ':
1763 case '\t':
1764 break;
1765 case '#':
1766 state = 1;
1767 break;
1768 default:
1769 state = 2;
1770 break;
1771 }
1772 break;
1773
1774 case 1: // comment
1775 break;
1776
1777 case 2: // rule
1778 switch (c) {
1779 case '\\':
1780 state = 3; // Continuation request
1781 default:
1782 break;
1783 }
1784 break;
1785 }
1786 switch (state) {
1787 case 2:
1788 rule.Append(c);
1789 break;
1790 }
1791 }
1792 return count;
1793 }
1794}
1795
1796////////////////////////////////////////////////////////////////////////////////
1797/// Read the class.rules files from the default location:.
1798/// $ROOTSYS/etc/class.rules (or ROOTETCDIR/class.rules)
1799
1801{
1802 static const char *suffix = "class.rules";
1803 TString sname = suffix;
1805
1806 Int_t res = -1;
1807
1808 FILE * f = fopen(sname,"r");
1809 if (f != 0) {
1810 res = ReadRulesContent(f);
1811 fclose(f);
1812 } else {
1813 ::Error("TClass::ReadRules()", "Cannot find rules file %s", sname.Data());
1814 }
1815 return res;
1816}
1817
1818////////////////////////////////////////////////////////////////////////////////
1819/// Read a class.rules file which contains one rule per line with comment
1820/// starting with a #
1821/// - Returns the number of rules loaded.
1822/// - Returns -1 in case of error.
1823
1824Int_t TClass::ReadRules( const char *filename )
1825{
1826 if (!filename || !filename[0]) {
1827 ::Error("TClass::ReadRules", "no file name specified");
1828 return -1;
1829 }
1830
1831 FILE * f = fopen(filename,"r");
1832 if (f == 0) {
1833 ::Error("TClass::ReadRules","Failed to open %s\n",filename);
1834 return -1;
1835 }
1836 Int_t count = ReadRulesContent(f);
1837
1838 fclose(f);
1839 return count;
1840
1841}
1842
1843////////////////////////////////////////////////////////////////////////////////
1844/// Add a schema evolution customization rule.
1845/// The syntax of the rule can be either the short form:
1846/// ~~~ {.cpp}
1847/// [type=Read] classname membername [attributes=... ] [version=[...] ] [checksum=[...] ] [oldtype=...] [code={...}]
1848/// ~~~
1849/// or the long form
1850/// ~~~ {.cpp}
1851/// [type=Read] sourceClass=classname [targetclass=newClassname] [ source="type membername; [type2 membername2]" ]
1852/// [target="membername3;membername4"] [attributes=... ] [version=...] [checksum=...] [code={...}|functionname]
1853/// ~~~
1854///
1855/// For example to set HepMC::GenVertex::m_event to _not_ owned the object it is pointing to:
1856/// HepMC::GenVertex m_event attributes=NotOwner
1857///
1858/// Semantic of the tags:
1859/// - type : the type of the rule, valid values: Read, ReadRaw, Write, WriteRaw, the default is 'Read'.
1860/// - sourceClass : the name of the class as it is on the rule file
1861/// - targetClass : the name of the class as it is in the current code ; defaults to the value of sourceClass
1862/// - source : the types and names of the data members from the class on file that are needed, the list is separated by semi-colons ';'
1863/// - oldtype: in the short form only, indicates the type on disk of the data member.
1864/// - target : the names of the data members updated by this rule, the list is separated by semi-colons ';'
1865/// - attributes : list of possible qualifiers among: Owner, NotOwner
1866/// - version : list of the version of the class layout that this rule applies to. The syntax can be [1,4,5] or [2-] or [1-3] or [-3]
1867/// - checksum : comma delimited list of the checksums of the class layout that this rule applies to.
1868/// - code={...} : code to be executed for the rule or name of the function implementing it.
1869
1870Bool_t TClass::AddRule( const char *rule )
1871{
1872 ROOT::TSchemaRule *ruleobj = new ROOT::TSchemaRule();
1873 if (! ruleobj->SetFromRule( rule ) ) {
1874 delete ruleobj;
1875 return kFALSE;
1876 }
1877
1879
1880 TClass *cl = TClass::GetClass( ruleobj->GetTargetClass() );
1881 if (!cl) {
1882 // Create an empty emulated class for now.
1883 cl = gInterpreter->GenerateTClass(ruleobj->GetTargetClass(), /* emulation = */ kTRUE, /*silent = */ kTRUE);
1884 }
1886
1887 TString errmsg;
1888 if( !rset->AddRule( ruleobj, ROOT::Detail::TSchemaRuleSet::kCheckConflict, &errmsg ) ) {
1889 ::Warning( "TClass::AddRule", "The rule for class: \"%s\": version, \"%s\" and data members: \"%s\" has been skipped because it conflicts with one of the other rules (%s).",
1890 ruleobj->GetTargetClass(), ruleobj->GetVersion(), ruleobj->GetTargetString(), errmsg.Data() );
1891 delete ruleobj;
1892 return kFALSE;
1893 }
1894 return kTRUE;
1895}
1896
1897////////////////////////////////////////////////////////////////////////////////
1898/// Adopt a new set of Data Model Evolution rules.
1899
1901{
1903
1904 delete fSchemaRules;
1905 fSchemaRules = rules;
1906 fSchemaRules->SetClass( this );
1907}
1908
1909////////////////////////////////////////////////////////////////////////////////
1910/// Return the set of the schema rules if any.
1911
1913{
1914 return fSchemaRules;
1915}
1916
1917////////////////////////////////////////////////////////////////////////////////
1918/// Return the set of the schema rules if any.
1919/// If create is true, create an empty set
1920
1922{
1923 if (create && fSchemaRules == 0) {
1925 fSchemaRules->SetClass( this );
1926 }
1927 return fSchemaRules;
1928}
1929
1930////////////////////////////////////////////////////////////////////////////////
1931
1932void TClass::AddImplFile(const char* filename, int line) {
1933 // Currently reset the implementation file and line.
1934 // In the close future, it will actually add this file and line
1935 // to a "list" of implementation files.
1936
1937 fImplFileName = filename;
1939}
1940
1941////////////////////////////////////////////////////////////////////////////////
1942/// Browse external object inherited from TObject.
1943/// It passes through inheritance tree and calls TBrowser::Add
1944/// in appropriate cases. Static function.
1945
1947{
1948 if (!obj) return 0;
1949
1950 TAutoInspector insp(b);
1951 obj->ShowMembers(insp);
1952 return insp.fCount;
1953}
1954
1955////////////////////////////////////////////////////////////////////////////////
1956/// Browse objects of of the class described by this TClass object.
1957
1958Int_t TClass::Browse(void *obj, TBrowser *b) const
1959{
1960 if (!obj) return 0;
1961
1962 TClass *actual = GetActualClass(obj);
1963 if (IsTObject()) {
1964 // Call TObject::Browse.
1965
1966 if (!fIsOffsetStreamerSet) {
1968 }
1969 TObject* realTObject = (TObject*)((size_t)obj + fOffsetStreamer);
1970 realTObject->Browse(b);
1971 return 1;
1972 } else if (actual != this) {
1973 return actual->Browse(obj, b);
1974 } else if (GetCollectionProxy()) {
1975
1976 // do something useful.
1977
1978 } else {
1979 TAutoInspector insp(b);
1980 CallShowMembers(obj,insp,kFALSE);
1981 return insp.fCount;
1982 }
1983
1984 return 0;
1985}
1986
1987////////////////////////////////////////////////////////////////////////////////
1988/// This method is called by a browser to get the class information.
1989
1991{
1992 if (!HasInterpreterInfo()) return;
1993
1994 if (b) {
1995 if (!fRealData) BuildRealData();
1996
1997 b->Add(GetListOfDataMembers(), "Data Members");
1998 b->Add(GetListOfRealData(), "Real Data Members");
1999 b->Add(GetListOfMethods(), "Methods");
2000 b->Add(GetListOfBases(), "Base Classes");
2001 }
2002}
2003
2004////////////////////////////////////////////////////////////////////////////////
2005/// Build a full list of persistent data members.
2006/// Scans the list of all data members in the class itself and also
2007/// in all base classes. For each persistent data member, inserts a
2008/// TRealData object in the list fRealData.
2009///
2010
2011void TClass::BuildRealData(void* pointer, Bool_t isTransient)
2012{
2013
2015
2016 // Only do this once.
2017 if (fRealData) {
2018 return;
2019 }
2020
2021 if (fClassVersion == 0) {
2022 isTransient = kTRUE;
2023 }
2024
2025 // When called via TMapFile (e.g. Update()) make sure that the dictionary
2026 // gets allocated on the heap and not in the mapped file.
2027 TMmallocDescTemp setreset;
2028
2029 // Handle emulated classes and STL containers specially.
2031 // We are an emulated class or an STL container.
2032 fRealData = new TList;
2033 BuildEmulatedRealData("", 0, this, isTransient);
2034 return;
2035 }
2036
2037 // return early on string
2038 static TClassRef clRefString("std::string");
2039 if (clRefString == this) {
2040 return;
2041 }
2042
2043 // Complain about stl classes ending up here (unique_ptr etc) - except for
2044 // pair where we will build .first, .second just fine
2045 // and those for which the user explicitly requested a dictionary.
2046 if (!isTransient && GetState() != kHasTClassInit
2049 Error("BuildRealData", "Inspection for %s not supported!", GetName());
2050 }
2051
2052 // The following statement will recursively call
2053 // all the subclasses of this class.
2054 fRealData = new TList;
2055 TBuildRealData brd(pointer, this);
2056
2057 // CallShowMember will force a call to InheritsFrom, which indirectly
2058 // calls TClass::GetClass. It forces the loading of new typedefs in
2059 // case some of them were not yet loaded.
2060 if ( ! CallShowMembers(pointer, brd, isTransient) ) {
2061 if ( isTransient ) {
2062 // This is a transient data member, so it is probably fine to not have
2063 // access to its content. However let's no mark it as definitively setup,
2064 // since another class might use this class for a persistent data member and
2065 // in this case we really want the error message.
2066 delete fRealData;
2067 fRealData = 0;
2068 } else {
2069 Error("BuildRealData", "Cannot find any ShowMembers function for %s!", GetName());
2070 }
2071 }
2072
2073 // Take this opportunity to build the real data for base classes.
2074 // In case one base class is abstract, it would not be possible later
2075 // to create the list of real data for this abstract class.
2076 TBaseClass* base = 0;
2077 TIter next(GetListOfBases());
2078 while ((base = (TBaseClass*) next())) {
2079 if (base->IsSTLContainer()) {
2080 continue;
2081 }
2082 TClass* c = base->GetClassPointer();
2083 if (c) {
2084 c->BuildRealData(0, isTransient);
2085 }
2086 }
2087}
2088
2089////////////////////////////////////////////////////////////////////////////////
2090/// Build the list of real data for an emulated class
2091
2092void TClass::BuildEmulatedRealData(const char *name, Long_t offset, TClass *cl, Bool_t isTransient)
2093{
2095
2097 if (Property() & kIsAbstract) {
2099 } else {
2100 info = GetStreamerInfoImpl(fClassVersion, isTransient);
2101 }
2102 if (!info) {
2103 // This class is abstract, but we don't yet have a SteamerInfo for it ...
2104 Error("BuildEmulatedRealData","Missing StreamerInfo for %s",GetName());
2105 // Humm .. no information ... let's bail out
2106 return;
2107 }
2108
2109 TIter next(info->GetElements());
2110 TStreamerElement *element;
2111 while ((element = (TStreamerElement*)next())) {
2112 Int_t etype = element->GetType();
2113 Long_t eoffset = element->GetOffset();
2114 TClass *cle = element->GetClassPointer();
2115 if (element->IsBase() || etype == TVirtualStreamerInfo::kBase) {
2116 //base class are skipped in this loop, they will be added at the end.
2117 continue;
2118 } else if (etype == TVirtualStreamerInfo::kTObject ||
2121 etype == TVirtualStreamerInfo::kAny) {
2122 //member class
2123 TString rdname; rdname.Form("%s%s",name,element->GetFullName());
2124 TRealData *rd = new TRealData(rdname,offset+eoffset,0);
2125 if (gDebug > 0) printf(" Class: %s, adding TRealData=%s, offset=%ld\n",cl->GetName(),rd->GetName(),rd->GetThisOffset());
2126 cl->GetListOfRealData()->Add(rd);
2127 // Now we a dot
2128 rdname.Form("%s%s.",name,element->GetFullName());
2129 if (cle) cle->BuildEmulatedRealData(rdname,offset+eoffset,cl, isTransient);
2130 } else {
2131 //others
2132 TString rdname; rdname.Form("%s%s",name,element->GetFullName());
2133 TRealData *rd = new TRealData(rdname,offset+eoffset,0);
2134 if (gDebug > 0) printf(" Class: %s, adding TRealData=%s, offset=%ld\n",cl->GetName(),rd->GetName(),rd->GetThisOffset());
2135 cl->GetListOfRealData()->Add(rd);
2136 }
2137 //if (fClassInfo==0 && element->IsBase()) {
2138 // if (fBase==0) fBase = new TList;
2139 // TClass *base = element->GetClassPointer();
2140 // fBase->Add(new TBaseClass(this, cl, eoffset));
2141 //}
2142 }
2143 // The base classes must added last on the list of real data (to help with ambiguous data member names)
2144 next.Reset();
2145 while ((element = (TStreamerElement*)next())) {
2146 Int_t etype = element->GetType();
2147 if (element->IsBase() || etype == TVirtualStreamerInfo::kBase) {
2148 //base class
2149 Long_t eoffset = element->GetOffset();
2150 TClass *cle = element->GetClassPointer();
2151 if (cle) cle->BuildEmulatedRealData(name,offset+eoffset,cl, isTransient);
2152 }
2153 }
2154}
2155
2156
2157////////////////////////////////////////////////////////////////////////////////
2158/// Calculate the offset between an object of this class to
2159/// its base class TObject. The pointer can be adjusted by
2160/// that offset to access any virtual method of TObject like
2161/// Streamer() and ShowMembers().
2162
2164{
2167 // When called via TMapFile (e.g. Update()) make sure that the dictionary
2168 // gets allocated on the heap and not in the mapped file.
2169
2170 TMmallocDescTemp setreset;
2172 if (fStreamerType == kTObject) {
2174 }
2176 }
2177}
2178
2179
2180////////////////////////////////////////////////////////////////////////////////
2181/// Call ShowMembers() on the obj of this class type, passing insp and parent.
2182/// isATObject is -1 if unknown, 0 if it is not a TObject, and 1 if it is a TObject.
2183/// The function returns whether it was able to call ShowMembers().
2184
2185Bool_t TClass::CallShowMembers(const void* obj, TMemberInspector &insp, Bool_t isTransient) const
2186{
2187 if (fShowMembers) {
2188 // This should always works since 'pointer' should be pointing
2189 // to an object of the actual type of this TClass object.
2190 fShowMembers(obj, insp, isTransient);
2191 return kTRUE;
2192 } else {
2193
2195 if (fClassInfo) {
2196
2197 if (strcmp(GetName(), "string") == 0) {
2198 // For std::string we know that we do not have a ShowMembers
2199 // function and that it's okay.
2200 return kTRUE;
2201 }
2202 // Since we do have some dictionary information, let's
2203 // call the interpreter's ShowMember.
2204 // This works with Cling to support interpreted classes.
2205 gInterpreter->InspectMembers(insp, obj, this, isTransient);
2206 return kTRUE;
2207
2208 } else if (TVirtualStreamerInfo* sinfo = GetStreamerInfo()) {
2209 sinfo->CallShowMembers(obj, insp, isTransient);
2210 return kTRUE;
2211 } // isATObject
2212 } // fShowMembers is set
2213
2214 return kFALSE;
2215}
2216
2217////////////////////////////////////////////////////////////////////////////////
2218/// Do a ShowMembers() traversal of all members and base classes' members
2219/// using the reflection information from the interpreter. Works also for
2220/// interpreted objects.
2221
2222void TClass::InterpretedShowMembers(void* obj, TMemberInspector &insp, Bool_t isTransient)
2223{
2224 return gInterpreter->InspectMembers(insp, obj, this, isTransient);
2225}
2226
2228{
2229 if (fCanSplit >= 0) {
2230 return ! ( fCanSplit & 0x2 );
2231 }
2232
2234
2235 if (GetCollectionProxy() != nullptr) {
2236 // A collection can never affect its derived class 'splittability'
2237 return kTRUE;
2238 }
2239
2240 if (this == TRef::Class()) { fCanSplit = 2; return kFALSE; }
2241 if (this == TRefArray::Class()) { fCanSplit = 2; return kFALSE; }
2242 if (this == TArray::Class()) { fCanSplit = 2; return kFALSE; }
2243 if (this == TClonesArray::Class()) { fCanSplit = 1; return kTRUE; }
2244 if (this == TCollection::Class()) { fCanSplit = 2; return kFALSE; }
2245
2246 // TTree is not always available (for example in rootcling), so we need
2247 // to grab it silently.
2248 auto refTreeClass( TClass::GetClass("TTree",kTRUE,kTRUE) );
2249 if (this == refTreeClass) { fCanSplit = 2; return kFALSE; }
2250
2251 if (!HasDataMemberInfo()) {
2252 TVirtualStreamerInfo *sinfo = ((TClass *)this)->GetCurrentStreamerInfo();
2253 if (sinfo==0) sinfo = GetStreamerInfo();
2254 TIter next(sinfo->GetElements());
2255 TStreamerElement *element;
2256 while ((element = (TStreamerElement*)next())) {
2257 if (element->IsA() == TStreamerBase::Class()) {
2258 TClass *clbase = element->GetClassPointer();
2259 if (!clbase) {
2260 // If there is a missing base class, we can't split the immediate
2261 // derived class.
2262 fCanSplit = 0;
2263 return kFALSE;
2264 } else if (!clbase->CanSplitBaseAllow()) {
2265 fCanSplit = 2;
2266 return kFALSE;
2267 }
2268 }
2269 }
2270 }
2271
2272 // If we don't have data member info there is no more information
2273 // we can find out.
2274 if (!HasDataMemberInfo()) return kTRUE;
2275
2276 TObjLink *lnk = GetListOfBases() ? fBase.load()->FirstLink() : 0;
2277
2278 // Look at inheritance tree
2279 while (lnk) {
2280 TClass *c;
2281 TBaseClass *base = (TBaseClass*) lnk->GetObject();
2282 c = base->GetClassPointer();
2283 if(!c) {
2284 // If there is a missing base class, we can't split the immediate
2285 // derived class.
2286 fCanSplit = 0;
2287 return kFALSE;
2288 } else if (!c->CanSplitBaseAllow()) {
2289 fCanSplit = 2;
2290 return kFALSE;
2291 }
2292 lnk = lnk->Next();
2293 }
2294 return kTRUE;
2295}
2296
2297////////////////////////////////////////////////////////////////////////////////
2298/// Return true if the data member of this TClass can be saved separately.
2299
2301{
2302 // Note: add the possibility to set it for the class and the derived class.
2303 // save the info in TVirtualStreamerInfo
2304 // deal with the info in MakeProject
2305 if (fCanSplit >= 0) {
2306 // The user explicitly set the value
2307 return (fCanSplit & 0x1) == 1;
2308 }
2309
2311 TClass *This = const_cast<TClass*>(this);
2312
2313 if (this == TObject::Class()) { This->fCanSplit = 1; return kTRUE; }
2314 if (fName == "TClonesArray") { This->fCanSplit = 1; return kTRUE; }
2315 if (fRefProxy) { This->fCanSplit = 0; return kFALSE; }
2316 if (fName.BeginsWith("TVectorT<")) { This->fCanSplit = 0; return kFALSE; }
2317 if (fName.BeginsWith("TMatrixT<")) { This->fCanSplit = 0; return kFALSE; }
2318 if (fName == "string") { This->fCanSplit = 0; return kFALSE; }
2319 if (fName == "std::string") { This->fCanSplit = 0; return kFALSE; }
2320
2321 if (GetCollectionProxy()!=0) {
2322 // For STL collection we need to look inside.
2323
2324 // However we do not split collections of collections
2325 // nor collections of strings
2326 // nor collections of pointers (unless explicit request (see TBranchSTL)).
2327
2328 if (GetCollectionProxy()->HasPointers()) { This->fCanSplit = 0; return kFALSE; }
2329
2330 TClass *valueClass = GetCollectionProxy()->GetValueClass();
2331 if (valueClass == 0) { This->fCanSplit = 0; return kFALSE; }
2332 static TClassRef stdStringClass("std::string");
2333 if (valueClass==TString::Class() || valueClass==stdStringClass)
2334 { This->fCanSplit = 0; return kFALSE; }
2335 if (!valueClass->CanSplit()) { This->fCanSplit = 0; return kFALSE; }
2336 if (valueClass->GetCollectionProxy() != 0) { This->fCanSplit = 0; return kFALSE; }
2337
2338 This->fCanSplit = 1;
2339 return kTRUE;
2340
2341 }
2342
2343 if (GetStreamer() != nullptr || fStreamerFunc != nullptr) {
2344
2345 // We have an external custom streamer provided by the user, we must not
2346 // split it.
2347 This->fCanSplit = 0;
2348 return kFALSE;
2349
2351
2352 // We have a custom member function streamer or
2353 // an older (not StreamerInfo based) automatic streamer.
2354 This->fCanSplit = 0;
2355 return kFALSE;
2356 }
2357
2358 if (Size()==1) {
2359 // 'Empty' class there is nothing to split!.
2360 This->fCanSplit = 0;
2361 return kFALSE;
2362 }
2363
2364
2365 if ( !This->CanSplitBaseAllow() ) {
2366 return kFALSE;
2367 }
2368
2369 This->fCanSplit = 1;
2370 return kTRUE;
2371}
2372
2373////////////////////////////////////////////////////////////////////////////////
2374/// Return the C++ property of this class, eg. is abstract, has virtual base
2375/// class, see EClassProperty in TDictionary.h
2376
2378{
2379 if (fProperty == -1) Property();
2380 return fClassProperty;
2381}
2382
2383////////////////////////////////////////////////////////////////////////////////
2384/// Create a Clone of this TClass object using a different name but using the same 'dictionary'.
2385/// This effectively creates a hard alias for the class name.
2386
2387TObject *TClass::Clone(const char *new_name) const
2388{
2389 if (new_name == 0 || new_name[0]=='\0' || fName == new_name) {
2390 Error("Clone","The name of the class must be changed when cloning a TClass object.");
2391 return 0;
2392 }
2393
2394 // Need to lock access to TROOT::GetListOfClasses so the cloning happens atomically
2396 // Temporarily remove the original from the list of classes.
2397 TClass::RemoveClass(const_cast<TClass*>(this));
2398
2399 TClass *copy;
2400 if (fTypeInfo) {
2401 copy = new TClass(GetName(),
2403 *fTypeInfo,
2404 new TIsAProxy(*fTypeInfo),
2408 GetImplFileLine());
2409 } else {
2410 copy = new TClass(GetName(),
2415 GetImplFileLine());
2416 }
2417 copy->fShowMembers = fShowMembers;
2418 // Remove the copy before renaming it
2419 TClass::RemoveClass(copy);
2420 copy->fName = new_name;
2421 TClass::AddClass(copy);
2422
2423 copy->SetNew(fNew);
2424 copy->SetNewArray(fNewArray);
2425 copy->SetDelete(fDelete);
2431 if (fStreamer) {
2433 }
2434 // If IsZombie is true, something went wrong and we will not be
2435 // able to properly copy the collection proxy
2436 if (fCollectionProxy && !copy->IsZombie()) {
2438 }
2439 copy->SetClassSize(fSizeof);
2440 if (fRefProxy) {
2442 }
2443 TClass::AddClass(const_cast<TClass*>(this));
2444 return copy;
2445}
2446
2447////////////////////////////////////////////////////////////////////////////////
2448/// Copy the argument.
2449
2451{
2452// // This code was used too quickly test the STL Emulation layer
2453// Int_t k = TClassEdit::IsSTLCont(GetName());
2454// if (k==1||k==-1) return;
2455
2456 delete fCollectionProxy;
2457 fCollectionProxy = orig.Generate();
2458}
2459
2460////////////////////////////////////////////////////////////////////////////////
2461/// Draw detailed class inheritance structure.
2462/// If a class B inherits from a class A, the description of B is drawn
2463/// on the right side of the description of A.
2464/// Member functions overridden by B are shown in class A with a blue line
2465/// erasing the corresponding member function
2466
2468{
2469 if (!HasInterpreterInfo()) return;
2470
2471 TVirtualPad *padsav = gPad;
2472
2473 // Should we create a new canvas?
2474 TString opt=option;
2475 if (!padsav || !opt.Contains("same")) {
2476 TVirtualPad *padclass = (TVirtualPad*)(gROOT->GetListOfCanvases())->FindObject("R__class");
2477 if (!padclass) {
2478 gROOT->ProcessLine("new TCanvas(\"R__class\",\"class\",20,20,1000,750);");
2479 } else {
2480 padclass->cd();
2481 }
2482 }
2483
2484 if (gPad) gPad->DrawClassObject(this,option);
2485
2486 if (padsav) padsav->cd();
2487}
2488
2489////////////////////////////////////////////////////////////////////////////////
2490/// Dump contents of object on stdout.
2491/// Using the information in the object dictionary
2492/// each data member is interpreted.
2493/// If a data member is a pointer, the pointer value is printed
2494/// 'obj' is assume to point to an object of the class describe by this TClass
2495///
2496/// The following output is the Dump of a TArrow object:
2497/// ~~~ {.cpp}
2498/// fAngle 0 Arrow opening angle (degrees)
2499/// fArrowSize 0.2 Arrow Size
2500/// fOption.*fData
2501/// fX1 0.1 X of 1st point
2502/// fY1 0.15 Y of 1st point
2503/// fX2 0.67 X of 2nd point
2504/// fY2 0.83 Y of 2nd point
2505/// fUniqueID 0 object unique identifier
2506/// fBits 50331648 bit field status word
2507/// fLineColor 1 line color
2508/// fLineStyle 1 line style
2509/// fLineWidth 1 line width
2510/// fFillColor 19 fill area color
2511/// fFillStyle 1001 fill area style
2512/// ~~~
2513///
2514/// If noAddr is true, printout of all pointer values is skipped.
2515
2516void TClass::Dump(const void *obj, Bool_t noAddr /*=kFALSE*/) const
2517{
2518
2519 Long_t prObj = noAddr ? 0 : (Long_t)obj;
2520 if (IsTObject()) {
2521 if (!fIsOffsetStreamerSet) {
2523 }
2524 TObject *tobj = (TObject*)((Long_t)obj + fOffsetStreamer);
2525
2526
2527 if (sizeof(this) == 4)
2528 Printf("==> Dumping object at: 0x%08lx, name=%s, class=%s\n",prObj,tobj->GetName(),GetName());
2529 else
2530 Printf("==> Dumping object at: 0x%016lx, name=%s, class=%s\n",prObj,tobj->GetName(),GetName());
2531 } else {
2532
2533 if (sizeof(this) == 4)
2534 Printf("==> Dumping object at: 0x%08lx, class=%s\n",prObj,GetName());
2535 else
2536 Printf("==> Dumping object at: 0x%016lx, class=%s\n",prObj,GetName());
2537 }
2538
2539 TDumpMembers dm(noAddr);
2540 if (!CallShowMembers(obj, dm, kFALSE)) {
2541 Info("Dump", "No ShowMembers function, dumping disabled");
2542 }
2543}
2544
2545////////////////////////////////////////////////////////////////////////////////
2546/// Introduce an escape character (@) in front of a special chars.
2547/// You need to use the result immediately before it is being overwritten.
2548
2549char *TClass::EscapeChars(const char *text) const
2550{
2551 static const UInt_t maxsize = 255;
2552 static char name[maxsize+2]; //One extra if last char needs to be escaped
2553
2554 UInt_t nch = strlen(text);
2555 UInt_t icur = 0;
2556 for (UInt_t i = 0; i < nch && icur < maxsize; ++i, ++icur) {
2557 if (text[i] == '\"' || text[i] == '[' || text[i] == '~' ||
2558 text[i] == ']' || text[i] == '&' || text[i] == '#' ||
2559 text[i] == '!' || text[i] == '^' || text[i] == '<' ||
2560 text[i] == '?' || text[i] == '>') {
2561 name[icur] = '@';
2562 ++icur;
2563 }
2564 name[icur] = text[i];
2565 }
2566 name[icur] = 0;
2567 return name;
2568}
2569
2570////////////////////////////////////////////////////////////////////////////////
2571/// Return a pointer the the real class of the object.
2572/// This is equivalent to object->IsA() when the class has a ClassDef.
2573/// It is REQUIRED that object is coming from a proper pointer to the
2574/// class represented by 'this'.
2575/// Example: Special case:
2576/// ~~~ {.cpp}
2577/// class MyClass : public AnotherClass, public TObject
2578/// ~~~
2579/// then on return, one must do:
2580/// ~~~ {.cpp}
2581/// TObject *obj = (TObject*)((void*)myobject)directory->Get("some object of MyClass");
2582/// MyClass::Class()->GetActualClass(obj); // this would be wrong!!!
2583/// ~~~
2584/// Also if the class represented by 'this' and NONE of its parents classes
2585/// have a virtual ptr table, the result will be 'this' and NOT the actual
2586/// class.
2587
2588TClass *TClass::GetActualClass(const void *object) const
2589{
2590 if (object==0) return (TClass*)this;
2591 if (fIsA) {
2592 return (*fIsA)(object); // ROOT::IsA((ThisClass*)object);
2593 } else if (fGlobalIsA) {
2594 return fGlobalIsA(this,object);
2595 } else {
2596 if (IsTObject()) {
2597
2598 if (!fIsOffsetStreamerSet) {
2600 }
2601 TObject* realTObject = (TObject*)((size_t)object + fOffsetStreamer);
2602
2603 return realTObject->IsA();
2604 }
2605
2606 if (HasInterpreterInfo()) {
2607
2608 TVirtualIsAProxy *isa = 0;
2610 isa = (TVirtualIsAProxy*)gROOT->ProcessLineFast(TString::Format("new ::TInstrumentedIsAProxy<%s>(0);",GetName()));
2611 }
2612 else {
2613 isa = (TVirtualIsAProxy*)gROOT->ProcessLineFast(TString::Format("new ::TIsAProxy(typeid(%s));",GetName()));
2614 }
2615 if (isa) {
2617 const_cast<TClass*>(this)->fIsA = isa;
2618 }
2619 if (fIsA) {
2620 return (*fIsA)(object); // ROOT::IsA((ThisClass*)object);
2621 }
2622 }
2624 if (sinfo) {
2625 return sinfo->GetActualClass(object);
2626 }
2627 return (TClass*)this;
2628 }
2629}
2630
2631////////////////////////////////////////////////////////////////////////////////
2632/// Return pointer to the base class "classname". Returns 0 in case
2633/// "classname" is not a base class. Takes care of multiple inheritance.
2634
2635TClass *TClass::GetBaseClass(const char *classname)
2636{
2637 // check if class name itself is equal to classname
2638 if (strcmp(GetName(), classname) == 0) return this;
2639
2640 if (!HasDataMemberInfo()) return 0;
2641
2642 // Make sure we deal with possible aliases, we could also have normalized
2643 // the name.
2644 TClass *search = TClass::GetClass(classname,kTRUE,kTRUE);
2645
2646 if (search) return GetBaseClass(search);
2647 else return 0;
2648}
2649
2650////////////////////////////////////////////////////////////////////////////////
2651/// Return pointer to the base class "cl". Returns 0 in case "cl"
2652/// is not a base class. Takes care of multiple inheritance.
2653
2655{
2656 // check if class name itself is equal to classname
2657 if (cl == this) return this;
2658
2659 if (!HasDataMemberInfo()) return 0;
2660
2661 TObjLink *lnk = GetListOfBases() ? fBase.load()->FirstLink() : 0;
2662
2663 // otherwise look at inheritance tree
2664 while (lnk) {
2665 TClass *c, *c1;
2666 TBaseClass *base = (TBaseClass*) lnk->GetObject();
2667 c = base->GetClassPointer();
2668 if (c) {
2669 if (cl == c) return c;
2670 c1 = c->GetBaseClass(cl);
2671 if (c1) return c1;
2672 }
2673 lnk = lnk->Next();
2674 }
2675 return 0;
2676}
2677
2678////////////////////////////////////////////////////////////////////////////////
2679/// Return data member offset to the base class "cl".
2680/// - Returns -1 in case "cl" is not a base class.
2681/// - Returns -2 if cl is a base class, but we can't find the offset
2682/// because it's virtual.
2683/// Takes care of multiple inheritance.
2684
2686{
2687 // check if class name itself is equal to classname
2688 if (cl == this) return 0;
2689
2690 if (!fBase.load()) {
2692 // If the information was not provided by the root pcm files and
2693 // if we can not find the ClassInfo, we have to fall back to the
2694 // StreamerInfo
2695 if (!fClassInfo) {
2697 if (!sinfo) return -1;
2698 TStreamerElement *element;
2699 Int_t offset = 0;
2700
2701 TObjArray &elems = *(sinfo->GetElements());
2702 Int_t size = elems.GetLast()+1;
2703 for(Int_t i=0; i<size; i++) {
2704 element = (TStreamerElement*)elems[i];
2705 if (element->IsBase()) {
2706 if (element->IsA() == TStreamerBase::Class()) {
2707 TStreamerBase *base = (TStreamerBase*)element;
2708 TClass *baseclass = base->GetClassPointer();
2709 if (!baseclass) return -1;
2710 Int_t subOffset = baseclass->GetBaseClassOffsetRecurse(cl);
2711 if (subOffset == -2) return -2;
2712 if (subOffset != -1) return offset+subOffset;
2713 offset += baseclass->Size();
2714 } else if (element->IsA() == TStreamerSTL::Class()) {
2715 TStreamerSTL *base = (TStreamerSTL*)element;
2716 TClass *baseclass = base->GetClassPointer();
2717 if (!baseclass) return -1;
2718 Int_t subOffset = baseclass->GetBaseClassOffsetRecurse(cl);
2719 if (subOffset == -2) return -2;
2720 if (subOffset != -1) return offset+subOffset;
2721 offset += baseclass->Size();
2722
2723 } else {
2724 Error("GetBaseClassOffsetRecurse","Unexpected element type for base class: %s\n",element->IsA()->GetName());
2725 }
2726 }
2727 }
2728 return -1;
2729 }
2730 }
2731
2732 TClass *c;
2733 Int_t off;
2734 TBaseClass *inh;
2735 TObjLink *lnk = 0;
2736 if (fBase.load() == 0)
2737 lnk = GetListOfBases()->FirstLink();
2738 else
2739 lnk = fBase.load()->FirstLink();
2740
2741 // otherwise look at inheritance tree
2742 while (lnk) {
2743 inh = (TBaseClass *)lnk->GetObject();
2744 //use option load=kFALSE to avoid a warning like:
2745 //"Warning in <TClass::TClass>: no dictionary for class TRefCnt is available"
2746 //We can not afford to not have the class if it exist, so we
2747 //use kTRUE.
2748 c = inh->GetClassPointer(kTRUE); // kFALSE);
2749 if (c) {
2750 if (cl == c) {
2751 if ((inh->Property() & kIsVirtualBase) != 0)
2752 return -2;
2753 return inh->GetDelta();
2754 }
2755 off = c->GetBaseClassOffsetRecurse(cl);
2756 if (off == -2) return -2;
2757 if (off != -1) {
2758 return off + inh->GetDelta();
2759 }
2760 }
2761 lnk = lnk->Next();
2762 }
2763 return -1;
2764}
2765
2766////////////////////////////////////////////////////////////////////////////////
2767/// - Return data member offset to the base class "cl".
2768/// - Returns -1 in case "cl" is not a base class.
2769/// Takes care of multiple inheritance.
2770
2771Int_t TClass::GetBaseClassOffset(const TClass *toBase, void *address, bool isDerivedObject)
2772{
2773 // Warning("GetBaseClassOffset","Requires the use of fClassInfo for %s to %s",GetName(),toBase->GetName());
2774
2775 if (this == toBase) return 0;
2776
2777 if ((!address /* || !has_virtual_base */) &&
2779 // At least of the ClassInfo have not been loaded in memory yet and
2780 // since there is no virtual base class (or we don't have enough so it
2781 // would not make a difference) we can use the 'static' information
2782 Int_t offset = GetBaseClassOffsetRecurse (toBase);
2783 if (offset != -2) {
2784 return offset;
2785 }
2786 return offset;
2787 }
2788
2789 ClassInfo_t* derived = GetClassInfo();
2790 ClassInfo_t* base = toBase->GetClassInfo();
2791 if(derived && base) {
2792 // TClingClassInfo::GetBaseOffset takes the lock.
2793 return gCling->ClassInfo_GetBaseOffset(derived, base, address, isDerivedObject);
2794 }
2795 else {
2796 Int_t offset = GetBaseClassOffsetRecurse (toBase);
2797 if (offset != -2) {
2798 return offset;
2799 }
2800 }
2801 return -1;
2802}
2803
2804////////////////////////////////////////////////////////////////////////////////
2805/// Return pointer to (base) class that contains datamember.
2806
2807TClass *TClass::GetBaseDataMember(const char *datamember)
2808{
2809 if (!HasDataMemberInfo()) return 0;
2810
2811 // Check if data member exists in class itself
2812 TDataMember *dm = GetDataMember(datamember);
2813 if (dm) return this;
2814
2815 // if datamember not found in class, search in next base classes
2816 TBaseClass *inh;
2817 TIter next(GetListOfBases());
2818 while ((inh = (TBaseClass *) next())) {
2819 TClass *c = inh->GetClassPointer();
2820 if (c) {
2821 TClass *cdm = c->GetBaseDataMember(datamember);
2822 if (cdm) return cdm;
2823 }
2824 }
2825
2826 return 0;
2827}
2828
2829namespace {
2830 // A local Helper class used to keep 2 pointer (the collection proxy
2831 // and the class streamer) in the thread local storage.
2832
2833 struct TClassLocalStorage {
2834 TClassLocalStorage() : fCollectionProxy(0), fStreamer(0) {};
2835
2836 TVirtualCollectionProxy *fCollectionProxy;
2837 TClassStreamer *fStreamer;
2838
2839 static TClassLocalStorage *GetStorage(const TClass *cl)
2840 {
2841 // Return the thread storage for the TClass.
2842
2843 void **thread_ptr = (*gThreadTsd)(0,ROOT::kClassThreadSlot);
2844 if (thread_ptr) {
2845 if (*thread_ptr==0) *thread_ptr = new TExMap();
2846 TExMap *lmap = (TExMap*)(*thread_ptr);
2847 ULong_t hash = TString::Hash(&cl, sizeof(void*));
2848 ULong_t local = 0;
2849 UInt_t slot;
2850 if ((local = (ULong_t)lmap->GetValue(hash, (Long_t)cl, slot)) != 0) {
2851 } else {
2852 local = (ULong_t) new TClassLocalStorage();
2853 lmap->AddAt(slot, hash, (Long_t)cl, local);
2854 }
2855 return (TClassLocalStorage*)local;
2856 }
2857 return 0;
2858 }
2859 };
2860}
2861
2862////////////////////////////////////////////////////////////////////////////////
2863/// Return the 'type' of the STL the TClass is representing.
2864/// and return ROOT::kNotSTL if it is not representing an STL collection.
2865
2867{
2868 auto proxy = GetCollectionProxy();
2869 if (proxy) return (ROOT::ESTLType)proxy->GetCollectionType();
2870 return ROOT::kNotSTL;
2871}
2872
2873
2874////////////////////////////////////////////////////////////////////////////////
2875/// Return the proxy describing the collection (if any).
2876
2878{
2879 // Use assert, so that this line (slow because of the TClassEdit) is completely
2880 // removed in optimized code.
2881 //assert(TestBit(kLoading) || !TClassEdit::IsSTLCont(fName) || fCollectionProxy || 0 == "The TClass for the STL collection has no collection proxy!");
2883 TClassLocalStorage *local = TClassLocalStorage::GetStorage(this);
2884 if (local == 0) return fCollectionProxy;
2885 if (local->fCollectionProxy==0) local->fCollectionProxy = fCollectionProxy->Generate();
2886 return local->fCollectionProxy;
2887 }
2888 return fCollectionProxy;
2889}
2890
2891////////////////////////////////////////////////////////////////////////////////
2892/// Return the Streamer Class allowing streaming (if any).
2893
2895{
2896 if (gThreadTsd && fStreamer) {
2897 TClassLocalStorage *local = TClassLocalStorage::GetStorage(this);
2898 if (local==0) return fStreamer;
2899 if (local->fStreamer==0) {
2900 local->fStreamer = fStreamer->Generate();
2901 const std::type_info &orig = ( typeid(*fStreamer) );
2902 if (!local->fStreamer) {
2903 Warning("GetStreamer","For %s, the TClassStreamer (%s) passed's call to Generate failed!",GetName(),orig.name());
2904 } else {
2905 const std::type_info &copy = ( typeid(*local->fStreamer) );
2906 if (strcmp(orig.name(),copy.name())!=0) {
2907 Warning("GetStreamer","For %s, the TClassStreamer passed does not properly implement the Generate method (%s vs %s)\n",GetName(),orig.name(),copy.name());
2908 }
2909 }
2910 }
2911 return local->fStreamer;
2912 }
2913 return fStreamer;
2914}
2915
2916////////////////////////////////////////////////////////////////////////////////
2917/// Get a wrapper/accessor function around this class custom streamer (member function).
2918
2920{
2921 return fStreamerFunc;
2922}
2923
2924////////////////////////////////////////////////////////////////////////////////
2925/// Get a wrapper/accessor function around this class custom conversion streamer (member function).
2926
2928{
2929 return fConvStreamerFunc;
2930}
2931
2932////////////////////////////////////////////////////////////////////////////////
2933/// Return the proxy implementing the IsA functionality.
2934
2936{
2937 return fIsA;
2938}
2939
2940////////////////////////////////////////////////////////////////////////////////
2941/// Static method returning pointer to TClass of the specified class name.
2942/// If load is true an attempt is made to obtain the class by loading
2943/// the appropriate shared library (directed by the rootmap file).
2944/// If silent is 'true', do not warn about missing dictionary for the class.
2945/// (typically used for class that are used only for transient members)
2946/// Returns 0 in case class is not found.
2947
2948TClass *TClass::GetClass(const char *name, Bool_t load, Bool_t silent)
2949{
2950 return TClass::GetClass(name, load, silent, 0, 0);
2951}
2952
2953TClass *TClass::GetClass(const char *name, Bool_t load, Bool_t silent, size_t hint_pair_offset, size_t hint_pair_size)
2954{
2955 if (!name || !name[0]) return 0;
2956
2957 if (strstr(name, "(anonymous)")) return 0;
2958 if (strncmp(name,"class ",6)==0) name += 6;
2959 if (strncmp(name,"struct ",7)==0) name += 7;
2960
2961 if (!gROOT->GetListOfClasses()) return 0;
2962
2963 // FindObject will take the read lock before actually getting the
2964 // TClass pointer so we will need not get a partially initialized
2965 // object.
2966 TClass *cl = (TClass*)gROOT->GetListOfClasses()->FindObject(name);
2967
2968 // Early return to release the lock without having to execute the
2969 // long-ish normalization.
2970 if (cl && (cl->IsLoaded() || cl->TestBit(kUnloading))) return cl;
2971
2973
2974 // Now that we got the write lock, another thread may have constructed the
2975 // TClass while we were waiting, so we need to do the checks again.
2976
2977 cl = (TClass*)gROOT->GetListOfClasses()->FindObject(name);
2978 if (cl) {
2979 if (cl->IsLoaded() || cl->TestBit(kUnloading)) return cl;
2980
2981 // We could speed-up some of the search by adding (the equivalent of)
2982 //
2983 // if (cl->GetState() == kInterpreter) return cl
2984 //
2985 // In this case, if a ROOT dictionary was available when the TClass
2986 // was first requested it would have been used and if a ROOT dictionary is
2987 // loaded later on TClassTable::Add will take care of updating the TClass.
2988 // So as far as ROOT dictionary are concerned, if the current TClass is
2989 // in interpreted state, we are sure there is nothing to load.
2990 //
2991 // However (see TROOT::LoadClass), the TClass can also be loaded/provided
2992 // by a user provided TClassGenerator. We have no way of knowing whether
2993 // those do (or even can) behave the same way as the ROOT dictionary and
2994 // have the 'dictionary is now available for use' step informs the existing
2995 // TClass that their dictionary is now available.
2996
2997 //we may pass here in case of a dummy class created by TVirtualStreamerInfo
2998 load = kTRUE;
2999 }
3000
3002 // If there is a @ symbol (followed by a version number) then this is a synthetic class name created
3003 // from an already normalized name for the purpose of supporting schema evolution.
3004 // There is no dictionary or interpreter information about this kind of class, the only
3005 // (undesirable) side-effect of doing the search would be a waste of CPU time and potential
3006 // auto-loading or auto-parsing based on the scope of the name.
3007 return cl;
3008 }
3009
3010 // To avoid spurious auto parsing, let's check if the name as-is is
3011 // known in the TClassTable.
3013 if (dict) {
3014 // The name is normalized, so the result of the first search is
3015 // authoritative.
3016 if (!cl && !load) return 0;
3017
3018 TClass *loadedcl = (dict)();
3019 if (loadedcl) {
3020 loadedcl->PostLoadCheck();
3021 return loadedcl;
3022 }
3023
3024 // We should really not fall through to here, but if we do, let's just
3025 // continue as before ...
3026 }
3027
3028 std::string normalizedName;
3029 Bool_t checkTable = kFALSE;
3030
3031 if (!cl) {
3032 {
3034 TClassEdit::GetNormalizedName(normalizedName, name);
3035 }
3036 // Try the normalized name.
3037 if (normalizedName != name) {
3038 cl = (TClass*)gROOT->GetListOfClasses()->FindObject(normalizedName.c_str());
3039
3040 if (cl) {
3041 if (cl->IsLoaded() || cl->TestBit(kUnloading)) return cl;
3042
3043 //we may pass here in case of a dummy class created by TVirtualStreamerInfo
3044 load = kTRUE;
3045 }
3046 checkTable = kTRUE;
3047 }
3048 } else {
3049 normalizedName = cl->GetName(); // Use the fact that all TClass names are normalized.
3050 checkTable = load && (normalizedName != name);
3051 }
3052
3053 if (!load) return 0;
3054
3055// This assertion currently fails because of
3056// TClass *c1 = TClass::GetClass("basic_iostream<char,char_traits<char> >");
3057// TClass *c2 = TClass::GetClass("std::iostream");
3058// where the TClassEdit normalized name of iostream is basic_iostream<char>
3059// i.e missing the addition of the default parameter. This is because TClingLookupHelper
3060// uses only 'part' of TMetaUtils::GetNormalizedName.
3061
3062// if (!cl) {
3063// TDataType* dataType = (TDataType*)gROOT->GetListOfTypes()->FindObject(name);
3064// TClass *altcl = dataType ? (TClass*)gROOT->GetListOfClasses()->FindObject(dataType->GetFullTypeName()) : 0;
3065// if (altcl && normalizedName != altcl->GetName())
3066// ::Fatal("TClass::GetClass","The existing name (%s) for %s is different from the normalized name: %s\n",
3067// altcl->GetName(), name, normalizedName.c_str());
3068// }
3069
3070 // We want to avoid auto-parsing due to intentionally missing dictionary for std::pair.
3071 // However, we don't need this special treatement in rootcling (there is no auto-parsing)
3072 // and we want to make that the TClass for the pair goes through the regular creation
3073 // mechanism (i.e. in rootcling they should be in kInterpreted state and never in
3074 // kEmulated state) so that they have proper interpreter (ClassInfo) information which
3075 // will be used to create the TProtoClass (if one is requested for the pair).
3076 const bool ispair = TClassEdit::IsStdPair(normalizedName) && !IsFromRootCling();
3077 const bool ispairbase = TClassEdit::IsStdPairBase(normalizedName) && !IsFromRootCling();
3078
3079 TClass *loadedcl = 0;
3080 if (checkTable) {
3081 loadedcl = LoadClassDefault(normalizedName.c_str(),silent);
3082 } else {
3083 if (gInterpreter->AutoLoad(normalizedName.c_str(),kTRUE)) {
3084 loadedcl = LoadClassDefault(normalizedName.c_str(),silent);
3085 }
3086 auto e = TEnum::GetEnum(normalizedName.c_str(), TEnum::kNone);
3087 if (e)
3088 return nullptr;
3089 // Maybe this was a typedef: let's try to see if this is the case
3090 if (!loadedcl && !ispair && !ispairbase) {
3091 if (TDataType* theDataType = gROOT->GetType(normalizedName.c_str())){
3092 // We have a typedef: we get the name of the underlying type
3093 auto underlyingTypeName = theDataType->GetTypeName();
3094 // We see if we can bootstrap a class with it
3095 auto underlyingTypeDict = TClassTable::GetDictNorm(underlyingTypeName.Data());
3096 if (underlyingTypeDict){
3097 loadedcl = underlyingTypeDict();
3098 }
3099
3100 }
3101 }
3102 }
3103 if (loadedcl) return loadedcl;
3104
3105 // See if the TClassGenerator can produce the TClass we need.
3106 loadedcl = LoadClassCustom(normalizedName.c_str(),silent);
3107 if (loadedcl) return loadedcl;
3108
3109 // We have not been able to find a loaded TClass, return the Emulated
3110 // TClass if we have one.
3111 if (cl) return cl;
3112
3113 if (ispair) {
3114 if (hint_pair_offset && hint_pair_size) {
3115 auto pairinfo = TVirtualStreamerInfo::Factory()->GenerateInfoForPair(normalizedName, silent, hint_pair_offset, hint_pair_size);
3116 // Fall-through to allow TClass to be created when known by the interpreter
3117 // This is used in the case where TStreamerInfo can not handle them.
3118 if (pairinfo)
3119 return pairinfo->GetClass();
3120 } else {
3121 // Check if we have an STL container that might provide it.
3122 static const size_t slen = strlen("pair");
3123 static const char *associativeContainer[] = { "map", "unordered_map", "multimap",
3124 "unordered_multimap", "set", "unordered_set", "multiset", "unordered_multiset" };
3125 for(auto contname : associativeContainer) {
3126 std::string collname = contname;
3127 collname.append( normalizedName.c_str() + slen );
3128 TClass *collcl = TClass::GetClass(collname.c_str(), false, silent);
3129 if (!collcl)
3130 collcl = LoadClassDefault(collname.c_str(), silent);
3131 if (collcl) {
3132 auto p = collcl->GetCollectionProxy();
3133 if (p)
3134 cl = p->GetValueClass();
3135 if (cl)
3136 return cl;
3137 }
3138 }
3139 }
3140 } else if (TClassEdit::IsSTLCont( normalizedName.c_str() )) {
3141
3142 return gInterpreter->GenerateTClass(normalizedName.c_str(), kTRUE, silent);
3143 }
3144
3145 // Check the interpreter only after autoparsing the template if any.
3146 if (!ispairbase) {
3147 std::string::size_type posLess = normalizedName.find('<');
3148 if (posLess != std::string::npos) {
3149 gCling->AutoParse(normalizedName.substr(0, posLess).c_str());
3150 }
3151 }
3152
3153 //last attempt. Look in CINT list of all (compiled+interpreted) classes
3154 if (gDebug>0){
3155 printf("TClass::GetClass: Header Parsing - The representation of %s was not found in the type system. A lookup in the interpreter is about to be tried: this can cause parsing. This can be avoided selecting %s in the linkdef/selection file.\n",normalizedName.c_str(), normalizedName.c_str());
3156 }
3157 if (normalizedName.length()) {
3158 auto cci = gInterpreter->CheckClassInfo(normalizedName.c_str(), kTRUE /* autoload */,
3159 kTRUE /*Only class, structs and ns*/);
3160
3161 // We could have an interpreted class with an inline ClassDef, in this case we do not
3162 // want to create an 'interpreted' TClass but we want the one triggered via the call to
3163 // the Dictionary member. If we go ahead and generate the 'interpreted' version it will
3164 // replace if/when there is a call to IsA on an object of this type.
3165
3167 auto ci = gInterpreter->ClassInfo_Factory(normalizedName.c_str());
3168 auto funcDecl = gInterpreter->GetFunctionWithPrototype(ci, "Dictionary", "", false, ROOT::kExactMatch);
3169 auto method = gInterpreter->MethodInfo_Factory(funcDecl);
3170 typedef void (*tcling_callfunc_Wrapper_t)(void *, int, void **, void *);
3171 auto funcPtr = (tcling_callfunc_Wrapper_t)gInterpreter->MethodInfo_InterfaceMethod(method);
3172
3173 TClass *res = nullptr;
3174 if (funcPtr)
3175 funcPtr(0, 0, nullptr, &res);
3176 // else
3177 // We could fallback to the interpreted case ...
3178 // For now just 'fail' (return nullptr)
3179
3180 gInterpreter->MethodInfo_Delete(method);
3181 gInterpreter->ClassInfo_Delete(ci);
3182
3183 return res;
3184 } else if (cci) {
3185 // Get the normalized name based on the decl (currently the only way
3186 // to get the part to add or drop the default arguments as requested by the user)
3187 std::string alternative;
3188 gInterpreter->GetInterpreterTypeName(normalizedName.c_str(), alternative, kTRUE);
3189 if (alternative.empty())
3190 return nullptr;
3191 const char *altname = alternative.c_str();
3192 if (strncmp(altname, "std::", 5) == 0) {
3193 // For namespace (for example std::__1), GetInterpreterTypeName does
3194 // not strip std::, so we must do it explicitly here.
3195 altname += 5;
3196 }
3197 if (altname != normalizedName && strcmp(altname, name) != 0) {
3198 // altname now contains the full name of the class including a possible
3199 // namespace if there has been a using namespace statement.
3200
3201 // At least in the case C<string [2]> (normalized) vs C<string[2]> (altname)
3202 // the TClassEdit normalization and the TMetaUtils normalization leads to
3203 // two different space layout. To avoid an infinite recursion, we also
3204 // add the test on (altname != name)
3205
3206 return GetClass(altname, load);
3207 }
3208
3209 TClass *ncl = gInterpreter->GenerateTClass(normalizedName.c_str(), /* emulation = */ kFALSE, silent);
3210 if (!ncl->IsZombie()) {
3211 return ncl;
3212 }
3213 delete ncl;
3214 }
3215 }
3216 return nullptr;
3217}
3218
3219////////////////////////////////////////////////////////////////////////////////
3220/// Return pointer to class with name.
3221
3222TClass *TClass::GetClass(const std::type_info& typeinfo, Bool_t load, Bool_t /* silent */, size_t hint_pair_offset, size_t hint_pair_size)
3223{
3224 if (!gROOT->GetListOfClasses())
3225 return 0;
3226
3227 //protect access to TROOT::GetIdMap
3229
3230 TClass* cl = GetIdMap()->Find(typeinfo.name());
3231
3232 if (cl && cl->IsLoaded()) return cl;
3233
3235
3236 // Now that we got the write lock, another thread may have constructed the
3237 // TClass while we were waiting, so we need to do the checks again.
3238
3239 cl = GetIdMap()->Find(typeinfo.name());
3240
3241 if (cl) {
3242 if (cl->IsLoaded()) return cl;
3243 //we may pass here in case of a dummy class created by TVirtualStreamerInfo
3244 load = kTRUE;
3245 } else {
3246 // Note we might need support for typedefs and simple types!
3247
3248 // TDataType *objType = GetType(name, load);
3249 //if (objType) {
3250 // const char *typdfName = objType->GetTypeName();
3251 // if (typdfName && strcmp(typdfName, name)) {
3252 // cl = GetClass(typdfName, load);
3253 // return cl;
3254 // }
3255 // }
3256 }
3257
3258 if (!load) return 0;
3259
3260 DictFuncPtr_t dict = TClassTable::GetDict(typeinfo);
3261 if (dict) {
3262 cl = (dict)();
3263 if (cl) cl->PostLoadCheck();
3264 return cl;
3265 }
3266 if (cl) return cl;
3267
3268 TIter next(gROOT->GetListOfClassGenerators());
3269 TClassGenerator *gen;
3270 while( (gen = (TClassGenerator*) next()) ) {
3271 cl = gen->GetClass(typeinfo,load);
3272 if (cl) {
3273 cl->PostLoadCheck();
3274 return cl;
3275 }
3276 }
3277
3278 // try AutoLoading the typeinfo
3279 int autoload_old = gCling->SetClassAutoLoading(1);
3280 if (!autoload_old) {
3281 // Re-disable, we just meant to test
3283 }
3284 if (autoload_old && gInterpreter->AutoLoad(typeinfo,kTRUE)) {
3285 // Disable autoload to avoid potential infinite recursion
3287 cl = GetClass(typeinfo, load, hint_pair_offset, hint_pair_size);
3288 if (cl) {
3289 return cl;
3290 }
3291 }
3292
3293 if (hint_pair_offset) {
3294 int err = 0;
3295 char* demangled_name = TClassEdit::DemangleTypeIdName(typeinfo, err);
3296 if (!err) {
3297 cl = TClass::GetClass(demangled_name, load, kTRUE, hint_pair_offset, hint_pair_size);
3298 free(demangled_name);
3299 if (cl)
3300 return cl;
3301 }
3302 }
3303
3304 // last attempt. Look in the interpreter list of all (compiled+interpreted)
3305 // classes
3306 cl = gInterpreter->GetClass(typeinfo, load);
3307
3308 return cl; // Can be zero.
3309}
3310
3311////////////////////////////////////////////////////////////////////////////////
3312/// Static method returning pointer to TClass of the specified ClassInfo.
3313/// If load is true an attempt is made to obtain the class by loading
3314/// the appropriate shared library (directed by the rootmap file).
3315/// If silent is 'true', do not warn about missing dictionary for the class.
3316/// (typically used for class that are used only for transient members)
3317/// Returns 0 in case class is not found.
3318
3319TClass *TClass::GetClass(ClassInfo_t *info, Bool_t load, Bool_t silent)
3320{
3321 if (!info || !gCling->ClassInfo_IsValid(info)) return 0;
3322 if (!gROOT->GetListOfClasses()) return 0;
3323
3324 // Technically we need the write lock only for the call to ClassInfo_FullName
3325 // and GenerateTClass but FindObject will take the read lock (and LoadClass will
3326 // take the write lock). Since taking/releasing the lock is expensive, let just
3327 // take the write guard and keep it.
3329
3330 // Get the normalized name.
3332
3333 TClass *cl = (TClass*)gROOT->GetListOfClasses()->FindObject(name);
3334
3335 if (cl) {
3336 if (cl->IsLoaded()) return cl;
3337
3338 //we may pass here in case of a dummy class created by TVirtualStreamerInfo
3339 load = kTRUE;
3340
3341 }
3342
3343 if (!load) return 0;
3344
3345 TClass *loadedcl = 0;
3346 if (cl) loadedcl = gROOT->LoadClass(cl->GetName(),silent);
3347 else loadedcl = gROOT->LoadClass(name,silent);
3348
3349 if (loadedcl) return loadedcl;
3350
3351 if (cl) return cl; // If we found the class but we already have a dummy class use it.
3352
3353 // We did not find a proper TClass but we do know (we have a valid
3354 // ClassInfo) that the class is known to the interpreter.
3355 TClass *ncl = gInterpreter->GenerateTClass(info, silent);
3356 if (!ncl->IsZombie()) {
3357 return ncl;
3358 } else {
3359 delete ncl;
3360 return 0;
3361 }
3362}
3363
3364////////////////////////////////////////////////////////////////////////////////
3365
3368}
3369
3370////////////////////////////////////////////////////////////////////////////////
3371
3372Bool_t TClass::GetClass(DeclId_t id, std::vector<TClass*> &classes)
3373{
3374 if (!gROOT->GetListOfClasses()) return 0;
3375
3376 DeclIdMap_t* map = GetDeclIdMap();
3377 // Get all the TClass pointer that have the same DeclId.
3378 DeclIdMap_t::equal_range iter = map->Find(id);
3379 if (iter.first == iter.second) return false;
3380 std::vector<TClass*>::iterator vectIt = classes.begin();
3381 for (DeclIdMap_t::const_iterator it = iter.first; it != iter.second; ++it)
3382 vectIt = classes.insert(vectIt, it->second);
3383 return true;
3384}
3385
3386////////////////////////////////////////////////////////////////////////////////
3387/// Return a pointer to the dictionary loading function generated by
3388/// rootcint
3389
3391{
3392 return TClassTable::GetDict(cname);
3393}
3394
3395////////////////////////////////////////////////////////////////////////////////
3396/// Return a pointer to the dictionary loading function generated by
3397/// rootcint
3398
3399DictFuncPtr_t TClass::GetDict (const std::type_info& info)
3400{
3401 return TClassTable::GetDict(info);
3402}
3403
3404////////////////////////////////////////////////////////////////////////////////
3405/// Return pointer to datamember object with name "datamember".
3406
3407TDataMember *TClass::GetDataMember(const char *datamember) const
3408{
3409 if ((!(fData.load() && (*fData).IsLoaded()) && !HasInterpreterInfo())
3410 || datamember == 0) return 0;
3411
3412 // Strip off leading *'s and trailing [
3413 const char *start_name = datamember;
3414 while (*start_name == '*') ++start_name;
3415
3416 // Empty name are 'legal', they represent anonymous unions.
3417 // if (*start_name == 0) return 0;
3418
3419 if (const char *s = strchr(start_name, '[')){
3420 UInt_t len = s-start_name;
3421 TString name(start_name,len);
3422 return (TDataMember *)((TClass*)this)->GetListOfDataMembers(kFALSE)->FindObject(name.Data());
3423 } else {
3424 return (TDataMember *)((TClass*)this)->GetListOfDataMembers(kFALSE)->FindObject(start_name);
3425 }
3426}
3427
3428////////////////////////////////////////////////////////////////////////////////
3429/// Return name of the file containing the declaration of this class.
3430
3431const char *TClass::GetDeclFileName() const
3432{
3433 if (fDeclFileName == kUndeterminedClassInfoName)
3434 return gInterpreter->ClassInfo_FileName( fClassInfo );
3435 return fDeclFileName;
3436}
3437
3438////////////////////////////////////////////////////////////////////////////////
3439/// return offset for member name. name can be a data member in
3440/// the class itself, one of its base classes, or one member in
3441/// one of the aggregated classes.
3442///
3443/// In case of an emulated class, the list of emulated TRealData is built
3444
3446{
3447 TRealData *rd = GetRealData(name);
3448 if (rd) return rd->GetThisOffset();
3449 if (strchr(name,'[')==0) {
3450 // If this is a simple name there is a chance to find it in the
3451 // StreamerInfo even if we did not find it in the RealData.
3452 // For example an array name would be fArray[3] in RealData but
3453 // just fArray in the streamerInfo.
3454 TVirtualStreamerInfo *info = const_cast<TClass*>(this)->GetCurrentStreamerInfo();
3455 if (info) {
3456 return info->GetOffset(name);
3457 }
3458 }
3459 return 0;
3460}
3461
3462////////////////////////////////////////////////////////////////////////////////
3463/// Return pointer to TRealData element with name "name".
3464///
3465/// Name can be a data member in the class itself,
3466/// one of its base classes, or a member in
3467/// one of the aggregated classes.
3468///
3469/// In case of an emulated class, the list of emulated TRealData is built.
3470
3472{
3473 if (!fRealData) {
3474 const_cast<TClass*>(this)->BuildRealData();
3475 }
3476
3477 if (!fRealData) {
3478 return 0;
3479 }
3480
3481 if (!name) {
3482 return 0;
3483 }
3484
3485 // First try just the whole name.
3487 if (rd) {
3488 return rd;
3489 }
3490
3491 std::string givenName(name);
3492
3493 // Try ignoring the array dimensions.
3494 std::string::size_type firstBracket = givenName.find_first_of("[");
3495 if (firstBracket != std::string::npos) {
3496 // -- We are looking for an array data member.
3497 std::string nameNoDim(givenName.substr(0, firstBracket));
3498 TObjLink* lnk = fRealData->FirstLink();
3499 while (lnk) {
3500 TObject* obj = lnk->GetObject();
3501 std::string objName(obj->GetName());
3502 std::string::size_type pos = objName.find_first_of("[");
3503 // Only match arrays to arrays for now.
3504 if (pos != std::string::npos) {
3505 objName.erase(pos);
3506 if (objName == nameNoDim) {
3507 return static_cast<TRealData*>(obj);
3508 }
3509 }
3510 lnk = lnk->Next();
3511 }
3512 }
3513
3514 // Now try it as a pointer.
3515 std::ostringstream ptrname;
3516 ptrname << "*" << givenName;
3517 rd = (TRealData*) fRealData->FindObject(ptrname.str().c_str());
3518 if (rd) {
3519 return rd;
3520 }
3521
3522 // Check for a dot in the name.
3523 std::string::size_type firstDot = givenName.find_first_of(".");
3524 if (firstDot == std::string::npos) {
3525 // -- Not found, a simple name, all done.
3526 return 0;
3527 }
3528
3529 //
3530 // At this point the name has a dot in it, so it is the name
3531 // of some contained sub-object.
3532 //
3533
3534 // May be a pointer like in TH1: fXaxis.fLabels (in TRealdata is named fXaxis.*fLabels)
3535 std::string::size_type lastDot = givenName.find_last_of(".");
3536 std::ostringstream starname;
3537 starname << givenName.substr(0, lastDot) << ".*" << givenName.substr(lastDot + 1);
3538 rd = (TRealData*) fRealData->FindObject(starname.str().c_str());
3539 if (rd) {
3540 return rd;
3541 }
3542
3543 // Last attempt in case a member has been changed from
3544 // a static array to a pointer, for example the member
3545 // was arr[20] and is now *arr.
3546 //
3547 // Note: In principle, one could also take into account
3548 // the opposite situation where a member like *arr has
3549 // been converted to arr[20].
3550 //
3551 // FIXME: What about checking after the first dot as well?
3552 //
3553 std::string::size_type bracket = starname.str().find_first_of("[");
3554 if (bracket != std::string::npos) {
3555 rd = (TRealData*) fRealData->FindObject(starname.str().substr(0, bracket).c_str());
3556 if (rd) {
3557 return rd;
3558 }
3559 }
3560
3561 // Strip the first component, it may be the name of
3562 // the branch (old TBranchElement code), and try again.
3563 std::string firstDotName(givenName.substr(firstDot + 1));
3564
3565 rd = GetRealData(firstDotName.c_str());
3566 if (rd)
3567 return rd;
3568
3569 // Not found;
3570 return nullptr;
3571}
3572
3573////////////////////////////////////////////////////////////////////////////////
3574
3576{
3577 if (!gInterpreter || !HasInterpreterInfo()) return 0;
3578
3579 // The following
3581
3583}
3584
3585////////////////////////////////////////////////////////////////////////////////
3586/// Get the list of shared libraries containing the code for class cls.
3587/// The first library in the list is the one containing the class, the
3588/// others are the libraries the first one depends on. Returns 0
3589/// in case the library is not found.
3590
3592{
3593 if (!gInterpreter) return 0;
3594
3595 if (fSharedLibs.IsNull())
3596 fSharedLibs = gInterpreter->GetClassSharedLibs(fName);
3597
3598 return !fSharedLibs.IsNull() ? fSharedLibs.Data() : 0;
3599}
3600
3601////////////////////////////////////////////////////////////////////////////////
3602/// Return list containing the TBaseClass(es) of a class.
3603
3605{
3606 if (!fBase.load()) {
3607 if (fCanLoadClassInfo) {
3608 if (fState == kHasTClassInit) {
3609
3611 if (!fHasRootPcmInfo) {
3612 // The bases are in our ProtoClass; we don't need the class info.
3614 if (proto && proto->FillTClass(this))
3615 return fBase;
3616 }
3617 }
3618 // We test again on fCanLoadClassInfo has another thread may have executed it.
3620 LoadClassInfo();
3621 }
3622 }
3623 if (!fClassInfo)
3624 return nullptr;
3625
3626 if (!gInterpreter)
3627 Fatal("GetListOfBases", "gInterpreter not initialized");
3628
3630 if (!fBase.load()) {
3631 gInterpreter->CreateListOfBaseClasses(this);
3632 }
3633 }
3634 return fBase;
3635}
3636
3637////////////////////////////////////////////////////////////////////////////////
3638/// Return a list containing the TEnums of a class.
3639///
3640/// The list returned is safe to use from multiple thread without explicitly
3641/// taking the ROOT global lock.
3642///
3643/// In the case the TClass represents a namespace, the returned list will
3644/// implicit take the ROOT global lock upon any access (see TListOfEnumsWithLock)
3645///
3646/// In the case the TClass represents a class or struct and requestListLoading
3647/// is true, the list is immutable (and thus safe to access from multiple thread
3648/// without taking the global lock at all).
3649///
3650/// In the case the TClass represents a class or struct and requestListLoading
3651/// is false, the list is mutable and thus we return a TListOfEnumsWithLock
3652/// which will implicit take the ROOT global lock upon any access.
3653
3654TList *TClass::GetListOfEnums(Bool_t requestListLoading /* = kTRUE */)
3655{
3656 auto temp = fEnums.load();
3657 if (temp) {
3658 if (requestListLoading) {
3659 if (fProperty == -1) Property();
3660 if (! ((kIsClass | kIsStruct | kIsUnion) & fProperty) ) {
3662 temp->Load();
3663 } else if ( temp->IsA() == TListOfEnumsWithLock::Class() ) {
3664 // We have a class for which the list was not loaded fully at
3665 // first use.
3667 temp->Load();
3668 }
3669 }
3670 return temp;
3671 }
3672
3673 if (!requestListLoading) {
3674 if (fProperty == -1) Property();
3676 if (fEnums.load()) {
3677 return fEnums.load();
3678 }
3679
3680 if (IsFromRootCling()) // rootcling is single thread (this save some space in the rootpcm).
3681 fEnums = new TListOfEnums(this);
3682 else
3683 fEnums = new TListOfEnumsWithLock(this);
3684 return fEnums;
3685 }
3686
3688 if (fEnums.load()) {
3689 (*fEnums).Load();
3690 return fEnums.load();
3691 }
3692 if (fProperty == -1) Property();
3693 if ( (kIsClass | kIsStruct | kIsUnion) & fProperty) {
3694 // For this case, the list will be immutable
3695 temp = new TListOfEnums(this);
3696 } else {
3697 //namespaces can have enums added to them
3698 temp = new TListOfEnumsWithLock(this);
3699 }
3700 temp->Load();
3701 fEnums = temp;
3702 return temp;
3703}
3704
3705////////////////////////////////////////////////////////////////////////////////
3706/// Create the list containing the TDataMembers (of actual data members or members
3707/// pulled in through using declarations) of a class.
3708
3709TList *TClass::CreateListOfDataMembers(std::atomic<TListOfDataMembers*> &data, TDictionary::EMemberSelection selection, bool load)
3710{
3712
3713 if (!data) {
3715 // The members are in our ProtoClass; we don't need the class info.
3717 if (proto && proto->FillTClass(this))
3718 return data;
3719 }
3720
3721 data = new TListOfDataMembers(this, selection);
3722 }
3723 if (IsClassStructOrUnion()) {
3724 // If the we have a class or struct or union, the order
3725 // of data members is the list is essential since it determines their
3726 // order on file. So we must always load. Also, the list is fixed
3727 // since the language does not allow to add members.
3728 if (!(*data).IsLoaded())
3729 (*data).Load();
3730
3731 } else if (load) (*data).Load();
3732 return data;
3733}
3734
3735////////////////////////////////////////////////////////////////////////////////
3736/// Return list containing the TDataMembers of a class.
3737
3739{
3740 // Fast path, no lock? Classes load at creation time.
3741 if (IsClassStructOrUnion()) {
3742 auto data = fData.load();
3743 if (data && data->IsLoaded())
3744 return data;
3745 } else if (!load && fData)
3746 return fData;
3747
3749}
3750
3751////////////////////////////////////////////////////////////////////////////////
3752/// Return list containing the TDataMembers of using declarations of a class.
3753
3755{
3756 // Fast path, no lock? Classes load at creation time.
3757 if ((!load || IsClassStructOrUnion()) && fUsingData)
3758 return fUsingData;
3759
3761}
3762
3763////////////////////////////////////////////////////////////////////////////////
3764/// Return list containing the TEnums of a class.
3765
3767{
3769
3771 if (load) fFuncTemplate->Load();
3772 return fFuncTemplate;
3773}
3774
3775////////////////////////////////////////////////////////////////////////////////
3776/// Return list containing the TMethods of a class.
3777/// If load is true, the list is populated with all the defined function
3778/// and currently instantiated function template.
3779
3781{
3783
3784 if (!fMethod.load()) GetMethodList();
3785 if (load) {
3786 if (gDebug>0) Info("GetListOfMethods","Header Parsing - Asking for all the methods of class %s: this can involve parsing.",GetName());
3787 (*fMethod).Load();
3788 }
3789 return fMethod;
3790}
3791
3792////////////////////////////////////////////////////////////////////////////////
3793/// Return the collection of functions named "name".
3794
3796{
3797 return const_cast<TClass*>(this)->GetMethodList()->GetListForObject(name);
3798}
3799
3800
3801////////////////////////////////////////////////////////////////////////////////
3802/// Returns a list of all public methods of this class and its base classes.
3803/// Refers to a subset of the methods in GetListOfMethods() so don't do
3804/// GetListOfAllPublicMethods()->Delete().
3805/// Algorithm used to get the list is:
3806/// - put all methods of the class in the list (also protected and private
3807/// ones).
3808/// - loop over all base classes and add only those methods not already in the
3809/// list (also protected and private ones).
3810/// - once finished, loop over resulting list and remove all private and
3811/// protected methods.
3812
3814{
3816
3818 if (load) {
3819 if (gDebug>0) Info("GetListOfAllPublicMethods","Header Parsing - Asking for all the methods of class %s: this can involve parsing.",GetName());
3821 }
3822 return fAllPubMethod;
3823}
3824
3825////////////////////////////////////////////////////////////////////////////////
3826/// Returns a list of all public data members of this class and its base
3827/// classes. Refers to a subset of the data members in GetListOfDatamembers()
3828/// so don't do GetListOfAllPublicDataMembers()->Delete().
3829
3831{
3833
3835 if (load) fAllPubData->Load();
3836 return fAllPubData;
3837}
3838
3839////////////////////////////////////////////////////////////////////////////////
3840/// Returns list of methods accessible by context menu.
3841
3843{
3844 if (!HasInterpreterInfo()) return;
3845
3846 // get the base class
3847 TIter nextBase(GetListOfBases(), kIterBackward);
3848 TBaseClass *baseClass;
3849 while ((baseClass = (TBaseClass *) nextBase())) {
3850 TClass *base = baseClass->GetClassPointer();
3851 if (base) base->GetMenuItems(list);
3852 }
3853
3854 // remove methods redefined in this class with no menu
3855 TMethod *method, *m;
3857 while ((method = (TMethod*)next())) {
3858 m = (TMethod*)list->FindObject(method->GetName());
3859 if (method->IsMenuItem() != kMenuNoMenu) {
3860 if (!m)
3861 list->AddFirst(method);
3862 } else {
3863 if (m && m->GetNargs() == method->GetNargs())
3864 list->Remove(m);
3865 }
3866 }
3867}
3868
3869////////////////////////////////////////////////////////////////////////////////
3870/// Check whether a class has a dictionary or not.
3871/// This is equivalent to ask if a class is coming from a bootstrapping
3872/// procedure initiated during the loading of a library.
3873
3875{
3876 return IsLoaded();
3877}
3878
3879////////////////////////////////////////////////////////////////////////////////
3880/// Check whether a class has a dictionary or ROOT can load one.
3881/// This is equivalent to ask HasDictionary() or whether a library is known
3882/// where it can be loaded from, or whether a Dictionary function is
3883/// available because the class's dictionary library was already loaded.
3884
3886{
3887 if (TClass* cl = (TClass*)gROOT->GetListOfClasses()->FindObject(clname))
3888 return cl->IsLoaded();
3889 return gClassTable->GetDict(clname) || gInterpreter->GetClassSharedLibs(clname);
3890}
3891
3892////////////////////////////////////////////////////////////////////////////////
3893/// Verify the base classes always.
3894
3896{
3897 TList* lb = GetListOfBases();
3898 if (!lb) return;
3899 TIter nextBase(lb);
3900 TBaseClass* base = 0;
3901 while ((base = (TBaseClass*)nextBase())) {
3902 TClass* baseCl = base->GetClassPointer();
3903 if (baseCl) {
3904 baseCl->GetMissingDictionariesWithRecursionCheck(result, visited, recurse);
3905 }
3906 }
3907}
3908
3909////////////////////////////////////////////////////////////////////////////////
3910/// Verify the Data Members.
3911
3913{
3915 if (!ldm) return ;
3916 TIter nextMemb(ldm);
3917 TDataMember * dm = 0;
3918 while ((dm = (TDataMember*)nextMemb())) {
3919 // If it is a transient
3920 if(!dm->IsPersistent()) {
3921 continue;
3922 }
3923 if (dm->Property() & kIsStatic) {
3924 continue;
3925 }
3926 // If it is a built-in data type.
3927 TClass* dmTClass = 0;
3928 if (dm->GetDataType()) {
3929 // We have a basic datatype.
3930 dmTClass = nullptr;
3931 // Otherwise get the string representing the type.
3932 } else if (dm->GetTypeName()) {
3933 dmTClass = TClass::GetClass(dm->GetTypeName());
3934 }
3935 if (dmTClass) {
3936 dmTClass->GetMissingDictionariesWithRecursionCheck(result, visited, recurse);
3937 }
3938 }
3939}
3940
3942{
3943 // Pair is a special case and we have to check its elements for missing dictionaries
3944 // Pair is a transparent container so we should always look at its.
3945
3947 for (int i = 0; i < 2; i++) {
3948 TClass* pairElement = ((TStreamerElement*)SI->GetElements()->At(i))->GetClass();
3949 if (pairElement) {
3950 pairElement->GetMissingDictionariesWithRecursionCheck(result, visited, recurse);
3951 }
3952 }
3953}
3954
3955////////////////////////////////////////////////////////////////////////////////
3956/// From the second level of recursion onwards it is different state check.
3957
3959{
3960 if (result.FindObject(this) || visited.FindObject(this)) return;
3961
3962 static TClassRef sCIString("string");
3963 if (this == sCIString) return;
3964
3965 TClassEdit::TSplitType splitType(fName);
3966 if (splitType.IsTemplate()) {
3967 // We now treat special cases:
3968 // - pair
3969 // - unique_ptr
3970 // - array
3971 // - tuple
3972
3973 // Small helper to get the TClass instance from a classname and recursively
3974 // investigate it
3975 auto checkDicts = [&](const string &clName){
3976 auto cl = TClass::GetClass(clName.c_str());
3977 if (!cl) {
3978 // We try to remove * and const from the type name if any
3979 const auto clNameShortType = TClassEdit::ShortType(clName.c_str(), 1);
3980 cl = TClass::GetClass(clNameShortType.c_str());
3981 }
3982 if (cl && !cl->HasDictionary()) {
3983 cl->GetMissingDictionariesWithRecursionCheck(result, visited, recurse);
3984 }
3985 };
3986
3987 const auto &elements = splitType.fElements;
3988 const auto &templName = elements[0];
3989
3990 // Special treatment for pair.
3991 if (templName == "pair") {
3992 GetMissingDictionariesForPairElements(result, visited, recurse);
3993 return;
3994 }
3995
3996 // Special treatment of unique_ptr or array
3997 // They are treated together since they have 1 single template argument
3998 // which is interesting when checking for missing dictionaries.
3999 if (templName == "unique_ptr" || templName == "array") {
4000 checkDicts(elements[1]);
4001 return;
4002 }
4003
4004 // Special treatment of tuple
4005 // This type must be treated separately since it can have N template
4006 // arguments which are interesting, unlike unique_ptr or array.
4007 if (templName == "tuple") {
4008 // -1 because the elements end with a list of the "stars", i.e. number of
4009 // * after the type name
4010 const auto nTemplArgs = elements.size() - 1;
4011 // loop starts at 1 because the first element is the template name
4012 for (auto iTemplArg = 1U; iTemplArg < nTemplArgs; ++iTemplArg) {
4013 checkDicts(elements[iTemplArg]);
4014 }
4015 return;
4016 }
4017 } // this is not a template
4018
4019 if (!HasDictionary()) {
4020 result.Add(this);
4021 }
4022
4023 visited.Add(this);
4024 //Check whether a custom streamer
4026 if (GetCollectionProxy()) {
4027 // We need to look at the collection's content
4028 // The collection has different kind of elements the check would be required.
4029 TClass* t = 0;
4030 if ((t = GetCollectionProxy()->GetValueClass())) {
4031 if (!t->HasDictionary()) {
4032 t->GetMissingDictionariesWithRecursionCheck(result, visited, recurse);
4033 }
4034 }
4035 } else {
4036 if (recurse) {
4037 GetMissingDictionariesForMembers(result, visited, recurse);
4038 }
4039 GetMissingDictionariesForBaseClasses(result, visited, recurse);
4040 }
4041 }
4042}
4043
4044////////////////////////////////////////////////////////////////////////////////
4045/// Get the classes that have a missing dictionary starting from this one.
4046/// - With recurse = false the classes checked for missing dictionaries are:
4047/// the class itself, all base classes, direct data members,
4048/// and for collection proxies the container's
4049/// elements without iterating over the element's data members;
4050/// - With recurse = true the classes checked for missing dictionaries are:
4051/// the class itself, all base classes, recursing on the data members,
4052/// and for the collection proxies recursion on the elements of the
4053/// collection and iterating over the element's data members.
4054
4056{
4057 // Top level recursion it different from the following levels of recursion.
4058
4059 if (result.FindObject(this)) return;
4060
4061 static TClassRef sCIString("string");
4062 if (this == sCIString) return;
4063
4064 THashTable visited;
4065
4067 GetMissingDictionariesForPairElements(result, visited, recurse);
4068 return;
4069 }
4070
4071 if (!HasDictionary()) {
4072 result.Add(this);
4073 }
4074
4075 visited.Add(this);
4076
4077 //Check whether a custom streamer
4079 if (GetCollectionProxy()) {
4080 // We need to look at the collection's content
4081 // The collection has different kind of elements the check would be required.
4082 TClass* t = 0;
4083 if ((t = GetCollectionProxy()->GetValueClass())) {
4084 if (!t->HasDictionary()) {
4085 t->GetMissingDictionariesWithRecursionCheck(result, visited, recurse);
4086 }
4087 }
4088 } else {
4089 GetMissingDictionariesForMembers(result, visited, recurse);
4090 GetMissingDictionariesForBaseClasses(result, visited, recurse);
4091 }
4092 }
4093}
4094
4095////////////////////////////////////////////////////////////////////////////////
4096/// Return kTRUE if the class has elements.
4097
4098Bool_t TClass::IsFolder(void *obj) const
4099{
4100 return Browse(obj,(TBrowser*)0);
4101}
4102
4103//______________________________________________________________________________
4104//______________________________________________________________________________
4105void TClass::ReplaceWith(TClass *newcl) const
4106{
4107 // Inform the other objects to replace this object by the new TClass (newcl)
4108
4110 //we must update the class pointers pointing to 'this' in all TStreamerElements
4111 TIter nextClass(gROOT->GetListOfClasses());
4112 TClass *acl;
4114
4115 // Since we are in the process of replacing a TClass by a TClass
4116 // coming from a dictionary, there is no point in loading any
4117 // libraries during this search.
4119 while ((acl = (TClass*)nextClass())) {
4120 if (acl == newcl) continue;
4121
4122 TIter nextInfo(acl->GetStreamerInfos());
4123 while ((info = (TVirtualStreamerInfo*)nextInfo())) {
4124
4125 info->Update(this, newcl);
4126 }
4127 }
4128
4129 gInterpreter->UnRegisterTClassUpdate(this);
4130}
4131
4132////////////////////////////////////////////////////////////////////////////////
4133/// Make sure that the current ClassInfo is up to date.
4134
4136{
4137 Warning("ResetClassInfo(Long_t tagnum)","Call to deprecated interface (does nothing)");
4138}
4139
4140////////////////////////////////////////////////////////////////////////////////
4141/// Make sure that the current ClassInfo is up to date.
4142
4144{
4146
4148
4149 if (fClassInfo) {
4151 gInterpreter->ClassInfo_Delete(fClassInfo);
4152 fClassInfo = 0;
4153 }
4154 // We can not check at this point whether after the unload there will
4155 // still be interpreter information about this class (as v5 was doing),
4156 // instead this function must only be called if the definition is (about)
4157 // to be unloaded.
4158
4159 ResetCaches();
4160
4161 // We got here because the definition Decl is about to be unloaded.
4163 if (fStreamerInfo->GetEntries() != 0) {
4165 } else {
4167 }
4168 } else {
4169 // if the ClassInfo was loaded for a class with a TClass Init and it
4170 // gets unloaded, should we guess it can be reloaded?
4172 }
4173}
4174
4175////////////////////////////////////////////////////////////////////////////////
4176/// To clean out all caches.
4177
4179{
4180 R__ASSERT(!TestBit(kLoading) && "Resetting the caches does not make sense during loading!" );
4181
4182 // Not owning lists, don't call Delete(), but unload
4183 if (fData.load())
4184 (*fData).Unload();
4185 if (fUsingData.load())
4186 (*fUsingData).Unload();
4187 if (fEnums.load())
4188 (*fEnums).Unload();
4189 if (fMethod.load())
4190 (*fMethod).Unload();
4191
4192 delete fAllPubData; fAllPubData = 0;
4193
4194 if (fBase.load())
4195 (*fBase).Delete();
4196 delete fBase.load(); fBase = 0;
4197
4198 if (fRealData)
4199 fRealData->Delete();
4200 delete fRealData; fRealData=0;
4201}
4202
4203////////////////////////////////////////////////////////////////////////////////
4204/// Resets the menu list to it's standard value.
4205
4207{
4208 if (fClassMenuList)
4210 else
4211 fClassMenuList = new TList();
4213}
4214
4215////////////////////////////////////////////////////////////////////////////////
4216/// The ls function lists the contents of a class on stdout. Ls output
4217/// is typically much less verbose then Dump().
4218/// If options contains 'streamerinfo', run ls on the list of streamerInfos
4219/// and the list of conversion streamerInfos.
4220
4221void TClass::ls(Option_t *options) const
4222{
4223 TNamed::ls(options);
4224 if (options==0 || options[0]==0) return;
4225
4226 if (strstr(options,"streamerinfo")!=0) {
4227 GetStreamerInfos()->ls(options);
4228
4229 if (fConversionStreamerInfo.load()) {
4230 std::map<std::string, TObjArray*>::iterator it;
4231 std::map<std::string, TObjArray*>::iterator end = (*fConversionStreamerInfo).end();
4232 for( it = (*fConversionStreamerInfo).begin(); it != end; ++it ) {
4233 it->second->ls(options);
4234 }
4235 }
4236 }
4237}
4238
4239////////////////////////////////////////////////////////////////////////////////
4240/// Makes a customizable version of the popup menu list, i.e. makes a list
4241/// of TClassMenuItem objects of methods accessible by context menu.
4242/// The standard (and different) way consists in having just one element
4243/// in this list, corresponding to the whole standard list.
4244/// Once the customizable version is done, one can remove or add elements.
4245
4247{
4249 TClassMenuItem *menuItem;
4250
4251 // Make sure fClassMenuList is initialized and empty.
4252 GetMenuList()->Delete();
4253
4254 TList* methodList = new TList;
4255 GetMenuItems(methodList);
4256
4257 TMethod *method;
4258 TMethodArg *methodArg;
4259 TClass *classPtr = 0;
4260 TIter next(methodList);
4261
4262 while ((method = (TMethod*) next())) {
4263 // if go to a mother class method, add separator
4264 if (classPtr != method->GetClass()) {
4265 menuItem = new TClassMenuItem(TClassMenuItem::kPopupSeparator, this);
4266 fClassMenuList->AddLast(menuItem);
4267 classPtr = method->GetClass();
4268 }
4269 // Build the signature of the method
4270 TString sig;
4271 TList* margsList = method->GetListOfMethodArgs();
4272 TIter nextarg(margsList);
4273 while ((methodArg = (TMethodArg*)nextarg())) {
4274 sig = sig+","+methodArg->GetFullTypeName();
4275 }
4276 if (sig.Length()!=0) sig.Remove(0,1); // remove first comma
4278 method->GetName(), method->GetName(),0,
4279 sig.Data(),-1,TClassMenuItem::kIsSelf);
4280 if (method->IsMenuItem() == kMenuToggle) menuItem->SetToggle();
4281 fClassMenuList->Add(menuItem);
4282 }
4283 delete methodList;
4284}
4285
4286////////////////////////////////////////////////////////////////////////////////
4287/// Register the fact that an object was moved from the memory location
4288/// 'arenaFrom' to the memory location 'arenaTo'.
4289
4290void TClass::Move(void *arenaFrom, void *arenaTo) const
4291{
4292 // If/when we have access to a copy constructor (or better to a move
4293 // constructor), this function should also perform the data move.
4294 // For now we just information the repository.
4295
4296 if ((GetState() <= kEmulated) && !fCollectionProxy) {
4297 MoveAddressInRepository("TClass::Move",arenaFrom,arenaTo,this);
4298 }
4299}
4300
4301////////////////////////////////////////////////////////////////////////////////
4302/// Return the list of menu items associated with the class.
4303
4305 if (!fClassMenuList) {
4306 fClassMenuList = new TList();
4308 }
4309 return fClassMenuList;
4310}
4311
4312////////////////////////////////////////////////////////////////////////////////
4313/// Return (create an empty one if needed) the list of functions.
4314/// The major difference with GetListOfMethod is that this returns
4315/// the internal type of fMethod and thus can not be made public.
4316/// It also never 'loads' the content of the list.
4317
4319{
4320 if (!fMethod.load()) {
4321 std::unique_ptr<TListOfFunctions> temp{ new TListOfFunctions(this) };
4322 TListOfFunctions* expected = nullptr;
4323 if(fMethod.compare_exchange_strong(expected, temp.get()) ) {
4324 temp.release();
4325 }
4326 }
4327 return fMethod;
4328}
4329
4330
4331////////////////////////////////////////////////////////////////////////////////
4332/// Return pointer to method without looking at parameters.
4333/// Does not look in (possible) base classes.
4334/// Has the side effect of loading all the TMethod object in the list
4335/// of the class.
4336
4337TMethod *TClass::GetMethodAny(const char *method)
4338{
4339 if (!HasInterpreterInfo()) return 0;
4340 return (TMethod*) GetMethodList()->FindObject(method);
4341}
4342
4343////////////////////////////////////////////////////////////////////////////////
4344/// Return pointer to method without looking at parameters.
4345/// Does look in all base classes.
4346
4348{
4349 if (!HasInterpreterInfo()) return 0;
4350
4351 TMethod* m = GetMethodAny(method);
4352 if (m) return m;
4353
4354 TBaseClass *base;
4355 TIter nextb(GetListOfBases());
4356 while ((base = (TBaseClass *) nextb())) {
4357 TClass *c = base->GetClassPointer();
4358 if (c) {
4359 m = c->GetMethodAllAny(method);
4360 if (m) return m;
4361 }
4362 }
4363
4364 return 0;
4365}
4366
4367////////////////////////////////////////////////////////////////////////////////
4368/// Find the best method (if there is one) matching the parameters.
4369/// The params string must contain argument values, like "3189, \"aap\", 1.3".
4370/// The function invokes GetClassMethod to search for a possible method
4371/// in the class itself or in its base classes. Returns 0 in case method
4372/// is not found.
4373
4374TMethod *TClass::GetMethod(const char *method, const char *params,
4375 Bool_t objectIsConst /* = kFALSE */)
4376{
4378 if (!fClassInfo) return 0;
4379
4380 if (!gInterpreter)
4381 Fatal("GetMethod", "gInterpreter not initialized");
4382
4383 TInterpreter::DeclId_t decl = gInterpreter->GetFunctionWithValues(fClassInfo,
4384 method, params,
4385 objectIsConst);
4386
4387 if (!decl) return 0;
4388
4389 // search recursively in this class or its base classes
4391 if (f) return f;
4392
4393 Error("GetMethod",
4394 "\nDid not find matching TMethod <%s> with \"%s\" %sfor %s",
4395 method,params,objectIsConst ? "const " : "", GetName());
4396 return 0;
4397}
4398
4399
4400////////////////////////////////////////////////////////////////////////////////
4401/// Find a method with decl id in this class or its bases.
4402
4404 if (TFunction* method = GetMethodList()->Get(declId))
4405 return static_cast<TMethod *>(method);
4406
4407 for (auto item : *GetListOfBases())
4408 if (auto base = static_cast<TBaseClass *>(item)->GetClassPointer())
4409 if (TFunction* method = base->FindClassOrBaseMethodWithId(declId))
4410 return static_cast<TMethod *>(method);
4411
4412 return nullptr;
4413}
4414
4415////////////////////////////////////////////////////////////////////////////////
4416/// Find the method with a given prototype. The proto string must be of the
4417/// form: "char*,int,double". Returns 0 in case method is not found.
4418
4419TMethod *TClass::GetMethodWithPrototype(const char *method, const char *proto,
4420 Bool_t objectIsConst /* = kFALSE */,
4421 ROOT::EFunctionMatchMode mode /* = ROOT::kConversionMatch */)
4422{
4424 if (!fClassInfo) return 0;
4425
4426 if (!gInterpreter)
4427 Fatal("GetMethodWithPrototype", "gInterpreter not initialized");
4428
4429 TInterpreter::DeclId_t decl = gInterpreter->GetFunctionWithPrototype(fClassInfo,
4430 method, proto,
4431 objectIsConst, mode);
4432
4433 if (!decl) return 0;
4435 if (f) return f;
4436 Error("GetMethodWithPrototype",
4437 "\nDid not find matching TMethod <%s> with \"%s\" %sfor %s",
4438 method,proto,objectIsConst ? "const " : "", GetName());
4439 return 0;
4440}
4441
4442////////////////////////////////////////////////////////////////////////////////
4443/// Look for a method in this class that has the interface function
4444/// address faddr.
4445
4447{
4448 if (!HasInterpreterInfo()) return 0;
4449
4450 TMethod *m;
4451 TIter next(GetListOfMethods());
4452 while ((m = (TMethod *) next())) {
4453 if (faddr == (Long_t)m->InterfaceMethod())
4454 return m;
4455 }
4456 return 0;
4457}
4458
4459////////////////////////////////////////////////////////////////////////////////
4460/// Look for a method in this class that has the name and matches the parameters.
4461/// The params string must contain argument values, like "3189, \"aap\", 1.3".
4462/// Returns 0 in case method is not found.
4463/// See TClass::GetMethod to also search the base classes.
4464
4465TMethod *TClass::GetClassMethod(const char *name, const char* params,
4466 Bool_t objectIsConst /* = kFALSE */)
4467{
4469 if (!fClassInfo) return 0;
4470
4471 if (!gInterpreter)
4472 Fatal("GetClassMethod", "gInterpreter not initialized");
4473
4474 TInterpreter::DeclId_t decl = gInterpreter->GetFunctionWithValues(fClassInfo,
4475 name, params,
4476 objectIsConst);
4477
4478 if (!decl) return 0;
4479
4480 TFunction *f = GetMethodList()->Get(decl);
4481
4482 return (TMethod*)f; // Could be zero if the decl is actually in a base class.
4483}
4484
4485////////////////////////////////////////////////////////////////////////////////
4486/// Find the method with a given prototype. The proto string must be of the
4487/// form: "char*,int,double". Returns 0 in case method is not found.
4488/// See TClass::GetMethodWithPrototype to also search the base classes.
4489
4491 Bool_t objectIsConst /* = kFALSE */,
4492 ROOT::EFunctionMatchMode mode /* = ROOT::kConversionMatch */)
4493{
4495 if (!fClassInfo) return 0;
4496
4497 if (!gInterpreter)
4498 Fatal("GetClassMethodWithPrototype", "gInterpreter not initialized");
4499
4500 TInterpreter::DeclId_t decl = gInterpreter->GetFunctionWithPrototype(fClassInfo,
4501 name, proto,
4502 objectIsConst,
4503 mode);
4504
4505 if (!decl) return 0;
4506
4507 TFunction *f = GetMethodList()->Get(decl);
4508
4509 return (TMethod*)f; // Could be zero if the decl is actually in a base class.
4510}
4511
4512////////////////////////////////////////////////////////////////////////////////
4513/// Return the number of data members of this class
4514/// Note that in case the list of data members is not yet created, it will be done
4515/// by GetListOfDataMembers().
4516
4518{
4519 if (!HasDataMemberInfo()) return 0;
4520
4522 if (lm)
4523 return lm->GetSize();
4524 else
4525 return 0;
4526}
4527
4528////////////////////////////////////////////////////////////////////////////////
4529/// Return the number of methods of this class
4530/// Note that in case the list of methods is not yet created, it will be done
4531/// by GetListOfMethods().
4532/// This will also load/populate the list of methods, to get 'just' the
4533/// number of currently loaded methods use:
4534/// cl->GetListOfMethods(false)->GetSize();
4535
4537{
4538 if (!HasInterpreterInfo()) return 0;
4539
4540 TList *lm = GetListOfMethods();
4541 if (lm)
4542 return lm->GetSize();
4543 else
4544 return 0;
4545}
4546
4547////////////////////////////////////////////////////////////////////////////////
4548/// returns a pointer to the TVirtualStreamerInfo object for version
4549/// If the object does not exist, it is created
4550///
4551/// Note: There are two special version numbers:
4552///
4553/// - 0: Use the class version from the currently loaded class library.
4554/// - -1: Assume no class library loaded (emulated class).
4555///
4556/// Warning: If we create a new streamer info, whether or not the build
4557/// optimizes is controlled externally to us by a global variable!
4558/// Don't call us unless you have set that variable properly
4559/// with TStreamer::Optimize()!
4560///
4561
4562TVirtualStreamerInfo* TClass::GetStreamerInfo(Int_t version /* = 0 */, Bool_t isTransient /* = false */) const
4563{
4565
4566 // Version 0 is special, it means the currently loaded version.
4567 // We need to set it at the beginning to be able to guess it correctly.
4568
4569 if (version == 0)
4570 version = fClassVersion;
4571
4572 // If the StreamerInfo is assigned to the fLastReadInfo, we are
4573 // guaranteed it was built and compiled.
4574 if (sinfo && sinfo->GetClassVersion() == version)
4575 return sinfo;
4576
4577 // Note that the access to fClassVersion above is technically not thread-safe with a low probably of problems.
4578 // fClassVersion is not an atomic and is modified TClass::SetClassVersion (called from RootClassVersion via
4579 // ROOT::ResetClassVersion) and is 'somewhat' protected by the atomic fVersionUsed.
4580 // However, direct access to fClassVersion should be replaced by calls to GetClassVersion to set fVersionUsed.
4581 // Even with such a change the code here and in these functions need to be reviewed as a cursory look seem
4582 // to indicates they are not yet properly protection against mutli-thread access.
4583 //
4584 // However, the use of these functions is rare and mostly done at library loading time which should
4585 // in almost all cases preceeds the possibility of GetStreamerInfo being called from multiple thread
4586 // on that same TClass object.
4587 //
4588 // Summary: need careful review but risk of problem is extremely low.
4589
4591
4592 return GetStreamerInfoImpl(version, isTransient);
4593};
4594
4595// Implementation of/for TStreamerInfo::GetStreamerInfo.
4596// This routine assumes the global lock has been taken.
4598{
4599 // Warning: version may be -1 for an emulated class, or -2 if the
4600 // user requested the emulated streamerInfo for an abstract
4601 // base class, even though we have a dictionary for it.
4602
4603 if ((version < -1) || (version >= fStreamerInfo->GetSize())) {
4604 Error("GetStreamerInfo", "class: %s, attempting to access a wrong version: %d", GetName(), version);
4605 // FIXME: Shouldn't we go to -1 here, or better just abort?
4606 version = fClassVersion;
4607 }
4608
4610
4611 if (!sinfo && (version != fClassVersion)) {
4612 // When the requested version does not exist we return
4613 // the TVirtualStreamerInfo for the currently loaded class version.
4614 // FIXME: This arguably makes no sense, we should warn and return nothing instead.
4615 // Note: This is done for STL collections
4616 // Note: fClassVersion could be -1 here (for an emulated class).
4617 // This is also the code path take for unversioned classes.
4619 }
4620
4621 if (!sinfo) {
4622 // We just were not able to find a streamer info, we have to make a new one.
4623 TMmallocDescTemp setreset;
4624 sinfo = TVirtualStreamerInfo::Factory()->NewInfo(const_cast<TClass*>(this));
4626 if (gDebug > 0) {
4627 printf("Creating StreamerInfo for class: %s, version: %d\n", GetName(), fClassVersion);
4628 }
4630 // If we do not have a StreamerInfo for this version and we do not
4631 // have dictionary information nor a proxy, there is nothing to build!
4632 sinfo->Build(silent);
4633 }
4634 } else {
4635 if (!sinfo->IsCompiled()) {
4636 // Streamer info has not been compiled, but exists.
4637 // Therefore it was read in from a file and we have to do schema evolution?
4638 // Or it didn't have a dictionary before, but does now?
4639 sinfo->BuildOld();
4640 }
4641 }
4642
4643 // Cache the current info if we now have it.
4644 if (version == fClassVersion)
4645 fCurrentInfo = sinfo;
4646
4647 // If the compilation succeeded, remember this StreamerInfo.
4648 if (sinfo->IsCompiled())
4649 fLastReadInfo = sinfo;
4650
4651 return sinfo;
4652}
4653
4654////////////////////////////////////////////////////////////////////////////////
4655/// For the case where the requestor class is emulated and this class is abstract,
4656/// returns a pointer to the TVirtualStreamerInfo object for version with an emulated
4657/// representation whether or not the class is loaded.
4658///
4659/// If the object does not exist, it is created
4660///
4661/// Note: There are two special version numbers:
4662///
4663/// - 0: Use the class version from the currently loaded class library.
4664/// - -1: Assume no class library loaded (emulated class).
4665///
4666/// Warning: If we create a new streamer info, whether or not the build
4667/// optimizes is controlled externally to us by a global variable!
4668/// Don't call us unless you have set that variable properly
4669/// with TStreamer::Optimize()!
4670///
4671
4673{
4674 TVirtualStreamerInfo *sinfo = nullptr;
4675
4676 TString newname(GetName());
4677 newname += "@@emulated";
4678
4680
4681 TClass *emulated = TClass::GetClass(newname);
4682
4683 if (emulated)
4684 sinfo = emulated->GetStreamerInfo(version);
4685
4686 if (!sinfo) {
4687 // The emulated version of the streamerInfo is explicitly requested and has
4688 // not been built yet.
4689
4690 sinfo = (TVirtualStreamerInfo*) fStreamerInfo->At(version);
4691
4692 if (!sinfo && (version != fClassVersion)) {
4693 // When the requested version does not exist we return
4694 // the TVirtualStreamerInfo for the currently loaded class version.
4695 // FIXME: This arguably makes no sense, we should warn and return nothing instead.
4697 }
4698
4699 if (!sinfo) {
4700 // Let's take the first available StreamerInfo as a start
4701 Int_t ninfos = fStreamerInfo->GetEntriesFast() - 1;
4702 for (Int_t i = -1; sinfo == 0 && i < ninfos; ++i)
4704 }
4705
4706 if (sinfo) {
4707 sinfo = dynamic_cast<TVirtualStreamerInfo *>(sinfo->Clone());
4708 if (sinfo) {
4709 sinfo->SetClass(0);
4710 sinfo->SetName(newname);
4711 sinfo->BuildCheck();
4712 sinfo->BuildOld();
4713 sinfo->GetClass()->AddRule(TString::Format("sourceClass=%s targetClass=%s",GetName(),newname.Data()));
4714 } else {
4715 Error("GetStreamerInfoAbstractEmulated", "could not create TVirtualStreamerInfo");
4716 }
4717 }
4718 }
4719 return sinfo;
4720}
4721
4722////////////////////////////////////////////////////////////////////////////////
4723/// For the case where the requestor class is emulated and this class is abstract,
4724/// returns a pointer to the TVirtualStreamerInfo object for version with an emulated
4725/// representation whether or not the class is loaded.
4726///
4727/// If the object does not exist, it is created
4728///
4729/// Warning: If we create a new streamer info, whether or not the build
4730/// optimizes is controlled externally to us by a global variable!
4731/// Don't call us unless you have set that variable properly
4732/// with TStreamer::Optimize()!
4733///
4734
4736{
4737 TVirtualStreamerInfo *sinfo = nullptr;
4738
4739 TString newname(GetName());
4740 newname += "@@emulated";
4741
4743
4744 TClass *emulated = TClass::GetClass(newname);
4745
4746 if (emulated)
4747 sinfo = emulated->FindStreamerInfo(checksum);
4748
4749 if (!sinfo) {
4750 // The emulated version of the streamerInfo is explicitly requested and has
4751 // not been built yet.
4752
4753 sinfo = (TVirtualStreamerInfo*) FindStreamerInfo(checksum);
4754
4755 if (!sinfo && (checksum != fCheckSum)) {
4756 // When the requested version does not exist we return
4757 // the TVirtualStreamerInfo for the currently loaded class version.
4758 // FIXME: This arguably makes no sense, we should warn and return nothing instead.
4760 }
4761
4762 if (!sinfo) {
4763 // Let's take the first available StreamerInfo as a start
4764 Int_t ninfos = fStreamerInfo->GetEntriesFast() - 1;
4765 for (Int_t i = -1; sinfo == 0 && i < ninfos; ++i)
4767 }
4768
4769 if (sinfo) {
4770 sinfo = dynamic_cast<TVirtualStreamerInfo*>( sinfo->Clone() );
4771 if (sinfo) {
4772 sinfo->SetClass(0);
4773 sinfo->SetName( newname );
4774 sinfo->BuildCheck();
4775 sinfo->BuildOld();
4776 sinfo->GetClass()->AddRule(TString::Format("sourceClass=%s targetClass=%s",GetName(),newname.Data()));
4777 } else {
4778 Error("GetStreamerInfoAbstractEmulated", "could not create TVirtualStreamerInfo");
4779 }
4780 }
4781 }
4782 return sinfo;
4783}
4784
4785////////////////////////////////////////////////////////////////////////////////
4786/// When the class kIgnoreTObjectStreamer bit is set, the automatically
4787/// generated Streamer will not call TObject::Streamer.
4788/// This option saves the TObject space overhead on the file.
4789/// However, the information (fBits, fUniqueID) of TObject is lost.
4790///
4791/// Note that to be effective for objects streamed object-wise this function
4792/// must be called for the class deriving directly from TObject, eg, assuming
4793/// that BigTrack derives from Track and Track derives from TObject, one must do:
4794/// ~~~ {.cpp}
4795/// Track::Class()->IgnoreTObjectStreamer();
4796/// ~~~
4797/// and not:
4798/// ~~~ {.cpp}
4799/// BigTrack::Class()->IgnoreTObjectStreamer();
4800/// ~~~
4801/// To be effective for object streamed member-wise or split in a TTree,
4802/// this function must be called for the most derived class (i.e. BigTrack).
4803
4805{
4806 // We need to tak the lock since we are test and then setting fBits
4807 // and TStreamerInfo::fBits (and the StreamerInfo state in general)
4808 // which can also be modified by another thread.
4810
4811 if ( doIgnore && TestBit(kIgnoreTObjectStreamer)) return;
4812 if (!doIgnore && !TestBit(kIgnoreTObjectStreamer)) return;
4814 if (sinfo) {
4815 if (sinfo->IsCompiled()) {
4816 // -- Warn the user that what they are doing cannot work.
4817 // Note: The reason is that TVirtualStreamerInfo::Build() examines
4818 // the kIgnoreTObjectStreamer bit and sets the TStreamerElement
4819 // type for the TObject base class streamer element it creates
4820 // to -1 as a flag. Later on the TStreamerInfo::Compile()
4821 // member function sees the flag and does not insert the base
4822 // class element into the compiled streamer info. None of this
4823 // machinery works correctly if we are called after the streamer
4824 // info has already been built and compiled.
4825 Error("IgnoreTObjectStreamer","Must be called before the creation of StreamerInfo");
4826 return;
4827 }
4828 }
4829 if (doIgnore) SetBit (kIgnoreTObjectStreamer);
4831}
4832
4833////////////////////////////////////////////////////////////////////////////////
4834/// Return kTRUE if this class inherits from a class with name "classname".
4835/// note that the function returns kTRUE in case classname is the class itself
4836
4837Bool_t TClass::InheritsFrom(const char *classname) const
4838{
4839 if (strcmp(GetName(), classname) == 0) return kTRUE;
4840
4841 return InheritsFrom(TClass::GetClass(classname,kTRUE,kTRUE));
4842}
4843
4844////////////////////////////////////////////////////////////////////////////////
4845/// Return kTRUE if this class inherits from class cl.
4846/// note that the function returns KTRUE in case cl is the class itself
4847
4849{
4850 if (!cl) return kFALSE;
4851 if (cl == this) return kTRUE;
4852
4853 if (!HasDataMemberInfo()) {
4854 TVirtualStreamerInfo *sinfo = ((TClass *)this)->GetCurrentStreamerInfo();
4855 if (sinfo==0) sinfo = GetStreamerInfo();
4856 TIter next(sinfo->GetElements());
4857 TStreamerElement *element;
4858 while ((element = (TStreamerElement*)next())) {
4859 if (element->IsA() == TStreamerBase::Class()) {
4860 TClass *clbase = element->GetClassPointer();
4861 if (!clbase) return kFALSE; //missing class
4862 if (clbase->InheritsFrom(cl)) return kTRUE;
4863 }
4864 }
4865 return kFALSE;
4866 }
4867 // cast const away (only for member fBase which can be set in GetListOfBases())
4868 if (((TClass *)this)->GetBaseClass(cl)) return kTRUE;
4869 return kFALSE;
4870}
4871
4872////////////////////////////////////////////////////////////////////////////////
4873/// Cast obj of this class type up to baseclass cl if up is true.
4874/// Cast obj of this class type down from baseclass cl if up is false.
4875/// If this class is not a baseclass of cl return 0, else the pointer
4876/// to the cl part of this (up) or to this (down).
4877
4878void *TClass::DynamicCast(const TClass *cl, void *obj, Bool_t up)
4879{
4880 if (cl == this) return obj;
4881
4882 if (!HasDataMemberInfo()) return 0;
4883
4884 Int_t off;
4885 if ((off = GetBaseClassOffset(cl, obj)) != -1) {
4886 if (up)
4887 return (void*)((Long_t)obj+off);
4888 else
4889 return (void*)((Long_t)obj-off);
4890 }
4891 return 0;
4892}
4893
4894////////////////////////////////////////////////////////////////////////////////
4895/// Cast obj of this class type up to baseclass cl if up is true.
4896/// Cast obj of this class type down from baseclass cl if up is false.
4897/// If this class is not a baseclass of cl return 0, else the pointer
4898/// to the cl part of this (up) or to this (down).
4899
4900const void *TClass::DynamicCast(const TClass *cl, const void *obj, Bool_t up)
4901{
4902 return DynamicCast(cl,const_cast<void*>(obj),up);
4903}
4904
4905////////////////////////////////////////////////////////////////////////////////
4906/// Return a pointer to a newly allocated object of this class.
4907/// The class must have a default constructor. For meaning of
4908/// defConstructor, see TClass::IsCallingNew().
4909///
4910/// If quiet is true, do no issue a message via Error on case
4911/// of problems, just return 0.
4912///
4913/// The constructor actually called here can be customized by
4914/// using the rootcint pragma:
4915/// ~~~ {.cpp}
4916/// #pragma link C++ ioctortype UserClass;
4917/// ~~~
4918/// For example, with this pragma and a class named MyClass,
4919/// this method will called the first of the following 3
4920/// constructors which exists and is public:
4921/// ~~~ {.cpp}
4922/// MyClass(UserClass*);
4923/// MyClass(TRootIOCtor*);
4924/// MyClass(); // Or a constructor with all its arguments defaulted.
4925/// ~~~
4926///
4927/// When more than one pragma ioctortype is used, the first seen as priority
4928/// For example with:
4929/// ~~~ {.cpp}
4930/// #pragma link C++ ioctortype UserClass1;
4931/// #pragma link C++ ioctortype UserClass2;
4932/// ~~~
4933/// We look in the following order:
4934/// ~~~ {.cpp}
4935/// MyClass(UserClass1*);
4936/// MyClass(UserClass2*);
4937/// MyClass(TRootIOCtor*);
4938/// MyClass(); // Or a constructor with all its arguments defaulted.
4939/// ~~~
4940
4941void *TClass::New(ENewType defConstructor, Bool_t quiet) const
4942{
4943 auto obj = NewObject(defConstructor, quiet);
4944 if (obj.GetPtr() && obj.GetAllocator()) {
4945 // Register the object for special handling in the destructor.
4946 RegisterAddressInRepository("TClass::New", obj.GetPtr(), this);
4947 }
4948 return obj.GetPtr();
4949}
4950
4951// See TClass:New
4952// returns a TClass::ObjectPtr which remembers if the object was allocated
4953// via a TStreamerInfo.
4954
4956{
4957 ObjectPtr p;
4958
4959 if (fNew) {
4960 // We have the new operator wrapper function,
4961 // so there is a dictionary and it was generated
4962 // by rootcint, so there should be a default
4963 // constructor we can call through the wrapper.
4964 {
4965 TClass__GetCallingNewRAII callingNew(defConstructor);
4966 p = fNew(0);
4967 }
4968 if (!p && !quiet) {
4969 //Error("New", "cannot create object of class %s version %d", GetName(), fClassVersion);
4970 Error("New", "cannot create object of class %s", GetName());
4971 }
4972 } else if (HasInterpreterInfo()) {
4973 // We have the dictionary but do not have the
4974 // constructor wrapper, so the dictionary was
4975 // not generated by rootcint. Let's try to
4976 // create the object by having the interpreter
4977 // call the new operator, hopefully the class
4978 // library is loaded and there will be a default
4979 // constructor we can call.
4980 // [This is very unlikely to work, but who knows!]
4981 {
4982 TClass__GetCallingNewRAII callingNew(defConstructor);
4984 }
4985 if (!p && !quiet) {
4986 //Error("New", "cannot create object of class %s version %d", GetName(), fClassVersion);
4987 Error("New", "cannot create object of class %s", GetName());
4988 }
4989 } else if (!HasInterpreterInfo() && fCollectionProxy) {
4990 // There is no dictionary at all, so this is an emulated
4991 // class; however we do have the services of a collection proxy,
4992 // so this is an emulated STL class.
4993 {
4994 TClass__GetCallingNewRAII callingNew(defConstructor);
4996 }
4997 if (!p && !quiet) {
4998 //Error("New", "cannot create object of class %s version %d", GetName(), fClassVersion);
4999 Error("New", "cannot create object of class %s", GetName());
5000 }
5001 } else if (!HasInterpreterInfo() && !fCollectionProxy) {
5002 // There is no dictionary at all and we do not have
5003 // the services of a collection proxy available, so
5004 // use the streamer info to approximate calling a
5005 // constructor (basically we just make sure that the
5006 // pointer data members are null, unless they are marked
5007 // as preallocated with the "->" comment, in which case
5008 // we default-construct an object to point at).
5009
5010 // Do not register any TObject's that we create
5011 // as a result of creating this object.
5012 // FIXME: Why do we do this?
5013 // FIXME: Partial Answer: Is this because we may never actually deregister them???
5014
5015 Bool_t statsave = GetObjectStat();
5016 if(statsave) {
5018 }
5020 if (!sinfo) {
5021 if (!quiet)
5022 Error("New", "Cannot construct class '%s' version %d, no streamer info available!", GetName(), fClassVersion);
5023 return 0;
5024 }
5025
5026 {
5027 TClass__GetCallingNewRAII callingNew(defConstructor);
5028 p = { sinfo->New(), sinfo};
5029 }
5030
5031 // FIXME: Mistake? See note above at the GetObjectStat() call.
5032 // Allow TObject's to be registered again.
5033 if(statsave) {
5034 SetObjectStat(statsave);
5035 }
5036
5037 if (!p) {
5038 Error("New", "Failed to construct class '%s' using streamer info", GetName());
5039 }
5040
5041 return p;
5042 } else {
5043 Fatal("New", "This cannot happen!");
5044 }
5045
5046 return p;
5047}
5048
5049////////////////////////////////////////////////////////////////////////////////
5050/// Return a pointer to a newly allocated object of this class.
5051/// The class must have a default constructor. For meaning of
5052/// defConstructor, see TClass::IsCallingNew().
5053
5054void *TClass::New(void *arena, ENewType defConstructor) const
5055{
5056 auto obj = NewObject(arena, defConstructor);
5057 if (obj.GetPtr() && obj.GetAllocator()) {
5058 // Register the object for special handling in the destructor.
5059 RegisterAddressInRepository("TClass::New with placement", obj.GetPtr(), this);
5060 }
5061 return obj.GetPtr();
5062}
5063
5064////////////////////////////////////////////////////////////////////////////////
5065/// Return a pointer to a newly allocated object of this class.
5066/// The class must have a default constructor. For meaning of
5067/// defConstructor, see TClass::IsCallingNew().
5068
5069TClass::ObjectPtr TClass::NewObject(void *arena, ENewType defConstructor) const
5070{
5071 ObjectPtr p;
5072
5073 if (fNew) {
5074 // We have the new operator wrapper function,
5075 // so there is a dictionary and it was generated
5076 // by rootcint, so there should be a default
5077 // constructor we can call through the wrapper.
5078 {
5079 TClass__GetCallingNewRAII callingNew(defConstructor);
5080 p = fNew(arena);
5081 }
5082 if (!p) {
5083 Error("New with placement", "cannot create object of class %s version %d at address %p", GetName(), fClassVersion, arena);
5084 }
5085 } else if (HasInterpreterInfo()) {
5086 // We have the dictionary but do not have the
5087 // constructor wrapper, so the dictionary was
5088 // not generated by rootcint. Let's try to
5089 // create the object by having the interpreter
5090 // call the new operator, hopefully the class
5091 // library is loaded and there will be a default
5092 // constructor we can call.
5093 // [This is very unlikely to work, but who knows!]
5094 {
5095 TClass__GetCallingNewRAII callingNew(defConstructor);
5096 p = gCling->ClassInfo_New(GetClassInfo(),arena);
5097 }
5098 if (!p) {
5099 Error("New with placement", "cannot create object of class %s version %d at address %p", GetName(), fClassVersion, arena);
5100 }
5101 } else if (!HasInterpreterInfo() && fCollectionProxy) {
5102 // There is no dictionary at all, so this is an emulated
5103 // class; however we do have the services of a collection proxy,
5104 // so this is an emulated STL class.
5105 {
5106 TClass__GetCallingNewRAII callingNew(defConstructor);
5107 p = fCollectionProxy->NewObject(arena);
5108 }
5109 } else if (!HasInterpreterInfo() && !fCollectionProxy) {
5110 // There is no dictionary at all and we do not have
5111 // the services of a collection proxy available, so
5112 // use the streamer info to approximate calling a
5113 // constructor (basically we just make sure that the
5114 // pointer data members are null, unless they are marked
5115 // as preallocated with the "->" comment, in which case
5116 // we default-construct an object to point at).
5117
5118 // ???BUG??? ???WHY???
5119 // Do not register any TObject's that we create
5120 // as a result of creating this object.
5121 Bool_t statsave = GetObjectStat();
5122 if(statsave) {
5124 }
5125
5127 if (!sinfo) {
5128 Error("New with placement", "Cannot construct class '%s' version %d at address %p, no streamer info available!", GetName(), fClassVersion, arena);
5129 return 0;
5130 }
5131
5132 {
5133 TClass__GetCallingNewRAII callingNew(defConstructor);
5134 p = { sinfo->New(arena), sinfo };
5135 }
5136
5137 // ???BUG???
5138 // Allow TObject's to be registered again.
5139 if(statsave) {
5140 SetObjectStat(statsave);
5141 }
5142
5143 } else {
5144 Error("New with placement", "This cannot happen!");
5145 }
5146
5147 return p;
5148}
5149
5150////////////////////////////////////////////////////////////////////////////////
5151/// Return a pointer to a newly allocated array of objects
5152/// of this class.
5153/// The class must have a default constructor. For meaning of
5154/// defConstructor, see TClass::IsCallingNew().
5155
5156void *TClass::NewArray(Long_t nElements, ENewType defConstructor) const
5157{
5158 auto obj =