ATLAS Offline Software
Loading...
Searching...
No Matches
eventloop_grid_merge.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
9#include <TList.h>
10#include <TSystem.h>
11#include <TFile.h>
12#include <regex>
13
14bool try_exec(const std::string& cmd)
15{
16 using namespace asg::msgUserCode;
17 if (gSystem->Exec(cmd.c_str()) != 0) {
18 ANA_MSG_ERROR ("command failed: " + cmd);
19 return false;
20 }
21 return true;
22}
23
24int main (int argc, char **argv)
25{
26 using namespace asg::msgUserCode;
28
30
31 if (argc != 4)
32 {
33 ANA_MSG_ERROR ("invalid number of arguments");
34 return -1;
35 }
36
37 std::string jobDefFile = argv[1];
38 std::string output = argv[2];
39 std::string input = argv[3];
40
41 std::string type = "DEFAULT";
42 std::string mergeCmd = "";
43
44 TFile jd(jobDefFile.c_str());
45
46 std::unique_ptr<TList> outs{dynamic_cast<TList*>(jd.Get("outputs"))};
47 if (outs.get() == nullptr) {
48 ANA_MSG_ERROR("Unable to get list of output streams");
49 return -1;
50 }
51 TIter itr(outs.get());
52 TObject* obj;
53 while ((obj = itr())) {
54 EL::OutputStream* os = dynamic_cast<EL::OutputStream*>(obj);
55 if (std::regex_match(output, std::regex(os->label() + "\\.root.*")) ||
56 std::regex_match(output, std::regex(".*\\." + os->label() + "\\.root.*")))
57 {
59 mergeCmd = os->options()->castString(EL::OutputStream::optMergeCmd, "", SH::MetaObject::CAST_NOCAST_DEFAULT);
60 break;
61 }
62 }
63
64 if (mergeCmd.empty()) {
65 if (type == "xAOD") {
66 mergeCmd = "xAODMerge -s";
67 } else if (type == "xAODNoMeta") {
68 mergeCmd = "xAODMerge";
69 } else {
70 mergeCmd = "hadd -f";
71 }
72 }
73 mergeCmd += " " + output + " " + input;
74 if (not try_exec(mergeCmd)) return -1;
75}
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 const std::string optType
static const std::string optMergeCmd
@ CAST_NOCAST_DEFAULT
cast and return the default value if the input has the wrong type
Definition MetaObject.h:78
bool try_exec(const std::string &cmd)
int main()
Definition hello.cxx:18
StatusCode Init(const char *appname)
Function initialising ROOT/PyROOT for using the ATLAS EDM.
Definition Init.cxx:31