#if defined(__CINT__) // we need to include this in interpreter and dictionary mode, // so CINT has the dictionary for its C++ API classes (G__SourceFileInfo) #include "ertti.h" #else // This is the compiler version of the same: #include "Api.h" #endif #include "TSystem.h" #include "TROOT.h" #include #include using namespace std; // Do not put any functions into the part that's visible both // for the interpreted mode and the library. #if !defined(__CINT__) || defined(__MAKECINT__) // This is only visibale in the library. // It must not contain any func with a name that exists also in // the interpreted part. void other() { cout << "It works!" << endl; } #else // This is only visible in interpreted mode. // It must not contain any func with a name that exists also in // the library part. void GetCurrentMacro(G__SourceFileInfo& macro) { // CINT keeps a linked list of all loaded files, // G__SourceFileInfo is both an element and an // iterator of that list. // // We start with the first one (0), and iterate // through the whole list. If we find one that is // not incldued by another file (i.e. it's "included" // by the command prompt), we call it a candidate. // The last candidate is the macro we're currently // executing. Of course this only works is the macro // is really started from the command prompt! G__SourceFileInfo srcfile; while (srcfile.Next()) if (!srcfile.IncludedFrom().IsValid()) // ignore included files macro = srcfile; } Bool_t CompileMacro(G__SourceFileInfo& macro) { // Compile the macro, even though it's currently busy Bool_t ret; // "Hide" the macro from Cint, so it doesn't realize // it's being executed. We simply replace the first // character of the macro name by '_', and set it back // when we're done. And yes, this is a very ugly hack; // TAclic should allow compiling a macro that is // loaded without forcing an unload. string macroname = macro.Name(); macro.Name()[0] = '_'; // ugly hack ret = gSystem->CompileMacro(macroname.c_str()); macro.Name()[0] = macroname[0]; // revert ugly hack return ret; } void autobuild() { G__SourceFileInfo macro; GetCurrentMacro(macro); if (!macro.IsValid()) { cout << "Cannot find currrent file!" << endl; return; } cout << "Current macro: " << macro.Name() << endl; if (CompileMacro(macro)) gROOT->ProcessLine("other();"); } #endif