![]() |
![]() |
#include <Iguana/Framework/interface/IgApplication.h>
Public Member Functions | |
virtual const char * | appname (void) const |
virtual int | argc (void) const |
virtual char ** | argv (void) const |
virtual const char * | driver (void) const |
IgApplication (void) | |
virtual int | run (int argc, char *argv[]) |
virtual IgState * | state (void) const |
virtual bool | verbose (void) const |
virtual | ~IgApplication (void) |
Protected Member Functions | |
virtual int | dumpDatabase (void) |
virtual int | initDatabase (void) |
virtual int | initDebugging (const char *appname) |
virtual int | initState (void) |
virtual int | loadDriver (void) |
virtual void | startMemStats (void) |
virtual void | startProfiler (void) |
virtual int | usage (void) |
Private Member Functions | |
void | pluginFeedback (IgPluginManager::FeedbackData data) |
Private Attributes | |
bool | m_all |
char * | m_appname |
int | m_argc |
char ** | m_argv |
char * | m_driver |
std::vector< std::string > | m_preload |
IgState * | m_state |
bool | m_verbose |
Definition at line 21 of file IgApplication.h.
IgApplication::IgApplication | ( | void | ) |
IgApplication::~IgApplication | ( | void | ) | [virtual] |
const char * IgApplication::appname | ( | void | ) | const [virtual] |
char ** IgApplication::argv | ( | void | ) | const [virtual] |
const char * IgApplication::driver | ( | void | ) | const [virtual] |
Definition at line 355 of file IgApplication.cc.
References IgPluginManager::beginDirectories(), IgModuleDescriptor::child(), IgModuleDescriptor::children(), GenMuonPlsPt100GeV_cfg::cout, archive::db, dir, IgPluginManager::endDirectories(), lat::endl(), lat::StringOps::find(), IgPluginManager::get(), i, m_all, plugin, and IgModuleDescriptor::token().
Referenced by run().
00356 { 00357 // List all categories and items in them. Set avoids duplicates. 00358 typedef std::pair<std::string,std::string> Seen; 00359 typedef std::set<Seen> SeenSet; 00360 typedef SeenSet::iterator SeenSetIterator; 00361 00362 IgPluginManager *db = IgPluginManager::get (); 00363 IgPluginManager::DirectoryIterator dir; 00364 IgModuleCache::Iterator plugin; 00365 IgModuleDescriptor *cache; 00366 SeenSet seen; 00367 unsigned i; 00368 00369 for (dir = db->beginDirectories (); dir != db->endDirectories (); ++dir) 00370 for (plugin = (*dir)->begin (); plugin != (*dir)->end (); ++plugin) 00371 for (cache=(*plugin)->cacheRoot(), i=0; i < cache->children(); ++i) 00372 seen.insert (Seen (cache->child (i)->token (0), 00373 cache->child (i)->token (1))); 00374 00375 SeenSetIterator cat = seen.begin (); 00376 SeenSetIterator current; 00377 while (cat != seen.end ()) 00378 { 00379 if (m_all || !lat::StringOps::find (cat->first, "IGUANA")) 00380 std::cout << "Category " << cat->first << ":\n"; 00381 00382 current = cat; 00383 00384 while (current != seen.end () && current->first == cat->first) 00385 { 00386 if (m_all || !lat::StringOps::find (cat->first, "IGUANA")) 00387 std::cout << " " << current->second << std::endl; 00388 ++current; 00389 } 00390 cat = current; 00391 } 00392 00393 if (seen.empty ()) 00394 std::cout << "No plug-ins\n"; 00395 00396 return EXIT_SUCCESS; 00397 }
Definition at line 317 of file IgApplication.cc.
References IgPluginManager::addFeedback(), lat::CreateCallback(), IgPluginManager::get(), IgPluginManager::initialise(), and pluginFeedback().
Referenced by run().
00318 { 00319 IgPluginManager::get ()->addFeedback 00320 (lat::CreateCallback (this, &IgApplication::pluginFeedback)); 00321 IgPluginManager::get ()->initialise (); 00322 return EXIT_SUCCESS; 00323 }
int IgApplication::initDebugging | ( | const char * | appname | ) | [protected, virtual] |
Definition at line 266 of file IgApplication.cc.
References IgOnCrashService::init(), and IgOnLowMemoryService::init().
Referenced by run().
00267 { 00268 // Install basic debugging service 00269 if (! IgOnCrashService::init (appname)) 00270 return EXIT_FAILURE; 00271 00272 if (! IgOnLowMemoryService::init (appname)) 00273 return EXIT_FAILURE; 00274 00275 return EXIT_SUCCESS; 00276 }
Definition at line 279 of file IgApplication.cc.
References m_argc, m_argv, and m_state.
Referenced by run().
00280 { 00281 // FIXME: install other services? 00282 m_state = new IgState; 00283 new IgArgsElement (m_state, m_argc, m_argv); 00284 new IgEnvsElement (m_state); 00285 new IgPluginLoader (m_state); 00286 return EXIT_SUCCESS; 00287 }
Definition at line 400 of file IgApplication.cc.
References ASSERT, TestMuL1L2Filter_cff::cerr, GenMuonPlsPt100GeV_cfg::cout, error, exception, lat::Error::explain(), IgOnCrashService::fatalException(), IgDriverDB::get(), m_argv, m_driver, m_state, m_verbose, name, IgDriver::run(), and usage().
Referenced by run().
00401 { 00402 try 00403 { 00404 ASSERT (m_driver); 00405 00406 if (m_verbose) 00407 std::cout << "Loading application driver `" << m_driver << "'.\n"; 00408 00409 IgDriver *app = IgDriverDB::get ()->create (m_driver, m_state); 00410 if (! app) 00411 { 00412 std::cout << "No such application driver `" << m_driver << "'.\n\n"; 00413 return usage (); 00414 } 00415 00416 if (m_verbose) 00417 std::cout << "Executing the driver.\n"; 00418 00419 return app->run (); 00420 } 00421 catch (lat::Error &error) 00422 { 00423 IgOnCrashService::fatalException 00424 (typeid(error).name (), error.explain ().c_str ()); 00425 std::cerr << m_argv [0] << ": cannot run the driver: " 00426 << error.explain () << "\n"; 00427 return EXIT_FAILURE; 00428 } 00429 catch (std::exception &error) 00430 { 00431 IgOnCrashService::fatalException 00432 (typeid(error).name (), error.what ()); 00433 std::cerr << m_argv [0] << ": cannot run the driver\n"; 00434 return EXIT_FAILURE; 00435 } 00436 catch (...) 00437 { 00438 IgOnCrashService::fatalException (0, 0); 00439 std::cerr << m_argv [0] << ": cannot run the driver\n"; 00440 return EXIT_FAILURE; 00441 } 00442 }
void IgApplication::pluginFeedback | ( | IgPluginManager::FeedbackData | data | ) | [private] |
Definition at line 326 of file IgApplication.cc.
References TestMuL1L2Filter_cff::cerr, IgPluginManager::FeedbackData::code, IgPluginManager::FeedbackData::error, IgPluginManager::ErrorBadCacheFile, IgPluginManager::ErrorBadModule, IgPluginManager::ErrorEntryFailure, IgPluginManager::ErrorLoadFailure, lat::Error::explain(), lat::StringOps::replace(), IgPluginManager::FeedbackData::scope, and IgPluginManager::StatusLoading.
Referenced by initDatabase().
00327 { 00328 std::string explanation; 00329 if (data.error) 00330 explanation = lat::StringOps::replace (data.error->explain (), '\n', "\n\t"); 00331 00332 if (data.code == IgPluginManager::StatusLoading) 00333 std::cerr << "Info: Loading module " << data.scope << "\n"; 00334 00335 else if (data.code == IgPluginManager::ErrorLoadFailure) 00336 std::cerr << " *** WARNING: module `" << data.scope 00337 << "' failed to load for the following reason\n\t" 00338 << explanation << "\n"; 00339 00340 else if (data.code == IgPluginManager::ErrorBadModule) 00341 std::cerr << " *** WARNING: module `" << data.scope 00342 << "' ignored until problems with it are fixed.\n\n"; 00343 00344 else if (data.code == IgPluginManager::ErrorBadCacheFile) 00345 std::cerr << " *** WARNING: cache file " << data.scope 00346 << " is corrupted.\n"; 00347 00348 else if (data.code == IgPluginManager::ErrorEntryFailure) 00349 std::cerr << " *** WARNING: module `" << data.scope 00350 << "' does not have the required entry point, reason was\n\t" 00351 << explanation << "\n"; 00352 }
Definition at line 94 of file IgApplication.cc.
References TestMuL1L2Filter_cff::cerr, GenMuonPlsPt100GeV_cfg::cout, lat::Signal::crashed(), dumpDatabase(), e, end, lat::endl(), help(), i, IGUANA_APP, IGUANA_COMPILER, IGUANA_CXX, IGUANA_HOST, IGUANA_UNAME, IGUANA_VERSION, IGUANA_WHO, lat::TimeInfo::init(), initDatabase(), initDebugging(), initState(), list(), loadDriver(), m_all, m_appname, m_argc, m_argv, m_driver, m_preload, m_verbose, lat::TimeInfo::processIdleTime(), lat::TimeInfo::processRealTime(), lat::TimeInfo::processSystemTime(), lat::TimeInfo::processUserTime(), startMemStats(), startProfiler(), StDecayID::status, IgLibraryPreloader::status(), and usage().
00095 { 00096 lat::TimeInfo::init (); 00097 initDebugging (argv [0]); 00098 00099 bool list = false; 00100 bool help = false; 00101 char defDriver [] = { "IGUANA" }; 00102 m_driver = defDriver; 00103 m_appname = argv [0]; 00104 00105 if (char *preloads = ::getenv ("IGUANA_PRELOADS")) 00106 { 00107 char *start = preloads; 00108 char *end = strchr (start, ':'); 00109 for ( ; end; start = end + 1, end = strchr (start, ':')) 00110 if (end - start) 00111 m_preload.push_back (std::string (start, end - start)); 00112 00113 if (*start) 00114 m_preload.push_back (start); 00115 } 00116 00117 int i = 1; 00118 00119 while (*++argv && argv [0][0] == '-') 00120 { 00121 i++; 00122 if (!strcmp (*argv, "--list")) 00123 { 00124 list = true; 00125 if ((i < argc) && (!strcmp (*++argv, "all"))) 00126 m_all = true; 00127 } 00128 else if (!strcmp (*argv, "--version")) 00129 { 00130 std::cout << "IGUANA " IGUANA_VERSION " (" IGUANA_HOST ")\n\n" 00131 << "Built by " IGUANA_WHO " on " __DATE__ " " __TIME__ " as:\n" 00132 << " " IGUANA_UNAME "\n" 00133 << " " IGUANA_CXX " (" IGUANA_COMPILER ")\n"; 00134 return EXIT_SUCCESS; 00135 } 00136 else if (!strcmp (*argv, "--help")) 00137 help = true; 00138 else if (!strcmp (*argv, "--profile")) 00139 startProfiler (); 00140 else if (!strcmp (*argv, "--memstats")) 00141 startMemStats (); 00142 else if (!strcmp (*argv, "--driver") || !strcmp (*argv, "-D")) 00143 { 00144 if (! *++argv) 00145 { 00146 help = true; 00147 std::cerr << "--driver requires an argument\n"; 00148 } 00149 else 00150 m_driver = *argv; 00151 } 00152 else if (!strcmp (*argv, "--verbose")) 00153 m_verbose = true; 00154 else if (!strcmp (*argv, "--preload")) 00155 { 00156 if (! *++argv) 00157 { 00158 help = true; 00159 std::cerr << "--preload requires an argument\n"; 00160 } 00161 else 00162 m_preload.push_back (*argv); 00163 } 00164 else 00165 // Assume the rest is for the driver. 00166 break; 00167 } 00168 00169 // Collect new argv vector for the driver, dropping out the main program and it's 00170 // options. OS X doesn't like running programs without full path, so manufacture 00171 // a new full path from the program name and the driver. 00172 lat::Filename fakeApp (m_appname, m_driver); 00173 m_argc = argc; 00174 m_argv = new char *[m_argc+1]; 00175 m_argv [0] = const_cast<char *> (static_cast<const char *> (fakeApp)); 00176 for (m_argc = 1; *argv; ++argv, ++m_argc) 00177 m_argv [m_argc] = *argv; 00178 m_argv [m_argc] = 0; 00179 00180 // Give help if requested or arguments are insufficient 00181 if (help || (! list && ! m_driver)) 00182 return usage (); 00183 00184 // Preload requested shared libraries 00185 int status; 00186 IgLibraryPreloader loader (m_argv [0], m_verbose); 00187 std::for_each (m_preload.begin (), m_preload.end (), loader); 00188 if ((status = loader.status ()) != EXIT_SUCCESS) 00189 return status; 00190 00191 // Initialise the plugin database 00192 if ((status = initDatabase ()) != EXIT_SUCCESS) 00193 return status; 00194 00195 // Initialise the state 00196 if ((status = initState ()) != EXIT_SUCCESS) 00197 return status; 00198 00199 // Do the work: if we want just a list, do so, otherwise create 00200 // and run the driver. 00201 status = (!list ? loadDriver () : dumpDatabase ()); 00202 00203 if (m_verbose) 00204 // FIXME: This should be done in the app driver, setting the 00205 // status bar message just before quitting. Uninteractive app 00206 // drivers shouldn't do this. We might want to have some mini 00207 // service that makes info like this available to app drivers 00208 // (along with crash protection and low-memory stuff above). 00209 std::cout << "\nThanks for using " IGUANA_APP " " IGUANA_VERSION "!" 00210 << (lat::Signal::crashed () ? " (We apologize for the inconvenience.)" 00211 : "") << std::endl 00212 << IGUANA_APP " took " 00213 << lat::TimeInfo::processUserTime () * 1e-9 << "s user, " 00214 << lat::TimeInfo::processSystemTime () * 1e-9 << "s system, " 00215 << lat::TimeInfo::processRealTime () * 1e-9 << "s real (" 00216 << lat::TimeInfo::processIdleTime () * 1e-9 << "s idle)\n"; 00217 00218 return status; 00219 }
Definition at line 248 of file IgApplication.cc.
References TestMuL1L2Filter_cff::cerr, error, lat::Error::explain(), and lat::SharedLibrary::load().
Referenced by run().
00249 { 00250 #ifdef __linux 00251 try 00252 { 00253 lat::SharedLibrary::load (std::string ("libMemProfLib.so")); 00254 } 00255 catch (lat::Error &error) 00256 { 00257 std::cerr << "Cannot load or initialise memprof runtime\n"; 00258 std::cerr << "Error was: " << error.explain () << "\n"; 00259 } 00260 #else 00261 std::cerr << "Memory profiling not available on this platform. Continuing without.\n"; 00262 #endif 00263 }
Definition at line 222 of file IgApplication.cc.
References TestMuL1L2Filter_cff::cerr, error, lat::Error::explain(), stor::func(), lat::SharedLibrary::function(), lat::SharedLibrary::load(), value, and void.
Referenced by run().
00223 { 00224 #ifdef __linux 00225 try 00226 { 00227 if (! getenv ("JPROF_FLAGS")) 00228 { 00229 static char value [] = "JPROF_FLAGS=JP_START JP_PERIOD=.0015"; 00230 putenv (value); 00231 } 00232 00233 lat::SharedLibrary *lib = lat::SharedLibrary::load (std::string ("libJProfLib.so")); 00234 void (*func) (void) = lib->function ("setupProfilingStuff"); 00235 (*func) (); 00236 } 00237 catch (lat::Error &error) 00238 { 00239 std::cerr << "Cannot load or initialise jprof runtime\n"; 00240 std::cerr << "Error was: " << error.explain () << "\n"; 00241 } 00242 #else 00243 std::cerr << "Profiling not available on this platform. Continuing without.\n"; 00244 #endif 00245 }
Definition at line 290 of file IgApplication.cc.
References appname(), TestMuL1L2Filter_cff::cerr, and lat::SearchPath::separator().
Referenced by loadDriver(), and run().
00291 { 00292 const char *app = appname (); 00293 00294 std::cerr << "Usage: " << app << " --help\n" 00295 << " or: " << app << " --version\n" 00296 << " or: " << app << " --list [all]\n" 00297 << " or: " << app 00298 << " [--verbose] [--preload LIBRARY]... [--profile] [--memstats]\n" 00299 << " [--driver|-D DRIVER] [DRIVER-OPTIONS...]\n\n" 00300 << "The $IGUANA_PLUGINS environment variable should be set to point to\n" 00301 << "the module registration directories, with directories separated\n" 00302 << "'" << lat::SearchPath::separator () << "' as with normal paths.\n\n" 00303 << "If no DRIVER is given, It will attempt to load `IGUANA'.\n" 00304 << "'IGUANA' DRIVER-OPTIONS are .....\n" 00305 << " [--iguana-session|-is <iguana-session>]\n\n" 00306 << "where '<iguana-session>' could be the name of any studio session type e.g.\n" 00307 << "'Vis Example--Qt Demo' or 'Vis Example--Open Inventor File Reader' etc.\n\n" 00308 << "One can also use the '; ' separated short names e.g. 'IvReader'\n\n" 00309 << "'IvReader' also support an optional command-line argument\n" 00310 << " [--ivfile|-iv <ivfile>]\n" 00311 << "for loading an open inventor IV file in the IV Reader.\n"; 00312 00313 return EXIT_FAILURE; 00314 }
bool IgApplication::m_all [private] |
char* IgApplication::m_appname [private] |
int IgApplication::m_argc [private] |
char** IgApplication::m_argv [private] |
Definition at line 60 of file IgApplication.h.
Referenced by argv(), initState(), loadDriver(), and run().
char* IgApplication::m_driver [private] |
std::vector<std::string> IgApplication::m_preload [private] |
IgState* IgApplication::m_state [private] |
Definition at line 57 of file IgApplication.h.
Referenced by initState(), loadDriver(), and state().
bool IgApplication::m_verbose [private] |