1 // Copyright (C) 2019 EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #ifndef YDEFX_LAUNCHER_H
20 #define YDEFX_LAUNCHER_H
22 #include "TMonoPyJob.hxx"
23 #include "TPyStudyJob.hxx"
31 Launcher():_lastError(){}
32 const std::string& lastError()const{return _lastError;}
35 * Create and submit a new job.
36 * Return nullptr in case of failure. Check the error with lastError().
38 template <class ...Ts>
39 Job* submitMonoPyJob(const PyStudyFunction& fnScript,
40 Sample<Ts...>& sample,
41 const JobParametersProxy& params);
43 template <class ...Ts>
44 Job* submitPyStudyJob(py2cpp::PyPtr& pyStudyObj,
45 const PyStudyFunction& fnScript,
46 Sample<Ts...>& sample,
47 const JobParametersProxy& params);
50 * Connect to an already created job.
51 * Return nullptr in case of failure. Check the error with lastError().
53 template <class ...Ts>
54 Job* connectJob(const std::string& jobDump, Sample<Ts...>& sample);
56 template <class ...Ts>
57 Job* submitMultiPyJob(const PyStudyFunction& fn,
58 Sample<Ts...>& sample,
59 const JobParametersProxy& params);
62 std::string _lastError;
65 ////////////////////////////////////////////////////////////////////////////////
66 // Template implementations
67 ////////////////////////////////////////////////////////////////////////////////
69 template <class ...Ts>
70 Job* Launcher::submitMonoPyJob(const PyStudyFunction& fnScript,
71 Sample<Ts...>& sample,
72 const JobParametersProxy& params)
74 Job* result = nullptr;
78 result = new TMonoPyJob<Ts...>(fnScript, sample, params);
80 catch(std::exception& e)
85 _lastError = e.what();
89 if(!result->lastError().empty())
91 _lastError = result->lastError();
99 _lastError = "Failed to submit job.\n";
100 _lastError += result->lastError();
107 template <class ...Ts>
108 Job* Launcher::submitPyStudyJob(py2cpp::PyPtr& pyStudyObj,
109 const PyStudyFunction& fnScript,
110 Sample<Ts...>& sample,
111 const JobParametersProxy& params)
113 Job* result = nullptr;
117 result = new TPyStudyJob<Ts...>(pyStudyObj, fnScript, sample, params);
119 catch(std::exception& e)
121 if(result != nullptr)
124 _lastError = e.what();
128 if(!result->lastError().empty())
130 _lastError = result->lastError();
136 if(!result->launch())
138 _lastError = "Failed to submit job.\n";
139 _lastError += result->lastError();
146 template <class ...Ts>
147 Job* Launcher::connectJob(const std::string& jobDump,
148 Sample<Ts...>& sample)
150 Job* result = nullptr;
154 result = new TMonoPyJob<Ts...>(jobDump, sample);
156 catch(std::exception& e)
158 if(result != nullptr)
161 _lastError = e.what();
167 template <class ...Ts>
168 Job* Launcher::submitMultiPyJob(const PyStudyFunction& fn,
169 Sample<Ts...>& sample,
170 const JobParametersProxy& params)
173 _lastError = "Not implemented!";
178 #endif // YDEFX_LAUNCHER_H