gdata
gDigitizedData.cc
Go to the documentation of this file.
1 
6 #include "gDigitizedData.h"
7 #include "../gdataConventions.h"
8 #include <string>
9 #include <map>
10 #include <vector>
11 
12 GDigitizedData::GDigitizedData(GHit *ghit, const std::shared_ptr<GLogger>& logger) : log(std::move(logger)) {
13  log->debug(CONSTRUCTOR, "GDigitizedData");
14  gidentity = ghit->getGID();
15 }
16 
17 std::map<std::string, int> GDigitizedData::getIntObservablesMap(int which) const {
18  std::map<std::string, int> filteredIntObservablesMap;
19  for (const auto& [varName, value] : intObservablesMap) {
20  if (validVarName(varName, which)) {
21  filteredIntObservablesMap[varName] = value;
22  }
23  }
24  log->debug(NORMAL, " getting ", which, " from intObservablesMap.");
25  return filteredIntObservablesMap;
26 }
27 
28 std::map<std::string, float> GDigitizedData::getFltObservablesMap(int which) const {
29  std::map<std::string, float> filteredFltObservablesMap;
30  for (const auto& [varName, value] : doubleObservablesMap) {
31  if (validVarName(varName, which)) {
32  filteredFltObservablesMap[varName] = value;
33  }
34  }
35  log->debug(NORMAL, " getting ", which, " from doubleObservablesMap.");
36  return filteredFltObservablesMap;
37 }
38 
39 bool GDigitizedData::validVarName(const std::string& varName, int which) const {
40  bool isSROVar = (varName == CRATESTRINGID || varName == SLOTSTRINGID || varName == CHANNELSTRINGID ||
41  varName == CHARGEATELECTRONICS || varName == TIMEATELECTRONICS);
42  if (which == 0) {
43  if (isSROVar) {
44  return false;
45  }
46  } else if (which == 1) {
47  if (!isSROVar) {
48  return false;
49  }
50  }
51  return true;
52 }
53 
54 void GDigitizedData::includeVariable(const std::string& vname, int value) {
55  log->debug(NORMAL, "Including int variable ", vname, " with value ", value);
56  intObservablesMap[vname] = value;
57 }
58 
59 void GDigitizedData::includeVariable(const std::string& vname, double value) {
60  log->debug(NORMAL, "Including float variable ", vname, " with value ", value);
61  doubleObservablesMap[vname] = value;
62 }
63 
65  if (intObservablesMap.find(TIMEATELECTRONICS) == intObservablesMap.end()) {
67  }
68  log->debug(NORMAL, "Getting TIMEATELECTRONICS from intObservablesMap.");
69  return intObservablesMap[TIMEATELECTRONICS];
70 }
71 
72 int GDigitizedData::getIntObservable(std::string varName) {
73  if (intObservablesMap.find(varName) == intObservablesMap.end()) {
74  log->error(EC__VARIABLENOTFOUND, "variable name <" + varName + "> not found in GDigitizedData::intObservablesMap");
75  }
76  return intObservablesMap[varName];
77 }
78 
79 float GDigitizedData::getFltObservable(std::string varName) {
80  if (doubleObservablesMap.find(varName) == doubleObservablesMap.end()) {
81  log->error(EC__VARIABLENOTFOUND, "variable name <" + varName + "> not found in GDigitizedData::doubleObservablesMap");
82  }
83  return doubleObservablesMap[varName];
84 }
85 
87  std::string identifierString = "";
88  for (size_t i = 0; i < gidentity.size() - 1; i++) {
89  identifierString += gidentity[i].getName() + "->" + std::to_string(gidentity[i].getValue()) + ", ";
90  }
91  identifierString += gidentity.back().getName() + "->" + std::to_string(gidentity.back().getValue());
92  return identifierString;
93 }
GDigitizedData(GHit *ghit, const std::shared_ptr< GLogger > &logger)
Constructs a GDigitizedData object from a GHit.
std::map< std::string, float > getFltObservablesMap(int which) const
Returns the filtered map of float observables.
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)
float getFltObservable(std::string varName)
int getIntObservable(std::string varName)
std::string getIdentityString()
Returns a string representation of the hit identity.
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.
constexpr int TIMEATELECTRONICSNOTDEFINED
Default value for undefined time at electronics.
constexpr int EC__VARIABLENOTFOUND
Exit code when a variable is not found.
constexpr const char * CHARGEATELECTRONICS
Identifier for charge at electronics.