gdata
Loading...
Searching...
No Matches
gDigitizedData.cc
Go to the documentation of this file.
1
6#include "gDigitizedData.h"
7#include "gdataConventions.h"
8
9// c++
10#include <string>
11#include <map>
12#include <vector>
13
14#include "gdynamicDigitization/gdynamicdigitization_options.h"
15
16std::atomic<int> GDigitizedData::globalDigitizedDataCounter{0};
17
18GDigitizedData::GDigitizedData(const std::shared_ptr<GOptions>& gopts, const GHit* ghit) : GBase(gopts, GDIGITIZED_DATA_LOGGER) {
19 gidentity = ghit->getGID();
20}
21
22std::map<std::string, int> GDigitizedData::getIntObservablesMap(int which) const {
23 std::map<std::string, int> filteredIntObservablesMap;
24 for (const auto& [varName, value] : intObservablesMap) { if (validVarName(varName, which)) { filteredIntObservablesMap[varName] = value; } }
25 log->info(2, " getting ", which, " from intObservablesMap.");
26 return filteredIntObservablesMap;
27}
28
29std::map<std::string, double> GDigitizedData::getDblObservablesMap(int which) const {
30 std::map<std::string, double> filteredDblObservablesMap;
31 for (const auto& [varName, value] : doubleObservablesMap) { if (validVarName(varName, which)) { filteredDblObservablesMap[varName] = value; } }
32 log->info(2, " getting ", which, " from doubleObservablesMap.");
33 return filteredDblObservablesMap;
34}
35
36bool GDigitizedData::validVarName(const std::string& varName, int which) {
37 bool isSROVar = (varName == CRATESTRINGID || varName == SLOTSTRINGID || varName == CHANNELSTRINGID ||
38 varName == CHARGEATELECTRONICS || varName == TIMEATELECTRONICS);
39 if (which == 0) { if (isSROVar) { return false; } }
40 else if (which == 1) { if (!isSROVar) { return false; } }
41 return true;
42}
43
44void GDigitizedData::includeVariable(const std::string& vname, int value) {
45 log->info(2, "Including int variable ", vname, " with value ", value);
46 intObservablesMap[vname] = value;
47}
48
49void GDigitizedData::includeVariable(const std::string& vname, double value) {
50 log->info(2, "double variable ", vname, " with value ", value);
51 doubleObservablesMap[vname] = value;
52}
53
55 if (intObservablesMap.find(TIMEATELECTRONICS) == intObservablesMap.end()) { return TIMEATELECTRONICSNOTDEFINED; }
56 log->info(2, "Getting TIMEATELECTRONICS from intObservablesMap.");
57 return intObservablesMap[TIMEATELECTRONICS];
58}
59
60int GDigitizedData::getIntObservable(const std::string& varName) {
61 if (intObservablesMap.find(varName) == intObservablesMap.end()) {
62 log->error(ERR_VARIABLENOTFOUND, "variable name <" + varName + "> not found in GDigitizedData::intObservablesMap");
63 }
64 return intObservablesMap[varName];
65}
66
67double GDigitizedData::getDblObservable(const std::string& varName) {
68 if (doubleObservablesMap.find(varName) == doubleObservablesMap.end()) {
69 log->error(ERR_VARIABLENOTFOUND, "variable name <" + varName + "> not found in GDigitizedData::doubleObservablesMap");
70 }
71 return doubleObservablesMap[varName];
72}
73
75 std::string identifierString;
76 for (size_t i = 0; i < gidentity.size() - 1; i++) { identifierString += gidentity[i].getName() + "->" + std::to_string(gidentity[i].getValue()) + ", "; }
77 identifierString += gidentity.back().getName() + "->" + std::to_string(gidentity.back().getValue());
78 return identifierString;
79}
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.
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 int ERR_VARIABLENOTFOUND
Exit code when a variable is not found.
constexpr const char * SLOTSTRINGID
Identifier for slot.
constexpr int TIMEATELECTRONICSNOTDEFINED
Default value for undefined time at electronics.
constexpr const char * CHARGEATELECTRONICS
Identifier for charge at electronics.