The Gaudi Framework  v32r2 (46d42edc)
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 11 of file GaudiMain.cpp.

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