ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
PhysicsAnalysis
D3PDTools
EventLoop
util
eventloop_exec_worker.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
#include <
AsgMessaging/MessageCheck.h
>
6
#include <
EventLoop/Driver.h
>
7
#include <
RootCoreUtils/ShellExec.h
>
8
#include <TSystem.h>
9
#include <
xAODRootAccess/Init.h
>
10
#include <fstream>
11
#include <sstream>
12
#include <string>
13
#include <vector>
14
15
int
main
(
int
argc,
char
**argv)
16
{
17
using namespace
asg::msgUserCode;
18
ANA_CHECK_SET_TYPE
(
int
);
19
20
ANA_CHECK
(
xAOD::Init
());
21
22
// arguments: <submitDir> <resubmit:0|1> <index>...
23
if
(argc < 3)
24
{
25
ANA_MSG_ERROR
(
"invalid number of arguments"
);
26
return
-1;
27
}
28
29
const
std::string submitDir = argv[1];
30
const
bool
resubmit = (std::string (argv[2]) ==
"1"
);
31
32
std::vector<std::size_t> indices;
33
for
(
int
arg = 3; arg != argc; ++ arg)
34
{
35
try
36
{
37
indices.push_back (std::stoul (argv[arg]));
38
}
catch
(std::exception& e)
39
{
40
ANA_MSG_ERROR
(
"failed to parse job index \""
<< argv[arg] <<
"\": "
<< e.what());
41
return
-1;
42
}
43
}
44
45
const
std::string basedirName = submitDir +
"/tmp"
;
46
47
// on resubmit the tmp directory already exists from the first submission
48
if
(!resubmit && gSystem->MakeDirectory (basedirName.c_str()) != 0)
49
{
50
ANA_MSG_ERROR
(
"failed to create directory "
+ basedirName);
51
return
-1;
52
}
53
54
auto
submitSingle = [&] (std::size_t
index
)
noexcept
-> StatusCode
55
{
56
try
57
{
58
const
std::string dirName = basedirName +
"/"
+ std::to_string (
index
);
59
if
(gSystem->MakeDirectory (dirName.c_str()) != 0 && !resubmit)
60
{
61
ANA_MSG_ERROR
(
"failed to create directory "
+ dirName);
62
return
StatusCode::FAILURE;
63
}
64
65
std::ostringstream cmd;
66
cmd <<
"cd "
<<
RCU::Shell::quote
(dirName) <<
" && "
;
67
cmd <<
RCU::Shell::quote
(submitDir) <<
"/submit/run "
<<
index
;
68
RCU::Shell::exec
(cmd.str());
69
}
catch
(std::exception& e)
70
{
71
ANA_MSG_ERROR
(
"exception in job "
<<
index
<<
": "
<< e.what());
72
return
StatusCode::FAILURE;
73
}
74
return
StatusCode::SUCCESS;
75
};
76
for
(std::size_t
index
: indices)
77
{
78
if
(submitSingle (
index
).isFailure())
79
return
EXIT_FAILURE;
80
}
81
// this particular file can be checked to see if a job has
82
// been submitted successfully.
83
std::ofstream ((submitDir +
"/submitted"
).c_str());
84
if
(!
EL::Driver::retrieve
(submitDir))
85
{
86
ANA_MSG_ERROR
(
"failed to retrieve job output in "
+ submitDir);
87
return
EXIT_FAILURE;
88
}
89
return
0;
90
}
MessageCheck.h
macros for messaging and checking status codes
ANA_MSG_ERROR
#define ANA_MSG_ERROR(xmsg,...)
Macro printing error messages.
Definition
Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:295
ANA_CHECK
#define ANA_CHECK(EXP)
check whether the given expression was successful
Definition
Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:325
ANA_CHECK_SET_TYPE
#define ANA_CHECK_SET_TYPE(TYPE)
set the type for ANA_CHECK to report failures
Definition
Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:315
Driver.h
Init.h
ShellExec.h
EL::Driver::retrieve
static bool retrieve(const std::string &location)
retrieve all the output for the job in the given location
main
int main()
Definition
hello.cxx:18
RCU::Shell::exec
void exec(const std::string &cmd)
effects: execute the given command guarantee: strong failures: out of memory II failures: system fail...
Definition
ShellExec.cxx:27
RCU::Shell::quote
std::string quote(const std::string &name)
effects: quote the given name to protect it from the shell returns: the quoted name guarantee: strong...
Definition
ShellExec.cxx:65
index
Definition
index.py:1
xAOD::Init
StatusCode Init(const char *appname)
Function initialising ROOT/PyROOT for using the ATLAS EDM.
Definition
Init.cxx:31
Generated on
for ATLAS Offline Software by
1.17.0