gdata
Loading...
Searching...
No Matches
gTrueInfoData.cc
Go to the documentation of this file.
1
10// See header for API docs.
11
12#include "gTrueInfoData.h"
13#include <string>
14#include <utility>
15
22std::atomic<int> GTrueInfoData::globalTrueInfoDataCounter{0};
23
24GTrueInfoData::GTrueInfoData(const std::shared_ptr<GOptions>& gopts, const GHit* ghit)
25 : GBase(gopts, GTRUEDATA_LOGGER) {
26 // The "identity" is a vector of (name,value) pairs that uniquely identifies
27 // the hit within a detector (e.g. sector/layer/component).
28 //
29 // Ownership and lifetime:
30 // - This constructor does not own the GHit pointer.
31 // - We copy the identifier vector out of the hit so the GTrueInfoData is self-contained
32 // and safe to use after the originating hit object has gone out of scope.
33 gidentity = ghit->getGID();
34}
35
36void GTrueInfoData::includeVariable(const std::string& varName, double value) {
37 // Store/overwrite a per-hit "true" numeric observable.
38 //
39 // Semantics:
40 // - Overwrite: repeated calls with the same key replace the previous value.
41 doubleObservablesMap[varName] = value;
42 log->info(2, FUNCTION_NAME, " including ", varName, " in trueInfoDoublesVariablesMap with value: ", value);
43}
44
45void GTrueInfoData::includeVariable(const std::string& varName, std::string value) {
46 // Store/overwrite a per-hit "true" string observable.
47 //
48 // Semantics:
49 // - Overwrite: repeated calls with the same key replace the previous value.
50 //
51 // Performance note:
52 // - \p value is moved into the internal map to avoid an extra copy when callers pass temporaries.
53 log->info(2, FUNCTION_NAME, " including ", varName, " in trueInfoStringVariablesMap with value:", value);
54 stringVariablesMap[varName] = std::move(value);
55}
56
57void GTrueInfoData::accumulateVariable(const std::string& vname, double value) {
58 // Accumulate is meant for run-level (integrated) quantities.
59 //
60 // Semantics (summation):
61 // - First contribution creates the key with the provided value.
62 // - Subsequent contributions add to the existing value (running sum).
63 if (doubleObservablesMap.find(vname) == doubleObservablesMap.end()) {
64 doubleObservablesMap[vname] = value;
65 log->info(2, FUNCTION_NAME, "Creating double variable ", vname, " with value ", value, ", sum is now:",
66 doubleObservablesMap[vname]);
67 }
68 else {
69 doubleObservablesMap[vname] += value;
70 log->info(2, FUNCTION_NAME, "Accumulating double variable ", vname, " with value ", value, ", sum is now:",
71 doubleObservablesMap[vname]);
72 }
73}
74
76 // Build a concise identity label from the \c gidentity vector.
77 //
78 // Output format:
79 // name1->value1, name2->value2, ...
80 std::string identifierString;
81 for (size_t i = 0; i < gidentity.size() - 1; i++) {
82 identifierString += gidentity[i].getName() + "->" + std::to_string(gidentity[i].getValue()) + ", ";
83 }
84 identifierString += gidentity.back().getName() + "->" + std::to_string(gidentity.back().getValue());
85 return identifierString;
86}
std::shared_ptr< GLogger > log
std::vector< GIdentifier > getGID() const
void info(int level, Args &&... args) const
void includeVariable(const std::string &varName, double var)
Store/overwrite a numeric "true" observable for this hit.
void accumulateVariable(const std::string &vname, double value)
Accumulate a numeric observable into this object (run-level integration).
GTrueInfoData(const std::shared_ptr< GOptions > &gopts, const GHit *ghit)
Construct true-hit data by copying identity from a hit.
std::string getIdentityString() const
Return a human-readable identity string for debugging and labeling.
Container for "true" (simulation-level) observables associated with one hit.
constexpr const char * GTRUEDATA_LOGGER
Logger domain name used by GTrueInfoData (controls verbosity/category in GLogger).
#define FUNCTION_NAME