gdata
Loading...
Searching...
No Matches
gDigitizedData.h
Go to the documentation of this file.
1#pragma once
2
11// c++
12#include <string>
13#include <map>
14#include <vector>
15#include <atomic>
16
17// gemc
18#include "ghit.h"
19#include "gbase.h"
20
21// gdata
22#include "gdataConventions.h" // for CRATESTRINGID, SLOTSTRINGID, CHANNELSTRINGID, TIMEATELECTRONICS
23
24constexpr const char* GDIGITIZED_DATA_LOGGER = "digitized_data";
25
26namespace gdigi_data {
27inline GOptions defineOptions() {
28 auto goptions = GOptions(GDIGITIZED_DATA_LOGGER);
29 return goptions;
30}
31}
32
33
34class GDigitizedData : public GBase<GDigitizedData> {
35public:
41 GDigitizedData(const std::shared_ptr<GOptions>& gopts, const GHit* ghit);
42
47 [[nodiscard]] std::string getIdentityString() const;
48
49 // Public interface to add data to a hit:
50 void includeVariable(const std::string& vname, int value);
51 void includeVariable(const std::string& vname, double value);
52 // void includeVariable(std::string vname, std::vector<int> values);
53
59 [[nodiscard]] std::map<std::string, int> getIntObservablesMap(int which) const;
60
66 [[nodiscard]] std::map<std::string, double> getDblObservablesMap(int which) const;
67
76
77 int getIntObservable(const std::string& varName);
78 double getDblObservable(const std::string& varName);
79
84 [[nodiscard]] inline std::map<std::string, std::vector<int>> getArrayIntObservablesMap() const { return arrayIntObservablesMap; }
85
90 [[nodiscard]] inline std::map<std::string, std::vector<double>> getArrayDblObservablesMap() const { return arrayDoubleObservablesMap; }
91
92
93 static std::unique_ptr<GDigitizedData> create(const std::shared_ptr<GOptions>& gopts) {
94 auto hit = GHit::create(gopts);
95 auto digi_data = std::make_unique<GDigitizedData>(gopts, hit);
96 auto counter = globalDigitizedDataCounter.fetch_add(1, std::memory_order_relaxed);
97
98 digi_data->includeVariable(CRATESTRINGID, counter % 10);
99 digi_data->includeVariable(SLOTSTRINGID, counter % 20);
100 digi_data->includeVariable(CHANNELSTRINGID, counter);
101 digi_data->includeVariable(TIMEATELECTRONICS, counter * 5);
102 digi_data->includeVariable("adc", counter * 0.1);
103 return digi_data;
104 }
105
106private:
107 std::map<std::string, int> intObservablesMap;
108 std::map<std::string, double> doubleObservablesMap;
109 std::map<std::string, std::vector<int>> arrayIntObservablesMap;
110 std::map<std::string, std::vector<double>> arrayDoubleObservablesMap;
111 std::vector<GIdentifier> gidentity;
112 [[nodiscard]] static bool validVarName(const std::string& varName, int which);
113
115 static std::atomic<int> globalDigitizedDataCounter;
116};
static std::unique_ptr< GDigitizedData > create(const std::shared_ptr< GOptions > &gopts)
int getIntObservable(const std::string &varName)
std::map< std::string, int > getIntObservablesMap(int which) const
Returns the filtered map of integer observables.
int getTimeAtElectronics()
Gets the time at electronics.
void includeVariable(const std::string &vname, int value)
std::map< std::string, double > getDblObservablesMap(int which) const
Returns the filtered map of double observables.
GDigitizedData(const std::shared_ptr< GOptions > &gopts, const GHit *ghit)
Constructs a GDigitizedData object from a GHit.
double getDblObservable(const std::string &varName)
std::string getIdentityString() const
Returns a string representation of the hit identity.
std::map< std::string, std::vector< int > > getArrayIntObservablesMap() const
Returns the map of integer array observables.
std::map< std::string, std::vector< double > > getArrayDblObservablesMap() const
Returns the map of double array observables.
constexpr const char * GDIGITIZED_DATA_LOGGER
Defines constants and exit codes for the GData library.
constexpr const char * TIMEATELECTRONICS
Identifier for time at electronics.
constexpr const char * CRATESTRINGID
Identifier for crate.
constexpr const char * CHANNELSTRINGID
Identifier for channel.
constexpr const char * SLOTSTRINGID
Identifier for slot.
GOptions defineOptions()