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