50{
52
53
54
55 void Driver ::
56 testInvariant () const
57 {
59 }
60
61
62
63 Driver ::
64 Driver ()
65 {
67 }
68
69
70
72 options ()
73 {
75 return &m_options;
76 }
77
78
79
81 options () const
82 {
84 return &m_options;
85 }
86
87
88
89 std::string Driver ::
90 submit (const Job& job, const std::string& location) const
91 {
92
93
94 std::string actualLocation = submitOnly (job, location);
96 wait (actualLocation);
97 return actualLocation;
98 }
99
100
101
102 std::string Driver ::
103 submitOnly (const Job& job, const std::string& location) const
104 {
106
107 Detail::ManagerData
data;
108 data.addManager (std::make_unique<Detail::BaseManager> ());
109 data.addManager (std::make_unique<Detail::SubmitDirManager> ());
110 data.addManager (std::make_unique<Detail::DriverManager> ());
111 data.addManager (std::make_unique<Detail::SubmitManager> ());
112
115 data.submitDir = location;
117 if (
data.run().isFailure())
118 throw std::runtime_error ("failed to submit job");
119 return data.submitDir;
120 }
121
122
123
124 void Driver ::
125 resubmit (const std::string& location,
126 const std::string& option)
127 {
128 Detail::ManagerData
data;
129 data.addManager (std::make_unique<Detail::BaseManager> ());
130 data.addManager (std::make_unique<Detail::SubmitDirManager> ());
131 data.addManager (std::make_unique<Detail::DriverManager> ());
132 data.addManager (std::make_unique<Detail::SubmitManager> ());
133 data.submitDir = location;
134
135 std::unique_ptr<TFile>
file (TFile::Open ((location +
"/driver.root").c_str(),
"READ"));
136 std::unique_ptr<Driver>
driver (
dynamic_cast<Driver*
>(
file->Get (
"driver")));
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"));
160 throw std::runtime_error ("failed to open driver file");
161 std::unique_ptr<Driver>
driver (
dynamic_cast<Driver*
>(
file->Get (
"driver")));
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
176
177 struct SigTrap {
179 {
182 }
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 }
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 RCU_THROW_MSG (
"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 }
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());
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
251 end =
data.job->sampleHandler().end(); sample != end; ++ sample)
252 {
253 const std::string name2 =
name +
"/" + (*sample)->name() +
".root";
254 std::unique_ptr<SH::SampleLocal> mysample
256 mysample->add (name2);
257 sh.add (mysample.release());
258 }
259 sh.fetch (
data.job->sampleHandler());
260 sh.save (
data.submitDir +
"/output-" +
out->label());
261 }
262 }
263
264
265
266 void Driver ::
267 diskOutputSave (Detail::ManagerData&
data)
268 {
270 sh_hist.
load (
data.submitDir +
"/hist");
271
272 for (Job::outputIter out =
data.job->outputBegin(),
273 end =
data.job->outputEnd(); out != end; ++ out)
274 {
277 end =
data.job->sampleHandler().end(); sample != end; ++ sample)
278 {
281 std::unique_ptr<SH::SampleLocal> mysample
283 TList *list =
dynamic_cast<TList*
>(histSample->
readHist (
"EventLoop_OutputStream_" +
out->label()));
284 if (list != 0)
285 {
287 for (TIter iter (list); (
obj =
iter.Next ()); )
288 {
289 TObjString *
str =
dynamic_cast<TObjString*
>(
obj);
291 mysample->add (
str->GetString().Data());
292 }
293 }
294 mysample->meta()->fetch (*
out->options());
295 sh.add (mysample.release());
296 }
297 sh.fetch (
data.job->sampleHandler());
298 sh.save (
data.submitDir +
"/output-" +
out->label());
299 }
300 }
301
302
303
304 ::StatusCode Driver ::
305 doManagerStep (Detail::ManagerData& ) const
306 {
307 return ::StatusCode::SUCCESS;
308 }
309}
#define RCU_ASSERT2_SOFT(x, y)
#define RCU_NEW_INVARIANT(x)
#define RCU_READ_INVARIANT(x)
char data[hepevt_bytes_allocation_ATLAS]
#define RCU_THROW_MSG(message)
static bool abortRetrieve
this flag is set to true when the wait() function is running and a SIGINT is caught,...
a DiskList implementation for local directories
A class that manages a list of Sample objects.
Sample * get(const std::string &name)
get the sample with the given name
std::vector< Sample * >::const_iterator iterator
the iterator to use
void load(const std::string &directory)
load all the samples from the given directory
A Sample based on a simple file list.
a base class that manages a set of files belonging to a particular data set and the associated meta-d...
TObject * readHist(const std::string &name) const
read an object from a histogram file
time(flags, cells_name, *args, **kw)
void handler(int sig)
signal handler