8bool GstreamerCsvFactory::openConnection() {
10 if (ofile_true_info.is_open() && ofile_digitized.is_open() &&
11 ofile_generated.is_open() && ofile_generated_tracked.is_open()) {
15 if (!ofile_true_info.is_open()) {
16 ofile_true_info.clear();
17 ofile_true_info.open(filename_true_info(), std::ios::out | std::ios::trunc);
19 if (!ofile_true_info.is_open() || !ofile_true_info) {
23 log->
info(1, SFUNCTION_NAME,
"GstreamerCsvFactory: opened file " + filename_true_info());
26 if (!ofile_digitized.is_open()) {
27 ofile_digitized.clear();
28 ofile_digitized.open(filename_digitized(), std::ios::out | std::ios::trunc);
30 if (!ofile_digitized.is_open() || !ofile_digitized) {
34 log->
info(1, SFUNCTION_NAME,
"GstreamerCsvFactory: opened file " + filename_digitized());
37 if (!ofile_generated.is_open()) {
38 ofile_generated.clear();
39 ofile_generated.open(filename_generated(), std::ios::out | std::ios::trunc);
40 if (!ofile_generated.is_open() || !ofile_generated) {
43 ofile_generated <<
"evn, timestamp, thread_id, bank, name, pid, type, multiplicity, p, theta, phi, vx, vy, vz\n";
44 log->
info(1, SFUNCTION_NAME,
"GstreamerCsvFactory: opened file " + filename_generated());
47 if (!ofile_generated_tracked.is_open()) {
48 ofile_generated_tracked.clear();
49 ofile_generated_tracked.open(filename_generated_tracked(), std::ios::out | std::ios::trunc);
50 if (!ofile_generated_tracked.is_open() || !ofile_generated_tracked) {
53 ofile_generated_tracked <<
"evn, timestamp, thread_id, bank, name, pid, type, multiplicity, p, theta, phi, vx, vy, vz\n";
54 log->
info(1, SFUNCTION_NAME,
"GstreamerCsvFactory: opened file " + filename_generated_tracked());
60bool GstreamerCsvFactory::closeConnectionImpl() {
62 const bool had_ancestor_stream = ofile_ancestors.is_open();
64 if (ofile_true_info.is_open()) ofile_true_info.close();
65 if (ofile_digitized.is_open()) ofile_digitized.close();
66 if (ofile_generated.is_open()) ofile_generated.close();
67 if (ofile_generated_tracked.is_open()) ofile_generated_tracked.close();
68 if (ofile_ancestors.is_open()) ofile_ancestors.close();
70 if (ofile_true_info.is_open()) {
73 if (ofile_digitized.is_open()) {
76 if (ofile_generated.is_open()) {
79 if (ofile_generated_tracked.is_open()) {
82 if (ofile_ancestors.is_open()) {
86 log->
info(1, SFUNCTION_NAME,
"GstreamerCsvFactory: closed file " + filename_true_info());
87 log->
info(1, SFUNCTION_NAME,
"GstreamerCsvFactory: closed file " + filename_digitized());
88 log->
info(1, SFUNCTION_NAME,
"GstreamerCsvFactory: closed file " + filename_generated());
89 log->
info(1, SFUNCTION_NAME,
"GstreamerCsvFactory: closed file " + filename_generated_tracked());
90 if (had_ancestor_stream) {
91 log->
info(1, SFUNCTION_NAME,
"GstreamerCsvFactory: closed file " + filename_ancestors());
97std::ofstream& GstreamerCsvFactory::generated_stream_for_bank(
const std::string& bankName) {
98 return bankName ==
"generated_tracked" ? ofile_generated_tracked : ofile_generated;
101bool GstreamerCsvFactory::publishEventGeneratedParticlesImpl(
const std::string& bankName,
103 auto& stream = generated_stream_for_bank(bankName);
104 if (!stream.is_open()) {
108 for (
const auto& particle : particles) {
109 stream << event_number <<
", " << timestamp <<
", " << thread_id <<
", " << bankName <<
", "
110 << particle.name <<
", "
111 << particle.pid <<
", "
112 << particle.type <<
", "
113 << particle.multiplicity <<
", "
114 << particle.p <<
", "
115 << particle.theta <<
", "
116 << particle.phi <<
", "
117 << particle.vx <<
", "
118 << particle.vy <<
", "
119 << particle.vz <<
"\n";
125bool GstreamerCsvFactory::publishEventAncestorsImpl(
const GAncestorBank& ancestors) {
126 if (!ofile_ancestors.is_open()) {
127 ofile_ancestors.open(filename_ancestors(), std::ios::out | std::ios::trunc);
128 if (!ofile_ancestors.is_open() || !ofile_ancestors) {
131 ofile_ancestors <<
"evn, timestamp, thread_id, pid, tid, mtid, trackE, px, py, pz, vx, vy, vz\n";
134 for (
const auto& ancestor : ancestors) {
135 ofile_ancestors << event_number <<
", " << timestamp <<
", " << thread_id <<
", "
136 << ancestor.pid <<
", " << ancestor.tid <<
", " << ancestor.mtid <<
", "
137 << ancestor.trackE <<
", " << ancestor.px <<
", " << ancestor.py <<
", "
138 << ancestor.pz <<
", " << ancestor.vx <<
", " << ancestor.vy <<
", "
139 << ancestor.vz <<
"\n";
std::shared_ptr< GLogger > log
void info(int level, Args &&... args) const
void error(int exit_code, Args &&... args) const
std::vector< GAncestorData > GAncestorBank
std::vector< GGeneratedParticleData > GGeneratedParticleBank
CSV streamer plugin declarations.
Shared constants and error codes for the gstreamer module.
#define ERR_CANTCLOSEOUTPUT
Output medium could not be closed cleanly.
#define ERR_CANTOPENOUTPUT
Output medium could not be opened successfully.