Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TClassTable.cxx
Go to the documentation of this file.
1// @(#)root/cont:$Id$
2// Author: Fons Rademakers 11/08/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 TClassTable
13\ingroup Containers
14This class registers for all classes their name, id and dictionary
15function in a hash table. Classes are automatically added by the
16ctor of a special init class when a global of this init class is
17initialized when the program starts (see the ClassImp macro).
18
19All functions in TClassTable are thread-safe.
20*/
21
22#include "TClassTable.h"
23
24#include "TClass.h"
25#include "TClassEdit.h"
26#include "TProtoClass.h"
27#include "TList.h"
28#include "TROOT.h"
29#include "TString.h"
30#include "TError.h"
31#include "TRegexp.h"
32
33#include "TObjString.h"
34#include "TMap.h"
35
36#include "TInterpreter.h"
37
38#include <map>
39#include <memory>
40#include <typeinfo>
41#include <cstdlib>
42#include <string>
43#include <mutex>
44
45using namespace ROOT;
46
48
53std::atomic<UInt_t> TClassTable::fgTally;
57
59
60static std::mutex &GetClassTableMutex()
61{
62 static std::mutex sMutex;
63 return sMutex;
64}
65
66// RAII to first normalize the input classname (operation that
67// both requires the ROOT global lock and might call `TClassTable`
68// resursively) and then acquire a lock on `TClassTable` local
69// mutex.
71 std::string fNormalizedName;
72
73public:
79
81 {
83 return;
84
85 // The recorded name is normalized, let's make sure we convert the
86 // input accordingly. This operation will take the ROOT global lock
87 // and might call recursively `TClassTable`, so this must be done
88 // outside of the `TClassTable` critical section.
90
91 GetClassTableMutex().lock();
92 }
93
95 GetClassTableMutex().unlock();
96 }
97
98 const std::string &GetNormalizedName() const {
99 return fNormalizedName;
100 }
101};
102
103////////////////////////////////////////////////////////////////////////////////
104
105namespace ROOT {
106 class TClassRec {
107 public:
109 fName(nullptr), fId(0), fDict(nullptr), fInfo(nullptr), fProto(nullptr), fNext(next)
110 {}
111
113 // TClassTable::fgIdMap->Remove(r->fInfo->name());
114 delete [] fName;
115 delete fProto;
116 delete fNext;
117 }
118
119 char *fName;
123 const std::type_info *fInfo;
126 };
127
128 class TClassAlt {
129 public:
130 TClassAlt(const char*alternate, const char *normName, TClassAlt *next) :
132 {}
133
135 // Nothing more to delete.
136 }
137
138 const char *fName; // Do not own
139 const char *fNormName; // Do not own
140 std::unique_ptr<TClassAlt> fNext;
141 };
142
143#define R__USE_STD_MAP
145#if defined R__USE_STD_MAP
146 // This wrapper class allow to avoid putting #include <map> in the
147 // TROOT.h header file.
148 public:
149 typedef std::map<std::string, TClassRec*> IdMap_t;
153#ifdef R__WIN32
154 // Window's std::map does NOT defined mapped_type
155 typedef TClassRec* mapped_type;
156#else
158#endif
159
160 private:
162
163 public:
164 void Add(const key_type &key, mapped_type &obj) {
165 fMap[key] = obj;
166 }
167
168 mapped_type Find(const key_type &key) const {
169 IdMap_t::const_iterator iter = fMap.find(key);
170 mapped_type cl = nullptr;
171 if (iter != fMap.end()) cl = iter->second;
172 return cl;
173 }
174
175 void Remove(const key_type &key) { fMap.erase(key); }
176
177 void Print() {
178 Info("TMapTypeToClassRec::Print", "printing the typeinfo map in TClassTable");
179 for (const_iterator iter = fMap.begin(); iter != fMap.end(); ++iter) {
180 printf("Key: %40s 0x%zx\n", iter->first.c_str(), (size_t)iter->second);
181 }
182 }
183#else
184 private:
185 TMap fMap;
186 public:
187#ifdef R__COMPLETE_MEM_TERMINATION
189 TIter next(&fMap);
190 TObjString *key;
191 while((key = (TObjString*)next())) {
192 delete key;
193 }
194 }
195#endif
196
197 void Add(const char *key, TClassRec *&obj)
198 {
199 // Add <key,value> pair to the map.
200
201 TObjString *realkey = new TObjString(key);
202 fMap.Add(realkey, (TObject*)obj);
203 }
204
205 TClassRec *Find(const char *key) const {
206 // Find the value corresponding the key.
207 const TPair *a = (const TPair *)fMap.FindObject(key);
208 if (a) return (TClassRec*) a->Value();
209 return 0;
210 }
211
212 void Remove(const char *key) {
213 // Remove the value corresponding the key.
214 TObjString realkey(key);
215 TObject *actual = fMap.Remove(&realkey);
216 delete actual;
217 }
218
219 void Print() {
220 // Print the content of the map.
221 Info("TMapTypeToClassRec::Print", "printing the typeinfo map in TClassTable");
222 TIter next(&fMap);
223 TObjString *key;
224 while((key = (TObjString*)next())) {
225 printf("Key: %s\n",key->String().Data());
226 TClassRec *data = (TClassRec*)fMap.GetValue(key);
227 if (data) {
228 printf(" class: %s %d\n",data->fName,data->fId);
229 } else {
230 printf(" no class: \n");
231 }
232 }
233 }
234#endif
235 };
236
237 static UInt_t ClassTableHash(const char *name, UInt_t size)
238 {
239 auto p = reinterpret_cast<const unsigned char*>( name );
240 UInt_t slot = 0;
241
242 while (*p) slot = slot<<1 ^ *p++;
243 slot %= size;
244
245 return slot;
246 }
247
248 std::vector<std::unique_ptr<TClassRec>> &GetDelayedAddClass()
249 {
250 static std::vector<std::unique_ptr<TClassRec>> delayedAddClass;
251 return delayedAddClass;
252 }
253
254 std::vector<std::pair<const char *, const char *>> &GetDelayedAddClassAlternate()
255 {
256 static std::vector<std::pair<const char *, const char *>> delayedAddClassAlternate;
258 }
259}
260
261////////////////////////////////////////////////////////////////////////////////
262/// TClassTable is a singleton (i.e. only one can exist per application).
263
265{
266 if (gClassTable) return;
267
268 fgSize = 1009; //this is the result of (int)TMath::NextPrime(1000);
269 fgTable = new TClassRec* [fgSize];
271 fgIdMap = new IdMap_t;
272 memset(fgTable, 0, fgSize * sizeof(TClassRec*));
273 memset(fgAlternate, 0, fgSize * sizeof(TClassAlt*));
274 gClassTable = this;
275
276 for (auto &&r : GetDelayedAddClass()) {
277 AddClass(r->fName, r->fId, *r->fInfo, r->fDict, r->fBits);
278 };
279 GetDelayedAddClass().clear();
280
281 for (auto &&r : GetDelayedAddClassAlternate()) {
282 AddAlternate(r.first, r.second);
283 }
285}
286
287////////////////////////////////////////////////////////////////////////////////
288/// TClassTable singleton is deleted in Terminate().
289
291{
292 // Try to avoid spurious warning from memory leak checkers.
293 if (gClassTable != this) return;
294
295 for (UInt_t i = 0; i < fgSize; i++) {
296 delete fgTable[i]; // Will delete all the elements in the chain.
297 }
298 delete [] fgTable; fgTable = nullptr;
299 delete [] fgSortedTable; fgSortedTable = nullptr;
300 delete fgIdMap; fgIdMap = nullptr;
301}
302
303////////////////////////////////////////////////////////////////////////////////
304/// Return true fs the table exist.
305/// If the table does not exist but the delayed list does, then
306/// create the table and return true.
307
309{
310 // This will be set at the lastest during TROOT construction, so before
311 // any threading could happen.
312 if (!gClassTable || !fgTable) {
313 if (GetDelayedAddClass().size()) {
314 new TClassTable;
315 return kTRUE;
316 }
317 return kFALSE;
318 }
319 return kTRUE;
320}
321
322////////////////////////////////////////////////////////////////////////////////
323/// Print the class table. Before printing the table is sorted
324/// alphabetically. Only classes specified in option are listed.
325/// The default is to list all classes.
326/// Standard wildcarding notation supported.
327
328void TClassTable::Print(Option_t *option) const
329{
330 std::lock_guard<std::mutex> lock(GetClassTableMutex());
331
332 // This is the very rare case (i.e. called before any dictionary load)
333 // so we don't need to execute this outside of the critical section.
334 if (fgTally == 0 || !fgTable)
335 return;
336
337 SortTable();
338
339 int n = 0, ninit = 0, nl = 0;
340
341 if (!option) option = "";
342 int nch = strlen(option);
343 TRegexp re(option, kTRUE);
344
345 Printf("\nDefined classes");
346 Printf("class version bits initialized");
347 Printf("================================================================");
348 for (UInt_t i = 0; i < fgTally; i++) {
350 if (!r) break;
351 n++;
352 TString s = r->fName;
353 if (nch && strcmp(option,r->fName) && s.Index(re) == kNPOS) continue;
354 nl++;
355 if (TClass::GetClass(r->fName, kFALSE)) {
356 ninit++;
357 Printf("%-35s %6d %7d Yes", r->fName, r->fId, r->fBits);
358 } else
359 Printf("%-35s %6d %7d No", r->fName, r->fId, r->fBits);
360 }
361 Printf("----------------------------------------------------------------");
362 Printf("Listed Classes: %4d Total classes: %4d initialized: %4d",nl, n, ninit);
363 Printf("================================================================\n");
364}
365
366//---- static members --------------------------------------------------------
367
368////////////////////////////////////////////////////////////////////////////////
369/// Returns class at index from sorted class table. Don't use this iterator
370/// while modifying the class table. The class table can be modified
371/// when making calls like TClass::GetClass(), etc.
372/// Returns 0 if index points beyond last class name.
373
375{
376 if (index < fgTally) {
377 std::lock_guard<std::mutex> lock(GetClassTableMutex());
378
379 SortTable();
381 if (r)
382 return r->fName;
383 }
384 return nullptr;
385}
386
387//______________________________________________________________________________
389//______________________________________________________________________________
391
392namespace ROOT { class TForNamespace {}; } // Dummy class to give a typeid to namespace (see also TGenericClassInfo)
393
394////////////////////////////////////////////////////////////////////////////////
395/// Add a class to the class table (this is a static function).
396/// Note that the given cname *must* be already normalized.
397
398void TClassTable::Add(const char *cname, Version_t id, const std::type_info &info,
400{
401 if (!cname || *cname == 0)
402 ::Fatal("TClassTable::Add()", "Failed to deduce type for '%s'", info.name());
403
404 // This will be set at the lastest during TROOT construction, so before
405 // any threading could happen.
406 if (!gClassTable)
407 new TClassTable;
408
409 std::unique_lock<std::mutex> lock(GetClassTableMutex());
410
411 // check if already in table, if so return
413 if (r->fName && r->fInfo) {
414 if ( strcmp(r->fInfo->name(), typeid(ROOT::TForNamespace).name()) ==0
415 && strcmp(info.name(), typeid(ROOT::TForNamespace).name()) ==0 ) {
416 // We have a namespace being reloaded.
417 // This okay we just keep the old one.
418 return;
419 }
421 lock.unlock(); // Warning might recursively call TClassTable during gROOT init
422 // Warn only for class that are not STD classes
423 ::Warning("TClassTable::Add", "class %s already in TClassTable", cname);
424 }
425 return;
426 } else if (ROOT::Internal::gROOTLocal && gCling) {
427 TClass *oldcl = (TClass*)gROOT->GetListOfClasses()->FindObject(cname);
428 if (oldcl) { // && oldcl->GetClassInfo()) {
429 // As a work-around to ROOT-6012, we need to register the class even if
430 // it is not a template instance, because a forward declaration in the header
431 // files loaded by the current dictionary wil also de-activate the update
432 // class info mechanism!
433
434 // The TClass exist and already has a class info, so it must
435 // correspond to a class template instantiation which the interpreter
436 // was able to make with the library containing the TClass Init.
437 // Because it is already known to the interpreter, the update class info
438 // will not be triggered, we need to force it.
440 }
441 }
442
443 if (!r->fName)
444 r->fName = StrDup(cname);
445 r->fId = id;
446 r->fBits = pragmabits;
447 r->fDict = dict;
448 r->fInfo = &info;
449
450 fgIdMap->Add(info.name(),r);
451
453}
454
455////////////////////////////////////////////////////////////////////////////////
456/// Add a class to the class table (this is a static function).
457/// The caller of this function should be holding the ROOT Write lock.
458
460{
461 // This will be set at the lastest during TROOT construction, so before
462 // any threading could happen.
463 if (!gClassTable)
464 new TClassTable;
465
466 std::unique_lock<std::mutex> lock(GetClassTableMutex());
467
468 // By definition the name in the TProtoClass is (must be) the normalized
469 // name, so there is no need to tweak it.
470 const char *cname = proto->GetName();
471
472 // check if already in table, if so return
474 if (r->fName) {
475 if (r->fProto) delete r->fProto;
476 r->fProto = proto;
477 TClass *oldcl = (TClass*)gROOT->GetListOfClasses()->FindObject(cname);
478
479 lock.unlock(); // FillTClass might recursively call TClassTable during gROOT init
480 if (oldcl && oldcl->GetState() == TClass::kHasTClassInit)
481 proto->FillTClass(oldcl);
482 return;
483 } else if (ROOT::Internal::gROOTLocal && gCling) {
484 TClass *oldcl = (TClass*)gROOT->GetListOfClasses()->FindObject(cname);
485 if (oldcl) { // && oldcl->GetClassInfo()) {
486 // As a work-around to ROOT-6012, we need to register the class even if
487 // it is not a template instance, because a forward declaration in the header
488 // files loaded by the current dictionary wil also de-activate the update
489 // class info mechanism!
490
491 lock.unlock(); // Warning might recursively call TClassTable during gROOT init
492 ::Warning("TClassTable::Add(TProtoClass*)","Called for existing class without a prior call add the dictionary function.");
493 }
494 }
495
496 r->fName = StrDup(cname);
497 r->fId = 0;
498 r->fBits = 0;
499 r->fDict = nullptr;
500 r->fInfo = nullptr;
501 r->fProto= proto;
502
504}
505
506////////////////////////////////////////////////////////////////////////////////
507
509{
510 // This will be set at the lastest during TROOT construction, so before
511 // any threading could happen.
512 if (!gClassTable)
513 new TClassTable;
514
515 std::lock_guard<std::mutex> lock(GetClassTableMutex());
516
518
519 for (const TClassAlt *a = fgAlternate[slot]; a; a = a->fNext.get()) {
520 if (strcmp(alternate,a->fName)==0) {
521 if (strcmp(normName,a->fNormName) != 0) {
522 fprintf(stderr,"Error in TClassTable::AddAlternate: "
523 "Second registration of %s with a different normalized name (old: '%s', new: '%s')\n",
524 alternate, a->fNormName, normName);
525 }
526 return nullptr;
527 }
528 }
529
531 return fgAlternate[slot];
532}
533
534////////////////////////////////////////////////////////////////////////////////
535///
537{
538 if (!alt || !gClassTable)
539 return;
540
541 std::lock_guard<std::mutex> lock(GetClassTableMutex());
542
544
545 if (!fgAlternate[slot])
546 return;
547
548 if (fgAlternate[slot] == alt)
549 fgAlternate[slot] = alt->fNext.release();
550 else {
551 for (TClassAlt *a = fgAlternate[slot]; a; a = a->fNext.get()) {
552 if (a->fNext.get() == alt) {
553 a->fNext.swap( alt->fNext );
554 assert( alt == alt->fNext.get());
555 alt->fNext.release();
556 }
557 }
558 }
559 delete alt;
560}
561
562////////////////////////////////////////////////////////////////////////////////
563
564Bool_t TClassTable::Check(const char *cname, std::string &normname)
565{
566 if (!CheckClassTableInit())
567 return kFALSE;
568
569 std::lock_guard<std::mutex> lock(GetClassTableMutex());
570
572
573 // Check if 'cname' is a known normalized name.
574 for (TClassRec *r = fgTable[slot]; r; r = r->fNext)
575 if (strcmp(cname,r->fName)==0) return kTRUE;
576
577 // See if 'cname' is register in the list of alternate names
578 for (const TClassAlt *a = fgAlternate[slot]; a; a = a->fNext.get()) {
579 if (strcmp(cname,a->fName)==0) {
580 normname = a->fNormName;
581 return kTRUE;
582 }
583 }
584
585 return kFALSE;
586}
587
588////////////////////////////////////////////////////////////////////////////////
589/// Remove a class from the class table. This happens when a shared library
590/// is unloaded (i.e. the dtor's of the global init objects are called).
591
592void TClassTable::Remove(const char *cname)
593{
594 if (!CheckClassTableInit())
595 return;
596
597 std::lock_guard<std::mutex> lock(GetClassTableMutex());
598
600
601 TClassRec *r;
602 TClassRec *prev = nullptr;
603 for (r = fgTable[slot]; r; r = r->fNext) {
604 if (!strcmp(r->fName, cname)) {
605 if (prev)
606 prev->fNext = r->fNext;
607 else
608 fgTable[slot] = r->fNext;
609 fgIdMap->Remove(r->fInfo->name());
610 r->fNext = nullptr; // Do not delete the others.
611 delete r;
612 fgTally--;
614 break;
615 }
616 prev = r;
617 }
618}
619
620////////////////////////////////////////////////////////////////////////////////
621/// Find a class by name in the class table (using hash of name). Returns
622/// 0 if the class is not in the table. Unless arguments insert is true in
623/// which case a new entry is created and returned.
624/// `cname` must be the normalized name of the class.
625
627{
628 // Internal routine, no explicit lock needed here.
629
631
632 for (TClassRec *r = fgTable[slot]; r; r = r->fNext)
633 if (strcmp(cname, r->fName) == 0)
634 return r;
635
636 if (!insert)
637 return nullptr;
638
640
641 fgTally++;
642 return fgTable[slot];
643}
644
645////////////////////////////////////////////////////////////////////////////////
646/// Returns the ID of a class.
647
649{
651
652 TClassRec *r = FindElement(guard.GetNormalizedName().c_str(), kFALSE);
653 if (r)
654 return r->fId;
655 return -1;
656}
657
658////////////////////////////////////////////////////////////////////////////////
659/// Returns the pragma bits as specified in the LinkDef.h file.
660
662{
664
665 TClassRec *r = FindElement(guard.GetNormalizedName().c_str(), kFALSE);
666 if (r)
667 return r->fBits;
668 return 0;
669}
670
671////////////////////////////////////////////////////////////////////////////////
672/// Given the class name returns the Dictionary() function of a class
673/// (uses hash of name).
674
676{
677 if (gDebug > 9) {
678 ::Info("GetDict", "searches for %s", cname);
679 fgIdMap->Print();
680 }
682
683 TClassRec *r = FindElement(guard.GetNormalizedName().c_str(), kFALSE);
684 if (r)
685 return r->fDict;
686 return nullptr;
687}
688
689////////////////////////////////////////////////////////////////////////////////
690/// Given the std::type_info returns the Dictionary() function of a class
691/// (uses hash of std::type_info::name()).
692
694{
695 if (!CheckClassTableInit())
696 return nullptr;
697
698 if (gDebug > 9)
699 ROOT::GetROOT(); // Info might recursively call TClassTable during the gROOT init
700
701 std::lock_guard<std::mutex> lock(GetClassTableMutex());
702
703 if (gDebug > 9) {
704 ::Info("GetDict", "searches for %s at 0x%zx", info.name(), (size_t)&info);
705 fgIdMap->Print();
706 }
707
708 TClassRec *r = fgIdMap->Find(info.name());
709 if (r)
710 return r->fDict;
711 return nullptr;
712}
713
714////////////////////////////////////////////////////////////////////////////////
715/// Given the normalized class name returns the Dictionary() function of a class
716/// (uses hash of name).
717
719{
720 if (!CheckClassTableInit())
721 return nullptr;
722
723 if (gDebug > 9)
724 ROOT::GetROOT(); // Info might recursively call TClassTable during the gROOT init
725
726 std::lock_guard<std::mutex> lock(GetClassTableMutex());
727
728 if (gDebug > 9) {
729 ::Info("GetDict", "searches for %s", cname);
730 fgIdMap->Print();
731 }
732
734 if (r)
735 return r->fDict;
736 return nullptr;
737}
738
739////////////////////////////////////////////////////////////////////////////////
740/// Given the class name returns the TClassProto object for the class.
741/// (uses hash of name).
742
744{
745 if (gDebug > 9) {
746 ::Info("GetDict", "searches for %s", cname);
747 }
748
749 if (!CheckClassTableInit())
750 return nullptr;
751
753
754 if (gDebug > 9) {
755 // Because of the early call to Info, gROOT is already initialized
756 // and thus this will not cause a recursive call to TClassTable.
757 ::Info("GetDict", "searches for %s", cname);
758 fgIdMap->Print();
759 }
760
761 TClassRec *r = FindElement(guard.GetNormalizedName().c_str(), kFALSE);
762 if (r)
763 return r->fProto;
764 return nullptr;
765}
766
767////////////////////////////////////////////////////////////////////////////////
768/// Given the class normalized name returns the TClassProto object for the class.
769/// (uses hash of name).
770
772{
773 if (gDebug > 9) {
774 ::Info("GetDict", "searches for %s", cname);
775 }
776
777 if (!CheckClassTableInit())
778 return nullptr;
779
780 std::lock_guard<std::mutex> lock(GetClassTableMutex());
781
782 if (gDebug > 9) {
783 fgIdMap->Print();
784 }
785
787 if (r)
788 return r->fProto;
789 return nullptr;
790}
791
792////////////////////////////////////////////////////////////////////////////////
793
794extern "C" {
795 static int ClassComp(const void *a, const void *b)
796 {
797 // Function used for sorting classes alphabetically.
798
799 return strcmp((*(TClassRec **)a)->fName, (*(TClassRec **)b)->fName);
800 }
801}
802
803////////////////////////////////////////////////////////////////////////////////
804/// Returns next class from sorted class table. Don't use this iterator
805/// while modifying the class table. The class table can be modified
806/// when making calls like TClass::GetClass(), etc.
807
809{
810 std::lock_guard<std::mutex> lock(GetClassTableMutex());
811
812 if (fgCursor < fgTally) {
814 return r->fName;
815 }
816
817 return nullptr;
818}
819
820////////////////////////////////////////////////////////////////////////////////
821/// Print the class table. Before printing the table is sorted
822/// alphabetically.
823
825{
826 if (fgTally == 0 || !fgTable)
827 return;
828
829 std::lock_guard<std::mutex> lock(GetClassTableMutex());
830
831 SortTable();
832
833 int n = 0, ninit = 0;
834
835 Printf("\nDefined classes");
836 Printf("class version bits initialized");
837 Printf("================================================================");
838 UInt_t last = fgTally;
839 for (UInt_t i = 0; i < last; i++) {
841 if (!r) break;
842 n++;
843 // Do not use TClass::GetClass to avoid any risk of autoloading.
844 if (gROOT->GetListOfClasses()->FindObject(r->fName)) {
845 ninit++;
846 Printf("%-35s %6d %7d Yes", r->fName, r->fId, r->fBits);
847 } else
848 Printf("%-35s %6d %7d No", r->fName, r->fId, r->fBits);
849 }
850 Printf("----------------------------------------------------------------");
851 Printf("Total classes: %4d initialized: %4d", n, ninit);
852 Printf("================================================================\n");
853}
854
855////////////////////////////////////////////////////////////////////////////////
856/// Sort the class table by ascending class ID's.
857
859{
860 // Internal routine.
861
862 if (!fgSorted) {
863 delete [] fgSortedTable;
865
866 int j = 0;
867 for (UInt_t i = 0; i < fgSize; i++)
868 for (TClassRec *r = fgTable[i]; r; r = r->fNext)
869 fgSortedTable[j++] = r;
870
872 fgSorted = kTRUE;
873 }
874}
875
876////////////////////////////////////////////////////////////////////////////////
877/// Deletes the class table (this static class function calls the dtor).
878
880{
881 if (gClassTable) {
882 for (UInt_t i = 0; i < fgSize; i++)
883 delete fgTable[i]; // Will delete all the elements in the chain.
884
885 delete [] fgTable; fgTable = nullptr;
886 delete [] fgSortedTable; fgSortedTable = nullptr;
887 delete fgIdMap; fgIdMap = nullptr;
888 fgSize = 0;
890 }
891}
892
893////////////////////////////////////////////////////////////////////////////////
894/// Global function called by the ctor of a class's init class
895/// (see the ClassImp macro).
896
897void ROOT::AddClass(const char *cname, Version_t id,
898 const std::type_info& info,
899 DictFuncPtr_t dict,
901{
902 if (!TROOT::Initialized() && !gClassTable) {
903 auto r = std::unique_ptr<TClassRec>(new TClassRec(nullptr));
904 r->fName = StrDup(cname);
905 r->fId = id;
906 r->fBits = pragmabits;
907 r->fDict = dict;
908 r->fInfo = &info;
909 GetDelayedAddClass().emplace_back(std::move(r));
910 } else {
912 }
913}
914
915////////////////////////////////////////////////////////////////////////////////
916/// Global function called by GenerateInitInstance.
917/// (see the ClassImp macro).
918
920{
921 if (!TROOT::Initialized() && !gClassTable) {
923 // If a library is loaded before gROOT is initialized we can assume
924 // it is hard linked along side libCore (or is libCore) thus can't
925 // really be unloaded.
926 return nullptr;
927 } else {
929 }
930}
931
933{
934 // This routine is meant to be called (indirectly) by dlclose so we
935 // we are guaranteed that the library initialization has completed.
937}
938
939////////////////////////////////////////////////////////////////////////////////
940/// Global function to update the version number.
941/// This is called via the RootClassVersion macro.
942///
943/// if cl!=0 and cname==-1, set the new class version if and only is
944/// greater than the existing one and greater or equal to 2;
945/// and also ignore the request if fVersionUsed is true.
946///
947/// Note on class version number:
948/// - If no class has been specified, TClass::GetVersion will return -1
949/// - The Class Version 0 request the whole object to be transient
950/// - The Class Version 1, unless specify via ClassDef indicates that the
951/// I/O should use the TClass checksum to distinguish the layout of the class
953{
954 if (cname && cname != (void*)-1 && TClassTable::CheckClassTableInit()) {
957 if (r)
958 r->fId = newid;
959 }
960 if (cl) {
961 if (cl->fVersionUsed) {
962 // Problem, the reset is called after the first usage!
963 if (cname!=(void*)-1)
964 Error("ResetClassVersion","Version number of %s can not be changed after first usage!",
965 cl->GetName());
966 } else {
967 if (newid < 0) {
968 Error("SetClassVersion","The class version (for %s) must be positive (value %d is ignored)",cl->GetName(),newid);
969 }
970 if (cname==(void*)-1) {
971 if (cl->fClassVersion<newid && 2<=newid) {
973 }
974 } else {
976 }
977 }
978 }
979}
980
981////////////////////////////////////////////////////////////////////////////////
982/// Global function called by the dtor of a class's init class
983/// (see the ClassImp macro).
984/// The caller of this function should be holding the ROOT Write lock.
985
987{
988 // don't delete class information since it is needed by the I/O system
989 // to write the StreamerInfo to file
990 if (cname) {
991 // Let's still remove this information to allow reloading later.
992 // Anyway since the shared library has been unloaded, the dictionary
993 // pointer is now invalid ....
994 // We still keep the TClass object around because TFile needs to
995 // get to the TStreamerInfo.
996 if (oldcl)
997 oldcl->SetUnloaded();
999 }
1000}
1001
1002////////////////////////////////////////////////////////////////////////////////
1003/// Global function to register the implementation file and line of
1004/// a class template (i.e. NOT a concrete class).
1005
1006TNamed *ROOT::RegisterClassTemplate(const char *name, const char *file,
1007 Int_t line)
1008{
1009 static TList table;
1010 static Bool_t isInit = []() {
1011 table.SetOwner(kTRUE);
1012 table.UseRWLock();
1013 return true;
1014 }();
1015 (void)isInit;
1016
1017 TString classname(name);
1018 Ssiz_t loc = classname.Index("<");
1019 if (loc >= 1)
1020 classname.Remove(loc);
1021 TNamed *reg = (TNamed*)table.FindObject(classname);
1022 if (file) {
1023 if (reg)
1024 reg->SetTitle(file);
1025 else {
1026 reg = new TNamed((const char*)classname, file);
1027 table.Add(reg);
1028 }
1029 reg->SetUniqueID(line);
1030 }
1031 return reg;
1032}
#define SafeDelete(p)
Definition RConfig.hxx:530
#define b(i)
Definition RSha256.hxx:100
#define a(i)
Definition RSha256.hxx:99
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
bool Bool_t
Definition RtypesCore.h:63
short Version_t
Definition RtypesCore.h:65
unsigned int UInt_t
Definition RtypesCore.h:46
short Short_t
Definition RtypesCore.h:39
constexpr Bool_t kFALSE
Definition RtypesCore.h:94
constexpr Ssiz_t kNPOS
Definition RtypesCore.h:117
constexpr Bool_t kTRUE
Definition RtypesCore.h:93
const char Option_t
Definition RtypesCore.h:66
TClass *(* DictFuncPtr_t)()
Definition Rtypes.h:85
#define ClassImp(name)
Definition Rtypes.h:382
static std::mutex & GetClassTableMutex()
TClassTable * gClassTable
static int ClassComp(const void *a, const void *b)
R__EXTERN TClassTable * gClassTable
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
void Info(const char *location, const char *msgfmt,...)
Use this function for informational messages.
Definition TError.cxx:218
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
Definition TError.cxx:185
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t option
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t r
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t index
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize id
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char cname
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void reg
char name[80]
Definition TGX11.cxx:110
R__EXTERN TInterpreter * gCling
Int_t gDebug
Definition TROOT.cxx:622
#define gROOT
Definition TROOT.h:414
void Printf(const char *fmt,...)
Formats a string in a circular formatting buffer and prints the string.
Definition TString.cxx:2503
char * StrDup(const char *str)
Duplicate the string str.
Definition TString.cxx:2557
const char * proto
Definition civetweb.c:17535
const char * fName
TClassAlt(const char *alternate, const char *normName, TClassAlt *next)
std::unique_ptr< TClassAlt > fNext
const char * fNormName
DictFuncPtr_t fDict
TClassRec(TClassRec *next)
const std::type_info * fInfo
TClassRec * fNext
TProtoClass * fProto
IdMap_t::size_type size_type
IdMap_t::mapped_type mapped_type
void Add(const key_type &key, mapped_type &obj)
IdMap_t::key_type key_type
std::map< std::string, TClassRec * > IdMap_t
IdMap_t::const_iterator const_iterator
void Remove(const key_type &key)
mapped_type Find(const key_type &key) const
IdMap_t::size_type size_type
Definition TClass.cxx:373
IdMap_t::mapped_type mapped_type
Definition TClass.cxx:378
IdMap_t::const_iterator const_iterator
Definition TClass.cxx:372
IdMap_t::key_type key_type
Definition TClass.cxx:371
const std::string & GetNormalizedName() const
NormalizeThenLock(const NormalizeThenLock &)=delete
NormalizeThenLock(const char *cname)
NormalizeThenLock(NormalizeThenLock &&)=delete
NormalizeThenLock & operator=(const NormalizeThenLock &)=delete
NormalizeThenLock & operator=(NormalizeThenLock &&)=delete
This class registers for all classes their name, id and dictionary function in a hash table.
Definition TClassTable.h:37
static void PrintTable()
Print the class table.
static Int_t GetPragmaBits(const char *name)
Returns the pragma bits as specified in the LinkDef.h file.
static DictFuncPtr_t GetDict(const char *cname)
Given the class name returns the Dictionary() function of a class (uses hash of name).
static Version_t GetID(const char *cname)
Returns the ID of a class.
ROOT::TMapTypeToClassRec IdMap_t
Definition TClassTable.h:43
static void SortTable()
Sort the class table by ascending class ID's.
static TProtoClass * GetProtoNorm(const char *cname)
Given the class normalized name returns the TClassProto object for the class.
static DictFuncPtr_t GetDictNorm(const char *cname)
Given the normalized class name returns the Dictionary() function of a class (uses hash of name).
static ROOT::TClassAlt ** fgAlternate
Definition TClassTable.h:46
void Print(Option_t *option="") const override
Print the class table.
static void Terminate()
Deletes the class table (this static class function calls the dtor).
static TProtoClass * GetProto(const char *cname)
Given the class name returns the TClassProto object for the class.
static std::atomic< UInt_t > fgTally
Definition TClassTable.h:51
TClassTable()
TClassTable is a singleton (i.e. only one can exist per application).
static char * Next()
Returns next class from sorted class table.
static char * At(UInt_t index)
Returns class at index from sorted class table.
static Bool_t Check(const char *cname, std::string &normname)
static void Init()
static void Remove(const char *cname)
Remove a class from the class table.
static ROOT::TClassRec ** fgSortedTable
Definition TClassTable.h:48
static ROOT::TClassRec ** fgTable
Definition TClassTable.h:47
static IdMap_t * fgIdMap
Definition TClassTable.h:49
static Bool_t CheckClassTableInit()
Return true fs the table exist.
static void Add(const char *cname, Version_t id, const std::type_info &info, DictFuncPtr_t dict, Int_t pragmabits)
Add a class to the class table (this is a static function).
~TClassTable()
TClassTable singleton is deleted in Terminate().
static void RemoveAlternate(ROOT::TClassAlt *alt)
static ROOT::TClassRec * FindElement(const char *cname, Bool_t insert)
Find a class by name in the class table (using hash of name).
static Bool_t fgSorted
Definition TClassTable.h:52
static UInt_t fgSize
Definition TClassTable.h:50
static ROOT::TClassAlt * AddAlternate(const char *normname, const char *alternate)
static UInt_t fgCursor
Definition TClassTable.h:53
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition TClass.h:81
Version_t fClassVersion
Definition TClass.h:221
void SetClassVersion(Version_t version)
Private function.
Definition TClass.cxx:5771
std::atomic< Bool_t > fVersionUsed
saved remember if fOffsetStreamer has been set.
Definition TClass.h:262
@ kHasTClassInit
Definition TClass.h:127
static TClass * GetClass(const char *name, Bool_t load=kTRUE, Bool_t silent=kFALSE)
Static method returning pointer to TClass of the specified class name.
Definition TClass.cxx:3038
virtual bool UseRWLock(Bool_t enable=true)
Set this collection to use a RW lock upon access, making it thread safe.
virtual void SetOwner(Bool_t enable=kTRUE)
Set whether this collection is the owner (enable==true) of its content.
virtual void RegisterTClassUpdate(TClass *oldcl, DictFuncPtr_t dict)=0
A doubly linked list.
Definition TList.h:38
TObject * FindObject(const char *name) const override
Find an object in this list using its name.
Definition TList.cxx:576
void Add(TObject *obj) override
Definition TList.h:81
TMap implements an associative array of (key,value) pairs using a THashTable for efficient retrieval ...
Definition TMap.h:40
The TNamed class is the base class for all named ROOT classes.
Definition TNamed.h:29
const char * GetName() const override
Returns name of object.
Definition TNamed.h:47
Collectable string class.
Definition TObjString.h:28
TString & String()
Definition TObjString.h:48
Mother of all ROOT objects.
Definition TObject.h:41
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition TObject.cxx:979
virtual void Fatal(const char *method, const char *msgfmt,...) const
Issue fatal error message.
Definition TObject.cxx:1021
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
Definition TObject.cxx:967
Class used by TMap to store (key,value) pairs.
Definition TMap.h:102
Persistent version of a TClass.
Definition TProtoClass.h:38
static Bool_t Initialized()
Return kTRUE if the TROOT object has been initialized.
Definition TROOT.cxx:2937
Regular expression class.
Definition TRegexp.h:31
Basic string class.
Definition TString.h:139
const char * Data() const
Definition TString.h:376
TString & Remove(Ssiz_t pos)
Definition TString.h:685
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
Definition TString.h:651
TLine * line
const Int_t n
Definition legend1.C:16
R__EXTERN TROOT * gROOTLocal
Definition TROOT.h:387
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
std::vector< std::pair< const char *, const char * > > & GetDelayedAddClassAlternate()
ROOT::TClassAlt * AddClassAlternate(const char *normName, const char *alternate)
Global function called by GenerateInitInstance.
std::vector< std::unique_ptr< TClassRec > > & GetDelayedAddClass()
void RemoveClass(const char *cname, TClass *cl)
Global function called by the dtor of a class's init class (see the ClassImp macro).
void AddClass(const char *cname, Version_t id, const std::type_info &info, DictFuncPtr_t dict, Int_t pragmabits)
Global function called by the ctor of a class's init class (see the ClassImp macro).
TNamed * RegisterClassTemplate(const char *name, const char *file, Int_t line)
Global function to register the implementation file and line of a class template (i....
static UInt_t ClassTableHash(const char *name, UInt_t size)
void ResetClassVersion(TClass *, const char *, Short_t)
Global function to update the version number.
TROOT * GetROOT()
Definition TROOT.cxx:472
void RemoveClassAlternate(ROOT::TClassAlt *)
bool IsStdClass(const char *type)
return true if the class belongs to the std namespace
void GetNormalizedName(std::string &norm_name, std::string_view name)
Return the normalized name.