-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmain.cpp
117 lines (100 loc) · 3.79 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
//////////////////////////////////////////////////////////////////////////
// Copyright (C) 2021-2024, Nazar Burmasov, Evgeny Kryshen
//
// E-mail of the corresponding author: [email protected]
//
// This file is a part of Upcgen
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//////////////////////////////////////////////////////////////////////////
#include "UpcGenerator.h"
#include <plog/Log.h>
#include <plog/Init.h>
#include <plog/Formatters/TxtFormatter.h>
#include <plog/Appenders/ColorConsoleAppender.h>
#include <algorithm>
class InputParser
{
public:
InputParser(int& argc, char** argv)
{
for (int i = 1; i < argc; ++i)
this->tokens.emplace_back(argv[i]);
}
const std::string& getCmdOption(const std::string& option) const
{
std::vector<std::string>::const_iterator itr;
itr = std::find(this->tokens.begin(), this->tokens.end(), option);
if (itr != this->tokens.end() && ++itr != this->tokens.end()) {
return *itr;
}
static const std::string empty_string("");
return empty_string;
}
bool cmdOptionExists(const std::string& option) const
{
return std::find(this->tokens.begin(), this->tokens.end(), option) != this->tokens.end();
}
private:
std::vector<std::string> tokens;
};
int main(int argc, char** argv)
{
InputParser input(argc, argv);
// define default values of command line parameters
// logging levels:
// 0 -> no debug logs
// 1 -> basic debug logs
// 2 -> verbose logs with intermediate calculation results
int debugLevel = 0;
int numThreads = 1;
std::string parFileName("parameters.in");
// initialize logger
static plog::ColorConsoleAppender<plog::TxtFormatter> consoleAppender;
plog::init(plog::verbose, &consoleAppender);
if (input.cmdOptionExists("-h")) {
printf("Available options:\n"
"-h -- help message\n"
"-debug -- set debug level: 0=no debug messages (default),\n"
" 1=save calculated cross sections into 'events.root' (for ROOT output only),\n"
" 2=print out intermediate calculation results and events info (warning, lots of messages)\n"
"-nthreads -- set number of threads for cross section and luminosity calculation (default is 1)\n"
"-parfile -- name of input parameter file\n");
std::_Exit(0);
}
const auto debugLevelOpt = input.getCmdOption("-debug");
if (!debugLevelOpt.empty()) {
debugLevel = std::stoi(debugLevelOpt);
}
const auto numThreadsOpt = input.getCmdOption("-nthreads");
if (!numThreadsOpt.empty()) {
numThreads = std::stoi(numThreadsOpt);
}
const auto parFileNameOpt = input.getCmdOption("-parfile");
if (!parFileNameOpt.empty()) {
parFileName = std::string(parFileNameOpt);
}
PLOG_INFO << "Configuring the generator...";
auto* upcGenerator = new UpcGenerator();
upcGenerator->setDebugLevel(debugLevel);
upcGenerator->setNumThreads(numThreads);
upcGenerator->setParFile(parFileName);
upcGenerator->configGeneratorFromFile();
PLOG_INFO << "Initializing the generator...";
upcGenerator->init();
PLOG_INFO << "Starting generation process...";
upcGenerator->generateEvents();
delete upcGenerator;
return 0;
}