/** * \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) { } 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 == "match") { is_ok = startElement_match(attributes); } else if (qName == "protein") { is_ok = startElement_protein(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, const QString & qName) { bool is_ok = true; // endElement_peptide_list try { /* if (qName == "protein") { is_ok = endElement_protein(); } else if (qName == "identification") { is_ok = endElement_identification(); } */ } 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() { //_p_project->getProteinStore().setRegexpDecoyPattern(_p_project->getProteinStore().getRegexpDecoy().pattern()); return true; } bool CondorQxmlSaxHandler::startDocument() { return true; } bool CondorQxmlSaxHandler::characters(const QString &str) { _current_text += str; return true; } /* 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; } @Override public void endDocument() throws SAXException { int reallyCompletedJobs = 0; if (this.empty) { reallyCompletedJobs = xtandemCondorAnalysis.getCondorJobNumber(); } else { int totalJobs = junexpanded + jidle + jrunning + jremoved + jcompleted + jheld + jsubmission_error; int diffJobs = xtandemCondorAnalysis.getCondorJobNumber() - totalJobs; reallyCompletedJobs = jcompleted + diffJobs; } xtandemCondorAnalysis.setJobCompleted(junexpanded, jidle, jrunning, jremoved, reallyCompletedJobs, jheld, jsubmission_error); String statusMessage = "" + junexpanded + " unexpanded jobs\n"; statusMessage += jidle + " idle jobs\n"; statusMessage += jrunning + " running jobs\n"; statusMessage += jremoved + " removed jobs\n"; statusMessage += reallyCompletedJobs + " completed jobs\n"; statusMessage += jheld + " held jobs\n"; statusMessage += jsubmission_error + " submission_errors\n"; logger.debug(statusMessage); xtandemCondorAnalysis.setStatusMessage(statusMessage); } // <c> // <a n="ProcId"><i>0</i></a> public void startElementc(String nameSpaceUri, Attributes attrs) { this.empty = false; currentProcId = null; currentJobStatus = null; currentRemoteHost = null; currentLastRemoteHost = null; } public void startElementa(String nameSpaceUri, Attributes attrs) { // logger.debug("startElementgroup begin"); // <group label="performance parameters" type="parameters"> this.inName = attrs.getValue("n"); } public void endElementi(String nameSpaceUri, String data) throws MSMSException { if (inName.equals("ProcId")) { this.currentProcId = new Integer(data); // logger.debug(currentProcId); } else if (inName.equals("JobStatus")) { // <a n="JobStatus"><i>2</i></a> this.currentJobStatus = new Integer(data); // logger.debug(currentProcId); } } public void endElements(String nameSpaceUri, String data) throws MSMSException { if (inName.equals("RemoteHost")) { // <a n="RemoteHost"><s>slot1@proteus3</s></a> this.currentRemoteHost = data; // logger.debug(currentProcId); } else if (inName.equals("LastRemoteHost")) { // <a n="LastRemoteHost"><s>slot1@proteus4</s></a> this.currentLastRemoteHost = data; // logger.debug(currentProcId); } } public void endElementa(String nameSpaceUri, String data) { this.inName = ""; } public void endElementc(String nameSpaceUri, String data) throws MSMSException { /* * 0 Unexpanded U 1 Idle I 2 Running R 3 Removed X 4 Completed C 5 Held * H 6 Submission_err E * if (currentJobStatus == 0) { this.junexpanded += 1; } else if (currentJobStatus == 1) { this.jidle += 1; } else if (currentJobStatus == 2) { this.jrunning += 1; } else if (currentJobStatus == 3) { this.jremoved += 1; } else if (currentJobStatus == 4) { this.jcompleted += 1; } else if (currentJobStatus == 5) { this.jheld += 1; } else if (currentJobStatus == 6) { this.jsubmission_error += 1; } logger.debug("currentRemoteHost:" + this.currentRemoteHost + " currentLastRemoteHost" + this.currentLastRemoteHost + " " + currentJobStatus); } } */