Salome HOME
merge from V4_1_0_maintainance branch (from tag mergeto_BR_QT4_Dev2_29Jul08)
[modules/kernel.git] / src / Batch / Batch_JobInfo_eLSF.cxx
1 // Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
3 // 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either 
7 // version 2.1 of the License.
8 // 
9 // This library is distributed in the hope that it will be useful 
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
12 // Lesser General Public License for more details.
13 //
14 // You should have received a copy of the GNU Lesser General Public  
15 // License along with this library; if not, write to the Free Software 
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 //
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 //
20 /*
21  * JobInfo_eLSF.cxx :  emulation of LSF client
22  *
23  * Auteur : Bernard SECHER - CEA DEN
24  * Mail   : mailto:bernard.secher@cea.fr
25  * Date   : Thu Apr 24 10:17:22 2008
26  * Projet : PAL Salome 
27  *
28  */
29
30 #include <cstdio>
31 #include <iostream>
32 #include <fstream>
33 #include <sstream>
34 #include "Batch_Parametre.hxx"
35 #include "Batch_Environnement.hxx"
36 #include "Batch_RunTimeException.hxx"
37 #include "Batch_APIInternalFailureException.hxx"
38 #include "Batch_JobInfo_eLSF.hxx"
39
40 namespace Batch {
41
42
43
44   // Constructeurs
45   JobInfo_eLSF::JobInfo_eLSF(int id, string logFile) : JobInfo()
46   {
47     // On remplit les membres _param et _env
48     ostringstream oss;
49     oss << id;
50     _param[ID] = oss.str();
51
52     // read status of job in log file
53     char line[128];
54     ifstream fp(logFile.c_str(),ios::in);
55     fp.getline(line,80,'\n');
56     
57     string sjobid, username, status;
58     fp >> sjobid;
59     fp >> username;
60     fp >> status;
61
62     _param[STATE] = status;
63
64     if( status.find("RUN") != string::npos)
65       _running = true;
66
67   }
68
69   // Teste si un job est present en machine
70   bool JobInfo_eLSF::isRunning() const
71   {
72     return _running;
73   }
74
75
76   // Destructeur
77   JobInfo_eLSF::~JobInfo_eLSF()
78   {
79     // Nothing to do
80   }
81
82   // Convertit une date HH:MM:SS en secondes
83   long JobInfo_eLSF::HMStoLong(const string & s)
84   {
85     long hour, min, sec;
86
87     sscanf( s.c_str(), "%ld:%ld:%ld", &hour, &min, &sec);
88     return ( ( ( hour * 60L ) + min ) * 60L ) + sec;
89   }
90
91   // Methode pour l'interfacage avec Python (SWIG) : affichage en Python
92   string JobInfo_eLSF::__str__() const
93   {
94     ostringstream sst;
95     sst << "<JobInfo_eLSF (" << this << ") :" << endl;
96     sst << " ID = " <<_param[ID] << endl;
97     sst << " STATE = " <<_param[STATE] << endl;
98
99     return sst.str();
100   }
101
102
103 }