The Gaudi Framework  v33r0 (d5ea422b)
GaudiMain.cpp File Reference
#include <Gaudi/Application.h>
#include <gsl/span>
#include <iostream>
#include <string_view>
Include dependency graph for GaudiMain.cpp:

Go to the source code of this file.

Functions

GAUDI_API int GaudiMain (int argc, char **argv)
 

Function Documentation

◆ GaudiMain()

GAUDI_API int GaudiMain ( int  argc,
char **  argv 
)

Definition at line 21 of file GaudiMain.cpp.

21  {
23 
24  std::string_view appType{"Gaudi::Application"};
25  std::string_view optsFile;
26 
27  gsl::span args{argv, argc};
28 
29  auto usage = [name = args[0]]( std::ostream& out ) -> std::ostream& {
30  return out << "usage: " << name << " [options] option_file\n";
31  };
32 
33  auto arg = args.begin();
34  ++arg; // ignore application name
35  while ( arg != args.end() ) {
36  std::string_view opt{*arg};
37  if ( opt == "--application" )
38  appType = *++arg;
39  else if ( opt == "-h" || opt == "--help" ) {
40  usage( std::cout );
41  std::cout << R"(
42 Options:
43  -h, --help show this help message and exit
44  --application APPLICATION
45  name of the application class to use [default: Gaudi::Application]
46 )";
47  return EXIT_SUCCESS;
48  } else if ( opt[0] == '-' ) {
49  std::cerr << "error: unknown option " << opt << '\n';
50  usage( std::cerr );
51  return EXIT_FAILURE;
52  } else {
53  optsFile = *arg++;
54  break; // we stop after the first positional argument
55  }
56  ++arg;
57  }
58  if ( arg != args.end() ) { std::cerr << "warning: ignoring extra positional arguments\n"; }
59  if ( optsFile.empty() ) {
60  std::cerr << "error: missing option file argument\n";
61  usage( std::cerr );
62  return EXIT_FAILURE;
63  }
64 
65  if ( optsFile.size() > 3 && optsFile.substr( optsFile.size() - 3 ) == ".py" ) {
66  opts["ApplicationMgr.EvtSel"] = "NONE";
67  opts["ApplicationMgr.JobOptionsType"] = "NONE";
68  opts["ApplicationMgr.DLLs"] = "['GaudiPython']";
69  opts["ApplicationMgr.Runable"] = "PythonScriptingSvc";
70  } else {
71  opts["ApplicationMgr.JobOptionsPath"] = optsFile;
72  }
73 
74  auto app = Gaudi::Application::create( appType, std::move( opts ) );
75  if ( !app ) {
76  std::cerr << "error: failure creating " << appType << '\n';
77  return EXIT_FAILURE;
78  }
79 
80  return app->run();
81 }
list argv
Definition: gaudirun.py:310
void usage(std::string argv0)
def create(cls, appType, opts)
Definition: __init__.py:96
T move(T... args)
STL class.
std::map< std::string, std::string > Options
Definition: Application.h:29