source: PSPA/Interface_Web/tags/v0.5/sources/controler/src/abstractSoftware.cc @ 456

Last change on this file since 456 was 456, checked in by garnier, 11 years ago

ajout de include algorithm

File size: 2.3 KB
Line 
1#include "abstractSoftware.h"
2#include "dataManager.h"
3#include <algorithm>
4
5abstractSoftware::abstractSoftware()
6{
7  globParamPtr_ = NULL;
8  dataManager_ = NULL;
9  nameOfSoftware_ = nomDeLogiciel("unknownSoftware");
10}
11
12abstractSoftware::abstractSoftware(string inputFileName, globalParameters* globals, dataManager* dt) {
13  inputFileName_ = inputFileName;
14  globParamPtr_ = globals;
15  dataManager_ = dt;
16  numeroDeb_ = 0;
17  numeroFin_ = 0;
18  nameOfSoftware_ = nomDeLogiciel("unknownSoftware");
19}
20
21bool abstractSoftware::initComputationLimits(unsigned int numeroDeb,unsigned int numeroFin) {
22  numeroDeb_ = numeroDeb;
23  numeroFin_ = numeroFin;
24  return ComputationLimitsOk();
25}
26
27bool abstractSoftware::ComputationLimitsOk() const {
28  if (   numeroDeb_ < 1 ||  numeroFin_ < 1 || numeroDeb_ > dataManager_->getBeamLineSize() || numeroFin_ > dataManager_->getBeamLineSize() ) {
29  dataManager_->consoleMessage(" abstractSoftware::initComputationLimit : numero of element out of limits in software " + getName() );
30    return false;
31  } else {
32    return true;
33  }
34}
35
36
37void abstractSoftware::registerElement(nomdElements::typedElement nomdel,trivaluedBool b) {
38  if (b == TBoolIgnore) {
39    ignoredElements_.push_back(nomdel);
40  } else if (b == TBoolOk) {
41    acceptedElements_.push_back(nomdel);
42  }
43}
44
45trivaluedBool abstractSoftware::doAcceptElement(nomdElements::typedElement typdel) {
46  if (acceptedElements_.size() == 0) {
47    return TBoolError;
48  }
49  if ( std::find(acceptedElements_.begin(), acceptedElements_.end(), typdel) != acceptedElements_.end()) {
50    return TBoolOk;
51  }
52  if (ignoredElements_.size() == 0) {
53    return TBoolError;
54  }
55  if ( std::find(ignoredElements_.begin(), ignoredElements_.end(), typdel) != ignoredElements_.end()) {
56    return TBoolIgnore;
57  }
58  return TBoolOk;
59}
60
61
62bool abstractSoftware::launchJob(string commandLine, string& resul)
63{
64  bool ExecuteStatus = true;
65
66  FILE* pp = popen(commandLine.c_str(), "r");
67  ostringstream sortie;
68  if (pp == NULL) {
69    sortie << " launching  failed : " << commandLine << endl;
70    ExecuteStatus = false;
71  } else {
72    cout << " executing command :  "  << commandLine << endl;
73    // on copie la sortie dans le fichier assigne
74    char buf[132];
75    while (fgets(buf, sizeof buf, pp))
76      {
77        sortie << buf;
78      }
79    pclose(pp);
80  }
81  resul =  sortie.str();
82  return ExecuteStatus;
83}
Note: See TracBrowser for help on using the repository browser.