votca 2024.2-dev
Loading...
Searching...
No Matches
job.h
Go to the documentation of this file.
1/*
2 * Copyright 2009-2020 The VOTCA Development Team
3 * (http://www.votca.org)
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License")
6 *
7 * You may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *
18 */
19
20#pragma once
21#ifndef VOTCA_XTP_JOB_H
22#define VOTCA_XTP_JOB_H
23
24// Standard includes
25#include <fstream>
26#include <iostream>
27#include <string>
28
29// VOTCA includes
31
32namespace votca {
33namespace xtp {
34
35class Job {
36
37 public:
39
40 Job(const tools::Property &prop);
41 Job(Index id, const std::string &tag, const tools::Property &input,
42 JobStatus status);
43
44 std::string ConvertStatus(JobStatus) const;
45 JobStatus ConvertStatus(std::string) const;
46
47 class JobResult {
48 public:
49 void setStatus(JobStatus stat) { status_ = stat; }
50 void setOutput(std::string output) {
51 has_output_ = true;
52 output_ = tools::Property().add("output", output);
53 }
54 void setOutput(tools::Property &output) {
55 has_output_ = true;
56 output_ = output.get("output");
57 }
58
59 JobStatus getStatus() const { return status_; }
60 bool hasOutput() const { return has_output_; }
61 const tools::Property &getOutput() const { return output_; }
62
64 bool hasError() const { return has_error_; }
65 const std::string &getError() const { return error_; }
66
67 void setError(std::string error) {
68 has_error_ = true;
69 error_ = error;
70 }
71
72 private:
75 bool has_output_ = false;
76 std::string error_;
77 bool has_error_ = false;
78 };
79
80 void Reset();
81 void ToStream(std::ofstream &ofs) const;
82 void UpdateFrom(const Job &ext);
83 void UpdateFromResult(const JobResult &res);
84
85 Index getId() const { return id_; }
86 std::string getTag() const { return tag_; }
88 const tools::Property &getInput() const { return input_; }
89 const JobStatus &getStatus() const { return status_; }
90 std::string getStatusStr() const { return ConvertStatus(status_); }
91
92 bool hasHost() const { return has_host_; }
93 bool hasTime() const { return has_time_; }
94 bool hasOutput() const { return has_output_; }
95 bool hasError() const { return has_error_; }
96
97 bool isAvailable() const { return (status_ == AVAILABLE) ? true : false; }
98 bool isAssigned() const { return (status_ == ASSIGNED) ? true : false; }
99 bool isFailed() const { return (status_ == FAILED) ? true : false; }
100 bool isComplete() const { return (status_ == COMPLETE) ? true : false; }
101 bool isFresh() const { return (attemptsCount_ < 1) ? true : false; }
102
103 void setStatus(JobStatus stat) { status_ = stat; }
104 void setStatus(std::string stat) { status_ = ConvertStatus(stat); }
105 void setTime(std::string time) {
106 time_ = time;
107 has_time_ = true;
108 }
109 void setHost(std::string host) {
110 host_ = host;
111 has_host_ = true;
112 }
113 void setOutput(std::string output) {
114 output_ = tools::Property().add("output", output);
115 has_output_ = true;
116 }
117
118 const std::string &getHost() const {
119 assert(has_host_ && "Job has no host");
120 return host_;
121 }
122 const std::string &getTime() const {
123 assert(has_time_ && "Job has no time");
124 return time_;
125 }
126 const tools::Property &getOutput() const {
127 assert(has_output_ && "Job has no output");
128 return output_;
129 }
130 const std::string &getError() const {
131 assert(has_error_ && "Job has no error");
132 return error_;
133 }
134
135 private:
136 // Defined by user
138 std::string tag_;
142
143 // Generated during runtime
144 std::string host_;
145 bool has_host_ = false;
146 std::string time_;
147 bool has_time_ = false;
149 bool has_error_ = false;
150 bool has_output_ = false;
151 std::string error_;
152}; // namespace xtp
153
154std::vector<Job> LOAD_JOBS(const std::string &xml_file);
155void WRITE_JOBS(const std::vector<Job> &jobs, const std::string &job_file);
156void UPDATE_JOBS(const std::vector<Job> &from, std::vector<Job> &to,
157 const std::string &thisHost);
158} // namespace xtp
159} // namespace votca
160
161#endif // VOTCA_XTP_JOB_H
class to manage program options with xml serialization functionality
Definition property.h:55
Property & add(const std::string &key, const std::string &value)
add a new property to structure
Definition property.cc:108
Property & get(const std::string &key)
get existing property
Definition property.cc:79
const std::string & getError() const
Definition job.h:65
std::string error_
Definition job.h:76
void setError(std::string error)
Definition job.h:67
tools::Property output_
Definition job.h:74
bool hasError() const
Definition job.h:64
bool hasOutput() const
Definition job.h:60
void setOutput(std::string output)
Definition job.h:50
const tools::Property & getOutput() const
Definition job.h:61
void setOutput(tools::Property &output)
Definition job.h:54
void setStatus(JobStatus stat)
Definition job.h:49
JobStatus getStatus() const
Definition job.h:59
tools::Property & getOutput()
Definition job.h:63
bool hasHost() const
Definition job.h:92
bool has_error_
Definition job.h:149
const tools::Property & getOutput() const
Definition job.h:126
void setStatus(JobStatus stat)
Definition job.h:103
void setOutput(std::string output)
Definition job.h:113
std::string tag_
Definition job.h:138
tools::Property & getInput()
Definition job.h:87
void ToStream(std::ofstream &ofs) const
Definition job.cc:121
const std::string & getError() const
Definition job.h:130
bool has_time_
Definition job.h:147
void setHost(std::string host)
Definition job.h:109
void setStatus(std::string stat)
Definition job.h:104
const std::string & getTime() const
Definition job.h:122
const std::string & getHost() const
Definition job.h:118
void Reset()
Definition job.cc:113
std::string getStatusStr() const
Definition job.h:90
bool isFresh() const
Definition job.h:101
std::string error_
Definition job.h:151
bool isAvailable() const
Definition job.h:97
tools::Property output_
Definition job.h:148
tools::Property input_
Definition job.h:141
Job(const tools::Property &prop)
Definition job.cc:35
bool isAssigned() const
Definition job.h:98
std::string time_
Definition job.h:146
bool has_host_
Definition job.h:145
bool hasTime() const
Definition job.h:93
void setTime(std::string time)
Definition job.h:105
bool isComplete() const
Definition job.h:100
Index attemptsCount_
Definition job.h:140
void UpdateFrom(const Job &ext)
Definition job.cc:149
bool hasOutput() const
Definition job.h:94
Index id_
Definition job.h:137
const JobStatus & getStatus() const
Definition job.h:89
std::string getTag() const
Definition job.h:86
bool hasError() const
Definition job.h:95
JobStatus status_
Definition job.h:139
bool isFailed() const
Definition job.h:99
std::string ConvertStatus(JobStatus) const
Definition job.cc:75
const tools::Property & getInput() const
Definition job.h:88
Index getId() const
Definition job.h:85
void UpdateFromResult(const JobResult &res)
Definition job.cc:170
bool has_output_
Definition job.h:150
std::string host_
Definition job.h:144
void WRITE_JOBS(const std::vector< Job > &jobs, const std::string &job_file)
Definition job.cc:199
void UPDATE_JOBS(const std::vector< Job > &from, std::vector< Job > &to, const std::string &thisHost)
Definition job.cc:215
std::vector< Job > LOAD_JOBS(const std::string &xml_file)
Definition job.cc:184
base class for all analysis tools
Definition basebead.h:33
Eigen::Index Index
Definition types.h:26