1 | #include "abstractSoftware.h" |
---|
2 | #include "dataManager.h" |
---|
3 | #include <algorithm> |
---|
4 | #include <iostream> |
---|
5 | |
---|
6 | |
---|
7 | abstractSoftware::abstractSoftware() |
---|
8 | { |
---|
9 | globParamPtr_ = NULL; |
---|
10 | sectParamPtr_ = NULL; //xx |
---|
11 | dataManager_ = NULL; |
---|
12 | nameOfSoftware_ = nomDeLogiciel("unknownSoftware"); |
---|
13 | } |
---|
14 | |
---|
15 | abstractSoftware::abstractSoftware(string inputFileName, globalParameters* globals, dataManager* dt) |
---|
16 | { |
---|
17 | inputFileName_ = inputFileName; |
---|
18 | globParamPtr_ = globals; |
---|
19 | sectParamPtr_ = NULL; //xx |
---|
20 | dataManager_ = dt; |
---|
21 | numeroDeb_ = 0; |
---|
22 | numeroFin_ = 0; |
---|
23 | nameOfSoftware_ = nomDeLogiciel("unknownSoftware"); |
---|
24 | } |
---|
25 | |
---|
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 | { |
---|
39 | numeroDeb_ = numeroDeb; |
---|
40 | numeroFin_ = numeroFin; |
---|
41 | return ComputationLimitsOk(); |
---|
42 | } |
---|
43 | |
---|
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() ); |
---|
48 | return false; |
---|
49 | } else { |
---|
50 | return true; |
---|
51 | } |
---|
52 | } |
---|
53 | |
---|
54 | void abstractSoftware::registerElement(nomdElements::typedElement nomdel,trivaluedBool b) |
---|
55 | { |
---|
56 | // std::cout << " abstractSoftware::registerElement soft : " << nameOfSoftware_.getString() << std::endl; |
---|
57 | if (b == TBoolIgnore) { |
---|
58 | // std::cout << " abstractSoftware::registerElement j'enregistre element " << nomdel << " ignore " << std::endl; |
---|
59 | ignoredElements_.push_back(nomdel); |
---|
60 | } else if (b == TBoolOk) { |
---|
61 | // std::cout << " abstractSoftware::registerElement j'enregistre element " << nomdel << " OK " << std::endl; |
---|
62 | acceptedElements_.push_back(nomdel); |
---|
63 | } |
---|
64 | } |
---|
65 | |
---|
66 | trivaluedBool abstractSoftware::doAcceptElement(nomdElements::typedElement typdel) |
---|
67 | { |
---|
68 | |
---|
69 | //xx |
---|
70 | if (acceptedElements_.size() == 0 && nameOfSoftware_ != nomDeLogiciel::unknownSoftware) { |
---|
71 | return TBoolError; |
---|
72 | } |
---|
73 | |
---|
74 | if (std::find(acceptedElements_.begin(),acceptedElements_.end(),typdel) != acceptedElements_.end()) { |
---|
75 | return TBoolOk; |
---|
76 | } |
---|
77 | |
---|
78 | if (ignoredElements_.size() == 0) { |
---|
79 | return TBoolError; |
---|
80 | } |
---|
81 | |
---|
82 | if (std::find(ignoredElements_.begin(),ignoredElements_.end(),typdel) != ignoredElements_.end()) { |
---|
83 | return TBoolIgnore; |
---|
84 | } |
---|
85 | |
---|
86 | return TBoolOk; |
---|
87 | } |
---|
88 | |
---|
89 | bool abstractSoftware::launchJob(string commandLine, string& resul) |
---|
90 | { |
---|
91 | bool ExecuteStatus = true; |
---|
92 | |
---|
93 | FILE* pp = popen(commandLine.c_str(), "r"); |
---|
94 | ostringstream sortie; |
---|
95 | if (pp == NULL) { |
---|
96 | sortie << " launching failed : " << commandLine << endl; |
---|
97 | ExecuteStatus = false; |
---|
98 | } else { |
---|
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 | } |
---|