[295] | 1 | #include "abstractSoftware.h" |
---|
[305] | 2 | #include "dataManager.h" |
---|
[419] | 3 | #include <algorithm> |
---|
[442] | 4 | #include <iostream> |
---|
[431] | 5 | |
---|
[442] | 6 | |
---|
[295] | 7 | abstractSoftware::abstractSoftware() |
---|
| 8 | { |
---|
[316] | 9 | globParamPtr_ = NULL; |
---|
[431] | 10 | sectParamPtr_ = NULL; //xx |
---|
[316] | 11 | dataManager_ = NULL; |
---|
[386] | 12 | nameOfSoftware_ = nomDeLogiciel("unknownSoftware"); |
---|
[295] | 13 | } |
---|
| 14 | |
---|
[431] | 15 | abstractSoftware::abstractSoftware(string inputFileName, globalParameters* globals, dataManager* dt) |
---|
| 16 | { |
---|
[316] | 17 | inputFileName_ = inputFileName; |
---|
[295] | 18 | globParamPtr_ = globals; |
---|
[431] | 19 | sectParamPtr_ = NULL; //xx |
---|
[305] | 20 | dataManager_ = dt; |
---|
[386] | 21 | numeroDeb_ = 0; |
---|
| 22 | numeroFin_ = 0; |
---|
| 23 | nameOfSoftware_ = nomDeLogiciel("unknownSoftware"); |
---|
[295] | 24 | } |
---|
| 25 | |
---|
[431] | 26 | abstractSoftware::abstractSoftware(string inputFileName,sectorParameters* lattice,dataManager* dt) |
---|
| 27 | { |
---|
| 28 | inputFileName_ = inputFileName; |
---|
| 29 | globParamPtr_ = NULL; |
---|
| 30 | sectParamPtr_ = lattice; |
---|
| 31 | dataManager_ = dt; |
---|
| 32 | numeroDeb_ = 0; |
---|
| 33 | numeroFin_ = 0; |
---|
| 34 | nameOfSoftware_ = nomDeLogiciel("unknownSoftware"); |
---|
| 35 | } |
---|
| 36 | |
---|
| 37 | bool abstractSoftware::initComputationLimits(unsigned int numeroDeb,unsigned int numeroFin) |
---|
| 38 | { |
---|
[386] | 39 | numeroDeb_ = numeroDeb; |
---|
| 40 | numeroFin_ = numeroFin; |
---|
| 41 | return ComputationLimitsOk(); |
---|
| 42 | } |
---|
[295] | 43 | |
---|
[431] | 44 | bool abstractSoftware::ComputationLimitsOk() const |
---|
| 45 | { |
---|
| 46 | if (numeroDeb_ < 1 || numeroFin_ < 1 || numeroDeb_ > dataManager_->getBeamLineSize() || numeroFin_ > dataManager_->getBeamLineSize() ) { |
---|
| 47 | dataManager_->consoleMessage(" abstractSoftware::initComputationLimit : num of element out of limits in software " + getName() ); |
---|
[386] | 48 | return false; |
---|
| 49 | } else { |
---|
| 50 | return true; |
---|
| 51 | } |
---|
| 52 | } |
---|
| 53 | |
---|
[431] | 54 | void abstractSoftware::registerElement(nomdElements::typedElement nomdel,trivaluedBool b) |
---|
| 55 | { |
---|
[442] | 56 | // std::cout << " abstractSoftware::registerElement soft : " << nameOfSoftware_.getString() << std::endl; |
---|
[418] | 57 | if (b == TBoolIgnore) { |
---|
[442] | 58 | // std::cout << " abstractSoftware::registerElement j'enregistre element " << nomdel << " ignore " << std::endl; |
---|
[418] | 59 | ignoredElements_.push_back(nomdel); |
---|
| 60 | } else if (b == TBoolOk) { |
---|
[442] | 61 | // std::cout << " abstractSoftware::registerElement j'enregistre element " << nomdel << " OK " << std::endl; |
---|
[418] | 62 | acceptedElements_.push_back(nomdel); |
---|
| 63 | } |
---|
| 64 | } |
---|
| 65 | |
---|
[431] | 66 | trivaluedBool abstractSoftware::doAcceptElement(nomdElements::typedElement typdel) |
---|
| 67 | { |
---|
| 68 | |
---|
| 69 | //xx |
---|
| 70 | if (acceptedElements_.size() == 0 && nameOfSoftware_ != nomDeLogiciel::unknownSoftware) { |
---|
[418] | 71 | return TBoolError; |
---|
| 72 | } |
---|
[431] | 73 | |
---|
| 74 | if (std::find(acceptedElements_.begin(),acceptedElements_.end(),typdel) != acceptedElements_.end()) { |
---|
[418] | 75 | return TBoolOk; |
---|
| 76 | } |
---|
[431] | 77 | |
---|
[418] | 78 | if (ignoredElements_.size() == 0) { |
---|
| 79 | return TBoolError; |
---|
| 80 | } |
---|
[431] | 81 | |
---|
| 82 | if (std::find(ignoredElements_.begin(),ignoredElements_.end(),typdel) != ignoredElements_.end()) { |
---|
[418] | 83 | return TBoolIgnore; |
---|
| 84 | } |
---|
[431] | 85 | |
---|
[418] | 86 | return TBoolOk; |
---|
| 87 | } |
---|
| 88 | |
---|
[295] | 89 | bool abstractSoftware::launchJob(string commandLine, string& resul) |
---|
| 90 | { |
---|
| 91 | bool ExecuteStatus = true; |
---|
[342] | 92 | |
---|
[295] | 93 | FILE* pp = popen(commandLine.c_str(), "r"); |
---|
[342] | 94 | ostringstream sortie; |
---|
[295] | 95 | if (pp == NULL) { |
---|
[431] | 96 | sortie << " launching failed : " << commandLine << endl; |
---|
[295] | 97 | ExecuteStatus = false; |
---|
[342] | 98 | } else { |
---|
[295] | 99 | // on copie la sortie dans le fichier assigne |
---|
| 100 | char buf[132]; |
---|
| 101 | while (fgets(buf, sizeof buf, pp)) |
---|
| 102 | { |
---|
| 103 | sortie << buf; |
---|
| 104 | } |
---|
| 105 | pclose(pp); |
---|
| 106 | } |
---|
| 107 | resul = sortie.str(); |
---|
| 108 | return ExecuteStatus; |
---|
| 109 | } |
---|