main.cpp 2.52 KB
Newer Older
Bryan Berthou's avatar
refs#16    
Bryan Berthou committed
1
2
#include <ElementaryUtils/logger/CustomException.h>
#include <ElementaryUtils/logger/LoggerManager.h>
Bryan Berthou's avatar
refs#16  
Bryan Berthou committed
3
4
5
#include <partons/Partons.h>
#include <partons/services/automation/AutomationService.h>
#include <partons/ServiceObjectRegistry.h>
6
#include <QtCore/qcoreapplication.h>
Bryan Berthou's avatar
refs#16  
Bryan Berthou committed
7
8
9
#include <string>
#include <vector>

Pawel Sznajder's avatar
Pawel Sznajder committed
10
11
12
/*
 * Parse XML scenarios.
 */
Bryan Berthou's avatar
refs#16  
Bryan Berthou committed
13
14
std::vector<std::string> parseArguments(int argc, char** argv) {
    if (argc <= 1) {
Bryan Berthou's avatar
refs#16    
Bryan Berthou committed
15
        throw ElemUtils::CustomException("main", __func__,
Bryan Berthou's avatar
refs#16  
Bryan Berthou committed
16
17
18
19
20
21
22
23
24
25
26
27
                "Missing argument, please provide one or more than one XML scenario file.");
    }

    std::vector<std::string> xmlScenarios;

    for (unsigned int i = 1; i != argc; i++) {
        xmlScenarios.push_back(argv[i]);
    }

    return xmlScenarios;
}

Pawel Sznajder's avatar
Pawel Sznajder committed
28
29
30
/*
 * Main function.
 */
Bryan Berthou's avatar
refs#16  
Bryan Berthou committed
31
32
33
34
35
36
37
int main(int argc, char** argv) {

    // Parse arguments to retrieve xml file path list.
    std::vector<std::string> xmlScenarioFilePathList = parseArguments(argc,
            argv);

    QCoreApplication a(argc, argv);
38
    PARTONS::Partons* pPartons = 0;
Bryan Berthou's avatar
refs#16  
Bryan Berthou committed
39
40

    try {
Pawel Sznajder's avatar
Pawel Sznajder committed
41

Bryan Berthou's avatar
refs#16  
Bryan Berthou committed
42
        // Init PARTONS application
43
        pPartons = PARTONS::Partons::getInstance();
Bryan Berthou's avatar
refs#16  
Bryan Berthou committed
44
45
        pPartons->init(argc, argv);

Pawel Sznajder's avatar
Pawel Sznajder committed
46
47
        // This you need to run XML scenarios indicated in arguments of the executable

Bryan Berthou's avatar
refs#16  
Bryan Berthou committed
48
        // Retrieve automation service parse scenario xml file and play it.
49
        PARTONS::AutomationService* pAutomationService =
Bryan Berthou's avatar
refs#16  
Bryan Berthou committed
50
51
52
                pPartons->getServiceObjectRegistry()->getAutomationService();

        for (unsigned int i = 0; i != xmlScenarioFilePathList.size(); i++) {
53
            PARTONS::Scenario* pScenario = pAutomationService->parseXMLFile(
Bryan Berthou's avatar
refs#16  
Bryan Berthou committed
54
55
56
                    xmlScenarioFilePathList[i]);
            pAutomationService->playScenario(pScenario);
        }
Pawel Sznajder's avatar
Pawel Sznajder committed
57
58
59
60
61
62

        // Here you can run your code based on PARTONS library, e.g.
        // computeSingleKinematicsForGPD();

        //TODO to run cpp one need to comment out XML part. But, if we relax argc <= 1 requirement they can be used in parallel.

Bryan Berthou's avatar
refs#16  
Bryan Berthou committed
63
        // If there is an exception
Bryan Berthou's avatar
refs#16    
Bryan Berthou committed
64
65
    } catch (const ElemUtils::CustomException &e) {
        pPartons->getLoggerManager()->error(e);
Nabil Chouika's avatar
refs#16    
Nabil Chouika committed
66
67
68
69
        // Close PARTONS application propertly
        if (pPartons) {
            pPartons->close();
        }
Bryan Berthou's avatar
refs#16    
Bryan Berthou committed
70
71
    } catch (const std::exception &e) {
        pPartons->getLoggerManager()->error("main", __func__, e.what());
Nabil Chouika's avatar
refs#16    
Nabil Chouika committed
72
73
74
75
        // Close PARTONS application propertly
        if (pPartons) {
            pPartons->close();
        }
Bryan Berthou's avatar
refs#16    
Bryan Berthou committed
76
    }
Bryan Berthou's avatar
refs#16  
Bryan Berthou committed
77

Bryan Berthou's avatar
refs#16    
Bryan Berthou committed
78
79
80
    // Close PARTONS application propertly
    if (pPartons) {
        pPartons->close();
Bryan Berthou's avatar
refs#16  
Bryan Berthou committed
81
82
83
84
    }

    return 0;
}