~christopher-hunt08/maus/maus_integrated_kalman

« back to all changes in this revision

Viewing changes to src/map/MapCppKLDigits/MapCppKLDigits.cc

  • Committer: Durga Rajaram
  • Date: 2014-07-16 15:13:05 UTC
  • mfrom: (659.1.92 cand)
  • Revision ID: durga@fnal.gov-20140716151305-q27rv1y9p03v9lks
Tags: MAUS-v0.9, MAUS-v0.9.0
MAUS-v0.9.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
#include "Utils/DAQChannelMap.hh"
22
22
#include "Utils/Exception.hh"
23
23
#include "Interface/dataCards.hh"
 
24
#include "API/PyWrapMapBase.hh"
24
25
 
25
26
#include "src/map/MapCppKLDigits/MapCppKLDigits.hh"
26
27
 
27
28
namespace MAUS {
28
29
 
29
 
bool MapCppKLDigits::birth(std::string argJsonConfigDocument) {
30
 
 
31
 
  _classname = "MapCppKLDigits";
 
30
PyMODINIT_FUNC init_MapCppKLDigits(void) {
 
31
  PyWrapMapBase<MAUS::MapCppKLDigits>::PyWrapMapBaseModInit
 
32
                                            ("MapCppKLDigits", "", "", "", "");
 
33
}
 
34
 
 
35
MapCppKLDigits::MapCppKLDigits() : MapBase<Json::Value>("MapCppKLDigits") {
 
36
}
 
37
 
 
38
void MapCppKLDigits::_birth(const std::string& argJsonConfigDocument) {
32
39
 
33
40
  char* pMAUS_ROOT_DIR = getenv("MAUS_ROOT_DIR");
34
41
 
35
42
  if (!pMAUS_ROOT_DIR) {
36
 
    Squeak::mout(Squeak::error)
37
 
    << "Could not find the $MAUS_ROOT_DIR environmental variable." << std::endl;
38
 
    Squeak::mout(Squeak::error) << "Did you try running: source env.sh ?"
39
 
                                << std::endl;
40
 
    return false;
 
43
    throw MAUS::Exception(Exception::recoverable,
 
44
              "Could not find the $MAUS_ROOT_DIR environmental variable.",
 
45
              "MapCppKLDigits::_birth");
41
46
  }
42
47
 
43
48
  // Check if the JSON document can be parsed, else return error only
44
 
  try {
45
 
    //  JsonCpp setup
46
 
    Json::Value configJSON;
47
 
    Json::Value map_file_name;
48
 
    Json::Value xEnable_V1724_Unpacking;
49
 
    configJSON = JsonWrapper::StringToJson(argJsonConfigDocument);
50
 
    //  this will contain the configuration
51
 
 
52
 
    map_file_name = JsonWrapper::GetProperty(configJSON,
53
 
                                             "KL_cabling_file",
54
 
                                             JsonWrapper::stringValue);
55
 
 
56
 
    std::string xMapFile = std::string(pMAUS_ROOT_DIR) + map_file_name.asString();
57
 
    bool loaded = _map.InitFromFile(xMapFile);
58
 
    if (!loaded)
59
 
      return false;
60
 
 
61
 
    xEnable_V1724_Unpacking = JsonWrapper::GetProperty(configJSON,
62
 
                                                       "Enable_V1724_Unpacking",
63
 
                                                       JsonWrapper::booleanValue);
64
 
 
65
 
    if (!xEnable_V1724_Unpacking.asBool()) {
66
 
      Squeak::mout(Squeak::warning)
67
 
      << "WARNING in MapCppKLDigits::birth. The unpacking of the flashADC V1724 is disabled!!!"
68
 
      << " Are you shure you want this?"
69
 
      << std::endl;
70
 
    }
71
 
 
72
 
    return true;
73
 
  } catch (Exception exc) {
74
 
    CppErrorHandler::getInstance()->HandleExceptionNoJson(exc, _classname);
75
 
  } catch (std::exception exc) {
76
 
    CppErrorHandler::getInstance()->HandleStdExcNoJson(exc, _classname);
77
 
  }
78
 
 
79
 
  return false;
80
 
}
81
 
 
82
 
 
83
 
bool MapCppKLDigits::death()  {return true;}
84
 
 
85
 
std::string MapCppKLDigits::process(std::string document) {
86
 
 
87
49
  //  JsonCpp setup
88
 
  Json::FastWriter writer;
89
 
  Json::Value root;
90
 
  Json::Value xEventType;
91
 
  // Check if the JSON document can be parsed, else return error only
92
 
  try {root = JsonWrapper::StringToJson(document);}
93
 
  catch (...) {
94
 
    Json::Value errors;
95
 
    std::stringstream ss;
96
 
    ss << _classname << " says: Failed to parse input document";
97
 
    errors["bad_json_document"] = ss.str();
98
 
    root["errors"] = errors;
99
 
    return writer.write(root);
 
50
  Json::Value configJSON;
 
51
  Json::Value map_file_name;
 
52
  Json::Value xEnable_V1724_Unpacking;
 
53
  configJSON = JsonWrapper::StringToJson(argJsonConfigDocument);
 
54
  //  this will contain the configuration
 
55
 
 
56
  map_file_name = JsonWrapper::GetProperty(configJSON,
 
57
                                           "KL_cabling_file",
 
58
                                           JsonWrapper::stringValue);
 
59
 
 
60
  std::string xMapFile = std::string(pMAUS_ROOT_DIR) + map_file_name.asString();
 
61
  bool loaded = _map.InitFromFile(xMapFile);
 
62
  if (!loaded)
 
63
    throw MAUS::Exception(Exception::recoverable,
 
64
                          "Failed to initialise map KLChannelMap",
 
65
                          "MapCppKLDigits::_birth");
 
66
 
 
67
    // Load the calibration
 
68
    bool loaded_cal = _mapcal.InitializeFromCards(configJSON);
 
69
    if (!loaded_cal)
 
70
    throw MAUS::Exception(Exception::recoverable,
 
71
                          "Failed to initialise map KLChannelMap",
 
72
                          "MapCppKLDigits::_birth");
 
73
 
 
74
 
 
75
  xEnable_V1724_Unpacking = JsonWrapper::GetProperty(configJSON,
 
76
                                                     "Enable_V1724_Unpacking",
 
77
                                                     JsonWrapper::booleanValue);
 
78
 
 
79
  if (!xEnable_V1724_Unpacking.asBool()) {
 
80
    Squeak::mout(Squeak::warning)
 
81
    << "WARNING in MapCppKLDigits::birth. The unpacking of the flashADC V1724 is disabled!!!"
 
82
    << " Are you shure you want this?"
 
83
    << std::endl;
100
84
  }
101
 
 
102
 
  try {
103
 
    xEventType = JsonWrapper::GetProperty(root,
 
85
}
 
86
 
 
87
 
 
88
void MapCppKLDigits::_death()  {}
 
89
 
 
90
void MapCppKLDigits::_process(Json::Value* document) const {
 
91
 
 
92
    Json::Value& root = *document;
 
93
    Json::Value xEventType = JsonWrapper::GetProperty(root,
104
94
                                          "daq_event_type",
105
95
                                          JsonWrapper::stringValue);
106
96
    if (xEventType == "physics_event" || xEventType == "calibration_event") {
136
126
          }
137
127
      }
138
128
    }
139
 
  } catch (Exception exc) {
140
 
    root = CppErrorHandler::getInstance()
141
 
      ->HandleException(root, exc, _classname);
142
 
  } catch (std::exception exc) {
143
 
    root = CppErrorHandler::getInstance()
144
 
      ->HandleStdExc(root, exc, _classname);
145
 
  }
146
 
 
147
 
  return writer.write(root);
148
129
}
149
130
 
150
131
bool MapCppKLDigits::SetConfiguration(std::string json_configuration) {
151
 
 
152
132
  return true;
153
133
}
154
134
 
155
 
Json::Value MapCppKLDigits::makeDigits(Json::Value xDocDetData, Json::Value xDocTrig) {
 
135
Json::Value MapCppKLDigits::makeDigits(Json::Value xDocDetData,
 
136
                                       Json::Value xDocTrig) const {
156
137
  Json::Value xDocDigits;
157
138
  // Get number of Particle trigger.
158
139
  int n_part_event_triggers = xDocTrig.size();
193
174
  return xDocDigits;
194
175
}
195
176
 
196
 
Json::Value MapCppKLDigits::getAdc(Json::Value xDocAdcHit) {
 
177
Json::Value MapCppKLDigits::getAdc(Json::Value xDocAdcHit) const {
197
178
  std::stringstream xConv;
198
179
  Json::Value xDocInfo;
199
180
 
208
189
 
209
190
  KLChannelKey* xKlAdcKey = _map.find(&xAdcDaqKey);
210
191
 
 
192
  // Get the gain factors
 
193
  double gain = _mapcal.Gain(*xKlAdcKey);
 
194
 
 
195
  // Get the charge
 
196
  int char_mm = JsonWrapper::GetProperty(xDocAdcHit,
 
197
                                            "charge_mm",
 
198
                                            JsonWrapper::intValue).asInt();
 
199
  int char_pm = JsonWrapper::GetProperty(xDocAdcHit,
 
200
                                            "charge_pm",
 
201
                                            JsonWrapper::intValue).asInt();
 
202
 
 
203
  // Equalize charges
 
204
  char_mm /= gain;
 
205
  char_pm /= gain;
 
206
 
211
207
  if (xKlAdcKey) {
212
208
    xDocInfo["kl_key"]            = xKlAdcKey->str();
213
209
    xDocInfo["cell"]              = xKlAdcKey->cell();
214
210
    xDocInfo["pmt"]               = xKlAdcKey->pmt();
215
211
 
216
212
 
217
 
    xDocInfo["charge_mm"] = xDocAdcHit["charge_mm"];
218
 
    xDocInfo["charge_pm"] = xDocAdcHit["charge_pm"];
 
213
    xDocInfo["charge_mm"] = char_mm;
 
214
    xDocInfo["charge_pm"] = char_pm;
219
215
    xDocInfo["position_max"] = xDocAdcHit["position_max"];
220
216
    xDocInfo["part_event_number"] = xDocAdcHit["part_event_number"];
221
217
    xDocInfo["phys_event_number"] = xDocAdcHit["phys_event_number"];
222
218
 
223
219
 
224
 
    // std::cout << "phys_event_number= " << xDocInfo["phys_event_number"] << std::endl;
225
 
    // std::cout << "part_event_number= " << xDocInfo["part_event_number"] << std::endl;
226
 
    // std::cout << "adc= " << xDocAdcHit["charge_mm"] << std::endl;
227
 
    // std::cout << "kl_key= " << xDocInfo["kl_key"] << std::endl;
228
 
    // std::cout << "kl_cell= " << xDocInfo["cell"] << std::endl;
229
 
    // std::cout << "kl_pmt= " << xDocInfo["pmt"] << std::endl;
 
220
     // std::cout << "phys_event_number= " << xDocInfo["phys_event_number"] << std::endl;
 
221
     // std::cout << "part_event_number= " << xDocInfo["part_event_number"] << std::endl;
 
222
     // std::cout << "adc before= " << xDocAdcHit["charge_mm"] << std::endl;
 
223
     // std::cout << "adc after= " << char_mm << std::endl;
 
224
     // std::cout << "gain= " << gain << std::endl;
 
225
     // std::cout << "kl_key= " << xDocInfo["kl_key"] << std::endl;
 
226
     // std::cout << "kl_cell= " << xDocInfo["cell"] << std::endl;
 
227
     // std::cout << "kl_pmt= " << xDocInfo["pmt"] << std::endl;
230
228
  }
231
229
 
232
230
  return xDocInfo;