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) {
22 filename_true_info());
25 log->info(1,
"%1GstreamerCsvFactory: opened file %2", SFUNCTION_NAME, filename_true_info());
28 if (!ofile_digitized.is_open()) {
29 ofile_digitized.clear();
30 ofile_digitized.open(filename_digitized(), std::ios::out | std::ios::trunc);
32 if (!ofile_digitized.is_open() || !ofile_digitized) {
35 filename_digitized());
38 log->info(1,
"%1GstreamerCsvFactory: opened file %2", SFUNCTION_NAME, filename_digitized());
41 if (!ofile_generated.is_open()) {
42 ofile_generated.clear();
43 ofile_generated.open(filename_generated(), std::ios::out | std::ios::trunc);
44 if (!ofile_generated.is_open() || !ofile_generated) {
47 filename_generated());
49 ofile_generated <<
"evn, timestamp, thread_id, bank, name, pid, type, multiplicity, p, theta, phi, vx, vy, vz\n";
50 log->info(1,
"%1GstreamerCsvFactory: opened file %2", SFUNCTION_NAME, filename_generated());
53 if (!ofile_generated_tracked.is_open()) {
54 ofile_generated_tracked.clear();
55 ofile_generated_tracked.open(filename_generated_tracked(), std::ios::out | std::ios::trunc);
56 if (!ofile_generated_tracked.is_open() || !ofile_generated_tracked) {
59 filename_generated_tracked());
61 ofile_generated_tracked <<
"evn, timestamp, thread_id, bank, name, pid, type, multiplicity, p, theta, phi, vx, vy, vz\n";
62 log->info(1,
"%1GstreamerCsvFactory: opened file %2", SFUNCTION_NAME, filename_generated_tracked());
70 const bool had_ancestor_stream = ofile_ancestors.is_open();
72 if (ofile_true_info.is_open()) ofile_true_info.close();
73 if (ofile_digitized.is_open()) ofile_digitized.close();
74 if (ofile_generated.is_open()) ofile_generated.close();
75 if (ofile_generated_tracked.is_open()) ofile_generated_tracked.close();
76 if (ofile_ancestors.is_open()) ofile_ancestors.close();
78 if (ofile_true_info.is_open()) {
82 if (ofile_digitized.is_open()) {
86 if (ofile_generated.is_open()) {
90 if (ofile_generated_tracked.is_open()) {
93 filename_generated_tracked());
95 if (ofile_ancestors.is_open()) {
100 log->info(1,
"%1GstreamerCsvFactory: closed file %2", SFUNCTION_NAME, filename_true_info());
101 log->info(1,
"%1GstreamerCsvFactory: closed file %2", SFUNCTION_NAME, filename_digitized());
102 log->info(1,
"%1GstreamerCsvFactory: closed file %2", SFUNCTION_NAME, filename_generated());
103 log->info(1,
"%1GstreamerCsvFactory: closed file %2", SFUNCTION_NAME, filename_generated_tracked());
104 if (had_ancestor_stream) {
105 log->info(1,
"%1GstreamerCsvFactory: closed file %2", SFUNCTION_NAME, filename_ancestors());
111std::ofstream& GstreamerCsvFactory::generated_stream_for_bank(
const std::string& bankName) {
112 return bankName ==
"generated_tracked" ? ofile_generated_tracked : ofile_generated;
115bool GstreamerCsvFactory::publishEventGeneratedParticlesImpl(
const std::string& bankName,
117 auto& stream = generated_stream_for_bank(bankName);
118 if (!stream.is_open()) {
122 for (
const auto& particle : particles) {
123 stream << event_number <<
", " << timestamp <<
", " << thread_id <<
", " << bankName <<
", "
124 << particle.name <<
", "
125 << particle.pid <<
", "
126 << particle.type <<
", "
127 << particle.multiplicity <<
", "
128 << particle.p <<
", "
129 << particle.theta <<
", "
130 << particle.phi <<
", "
131 << particle.vx <<
", "
132 << particle.vy <<
", "
133 << particle.vz <<
"\n";
139bool GstreamerCsvFactory::publishEventAncestorsImpl(
const GAncestorBank& ancestors) {
140 if (!ofile_ancestors.is_open()) {
141 ofile_ancestors.open(filename_ancestors(), std::ios::out | std::ios::trunc);
142 if (!ofile_ancestors.is_open() || !ofile_ancestors) {
145 filename_ancestors());
147 ofile_ancestors <<
"evn, timestamp, thread_id, pid, tid, mtid, trackE, px, py, pz, vx, vy, vz\n";
150 for (
const auto& ancestor : ancestors) {
151 ofile_ancestors << event_number <<
", " << timestamp <<
", " << thread_id <<
", "
152 << ancestor.pid <<
", " << ancestor.tid <<
", " << ancestor.mtid <<
", "
153 << ancestor.trackE <<
", " << ancestor.px <<
", " << ancestor.py <<
", "
154 << ancestor.pz <<
", " << ancestor.vx <<
", " << ancestor.vy <<
", "
155 << ancestor.vz <<
"\n";
std::shared_ptr< GLogger > log
virtual bool closeConnectionImpl()
Plugin-specific close implementation hook.
virtual bool openConnection()
Open the output medium used by this streamer.
std::vector< GAncestorData > GAncestorBank
std::vector< GGeneratedParticleData > GGeneratedParticleBank
CSV streamer plugin declarations.
Shared constants and error codes for the gstreamer module.
constexpr int ERR_CANTOPENOUTPUT
Output medium could not be opened successfully.
constexpr int ERR_CANTCLOSEOUTPUT
Output medium could not be closed cleanly.