Skip to content

Commit e887875

Browse files
committed
adding automatic inclusing of identity variables in gstreamers
1 parent b2d501b commit e887875

15 files changed

Lines changed: 136 additions & 116 deletions

gdata/examples/event_example.cc

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,6 @@
4242
* - \ref GEventDataCollection::addDetectorDigitizedData "addDetectorDigitizedData()"
4343
* - inspecting stored data:
4444
* - per-detector hit counts
45-
* - identity strings from
46-
* \ref GTrueInfoData::getIdentityString "getIdentityString()" and
47-
* \ref GDigitizedData::getIdentityString "getIdentityString()"
4845
* - truth and digitized observable maps
4946
* - demonstrating filtering of streaming-readout keys for digitized data with:
5047
* - \ref GDigitizedData::getIntObservablesMap "getIntObservablesMap()"
@@ -164,7 +161,9 @@ static void dump_event(const std::shared_ptr<GEventDataCollection>& edc, const s
164161
const auto doubles = th->getDoubleVariablesMap();
165162
const auto strings = th->getStringVariablesMap();
166163

167-
log->info(0, " [truth hit ", i, "] id={", th->getIdentityString(), "}");
164+
auto idString = getIdentityString(th->getIdentity());
165+
166+
log->info(0, " [truth hit ", i, "] id={",idString, "}");
168167
log->info(0, " doubles: ", map_to_string(doubles));
169168

170169
// Strings are often empty in this toy factory, but the code shows how to inspect them.
@@ -186,7 +185,9 @@ static void dump_event(const std::shared_ptr<GEventDataCollection>& edc, const s
186185
const auto dbls_non_sro = dh->getDblObservablesMap(0);
187186
const auto dbls_sro_only = dh->getDblObservablesMap(1);
188187

189-
log->info(0, " [digi hit ", i, "] id={", dh->getIdentityString(), "}");
188+
auto idString = getIdentityString(dh->getIdentity());
189+
190+
log->info(0, " [digi hit ", i, "] id={",idString, "}");
190191
log->info(0, " int non-SRO: ", map_to_string(ints_non_sro));
191192
log->info(0, " int SRO: ", map_to_string(ints_sro));
192193
log->info(0, " dbl non-SRO: ", map_to_string(dbls_non_sro));

gdata/gDigitizedData.cc

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -127,18 +127,12 @@ double GDigitizedData::getDblObservable(const std::string& varName) {
127127
return doubleObservablesMap[varName];
128128
}
129129

130-
std::string GDigitizedData::getIdentityString() const {
131-
// Build a compact label from the stored identifier vector.
132-
std::string identifierString;
133-
for (size_t i = 0; i < gidentity.size() - 1; i++) {
134-
identifierString += gidentity[i].getName() + "->" + std::to_string(gidentity[i].getValue()) + ", ";
135-
}
136-
identifierString += gidentity.back().getName() + "->" + std::to_string(gidentity.back().getValue());
137-
return identifierString;
138-
}
139130

140131
std::ostream& operator<<(std::ostream& os, const GDigitizedData& data) {
141-
os << "GDigitizedData{identity=\"" << data.getIdentityString() << "\"";
132+
133+
auto idString = getIdentityString(data.gidentity);
134+
135+
os << "GDigitizedData{identity=\"" << idString << "\"";
142136

143137
if (!data.intObservablesMap.empty()) {
144138
os << ", intObservables={";

gdata/gDigitizedData.h

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323
* Identity:
2424
* - the object copies the hit identity from the source GHit
2525
* - the identity is preserved independently of the originating hit lifetime
26-
* - a readable representation is available through
27-
* \ref GDigitizedData::getIdentityString "getIdentityString()"
2826
*
2927
* Event and integration semantics:
3028
* - \ref GDigitizedData::includeVariable "includeVariable()" stores or overwrites per-hit values
@@ -132,19 +130,6 @@ class GDigitizedData : public GBase<GDigitizedData>
132130
*/
133131
GDigitizedData(const std::shared_ptr<GOptions>& gopts, const GHit* ghit);
134132

135-
/**
136-
* \brief Builds a readable identity string from the stored hit identifiers.
137-
*
138-
* \details
139-
* The generated format is:
140-
* \code
141-
* name1->value1, name2->value2, ...
142-
* \endcode
143-
*
144-
* \return Identity string assembled from the stored \c gidentity vector.
145-
*/
146-
[[nodiscard]] std::string getIdentityString() const;
147-
148133
/**
149134
* \brief Stores or overwrites one integer observable for this hit.
150135
*
@@ -289,6 +274,14 @@ class GDigitizedData : public GBase<GDigitizedData>
289274
return arrayDoubleObservablesMap;
290275
}
291276

277+
/**
278+
*
279+
* \brief Returns the identifier vectory
280+
*
281+
* @return gidentity
282+
*/
283+
[[nodiscard]] inline const std::vector<GIdentifier>& getIdentity() const { return gidentity; }
284+
292285
/**
293286
* \brief Creates deterministic example data for tests and examples.
294287
*

gdata/gTrueInfoData.cc

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,18 +48,11 @@ void GTrueInfoData::accumulateVariable(const std::string& vname, double value) {
4848
}
4949
}
5050

51-
std::string GTrueInfoData::getIdentityString() const {
52-
// Build a compact label from the stored identifier vector.
53-
std::string identifierString;
54-
for (size_t i = 0; i < gidentity.size() - 1; i++) {
55-
identifierString += gidentity[i].getName() + "->" + std::to_string(gidentity[i].getValue()) + ", ";
56-
}
57-
identifierString += gidentity.back().getName() + "->" + std::to_string(gidentity.back().getValue());
58-
return identifierString;
59-
}
6051

6152
std::ostream& operator<<(std::ostream& os, const GTrueInfoData& data) {
62-
os << "GTrueInfoData{identity=\"" << data.getIdentityString() << "\"";
53+
auto idString = getIdentityString(data.gidentity);
54+
55+
os << "GTrueInfoData{identity=\"" << idString << "\"";
6356

6457
if (!data.doubleObservablesMap.empty()) {
6558
os << ", doubleObservables={";

gdata/gTrueInfoData.h

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@
3030
* Identity model:
3131
* - each object stores a copy of the hit identity vector extracted from GHit
3232
* - the identity is preserved independently of the originating hit lifetime
33-
* - a readable representation is available through
34-
* \ref GTrueInfoData::getIdentityString "getIdentityString()"
3533
*
3634
* Threading:
3735
* - regular instances do not share mutable state
@@ -122,24 +120,6 @@ class GTrueInfoData : public GBase<GTrueInfoData>
122120
*/
123121
GTrueInfoData(const std::shared_ptr<GOptions>& gopts, const GHit* ghit);
124122

125-
/**
126-
* \brief Builds a readable identity string from the stored hit identifiers.
127-
*
128-
* \details
129-
* The generated format is:
130-
* \code
131-
* name1->value1, name2->value2, ...
132-
* \endcode
133-
*
134-
* This string is intended for:
135-
* - logs
136-
* - debugging output
137-
* - human-readable summaries
138-
*
139-
* \return Identity string assembled from the stored \c gidentity vector.
140-
*/
141-
[[nodiscard]] std::string getIdentityString() const;
142-
143123
/**
144124
* \brief Stores or overwrites one numeric truth observable.
145125
*
@@ -249,6 +229,14 @@ class GTrueInfoData : public GBase<GTrueInfoData>
249229
return true_info_data;
250230
}
251231

232+
/**
233+
*
234+
* \brief Returns the identifier vectory
235+
*
236+
* @return gidentity
237+
*/
238+
[[nodiscard]] inline const std::vector<GIdentifier>& getIdentity() const { return gidentity; }
239+
252240
private:
253241
/**
254242
* \brief Numeric truth observables.

gdynamicDigitization/gDosimeterDigitization.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,13 @@ bool GDosimeterDigitization::defineReadoutSpecsImpl() {
2828

2929
// See header for API docs.
3030
std::unique_ptr<GDigitizedData> GDosimeterDigitization::digitizeHitImpl(GHit* ghit, [[maybe_unused]] size_t hitn) {
31+
32+
auto gdata = std::make_unique<GDigitizedData>(gopts, ghit);
33+
3134
auto etot = ghit->getTotalEnergyDeposited();
3235
auto mass = ghit->getMass();
3336
auto dose = etot / mass;
3437

35-
auto gdata = std::make_unique<GDigitizedData>(gopts, ghit);
36-
3738
// Store the detector identity and the total deposited energy.
3839
gdata->includeVariable("etot", etot / MeV);
3940
gdata->includeVariable("dose", dose / gemc_units::picogray);

gdynamicDigitization/gFluxDigitization.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ std::unique_ptr<GDigitizedData> GFluxDigitization::digitizeHitImpl(GHit* ghit, s
1818

1919
auto gdata = std::make_unique<GDigitizedData>(gopts, ghit);
2020

21-
gdata->includeVariable(identity.getName(), identity.getValue());
2221
gdata->includeVariable("hitn", static_cast<int>(hitn));
2322
gdata->includeVariable("totEdep", ghit->getTotalEnergyDeposited());
2423
gdata->includeVariable("time", ghit->getAverageTime());

ghit/ghit.h

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class GHit : public G4VHit
5656
* a simple hard-coded scheme but keeps this field for future expansion.
5757
*/
5858
GHit(std::shared_ptr<GTouchable> gt, HitBitSet hbs, const G4Step* thisStep = nullptr,
59-
const std::string& cScheme = "default");
59+
const std::string& cScheme = "default");
6060

6161
/**
6262
* \brief Destructor.
@@ -484,3 +484,21 @@ inline void GHit::operator delete(void* hit) {
484484

485485
GHitAllocator->FreeSingle((GHit*)hit);
486486
}
487+
488+
[[nodiscard]] inline std::string getIdentityString(std::vector<GIdentifier> gidentity) {
489+
// Build a compact label from the stored identifier vector.
490+
std::string identifierString;
491+
for (size_t i = 0; i < gidentity.size() - 1; i++) {
492+
identifierString += gidentity[i].getName() + "->" + std::to_string(gidentity[i].getValue()) + ", ";
493+
}
494+
identifierString += gidentity.back().getName() + "->" + std::to_string(gidentity.back().getValue());
495+
return identifierString;
496+
}
497+
498+
[[nodiscard]] inline std::map<std::string, int> getIdentityMap(std::vector<GIdentifier> gidentity) {
499+
std::map<std::string, int> identityMap;
500+
for (auto& id : gidentity) {
501+
identityMap[id.getName()] = id.getValue();
502+
}
503+
return identityMap;
504+
}

gstreamer/factories/ASCII/event/publishDigitized.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ bool GstreamerTextFactory::publishEventDigitizedDataImpl(const std::string&
1313
ofile << GTAB << "Detector <" << detectorName << "> Digitized Bank {\n";
1414

1515
for (auto dgtzHit : digitizedData) {
16-
std::string identifierString = dgtzHit->getIdentityString();
16+
auto identifierString = getIdentityString(dgtzHit->getIdentity());
1717

1818
ofile << GTABTAB << "Hit address: " << identifierString << " {\n";
1919

gstreamer/factories/ASCII/event/publishTrueInfo.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ bool GstreamerTextFactory::publishEventTrueInfoDataImpl(const std::string&
1313
ofile << GTAB << "Detector <" << detectorName << "> True Info Bank {\n";
1414

1515
for (auto trueInfoHit : trueInfoData) {
16-
std::string identifierString = trueInfoHit->getIdentityString();
16+
auto identifierString = getIdentityString(trueInfoHit->getIdentity());
1717

1818
ofile << GTABTAB << "Hit address: " << identifierString << " {\n";
1919

0 commit comments

Comments
 (0)