Adding warning print in case the tuner cannot be loaded
[satune.git] / src / Tuner / searchtuner.cc
index 674758e2580ff1ac1e454a25228dc9f1f8ceabff..9eff9763ba5301eb1e02e21d2a3592d2973a2873 100644 (file)
@@ -95,9 +95,49 @@ SearchTuner::SearchTuner(const char *filename) {
                                setting = new TunableSetting(param);
                        }
                        setting->setDecision(lowValue, highValue, defaultValue, selectedValue);
+                       settings.add(setting);
                        usedSettings.add(setting);
                }
                myfile.close();
+       } else{
+               model_print("Warning: Tuner couldn't be loaded ... Using default tuner instead ....\n");
+       }
+}
+
+void SearchTuner::addUsed(const char *filename) {
+       ifstream myfile;
+       myfile.open (filename, ios::in);
+       if (myfile.is_open()) {
+               bool hasVar;
+               VarType type1;
+               VarType type2;
+               TunableParam param;
+               int lowValue;
+               int highValue;
+               int defaultValue;
+               int selectedValue;
+               while (myfile >> hasVar >> type1 >> type2 >> param >> lowValue >> highValue >> defaultValue >> selectedValue) {
+                       TunableSetting *setting;
+
+                       if (hasVar) {
+                               setting = new TunableSetting(type1, type2, param);
+                       } else {
+                               setting = new TunableSetting(param);
+                       }
+                       setting->setDecision(lowValue, highValue, defaultValue, selectedValue);
+                       if (!settings.contains(setting)) {
+                               settings.add(setting);
+                               usedSettings.add(setting);
+                       } else {
+                               TunableSetting *tmp = settings.get(setting);
+                               settings.remove(tmp);
+                               usedSettings.remove(tmp);
+                               delete tmp;
+                               settings.add(setting);
+                               usedSettings.add(setting);
+                       }
+               }
+               myfile.close();
        }
 }
 
@@ -122,6 +162,24 @@ SearchTuner::~SearchTuner() {
        delete iterator;
 }
 
+void SearchTuner::setTunable(TunableParam param, TunableDesc *descriptor, uint value) {
+       TunableSetting *result = new TunableSetting(param);
+       result->setDecision(descriptor->lowValue, descriptor->highValue, descriptor->defaultValue, value);
+       settings.add(result);
+       usedSettings.add(result);
+}
+
+void SearchTuner::setVarTunable(VarType vartype, TunableParam param, TunableDesc *descriptor, uint value) {
+       setVarTunable(vartype, 0, param, descriptor, value);
+}
+
+void SearchTuner::setVarTunable(VarType vartype1, VarType vartype2, TunableParam param, TunableDesc *descriptor, uint value) {
+       TunableSetting *result = new TunableSetting(vartype1, vartype2, param);
+       result->setDecision(descriptor->lowValue, descriptor->highValue, descriptor->defaultValue, value);
+       settings.add(result);
+       usedSettings.add(result);
+}
+
 int SearchTuner::getTunable(TunableParam param, TunableDesc *descriptor) {
        TunableSetting setting(param);
        TunableSetting *result = usedSettings.get(&setting);
@@ -194,6 +252,18 @@ void SearchTuner::serialize(const char *filename) {
        delete iterator;
 }
 
+void SearchTuner::serializeUsed(const char *filename) {
+       ofstream myfile;
+       myfile.open (filename, ios::out | ios::trunc);
+       SetIteratorTunableSetting *iterator = usedSettings.iterator();
+       while (iterator->hasNext()) {
+               TunableSetting *setting = iterator->next();
+               myfile << *setting << endl;
+       }
+       myfile.close();
+       delete iterator;
+}
+
 void SearchTuner::printUsed() {
        SetIteratorTunableSetting *iterator = usedSettings.iterator();
        while (iterator->hasNext()) {