<commit_before>#include "ExecutionXmlReader.h"


#include <string>
using std::string;
#include <iostream>
using std::cout;
using std::endl;

ExecutionXmlReader::ExecutionXmlReader(const string& filename)
:executionPointer_(execution(filename)), runMode_(0) {
    
    readXml();
}

void ExecutionXmlReader::readXml() {

     try {
        ExecutionType::NMSmodel_type& myModel(executionPointer_->NMSmodel());
        ExecutionType::NMSmodel_type::activation_type& myActivation(myModel.activation());
        ExecutionType::NMSmodel_type::activation_type::exponential_optional& myExpOpt(myActivation.exponential());
        ExecutionType::NMSmodel_type::activation_type::piecewise_optional& myPWOpt(myActivation.piecewise());
 
        if(myExpOpt.present())
            runMode_ += NMSModelCfg::ExponentialActivation;
        else if(myPWOpt.present())
            runMode_ += NMSModelCfg::PiecewiseActivation;
        else {
            cout << "invalid XML: ActivationType not found\n";
            exit(EXIT_FAILURE);
        }
        
        ExecutionType::NMSmodel_type::tendon_type& myTendon(myModel.tendon());
        ExecutionType::NMSmodel_type::tendon_type::stiff_optional& myStiffOpt(myTendon.stiff());
        ExecutionType::NMSmodel_type::tendon_type::elastic_optional& myElsaticOpt(myTendon.elastic());
        ExecutionType::NMSmodel_type::tendon_type::elasticBiSec_optional& myElsaticBiSecOpt(myTendon.elasticBiSec());
        
        if(myStiffOpt.present())
            runMode_ += NMSModelCfg::StiffTendon;
        else if (myElsaticOpt.present())
            runMode_ += NMSModelCfg::ElasticTendon;
        else if (myElsaticBiSecOpt.present())
            runMode_ += NMSModelCfg::ElasticTendonBiSec;
        else {
            cout << "invalid XML: TendonType not found\n";
            exit(EXIT_FAILURE);
        }
            
        ExecutionType::NMSmodel_type::type_type& myType(myModel.type());
        ExecutionType::NMSmodel_type::type_type::hybrid_optional& myHybOpt(myType.hybrid());
        ExecutionType::NMSmodel_type::type_type::openLoop_optional& myOLOpt(myType.openLoop());
        if(myHybOpt.present())
            runMode_ += NMSModelCfg::Hybrid;
        else if(myOLOpt.present())
            runMode_ += NMSModelCfg::OpenLoop;
        else {
            cout << "invalid XML: Hybrid/OpenLoop Type not found\n";
            exit(EXIT_FAILURE);
        }
        
        ExecutionType::online_optional& myOnlineOpt(executionPointer_->online());
        ExecutionType::offline_optional& myOfflineOpt(executionPointer_->offline());
        if(myOnlineOpt.present())
            runMode_ += NMSModelCfg::Online;
        else if (myOfflineOpt.present())
            runMode_ += NMSModelCfg::Offline;
        else {
            cout << "invalid XML: Online/Offline Type not found\n";
            exit(EXIT_FAILURE);
        }
        
 
 //ANCORA DA IMPLEMENTARE
 /*       
        ExecutionType::samplingFrequency_optional& myFreqOpt(executionPointer->samplingFrequency());
        if(myFreqOpt.present())
            myExecutionCfg.frequency_ = ExecutionCfg::Enabled;
        else
            myExecutionCfg.frequency_ = ExecutionCfg::Disabled;
            
        ExecutionType::logging_type::txt_optional& myTxtOpt(executionPointer->logging().txt()); 
        ExecutionType::logging_type::csv_optional& myCsvOpt(executionPointer->logging().csv());
        ExecutionType::logging_type::mot_optional& myMotOpt(executionPointer->logging().mot());
        if(myTxtOpt.present())
            myExecutionCfg.logging_ = ExecutionCfg::txt;
        else if(myCsvOpt.present())
            myExecutionCfg.logging_ = ExecutionCfg::csv;
        else if(myMotOpt.present())
            myExecutionCfg.logging_ = ExecutionCfg::mot;
        else {
            cout << "invalid XML: Logging Type not found\n";
            exit(EXIT_FAILURE);
        }
*/        
    }  
    catch (const xml_schema::exception& e) {
        cout << e << endl;
        exit(EXIT_FAILURE);
    }
    
    
}


void ExecutionXmlReader::getMusclesToPredict(std::vector<std::string>& musclesToPredict) {
    
    ExecutionType::NMSmodel_type& myModel(executionPointer_->NMSmodel());
    ExecutionType::NMSmodel_type::type_type& myType(myModel.type());
    ExecutionType::NMSmodel_type::type_type::hybrid_optional& myHybOpt(myType.hybrid());
    if(!myHybOpt.present()) {
        cout << "Cannot get hybrid parameters, hybrid option not selected\n";
        exit(EXIT_FAILURE);
    }


    musclesToPredict.clear();
    HybridType::predictedMuscles_type& predictedMuscles(myType.hybrid()->predictedMuscles());
    for(unsigned mi = 0; mi < predictedMuscles.size(); ++mi)
        musclesToPredict.push_back(predictedMuscles.at(mi));
}


void ExecutionXmlReader::getMusclesToTrack(std::vector<std::string>& musclesToTrack) {
    
    ExecutionType::NMSmodel_type& myModel(executionPointer_->NMSmodel());
    ExecutionType::NMSmodel_type::type_type& myType(myModel.type());
    ExecutionType::NMSmodel_type::type_type::hybrid_optional& myHybOpt(myType.hybrid());
    if(!myHybOpt.present()) {
        cout << "Cannot get hybrid parameters, hybrid option not selected\n";
        exit(EXIT_FAILURE);
    }


    musclesToTrack.clear();
    HybridType::trackedMuscles_type& trackedMuscles(myType.hybrid()->trackedMuscles());
    for(unsigned mi = 0; mi < trackedMuscles.size(); ++mi)
        musclesToTrack.push_back(trackedMuscles.at(mi));
}

void ExecutionXmlReader::getHybridWeightings(double& alpha, double& beta, double& gamma) {

    ExecutionType::NMSmodel_type& myModel(executionPointer_->NMSmodel());
    ExecutionType::NMSmodel_type::type_type& myType(myModel.type());
    ExecutionType::NMSmodel_type::type_type::hybrid_optional& myHybOpt(myType.hybrid());
    if(!myHybOpt.present()) {
        cout << "Cannot get hybrid parameters, hybrid option not selected\n";
        exit(EXIT_FAILURE);
    }

    HybridType::alpha_type& myAlpha(myType.hybrid()->alpha());
    alpha = myAlpha;
    
    HybridType::beta_type& myBeta(myType.hybrid()->beta());
    beta = myBeta;

    HybridType::gamma_type& myGamma(myType.hybrid()->gamma());
    gamma = myGamma;
    
    
}



NMSModelCfg::RunMode ExecutionXmlReader::getRunMode() const {
    
    return static_cast<NMSModelCfg::RunMode>(runMode_);

}
<commit_msg>Add exception when reading execution.xml<commit_after>#include "ExecutionXmlReader.h"


#include <string>
using std::string;
#include <iostream>
using std::cout;
using std::endl;

ExecutionXmlReader::ExecutionXmlReader(const string& filename)
:executionPointer_(execution(filename)), runMode_(0) {
    
    try {
        std::auto_ptr<ExecutionType> executionPointer(execution(filename));
        executionPointer_ = executionPointer;
    }  
    catch (const xml_schema::exception& e) {
        cout << e << endl;
        exit(EXIT_FAILURE);
    }
    readXml();
}

void ExecutionXmlReader::readXml() {

     try {
        ExecutionType::NMSmodel_type& myModel(executionPointer_->NMSmodel());
        ExecutionType::NMSmodel_type::activation_type& myActivation(myModel.activation());
        ExecutionType::NMSmodel_type::activation_type::exponential_optional& myExpOpt(myActivation.exponential());
        ExecutionType::NMSmodel_type::activation_type::piecewise_optional& myPWOpt(myActivation.piecewise());
 
        if(myExpOpt.present())
            runMode_ += NMSModelCfg::ExponentialActivation;
        else if(myPWOpt.present())
            runMode_ += NMSModelCfg::PiecewiseActivation;
        else {
            cout << "invalid XML: ActivationType not found\n";
            exit(EXIT_FAILURE);
        }
        
        ExecutionType::NMSmodel_type::tendon_type& myTendon(myModel.tendon());
        ExecutionType::NMSmodel_type::tendon_type::stiff_optional& myStiffOpt(myTendon.stiff());
        ExecutionType::NMSmodel_type::tendon_type::elastic_optional& myElsaticOpt(myTendon.elastic());
        ExecutionType::NMSmodel_type::tendon_type::elasticBiSec_optional& myElsaticBiSecOpt(myTendon.elasticBiSec());
        
        if(myStiffOpt.present())
            runMode_ += NMSModelCfg::StiffTendon;
        else if (myElsaticOpt.present())
            runMode_ += NMSModelCfg::ElasticTendon;
        else if (myElsaticBiSecOpt.present())
            runMode_ += NMSModelCfg::ElasticTendonBiSec;
        else {
            cout << "invalid XML: TendonType not found\n";
            exit(EXIT_FAILURE);
        }
            
        ExecutionType::NMSmodel_type::type_type& myType(myModel.type());
        ExecutionType::NMSmodel_type::type_type::hybrid_optional& myHybOpt(myType.hybrid());
        ExecutionType::NMSmodel_type::type_type::openLoop_optional& myOLOpt(myType.openLoop());
        if(myHybOpt.present())
            runMode_ += NMSModelCfg::Hybrid;
        else if(myOLOpt.present())
            runMode_ += NMSModelCfg::OpenLoop;
        else {
            cout << "invalid XML: Hybrid/OpenLoop Type not found\n";
            exit(EXIT_FAILURE);
        }
        
        ExecutionType::online_optional& myOnlineOpt(executionPointer_->online());
        ExecutionType::offline_optional& myOfflineOpt(executionPointer_->offline());
        if(myOnlineOpt.present())
            runMode_ += NMSModelCfg::Online;
        else if (myOfflineOpt.present())
            runMode_ += NMSModelCfg::Offline;
        else {
            cout << "invalid XML: Online/Offline Type not found\n";
            exit(EXIT_FAILURE);
        }
        
 
 //ANCORA DA IMPLEMENTARE
 /*       
        ExecutionType::samplingFrequency_optional& myFreqOpt(executionPointer->samplingFrequency());
        if(myFreqOpt.present())
            myExecutionCfg.frequency_ = ExecutionCfg::Enabled;
        else
            myExecutionCfg.frequency_ = ExecutionCfg::Disabled;
            
        ExecutionType::logging_type::txt_optional& myTxtOpt(executionPointer->logging().txt()); 
        ExecutionType::logging_type::csv_optional& myCsvOpt(executionPointer->logging().csv());
        ExecutionType::logging_type::mot_optional& myMotOpt(executionPointer->logging().mot());
        if(myTxtOpt.present())
            myExecutionCfg.logging_ = ExecutionCfg::txt;
        else if(myCsvOpt.present())
            myExecutionCfg.logging_ = ExecutionCfg::csv;
        else if(myMotOpt.present())
            myExecutionCfg.logging_ = ExecutionCfg::mot;
        else {
            cout << "invalid XML: Logging Type not found\n";
            exit(EXIT_FAILURE);
        }
*/        
    }  
    catch (const xml_schema::exception& e) {
        cout << e << endl;
        exit(EXIT_FAILURE);
    }
    
    
}


void ExecutionXmlReader::getMusclesToPredict(std::vector<std::string>& musclesToPredict) {
    
    ExecutionType::NMSmodel_type& myModel(executionPointer_->NMSmodel());
    ExecutionType::NMSmodel_type::type_type& myType(myModel.type());
    ExecutionType::NMSmodel_type::type_type::hybrid_optional& myHybOpt(myType.hybrid());
    if(!myHybOpt.present()) {
        cout << "Cannot get hybrid parameters, hybrid option not selected\n";
        exit(EXIT_FAILURE);
    }


    musclesToPredict.clear();
    HybridType::predictedMuscles_type& predictedMuscles(myType.hybrid()->predictedMuscles());
    for(unsigned mi = 0; mi < predictedMuscles.size(); ++mi)
        musclesToPredict.push_back(predictedMuscles.at(mi));
}


void ExecutionXmlReader::getMusclesToTrack(std::vector<std::string>& musclesToTrack) {
    
    ExecutionType::NMSmodel_type& myModel(executionPointer_->NMSmodel());
    ExecutionType::NMSmodel_type::type_type& myType(myModel.type());
    ExecutionType::NMSmodel_type::type_type::hybrid_optional& myHybOpt(myType.hybrid());
    if(!myHybOpt.present()) {
        cout << "Cannot get hybrid parameters, hybrid option not selected\n";
        exit(EXIT_FAILURE);
    }


    musclesToTrack.clear();
    HybridType::trackedMuscles_type& trackedMuscles(myType.hybrid()->trackedMuscles());
    for(unsigned mi = 0; mi < trackedMuscles.size(); ++mi)
        musclesToTrack.push_back(trackedMuscles.at(mi));
}

void ExecutionXmlReader::getHybridWeightings(double& alpha, double& beta, double& gamma) {

    ExecutionType::NMSmodel_type& myModel(executionPointer_->NMSmodel());
    ExecutionType::NMSmodel_type::type_type& myType(myModel.type());
    ExecutionType::NMSmodel_type::type_type::hybrid_optional& myHybOpt(myType.hybrid());
    if(!myHybOpt.present()) {
        cout << "Cannot get hybrid parameters, hybrid option not selected\n";
        exit(EXIT_FAILURE);
    }

    HybridType::alpha_type& myAlpha(myType.hybrid()->alpha());
    alpha = myAlpha;
    
    HybridType::beta_type& myBeta(myType.hybrid()->beta());
    beta = myBeta;

    HybridType::gamma_type& myGamma(myType.hybrid()->gamma());
    gamma = myGamma;
    
    
}



NMSModelCfg::RunMode ExecutionXmlReader::getRunMode() const {
    
    return static_cast<NMSModelCfg::RunMode>(runMode_);

}

{'fraction_non_alphanumeric': 0.12586166834482224, 'fraction_numerical': 0.00046472000619626676, 'mean_word_length': 3.5178446466060183, 'pattern_counts': {'":': 0, '<': 62, '<?xml version=': 0, '>': 44, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5306628', 'n_tokens_mistral': 4028, 'n_tokens_neox': 3876, 'n_words': 547}