Newer
Older
/**
* \file input/condorqxmlsaxhandler.cpp
* \date 15/9/2017
* \author Olivier Langella
* \brief parse condor_q XML
*/
/*******************************************************************************
* Copyright (c) 2017 Olivier Langella <Olivier.Langella@u-psud.fr>.
*
* This file is part of XTPcpp.
*
* XTPcpp is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* XTPcpp is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with XTPcpp. If not, see <http://www.gnu.org/licenses/>.
*
* Contributors:
* Olivier Langella <Olivier.Langella@u-psud.fr> - initial API and implementation
******************************************************************************/
#include "condorqxmlsaxhandler.h"
#include "../core/tandem_run/tandemcondorprocess.h"
#include <pappsomspp/pappsoexception.h>
CondorQxmlSaxHandler::CondorQxmlSaxHandler(TandemCondorProcess * tandem_condor_process) {
_is_empty = true;
_tandem_condor_process = tandem_condor_process;
}
CondorQxmlSaxHandler::~CondorQxmlSaxHandler() {
}
bool CondorQxmlSaxHandler::startElement(const QString & namespaceURI, const QString & localName,
const QString & qName, const QXmlAttributes & attributes) {
qDebug()<< "CondorQxmlSaxHandler::startElement begin" << namespaceURI << " " << localName << " " << qName ;
_tag_stack.push_back(qName);
bool is_ok = true;
try {
//startElement_group
if (qName == "c") {
is_ok = startElement_c(attributes);
} else if (qName == "a") {
is_ok = startElement_a(attributes);
_current_text.clear();
}
catch (pappso::PappsoException exception_pappso) {
_errorStr = QObject::tr("ERROR in CondorQxmlSaxHandler::startElement tag %1, PAPPSO exception:\n%2").arg(qName).arg(exception_pappso.qwhat());
return false;
}
catch (std::exception exception_std) {
_errorStr = QObject::tr("ERROR in CondorQxmlSaxHandler::startElement tag %1, std exception:\n%2").arg(qName).arg(exception_std.what());
return false;
}
return is_ok;
}
bool CondorQxmlSaxHandler::endElement(const QString & namespaceURI, const QString & localName,
bool is_ok = true;
// endElement_peptide_list
try {
is_ok = endElement_a();
}
else if (qName == "c") {
is_ok = endElement_c();
else if (qName == "i") {
is_ok = endElement_i();
else if (qName == "s") {
is_ok = endElement_s();
}
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
}
catch (pappso::PappsoException exception_pappso) {
_errorStr = QObject::tr("ERROR in CondorQxmlSaxHandler::endElement tag %1, PAPPSO exception:\n%2").arg(qName).arg(exception_pappso.qwhat());
return false;
}
catch (std::exception exception_std) {
_errorStr = QObject::tr("ERROR in CondorQxmlSaxHandler::endElement tag %1, std exception:\n%2").arg(qName).arg(exception_std.what());
return false;
}
_current_text.clear();
_tag_stack.pop_back();
return is_ok;
}
bool CondorQxmlSaxHandler::error(const QXmlParseException &exception) {
_errorStr = QObject::tr("Parse error at line %1, column %2 :\n"
"%3").arg(exception.lineNumber()).arg(exception.columnNumber()).arg(
exception.message());
return false;
}
bool CondorQxmlSaxHandler::fatalError(const QXmlParseException &exception) {
_errorStr = QObject::tr("Parse error at line %1, column %2 :\n"
"%3").arg(exception.lineNumber()).arg(exception.columnNumber()).arg(
exception.message());
return false;
}
QString CondorQxmlSaxHandler::errorString() const {
return _errorStr;
}
bool CondorQxmlSaxHandler::endDocument() {
unsigned int really_completed_jobs = 0;
if (_is_empty) {
really_completed_jobs = _tandem_condor_process->getCondorJobSize();
} else {
int total_jobs = 0;
for (std::int8_t i=0; i < 10; i++) {
total_jobs += _count_status[i];
}
int diff_jobs = _tandem_condor_process->getCondorJobSize()
- total_jobs;
really_completed_jobs = _count_status[(std::int8_t) CondorJobStatus::Completed] + diff_jobs;
}
_count_status[(std::int8_t) CondorJobStatus::Completed] = really_completed_jobs;
_tandem_condor_process->setCondorJobStatus(_count_status);
/*
xtandemCondorAnalysis.setJobCompleted(junexpanded, jidle, jrunning,
jremoved, reallyCompletedJobs, jheld, jsubmission_error);
*/
return true;
}
bool CondorQxmlSaxHandler::startDocument() {
for (std::int8_t i=0; i < 10; i++) {
_count_status[i] = 0;
}
_is_empty = true;
return true;
}
bool CondorQxmlSaxHandler::characters(const QString &str) {
_current_text += str;
return true;
}
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
bool CondorQxmlSaxHandler::startElement_c(QXmlAttributes attributes) {
// <c>
// <a n="ProcId"><i>0</i></a>
_condor_job_status = CondorJobStatus::Unexpanded;
_current_proc_id = 0;
_is_empty = false;
_current_remote_host = "";
_current_last_remote_host = "";
return true;
}
bool CondorQxmlSaxHandler::startElement_a(QXmlAttributes attributes) {
// logger.debug("startElementgroup begin");
// <group label="performance parameters" type="parameters">
_in_name = attributes.value("n");
return true;
}
bool CondorQxmlSaxHandler::endElement_a() {
_in_name = "";
return true;
}
bool CondorQxmlSaxHandler::endElement_i() {
if (_in_name == "ProcId") {
_current_proc_id = _current_text.toInt();
} else if (_in_name == "JobStatus") {
// <a n="JobStatus"><i>2</i></a>
_condor_job_status = static_cast<CondorJobStatus>(_current_text.toInt());
// logger.debug(currentProcId);
}
return true;
}
bool CondorQxmlSaxHandler::endElement_s() {
if (_in_name == "RemoteHost") {
// <a n="RemoteHost"><s>slot1@proteus3</s></a>
_current_remote_host = _current_text;
} else if ( _in_name == "LastRemoteHost") {
// <a n="LastRemoteHost"><s>slot1@proteus4</s></a>
_current_last_remote_host = _current_text;
}
return true;
}
bool CondorQxmlSaxHandler::endElement_c() {
/*
* 0 Unexpanded U 1 Idle I 2 Running R 3 Removed X 4 Completed C 5 Held
* H 6 Submission_err E
*/
_count_status[(std::int8_t) _condor_job_status] += 1;
qDebug() << "currentRemoteHost:" << _current_remote_host <<
" currentLastRemoteHost" << _current_last_remote_host << " "
<< (std::int8_t)_condor_job_status;
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
/*
package fr.inra.pappso.xtandempipeline.sax_parse;
import org.apache.log4j.Logger;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import fr.inra.pappso.xtandempipeline.MsException.MSMSException;
import fr.inra.pappso.xtandempipeline.thread.XtandemCondorAnalysis;
public class HandlerHTCondorQueue extends SaxBaseHandler {
private static final Logger logger = Logger
.getLogger(HandlerHTCondorQueue.class);
private Object inName;
private Integer currentProcId;
private Integer currentJobStatus;
private String currentRemoteHost;
private String currentLastRemoteHost;
private int junexpanded = 0;
private int jidle = 0;
private int jrunning = 0;
private int jremoved = 0;
private int jcompleted = 0;
private int jheld = 0;
private int jsubmission_error = 0;
private XtandemCondorAnalysis xtandemCondorAnalysis;
private boolean empty = true;
public HandlerHTCondorQueue(XtandemCondorAnalysis xtandemCondorAnalysis)
throws MSMSException {
super();
this.xtandemCondorAnalysis = xtandemCondorAnalysis;
}
@Override
public void startDocument() throws SAXException {
this.empty = true;
}
}
*/