ATLAS Offline Software
CondorDriver.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
7 
8 //
9 // includes
10 //
11 
12 #include <EventLoop/CondorDriver.h>
13 
15 #include <EventLoop/BatchJob.h>
16 #include <EventLoop/Job.h>
17 #include <EventLoop/ManagerData.h>
18 #include <EventLoop/MessageCheck.h>
19 #include <RootCoreUtils/Assert.h>
20 #include <RootCoreUtils/ThrowMsg.h>
21 #include <TSystem.h>
22 #include <fstream>
23 #include <memory>
24 #include <sstream>
25 #include <cstdlib>
26 #include <filesystem>
27 
28 //
29 // method implementations
30 //
31 
33 
34 namespace EL
35 {
36  void CondorDriver ::
37  testInvariant () const
38  {
39  RCU_INVARIANT (this != 0);
40  }
41 
42 
43 
46  {
47  RCU_NEW_INVARIANT (this);
48  }
49 
50 
51 
53  doManagerStep (Detail::ManagerData& data) const
54  {
55  RCU_READ_INVARIANT (this);
56  using namespace msgEventLoop;
58  switch (data.step)
59  {
61  {
62  data.batchInit = "export PATH LD_LIBRARY_PATH PYTHONPATH";
63  }
64  break;
65 
68  {
69  // name of tarball being made (this needs to match BatchDriver.cxx)
70  const std::string tarballName("AnalysisPackage.tar.gz");
71 
72  if (!data.resubmit)
73  {
74  if(!data.options.castBool(Job::optBatchSharedFileSystem,true))
75  {
76  const std::string newLocation = data.submitDir + "/submit/" + tarballName;
77  int status=gSystem->CopyFile(tarballName.c_str(),newLocation.c_str());
78  if(status != 0)
79  RCU_THROW_MSG( ("failed to copy " + tarballName + " to " + newLocation).c_str() );
80  }
81  }
82 
83  {
84  std::ofstream file ((data.submitDir + "/submit/submit").c_str());
85  file << "executable = run\n";
86  file << "universe = vanilla\n";
87  file << "log = submit/run.log\n";
88  file << "output = submit/log-$(Item).out\n";
89  file << "error = submit/log-$(Item).err\n";
90  file << "initialdir = " << data.submitDir << "\n";
91  if(!data.options.castBool(Job::optBatchSharedFileSystem,true))
92  { // Transfer data with non-shared file-systems
93  file << "should_transfer_files = YES\n";
94  file << "when_to_transfer_output = ON_EXIT\n";
95  file << "transfer_input_files = submit/" << tarballName << ", submit/segments, submit/config.root\n";
96  file << "transfer_output_files = fetch, status\n";
97  if (char* x509userproxy = std::getenv("X509_USER_PROXY")) {
98  std::filesystem::path proxyPath(x509userproxy);
99  std::filesystem::path proxyPathDestination(data.submitDir + "/submit/" + proxyPath.filename().string());
100  std::filesystem::copy(proxyPath,
101  proxyPathDestination,
102  std::filesystem::copy_options::overwrite_existing);
103  file << "x509userproxy = " << proxyPathDestination.string() <<"\n";
104  }
105  else {
106  ANA_MSG_INFO("X509_USER_PROXY not set");
107  }
108  }
109  file << "arguments = $(Item)\n";
110  file << "\n" << data.options.castString (Job::optCondorConf) << "\n";
111  file << "queue in ( ";
112  bool first {true};
113  for (std::size_t index : data.batchJobIndices)
114  {
115  if (first)
116  first = false;
117  else
118  file << ", ";
119  file << index;
120  }
121  file << " )\n";
122  }
123 
124  {
125  std::ostringstream cmd;
126  cmd << "cd " << data.submitDir << "/submit && condor_submit "
127  << data.options.castString (Job::optSubmitFlags) << " submit";
128  if (gSystem->Exec (cmd.str().c_str()) != 0)
129  RCU_THROW_MSG (("failed to execute: " + cmd.str()).c_str());
130  }
131  data.submitted = true;
132  }
133  break;
134 
135  default:
136  break;
137  }
138  return ::StatusCode::SUCCESS;
139  }
140 }
EL::Job::optCondorConf
static const std::string optCondorConf
description: the name of the option for supplying extra parameters for condor systems
Definition: Job.h:299
EL::CondorDriver::CondorDriver
CondorDriver()
effects: standard default constructor guarantee: strong failures: low level errors I
data
char data[hepevt_bytes_allocation_ATLAS]
Definition: HepEvt.cxx:11
EL::CondorDriver
a Driver to run on Condor batch systems
Definition: CondorDriver.h:21
athena.path
path
python interpreter configuration --------------------------------------—
Definition: athena.py:128
EL::Job::optBatchSharedFileSystem
static const std::string optBatchSharedFileSystem
description: batch-specific options rationale: these options are for configuring batch drivers
Definition: Job.h:513
EL::Detail::ManagerStep::batchScriptVar
@ batchScriptVar
create the variables needed for the batch-run script
CondorDriver.h
EL::BatchDriver::doManagerStep
virtual ::StatusCode doManagerStep(Detail::ManagerData &data) const override
index
Definition: index.py:1
rerun_display.cmd
string cmd
Definition: rerun_display.py:67
Job.h
ANA_CHECK
#define ANA_CHECK(EXP)
check whether the given expression was successful
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:324
Assert.h
MessageCheck.h
EL::Detail::ManagerStep::doResubmit
@ doResubmit
call the actual doResubmit method
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ManagerData.h
ANA_MSG_INFO
#define ANA_MSG_INFO(xmsg)
Macro printing info messages.
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:290
file
TFile * file
Definition: tile_monitor.h:29
EL::CondorDriver::doManagerStep
virtual ::StatusCode doManagerStep(Detail::ManagerData &data) const override
EL
This module defines the arguments passed from the BATCH driver to the BATCH worker.
Definition: AlgorithmWorkerData.h:24
EL::Job::optSubmitFlags
static const std::string optSubmitFlags
description: the name of the option for supplying extra submit parameters to batch systems rationale:...
Definition: Job.h:293
RCU_INVARIANT
#define RCU_INVARIANT(x)
Definition: Assert.h:201
StatusCode.h
ThrowMsg.h
BatchJob.h
EL::CondorDriver::testInvariant
void testInvariant() const
effects: test the invariant of this object guarantee: no-fail
DeMoScan.index
string index
Definition: DeMoScan.py:364
SCT_ConditionsAlgorithms::CoveritySafe::getenv
std::string getenv(const std::string &variableName)
get an environment variable
Definition: SCT_ConditionsUtilities.cxx:17
DeMoScan.first
bool first
Definition: DeMoScan.py:536
merge.status
status
Definition: merge.py:17
RCU_THROW_MSG
#define RCU_THROW_MSG(message)
Definition: PrintMsg.h:58
calibdata.copy
bool copy
Definition: calibdata.py:27
RCU_READ_INVARIANT
#define RCU_READ_INVARIANT(x)
Definition: Assert.h:229
EL::Detail::ManagerStep::submitJob
@ submitJob
do the actual job submission
ClassImp
ClassImp(EL::CondorDriver) namespace EL
Definition: CondorDriver.cxx:32
RCU_NEW_INVARIANT
#define RCU_NEW_INVARIANT(x)
Definition: Assert.h:233