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 <gemc/gbase/gbase.h>
52#include <gemc/ghit/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
166 void includeTransientVariable(const std::string& vname, double value);
167
174 [[nodiscard]] bool hasTransientVariable(const std::string& vname) const;
175
184 [[nodiscard]] double getTransientVariable(const std::string& vname) const;
185
199 void accumulateVariable(const std::string& vname, int value);
200
214 void accumulateVariable(const std::string& vname, double value);
215
229 [[nodiscard]] std::map<std::string, int> getIntObservablesMap(int which) const;
230
241 [[nodiscard]] std::map<std::string, double> getDblObservablesMap(int which) const;
242
256
267 int getIntObservable(const std::string& varName);
268
279 double getDblObservable(const std::string& varName);
280
289 [[nodiscard]] inline std::map<std::string, std::vector<int>> getArrayIntObservablesMap() const {
290 return arrayIntObservablesMap;
291 }
292
302 [[nodiscard]] inline std::map<std::string, std::vector<double>> getArrayDblObservablesMap() const {
303 return arrayDoubleObservablesMap;
304 }
305
312 [[nodiscard]] inline const std::vector<GIdentifier>& getIdentity() const { return gidentity; }
313
330 static std::unique_ptr<GDigitizedData> create(const std::shared_ptr<GOptions>& gopts) {
331 auto hit = GHit::create(gopts);
332 auto digi_data = std::make_unique<GDigitizedData>(gopts, hit);
333 auto counter = globalDigitizedDataCounter.fetch_add(1, std::memory_order_relaxed);
334
335 digi_data->includeVariable(CRATESTRINGID, counter % 10);
336 digi_data->includeVariable(SLOTSTRINGID, counter % 20);
337 digi_data->includeVariable(CHANNELSTRINGID, counter);
338 digi_data->includeVariable(TIMEATELECTRONICS, counter * 5);
339 digi_data->includeVariable("adc", counter * 0.1);
340 return digi_data;
341 }
342
343private:
345 std::map<std::string, int> intObservablesMap;
346
348 std::map<std::string, double> doubleObservablesMap;
349
351 std::map<std::string, double> transientVariablesMap;
352
354 std::map<std::string, std::vector<int>> arrayIntObservablesMap;
355
357 std::map<std::string, std::vector<double>> arrayDoubleObservablesMap;
358
360 std::vector<GIdentifier> gidentity;
361
376 [[nodiscard]] static bool validVarName(const std::string& varName, int which);
377
384 static std::atomic<int> globalDigitizedDataCounter;
385
386protected:
387 friend std::ostream& operator<<(std::ostream& os, const GDigitizedData& data);
388};
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.
bool hasTransientVariable(const std::string &vname) const
Returns whether a transient floating-point value is present.
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.
double getTransientVariable(const std::string &vname) const
Returns a transient floating-point value by key.
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.
void includeTransientVariable(const std::string &vname, double value)
Stores a non-published floating-point value for post-digitization decisions.
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.