-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
GeneratorWorker.cpp
81 lines (71 loc) · 3.14 KB
/
GeneratorWorker.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
/*
* CepGen: a central exclusive processes event generator
* Copyright (C) 2013-2024 Laurent Forthomme
*
* 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
* 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 <http://www.gnu.org/licenses/>.
*/
#include "CepGen/Core/Exception.h"
#include "CepGen/Core/GeneratorWorker.h"
#include "CepGen/Core/RunParameters.h"
#include "CepGen/Event/Event.h"
#include "CepGen/EventFilter/EventExporter.h"
#include "CepGen/Integration/Integrator.h"
#include "CepGen/Integration/ProcessIntegrand.h"
#include "CepGen/Process/Process.h"
#include "CepGen/Utils/String.h"
#include "CepGen/Utils/TimeKeeper.h"
namespace cepgen {
GeneratorWorker::GeneratorWorker(const ParametersList& params) : SteeredObject(params) {}
void GeneratorWorker::setRunParameters(const RunParameters* params) {
params_ = params;
integrand_.reset(new ProcessIntegrand(params));
CG_DEBUG("GeneratorWorker") << "New generator worker initialised for integration/event generation.\n\t"
<< "Run parameters at " << (void*)params_ << ".";
}
GeneratorWorker::~GeneratorWorker() {
CG_DEBUG("GeneratorWorker") << "Generator worker destructed. Releasing the parameters at " << (void*)params_ << ".";
}
void GeneratorWorker::setIntegrator(const Integrator* integr) {
integrator_ = integr;
CG_DEBUG("GeneratorWorker:integrator")
<< "Dim-" << integrand_->size() << " " << integrator_->name() << " integrator set.";
}
void GeneratorWorker::generate(size_t num_events, const std::function<void(const proc::Process&)>& callback) {
if (!params_)
throw CG_FATAL("GeneratorWorker:generate") << "No steering parameters specified!";
callback_proc_ = callback;
while (params_->numGeneratedEvents() < num_events)
next();
}
bool GeneratorWorker::storeEvent() {
CG_TICKER(const_cast<RunParameters*>(params_)->timeKeeper());
if (!integrand_->process().hasEvent())
return true;
const auto& event = integrand_->process().event();
const auto ngen = params_->numGeneratedEvents();
if ((ngen + 1) % params_->generation().printEvery() == 0)
CG_INFO("GeneratorWorker:store") << utils::s("event", ngen + 1, true) << " generated.";
if (callback_proc_)
callback_proc_(integrand_->process());
for (const auto& mod : params_->eventExportersSequence())
*mod << event;
const_cast<RunParameters*>(params_)->addGenerationTime(event.metadata.at("time:total"));
return true;
}
ParametersDescription GeneratorWorker::description() {
auto desc = ParametersDescription();
desc.setDescription("Unnamed generator worker");
return desc;
}
} // namespace cepgen