gdata
Loading...
Searching...
No Matches
gDigitizedData.h
Go to the documentation of this file.
1#pragma once
2
46#include <atomic>
47#include <map>
48#include <ostream>
49#include <string>
50#include <vector>
51
52// gemc
53#include "gbase.h"
54#include "ghit.h"
55
56// gdata
57#include "gdataConventions.h"
58
60constexpr const char* GDIGITIZED_DATA_LOGGER = "digitized_data";
61
62namespace gdigi_data {
63
77
78} // namespace gdigi_data
79
115class GDigitizedData : public GBase<GDigitizedData>
116{
117public:
133 GDigitizedData(const std::shared_ptr<GOptions>& gopts, const GHit* ghit);
134
146 [[nodiscard]] std::string getIdentityString() const;
147
158 void includeVariable(const std::string& vname, int value);
159
170 void includeVariable(const std::string& vname, double value);
171
185 void accumulateVariable(const std::string& vname, int value);
186
200 void accumulateVariable(const std::string& vname, double value);
201
215 [[nodiscard]] std::map<std::string, int> getIntObservablesMap(int which) const;
216
227 [[nodiscard]] std::map<std::string, double> getDblObservablesMap(int which) const;
228
242
253 int getIntObservable(const std::string& varName);
254
265 double getDblObservable(const std::string& varName);
266
275 [[nodiscard]] inline std::map<std::string, std::vector<int>> getArrayIntObservablesMap() const {
276 return arrayIntObservablesMap;
277 }
278
288 [[nodiscard]] inline std::map<std::string, std::vector<double>> getArrayDblObservablesMap() const {
289 return arrayDoubleObservablesMap;
290 }
291
308 static std::unique_ptr<GDigitizedData> create(const std::shared_ptr<GOptions>& gopts) {
309 auto hit = GHit::create(gopts);
310 auto digi_data = std::make_unique<GDigitizedData>(gopts, hit);
311 auto counter = globalDigitizedDataCounter.fetch_add(1, std::memory_order_relaxed);
312
313 digi_data->includeVariable(CRATESTRINGID, counter % 10);
314 digi_data->includeVariable(SLOTSTRINGID, counter % 20);
315 digi_data->includeVariable(CHANNELSTRINGID, counter);
316 digi_data->includeVariable(TIMEATELECTRONICS, counter * 5);
317 digi_data->includeVariable("adc", counter * 0.1);
318 return digi_data;
319 }
320
321private:
323 std::map<std::string, int> intObservablesMap;
324
326 std::map<std::string, double> doubleObservablesMap;
327
329 std::map<std::string, std::vector<int>> arrayIntObservablesMap;
330
332 std::map<std::string, std::vector<double>> arrayDoubleObservablesMap;
333
335 std::vector<GIdentifier> gidentity;
336
351 [[nodiscard]] static bool validVarName(const std::string& varName, int which);
352
359 static std::atomic<int> globalDigitizedDataCounter;
360
361protected:
362 friend std::ostream& operator<<(std::ostream& os, const GDigitizedData& data);
363};
Stores digitized, electronics-level observables for one hit.
void accumulateVariable(const std::string &vname, int value)
Accumulates one integer observable into the current object.
static std::unique_ptr< GDigitizedData > create(const std::shared_ptr< GOptions > &gopts)
Creates deterministic example data for tests and examples.
int getIntObservable(const std::string &varName)
Returns one integer observable by key.
std::map< std::string, int > getIntObservablesMap(int which) const
Returns a filtered copy of the integer observables map.
int getTimeAtElectronics()
Returns the conventional timeAtElectronics integer observable when present.
void includeVariable(const std::string &vname, int value)
Stores or overwrites one integer observable for this hit.
friend std::ostream & operator<<(std::ostream &os, const GDigitizedData &data)
std::map< std::string, double > getDblObservablesMap(int which) const
Returns a filtered copy of the floating-point observables map.
GDigitizedData(const std::shared_ptr< GOptions > &gopts, const GHit *ghit)
Constructs the object and copies the hit identity from the source hit.
double getDblObservable(const std::string &varName)
Returns one floating-point observable by key.
std::string getIdentityString() const
Builds a readable identity string from the stored hit identifiers.
std::map< std::string, std::vector< int > > getArrayIntObservablesMap() const
Returns a copy of the array-valued integer observables.
std::map< std::string, std::vector< double > > getArrayDblObservablesMap() const
Returns a copy of the array-valued floating-point observables.
static GHit * create(const std::shared_ptr< GOptions > &gopts)
constexpr const char * GDIGITIZED_DATA_LOGGER
Logger domain name used by GDigitizedData.
Shared constants, schema keys, and error codes for the GData module.
constexpr const char * TIMEATELECTRONICS
Electronics-stage time or TDC proxy.
constexpr const char * CRATESTRINGID
Electronics crate identifier.
constexpr const char * CHANNELSTRINGID
Channel index within the slot or module.
constexpr const char * SLOTSTRINGID
Slot index within the crate.
GOptions defineOptions()
Defines the options subtree used by the digitized-data logger domain.