main.cpp 3.16 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>

10
11
12
13
14
15
16
17
18
19
20
21
/*
 * Some declarations from examples.cpp
 * Uncomment the one you want to use.
 */
//void computeSingleKinematicsForGPD();
//void computeManyKinematicsForGPD();
//void computeSingleKinematicsForDVCSComptonFormFactor();
//void computeManyKinematicsForDVCSComptonFormFactor();
//void computeSingleKinematicsForDVCSObservable();
//void computeManyKinematicsForDVCSObservable();
//void changeIntegrationRoutine();

Pawel Sznajder's avatar
Pawel Sznajder committed
22
23
24
/*
 * Parse XML scenarios.
 */
Bryan Berthou's avatar
refs#16  
Bryan Berthou committed
25
std::vector<std::string> parseArguments(int argc, char** argv) {
26
    std::vector<std::string> xmlScenarios(argc - 1);
Bryan Berthou's avatar
refs#16  
Bryan Berthou committed
27

28
    for (unsigned int i = 1; i < argc; i++) {
29
        xmlScenarios[i - 1] = argv[i];
Bryan Berthou's avatar
refs#16  
Bryan Berthou committed
30
31
32
33
34
    }

    return xmlScenarios;
}

Pawel Sznajder's avatar
Pawel Sznajder committed
35
36
37
/*
 * Main function.
 */
Bryan Berthou's avatar
refs#16  
Bryan Berthou committed
38
39
40
int main(int argc, char** argv) {

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

    try {
Pawel Sznajder's avatar
Pawel Sznajder committed
44

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

49
50
51
52
        if (argc <= 1) {
            // If you want to run your C++ code based on PARTONS library, comment out this exception:
            throw ElemUtils::CustomException("main", __func__,
                    "Missing argument, please provide one or more than one XML scenario file.");
Pawel Sznajder's avatar
Pawel Sznajder committed
53

54
55
            // And include your code here, e.g. this function in examples.cpp:
            // computeSingleKinematicsForGPD(); // It has to be declared before, uncomment the declaration too.
Bryan Berthou's avatar
refs#16  
Bryan Berthou committed
56

57
58
59
60
            // The program will then run the code here when there are no XML scenarios in argument.

        } else {
            // You need this to run XML scenarios indicated in arguments of the executable.
Pawel Sznajder's avatar
Pawel Sznajder committed
61

62
63
64
            // Parse arguments to retrieve xml file path list.
            std::vector<std::string> xmlScenarioFilePathList = parseArguments(
                    argc, argv);
Pawel Sznajder's avatar
Pawel Sznajder committed
65

66
67
68
69
70
71
72
73
74
75
            // Retrieve automation service parse scenario xml file and play it.
            PARTONS::AutomationService* pAutomationService =
                    pPartons->getServiceObjectRegistry()->getAutomationService();

            for (unsigned int i = 0; i < xmlScenarioFilePathList.size(); i++) {
                PARTONS::Scenario* pScenario = pAutomationService->parseXMLFile(
                        xmlScenarioFilePathList[i]);
                pAutomationService->playScenario(pScenario);
            }
        }
Pawel Sznajder's avatar
Pawel Sznajder committed
76

Bryan Berthou's avatar
refs#16  
Bryan Berthou committed
77
        // If there is an exception
Bryan Berthou's avatar
refs#16    
Bryan Berthou committed
78
79
    } catch (const ElemUtils::CustomException &e) {
        pPartons->getLoggerManager()->error(e);
Nabil Chouika's avatar
typo    
Nabil Chouika committed
80
        // Close PARTONS application properly
Nabil Chouika's avatar
refs#16    
Nabil Chouika committed
81
82
83
        if (pPartons) {
            pPartons->close();
        }
Bryan Berthou's avatar
refs#16    
Bryan Berthou committed
84
85
    } catch (const std::exception &e) {
        pPartons->getLoggerManager()->error("main", __func__, e.what());
Nabil Chouika's avatar
typo    
Nabil Chouika committed
86
        // Close PARTONS application properly
Nabil Chouika's avatar
refs#16    
Nabil Chouika committed
87
88
89
        if (pPartons) {
            pPartons->close();
        }
Bryan Berthou's avatar
refs#16    
Bryan Berthou committed
90
    }
Bryan Berthou's avatar
refs#16  
Bryan Berthou committed
91

Nabil Chouika's avatar
typo    
Nabil Chouika committed
92
    // Close PARTONS application properly
Bryan Berthou's avatar
refs#16    
Bryan Berthou committed
93
94
    if (pPartons) {
        pPartons->close();
Bryan Berthou's avatar
refs#16  
Bryan Berthou committed
95
96
97
98
    }

    return 0;
}