The Gaudi Framework
v33r0 (d5ea422b)
GaudiMain.cpp
Go to the documentation of this file.
1
/***********************************************************************************\
2
* (c) Copyright 1998-2019 CERN for the benefit of the LHCb and ATLAS collaborations *
3
* *
4
* This software is distributed under the terms of the Apache version 2 licence, *
5
* copied verbatim in the file "LICENSE". *
6
* *
7
* In applying this licence, CERN does not waive the privileges and immunities *
8
* granted to it by virtue of its status as an Intergovernmental Organization *
9
* or submit itself to any jurisdiction. *
10
\***********************************************************************************/
11
//------------------------------------------------------------------------------
12
//
13
// Description: Main Program for Gaudi applications
14
//
15
//------------------------------------------------------------------------------
16
#include <
Gaudi/Application.h
>
17
#include <gsl/span>
18
#include <iostream>
19
#include <string_view>
20
21
extern
"C"
GAUDI_API
int
GaudiMain
(
int
argc
,
char
**
argv
) {
22
Gaudi::Application::Options
opts
;
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
}
gaudiComponentHelp.name
name
Definition:
gaudiComponentHelp.py:52
gaudirun.argv
list argv
Definition:
gaudirun.py:310
usage
void usage(std::string argv0)
Definition:
listcomponents.cpp:41
gaudirun.opts
opts
Definition:
gaudirun.py:319
gaudirun.args
args
Definition:
gaudirun.py:319
Gaudi.Application.create
def create(cls, appType, opts)
Definition:
__init__.py:96
std::move
T move(T... args)
plotBacklogPyRoot.argc
argc
Definition:
plotBacklogPyRoot.py:153
GaudiMain
GAUDI_API int GaudiMain(int argc, char **argv)
Definition:
GaudiMain.cpp:21
GAUDI_API
#define GAUDI_API
Definition:
Kernel.h:81
std::ostream
STL class.
Application.h
Gaudi.Application::Options
std::map< std::string, std::string > Options
Definition:
Application.h:29
GaudiKernel
src
Lib
GaudiMain.cpp
Generated on Mon Dec 16 2019 23:26:35 for The Gaudi Framework by
1.8.15