ATLAS Offline Software
Loading...
Searching...
No Matches
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
6#include <EventLoop/Driver.h>
8#include <TSystem.h>
10#include <fstream>
11#include <sstream>
12#include <string>
13#include <vector>
14
15int main (int argc, char **argv)
16{
17 using namespace asg::msgUserCode;
19
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}
macros for messaging and checking status codes
#define ANA_MSG_ERROR(xmsg,...)
Macro printing error messages.
#define ANA_CHECK(EXP)
check whether the given expression was successful
#define ANA_CHECK_SET_TYPE(TYPE)
set the type for ANA_CHECK to report failures
static bool retrieve(const std::string &location)
retrieve all the output for the job in the given location
int main()
Definition hello.cxx:18
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
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
Definition index.py:1
StatusCode Init(const char *appname)
Function initialising ROOT/PyROOT for using the ATLAS EDM.
Definition Init.cxx:31