ATLAS Offline Software
Loading...
Searching...
No Matches
Driver.cxx File Reference
#include <EventLoop/Driver.h>
#include <EventLoop/BaseManager.h>
#include <EventLoop/DriverManager.h>
#include <EventLoop/Job.h>
#include <EventLoop/ManagerData.h>
#include <EventLoop/ManagerOrder.h>
#include <EventLoop/ManagerStep.h>
#include <EventLoop/MessageCheck.h>
#include <EventLoop/MetricsSvc.h>
#include <EventLoop/OutputStream.h>
#include <EventLoop/RetrieveManager.h>
#include <EventLoop/SubmitDirManager.h>
#include <EventLoop/SubmitManager.h>
#include <RootCoreUtils/RootUtils.h>
#include <SampleHandler/DiskListLocal.h>
#include <SampleHandler/Sample.h>
#include <SampleHandler/SampleHist.h>
#include <SampleHandler/SampleLocal.h>
#include <TFile.h>
#include <TObjString.h>
#include <TSystem.h>
#include <cstddef>
#include <fstream>
#include <iostream>
#include <memory>
#include <stdexcept>
#include <signal.h>

Go to the source code of this file.

Functions

 ClassImp (EL::Driver) namespace EL

Function Documentation

◆ ClassImp()

ClassImp ( EL::Driver )

Definition at line 47 of file Driver.cxx.

50{
51 bool EL::Driver::abortRetrieve(false);
52
53
54
55 void Driver ::
56 testInvariant () const
57 {}
58
59
60
61 Driver ::
62 Driver ()
63 {
64 RCU_NEW_INVARIANT (this);
65 }
66
67
68
69 SH::MetaObject *Driver ::
70 options ()
71 {
72 RCU_READ_INVARIANT (this);
73 return &m_options;
74 }
75
76
77
78 const SH::MetaObject *Driver ::
79 options () const
80 {
81 RCU_READ_INVARIANT (this);
82 return &m_options;
83 }
84
85
86
87 std::string Driver ::
88 submit (const Job& job, const std::string& location) const
89 {
90 // no invariant used
91
92 std::string actualLocation = submitOnly (job, location);
93 ANA_MSG_DEBUG ("wait on: " << actualLocation);
94 wait (actualLocation);
95 return actualLocation;
96 }
97
98
99
100 std::string Driver ::
101 submitOnly (const Job& job, const std::string& location) const
102 {
103 RCU_READ_INVARIANT (this);
104
105 Detail::ManagerData data;
106 data.addManager (std::make_unique<Detail::BaseManager> ());
107 data.addManager (std::make_unique<Detail::SubmitDirManager> ());
108 data.addManager (std::make_unique<Detail::DriverManager> ());
109 data.addManager (std::make_unique<Detail::SubmitManager> ());
110
111 Job myjob = job;
112 data.driver = this;
113 data.submitDir = location;
114 data.job = &myjob;
115 if (data.run().isFailure())
116 throw std::runtime_error ("failed to submit job");
117 return data.submitDir;
118 }
119
120
121
122 void Driver ::
123 resubmit (const std::string& location,
124 const std::string& option)
125 {
126 Detail::ManagerData data;
127 data.addManager (std::make_unique<Detail::BaseManager> ());
128 data.addManager (std::make_unique<Detail::SubmitDirManager> ());
129 data.addManager (std::make_unique<Detail::DriverManager> ());
130 data.addManager (std::make_unique<Detail::SubmitManager> ());
131 data.submitDir = location;
132
133 std::unique_ptr<TFile> file (TFile::Open ((location + "/driver.root").c_str(), "READ"));
134 if (!file || file->IsZombie())
135 throw std::runtime_error ("failed to open driver file");
136 std::unique_ptr<Driver> driver (dynamic_cast<Driver*>(file->Get ("driver")));
137 RCU_ASSERT2_SOFT (driver.get() != 0, "failed to read driver");
138 data.driver = driver.get();
139
140 data.resubmit = true;
141 data.resubmitOption = option;
142 if (data.run().isFailure())
143 throw std::runtime_error ("failed to resubmit job");
144 }
145
146
147
148 bool Driver ::
149 retrieve (const std::string& location)
150 {
151 Detail::ManagerData data;
152 data.addManager (std::make_unique<Detail::BaseManager> ());
153 data.addManager (std::make_unique<Detail::SubmitDirManager> ());
154 data.addManager (std::make_unique<Detail::DriverManager> ());
155 data.addManager (std::make_unique<Detail::RetrieveManager> ());
156 data.submitDir = location;
157
158 std::unique_ptr<TFile> file (TFile::Open ((location + "/driver.root").c_str(), "READ"));
159 if (!file || file->IsZombie())
160 throw std::runtime_error ("failed to open driver file");
161 std::unique_ptr<Driver> driver (dynamic_cast<Driver*>(file->Get ("driver")));
162 RCU_ASSERT2_SOFT (driver.get() != 0, "failed to read driver");
163 data.driver = driver.get();
164
165 if (data.run().isFailure())
166 throw std::runtime_error ("failed to retrieve job");
167 return data.completed;
168 }
169
170
171
172 bool Driver ::
173 wait (const std::string& location, unsigned time)
174 {
175 // no invariant used
176
177 struct SigTrap {
178 static void handler (int)
179 {
181 ANA_MSG_INFO ("\nAborting...");
182 }
183 SigTrap() { signal (SIGINT, &handler); }
184 ~SigTrap() { signal (SIGINT, SIG_DFL); EL::Driver::abortRetrieve = false; }
185 } sigTrap;
186
187 while (!retrieve (location))
188 {
189 if (abortRetrieve) { return false; }
190 ANA_MSG_INFO ("not all worker jobs finished yet, waiting " << time << " seconds");
191 for (unsigned i = 0; i != time; ++i)
192 {
193 if (abortRetrieve) { return false; }
194 sleep (1);
195 }
196 ANA_MSG_INFO ("rechecking jobs");
197 }
198 return true;
199 }
200
201
202
203 void Driver ::
204 updateLocation (const std::string& location)
205 {
206 std::string from;
207 {
208 std::ifstream file ((location + "/location").c_str());
209 if (!std::getline (file, from))
210 throw std::runtime_error ("failed to read submit location from " + location + "/location");
211 }
212 std::string to = location;
213 while (!to.empty() && to[to.size()-1] == '/')
214 to.resize (to.size()-1);
215 {
217 sh.load (location + "/hist");
218 sh.updateLocation (from, to);
219 sh.save (location + "/hist");
220 }
221 SH::DiskListLocal list (location);
222 while (list.next())
223 {
224 if (list.fileName().find ("output-") == 0)
225 {
227 sh.load (list.path());
228 sh.updateLocation (from, to);
229 sh.save (list.path());
230 }
231 }
232 {
233 std::ofstream file ((location + "/location").c_str());
234 file << to << std::endl;
235 }
236 }
237
238
239
240 void Driver ::
241 mergedOutputSave (Detail::ManagerData& data)
242 {
243 for (Job::outputIter out = data.job->outputBegin(),
244 end = data.job->outputEnd(); out != end; ++ out)
245 {
246 const std::string name
247 = data.submitDir + "/data-" + out->label();
248
250 for (SH::Sample *sample : data.job->sampleHandler())
251 {
252 const std::string name2 = name + "/" + sample->name() + ".root";
253 std::unique_ptr<SH::SampleLocal> mysample
254 (new SH::SampleLocal (sample->name()));
255 mysample->add (name2);
256 sh.add (std::move (mysample));
257 }
258 sh.fetch (data.job->sampleHandler());
259 sh.save (data.submitDir + "/output-" + out->label());
260 }
261 }
262
263
264
265 void Driver ::
266 diskOutputSave (Detail::ManagerData& data)
267 {
268 SH::SampleHandler sh_hist;
269 sh_hist.load (data.submitDir + "/hist");
270
271 for (Job::outputIter out = data.job->outputBegin(),
272 end = data.job->outputEnd(); out != end; ++ out)
273 {
275 for (SH::Sample *sample : data.job->sampleHandler())
276 {
277 SH::Sample *histSample = sh_hist.get (sample->name());
278 RCU_ASSERT (histSample != 0);
279 std::unique_ptr<SH::SampleLocal> mysample
280 (new SH::SampleLocal (sample->name()));
281 TList *list = dynamic_cast<TList*>(histSample->readHist ("EventLoop_OutputStream_" + out->label()));
282 if (list != 0)
283 {
284 TObject *obj = 0;
285 for (TIter iter (list); (obj = iter.Next ()); )
286 {
287 TObjString *str = dynamic_cast<TObjString*>(obj);
288 RCU_ASSERT (str != 0);
289 mysample->add (str->GetString().Data());
290 }
291 }
292 mysample->meta()->fetch (*out->options());
293 sh.add (std::move (mysample));
294 }
295 sh.fetch (data.job->sampleHandler());
296 sh.save (data.submitDir + "/output-" + out->label());
297 }
298 }
299
300
301
302 ::StatusCode Driver ::
303 doManagerStep (Detail::ManagerData& /*data*/) const
304 {
305 return ::StatusCode::SUCCESS;
306 }
307}
#define RCU_ASSERT(x)
Definition Assert.h:210
#define RCU_ASSERT2_SOFT(x, y)
Definition Assert.h:157
#define RCU_NEW_INVARIANT(x)
Definition Assert.h:221
#define RCU_READ_INVARIANT(x)
Definition Assert.h:217
#define ANA_MSG_DEBUG(xmsg,...)
Macro printing debug messages.
#define ANA_MSG_INFO(xmsg,...)
Macro printing info messages.
static bool abortRetrieve
this flag is set to true when the wait() function is running and a SIGINT is caught,...
Definition Driver.h:212
a DiskList implementation for local directories
A class that manages meta-data to be associated with an object.
Definition MetaObject.h:48
A class that manages a list of Sample objects.
Sample * get(const std::string &name)
get the sample with the given name
void load(const std::string &directory)
load all the samples from the given directory
A Sample based on a simple file list.
Definition SampleLocal.h:30
a base class that manages a set of files belonging to a particular data set and the associated meta-d...
Definition Sample.h:49
TObject * readHist(const std::string &name) const
read an object from a histogram file
time(flags, cells_name, *args, **kw)
CONT to(RANGE &&r)
Definition ranges.h:39
void handler(int sig)
signal handler
Definition rmain.cxx:99
TFile * file