gdata
Loading...
Searching...
No Matches
gDigitizedData.h
Go to the documentation of this file.
1#pragma once
2
36// c++
37#include <string>
38#include <map>
39#include <vector>
40#include <atomic>
41
42// gemc
43#include "ghit.h"
44#include "gbase.h"
45
46// gdata
47#include "gdataConventions.h" // CRATESTRINGID, SLOTSTRINGID, CHANNELSTRINGID, TIMEATELECTRONICS, ...
48
50constexpr const char* GDIGITIZED_DATA_LOGGER = "digitized_data";
51
52namespace gdigi_data {
66} // namespace gdigi_data
67
85class GDigitizedData : public GBase<GDigitizedData>
86{
87public:
102 GDigitizedData(const std::shared_ptr<GOptions>& gopts, const GHit* ghit);
103
115 [[nodiscard]] std::string getIdentityString() const;
116
131 void includeVariable(const std::string& vname, int value);
132
134 void includeVariable(const std::string& vname, double value);
151 void accumulateVariable(const std::string& vname, int value);
152
154 void accumulateVariable(const std::string& vname, double value);
168 [[nodiscard]] std::map<std::string, int> getIntObservablesMap(int which) const;
169
180 [[nodiscard]] std::map<std::string, double> getDblObservablesMap(int which) const;
181
192
203 int getIntObservable(const std::string& varName);
204
214 double getDblObservable(const std::string& varName);
215
227 [[nodiscard]] inline std::map<std::string, std::vector<int>> getArrayIntObservablesMap() const {
228 return arrayIntObservablesMap;
229 }
230
239 [[nodiscard]] inline std::map<std::string, std::vector<double>> getArrayDblObservablesMap() const {
240 return arrayDoubleObservablesMap;
241 }
242
258 static std::unique_ptr<GDigitizedData> create(const std::shared_ptr<GOptions>& gopts) {
259 auto hit = GHit::create(gopts);
260 auto digi_data = std::make_unique<GDigitizedData>(gopts, hit);
261 auto counter = globalDigitizedDataCounter.fetch_add(1, std::memory_order_relaxed);
262
263 digi_data->includeVariable(CRATESTRINGID, counter % 10);
264 digi_data->includeVariable(SLOTSTRINGID, counter % 20);
265 digi_data->includeVariable(CHANNELSTRINGID, counter);
266 digi_data->includeVariable(TIMEATELECTRONICS, counter * 5);
267 digi_data->includeVariable("adc", counter * 0.1);
268 return digi_data;
269 }
270
271private:
273 std::map<std::string, int> intObservablesMap;
274
276 std::map<std::string, double> doubleObservablesMap;
277
279 std::map<std::string, std::vector<int>> arrayIntObservablesMap;
280
282 std::map<std::string, std::vector<double>> arrayDoubleObservablesMap;
283
285 std::vector<GIdentifier> gidentity;
286
300 [[nodiscard]] static bool validVarName(const std::string& varName, int which);
301
303 static std::atomic<int> globalDigitizedDataCounter;
304};
Container for digitized (electronics-level) observables for one hit.
void accumulateVariable(const std::string &vname, int value)
Accumulate an integer observable (run-level integration).
static std::unique_ptr< GDigitizedData > create(const std::shared_ptr< GOptions > &gopts)
Test/example factory: create a digitized hit with deterministic dummy data.
int getIntObservable(const std::string &varName)
Retrieve one integer observable by name.
std::map< std::string, int > getIntObservablesMap(int which) const
Return a filtered copy of the integer observables map.
int getTimeAtElectronics()
Convenience accessor for TIMEATELECTRONICS.
void includeVariable(const std::string &vname, int value)
Store/overwrite an integer observable for this hit (event-level).
std::map< std::string, double > getDblObservablesMap(int which) const
Return a filtered copy of the double observables map.
GDigitizedData(const std::shared_ptr< GOptions > &gopts, const GHit *ghit)
Construct digitized data by copying identity from a hit.
double getDblObservable(const std::string &varName)
Retrieve one double observable by name.
std::string getIdentityString() const
Return a human-readable identity string for debugging and labeling.
std::map< std::string, std::vector< int > > getArrayIntObservablesMap() const
Get the array-valued integer observables map.
std::map< std::string, std::vector< double > > getArrayDblObservablesMap() const
Get the array-valued double observables map.
static GHit * create(const std::shared_ptr< GOptions > &gopts)
constexpr const char * GDIGITIZED_DATA_LOGGER
Logger domain name used by GDigitizedData (controls verbosity/category in GLogger).
Shared constants and error codes for the GData library.
constexpr const char * TIMEATELECTRONICS
Time (or TDC proxy) at electronics stage.
constexpr const char * CRATESTRINGID
Electronics crate index.
constexpr const char * CHANNELSTRINGID
Channel index within a slot/module.
constexpr const char * SLOTSTRINGID
Slot index within a crate (module position).
GOptions defineOptions()
Defines GOptions for the digitized-data logger domain.