ATLAS Offline Software
getDynamicAuxID.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
15 #include "TClass.h"
16 #include "TROOT.h"
17 
18 
19 namespace SG {
20 
21 
26 TClass* getClassIfDictionaryExists (const std::string& cname)
27 {
28  if (TClass* cl = (TClass*)gROOT->GetListOfClasses()->FindObject(cname.c_str())) {
29  if (cl->IsLoaded() && cl->HasDictionary()) return cl;
30  return nullptr;
31  }
32 
33  // The idea of calling GetClassSharedLibs was to test if a class was
34  // listed in the rootmap file, so we could avoid autoparsing.
35  // This worked with older versions of root 6.
36  // But now root has started doing dynamic linking itself,
37  // and GetClassSharedLibs will itself trigger autoparsing.
38  // So currently, this test does more harm than good.
39  // Still need to see if we can find a reliable way of failing
40  // a TClass lookup rather than triggering autoparsing.
41  //if (gInterpreter->GetClassSharedLibs (cname.c_str()))
42  {
43  TClass* cl = TClass::GetClass (cname.c_str());
44  if (cl->HasDictionary())
45  return cl;
46  }
47  return nullptr;
48 }
49 
50 
63 SG::auxid_t getDynamicAuxID (const std::type_info& ti,
64  const std::string& name,
65  const std::string& elementTypeName,
66  const std::string& branchTypeName,
67  bool standalone)
68 {
70  SG::auxid_t auxid = SG::null_auxid;
71 
72  auxid = r.getAuxID (ti, name, "", SG::AuxTypeRegistry::Flags::SkipNameCheck);
73  if (auxid != SG::null_auxid) return auxid;
74 
75  // Be careful --- if we don't exactly match the name
76  // in TClassTable, then we may trigger autoparsing. Besides the
77  // resource usage that implies, that can lead to crashes in dbg
78  // builds due to cling bugs.
79  std::string tn = elementTypeName;
80  if (tn.starts_with("std::vector<"))
81  tn.erase (0, 5);
82  std::string fac_class_name = "SG::AuxTypeVectorFactory<" +
83  tn + ",allocator<" + tn;
84  if (fac_class_name[fac_class_name.size()-1] == '>')
85  fac_class_name += ' ';
86  fac_class_name += "> >";
87  TClass* fac_class = getClassIfDictionaryExists (fac_class_name);
88  if (fac_class)
89  {
90  TClass* base_class = getClassIfDictionaryExists ("SG::IAuxTypeVectorFactory");
91  if (base_class) {
92  int offs = fac_class->GetBaseClassOffset (base_class);
93  if (offs >= 0) {
94  void* fac_vp = fac_class->New();
95  if (fac_vp) {
96  SG::IAuxTypeVectorFactory* fac = reinterpret_cast<SG::IAuxTypeVectorFactory*> (reinterpret_cast<unsigned long>(fac_vp) + offs);
97  const std::type_info* tiAlloc = fac->tiAlloc();
98  r.addFactory (ti, *tiAlloc, std::unique_ptr<SG::IAuxTypeVectorFactory> (fac));
99  auxid = r.getAuxID(*fac->tiAlloc(), ti, name);
100  }
101  }
102  }
103  }
104 
105  if (auxid == SG::null_auxid) {
106  std::string vec_name = branchTypeName;
107  if (standalone) {
108  vec_name = "std::vector<" + branchTypeName;
109  if (vec_name[vec_name.size()-1] == '>')
110  vec_name += " ";
111  vec_name += ">";
112  }
113  TClass* vec_class = TClass::GetClass (vec_name.c_str());
114 
115  if (vec_class) {
116  auto facp = std::make_unique<SG::RootAuxVectorFactory> (vec_class);
117  std::string tiAllocName = facp->tiAllocName();
118  (void)r.addFactory (ti, tiAllocName, std::move (facp));
119  auxid = r.getAuxID(tiAllocName, ti, name);
120  }
121  }
122 
123  return auxid;
124 }
125 
126 
127 } // namespace SG
beamspotman.r
def r
Definition: beamspotman.py:676
SG
Forward declaration.
Definition: CaloCellPacker_400_500.h:32
SG::SkipNameCheck
@ SkipNameCheck
Definition: AuxTypes.h:81
SG::AuxTypeRegistry::instance
static AuxTypeRegistry & instance()
Return the singleton registry instance.
Definition: AuxTypeRegistry.cxx:49
SG::getDynamicAuxID
SG::auxid_t getDynamicAuxID(const std::type_info &ti, const std::string &name, const std::string &elementTypeName, const std::string &branch_type_name, bool standalone)
Find the auxid for a dynamic branch.
Definition: getDynamicAuxID.cxx:63
SG::AuxTypeRegistry
Handle mappings between names and auxid_t.
Definition: AuxTypeRegistry.h:62
SG::auxid_t
size_t auxid_t
Identifier for a particular aux data item.
Definition: AuxTypes.h:27
SG::IAuxTypeVectorFactory
Interface for factory objects that create vectors.
Definition: IAuxTypeVectorFactory.h:50
SG::IAuxTypeVectorFactory::tiAlloc
virtual const std::type_info * tiAlloc() const =0
Return the type_info of the vector allocator.
getDynamicAuxID.h
Find the auxid for a dynamic branch.
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:192
SG::getClassIfDictionaryExists
TClass * getClassIfDictionaryExists(const std::string &cname)
Look up a TClass given a name.
Definition: getDynamicAuxID.cxx:26
RootAuxVectorFactory.h
Dynamic implementation of IAuxVectorFactory, relying on root's vector proxy.
AuxTypeRegistry.h
Handle mappings between names and auxid_t.
dq_make_web_display.cl
cl
print [x.__class__ for x in toList(dqregion.getSubRegions()) ]
Definition: dq_make_web_display.py:26