Commit ab842a737cef35b8423a67b5742b388c73d83e57
1 parent
4de2b52c
Exists in
master
and in
89 other branches
Optimize ttcat_to_param process
Showing
1 changed file
with
19 additions
and
4 deletions
Show diff stats
src/ExternLib/ttcat_to_param/TTCatToParam.hh
@@ -19,6 +19,10 @@ | @@ -19,6 +19,10 @@ | ||
19 | namespace AMDA { | 19 | namespace AMDA { |
20 | namespace Parameters { | 20 | namespace Parameters { |
21 | 21 | ||
22 | +bool compareInterval(TimeTableCatalog::TimeInterval i1, TimeTableCatalog::TimeInterval i2) { | ||
23 | + return (i1._startTime < i2._startTime); | ||
24 | +} | ||
25 | + | ||
22 | /** | 26 | /** |
23 | * @class TTCatToParam | 27 | * @class TTCatToParam |
24 | * @brief Convert a time table or a catalog to a parameter. | 28 | * @brief Convert a time table or a catalog to a parameter. |
@@ -35,6 +39,8 @@ public: | @@ -35,6 +39,8 @@ public: | ||
35 | _paramOutput(new ParamDataScalaireDouble()), | 39 | _paramOutput(new ParamDataScalaireDouble()), |
36 | _intervals(intervals), _paramName(paramName), _paramComp(paramComp) { | 40 | _intervals(intervals), _paramName(paramName), _paramComp(paramComp) { |
37 | _paramDataOutput=_paramOutput; | 41 | _paramDataOutput=_paramOutput; |
42 | + std::sort(_intervals.begin(), _intervals.end(), compareInterval); | ||
43 | + _crtIt = _intervals.begin(); | ||
38 | } | 44 | } |
39 | 45 | ||
40 | /** | 46 | /** |
@@ -45,15 +51,23 @@ public: | @@ -45,15 +51,23 @@ public: | ||
45 | for (unsigned int index = pParamDataIndexInfo._startIndex; | 51 | for (unsigned int index = pParamDataIndexInfo._startIndex; |
46 | index< pParamDataIndexInfo._startIndex + pParamDataIndexInfo._nbDataToProcess; index++) { | 52 | index< pParamDataIndexInfo._startIndex + pParamDataIndexInfo._nbDataToProcess; index++) { |
47 | double crtTime = _paramInput.getTime(index); | 53 | double crtTime = _paramInput.getTime(index); |
48 | - _paramOutput->getDataList().push_back(getValue(crtTime)); | ||
49 | - _paramOutput->pushTime(crtTime); | 54 | + double value = getValue(crtTime); |
55 | + if (!isNAN(value)) { | ||
56 | + _paramOutput->getDataList().push_back(getValue(crtTime)); | ||
57 | + _paramOutput->pushTime(crtTime); | ||
58 | + } | ||
50 | } | 59 | } |
51 | } | 60 | } |
52 | 61 | ||
53 | double getValue(double time) { | 62 | double getValue(double time) { |
54 | - for(std::vector<TimeTableCatalog::TimeInterval>::iterator it = _intervals.begin(); it != _intervals.end(); ++it) { | ||
55 | - if ((time < it->_startTime) || (time > it->_stopTime)) | 63 | + for(std::vector<TimeTableCatalog::TimeInterval>::iterator it = _crtIt; it != _intervals.end(); ++it) { |
64 | + _crtIt = it; | ||
65 | + if (time < it->_startTime) { | ||
66 | + return NAN; | ||
67 | + } | ||
68 | + else if (time > it->_stopTime) { | ||
56 | continue; | 69 | continue; |
70 | + } | ||
57 | if (_paramName.empty()) { | 71 | if (_paramName.empty()) { |
58 | return 1.; | 72 | return 1.; |
59 | } | 73 | } |
@@ -80,6 +94,7 @@ public: | @@ -80,6 +94,7 @@ public: | ||
80 | std::vector<TimeTableCatalog::TimeInterval> _intervals; | 94 | std::vector<TimeTableCatalog::TimeInterval> _intervals; |
81 | std::string _paramName; | 95 | std::string _paramName; |
82 | int _paramComp; | 96 | int _paramComp; |
97 | + std::vector<TimeTableCatalog::TimeInterval>::iterator _crtIt; | ||
83 | }; | 98 | }; |
84 | 99 | ||
85 | } /* namespace Parameters */ | 100 | } /* namespace Parameters */ |