BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
JobWorker Class Reference

Description

The JobWorker class provides running the domain simulation in a thread.

Definition at line 28 of file JobWorker.h.

Inheritance diagram for JobWorker:
[legend]
Collaboration diagram for JobWorker:
[legend]

Public Slots

void start ()
 
void terminate ()
 Sets request for JobRunner to terminate underlying domain simulation. More...
 

Signals

void finished ()
 
void progressUpdate ()
 
void started ()
 

Public Member Functions

 JobWorker (QString identifier, ISimulation *simulation)
 
 ~JobWorker ()
 
QString failureMessage () const
 
QString identifier () const
 
int progress () const
 
const SimulationResult * result () const
 
const QDateTime & simulationEnd () const
 
const QDateTime & simulationStart () const
 
JobStatus status () const
 

Private Member Functions

bool updateProgress (int percentage_done)
 Sets current progress. Returns true if we want to continue the simulation. More...
 

Private Attributes

QString m_failure_message
 
QString m_identifier
 
JobStatus m_job_status
 
int m_percentage_done
 
std::unique_ptr< const SimulationResult > m_result
 
ISimulation * m_simulation
 
QDateTime m_simulation_end
 
QDateTime m_simulation_start
 
bool m_terminate_request_flag
 

Constructor & Destructor Documentation

◆ JobWorker()

JobWorker::JobWorker ( QString  identifier,
ISimulation *  simulation 
)

Definition at line 22 of file JobWorker.cpp.

23  : m_identifier(std::move(identifier))
24  , m_simulation(simulation)
28 {
29 }
@ Idle
the job has not been started yet
int m_percentage_done
Definition: JobWorker.h:61
QString identifier() const
Definition: JobWorker.cpp:33
bool m_terminate_request_flag
Definition: JobWorker.h:63
QString m_identifier
Definition: JobWorker.h:59
JobStatus m_job_status
Definition: JobWorker.h:62
ISimulation * m_simulation
Definition: JobWorker.h:60

References Idle.

◆ ~JobWorker()

JobWorker::~JobWorker ( )
default

Member Function Documentation

◆ failureMessage()

QString JobWorker::failureMessage ( ) const

Definition at line 87 of file JobWorker.cpp.

88 {
89  return m_failure_message;
90 }
QString m_failure_message
Definition: JobWorker.h:64

References m_failure_message.

Referenced by JobQueueData::processFinishedJob().

◆ finished

void JobWorker::finished ( )
signal

Referenced by JobQueueData::runJob(), and start().

◆ identifier()

QString JobWorker::identifier ( ) const

Definition at line 33 of file JobWorker.cpp.

34 {
35  return m_identifier;
36 }

References m_identifier.

◆ progress()

int JobWorker::progress ( ) const

Definition at line 38 of file JobWorker.cpp.

39 {
40  return m_percentage_done;
41 }

References m_percentage_done.

◆ progressUpdate

void JobWorker::progressUpdate ( )
signal

◆ result()

const SimulationResult * JobWorker::result ( ) const

Definition at line 102 of file JobWorker.cpp.

103 {
104  return m_result.get();
105 }
std::unique_ptr< const SimulationResult > m_result
Definition: JobWorker.h:67

References m_result.

Referenced by JobQueueData::processFinishedJob(), and start().

◆ simulationEnd()

const QDateTime & JobWorker::simulationEnd ( ) const

Definition at line 97 of file JobWorker.cpp.

98 {
99  return m_simulation_end;
100 }
QDateTime m_simulation_end
Definition: JobWorker.h:66

References m_simulation_end.

Referenced by JobQueueData::processFinishedJob().

◆ simulationStart()

const QDateTime & JobWorker::simulationStart ( ) const

Definition at line 92 of file JobWorker.cpp.

93 {
94  return m_simulation_start;
95 }
QDateTime m_simulation_start
Definition: JobWorker.h:65

References m_simulation_start.

◆ start

void JobWorker::start ( )
slot

Definition at line 43 of file JobWorker.cpp.

44 {
46  m_simulation_start = QDateTime::currentDateTime();
47  m_simulation_end = QDateTime();
48  m_result.release();
49  emit started();
50 
51  if (m_simulation) {
52  m_simulation->subscribe([this](size_t percentage_done) {
53  return updateProgress(static_cast<int>(percentage_done));
54  });
55 
57 
58  try {
59  SimulationResult result = m_simulation->simulate();
62  m_result = std::make_unique<SimulationResult>(std::move(result));
63  } catch (const std::exception& ex) {
65  m_percentage_done = 100;
67  "JobRunner::start() -> ISimulation failed with exception throw:\n\n";
68 
69  m_failure_message.append(QString(ex.what()));
70  }
71  } else {
73  m_percentage_done = 100;
74  m_failure_message = "JobRunner::start() -> Error. ISimulation doesn't exist.";
75  }
76 
77  m_simulation_end = QDateTime::currentDateTime();
78  emit progressUpdate();
79  emit finished();
80 }
@ Completed
the job was successfully completed
@ Canceled
the job was stopped by the user
@ Running
the job is busy calculating
@ Failed
the job aborted because it hit an error
bool updateProgress(int percentage_done)
Sets current progress. Returns true if we want to continue the simulation.
Definition: JobWorker.cpp:117
void progressUpdate()
const SimulationResult * result() const
Definition: JobWorker.cpp:102
void finished()
void started()

References Canceled, Completed, Failed, finished(), m_failure_message, m_job_status, m_percentage_done, m_result, m_simulation, m_simulation_end, m_simulation_start, m_terminate_request_flag, progressUpdate(), result(), Running, started(), and updateProgress().

Referenced by JobQueueData::runJob().

Here is the call graph for this function:

◆ started

void JobWorker::started ( )
signal

Referenced by JobQueueData::runJob(), and start().

◆ status()

JobStatus JobWorker::status ( ) const

Definition at line 82 of file JobWorker.cpp.

83 {
84  return m_job_status;
85 }

References m_job_status.

Referenced by JobQueueData::processFinishedJob().

◆ terminate

void JobWorker::terminate ( )
slot

Sets request for JobRunner to terminate underlying domain simulation.

Definition at line 109 of file JobWorker.cpp.

110 {
113 }

References Canceled, m_job_status, and m_terminate_request_flag.

Referenced by JobQueueData::cancelJob().

◆ updateProgress()

bool JobWorker::updateProgress ( int  percentage_done)
private

Sets current progress. Returns true if we want to continue the simulation.

Definition at line 117 of file JobWorker.cpp.

118 {
119  if (percentage_done > m_percentage_done) {
120  m_percentage_done = percentage_done;
121  emit progressUpdate();
122  }
123  return !m_terminate_request_flag;
124 }

References m_percentage_done, m_terminate_request_flag, and progressUpdate().

Referenced by start().

Member Data Documentation

◆ m_failure_message

QString JobWorker::m_failure_message
private

Definition at line 64 of file JobWorker.h.

Referenced by failureMessage(), and start().

◆ m_identifier

QString JobWorker::m_identifier
private

Definition at line 59 of file JobWorker.h.

Referenced by identifier().

◆ m_job_status

JobStatus JobWorker::m_job_status
private

Definition at line 62 of file JobWorker.h.

Referenced by start(), status(), and terminate().

◆ m_percentage_done

int JobWorker::m_percentage_done
private

Definition at line 61 of file JobWorker.h.

Referenced by progress(), start(), and updateProgress().

◆ m_result

std::unique_ptr<const SimulationResult> JobWorker::m_result
private

Definition at line 67 of file JobWorker.h.

Referenced by result(), and start().

◆ m_simulation

ISimulation* JobWorker::m_simulation
private

Definition at line 60 of file JobWorker.h.

Referenced by start().

◆ m_simulation_end

QDateTime JobWorker::m_simulation_end
private

Definition at line 66 of file JobWorker.h.

Referenced by simulationEnd(), and start().

◆ m_simulation_start

QDateTime JobWorker::m_simulation_start
private

Definition at line 65 of file JobWorker.h.

Referenced by simulationStart(), and start().

◆ m_terminate_request_flag

bool JobWorker::m_terminate_request_flag
private

Definition at line 63 of file JobWorker.h.

Referenced by start(), terminate(), and updateProgress().


The documentation for this class was generated from the following files: