18 #include "TInterpreter.h"
31 #include "Cintex/Cintex.h"
43 class RootLoadFileSentry {
45 RootLoadFileSentry() {
46 G__setfilecontext(
"{CMS auto library loader}", &oldIFile_);
49 ~RootLoadFileSentry() {
50 G__input_file*
ifile = G__get_ifile();
57 G__input_file oldIFile_;
82 std::map<std::string, std::string>&
83 cintToReflexSpecialCasesMap() {
84 static std::map<std::string, std::string> s_map;
89 addWrapperOfVectorOfBuiltin(std::map<std::string, std::string>& iMap,
char const* iBuiltin) {
90 static std::string const sReflexPrefix(
"edm::Wrapper<std::vector<");
94 static std::string const sCintPrefix(
"Wrapper<vector<");
95 static std::string const sCintMiddle(
",allocator<");
99 iMap.insert(make_pair(sCintPrefix +
type + sCintMiddle +
type + sCintPostfix,
100 sReflexPrefix +
type + sReflexPostfix));
110 isDictionaryLoaded(
std::string const& rootclassname) {
114 ClassInfo_t*
info = gInterpreter->ClassInfo_Factory(rootclassname.c_str());
115 return gInterpreter->ClassInfo_IsValid(info);
118 bool loadLibraryForClass(
char const* classname) {
120 if(
nullptr == classname) {
126 std::string rootclassname = classNameForRoot(classname);
129 RootLoadFileSentry sentry;
131 if(!isDictionaryLoaded(rootclassname)) {
145 if(!isDictionaryLoaded(rootclassname)) {
160 int ALL_AutoLoadCallback(
char*
c,
char*
l) {
163 if(
nullptr == c ||
nullptr == l || l[0] == 0) {
166 ULong_t varp = G__getgvp();
167 G__setgvp((
long)G__PVOID);
168 int result = loadLibraryForClass(c) ? 1:0;
179 if(!result && 0 != strcmp(l, kDummyLibName) && gPrevious) {
187 struct CompareFirst {
188 bool operator()(std::pair<std::string, std::string>
const& iLHS,
189 std::pair<std::string, std::string>
const& iRHS)
const{
190 return iLHS.first > iRHS.first;
194 void registerTypes() {
199 CatToInfos::const_iterator itFound = db->
categoryToInfos().find(
"Capability");
209 typedef std::vector<std::pair<std::string, std::string> > ClassAndLibraries;
210 ClassAndLibraries classes;
211 classes.reserve(1000);
215 std::map<std::string, std::string> specialsToLib;
216 std::map<std::string, std::string>
const& specials = cintToReflexSpecialCasesMap();
217 for(
auto const& special : specials) {
218 specialsToLib[classNameForRoot(special.second)];
221 for(
auto const& info : itFound->second) {
222 if (lastClass == info.name_) {
225 lastClass = info.name_;
226 if(cPrefix == lastClass.substr(0, cPrefix.size())) {
228 classes.emplace_back(className, info.loadable_.string());
229 std::map<std::string, std::string>::iterator iFound = specialsToLib.find(className);
230 if(iFound != specialsToLib.end()) {
232 iFound->second = info.loadable_.string();
239 for(ClassAndLibraries::reverse_iterator itClass = classes.rbegin(), itClassEnd = classes.rend();
240 itClass != itClassEnd;
248 while(std::string::npos != (pos = className.find_first_of(toFind, pos))) {
249 if (className[pos] ==
'<') {
break;}
250 if (className.size() <= pos + 1 || className[pos + 1] !=
':') {
break;}
252 G__set_class_autoloading_table(const_cast<char*>(className.substr(0, pos).c_str()), const_cast<char*>(
""));
256 G__set_class_autoloading_table(const_cast<char*>(className.c_str()), const_cast<char*>(libraryName.c_str()));
261 for(
auto const& special : specials) {
266 if(specialsToLib[rootname].
size()) {
268 if(!isDictionaryLoaded(rootname) and
270 std::cout <<
"failed to load plugin for " << cPrefix + name << std::endl;
274 if(!isDictionaryLoaded(rootname)) {
275 std::cout <<
"dictionary did not build " << name << std::endl;
278 TClass* namedClass = TClass::GetClass(rootname.c_str());
279 if(
nullptr == namedClass) {
280 std::cout <<
"failed to get TClass for " << name << std::endl;
283 namedClass->Clone(special.first.c_str());
284 std::string magictypedef(
"namespace edm { typedef ");
285 magictypedef += rootname +
" " + special.first +
"; }";
287 gROOT->ProcessLine(magictypedef.c_str());
298 #
if ROOT_VERSION_CODE >= ROOT_VERSION(5,27,6)
299 classNameAttemptingToLoad_(
nullptr),
300 isInitializingCintex_(
true) {
305 gROOT->AddClassGenerator(
this);
306 ROOT::Cintex::Cintex::Enable();
307 #if ROOT_VERSION_CODE >= ROOT_VERSION(5,27,6)
311 std::map<std::string, std::string>& specials = cintToReflexSpecialCasesMap();
312 if(specials.empty()) {
313 addWrapperOfVectorOfBuiltin(specials,
"bool");
315 addWrapperOfVectorOfBuiltin(specials,
"char");
316 addWrapperOfVectorOfBuiltin(specials,
"unsigned char");
317 addWrapperOfVectorOfBuiltin(specials,
"signed char");
318 addWrapperOfVectorOfBuiltin(specials,
"short");
319 addWrapperOfVectorOfBuiltin(specials,
"unsigned short");
320 addWrapperOfVectorOfBuiltin(specials,
"int");
321 addWrapperOfVectorOfBuiltin(specials,
"unsigned int");
322 addWrapperOfVectorOfBuiltin(specials,
"long");
323 addWrapperOfVectorOfBuiltin(specials,
"unsigned long");
324 addWrapperOfVectorOfBuiltin(specials,
"long long");
325 addWrapperOfVectorOfBuiltin(specials,
"unsigned long long");
327 addWrapperOfVectorOfBuiltin(specials,
"float");
328 addWrapperOfVectorOfBuiltin(specials,
"double");
333 G__set_class_autoloading_callback(&ALL_AutoLoadCallback);
343 TClass* returnValue =
nullptr;
349 if (idx != std::string::npos) {
353 if(className.size() > idx + 6 && className[idx + 6] ==
' ') {
354 className.replace(idx + 6, 1,
"");
357 returnValue = gROOT->GetClass(className.c_str(), kTRUE);
372 #if ROOT_VERSION_CODE >= ROOT_VERSION(5,27,6)
375 if (loadLibraryForClass(classname)) {
383 returnValue = gROOT->GetClass(classname, kTRUE);
393 TClass* returnValue =
nullptr;
416 CatToInfos::const_iterator itFound = db->
categoryToInfos().find(
"Capability");
424 RootLoadFileSentry sentry;
426 for(
auto const& info : itFound->second) {
427 if (lastClass == info.name_) {
431 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()
CallbackPtr G__p_class_autoloading
bool isInitializingCintex_
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
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
static PluginManager * get()
tuple size
Write out results.
static char const * kDummyLibName
std::string className(const T &t)