ATLAS Offline Software
Loading...
Searching...
No Matches
AddDVProxy.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3*/
4
5// Local include(s):
8
9// ROOT include(s):
10#include <TClass.h>
11#include <TError.h>
12#include <TInterpreter.h>
13#include <TROOT.h>
14#include <TClassGenerator.h>
15#include <TClassEdit.h>
16
17// System include(s):
18#include <mutex>
19
20
21namespace {
22
23
35class xAODClassGenerator : public TClassGenerator
36{
37public:
38 using TClassGenerator::GetClass;
39 virtual TClass *GetClass(const char* classname, Bool_t load) override;
40 virtual TClass *GetClass(const std::type_info& , Bool_t ) override
41 { return nullptr; }
42
43 // Protect against recursive invocation.
44 static thread_local bool m_active;
45 struct BeActive
46 {
47 BeActive() { m_active = true; }
48 ~BeActive() { m_active = false; }
49 };
50
51};
52
53
54
55thread_local bool xAODClassGenerator::m_active = false;
56
57
58TClass* xAODClassGenerator::GetClass(const char* classname, Bool_t load)
59{
60 static const std::string prefs[] = {
61 "SG::AuxTypeVectorFactory<",
62 "DataLink<",
63 "ElementLink<",
64 "SG::BaseInfo<",
65 "DataVector<",
66 };
67 if (m_active) return nullptr;
68 for (const std::string& pref : prefs) {
69 if (strncmp (classname, pref.c_str(), pref.size()) == 0) {
70 std::string eltName;
71 {
72 // Protect against data race inside TClassEdit.
73 // https://github.com/root-project/root/issues/10353
74 // Should be fixed in root 6.26.02.
75 R__WRITE_LOCKGUARD(ROOT::gCoreMutex);
76 TClassEdit::TSplitType s (classname);
77 if (s.fElements.size() >= 2) {
78 eltName = s.fElements[1];
79 }
80 }
81 if (!eltName.empty()) {
82 TClass::GetClass (eltName.c_str(), load);
83 BeActive active;
84 return TClass::GetClass (classname, load);
85 }
86 }
87 }
88 return nullptr;
89}
90
91
92xAODClassGenerator generator ATLAS_THREAD_SAFE;
93
94
95} // anonymous namespace
96
97
98namespace xAOD {
99
105
106 // Enable library auto-loading. Only once per job.
107 static std::once_flag libLoadFlag;
108 std::call_once( libLoadFlag, []( TInterpreter& interpreter ) {
109
110 // Enable library auto-loading.
111 TClass::ReadRules();
112 interpreter.LoadLibraryMap();
113 interpreter.SetClassAutoloading( true );
114
115 // Make sure that the minimal set of dictionaries are loaded:
116 if( ! TClass::GetClass( "DataVector<xAOD::TDVCollectionProxyDummy>" ) ) {
117 ::Error( "xAOD::AddDVProxy::loadDictionaries",
118 "Couldn't load the dictionary for "
119 "DataVector<xAOD::TDVCollectionProxyDummy>" );
120 }
121
122 // Install the cling workaround (see above).
123 gROOT->AddClassGenerator (&generator);
124
125 }, *gInterpreter );
126
127 return;
128 }
129
130} // namespace xAOD
static Double_t * pref
Define macros for attributes used to control the static checker.
#define ATLAS_THREAD_SAFE
static void loadDictionaries()
Helper function force-loading all the needed dictionaries.
@ active
Definition Layer.h:47
generator
Configure Herwig7 These are the commands corresponding to what would go into the regular Herwig infil...