56 testInvariant ()
const
88 submit (
const Job& job,
const std::string& location)
const
92 std::string actualLocation = submitOnly (job, location);
94 wait (actualLocation);
95 return actualLocation;
100 std::string Driver ::
101 submitOnly (
const Job& job,
const std::string& location)
const
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> ());
113 data.submitDir = location;
115 if (data.run().isFailure())
116 throw std::runtime_error (
"failed to submit job");
117 return data.submitDir;
123 resubmit (
const std::string& location,
124 const std::string& option)
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;
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")));
138 data.driver = driver.get();
140 data.resubmit =
true;
141 data.resubmitOption = option;
142 if (data.run().isFailure())
143 throw std::runtime_error (
"failed to resubmit job");
149 retrieve (
const std::string& location)
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;
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")));
163 data.driver = driver.get();
165 if (data.run().isFailure())
166 throw std::runtime_error (
"failed to retrieve job");
167 return data.completed;
173 wait (
const std::string& location,
unsigned time)
183 SigTrap() { signal (SIGINT, &
handler); }
187 while (!retrieve (location))
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)
193 if (abortRetrieve) {
return false; }
204 updateLocation (
const std::string& location)
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");
212 std::string to = location;
213 while (!to.empty() && to[to.size()-1] ==
'/')
214 to.resize (to.size()-1);
217 sh.load (location +
"/hist");
218 sh.updateLocation (from, to);
219 sh.save (location +
"/hist");
224 if (list.fileName().find (
"output-") == 0)
227 sh.load (list.path());
228 sh.updateLocation (from, to);
229 sh.save (list.path());
233 std::ofstream
file ((location +
"/location").c_str());
234 file << to << std::endl;
241 mergedOutputSave (Detail::ManagerData& data)
244 end = data.job->outputEnd(); out != end; ++ out)
246 const std::string name
247 = data.submitDir +
"/data-" + out->label();
250 for (
SH::Sample *sample : data.job->sampleHandler())
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));
258 sh.fetch (data.job->sampleHandler());
259 sh.save (data.submitDir +
"/output-" + out->label());
266 diskOutputSave (Detail::ManagerData& data)
269 sh_hist.
load (data.submitDir +
"/hist");
272 end = data.job->outputEnd(); out != end; ++ out)
275 for (
SH::Sample *sample : data.job->sampleHandler())
279 std::unique_ptr<SH::SampleLocal> mysample
281 TList *list =
dynamic_cast<TList*
>(histSample->
readHist (
"EventLoop_OutputStream_" + out->label()));
285 for (TIter iter (list); (obj = iter.Next ()); )
287 TObjString *
str =
dynamic_cast<TObjString*
>(obj);
289 mysample->add (
str->GetString().Data());
292 mysample->meta()->fetch (*out->options());
293 sh.add (std::move (mysample));
295 sh.fetch (data.job->sampleHandler());
296 sh.save (data.submitDir +
"/output-" + out->label());
302 ::StatusCode Driver ::
303 doManagerStep (Detail::ManagerData& )
const
305 return ::StatusCode::SUCCESS;