gdata
Loading...
Searching...
No Matches
gDigitizedData.h
Go to the documentation of this file.
1#pragma once
2
44#include <atomic>
45#include <map>
46#include <ostream>
47#include <string>
48#include <vector>
49
50// gemc
51#include "gbase.h"
52#include "ghit.h"
53
54// gdata
55#include "gdataConventions.h"
56
58constexpr const char* GDIGITIZED_DATA_LOGGER = "digitized_data";
59
60namespace gdigi_data {
61
75
76} // namespace gdigi_data
77
113class GDigitizedData : public GBase<GDigitizedData>
114{
115public:
131 GDigitizedData(const std::shared_ptr<GOptions>& gopts, const GHit* ghit);
132
143 void includeVariable(const std::string& vname, int value);
144
155 void includeVariable(const std::string& vname, double value);
156
170 void accumulateVariable(const std::string& vname, int value);
171
185 void accumulateVariable(const std::string& vname, double value);
186
200 [[nodiscard]] std::map<std::string, int> getIntObservablesMap(int which) const;
201
212 [[nodiscard]] std::map<std::string, double> getDblObservablesMap(int which) const;
213
227
238 int getIntObservable(const std::string& varName);
239
250 double getDblObservable(const std::string& varName);
251
260 [[nodiscard]] inline std::map<std::string, std::vector<int>> getArrayIntObservablesMap() const {
261 return arrayIntObservablesMap;
262 }
263
273 [[nodiscard]] inline std::map<std::string, std::vector<double>> getArrayDblObservablesMap() const {
274 return arrayDoubleObservablesMap;
275 }
276
283 [[nodiscard]] inline const std::vector<GIdentifier>& getIdentity() const { return gidentity; }
284
301 static std::unique_ptr<GDigitizedData> create(const std::shared_ptr<GOptions>& gopts) {
302 auto hit = GHit::create(gopts);
303 auto digi_data = std::make_unique<GDigitizedData>(gopts, hit);
304 auto counter = globalDigitizedDataCounter.fetch_add(1, std::memory_order_relaxed);
305
306 digi_data->includeVariable(CRATESTRINGID, counter % 10);
307 digi_data->includeVariable(SLOTSTRINGID, counter % 20);
308 digi_data->includeVariable(CHANNELSTRINGID, counter);
309 digi_data->includeVariable(TIMEATELECTRONICS, counter * 5);
310 digi_data->includeVariable("adc", counter * 0.1);
311 return digi_data;
312 }
313
314private:
316 std::map<std::string, int> intObservablesMap;
317
319 std::map<std::string, double> doubleObservablesMap;
320
322 std::map<std::string, std::vector<int>> arrayIntObservablesMap;
323
325 std::map<std::string, std::vector<double>> arrayDoubleObservablesMap;
326
328 std::vector<GIdentifier> gidentity;
329
344 [[nodiscard]] static bool validVarName(const std::string& varName, int which);
345
352 static std::atomic<int> globalDigitizedDataCounter;
353
354protected:
355 friend std::ostream& operator<<(std::ostream& os, const GDigitizedData& data);
356};
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.
const std::vector< GIdentifier > & getIdentity() const
Returns the identifier vectory.
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::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.