Skip to content

Commit 596d5c7

Browse files
committed
improved ascii factory, not opening connection on streamer instantiation, but in begin of the run. improving system template
1 parent 5a8de99 commit 596d5c7

14 files changed

Lines changed: 133 additions & 83 deletions

File tree

.github/workflows/docker.yml

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,6 @@ jobs:
105105
cache-from: type=gha
106106
cache-to: type=gha,mode=max
107107

108-
109-
110108
# Extract logs from the built image (use new tag names)
111109
- name: Extract /root/src/logs from image
112110
if: ${{ always() }}
@@ -140,7 +138,6 @@ jobs:
140138
141139
ls -l ci-logs || true
142140
143-
144141
- name: Upload build logs artifact
145142
if: ${{ always() }}
146143
uses: actions/upload-artifact@v4
@@ -152,3 +149,44 @@ jobs:
152149
ci-logs/test.log
153150
if-no-files-found: ignore
154151
retention-days: 14
152+
153+
- name: Summarize image reference
154+
if: ${{ always() }}
155+
env:
156+
IMAGE: ${{ needs.discover.outputs.image }}
157+
PRIMARY_TAG: ${{ matrix.tag }}-${{ matrix.os }}
158+
LATEST_TAG: latest-${{ matrix.os }}
159+
IS_LATEST: ${{ matrix.latest }}
160+
PUSHED: ${{ github.event_name != 'pull_request' }}
161+
run: |
162+
{
163+
echo "## Docker Image"
164+
if [ "$PUSHED" = "true" ]; then
165+
echo ""
166+
echo "**Primary tag:** \`$IMAGE:$PRIMARY_TAG\`"
167+
if [ "$IS_LATEST" = "true" ]; then
168+
echo ""
169+
echo "**Alias:** \`$IMAGE:$LATEST_TAG\`"
170+
fi
171+
echo ""
172+
echo "### Pull"
173+
echo '```bash'
174+
echo "docker pull $IMAGE:$PRIMARY_TAG"
175+
echo '```'
176+
echo "### Run"
177+
echo '```bash'
178+
echo "docker run --rm $IMAGE:$PRIMARY_TAG uname -m"
179+
echo '```'
180+
else
181+
echo ""
182+
echo "_PR build (image not pushed). Loaded locally on the runner with tags:_"
183+
echo '```'
184+
# Show every tag we applied locally (one per line)
185+
printf '%s\n' "${{ steps.meta.outputs.tags }}"
186+
echo '```'
187+
echo "To pull later (after merge to main):"
188+
echo '```bash'
189+
echo "docker pull $IMAGE:$PRIMARY_TAG"
190+
echo '```'
191+
fi
192+
} >> "$GITHUB_STEP_SUMMARY"

actions/run/gRunAction.cc

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,17 @@ void GRunAction::BeginOfRunAction(const G4Run* aRun) {
3333
int neventsThisRun = aRun->GetNumberOfEventToBeProcessed();
3434

3535
// define gstreamer_map
36-
if (gstreamer_map == nullptr) {
37-
if (!IsMaster()) {
38-
log->info(0, " Defining gstreamers for thread id ", thread_id);
39-
gstreamer_map = gstreamer::gstreamersMapPtr(goptions, thread_id);
36+
if (!IsMaster() && gstreamer_map == nullptr) {
37+
log->info(0, " Defining gstreamers for thread id ", thread_id);
38+
gstreamer_map = gstreamer::gstreamersMapPtr(goptions, thread_id);
39+
}
40+
41+
// (re)-open for this run
42+
if (!IsMaster()) {
43+
for (auto& [name, gstreamer] : *gstreamer_map) {
44+
if (!gstreamer->openConnection()) {
45+
log->error(1, "Failed to open connection for GStreamer ", name, " in thread ", thread_id);
46+
}
4047
}
4148
}
4249

api/system_template.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ def write_templates(system, variations):
187187
pg.write('def build_mother_volume(configuration):\n')
188188
pg.write(' gvolume = GVolume(\'absorber\')\n')
189189
pg.write(' gvolume.description = \'scintillator box\'\n')
190-
pg.write(' gvolume.make_box(100.0, 100.0, 1.0)\n')
190+
pg.write(' gvolume.make_box(40.0, 40.0, 2.0)\n')
191191
pg.write(' gvolume.material = \'carbonFiber\'\n')
192192
pg.write(' gvolume.color = \'3399FF\'\n')
193193
pg.write(' gvolume.digitization = \'flux\'\n')
@@ -207,14 +207,12 @@ def write_templates(system, variations):
207207
# ask_to_overwrite_file(yaml)
208208
with open(f'{yaml}', 'w') as pj:
209209
pj.write('runno: 1\n')
210-
pj.write('n: 10\n\n')
210+
pj.write('n: 100\n\n')
211+
pj.write('nthreads: 4\n\n')
211212
pj.write('gparticle:\n')
212213
pj.write(' - name: proton\n')
213214
pj.write(' p: 1500\n')
214-
pj.write(' theta: 10.0\n')
215-
pj.write(' delta_theta: 4.0\n')
216-
pj.write(' delta_phi: 180.0\n')
217-
pj.write(' vz: -100.0\n')
215+
pj.write(' vz: -5.0\n')
218216
pj.write('verbosity:\n')
219217
pj.write(' - ghits: 0\n')
220218
pj.write(' - gsystem: 1\n')
@@ -224,7 +222,7 @@ def write_templates(system, variations):
224222
pj.write(f' - name: {system}\n')
225223
pj.write(' factory: sqlite\n\n')
226224
pj.write('gstreamer:\n')
227-
pj.write(f' - filename: {system}.txt\n')
225+
pj.write(f' - filename: {system}\n')
228226
pj.write(' format: ascii\n\n')
229227
pj.write('root: G4Box, 15*cm, 15*cm, 15*cm, G4_AIR\n')
230228

gemc.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ int main(int argc, char* argv[]) {
9999

100100
app_result = QApplication::exec();
101101

102+
runManager.reset();
102103
delete g4SceneProperties;
103104
delete uiQtSession;
104105
}

gstreamer/factories/ASCII/event/event.cc

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,23 @@
22
#include "../gstreamerASCIIFactory.h"
33
#include "gstreamerConventions.h"
44

5+
// using \n instead of endl so flushing isn't forced at each line
56
bool GstreamerTextFactory::startEventImpl([[maybe_unused]] const std::shared_ptr<GEventDataCollection>& event_data) {
6-
if (ofile == nullptr) { log->error(ERR_CANTOPENOUTPUT, "Error: can't open ", ofile); }
7+
if (!ofile.is_open()) { log->error(ERR_CANTOPENOUTPUT, SFUNCTION_NAME, "Error: can't access ", filename()); }
78

89
auto eventNumber = event_data->getHeader()->getG4LocalEvn();
9-
*ofile << "Event n. " << eventNumber << " {" << std::endl;
10+
ofile << "Event n. " << eventNumber << " {\n";
1011

1112
return true;
1213
}
1314

1415

1516
bool GstreamerTextFactory::endEventImpl([[maybe_unused]] const std::shared_ptr<GEventDataCollection>& event_data) {
16-
if (ofile == nullptr) { log->error(ERR_CANTOPENOUTPUT, "Error: can't open ", ofile); }
17+
if (!ofile.is_open()) { log->error(ERR_CANTOPENOUTPUT, SFUNCTION_NAME, "Error: can't access ", filename()); }
1718

1819
int eventNumber = event_data->getHeader()->getG4LocalEvn();
1920

20-
*ofile << "} end of event " << eventNumber << std::endl;
21+
ofile << "} end of event " << eventNumber << "\n";
2122

2223
return true;
2324
}

gstreamer/factories/ASCII/event/eventHeader.cc

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
#include "../gstreamerASCIIFactory.h"
33
#include "gstreamerConventions.h"
44

5-
bool GstreamerTextFactory::publishEventHeaderImpl([[maybe_unused]]const std::unique_ptr<GEventHeader>& gheader)
6-
{
7-
if (ofile == nullptr) { log->error(ERR_CANTOPENOUTPUT, "Error: can't open ", ofile); }
8-
9-
*ofile << GTAB << "Header Bank {" << std::endl;
10-
*ofile << GTABTAB << " time: " << gheader->getTimeStamp() << std::endl;
11-
*ofile << GTABTAB << " g4run-local event number: " << gheader->getG4LocalEvn() << std::endl;
12-
*ofile << GTABTAB << " thread id: " << gheader->getThreadID() << std::endl;
13-
*ofile << GTAB << "}" << std::endl;
5+
// using \n instead of endl so flushing isn't forced at each line
6+
bool GstreamerTextFactory::publishEventHeaderImpl([[maybe_unused]] const std::unique_ptr<GEventHeader>& gheader) {
7+
if (!ofile.is_open()) { log->error(ERR_CANTOPENOUTPUT, SFUNCTION_NAME, "Error: can't access ", filename()); }
8+
9+
ofile << GTAB << "Header Bank {\n";
10+
ofile << GTABTAB << " time: " << gheader->getTimeStamp() << "\n";
11+
ofile << GTABTAB << " g4run-local event number: " << gheader->getG4LocalEvn() << "\n";;
12+
ofile << GTABTAB << " thread id: " << gheader->getThreadID() << "\n";
13+
ofile << GTAB << "}\n";
1414

1515
return true;
1616
}

gstreamer/factories/ASCII/event/publishDigitized.cc

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,24 @@
22
#include "../gstreamerASCIIFactory.h"
33
#include "gstreamerConventions.h"
44

5+
// using \n instead of endl so flushing isn't forced at each line
56
bool GstreamerTextFactory::publishEventDigitizedDataImpl(const std::string& detectorName, const std::vector<const GDigitizedData*>& digitizedData) {
7+
if (!ofile.is_open()) { log->error(ERR_CANTOPENOUTPUT, SFUNCTION_NAME, "Error: can't access ", filename()); }
68

7-
if (ofile == nullptr) { log->error(ERR_CANTOPENOUTPUT, "Error: can't open ", ofile); }
8-
9-
*ofile << GTAB << "Detector <" << detectorName << "> Digitized Bank {" << std::endl;
9+
ofile << GTAB << "Detector <" << detectorName << "> Digitized Bank {\n";
1010

1111
for (auto dgtzHit : digitizedData) {
1212
std::string identifierString = dgtzHit->getIdentityString();
1313

14-
*ofile << GTABTAB << "Hit address: " << identifierString << " {" << std::endl;
14+
ofile << GTABTAB << "Hit address: " << identifierString << " {\n";
1515

1616
// argument passed to getter: 0 = do not get sro vars
17-
for (const auto& [variableName, value] : dgtzHit->getIntObservablesMap(0)) { *ofile << GTABTABTAB << variableName << ": " << value << std::endl; }
18-
for (const auto& [variableName, value] : dgtzHit->getDblObservablesMap(0)) { *ofile << GTABTABTAB << variableName << ": " << value << std::endl; }
17+
for (const auto& [variableName, value] : dgtzHit->getIntObservablesMap(0)) { ofile << GTABTABTAB << variableName << ": " << value << "\n"; }
18+
for (const auto& [variableName, value] : dgtzHit->getDblObservablesMap(0)) { ofile << GTABTABTAB << variableName << ": " << value << "\n"; }
1919

20-
*ofile << GTABTAB << "}" << std::endl;
20+
ofile << GTABTAB << "}\n";
2121
}
22-
*ofile << GTAB << "}" << std::endl;
22+
ofile << GTAB << "}\n";
2323

2424
return true;
2525
}

gstreamer/factories/ASCII/event/publishTrueInfo.cc

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,23 @@
22
#include "../gstreamerASCIIFactory.h"
33
#include "gstreamerConventions.h"
44

5+
// using \n instead of endl so flushing isn't forced at each line
56
bool GstreamerTextFactory::publishEventTrueInfoDataImpl(const std::string& detectorName, const std::vector<const GTrueInfoData*>& trueInfoData) {
6-
if (ofile == nullptr) { log->error(ERR_CANTOPENOUTPUT, "Error: can't open ", ofile); }
7+
if (!ofile.is_open()) { log->error(ERR_CANTOPENOUTPUT, SFUNCTION_NAME, "Error: can't access ", filename()); }
78

8-
*ofile << GTAB << "Detector <" << detectorName << "> True Info Bank {" << std::endl;
9+
ofile << GTAB << "Detector <" << detectorName << "> True Info Bank {\n";
910

1011
for (auto trueInfoHit : trueInfoData) {
1112
std::string identifierString = trueInfoHit->getIdentityString();
1213

13-
*ofile << GTABTAB << "Hit address: " << identifierString << " {" << std::endl;
14+
ofile << GTABTAB << "Hit address: " << identifierString << " {\n";
1415

15-
for (const auto& [variableName, value] : trueInfoHit->getDoubleVariablesMap()) { *ofile << GTABTABTAB << variableName << ": " << value << std::endl; }
16-
for (const auto& [variableName, value] : trueInfoHit->getStringVariablesMap()) { *ofile << GTABTABTAB << variableName << ": " << value << std::endl; }
16+
for (const auto& [variableName, value] : trueInfoHit->getDoubleVariablesMap()) { ofile << GTABTABTAB << variableName << ": " << value << "\n"; }
17+
for (const auto& [variableName, value] : trueInfoHit->getStringVariablesMap()) { ofile << GTABTABTAB << variableName << ": " << value << "\n"; }
1718

18-
*ofile << GTABTAB << "}" << std::endl;
19+
ofile << GTABTAB << "}\n";
1920
}
20-
*ofile << GTAB << "}" << std::endl;
21-
21+
ofile << GTAB << "}\n";
2222

2323
return true;
2424
}

gstreamer/factories/ASCII/gstreamerASCIIConnection.cc

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,20 @@
33
#include "gstreamerConventions.h"
44

55
bool GstreamerTextFactory::openConnection() {
6-
ofile = new std::ofstream(filename());
6+
if (ofile.is_open()) {
7+
// Already open for this thread; nothing to do.
8+
return true;
9+
}
710

8-
if (!ofile->is_open()) { log->error(ERR_CANTOPENOUTPUT, "GstreamerTextFactory: could not open file " + filename()); }
11+
ofile.clear(); // clear fail/eof bits from last use
12+
// std::ios::out — open for writing.
13+
// std::ios::trunc — if the file already exists, truncate it to size 0 on open (wipe its contents). If it doesn’t exist, it will be created.
14+
// another variant: std::ios::app: append
15+
ofile.open(filename(), std::ios::out | std::ios::trunc);
16+
17+
if (!ofile.is_open() || !ofile) {
18+
log->error(ERR_CANTOPENOUTPUT, SFUNCTION_NAME, " could not open file ", filename());
19+
}
920

1021
log->info(0, "GstreamerTextFactory: opened file " + filename());
1122
return true;
@@ -15,10 +26,9 @@ bool GstreamerTextFactory::closeConnectionImpl() {
1526

1627
flushEventBuffer();
1728

18-
if (ofile->is_open()) { ofile->close(); }
29+
if (ofile.is_open()) ofile.close();
1930

20-
if (ofile->is_open()) { log->error(ERR_CANTCLOSEOUTPUT, "GstreamerTextFactory: could not close file " + filename()); }
31+
if (ofile.is_open()) { log->error(ERR_CANTCLOSEOUTPUT, SFUNCTION_NAME, " could not close file " + filename()); }
2132

22-
/// delete ofile;
2333
return true;
2434
}

gstreamer/factories/ASCII/gstreamerASCIIFactory.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,22 @@
22

33
// gstreamer
44
#include "gstreamer.h"
5-
#include "gstreamerConventions.h"
65

76
// c++
87
#include <fstream>
98

109
class GstreamerTextFactory : public GStreamer {
1110
public:
12-
// GstreamerTextFactory() = default;
13-
1411
// inherit the base (const std::shared_ptr<GOptions>&) ctor
1512
using GStreamer::GStreamer;
1613

17-
private:
18-
19-
14+
// One instance per thread: forbid copy/move to prevent accidental sharing
15+
GstreamerTextFactory(const GstreamerTextFactory&) = delete;
16+
GstreamerTextFactory& operator=(const GstreamerTextFactory&) = delete;
17+
GstreamerTextFactory(GstreamerTextFactory&&) = delete;
18+
GstreamerTextFactory& operator=(GstreamerTextFactory&&) = delete;
2019

20+
private:
2121
// open and close the output media
2222
bool openConnection() override;
2323
bool closeConnectionImpl() override;
@@ -40,7 +40,7 @@ class GstreamerTextFactory : public GStreamer {
4040
bool publishFrameHeaderImpl(const GFrameHeader* gframeHeader) override;
4141
bool publishPayloadImpl(const std::vector<GIntegralPayload*>* payload) override;
4242

43-
private:
44-
std::ofstream* ofile = nullptr;
45-
std::string filename() const override { return gstreamer_definitions.rootname + ".txt"; }
43+
std::ofstream ofile;
44+
45+
[[nodiscard]] std::string filename() const override { return gstreamer_definitions.rootname + ".txt"; }
4646
};

0 commit comments

Comments
 (0)