50{
52
53
54
55 void Driver ::
56 testInvariant () const
57 {}
58
59
60
61 Driver ::
62 Driver ()
63 {
65 }
66
67
68
70 options ()
71 {
73 return &m_options;
74 }
75
76
77
79 options () const
80 {
82 return &m_options;
83 }
84
85
86
87 std::string Driver ::
88 submit (const Job& job, const std::string& location) const
89 {
90
91
92 std::string actualLocation = submitOnly (job, location);
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 {
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
113 data.submitDir = location;
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"));
135 throw std::runtime_error ("failed to open driver file");
136 std::unique_ptr<Driver>
driver (
dynamic_cast<Driver*
>(
file->Get (
"driver")));
139
140 data.resubmit =
true;
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 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 }
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 {
252 const std::string name2 =
name +
"/" +
sample->name() +
".root";
253 std::unique_ptr<SH::SampleLocal> mysample
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 {
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 {
276 {
279 std::unique_ptr<SH::SampleLocal> mysample
281 TList *list =
dynamic_cast<TList*
>(histSample->
readHist (
"EventLoop_OutputStream_" +
out->label()));
282 if (list != 0)
283 {
285 for (TIter iter (list); (
obj =
iter.Next ()); )
286 {
287 TObjString *
str =
dynamic_cast<TObjString*
>(
obj);
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& ) const
304 {
305 return ::StatusCode::SUCCESS;
306 }
307}
#define RCU_ASSERT2_SOFT(x, y)
#define RCU_NEW_INVARIANT(x)
#define RCU_READ_INVARIANT(x)
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
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