18 #include "TInterpreter.h"
19 #include "TVirtualMutex.h"
32 #include "Cintex/Cintex.h"
44 class RootLoadFileSentry {
46 RootLoadFileSentry() {
47 R__LOCKGUARD2(gCINTMutex);
48 G__setfilecontext(
"{CMS auto library loader}", &oldIFile_);
51 ~RootLoadFileSentry() {
52 R__LOCKGUARD2(gCINTMutex);
53 G__input_file*
ifile = G__get_ifile();
60 G__input_file oldIFile_;
85 std::map<std::string, std::string>&
86 cintToReflexSpecialCasesMap() {
87 static std::map<std::string, std::string> s_map;
92 addWrapperOfVectorOfBuiltin(std::map<std::string, std::string>& iMap,
char const* iBuiltin) {
93 static std::string const sReflexPrefix(
"edm::Wrapper<std::vector<");
97 static std::string const sCintPrefix(
"Wrapper<vector<");
98 static std::string const sCintMiddle(
",allocator<");
102 iMap.insert(make_pair(sCintPrefix +
type + sCintMiddle +
type + sCintPostfix,
103 sReflexPrefix +
type + sReflexPostfix));
113 isDictionaryLoaded(
std::string const& rootclassname) {
117 ClassInfo_t*
info = gInterpreter->ClassInfo_Factory(rootclassname.c_str());
118 return gInterpreter->ClassInfo_IsValid(info);
121 bool loadLibraryForClass(
char const*
classname) {
123 if(
nullptr == classname) {
129 std::string rootclassname = classNameForRoot(classname);
132 RootLoadFileSentry sentry;
134 if(!isDictionaryLoaded(rootclassname)) {
148 if(!isDictionaryLoaded(rootclassname)) {
163 int ALL_AutoLoadCallback(
char*
c,
char*
l) {
166 if(
nullptr == c ||
nullptr == l || l[0] == 0) {
169 ULong_t varp = G__getgvp();
170 G__setgvp((
long)G__PVOID);
171 int result = loadLibraryForClass(c) ? 1:0;
182 if(!result && 0 != strcmp(l, kDummyLibName) && gPrevious) {
190 struct CompareFirst {
191 bool operator()(std::pair<std::string, std::string>
const& iLHS,
192 std::pair<std::string, std::string>
const& iRHS)
const{
193 return iLHS.first > iRHS.first;
197 void registerTypes() {
202 CatToInfos::const_iterator itFound = db->
categoryToInfos().find(
"Capability");
212 typedef std::vector<std::pair<std::string, std::string> > ClassAndLibraries;
213 ClassAndLibraries classes;
214 classes.reserve(1000);
218 std::map<std::string, std::string> specialsToLib;
219 std::map<std::string, std::string>
const& specials = cintToReflexSpecialCasesMap();
220 for(
auto const& special : specials) {
221 specialsToLib[classNameForRoot(special.second)];
224 for(
auto const& info : itFound->second) {
225 if (lastClass == info.name_) {
228 lastClass = info.name_;
229 if(cPrefix == lastClass.substr(0, cPrefix.size())) {
231 classes.emplace_back(className, info.loadable_.string());
232 std::map<std::string, std::string>::iterator iFound = specialsToLib.find(className);
233 if(iFound != specialsToLib.end()) {
235 iFound->second = info.loadable_.string();
242 for(ClassAndLibraries::reverse_iterator itClass = classes.rbegin(), itClassEnd = classes.rend();
243 itClass != itClassEnd;
251 while(std::string::npos != (pos = className.find_first_of(toFind, pos))) {
252 if (className[pos] ==
'<') {
break;}
253 if (className.size() <= pos + 1 || className[pos + 1] !=
':') {
break;}
255 G__set_class_autoloading_table(const_cast<char*>(className.substr(0, pos).c_str()), const_cast<char*>(
""));
259 G__set_class_autoloading_table(const_cast<char*>(className.c_str()), const_cast<char*>(libraryName.c_str()));
264 for(
auto const& special : specials) {
269 if(specialsToLib[rootname].
size()) {
271 if(!isDictionaryLoaded(rootname) and
273 std::cout <<
"failed to load plugin for " << cPrefix + name << std::endl;
277 if(!isDictionaryLoaded(rootname)) {
278 std::cout <<
"dictionary did not build " << name << std::endl;
281 TClass* namedClass = TClass::GetClass(rootname.c_str());
282 if(
nullptr == namedClass) {
283 std::cout <<
"failed to get TClass for " << name << std::endl;
286 namedClass->Clone(special.first.c_str());
287 std::string magictypedef(
"namespace edm { typedef ");
288 magictypedef += rootname +
" " + special.first +
"; }";
290 gROOT->ProcessLine(magictypedef.c_str());
301 #
if ROOT_VERSION_CODE >= ROOT_VERSION(5,27,6)
302 classNameAttemptingToLoad_(
nullptr),
303 isInitializingCintex_(
true) {
308 gROOT->AddClassGenerator(
this);
309 ROOT::Cintex::Cintex::Enable();
310 #if ROOT_VERSION_CODE >= ROOT_VERSION(5,27,6)
314 std::map<std::string, std::string>& specials = cintToReflexSpecialCasesMap();
315 if(specials.empty()) {
316 addWrapperOfVectorOfBuiltin(specials,
"bool");
318 addWrapperOfVectorOfBuiltin(specials,
"char");
319 addWrapperOfVectorOfBuiltin(specials,
"unsigned char");
320 addWrapperOfVectorOfBuiltin(specials,
"signed char");
321 addWrapperOfVectorOfBuiltin(specials,
"short");
322 addWrapperOfVectorOfBuiltin(specials,
"unsigned short");
323 addWrapperOfVectorOfBuiltin(specials,
"int");
324 addWrapperOfVectorOfBuiltin(specials,
"unsigned int");
325 addWrapperOfVectorOfBuiltin(specials,
"long");
326 addWrapperOfVectorOfBuiltin(specials,
"unsigned long");
327 addWrapperOfVectorOfBuiltin(specials,
"long long");
328 addWrapperOfVectorOfBuiltin(specials,
"unsigned long long");
330 addWrapperOfVectorOfBuiltin(specials,
"float");
331 addWrapperOfVectorOfBuiltin(specials,
"double");
336 G__set_class_autoloading_callback(&ALL_AutoLoadCallback);
346 TClass* returnValue =
nullptr;
352 if (idx != std::string::npos) {
356 if(className.size() > idx + 6 && className[idx + 6] ==
' ') {
357 className.replace(idx + 6, 1,
"");
360 returnValue = gROOT->GetClass(className.c_str(), kTRUE);
375 #if ROOT_VERSION_CODE >= ROOT_VERSION(5,27,6)
378 if (loadLibraryForClass(classname)) {
386 returnValue = gROOT->GetClass(classname, kTRUE);
396 TClass* returnValue =
nullptr;
419 CatToInfos::const_iterator itFound = db->
categoryToInfos().find(
"Capability");
427 RootLoadFileSentry sentry;
429 for(
auto const& info : itFound->second) {
430 if (lastClass == info.name_) {
434 lastClass = info.name_;
const CategoryToInfos & categoryToInfos() const
virtual TClass * GetClass(char const *classname, Bool_t load)
return class type
std::string const & dictionaryPlugInPrefix()
std::string CintName(std::string const &)
int(* CallbackPtr)(char *, char *)
std::string stdNamespaceAdder(const std::string &iClassName)
std::map< std::string, Infos > CategoryToInfos
static PluginCapabilities * get()
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
CallbackPtr G__p_class_autoloading
bool isInitializingCintex_
tuple idx
DEBUGGING if hasattr(process,"trackMonIterativeTracking2012"): print "trackMonIterativeTracking2012 D...
static void loadAll()
load all known libraries holding dictionaries
char const * classNameAttemptingToLoad_
static CallbackPtr gPrevious
void load(const std::string &iName)
static void enable()
interface for TClass generators
if(conf.exists("allCellsPositionCalc"))
static PluginManager * get()
tuple size
Write out results.
static char const * kDummyLibName
std::string className(const T &t)