REST-for-Physics  v2.3
Rare Event Searches ToolKit for Physics
TRestDetectorDaqChannelSwitchingProcess.cxx
1 
17 #include "TRestDetectorDaqChannelSwitchingProcess.h"
18 
19 #include <TLegend.h>
20 #include <TPaveText.h>
21 
22 using namespace std;
23 
25 
26 TRestDetectorDaqChannelSwitchingProcess::TRestDetectorDaqChannelSwitchingProcess() { Initialize(); }
27 
28 TRestDetectorDaqChannelSwitchingProcess::~TRestDetectorDaqChannelSwitchingProcess() {}
29 
31  SetLibraryVersion(LIBRARY_VERSION);
32  SetSectionName(this->ClassName());
33 
34  fFirstDaqChannelDef.clear();
35  fIgnoreUndefinedModules = false;
36  fReadout = nullptr;
37  fEvent = nullptr;
38 }
39 
41  fReadout = GetMetadata<TRestDetectorReadout>();
42  if (fReadout != nullptr) {
43  auto iter = fFirstDaqChannelDef.begin();
44  while (iter != fFirstDaqChannelDef.end()) {
45  auto mod = fReadout->GetReadoutModuleWithID(iter->first);
46  if (mod == nullptr) continue;
47  // finding out the old "firstdaqchannel" value
48  int mindaq = 1e9;
49  for (size_t i = 0; i < mod->GetNumberOfChannels(); i++) {
50  if (mod->GetChannel(i)->GetDaqID() < mindaq) {
51  mindaq = mod->GetChannel(i)->GetDaqID();
52  }
53  }
54 
55  // re-setting the value
56  for (size_t i = 0; i < mod->GetNumberOfChannels(); i++) {
57  mod->GetChannel(i)->SetDaqID(mod->GetChannel(i)->GetDaqID() - mindaq + iter->second);
58  }
59 
60  iter++;
61  }
62 
63  if (fIgnoreUndefinedModules) {
64  for (int i = 0; i < fReadout->GetNumberOfReadoutPlanes(); i++) {
65  TRestDetectorReadoutPlane& plane = (*fReadout)[i];
66 
67  for (size_t j = 0; j < plane.GetNumberOfModules(); j++) {
68  TRestDetectorReadoutModule& mod = plane[j];
69  if (fFirstDaqChannelDef.count(mod.GetModuleID()) == 0) {
70  for (size_t i = 0; i < mod.GetNumberOfChannels(); i++) {
71  mod.GetChannel(i)->SetDaqID(-1e9);
72  }
73  }
74  }
75  }
76  }
77  }
78 }
79 
81  fEvent = inputEvent;
82  return inputEvent;
83 }
84 
86 
87 // redefining module's first daq channel:
88 // <module id="1" firstdaqchannel="136*3" />
89 // ignore undefined modules modules by setting their channel's daq id to -1e9
90 // <parameter name="ignoreUndefinedModules" value="true" />
92  TiXmlElement* ele = fElement->FirstChildElement("module");
93  while (ele != nullptr) {
94  int id = StringToInteger(GetParameter("id", ele));
95  int channel = StringToInteger(GetParameter("firstdaqchannel", ele));
96  if (id == -1 || channel == -1) continue;
97  fFirstDaqChannelDef[id] = channel;
98  ele = ele->NextSiblingElement("module");
99  }
100  fIgnoreUndefinedModules = StringToBool(GetParameter("ignoreUndefinedModules", "false"));
101 }
void EndProcess() override
To be executed at the end of the run (outside event loop)
void InitFromConfigFile() override
To make settings from rml file. This method must be implemented in the derived class.
TRestEvent * ProcessEvent(TRestEvent *inputEvent) override
Process one event.
void InitProcess() override
To be executed at the beginning of the run (outside event loop)
void SetDaqID(Int_t id)
Sets the daq channel number id.
Int_t GetModuleID() const
Returns the module id.
TRestDetectorReadoutChannel * GetChannel(size_t n)
Returns a pointer to a readout channel by index.
size_t GetNumberOfChannels() const
Returns the total number of channels defined inside the module.
size_t GetNumberOfModules() const
Returns the total number of modules in the readout plane.
A base class for any REST event.
Definition: TRestEvent.h:38
Int_t StringToInteger(std::string in)
Gets an integer from a string.